65 int m_ActiveSymptomIndexPrimary = -1;
66 int m_CurrentCommandID;
68 const int STORAGE_VERSION = 121;
70 bool m_ShowDebug =
false;
71 bool m_ShowDebug2 =
false;
77 RegisterSymptom(
new CoughSymptom);
79 RegisterSymptom(
new BlindnessSymptom);
80 RegisterSymptom(
new SneezeSymptom);
81 RegisterSymptom(
new FeverBlurSymptom);
82 RegisterSymptom(
new BloodLoss);
84 RegisterSymptom(
new FreezeSymptom);
85 RegisterSymptom(
new FreezeRattleSymptom);
86 RegisterSymptom(
new HotSymptom);
87 RegisterSymptom(
new PainLightSymptom);
88 RegisterSymptom(
new PainHeavySymptom);
89 RegisterSymptom(
new HandShiversSymptom);
91 RegisterSymptom(
new HMP3Symptom);
92 RegisterSymptom(
new GaspSymptom);
95 int GetStorageVersion()
101 void AutoactivateSymptoms()
108 QueueUpSecondarySymptom(SymptomIDs.SYMPTOM_BLOODLOSS);
126 AutoactivateSymptoms();
129 void OnPlayerKilled()
131 foreach (
SymptomBase symptomPrimary : m_SymptomQueuePrimary)
132 symptomPrimary.OnOwnerKilled();
134 foreach (
SymptomBase symptomSecondary : m_SymptomQueueSecondary)
135 symptomSecondary.OnOwnerKilled();
140 return m_SymptomsUIDs.Get(SYMPTOM_uid);
151 int id = Symptom.GetType();
153 if (m_AvailableSymptoms.Contains(
id))
155 ErrorEx(
string.Format(
"Symptom %1 already registered!", Symptom.GetName()));
159 m_AvailableSymptoms.Insert(
id, Symptom);
166 m_AnimMeta.AnimFinished(type);
170 void OnAnimationStarted()
172 if (GetCurrentPrimaryActiveSymptom())
173 GetCurrentPrimaryActiveSymptom().AnimationStart();
178 int uid =
Math.RandomInt(1, 2147483647);
182 return CreateUniqueID();
185 bool IsUIDUsed(
int uid)
187 return m_SymptomsUIDs.Contains(uid);
190 string GetSymptomName(
int symptom_id)
192 return m_AvailableSymptoms.Get(symptom_id).GetName();
197 SmptAnimMetaBase animMeta = m_AvailableSymptoms.Get(symptom_id).SpawnAnimMetaObject();
198 animMeta.m_StateType = symptom_id;
204 void RequestSymptomExit(
int SYMPTOM_uid)
206 if (m_SymptomsUIDs.Get(SYMPTOM_uid))
207 m_SymptomsUIDs.Get(SYMPTOM_uid).RequestDestroy();
210 bool IsSymptomPrimary(
int symptom_id)
212 return m_AvailableSymptoms.Get(symptom_id).IsPrimary();
219 int GetCurrentCommandID()
221 return m_CurrentCommandID;
224 void OnTick(
float deltatime,
int pCurrentCommandID, HumanMovementState movement_state)
228 m_CurrentCommandID =
m_Player.GetCurrentCommandID();
229 if (m_ActiveSymptomIndexPrimary == -1)
231 m_ActiveSymptomIndexPrimary = FindFirstAvailableSymptomIndex();
233 if (m_ActiveSymptomIndexPrimary != -1 && m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary).IsSyncToRemotes())
234 m_Player.SetActivePrimarySymptomID(m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary).GetType());
237 UpdateActiveSymptoms(deltatime);
241 if ( m_AnimMeta.IsDestroyReqested() )
251 if ( !m_AnimMeta.IsPlaying() )
254 SymptomBase symptom = m_AvailableSymptoms.Get( m_AnimMeta.m_StateType );
266 m_AnimMeta.Update(movement_state);
270 #ifdef DIAG_DEVELOPER
276 array<ref Param> secondary_debug = PrepareClientDebug(m_SymptomQueueSecondary);
278 DisplayDebug1(
"Symptoms Client", 50, primary_debug, secondary_debug);
279 DisplayDebug2(
"Symptoms Server", 300, m_SymptomQueueServerDbgPrimary, m_SymptomQueueServerDbgSecondary);
280 ShowAvailableSymptoms();
284 CleanDebug1(
"Symptoms Client", 50);
285 CleanDebug2(
"Symptoms Server", 300);
286 CleanAvailableSymptoms();
290 if (HMPRange == 1 && m_ActiveSymptomTypes.Get(SymptomIDs.SYMPTOM_HMP_SEVERE) == 0)
292 QueueUpSecondarySymptomEx(SymptomIDs.SYMPTOM_HMP_SEVERE);
294 else if (HMPRange == 0 && m_ActiveSymptomTypes.Get(SymptomIDs.SYMPTOM_HMP_SEVERE) > 0)
296 RemoveSecondarySymptom(SymptomIDs.SYMPTOM_HMP_SEVERE);
312 if (ctx.Read(state_type))
317 m_AnimMeta.Init(ctx,
this,
m_Player);
323 void UpdateActiveSymptoms(
float deltatime)
327 if ( GetCurrentPrimaryActiveSymptom() )
329 if ( !GetCurrentPrimaryActiveSymptom().IsActivated() )
331 if ( GetCurrentPrimaryActiveSymptom().
CanActivate() )
332 GetCurrentPrimaryActiveSymptom().Activate();
334 if ( GetCurrentPrimaryActiveSymptom().IsActivated() )
336 GetCurrentPrimaryActiveSymptom().Update(deltatime);
340 for (
int i = 0; i < m_SymptomQueueSecondary.Count(); i++)
342 if ( m_SymptomQueueSecondary.Get(i) && !m_SymptomQueueSecondary.Get(i).IsActivated() )
344 m_SymptomQueueSecondary.Get(i).Activate();
348 if (m_SymptomQueueSecondary.Get(i)) m_SymptomQueueSecondary.Get(i).Update(deltatime);
359 is_primary = Symptom.IsPrimary();
360 DecreaseSymptomCount(Symptom.GetType());
363 if (m_SymptomsUIDs.Contains(uid))
364 m_SymptomsUIDs.Remove(uid);
366 Debug.LogError(
"Symptom with this UID does not exist",
"PlayerSymptoms");
370 for (
int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
372 if ( m_SymptomQueuePrimary.Get(i) == Symptom )
374 m_SymptomQueuePrimary.RemoveOrdered(i);
381 for (i = 0; i < m_SymptomQueueSecondary.Count(); i++)
383 if (m_SymptomQueueSecondary.Get(i) == Symptom)
385 m_SymptomQueueSecondary.RemoveOrdered(i);
390 m_ActiveSymptomIndexPrimary = -1;
391 m_Player.SetActivePrimarySymptomID(0);
393 #ifdef DIAG_DEVELOPER
394 if (
GetGame() ) SendServerDebugToClient();
399 int GetSymptomMaxCount(
int symptom_id)
401 return m_AvailableSymptoms.Get(symptom_id).GetMaxCount();
405 int GetSymptomCount(
int symptom_id)
407 if ( m_ActiveSymptomTypes.Contains(symptom_id) )
408 return m_ActiveSymptomTypes.Get(symptom_id);
413 void IncreaseSymptomCount(
int symptom_id)
415 if ( m_ActiveSymptomTypes.Contains(symptom_id) )
417 m_ActiveSymptomTypes.Set(symptom_id, m_ActiveSymptomTypes.Get(symptom_id) + 1);
421 m_ActiveSymptomTypes.Insert(symptom_id, 1);
425 void DecreaseSymptomCount(
int symptom_id)
427 if ( m_ActiveSymptomTypes.Contains(symptom_id) )
429 if ( m_ActiveSymptomTypes.Get(symptom_id) == 1)
430 m_ActiveSymptomTypes.Remove(symptom_id);
432 m_ActiveSymptomTypes.Set(symptom_id, m_ActiveSymptomTypes.Get(symptom_id) - 1);
436 SymptomBase SpawnSymptom(
int symptom_id,
int uid = -1)
438 if (m_AvailableSymptoms.Get(symptom_id))
443 uid = CreateUniqueID();
448 if ( m_SymptomsUIDs.Contains(uid) )
449 ErrorEx(
string.Format(
"Symptoms: Unique ID (=%1) already exists!", uid));
451 m_SymptomsUIDs.Insert(uid, symptom);
452 IncreaseSymptomCount(symptom_id);
459 Error(
"Symptom not registered");
465 void CleanUpPrimaryQueue()
467 foreach (
SymptomBase symptom : m_SymptomQueuePrimary)
469 symptom.RequestDestroy();
473 SymptomBase QueueUpPrimarySymptom(
int symptom_id,
int uid = -1)
475 if ((GetSymptomCount(symptom_id) >= GetSymptomMaxCount(symptom_id)) && GetSymptomMaxCount(symptom_id) != -1)
478 SymptomBase symptom = m_AvailableSymptoms.Get(symptom_id);
479 if (
m_Player.IsUnconscious() && !symptom.AllowInUnconscious())
484 for (
int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
486 if (m_SymptomQueuePrimary.Get(i).CanBeInterupted() && ComparePriority(GetSymptomPriority(symptom_id), m_SymptomQueuePrimary.Get(i).GetPriority()) == 1)
488 symptom = SpawnSymptom(symptom_id, uid);
489 m_SymptomQueuePrimary.InsertAt(symptom,i);
499 symptom = SpawnSymptom( symptom_id, uid );
500 m_SymptomQueuePrimary.Insert(symptom);
502 #ifdef DIAG_DEVELOPER
503 SendServerDebugToClient();
508 void QueueUpSecondarySymptom(
int symptom_id,
int uid = -1)
510 QueueUpSecondarySymptomEx(symptom_id, uid);
513 SymptomBase QueueUpSecondarySymptomEx(
int symptom_id,
int uid = -1)
515 if ((GetSymptomCount(symptom_id) >= GetSymptomMaxCount(symptom_id)) && GetSymptomMaxCount(symptom_id) != -1)
518 if (m_AvailableSymptoms.Get(symptom_id).IsPrimary())
521 if (
m_Player.IsUnconscious() && !m_AvailableSymptoms.Get(symptom_id).AllowInUnconscious())
524 SymptomBase Symptom = SpawnSymptom( symptom_id, uid);
526 m_SymptomQueueSecondary.Insert(Symptom);
531 void RemoveSecondarySymptom(
int symptom_id)
533 for (
int i = 0; i < m_SymptomQueueSecondary.Count();i++)
535 if ( m_SymptomQueueSecondary.Get(i) && m_SymptomQueueSecondary.Get(i).GetType() == symptom_id )
537 m_SymptomQueueSecondary.Get(i).RequestDestroy();
547 if ( m_ActiveSymptomIndexPrimary >= 0 && m_ActiveSymptomIndexPrimary < m_SymptomQueuePrimary.Count() )
549 if ( m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary) )
return m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary);
552 if ( !
GetGame().IsDedicatedServer() )
554 if ( m_SymptomQueuePrimary.Count() > 0 )
555 return m_SymptomQueuePrimary.Get(0);
560 int FindFirstAvailableSymptomIndex()
562 for (
int i = 0; i < m_SymptomQueuePrimary.Count();i++)
564 if ( m_SymptomQueuePrimary.Get(i).CanActivate() )
572 int ComparePriority(
int prio1,
int prio2 )
578 else if ( prio2 > prio1 )
585 int GetSymptomPriority(
int symptom_id)
587 return m_AvailableSymptoms.Get(symptom_id).GetPriority();
596 bool is_primary = m_AvailableSymptoms.Get(symptom_id).IsPrimary();
598 if ( rpc_type ==
ERPCs.RPC_PLAYER_SYMPTOM_ON )
602 CleanUpPrimaryQueue();
603 QueueUpPrimarySymptom(symptom_id,uid);
607 QueueUpSecondarySymptom(symptom_id,uid);
610 else if ( rpc_type ==
ERPCs.RPC_PLAYER_SYMPTOM_OFF )
614 CleanUpPrimaryQueue();
618 RemoveSecondarySymptom( symptom_id );
627 for (
int i = 0; i < m_SymptomQueuePrimary.Count(); i++ )
629 if ( m_SymptomQueuePrimary.Get(i).IsPersistent() )
631 m_SaveQueue.Insert( m_SymptomQueuePrimary.Get(i).GetType() );
635 for ( i = 0; i < m_SymptomQueueSecondary.Count(); i++ )
637 if ( m_SymptomQueueSecondary.Get(i).IsPersistent() )
639 m_SaveQueue.Insert( m_SymptomQueueSecondary.Get(i).GetType() );
643 ctx.Write( m_SaveQueue );
650 if (ctx.Read(m_SaveQueue))
652 for (
int i = 0; i < m_SaveQueue.Count(); i++ )
654 int id = m_SaveQueue.Get(i);
656 if ( IsSymptomPrimary(
id) )
658 QueueUpPrimarySymptom(
id );
662 QueueUpSecondarySymptom(
id );
678 case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_ON:
694 case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_OFF:
701 case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG:
703 int primary_Symptoms_count;
704 int secondary_Symptoms_count;
718 m_SymptomQueueServerDbg.Clear();
719 m_SymptomQueueServerDbgPrimary.Clear();
720 m_SymptomQueueServerDbgSecondary.Clear();
722 int overall_count = primary_Symptoms_count + secondary_Symptoms_count;
723 for (
int i = 0; i < overall_count ; ++i)
727 bool is_primary = p3.param1;
731 m_SymptomQueueServerDbgPrimary.Insert(p3);
735 m_SymptomQueueServerDbgSecondary.Insert(p3);
752 void SendServerDebugToClient()
756 Param1<int> p1 =
new Param1<int>(0);
757 Param1<int> p2 =
new Param1<int>(0);
759 p1.param1 = m_SymptomQueuePrimary.Count();
760 p2.param1 = m_SymptomQueueSecondary.Count();
762 debug_list.Insert(p1);
763 debug_list.Insert(p2);
771 foreach (
SymptomBase symptom : m_SymptomQueuePrimary )
773 is_primary = symptom.IsPrimary();
774 symptom_id = symptom.GetType();
775 SYMPTOM_uid = symptom.GetUID();
778 debug_list.Insert(p);
781 foreach (
SymptomBase secSymptom : m_SymptomQueueSecondary )
783 is_primary = secSymptom.IsPrimary();
784 symptom_id = secSymptom.GetType();
785 SYMPTOM_uid = secSymptom.GetUID();
788 debug_list.Insert(p);
791 GetGame().RPC(GetPlayer(),
ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG, debug_list,
true);
794 void DebugRequestExitSymptom(
int SYMPTOM_uid)
807 for (
int i = 0; i < Symptoms.Count(); i++)
809 bool is_primary = Symptoms.Get(i).IsPrimary();
810 int symptom_id = Symptoms.Get(i).GetType();
811 int SYMPTOM_uid = Symptoms.Get(i).GetUID();
814 debug_array.Insert(p3);
824 DbgUI.BeginCleanupScope();
826 DbgUI.Text(
"Primary: ");
833 for (
int i = 0; i < Symptoms_primary.Count(); i++)
837 is_primary = p3.param1;
838 symptom_id = p3.param2;
839 SYMPTOM_uid = p3.param3;
840 SYMPTOM_name = GetSymptomName(symptom_id);
842 primary += SYMPTOM_name +
" | ";
846 DbgUI.Text(
"Secondary: ");
847 for (i = 0; i < Symptoms_secondary.Count(); i++)
851 is_primary = p3.param1;
852 symptom_id = p3.param2;
853 SYMPTOM_uid = p3.param3;
854 SYMPTOM_name = GetSymptomName(symptom_id);
855 DbgUI.Text(SYMPTOM_name);
859 DbgUI.EndCleanupScope();
867 DbgUI.BeginCleanupScope();
869 DbgUI.Text(
"Primary: ");
876 for (
int i = 0; i < Symptoms_primary.Count(); i++)
880 is_primary = p3.param1;
881 symptom_id = p3.param2;
882 SYMPTOM_uid = p3.param3;
883 SYMPTOM_name = GetSymptomName(symptom_id);
885 if (
DbgUI.Button( i.ToString() +
" " + SYMPTOM_name, 80))
887 DebugRequestExitSymptom(SYMPTOM_uid);
891 DbgUI.Text(
"Secondary: ");
892 for (i = 0; i < Symptoms_secondary.Count(); i++)
896 is_primary = p3.param1;
897 symptom_id = p3.param2;
898 SYMPTOM_uid = p3.param3;
899 SYMPTOM_name = GetSymptomName(symptom_id);
901 if (
DbgUI.Button( i.ToString() +
" " + SYMPTOM_name, 80))
903 DebugRequestExitSymptom(SYMPTOM_uid);
908 DbgUI.EndCleanupScope();
911 void ShowAvailableSymptoms()
913 DbgUI.BeginCleanupScope();
914 DbgUI.Begin(
"available Symptoms", 300, 50);
916 for (
int i = 0; i < m_AvailableSymptoms.Count(); i++)
918 SymptomBase Symptom = m_AvailableSymptoms.GetElement(i);
919 string SYMPTOM_name = Symptom.GetName();
920 int symptom_id = Symptom.GetType();
922 if (
DbgUI.Button( i.ToString() +
" " + SYMPTOM_name, 80))
924 DebugRequestActivateSymptom(symptom_id);
929 DbgUI.EndCleanupScope();
932 void CleanAvailableSymptoms()
934 DbgUI.BeginCleanupScope();
935 DbgUI.Begin(
"available Symptoms", 300, 50);
937 DbgUI.EndCleanupScope();
940 void CleanDebug1(
string name,
int y_offset)
942 DbgUI.BeginCleanupScope();
945 DbgUI.EndCleanupScope();
948 void CleanDebug2(
string name,
int y_offset)
950 DbgUI.BeginCleanupScope();
953 DbgUI.EndCleanupScope();
956 void DebugRequestActivateSymptom(
int symptom_id)