Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MineAwarenessComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/ScriptWizard", description: "")]
5
6class SCR_MineDetectionData
7{
10}
11
13{
14 protected ref set<RplId> m_aDetectedMines;
16
17 //------------------------------------------------------------------------------------------------
20 {
21 PlayerController playerController = GetGame().GetPlayerController();
22 if (!playerController)
23 return null;
24
25 return SCR_MineAwarenessComponent.Cast(playerController.FindComponent(SCR_MineAwarenessComponent));
26 }
27
28 //------------------------------------------------------------------------------------------------
32 void Detect(RplId id, bool instant = false)
33 {
34 if (instant)
35 {
36 m_aDetectedMines.Insert(id);
37 return;
38 }
39
40 // Only called for mines which are not in m_aDetectedMines
41 if (!m_mMineDetection.Contains(id))
42 m_mMineDetection.Insert(id, new SCR_MineDetectionData);
43
44 // Check if there is some start time
45 ChimeraWorld world = GetOwner().GetWorld();
46 WorldTimestamp currentTime = world.GetServerTimestamp();
47 SCR_MineDetectionData data = m_mMineDetection.Get(id);
48 if (data.m_fLastTime == 0)
49 data.m_fLastTime = currentTime;
50
51 float sinceLastTime = currentTime.DiffMilliseconds(data.m_fLastTime);
52 if (sinceLastTime < 1000)
53 data.m_fTimeElapsed += sinceLastTime;
54
55 data.m_fLastTime = currentTime;
56
57 if (data.m_fTimeElapsed > 2000)
58 {
59 m_aDetectedMines.Insert(id);
60 m_mMineDetection.Remove(id);
61 }
62 }
63
64 //------------------------------------------------------------------------------------------------
68 bool IsDetected(IEntity entity)
69 {
70 RplComponent rplComponent = RplComponent.Cast(entity.FindComponent(RplComponent));
71 if (!rplComponent)
72 return true; // visible by default when entity doesn't have any rpl component
73
74 RplId id = rplComponent.Id();
75 bool isDetected = m_aDetectedMines.Contains(id);
76
77 if (!isDetected)
78 Detect(id);
79
80 return isDetected;
81 }
82
83 //------------------------------------------------------------------------------------------------
84 override event protected void EOnInit(IEntity owner)
85 {
86 m_aDetectedMines = new set<RplId>();
87 }
88
89 //------------------------------------------------------------------------------------------------
90 override event protected void OnPostInit(IEntity owner)
91 {
93 }
94}
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Get all prefabs that have the spawner data
float m_fTimeElapsed
SCR_MineAwarenessComponentClass m_fLastTime
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
Replication item identifier.
Definition RplId.c:14
ref map< RplId, ref SCR_MineDetectionData > m_mMineDetection
static SCR_MineAwarenessComponent GetLocalInstance()
void Detect(RplId id, bool instant=false)
proto external GenericEntity GetOwner()
Get owner entity.
Definition Types.c:486
EntityEvent
Various entity events.
Definition EntityEvent.c:14