123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- class SymptomBase
- {
- const float MAX_TIME_ACTIVE_SAVEGUARD = 20;
- int m_Priority;
- SoundOnVehicle m_SoundObject;
- bool m_PlayedSound;
- bool m_IsActivated;
- PlayerBase m_Player;
- float m_ServerUpdateInterval = 1;
- float m_ServerUpdateDelta;
- bool m_IsTemplate = true;
- float m_ActivatedTime;
- int m_ID;//ID for the type of Symptom
- int m_UID;//unique ID
- bool m_IsClientOnly;
- bool m_DestroyOnAnimFinish = true;
- bool m_DestroyRequested = false;
- int m_SymptomType = -1;
- bool m_IsPersistent = false;
- SymptomManager m_Manager;
- bool m_SyncToClient = false;
- float m_Duration;
- bool m_AnimPlayRequested;
- int m_MaxCount = -1;//how many symptoms of this type can be queued up at the same time, '-1' for unlimited
- SymptomCB m_AnimCallback;
-
- ref array<Param> m_PersistentParams = new array<Param>;
-
- void SymptomBase()
- {
- }
-
- void ~SymptomBase()
- {
- }
- void Init(SymptomManager manager, PlayerBase player, int uid)
- {
- m_Manager = manager;
- m_Player = player;
- m_UID = uid;
- m_IsTemplate = false;
- OnInit();
- }
-
- int GetMaxCount()
- {
- return m_MaxCount;
- }
-
- int GetUID()
- {
- return m_UID;
- }
- void OnOwnerKilled()
- {
-
-
- }
-
- bool CanBeInterupted()
- {
- if (m_AnimPlayRequested)
- {
- //Print("--------- preventing interrupt ---------");
- return false;
- }
- return true;
- }
-
- bool IsClientOnly()
- {
- return m_IsClientOnly;
- }
-
-
- void SetDuration(float duration)
- {
- m_Duration = duration;
- }
-
- float GetDuration()
- {
- return m_Duration;
- }
-
- string GetName()
- {
- return this.ClassName();
- }
- SymptomManager GetManager()
- {
- return m_Manager;
- }
-
- int GetType()
- {
- return m_ID;
- }
-
- void SetParam(Param p)
- {
-
- }
- bool IsSyncToClient()
- {
- return m_SyncToClient;
- }
-
- //! This symptom is synchronized to remotes in a form id within symptom manager
- bool IsSyncToRemotes()
- {
- return false;
- }
- void GetPersistentParams(array<Param> params)
- {
- for (int i = 0; i < m_PersistentParams.Count(); i++)
- {
- params.Insert(m_PersistentParams.Get(i));
- }
- }
- void MakeParamObjectPersistent(Param object)
- {
- if ( !GetGame().IsServer() && !GetGame().IsMultiplayer() ) return;
-
- m_PersistentParams.Insert(object);
- }
-
- bool IsPersistent()
- {
- return m_IsPersistent;
- }
-
- bool IsPrimary()
- {
- if ( m_SymptomType == SymptomTypes.PRIMARY)
- return true;
- else return false;
- }
-
- // override this if you want the symptom to be played also while the player is unconscious
- bool AllowInUnconscious()
- {
- return false;
- }
-
- PlayerBase GetPlayer()
- {
- return m_Player;
- }
- int GetPriority()
- {
- return m_Priority;
- }
-
- bool OnConstructed(SymptomManager manager)
- {
-
- }
-
- void OnDestructed()
- {
- if ( IsActivated() ) Deactivate();
- if ( GetManager() ) m_Manager.OnSymptomExit(this, m_UID);
- }
- void Activate()
- {
- m_IsActivated = true;
- if ( GetGame() && GetGame().IsServer() )
- {
- OnGetActivatedServer(m_Player);
- if ( GetGame().IsMultiplayer() )
- {
- if ( IsSyncToClient() )
- SyncToClientActivated( GetType(), GetUID() );
- #ifdef DIAG_DEVELOPER
- GetManager().SendServerDebugToClient();
- #endif
- }
- }
- if ( !GetGame().IsDedicatedServer() )
- {
- OnGetActivatedClient(m_Player);
- }
- }
-
- void Deactivate()
- {
- if ( !GetGame() ) return;
- m_IsActivated = false;
- if ( GetGame().IsServer() )
- {
- OnGetDeactivatedServer(m_Player);
- if ( GetGame().IsMultiplayer() && IsSyncToClient() )
- {
- SyncToClientDeactivated( GetType(), GetUID() );
- }
- }
- if ( !GetGame().IsDedicatedServer() )
- {
- OnGetDeactivatedClient(m_Player);
- }
-
- }
-
- bool IsActivated()
- {
- return m_IsActivated;
- }
-
-
-
- void Update(float deltatime)
- {
- if ( GetGame().IsServer() )
- {
- m_ServerUpdateDelta += deltatime;
- if (m_ServerUpdateDelta > m_ServerUpdateInterval )
- {
- m_ActivatedTime += m_ServerUpdateDelta;
- OnUpdateServer(m_Player, m_ServerUpdateDelta);
- m_ServerUpdateDelta = 0;
- }
- }
- if ( GetGame().IsClient() )
- {
- OnUpdateClient(m_Player, deltatime);
- }
- if ( GetGame().IsServer() && !GetGame().IsMultiplayer() && !GetGame().IsMissionMainMenu() )
- {
- OnUpdateClient(m_Player, deltatime);
- }
- CheckDestroy();
- }
-
- void PlayAnimationFB(int animation, int stance_mask, float running_time = -1)
- {
- DayZPlayerSyncJunctures.SendPlayerSymptomFB(m_Player, animation, GetType() , stance_mask, running_time );
- m_AnimPlayRequested = true;
- }
-
- void PlayAnimationADD(int type)
- {
- DayZPlayerSyncJunctures.SendPlayerSymptomADD(m_Player, type, GetType());
- m_AnimPlayRequested = true;
- }
-
- void PlaySound(EPlayerSoundEventID id)
- {
- GetPlayer().RequestSoundEvent(id);
- m_PlayedSound = true;
- }
- void SyncToClientActivated( int SYMPTOM_id, int uid )
- {
- if ( !GetPlayer() ) return;
-
- CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
- CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
- GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_ON, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
- }
-
- void SyncToClientDeactivated( int SYMPTOM_id, int uid )
- {
- if ( !GetPlayer() ) return;
- CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
- CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
- GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_OFF, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
- }
- void CheckSoundFinished()
- {
- if (GetGame().IsServer())
- {
- if (m_PlayedSound && m_ActivatedTime >= m_Duration)
- RequestDestroy();
- }
- }
-
- void CheckDestroy()
- {
- CheckSoundFinished();
- if ( IsPrimary() && m_ActivatedTime > MAX_TIME_ACTIVE_SAVEGUARD)
- {
- RequestDestroy();
- }
-
- if (m_DestroyRequested)
- Destroy();
- }
-
- SmptAnimMetaBase SpawnAnimMetaObject()
- {
- return null;
- }
-
- void RequestDestroy()
- {
- m_DestroyRequested = true;
- //if(!IsActivated() ) Destroy();
- }
- void Destroy()
- {
- if (!m_IsTemplate)
- OnDestructed();
- }
-
- //!gets called upon animation Symptom exit
- void AnimationFinish()
- {
- //Print("*********** OnAnimationFinish ************");
- if ( m_DestroyOnAnimFinish ) RequestDestroy();
- OnAnimationFinish();
- }
-
- void AnimationPlayFailed()
- {
- OnAnimationPlayFailed();
- AnimationFinish();
- }
-
- void AnimationStart()
- {
- OnAnimationStart();
- }
-
- protected void OnAnimationFinish();
- protected void OnAnimationStart();
- protected void OnAnimationPlayFailed();
-
- //!this is just for the Symptom parameters set-up and is called even if the Symptom doesn't execute, don't put any gameplay code in here
- void OnInit();
-
- //!gets called every frame
- void OnUpdateServer(PlayerBase player, float deltatime);
- bool CanActivate(){return true;}//server only
- //!gets called every frame
- void OnUpdateClient(PlayerBase player, float deltatime);
- //!gets called once on an Symptom which is being activated
- void OnGetActivatedServer(PlayerBase player);
- void OnGetActivatedClient(PlayerBase player);
- //!only gets called once on an active Symptom that is being deactivated
- void OnGetDeactivatedServer(PlayerBase player);
- void OnGetDeactivatedClient(PlayerBase player);
- }
|