File size: 5,084 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
enum EAchievementError
{
ERR_OK,
ERR_NOT_FOUND,
ERR_BAD_DATA,
ERR_NOT_IMPLEMENTED,
ERR_UNKNOWN,
};
enum EAchievementTargetId
{
TARGET_SURVIVOR,
TARGET_INFECTED,
};
enum EAchievementRankId
{
RANK_SURVIVOR, //!< must be TARGET_SURVIVOR
RANK_INFECTED, //!< must be TARGET_INFECTED
RANK_INFECTED_SOLDIER, //!< must be TARGET_INFECTED
};
enum EAchievementRangeId
{
RANGE_OTHER,
RANGE_MELEE,
RANGE_RANGED,
};
enum EAchievementHitId
{
HIT_OTHER,
HIT_HEADSHOT,
};
enum EAchievementActionId
{
ACTION_EAT,
ACTION_DRINK,
ACTION_EQUIP_GEAR,
ACTION_COOK_STEAK,
ACTION_IGNITE_FIRE_MATCHBOX,
ACTION_IGNITE_FIRE_ROAD_FLARE,
ACTION_IGNITE_FIRE_HAND_DRILL,
ACTION_SHAVE,
ACTION_GUT_DEER,
ACTION_APPLY_MEDS_ON_SURVIVOR,
ACTION_HANDCUFF_SURVIVOR,
};
class Achievements
{
private void Achievements();
private void ~Achievements();
static proto EAchievementError SendEventAction(EAchievementActionId action_id);
static proto EAchievementError SendEventKill(EAchievementTargetId target_id, EAchievementRankId rank_id, EAchievementRangeId range_id, EAchievementHitId hit_id, float distance);
//===================================
// OnActionEat
//===================================
static void OnActionEat()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_EAT ) );
}
//===================================
// OnActionDrink
//===================================
static void OnActionDrink()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_DRINK ) );
}
//===================================
// OnEquipdFullGear
//===================================
static void OnEquippedFullGear()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_EQUIP_GEAR ) );
}
//===================================
// OnCookedSteak
//===================================
static void OnCookedSteak()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_COOK_STEAK ) );
}
//===================================
// OnActionIgniteMatchbox
//===================================
static void OnActionIgniteMatchbox()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_IGNITE_FIRE_MATCHBOX ) );
}
//===================================
// OnActionIgniteRoadflare
//===================================
static void OnActionIgniteRoadflare()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_IGNITE_FIRE_ROAD_FLARE ) );
}
//===================================
// OnActionIgniteDrill
//===================================
static void OnActionIgniteDrill()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_IGNITE_FIRE_HAND_DRILL ) );
}
//===================================
// OnActionShave
//===================================
static void OnActionShave()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_SHAVE ) );
}
//===================================
// OnActionGutDeer
//===================================
static void OnActionGutDeer()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_GUT_DEER ) );
}
//===================================
// OnActionMedsSurvivor
//===================================
static void OnActionMedsSurvivor()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_APPLY_MEDS_ON_SURVIVOR ) );
}
//===================================
// OnActionHandcuff
//===================================
static void OnActionHandcuff()
{
CheckError( SendEventAction( EAchievementActionId.ACTION_HANDCUFF_SURVIVOR ) );
}
//===================================
// OnPlayerKilled
//===================================
static void OnPlayerKilled(EntityAI victim, EntityAI killer, EntityAI source, bool is_headshot)
{
EAchievementTargetId target_id = EAchievementTargetId.TARGET_SURVIVOR;
EAchievementRankId target_rank_id = EAchievementRankId.RANK_SURVIVOR;
EAchievementRangeId range_id = EAchievementRangeId.RANGE_OTHER;
EAchievementHitId hit_id = EAchievementHitId.HIT_OTHER;
float distance = 0;
if ( victim.IsZombie() )
{
target_id = EAchievementTargetId.TARGET_INFECTED;
target_rank_id = EAchievementRankId.RANK_INFECTED;
if ( victim.IsZombieMilitary() )
{
target_rank_id = EAchievementRankId.RANK_INFECTED_SOLDIER;
}
}
if ( source )
{
if ( source.IsMeleeWeapon() )
{
range_id = EAchievementRangeId.RANGE_MELEE;
}
else if ( source.IsWeapon() && killer )
{
range_id = EAchievementRangeId.RANGE_RANGED;
distance = vector.Distance( killer.GetPosition(), victim.GetPosition() );
if ( is_headshot )
{
hit_id = EAchievementHitId.HIT_HEADSHOT;
}
}
}
CheckError( SendEventKill(target_id, target_rank_id, range_id, hit_id, distance) );
}
//-----------------------------------
// CheckError
//-----------------------------------
private static void CheckError(EAchievementError error)
{
if ( error != EAchievementError.ERR_OK )
{
Print("Achievements: Cannot send achievement event. Error ID: " + error);
}
}
};
typedef Achievements AchievementsXbox; |