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();
34 void InitRefresherData()
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";
55 override int GetMeleeTargetType()
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);
179 void HandleRefreshers()
182 if (!
mission.m_ActiveRefresherLocations)
186 if ( m_RefresherActive && idx == -1 )
188 InsertRefresherPosition();
190 else if ( !m_RefresherActive && idx > -1 )
192 RemoveRefresherPosition(idx);
196 void SetRefresherActive(
bool state)
198 if ( m_RefresherActive != state )
200 m_RefresherActive = state;
208 void InsertRefresherPosition()
214 void RemoveRefresherPosition(
int idx = -2)
230 mission.m_ActiveRefresherLocations.Remove(idx);
236 super.OnVariablesSynchronized();
238 if ( m_RefresherActive != m_RefresherActiveLocal )
241 m_RefresherActiveLocal = m_RefresherActive;
247 override void OnPartBuiltServer( notnull Man player,
string part_name,
int action_id )
251 super.OnPartBuiltServer( player, part_name, action_id );
261 super.OnPartDismantledServer( player, part_name, action_id );
267 override void OnPartDestroyedServer( Man player,
string part_name,
int action_id,
bool destroyed_by_connected_part =
false )
269 super.OnPartDestroyedServer( player, part_name, action_id );
278 if ( !super.CanReceiveAttachment(attachment, slotId) )
282 if ( !
GetGame().IsDedicatedServer() )
290 construction_action_data.SetActionInitiator( NULL );
297 if ( slot_name ==
"Material_FPole_Flag" )
308 for (
int i = 0; i <
GetConstruction().GetConstructionParts().Count(); i++)
313 if (part_id == -1 || part_id > part.GetId())
316 part_id = part.GetId();
323 string cfg_path =
"cfgVehicles " +
GetType() +
" Construction " + part_lowest.GetMainPartName() +
" " + part_lowest.GetPartName() +
" Materials";
324 string material_path;
325 if (
GetGame().ConfigIsExisting(cfg_path) )
328 string child_slot_name;
329 for ( i = 0; i <
GetGame().ConfigGetChildrenCount( cfg_path ); i++ )
331 GetGame().ConfigGetChildName( cfg_path, i, child_name );
332 material_path =
"" + cfg_path +
" " + child_name +
" slot_name";
333 if (
GetGame().ConfigGetText(material_path,child_slot_name) && child_slot_name == slot_name )
350 override bool CanBeRepairedToPristine()
360 vector player_pos = player.GetPosition();
362 vector ref_dir = GetDirection();
372 vector dir_to_fence = fence_pos - player_pos;
374 float len = dir_to_fence.Length();
376 dir_to_fence.Normalize();
378 vector ref_dir_angle = ref_dir.VectorToAngles();
379 vector dir_to_fence_angle = dir_to_fence.VectorToAngles();
380 vector test_angles = dir_to_fence_angle - ref_dir_angle;
382 vector test_position = test_angles.AnglesToVector() * len;
384 if(test_position[0] < b1[0] || test_position[0] > b2[0] || test_position[2] < 0.2 || test_position[2] > 2.2 )
399 vector player_pos = player.GetPosition();
400 vector ref_dir = GetDirection();
403 vector fence_player_dir = player.GetDirection();
404 fence_player_dir.Normalize();
405 fence_player_dir[1] = 0;
410 if ( ref_dir.Length() != 0 )
412 float angle =
Math.Acos( fence_player_dir * ref_dir );
414 if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
427 vector ref_dir = GetDirection();
437 if ( ref_dir.Length() != 0 )
439 float angle =
Math.Acos( cam_dir * ref_dir );
441 if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
453 if ( MemoryPointExists( selection ) )
455 vector selection_pos = ModelToWorld( GetMemoryPointPos( selection ) );
456 float distance =
vector.Distance( selection_pos, player.GetPosition() );
457 if ( distance >= MAX_ACTION_DETECTION_DISTANCE )
488 void AnimateFlagEx(
float delta,
PlayerBase player =
null)
490 float temp =
Math.Clamp( delta,0,1 );
492 if (temp < 0.01 || temp > 0.99)
494 phase_new =
Math.Round(temp);
499 SetAnimationPhase(
"flag_mast",phase_new);
502 LogAnimateFlag(phase_new, player);
504 GetInventory().SetSlotLock(
InventorySlots.GetSlotIdFromString(
"Material_FPole_Flag"),phase_new != 1);
508 void AnimateFlag(
float delta)
510 AnimateFlagEx(delta);
513 protected void LogAnimateFlag(
float newPhase, notnull
PlayerBase player)
515 PluginAdminLog logs = PluginAdminLog.Cast(
GetPlugin(PluginAdminLog));
519 logs.TotemFlagChange(
true, player,
this);
521 else if (newPhase == 1)
524 logs.TotemFlagChange(
false, player,
this);
529 void SetRefreshTimer01(
float fraction)
531 float temp =
Math.Clamp(m_FlagRefresherMaxDuration * fraction, 0, m_FlagRefresherMaxDuration);
532 m_RefresherTimeRemaining =
Math.Round(temp);
542 void AddRefresherTime01(
float fraction)
544 float temp =
Math.Clamp(m_RefresherTimeRemaining + (fraction * m_FlagRefresherMaxDuration), 0, m_FlagRefresherMaxDuration);
545 m_RefresherTimeRemaining =
Math.Round(temp);
546 SetRefresherActive(m_RefresherTimeRemaining > 0);
550 float GetRefresherTime01()
552 return m_RefresherTimeRemaining / m_FlagRefresherMaxDuration;
555 void CheckLoadedVariables(
int max_duration)
557 if (max_duration != m_FlagRefresherMaxDuration)
559 m_RefresherTimeRemaining = m_FlagRefresherMaxDuration * m_RefresherTimeRemaining / max_duration;
581 super.OnDebugSpawn();
583 GetInventory().CreateInInventory(
"Flag_DayZ");
585 AddRefresherTime01(1);