File size: 8,658 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 371 372 |
//max 32 synced modifiers supported
enum eModifierSyncIDs
{
MODIFIER_SYNC_WOUND_INFECT_1 = 0x00000001,
MODIFIER_SYNC_WOUND_INFECT_2 = 0x00000002,
MODIFIER_SYNC_CONTAMINATION = 0x00000004,//stage1
MODIFIER_SYNC_CONTAMINATION2 = 0x00000008,//stage2 and stage3 share the same sync id
MODIFIER_SYNC_ZONE_EXPOSURE = 0x00000010,
MODIFIER_SYNC_DROWNING = 0x00000020,
MODIFIER_SYNC_FEVER = 0x00000040,
//0x00000080,
//0x00000100,
//0x00000200,
//0x00000400,
//0x00000800,
//0x00001000,
LAST_INDEX,
};
enum EActivationType {
TRIGGER_EVENT_OFF,
TRIGGER_EVENT_ON_ACTIVATION,
TRIGGER_EVENT_ON_CONNECT
};
const int DEFAULT_TICK_TIME_ACTIVE = 3;
const int DEFAULT_TICK_TIME_ACTIVE_SHORT = 1;
const int DEFAULT_TICK_TIME_INACTIVE = 3;
const int DEFAULT_TICK_TIME_INACTIVE_LONG = 10;
class ModifierDebugObj
{
string m_Name;
int m_ID;
bool m_IsActive;
bool m_IsLocked;
void ModifierDebugObj(int id, string name, bool active, bool locked)
{
m_Name = name;
m_ID = id;
m_IsActive = active;
m_IsLocked = locked;
}
string GetName()
{
return m_Name;
}
int GetID()
{
return m_ID;
}
bool IsActive()
{
return m_IsActive;
}
bool IsLocked()
{
return m_IsLocked;
}
}
class ModifiersManager
{
PlayerBase m_Player;
ref map<int, ref ModifierBase> m_ModifierList;
ref array< ref ModifierBase> m_ModifierListArray = new array< ref ModifierBase>;
ref array<ref Param> m_ParamList;
bool m_AllowModifierTick = false;
const int STORAGE_VERSION = 121;
void ModifiersManager(PlayerBase player)
{
m_ModifierList = new map<int, ref ModifierBase>;
m_ParamList = new array<ref Param>;
m_Player = player;
Init();
}
void Init()
{
#ifdef DEVELOPER
AddModifier(new TestDiseaseMdfr);
#endif
AddModifier(new BloodRegenMdfr);
//AddModifier(new BoneRegen);
//AddModifier(new Health);
AddModifier(new SalineMdfr);
AddModifier(new HealthRegenMdfr);
AddModifier(new HungerMdfr);
//AddModifier(new Shock);
AddModifier(new ImmuneSystemMdfr);
AddModifier(new StomachMdfr);
AddModifier(new HeatComfortMdfr);
AddModifier(new ThirstMdfr);
AddModifier(new BleedingCheckMdfr);
//AddModifier(new Blinded);
//AddModifier(new BrokenArms);
AddModifier(new BrokenLegsMdfr); // <-- Broken legs are here
AddModifier(new VomitStuffedMdfr);
AddModifier(new BurningMdfr);
AddModifier(new FeverMdfr);
AddModifier(new HeartAttackMdfr);
AddModifier(new HemolyticReactionMdfr);
AddModifier(new PoisoningMdfr);
AddModifier(new StuffedStomachMdfr);
//AddModifier(new Tremor);
AddModifier(new UnconsciousnessMdfr);
AddModifier(new ShockDamageMdfr);
AddModifier(new CommonColdMdfr);
AddModifier(new CholeraMdfr);
AddModifier(new InfluenzaMdfr);
AddModifier(new SalmonellaMdfr);
AddModifier(new BrainDiseaseMdfr);
AddModifier(new WetMdfr);
AddModifier(new ImmunityBoost);
AddModifier(new AntibioticsMdfr);
AddModifier(new ToxicityMdfr);
AddModifier(new BreathVapourMdfr);
AddModifier(new ShockMdfr);
AddModifier(new WoundInfectStage1Mdfr);
AddModifier(new WoundInfectStage2Mdfr);
AddModifier(new CharcoalMdfr);
AddModifier(new MorphineMdfr);
AddModifier(new PainKillersMdfr);
AddModifier(new EpinephrineMdfr);
AddModifier(new HeatBufferMdfr);
AddModifier(new DisinfectionMdfr);
AddModifier(new FatigueMdfr);
AddModifier(new ContaminationStage1Mdfr);
AddModifier(new ContaminationStage2Mdfr);
AddModifier(new ContaminationStage3Mdfr);
AddModifier(new AreaExposureMdfr);
AddModifier(new MaskMdfr);
AddModifier(new FliesMdfr);
AddModifier(new DrowningMdfr);
}
void SetModifiers(bool enable)
{
if (m_AllowModifierTick == enable)
return;
m_AllowModifierTick = enable;
#ifdef DIAG_DEVELOPER
#ifndef SERVER
DiagMenu.SetValue(DiagMenuIDs.CHEATS_MODIFIERS, enable);
#endif
#endif
if ( !enable )
{
for (int i = 0; i < m_ModifierList.Count(); i++)
{
m_ModifierList.GetElement(i).ResetLastTickTime();
}
}
}
int GetStorageVersion()
{
return STORAGE_VERSION;
}
bool IsModifiersEnable()
{
return m_AllowModifierTick;
}
void AddModifier(ModifierBase modifier)
{
modifier.InitBase(m_Player,this);
int id = modifier.GetModifierID();
if (id < 1)
{
Error("modifiers ID must be 1 or higher(for debugging reasons)");
}
//TODO: add a check for duplicity
m_ModifierList.Insert(id, modifier);
m_ModifierListArray.Insert(modifier);
}
bool IsModifierActive(eModifiers modifier_id)
{
return m_ModifierList.Get(modifier_id).IsActive();
}
void OnScheduledTick(float delta_time)
{
if(!m_AllowModifierTick) return;
foreach(ModifierBase m: m_ModifierListArray)
{
m.Tick(delta_time);
}
}
void DeactivateAllModifiers()
{
for(int i = 0; i < m_ModifierList.Count(); i++)
{
m_ModifierList.GetElement(i).Deactivate();
}
}
void ActivateModifier(int modifier_id, bool triggerEvent = EActivationType.TRIGGER_EVENT_ON_ACTIVATION)
{
m_ModifierList.Get(modifier_id).ActivateRequest(triggerEvent);
}
void DeactivateModifier(int modifier_id, bool triggerEvent = true)
{
m_ModifierList.Get(modifier_id).Deactivate(triggerEvent);
}
void OnStoreSave( ParamsWriteContext ctx )
{
CachedObjectsArrays.ARRAY_INT.Clear();
int modifier_count;
for(int x = 0; x < m_ModifierList.Count(); x++)
{
ModifierBase mdfr = m_ModifierList.GetElement(x);
if( mdfr.IsActive() && mdfr.IsPersistent() )
{
modifier_count++;
//save the modifier id
CachedObjectsArrays.ARRAY_INT.Insert( mdfr.GetModifierID() );
if( mdfr.IsTrackAttachedTime() )
{
//save the overall attached time
CachedObjectsArrays.ARRAY_INT.Insert( mdfr.GetAttachedTime() );
}
}
}
//write the count
//CachedObjectsParams.PARAM1_INT.param1 = modifier_count;
//PrintString("Saving modifiers count: "+ modifier_count);
ctx.Write(modifier_count);
//write the individual modifiers and respective attached times
for(int i = 0; i < CachedObjectsArrays.ARRAY_INT.Count(); i++)
{
int item = CachedObjectsArrays.ARRAY_INT.Get(i);
//PrintString( "saving item: "+item );
ctx.Write(item);
}
for (int z = 0; z < m_ParamList.Count(); z++)
{
m_ParamList.Get(z).Serialize(ctx);
}
}
bool OnStoreLoad( ParamsReadContext ctx, int version )
{
int modifier_count;
if(!ctx.Read(modifier_count))
return false;
//PrintString("Loading modifiers count: "+ modifier_count);
for(int i = 0; i < modifier_count; i++)
{
int modifier_id;
if(!ctx.Read(modifier_id))
return false;
//PrintString( "loading item: "+modifier_id );
//int modifier_id = CachedObjectsParams.PARAM1_INT.param1;
ModifierBase modifier = GetModifier(modifier_id);
if( modifier )
{
if( modifier.IsTrackAttachedTime() )
{
int time;
if(!ctx.Read(time))//get the attached time
return false;
modifier.SetAttachedTime( time );
}
ActivateModifier(modifier_id, EActivationType.TRIGGER_EVENT_ON_CONNECT);
}
else
{
Debug.LogError("DB loading: non-existent modifier with id:"+modifier_id.ToString());
}
}
for (int x = 0; x < m_ParamList.Count(); x++)
{
if(!m_ParamList.Get(x).Deserializer(ctx))
{
return false;
}
}
return true;
}
ModifierBase GetModifier(int modifier_id)
{
return m_ModifierList.Get(modifier_id);
}
PlayerBase GetPlayer()
{
return m_Player;
}
void SetModifierLock(int modifier_id, bool state)
{
m_ModifierList.Get(modifier_id).SetLock(state);
}
bool GetModifierLock(int modifier_id)
{
return m_ModifierList.Get(modifier_id).IsLocked();
}
void DbgGetModifiers(array<ref ModifierDebugObj> modifiers)
{
modifiers.Clear();
for(int i = 1;i < eModifiers.COUNT; i++)
{
if(m_ModifierList.Contains(i))
{
ModifierBase modifier = m_ModifierList.Get(i);
int modifier_id = modifier.GetModifierID();
string modifier_name = modifier.GetName();
bool active = modifier.IsActive();
string debug_text = modifier.GetDebugTextSimple();
bool is_locked = modifier.IsLocked();
if(active && debug_text != "")
{
modifier_name +=" | "+debug_text;
}
ModifierDebugObj obj = new ModifierDebugObj(modifier_id, modifier_name, active, is_locked);
modifiers.Insert( obj );
}
}
}
void ResetAll()
{
bool hasAreaExposureModifier = IsModifierActive(eModifiers.MDF_AREAEXPOSURE);
bool hasMaksModifier = IsModifierActive(eModifiers.MDF_MASK);
DeactivateAllModifiers();
if (hasAreaExposureModifier)
ActivateModifier(eModifiers.MDF_AREAEXPOSURE);
if (hasMaksModifier)
ActivateModifier(eModifiers.MDF_MASK);
}
}
|