Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CharacterCommandLoiter.c
Go to the documentation of this file.
1enum ELoiterCommandState // TODO: SCR_
2{
3 LOITERING = 0,
4 EXITING = 1,
5 DONE = 2
6}
7
9{
10 //------------------------------------------------------------------------------------------------
11 // constructor
12 void SCR_CharacterCommandLoiter(BaseAnimPhysComponent pAnimPhysComponent, ChimeraCharacter pCharacter, CharacterInputContext pBaseInputCtx,
13 SCR_ScriptedCharacterInputContext pScrInputCtx, SCR_ScriptedCommandsStaticTable pStaticTable, SCR_CharacterCommandHandlerComponent pScrCommandHandler,
15 {
16 m_pCharAnimComponent = CharacterAnimationComponent.Cast(pAnimPhysComponent);
17 m_pCharacter = pCharacter;
18 m_pBaseInputCtx = pBaseInputCtx;
19 m_pScrInputCtx = pScrInputCtx;
20 m_pStaticTable = pStaticTable;
21 m_pCommandHandler = pScrCommandHandler;
22 m_customAnimData = customAnimData;
23 }
24 //------------------------------------------------------------------------------------------------
29
30 //------------------------------------------------------------------------------------------------
31 override void OnActivate()
32 {
33 m_bWasTag = false;
34
35 if (m_pScrInputCtx.m_iLoiteringType < 0)
36 {
37 SetFlagFinished(true);
38 return;
39 }
40
41 if (m_customAnimData.m_GraphBindingName != string.Empty && m_customAnimData.m_GraphName != string.Empty)
42 {
43 PreAnim_SetAttachment(m_customAnimData.m_GraphBindingName, m_customAnimData.m_GraphName, m_customAnimData.m_GraphInstanceName, "MasterControl");
44 }
45
47 }
48
49 //------------------------------------------------------------------------------------------------
51 {
52 if (!m_pScrInputCtx)
53 return;
54
55 IEntity loiterEnt = m_pScrInputCtx.GetLoiterEntity();
56 if (!loiterEnt)
57 return;
58
60 if (!actMgr)
61 return;
62
63 array<BaseUserAction> actions = {};
64 actMgr.GetActionsList(actions);
65
66 foreach (BaseUserAction act : actions)
67 {
68 SCR_LoiterUserAction loiterAct = SCR_LoiterUserAction.Cast(act);
69 if (loiterAct && loiterAct.IsOccupiedBy(m_pCharacter))
70 loiterAct.ReleaseOccupant();
71 }
72 }
73
74 //------------------------------------------------------------------------------------------------
75 override void OnDeactivate()
76 {
77 // If loitering was terminated without properly releasing the ownership of the loiter action, do it now
79
80 if (m_customAnimData && m_customAnimData.m_CustomCommand != -1 && m_customAnimData.m_GraphName != string.Empty)
81 {
82 PreAnim_SetAttachment(m_customAnimData.m_GraphBindingName, string.Empty, string.Empty, string.Empty);
83 }
84 }
85
86 //------------------------------------------------------------------------------------------------
87 override void OnPossess()
88 {
89 StopLoitering(true);
90 }
91
92 //------------------------------------------------------------------------------------------------
93 override bool ShouldForceFreeLook()
94 {
95 return true;
96 }
97
98 //------------------------------------------------------------------------------------------------
99 override bool IsRootMotionControlled()
100 {
101 return m_pScrInputCtx.m_bLoiteringRootMotion;
102 }
103
104 //------------------------------------------------------------------------------------------------
105 override void PrePhysUpdate(float pDt)
106 {
107 switch (m_eState)
108 {
109 case ELoiterCommandState.LOITERING:
110 {
111 bool isTag = m_pCharAnimComponent.IsPrimaryTag(m_pStaticTable.m_IsLoiteringTag);
112 m_bWasTag = isTag || m_bWasTag;
113
114 bool cancelLoiterInputs = false;
115
116 PlayerController playerController = GetGame().GetPlayerController();
117 if (playerController && playerController.GetControlledEntity() == m_pCharacter)
118 {
119 InputManager iManager = GetGame().GetInputManager();
120 cancelLoiterInputs = iManager.GetActionValue("CharacterFire") || iManager.GetActionValue("CharacterSprint") || iManager.GetActionValue("CharacterRaiseWeapon") || iManager.GetActionValue("CharacterWeaponADS") || iManager.GetActionValue("CharacterReload");
121 }
122
123 if ((m_bWasTag && !isTag) || (cancelLoiterInputs && !m_pScrInputCtx.m_bLoiteringDisablePlayerInput))
124 {
125 m_pCommandHandler.StopLoitering(false);
126 }
127 }
128 break;
129 case ELoiterCommandState.EXITING:
130 {
131 m_pCharAnimComponent.CallCommand(m_pStaticTable.m_CommandGesture, -1, 0.0); // -1 is soft exit.
132 // @TODO(ivanickyjak) We cannot use tags on server.
133 bool isTag = m_pCharAnimComponent.IsPrimaryTag(m_pStaticTable.m_IsLoiteringTag) || m_pCharAnimComponent.IsSecondaryTag(m_pStaticTable.m_IsLoiteringTag);
134 if (!isTag)
135 {
136 FinishLoiter();
137 m_pCommandHandler.BroadCastLoiterFinish();
138 }
139 }
140 break;
141 }
142 }
143
144 //------------------------------------------------------------------------------------------------
148 {
149 TAnimGraphCommand customCommand = -1;
151 customCommand = m_customAnimData.m_CustomCommand;
152
153 switch (newState)
154 {
155 case ELoiterCommandState.LOITERING:
156 {
157 m_bWasTag = false;
158 if (customCommand != -1)
159 m_pCharAnimComponent.CallCommand4I(customCommand, 0, m_pScrInputCtx.m_iLoiteringType, 0, 0, 0.0);
160 else
161 m_pCharAnimComponent.CallCommand4I(m_pStaticTable.m_CommandGesture, 0, m_pScrInputCtx.m_iLoiteringType, 0, 0, 0.0);
162 }
163 break;
164 case ELoiterCommandState.EXITING:
165 {
166 if (customCommand == -1)
167 m_pCharAnimComponent.CallCommand(m_pStaticTable.m_CommandGesture, -1, 0.0); // -1 is soft exit.
168 }
169 break;
170 }
171
172 m_eState = newState;
173 }
174
175 //------------------------------------------------------------------------------------------------
177 void StopLoitering(bool terminateFast)
178 {
180 }
181
182 //------------------------------------------------------------------------------------------------
184 {
185 SetFlagFinished(true);
186 m_pScrInputCtx.m_iLoiteringType = -1;
187 }
188
194 protected SCR_CharacterCommandHandlerComponent m_pCommandHandler;
196
198 protected bool m_bWasTag;
199}
200
201class SCR_LoiterCustomAnimData
202{
203 const static string BINDING_NAME_NPC = "NPC";
204 TAnimGraphCommand m_CustomCommand = -1;
205 string m_GraphName = string.Empty;
206 string m_GraphInstanceName = string.Empty;
207 string m_GraphBindingName = BINDING_NAME_NPC;
208
209 const static ref SCR_LoiterCustomAnimData Default = new SCR_LoiterCustomAnimData();
210
211 //------------------------------------------------------------------------------------------------
212 void SCR_LoiterCustomAnimData()
213 {}
214
215 //------------------------------------------------------------------------------------------------
216 bool IsDefault()
217 {
218 return m_CustomCommand == -1 && m_GraphName.IsEmpty() && m_GraphInstanceName.IsEmpty() && m_GraphBindingName == BINDING_NAME_NPC;
219 }
220
221 //------------------------------------------------------------------------------------------------
222 void OnRplLoad(ScriptBitReader r)
223 {
224 int cmdInt;
225 r.ReadInt(cmdInt);
226 m_CustomCommand = cmdInt;
227 r.ReadString(m_GraphName);
228 r.ReadString(m_GraphInstanceName);
229 r.ReadString(m_GraphBindingName);
230 }
231
232 //------------------------------------------------------------------------------------------------
233 void OnRplSave(ScriptBitWriter w)
234 {
235 w.WriteInt(m_CustomCommand);
236 w.WriteString(m_GraphName);
237 w.WriteString(m_GraphInstanceName);
238 w.WriteString(m_GraphBindingName);
239 }
240
241 //------------------------------------------------------------------------------------------------
242 static bool Extract(SCR_LoiterCustomAnimData instance, ScriptCtx ctx, SSnapSerializerBase snapshot)
243 {
244 snapshot.SerializeInt(instance.m_CustomCommand);
245 snapshot.SerializeString(instance.m_GraphName);
246 snapshot.SerializeString(instance.m_GraphInstanceName);
247 snapshot.SerializeString(instance.m_GraphBindingName);
248 return true;
249 }
250
251 //------------------------------------------------------------------------------------------------
252 static bool Inject(SSnapSerializerBase snapshot, ScriptCtx ctx, SCR_LoiterCustomAnimData instance)
253 {
254 snapshot.SerializeInt(instance.m_CustomCommand);
255 snapshot.SerializeString(instance.m_GraphName);
256 snapshot.SerializeString(instance.m_GraphInstanceName);
257 snapshot.SerializeString(instance.m_GraphBindingName);
258 return true;
259 }
260
261 //------------------------------------------------------------------------------------------------
262 static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
263 {
264 snapshot.EncodeInt(packet);
265 snapshot.EncodeString(packet);
266 snapshot.EncodeString(packet);
267 snapshot.EncodeString(packet);
268 }
269
270 //------------------------------------------------------------------------------------------------
271 static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
272 {
273 snapshot.DecodeInt(packet);
274 snapshot.DecodeString(packet);
275 snapshot.DecodeString(packet);
276 snapshot.DecodeString(packet);
277 return true;
278 }
279
280 //------------------------------------------------------------------------------------------------
281 static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs , ScriptCtx ctx)
282 {
283 return lhs.CompareSnapshots(rhs, 4)
284 && lhs.CompareStringSnapshots(rhs)
285 && lhs.CompareStringSnapshots(rhs)
286 && lhs.CompareStringSnapshots(rhs);
287 }
288
289 //------------------------------------------------------------------------------------------------
290 static bool PropCompare(SCR_LoiterCustomAnimData instance, SSnapSerializerBase snapshot, ScriptCtx ctx)
291 {
292 return snapshot.CompareInt(instance.m_CustomCommand)
293 && snapshot.CompareString(instance.m_GraphName)
294 && snapshot.CompareString(instance.m_GraphInstanceName)
295 && snapshot.CompareString(instance.m_GraphBindingName);
296 }
297}
int TAnimGraphCommand
Definition ECommandIDs.c:1
ArmaReforgerScripted GetGame()
Definition game.c:1398
EAITargetClusterState m_eState
void FreeOccupiedActions()
SCR_LoiterCustomAnimData m_customAnimData
SCR_ScriptedCommandsStaticTable m_pStaticTable
SCR_ScriptedCharacterInputContext GetScriptedInputContext()
override bool ShouldForceFreeLook()
override void OnPossess()
CharacterInputContext m_pBaseInputCtx
void FinishLoiter()
override bool IsRootMotionControlled()
enum ELoiterCommandState SCR_CharacterCommandLoiter(BaseAnimPhysComponent pAnimPhysComponent, ChimeraCharacter pCharacter, CharacterInputContext pBaseInputCtx, SCR_ScriptedCharacterInputContext pScrInputCtx, SCR_ScriptedCommandsStaticTable pStaticTable, SCR_CharacterCommandHandlerComponent pScrCommandHandler, SCR_LoiterCustomAnimData customAnimData)
void SwitchState(ELoiterCommandState newState)
SCR_CharacterCommandHandlerComponent m_pCommandHandler
ChimeraCharacter m_pCharacter
CharacterAnimationComponent m_pCharAnimComponent
SCR_ScriptedCharacterInputContext m_pScrInputCtx
void StopLoitering(bool terminateFast)
override bool IsDefault()
proto native void PreAnim_SetAttachment(string bindingName, string animGraphResourceName, string animInstanceResourceName, string startingNodeName)
void PrePhysUpdate(float pDt)
void OnDeactivate()
called when command ends
proto native void SetFlagFinished(bool pFinished)
this terminates human command script and shows CommandHandler( ... pCurrentCommandFinished == true );
proto external Managed FindComponent(typename typeName)
Input management system for user interactions.