File size: 15,187 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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
class FallDamageData
{
int m_LandType;
float m_Height;
float m_HealthCoef;
float m_ShockCoef;
float m_BrokenLegsCoef;
float m_BleedingHandsCoef;
float m_BleedingFeetCoef;
float m_BleedingLegsCoef;
float m_GlovesHealthCoef;
float m_ShoesHealthCoef;
float m_PantsHealthCoef;
float m_BleedingChanceCoef;
float m_BleedingChanceLegsCoef;
}
class DayZPlayerImplementFallDamage
{
static const string FALL_DAMAGE_AMMO_HEALTH = "FallDamageHealth";
static const string FALL_DAMAGE_AMMO_SHOCK = "FallDamageShock";
static const string FALL_DAMAGE_AMMO_HEALTH_ATTACHMENT = "FallDamageHealthAttachment";
static const string FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS = "FallDamageHealthOtherAttachments";
const float HEALTH_HEIGHT_LOW = 5;
const float HEALTH_HEIGHT_HIGH = 14;
private const float SHOCK_HEIGHT_LOW = 3;
private const float SHOCK_HEIGHT_HIGH = 12;
private const float BROKENLEGS_HEIGHT_LOW = 5;
private const float BROKENLEGS_HEIGHT_HIGH = 9;
private const float GLOVES_HEALTH_HEIGHT_LOW = 5;
private const float GLOVES_HEALTH_HEIGHT_HIGH = 15;
private const float SHOES_HEALTH_HEIGHT_LOW = 2;
private const float SHOES_HEALTH_HEIGHT_HIGH = 15;
private const float PANTS_HEALTH_HEIGHT_LOW = 5;
private const float PANTS_HEALTH_HEIGHT_HIGH = 16;
private const float BLEEDINGHANDS_HEIGHT_LOW = 5;
private const float BLEEDINGFEET_HEIGHT_LOW = 3;
private const float BLEEDINGLEGS_HEIGHT_LOW = 10;
private const float RANDOM_THRESHOLD_HEALTH_LOW = 0.05;
private const float RANDOM_THRESHOLD_HEALTH_HIGH = 0.1;
private const float RANDOM_THRESHOLD_LEGS_LOW = 0.05;
private const float RANDOM_THRESHOLD_LEGS_HIGH = 0.1;
private const float RANDOM_THRESHOLD_ATTACHMENTS_LOW = 0;
private const float RANDOM_THRESHOLD_ATTACHMENTS_HIGH = 0.2;
private const float BLEEDING_CHANCE_HEIGHT_LOW = 3;
private const float BLEEDING_CHANCE_HEIGHT_HIGH = 15;
private static const float BROKENLEGS_HEALTH_DAMAGE_MAX = 125;
private static const string BLEEDING_HANDS_SELECTIONS[2] = {"LeftForeArmRoll", "RightForeArmRoll"};
private static const string BLEEDING_FEET_SELECTIONS[2] = {"LeftFoot", "RightFoot"};
private static const string BLEEDING_LEGS_SELECTIONS[2] = {"LeftLeg", "RightLeg"};
private const int DAMAGE_TYPE_GLOBAL = 0;
private const int DAMAGE_TYPE_LEGS = 1;
private const int DAMAGE_TYPE_ATTACHMENTS = 2;
DayZPlayer m_Player;
private ref FallDamageData m_FallDamageData;
#ifdef DIAG_DEVELOPER
bool m_Debug = false;
private static ref map<string, float> m_AmmoTypeData;
#endif
void DayZPlayerImplementFallDamage(DayZPlayer pPlayer)
{
m_Player = pPlayer;
m_FallDamageData = new FallDamageData();
#ifdef DIAG_DEVELOPER
PreloadAmmoTypeData();
#endif
}
float GetHeight()
{
return m_FallDamageData.m_Height;
}
int GetLandType()
{
return m_FallDamageData.m_LandType;
}
void HandleFallDamage(FallDamageData pData)
{
m_FallDamageData = pData;
m_FallDamageData.m_HealthCoef = Math.InverseLerp(HEALTH_HEIGHT_LOW, HEALTH_HEIGHT_HIGH, pData.m_Height);
m_FallDamageData.m_HealthCoef = Randomize(DAMAGE_TYPE_GLOBAL, m_FallDamageData.m_HealthCoef);
m_FallDamageData.m_HealthCoef = Math.Clamp(m_FallDamageData.m_HealthCoef, 0, 1);
m_FallDamageData.m_ShockCoef = Math.InverseLerp(SHOCK_HEIGHT_LOW, SHOCK_HEIGHT_HIGH, pData.m_Height);
m_FallDamageData.m_ShockCoef = Math.Clamp(m_FallDamageData.m_ShockCoef, 0, 1);
m_FallDamageData.m_BrokenLegsCoef = Math.InverseLerp(BROKENLEGS_HEIGHT_LOW, BROKENLEGS_HEIGHT_HIGH, pData.m_Height);
m_FallDamageData.m_BrokenLegsCoef = Randomize(DAMAGE_TYPE_LEGS, m_FallDamageData.m_BrokenLegsCoef);
m_FallDamageData.m_BrokenLegsCoef = Math.Clamp(m_FallDamageData.m_BrokenLegsCoef, 0, 1);
m_FallDamageData.m_BleedingHandsCoef = Math.InverseLerp(0, BLEEDINGHANDS_HEIGHT_LOW, pData.m_Height);
m_FallDamageData.m_BleedingHandsCoef = Math.Clamp(m_FallDamageData.m_BleedingHandsCoef, 0, 1);
m_FallDamageData.m_BleedingFeetCoef = Math.InverseLerp(0, BLEEDINGFEET_HEIGHT_LOW, pData.m_Height);
m_FallDamageData.m_BleedingFeetCoef = Math.Clamp(m_FallDamageData.m_BleedingFeetCoef, 0, 1);
m_FallDamageData.m_BleedingLegsCoef = Math.InverseLerp(0, BLEEDINGLEGS_HEIGHT_LOW, pData.m_Height);
m_FallDamageData.m_BleedingLegsCoef = Math.Clamp(m_FallDamageData.m_BleedingLegsCoef, 0, 1);
m_FallDamageData.m_GlovesHealthCoef = Math.InverseLerp(GLOVES_HEALTH_HEIGHT_LOW, GLOVES_HEALTH_HEIGHT_HIGH, pData.m_Height);
m_FallDamageData.m_GlovesHealthCoef = Randomize(DAMAGE_TYPE_ATTACHMENTS, m_FallDamageData.m_GlovesHealthCoef);
m_FallDamageData.m_GlovesHealthCoef = Math.Clamp(m_FallDamageData.m_GlovesHealthCoef, 0, 1);
m_FallDamageData.m_ShoesHealthCoef = Math.InverseLerp(SHOES_HEALTH_HEIGHT_LOW, SHOES_HEALTH_HEIGHT_HIGH, pData.m_Height);
m_FallDamageData.m_ShoesHealthCoef = Randomize(DAMAGE_TYPE_ATTACHMENTS, m_FallDamageData.m_ShoesHealthCoef);
m_FallDamageData.m_ShoesHealthCoef = Math.Clamp(m_FallDamageData.m_ShoesHealthCoef, 0, 1);
m_FallDamageData.m_PantsHealthCoef = Math.InverseLerp(PANTS_HEALTH_HEIGHT_LOW, PANTS_HEALTH_HEIGHT_HIGH, pData.m_Height);
m_FallDamageData.m_PantsHealthCoef = Randomize(DAMAGE_TYPE_ATTACHMENTS, m_FallDamageData.m_PantsHealthCoef);
m_FallDamageData.m_PantsHealthCoef = Math.Clamp(m_FallDamageData.m_PantsHealthCoef, 0, 1);
m_FallDamageData.m_BleedingChanceCoef = Math.InverseLerp(BLEEDING_CHANCE_HEIGHT_LOW, BLEEDING_CHANCE_HEIGHT_HIGH, pData.m_Height);
m_FallDamageData.m_BleedingChanceCoef = Math.Clamp(m_FallDamageData.m_BleedingChanceCoef, 0, 0.7);
m_FallDamageData.m_BleedingChanceLegsCoef = 0.15;
if (GetGame().IsServer())
{
PlayerBase playerBase = PlayerBase.Cast(m_Player);
if (playerBase)
{
AttachBleedingToZonesByHeight(playerBase);
DamageAttachedGear(playerBase);
playerBase.DamageAllLegs(BROKENLEGS_HEALTH_DAMAGE_MAX * m_FallDamageData.m_BrokenLegsCoef);
}
vector posMS = m_Player.WorldToModel(m_Player.GetPosition());
m_Player.ProcessDirectDamage(DamageType.CUSTOM, m_Player, "", FALL_DAMAGE_AMMO_HEALTH, posMS, m_FallDamageData.m_HealthCoef);
m_Player.ProcessDirectDamage(DamageType.CUSTOM, m_Player, "", FALL_DAMAGE_AMMO_SHOCK, posMS, m_FallDamageData.m_ShockCoef);
if (playerBase)
playerBase.ForceUpdateInjuredState();
}
}
private float Randomize(int pType, float pValue)
{
Math.Randomize(GetGame().GetTime());
int randomizedSign = -1;
if (Math.RandomIntInclusive(1, 2) % 2 == 1)
randomizedSign = 1;
float randomizationValue = 0;
switch (pType)
{
case DAMAGE_TYPE_GLOBAL:
randomizationValue = Math.RandomFloatInclusive(RANDOM_THRESHOLD_HEALTH_LOW, RANDOM_THRESHOLD_HEALTH_HIGH);
break;
case DAMAGE_TYPE_LEGS:
randomizationValue = Math.RandomFloatInclusive(RANDOM_THRESHOLD_LEGS_LOW, RANDOM_THRESHOLD_LEGS_HIGH);
break;
case DAMAGE_TYPE_ATTACHMENTS:
randomizationValue = Math.RandomFloatInclusive(RANDOM_THRESHOLD_ATTACHMENTS_LOW, RANDOM_THRESHOLD_ATTACHMENTS_HIGH);
break;
}
return pValue + (randomizedSign * pValue * randomizationValue);
}
private void AttachBleedingToZonesByHeight(notnull PlayerBase pPlayer)
{
Math.Randomize(GetGame().GetTime());
int bleedingSelectionIndex;
BleedingSourcesManagerServer bleedingManager = pPlayer.GetBleedingManagerServer();
if (Math.RandomFloatInclusive(0.0, 1.0) <= m_FallDamageData.m_BleedingChanceCoef && m_FallDamageData.m_BleedingHandsCoef == 1.0 && pPlayer.FindAttachmentBySlotName("Gloves") == null)
{
bleedingSelectionIndex = Math.RandomInt(0, 2);
bleedingManager.AttemptAddBleedingSourceBySelection(BLEEDING_HANDS_SELECTIONS[bleedingSelectionIndex]);
}
if (Math.RandomFloatInclusive(0.0, 1.0) <= m_FallDamageData.m_BleedingChanceCoef && m_FallDamageData.m_BleedingFeetCoef == 1.0 && pPlayer.FindAttachmentBySlotName("Feet") == null)
{
bleedingSelectionIndex = Math.RandomInt(0, 2);
bleedingManager.AttemptAddBleedingSourceBySelection(BLEEDING_FEET_SELECTIONS[bleedingSelectionIndex]);
}
if (Math.RandomFloatInclusive(0.0, 1.0) <= m_FallDamageData.m_BleedingChanceLegsCoef && m_FallDamageData.m_BleedingLegsCoef == 1.0)
{
bleedingSelectionIndex = Math.RandomInt(0, 2);
bleedingManager.AttemptAddBleedingSourceBySelection(BLEEDING_LEGS_SELECTIONS[bleedingSelectionIndex]);
}
}
private void DamageAttachedGear(notnull PlayerBase pPlayer)
{
EntityAI gloves = pPlayer.FindAttachmentBySlotName("Gloves");
if (gloves)
gloves.ProcessDirectDamage(DT_CUSTOM, pPlayer, "", FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS, gloves.WorldToModel(gloves.GetPosition()), m_FallDamageData.m_GlovesHealthCoef);
EntityAI shoes = pPlayer.FindAttachmentBySlotName("Feet");
if (shoes)
shoes.ProcessDirectDamage(DT_CUSTOM, pPlayer, "", FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS, shoes.WorldToModel(shoes.GetPosition()), m_FallDamageData.m_ShoesHealthCoef);
EntityAI pants = pPlayer.FindAttachmentBySlotName("Legs");
if (pants)
pants.ProcessDirectDamage(DT_CUSTOM, pPlayer, "", FALL_DAMAGE_AMMO_HEALTH_ATTACHMENT, pants.WorldToModel(pants.GetPosition()), m_FallDamageData.m_PantsHealthCoef);
}
#ifdef DIAG_DEVELOPER
FallDamageDebugData GetFallDamageDebugData()
{
FallDamageDebugData data = new FallDamageDebugData();
data.Synch(this);
return data;
}
void ShowFallDamageDebugInfo(bool enabled)
{
FallDamageDebugData data = GetFallDamageDebugData();
DisplayFallDamageDebugInfo(enabled, data);
}
private static string LandTypeToString(int landType)
{
switch (landType)
{
case 1:
return "LIGHT";
case 2:
return "MEDIUM";
case 3:
return "HEAVY":
}
return "NONE";
}
private void PreloadAmmoTypeData()
{
if (m_AmmoTypeData == null)
m_AmmoTypeData = new ref map<string, float>();
m_AmmoTypeData.Insert(FALL_DAMAGE_AMMO_HEALTH, GetValuesFromAmmoType(FALL_DAMAGE_AMMO_HEALTH)[0]);
m_AmmoTypeData.Insert(FALL_DAMAGE_AMMO_SHOCK, GetValuesFromAmmoType(FALL_DAMAGE_AMMO_SHOCK)[2]);
m_AmmoTypeData.Insert(FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS, GetValuesFromAmmoType(FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS)[0]);
m_AmmoTypeData.Insert(FALL_DAMAGE_AMMO_HEALTH_ATTACHMENT, GetValuesFromAmmoType(FALL_DAMAGE_AMMO_HEALTH_ATTACHMENT)[0]);
}
private vector GetValuesFromAmmoType(string pAmmoType)
{
vector values = vector.Zero;
values[0] = GetGame().ConfigGetFloat(string.Format("CfgAmmo %1 DamageApplied Health damage", pAmmoType));
values[1] = GetGame().ConfigGetFloat(string.Format("CfgAmmo %1 DamageApplied Blood damage", pAmmoType));
values[2] = GetGame().ConfigGetFloat(string.Format("CfgAmmo %1 DamageApplied Shock damage", pAmmoType));
return values;
}
static void DisplayFallDamageDebugInfo(bool enabled, FallDamageDebugData data)
{
int windowPosX = 10;
int windowPosY = 200;
DbgUI.Begin("Fall Damage (last)", windowPosX, windowPosY);
if (enabled)
{
DbgUI.Text(string.Format("Height:\t%1", Math.Clamp(data.m_Height, 0, float.MAX)));
DbgUI.Text(string.Format("Land Type:\t%1 (%2)", data.m_LandType, LandTypeToString(data.m_LandType)));
DbgUI.Text("");
DbgUI.Text("Health");
DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_HealthCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_HEALTH] * data.m_HealthCoef));
DbgUI.Text("Shock");
DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_ShockCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_SHOCK] * data.m_ShockCoef));
DbgUI.Text("Broken Legs:");
DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_BrokenLegsCoef, BROKENLEGS_HEALTH_DAMAGE_MAX * data.m_BrokenLegsCoef));
DbgUI.Text("Gloves damage:");
DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_GlovesHealthCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS] * data.m_GlovesHealthCoef));
DbgUI.Text("Shoes damage:");
DbgUI.Text(string.Format(" coef:%1 dmg:%2", data.m_ShoesHealthCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_HEALTH_OTHER_ATTACHMENTS] * data.m_ShoesHealthCoef));
DbgUI.Text("Pants damage:");
DbgUI.Text(string.Format(" coef:%1 dmg:%2" , data.m_PantsHealthCoef, m_AmmoTypeData[FALL_DAMAGE_AMMO_HEALTH_ATTACHMENT] * data.m_PantsHealthCoef));
DbgUI.Text("Bleeding coefs:");
DbgUI.Text(string.Format(" hands:%1", data.m_BleedingHandsCoef));
DbgUI.Text(string.Format(" feet:%1", data.m_BleedingFeetCoef));
DbgUI.Text(string.Format(" legs:%1", data.m_BleedingLegsCoef));
DbgUI.Text(string.Format(" H&F chance:%1", data.m_BleedingChanceCoef));
}
DbgUI.End();
}
void FillDebugFallDamageData(FallDamageDebugData data)
{
data.m_Height = m_FallDamageData.m_Height;
data.m_LandType = m_FallDamageData.m_LandType;
data.m_HealthCoef = m_FallDamageData.m_HealthCoef;
data.m_ShockCoef = m_FallDamageData.m_ShockCoef;
data.m_BrokenLegsCoef = m_FallDamageData.m_BrokenLegsCoef;
data.m_GlovesHealthCoef = m_FallDamageData.m_GlovesHealthCoef;
data.m_ShoesHealthCoef = m_FallDamageData.m_ShoesHealthCoef;
data.m_PantsHealthCoef = m_FallDamageData.m_PantsHealthCoef;
data.m_BleedingHandsCoef = m_FallDamageData.m_BleedingHandsCoef;
data.m_BleedingFeetCoef = m_FallDamageData.m_BleedingFeetCoef;
data.m_BleedingLegsCoef = m_FallDamageData.m_BleedingLegsCoef;
data.m_BleedingChanceCoef = m_FallDamageData.m_BleedingChanceCoef;
}
#endif
//!
//! DEPRECATED
//!
const string FD_AMMO = "FallDamage"; //!< ammo type used for damaging
const float FD_DMG_FROM_HEIGHT = 2.5; //!< damage will not be taken into account bellow this HeightToDamage
const float FD_MAX_DMG_AT_HEIGHT = 15; //!< height where player gets 100% damage
const float FD_MAX_HEIGHT_LEG_BREAK = 8; //!< height where legs break most of the time
void HandleFallDamage(float pHeight);
float DamageCoef(float pHeight);
}
#ifdef DIAG_DEVELOPER
class FallDamageDebugData : Param
{
int m_LandType;
float m_Height;
float m_HealthCoef;
float m_ShockCoef;
float m_BrokenLegsCoef;
float m_GlovesHealthCoef;
float m_ShoesHealthCoef;
float m_PantsHealthCoef;
float m_BleedingHandsCoef;
float m_BleedingFeetCoef;
float m_BleedingLegsCoef;
float m_BleedingChanceCoef;
void Synch(DayZPlayerImplementFallDamage fallDamage)
{
m_Height = fallDamage.GetHeight();
m_LandType = fallDamage.GetLandType();
fallDamage.FillDebugFallDamageData(this);
}
override bool Serialize(Serializer ctx)
{
return ctx.Write(m_Height) && ctx.Write(m_LandType) && ctx.Write(m_HealthCoef) && ctx.Write(m_ShockCoef) && ctx.Write(m_BrokenLegsCoef) && ctx.Write(m_GlovesHealthCoef) && ctx.Write(m_ShoesHealthCoef) && ctx.Write(m_PantsHealthCoef) && ctx.Write(m_BleedingHandsCoef) && ctx.Write(m_BleedingFeetCoef) && ctx.Write(m_BleedingLegsCoef);
}
override bool Deserializer(Serializer ctx)
{
return ctx.Read(m_Height) && ctx.Read(m_LandType) && ctx.Read(m_HealthCoef) && ctx.Read(m_ShockCoef) && ctx.Write(m_BrokenLegsCoef) && ctx.Read(m_GlovesHealthCoef) && ctx.Read(m_ShoesHealthCoef) && ctx.Read(m_PantsHealthCoef) && ctx.Read(m_BleedingHandsCoef) && ctx.Read(m_BleedingFeetCoef) && ctx.Read(m_BleedingLegsCoef);
}
}
#endif
|