3 const float MAX_ACTION_DETECTION_ANGLE_RAD = 1.3;
4 const float MAX_ACTION_DETECTION_DISTANCE = 2.0;
6 bool m_RefresherActive;
7 bool m_RefresherActiveLocal;
8 bool m_RefresherInitialized;
9 int m_RefresherTimeRemaining;
10 int m_RefreshTimeCounter;
12 protected int m_FlagRefresherFrequency =
GameConstants.REFRESHER_FREQUENCY_DEFAULT;
13 protected int m_FlagRefresherMaxDuration =
GameConstants.REFRESHER_MAX_DURATION_DEFAULT;
17 m_RefresherActive =
false;
18 m_RefresherActiveLocal =
false;
19 m_RefresherInitialized =
false;
20 m_RefresherTimeRemaining = 0;
26 RegisterNetSyncVariableBool(
"m_RefresherActive");
31 RemoveRefresherPosition();
36 int frequency = GetCEApi().GetCEGlobalInt(
"FlagRefreshFrequency");
37 int max_duration = GetCEApi().GetCEGlobalInt(
"FlagRefreshMaxDuration");
41 m_FlagRefresherFrequency = frequency;
43 if ( max_duration > 0 )
45 m_FlagRefresherMaxDuration = max_duration;
47 m_RefresherInitialized =
true;
52 return "TerritoryFlagKit";
74 if ( MemoryPointExists(
"kit_spawn_position" ) )
77 position = GetMemoryPointPos(
"kit_spawn_position" );
79 return ModelToWorld( position );
87 if ( category_name ==
"Base" && !
HasBase() )
103 super.OnStoreSave( ctx );
105 ctx.Write( m_RefresherTimeRemaining );
106 ctx.Write( m_RefreshTimeCounter );
107 ctx.Write( m_FlagRefresherMaxDuration );
108 ctx.Write( m_RefresherActive );
113 if ( !super.OnStoreLoad( ctx, version ) )
117 int loaded_max_duration;
119 if ( !ctx.Read( m_RefresherTimeRemaining ) )
124 if ( !ctx.Read( m_RefreshTimeCounter ) )
129 if ( !ctx.Read( loaded_max_duration ) )
134 if ( version >= 118 && !ctx.Read( m_RefresherActive ) )
139 CheckLoadedVariables(loaded_max_duration);
140 AnimateFlag(1 - GetRefresherTime01());
147 super.AfterStoreLoad();
149 if (!m_RefresherInitialized && GetCEApi())
161 int time_elapsed_rounded =
Math.Round(m_ElapsedSinceLastUpdate);
163 if ( m_RefresherTimeRemaining > 0 )
165 m_RefreshTimeCounter += time_elapsed_rounded;
166 if ( m_RefreshTimeCounter >= m_FlagRefresherFrequency )
169 m_RefresherTimeRemaining =
Math.Clamp(m_RefresherTimeRemaining - m_RefreshTimeCounter,0,m_FlagRefresherMaxDuration);
170 m_RefreshTimeCounter = 0;
171 AnimateFlag( 1 - GetRefresherTime01() );
175 SetRefresherActive(m_RefresherTimeRemaining > 0);
182 if (!
mission.m_ActiveRefresherLocations)
186 if ( m_RefresherActive && idx == -1 )
188 InsertRefresherPosition();
190 else if ( !m_RefresherActive && idx > -1 )
192 RemoveRefresherPosition(idx);
198 if ( m_RefresherActive != state )
200 m_RefresherActive = state;
233 mission.m_ActiveRefresherLocations.Remove(idx);
239 super.OnVariablesSynchronized();
241 if ( m_RefresherActive != m_RefresherActiveLocal )
244 m_RefresherActiveLocal = m_RefresherActive;
254 super.OnPartBuiltServer( player, part_name, action_id );
264 super.OnPartDismantledServer( player, part_name, action_id );
270 override void OnPartDestroyedServer( Man player,
string part_name,
int action_id,
bool destroyed_by_connected_part =
false )
272 super.OnPartDestroyedServer( player, part_name, action_id );
281 super.EEItemDetached( item, slot_name );
285 float state = GetAnimationPhase(
"flag_mast");
289 SetRefreshTimer01(0);
296 if ( !super.CanReceiveAttachment(attachment, slotId) )
300 if ( !
GetGame().IsDedicatedServer() )
315 if ( slot_name ==
"Material_FPole_Flag" )
326 for (
int i = 0; i <
GetConstruction().GetConstructionParts().Count(); i++)
331 if (part_id == -1 || part_id > part.GetId())
334 part_id = part.GetId();
341 string cfg_path =
"cfgVehicles " +
GetType() +
" Construction " + part_lowest.GetMainPartName() +
" " + part_lowest.GetPartName() +
" Materials";
342 string material_path;
343 if (
GetGame().ConfigIsExisting(cfg_path) )
346 string child_slot_name;
347 for ( i = 0; i <
GetGame().ConfigGetChildrenCount( cfg_path ); i++ )
349 GetGame().ConfigGetChildName( cfg_path, i, child_name );
350 material_path =
"" + cfg_path +
" " + child_name +
" slot_name";
351 if (
GetGame().ConfigGetText(material_path,child_slot_name) && child_slot_name == slot_name )
378 vector player_pos = player.GetPosition();
380 vector ref_dir = GetDirection();
390 vector dir_to_fence = fence_pos - player_pos;
392 float len = dir_to_fence.Length();
394 dir_to_fence.Normalize();
396 vector ref_dir_angle = ref_dir.VectorToAngles();
397 vector dir_to_fence_angle = dir_to_fence.VectorToAngles();
398 vector test_angles = dir_to_fence_angle - ref_dir_angle;
400 vector test_position = test_angles.AnglesToVector() * len;
402 if(test_position[0] < b1[0] || test_position[0] > b2[0] || test_position[2] < 0.2 || test_position[2] > 2.2 )
417 vector player_pos = player.GetPosition();
418 vector ref_dir = GetDirection();
421 vector fence_player_dir = player.GetDirection();
422 fence_player_dir.Normalize();
423 fence_player_dir[1] = 0;
428 if ( ref_dir.Length() != 0 )
430 float angle =
Math.Acos( fence_player_dir * ref_dir );
432 if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
445 vector ref_dir = GetDirection();
455 if ( ref_dir.Length() != 0 )
457 float angle =
Math.Acos( cam_dir * ref_dir );
459 if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
471 if ( MemoryPointExists( selection ) )
473 vector selection_pos = ModelToWorld( GetMemoryPointPos( selection ) );
474 float distance =
vector.Distance( selection_pos, player.GetPosition() );
475 if ( distance >= MAX_ACTION_DETECTION_DISTANCE )
508 float temp =
Math.Clamp( delta,0,1 );
510 if (temp < 0.01 || temp > 0.99)
512 phase_new =
Math.Round(temp);
517 SetAnimationPhase(
"flag_mast",phase_new);
520 LogAnimateFlag(phase_new, player);
522 GetInventory().SetSlotLock(
InventorySlots.GetSlotIdFromString(
"Material_FPole_Flag"),phase_new != 1);
528 AnimateFlagEx(delta);
533 PluginAdminLog logs = PluginAdminLog.Cast(
GetPlugin(PluginAdminLog));
537 logs.TotemFlagChange(
true, player,
this);
539 else if (newPhase == 1)
542 logs.TotemFlagChange(
false, player,
this);
549 float temp =
Math.Clamp(m_FlagRefresherMaxDuration * fraction, 0, m_FlagRefresherMaxDuration);
550 m_RefresherTimeRemaining =
Math.Round(temp);
562 float temp =
Math.Clamp(m_RefresherTimeRemaining + (fraction * m_FlagRefresherMaxDuration), 0, m_FlagRefresherMaxDuration);
563 m_RefresherTimeRemaining =
Math.Round(temp);
564 SetRefresherActive(m_RefresherTimeRemaining > 0);
570 return m_RefresherTimeRemaining / m_FlagRefresherMaxDuration;
575 if (max_duration != m_FlagRefresherMaxDuration)
577 m_RefresherTimeRemaining = m_FlagRefresherMaxDuration * m_RefresherTimeRemaining / max_duration;
599 super.OnDebugSpawn();
601 GetInventory().CreateInInventory(
"Flag_DayZ");
603 AddRefresherTime01(1);
eBleedingSourceType GetType()
ActionFoldBaseBuildingObjectCB ActionContinuousBaseCB ActionFoldBaseBuildingObject()
void AddAction(typename actionName)
Construction GetConstruction()
override bool CanDisplayAttachmentCategory(string category_name)
override void OnDebugSpawn()
override bool IsPlayerInside(PlayerBase player, string selection)
override void OnVariablesSynchronized()
void SetRefreshTimer01(float fraction)
void RemoveRefresherPosition(int idx=-2)
override string GetConstructionKitType()
float GetRefresherTime01()
override void EEItemDetached(EntityAI item, string slot_name)
override bool CanPutIntoHands(EntityAI parent)
override void OnPartBuiltServer(notnull Man player, string part_name, int action_id)
override void SetActions()
void AddRefresherTime01(float fraction)
void SetRefresherActive(bool state)
override bool IsFacingCamera(string selection)
override bool IsFacingPlayer(PlayerBase player, string selection)
override void OnCEUpdate()
override void AfterStoreLoad()
override bool OnStoreLoad(ParamsReadContext ctx, int version)
void LogAnimateFlag(float newPhase, notnull PlayerBase player)
override int GetMeleeTargetType()
override bool HasProperDistance(string selection, PlayerBase player)
void HandleRefreshers()
Saves positions of active lifetime refreshers to MissionGameplay / MissionServer.
override void OnPartDestroyedServer(Man player, string part_name, int action_id, bool destroyed_by_connected_part=false)
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
void CheckLoadedVariables(int max_duration)
override void OnStoreSave(ParamsWriteContext ctx)
void InsertRefresherPosition()
override vector GetKitSpawnPosition()
override bool CanBeRepairedToPristine()
void AnimateFlagEx(float delta, PlayerBase player=null)
void AnimateFlag(float delta)
override void OnPartDismantledServer(notnull Man player, string part_name, int action_id)
void SetActionInitiator(PlayerBase action_initiator)
provides access to slot configuration
Serialization general interface. Serializer API works with:
bool IsPartConstructed(string part_name)
proto native CGame GetGame()
class JsonUndergroundAreaTriggerData GetPosition
PluginBase GetPlugin(typename plugin_type)