DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Magnum.c
Go to the documentation of this file.
1const float MAGNUM_ROTATION_POSITION_M1 = -0.167;
2const float MAGNUM_ROTATION_POSITION_0 = 0.0;
3const float MAGNUM_ROTATION_POSITION_1 = 0.167;
4const float MAGNUM_ROTATION_POSITION_2 = 0.334;
5const float MAGNUM_ROTATION_POSITION_3 = 0.500;
6const float MAGNUM_ROTATION_POSITION_4 = 0.668;
7const float MAGNUM_ROTATION_POSITION_5 = 0.835;
8const float MAGNUM_ROTATION_POSITION_6 = 1.0;
9
10
12{
13 DEFAULT = 0,
14};
15
17{
19 DEFAULT = 1,
20}
21
22class Magnum_Static_State extends WeaponStableState
23{
24 bool init = false;
25 override void OnEntry(WeaponEventBase e)
26 {
27 if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnstate] { Magnum stable state"); }
28 super.OnEntry(e);
29 if (init)
30 {
31 Magnum_Base magnum;
32 if (CastTo(magnum, m_weapon))
33 {
34 magnum.SyncCylinderRotation();
35 //magnum.SyncSelectionStateFromState();
36 }
37 }
38 init = true;
39 }
40 override void OnExit (WeaponEventBase e) { super.OnExit(e); if (LogManager.IsWeaponLogEnable()) { wpnPrint("[wpnstate] } Magnum stable state"); } }
41 override int GetCurrentStateID () { return MagnumStableStateID.DEFAULT; }
42 override bool HasBullet() { return m_weapon.IsChamberFull(m_weapon.GetCurrentMuzzle()); }
43 override bool HasMagazine() { return false; }
44 override bool IsJammed() { return m_weapon.IsJammed(); }
45 override bool IsSingleState() { return true; }
46};
47
48
49
50class Magnum_Base extends Weapon_Base
51{
55 const string ATT_SLOT_CYLINDER = "RevolverCylinder";
56 const string ATT_SLOT_EJECTOR = "RevolverEjector";
57
58 override void SetActions()
59 {
60 super.SetActions();
62
65
66 }
67
69 {
70 return new MagnumRecoil(this);
71 }
72
74 {
75 m_LastMuzzleloaded = 0;
76 m_ActiveMuzzle = 0;
77
78 /*m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionTypes.CHAMBERING_STARTLOOPABLE_CLOSED));
79 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionTypes.CHAMBERING_ENDLOOPABLE));
80 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionTypes.MECHANISM_CLOSED));
81 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionTypes.MECHANISM_SPECIAL));
82 m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionTypes.UNJAMMING_START));
83 m_abilities.Insert(new AbilityRecord(WeaponActions.UNJAMMING, WeaponActionTypes.UNJAMMING_END));
84 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionTypes.FIRE_NORMAL));
85 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionTypes.FIRE_COCKED));*/
86 }
87
88 override void InitStateMachine ()
89 {
90 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_CLOSED));
91 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_CLOSED_KEEP));
92 m_abilities.Insert(new AbilityRecord(WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE));
93 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED));
94 m_abilities.Insert(new AbilityRecord(WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_SPECIAL));
95 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL));
96 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED));
97 m_abilities.Insert(new AbilityRecord(WeaponActions.FIRE, WeaponActionFireTypes.FIRE_UNCOCKED));
98
99
100 // setup state machine
101 // basic weapon state
102 C = new Magnum_Static_State(this, NULL, MagnumAnimState.DEFAULT);
103
104
105 WeaponMagnumChambering Chamber = new WeaponMagnumChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_CLOSED_KEEP,WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE);
106 WeaponMagnumChambering Chamber_E = new WeaponMagnumChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_STARTLOOPABLE_CLOSED,WeaponActionChamberingTypes.CHAMBERING_ENDLOOPABLE);
107 //WeaponMagnumChambering Chamber_CC00 = new WeaponMagnumChambering(this, NULL, WeaponActions.CHAMBERING, WeaponActionChamberingTypes.CHAMBERING_END);
108
109 WeaponCharging Mech = new WeaponCharging(this, NULL, WeaponActions.MECHANISM, WeaponActionMechanismTypes.MECHANISM_CLOSED);
110
111 WeaponStateBase Trigger_normal = new WeaponFireMagnum(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_NORMAL);
112 WeaponStateBase Trigger_dry = new WeaponFireMagnum(this, NULL, WeaponActions.FIRE, WeaponActionFireTypes.FIRE_COCKED);
113
114 // events
115
116 WeaponEventBase __L__ = new WeaponEventLoad1Bullet;
117 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
118 WeaponEventBase _abt_ = new WeaponEventHumanCommandActionAborted;
119 WeaponEventBase __M__ = new WeaponEventMechanism;
120 WeaponEventBase __T__ = new WeaponEventTrigger;
121
122
123 WeaponEventBase _rto_ = new WeaponEventReloadTimeout;
124 WeaponEventBase _dto_ = new WeaponEventDryFireTimeout;
125
126
127 m_fsm = new WeaponFSM();
128
129
130
131 m_fsm.AddTransition(new WeaponTransition( C, __L__, Chamber, null, new WeaponGuardAnyChamberFiredOut(this))); // chamber from closed charged
132 m_fsm.AddTransition(new WeaponTransition( Chamber, _fin_, C));
133 m_fsm.AddTransition(new WeaponTransition( Chamber, _abt_, C));
134
135
136 m_fsm.AddTransition(new WeaponTransition( C, __L__, Chamber_E)); // chamber from closed charged
137 m_fsm.AddTransition(new WeaponTransition( Chamber_E, _fin_, C));
138 m_fsm.AddTransition(new WeaponTransition( Chamber_E, _abt_, C));
139
140
141 m_fsm.AddTransition(new WeaponTransition( C, __M__, Mech)); // charge from closed
142 m_fsm.AddTransition(new WeaponTransition( Mech, _fin_, C));
143 m_fsm.AddTransition(new WeaponTransition( Mech, _abt_, C));
144
145
146
147 m_fsm.AddTransition(new WeaponTransition( C, __T__, Trigger_normal, null, new GuardAnd (new WeaponGuardCurrentChamberFull(this), new GuardNot(new WeaponGuardCurrentChamberFiredOut(this))) )); // fire.cocked
148 m_fsm.AddTransition(new WeaponTransition( Trigger_normal, _fin_, C));
149 m_fsm.AddTransition(new WeaponTransition( Trigger_normal, _dto_, C));
150 m_fsm.AddTransition(new WeaponTransition( Trigger_normal, _abt_, C));
151
152 m_fsm.AddTransition(new WeaponTransition( C, __T__, Trigger_dry)); // fire.cocked
153 m_fsm.AddTransition(new WeaponTransition( Trigger_dry, _fin_, C));
154 m_fsm.AddTransition(new WeaponTransition( Trigger_dry, _dto_, C));
155 m_fsm.AddTransition(new WeaponTransition( Trigger_dry, _abt_, C));
156
157
158 SetInitialState(C);
159 SelectionBulletHide();
160 SetCurrentMuzzle(0);
161 //HideMagazine();
162 m_fsm.Start();
163 }
164
165 override bool CanChamberBullet(int muzzleIndex, Magazine mag)
166 {
167 for (int i = 0; i < GetMuzzleCount(); i++)
168 {
169 if ( CanChamberFromMag(i, mag) )
170 {
171 if (IsChamberEmpty(i))
172 return true;
173
174 if (IsChamberFiredOut(i))
175 return true;
176 }
177 }
178 return false;
179 }
180
181 override void AssembleGun()
182 {
183 super.AssembleGun();
184
185 if ( !FindAttachmentBySlotName(ATT_SLOT_EJECTOR) )
186 {
187 GetInventory().CreateAttachment("Magnum_Ejector");
188 }
189
190 if ( !FindAttachmentBySlotName(ATT_SLOT_CYLINDER) )
191 {
192 GetInventory().CreateAttachment("Magnum_Cylinder");
193 }
194
195 ForceSyncSelectionState();
196 SyncCylinderRotation();
197 }
198
199 static float GetCylinderRotation(int muzzleIndex)
200 {
201 switch (muzzleIndex)
202 {
203 case 0:
205 case 1:
207 case 2:
209 case 3:
211 case 4:
213 case 5:
215 }
216
217 ErrorEx(string.Format("Invalid muzzle index: %1", muzzleIndex));
218
220 }
221
222 void SetCylinderRotationAnimationPhase(float rot, bool reset = false)
223 {
224 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
225 Magnum_Ejector ejector = Magnum_Ejector.Cast(GetAttachmentByType(Magnum_Ejector));
226 if (cylinder && ejector)
227 {
228 float anim_phase = cylinder.GetAnimationPhase("Rotate_Cylinder");
229 if ( Math.AbsFloat(anim_phase - rot) > 0.1 )
230 {
231 if (reset)
232 {
233 cylinder.ResetAnimationPhase("Rotate_Cylinder", rot );
234 ejector.ResetAnimationPhase("Rotate_Ejector", rot );
235 }
236 else if (rot == MAGNUM_ROTATION_POSITION_0)
237 {
238 cylinder.ResetAnimationPhase("Rotate_Cylinder", MAGNUM_ROTATION_POSITION_M1 );
239 ejector.ResetAnimationPhase("Rotate_Ejector", MAGNUM_ROTATION_POSITION_M1 );
240 }
241
242 cylinder.SetAnimationPhase("Rotate_Cylinder", rot );
243 ejector.SetAnimationPhase("Rotate_Ejector", rot );
244 }
245 }
246 }
247
248 void SyncCylinderRotation(bool reset = true)
249 {
250 SetCylinderRotationAnimationPhase(GetCylinderRotation(GetCurrentMuzzle()), reset);
251 }
252
253 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
254 {
255 super.EEHealthLevelChanged(oldLevel,newLevel,zone);
256
257 if (GetGame().IsClient())
258 return;
259
260 SetAttachmentsHealth();
261 }
262
263 //sets health of cylinder and ejector objects
265 {
266 EntityAI entity;
267 ItemBase attachment;
268 for (int i = 0; i < GetInventory().AttachmentCount(); i++)
269 {
270 entity = GetInventory().GetAttachmentFromIndex(i);
271 if ( Class.CastTo(attachment,entity) )
272 {
273 attachment.SetHealth01("","Health",GetHealth01());
274 }
275 }
276 }
277
278 override void OnFire(int muzzle_index)
279 {
280 super.OnFire(muzzle_index);
281 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
282 if (cylinder)
283 {
284 string bullet_nose = "bullet_nose";
285 if (muzzle_index > 0)
286 bullet_nose = string.Format("bullet_nose_" + (muzzle_index + 1));
287 cylinder.HideSelection(bullet_nose);
288 }
289 }
290
292 {
293 return false;
294 }
295
296 override bool CanEjectBullet()
297 {
298 for (int i = 0; i < GetMuzzleCount(); i++)
299 {
300 if (IsChamberFull(i))
301 return true;
302 }
303 return false;
304 }
305
306 override void ShowBullet(int muzzleIndex)
307 {
308 super.ShowBullet(muzzleIndex);
309
310 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
311 if (cylinder)
312 {
313 string bullet = "bullet";
314 if (muzzleIndex > 0)
315 bullet = string.Format("bullet_" + (muzzleIndex + 1));
316
317 cylinder.ShowSelection(bullet);
318
319 if (!IsChamberFiredOut(muzzleIndex))
320 {
321 string bullet_nose = "bullet_nose";
322 if (muzzleIndex > 0)
323 bullet_nose = string.Format("bullet_nose_" + (muzzleIndex + 1));
324 cylinder.ShowSelection(bullet_nose);
325 }
326 }
327 }
328
329 override void HideBullet(int muzzleIndex)
330 {
331 super.HideBullet(muzzleIndex);
332
333 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
334 if (cylinder)
335 {
336 string bullet = "bullet";
337 if (muzzleIndex > 0)
338 bullet = string.Format("bullet_" + (muzzleIndex + 1));
339
340 cylinder.HideSelection(bullet);
341
342 string bullet_nose = "bullet_nose";
343 if (muzzleIndex > 0)
344 bullet_nose = string.Format("bullet_nose_" + (muzzleIndex + 1));
345 cylinder.HideSelection(bullet_nose);
346 }
347 }
348
349 //Debug menu Spawn Ground Special
350 override void OnDebugSpawn()
351 {
352 super.OnDebugSpawn();
353
354 EntityAI entity;
355 if ( Class.CastTo(entity, this) )
356 {
357 entity.SpawnEntityOnGroundPos("Ammo_357", entity.GetPosition());
358 }
359 }
360};
361
362class Magnum extends Magnum_Base
363{
364 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
365 {
366 super.GetDebugActions(outputList);
367
368 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.LIGHT_GREY));
369 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SPIN, "Spin", FadeColors.LIGHT_GREY));
370 }
371
372 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
373 {
374 if (GetGame().IsServer())
375 {
376 if (action_id == EActions.SPIN)
377 {
378 const float animPhaseOffset = 0.167;
379
380 Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(GetAttachmentByType(Magnum_Cylinder));
381 Magnum_Ejector ejector = Magnum_Ejector.Cast(GetAttachmentByType(Magnum_Ejector));
382
383 if (cylinder)
384 {
385 float animPhase = cylinder.GetAnimationPhase("Rotate_Cylinder");
386 if (animPhase + animPhaseOffset > 1.0)
387 {
388 animPhase -= 1.0;
389 cylinder.ResetAnimationPhase("Rotate_Cylinder", animPhase);
390 ejector.ResetAnimationPhase("Rotate_Ejector", animPhase);
391 }
392
393 cylinder.SetAnimationPhase("Rotate_Cylinder", animPhase);
394 ejector.ResetAnimationPhase("Rotate_Ejector", animPhase);
395 }
396 }
397 }
398
399 return super.OnAction(action_id, player, ctx);
400 }
401}
402
403class SawedoffMagnum extends Magnum_Base {};
404class Magnum_Cylinder extends DummyItem {};
405class Magnum_Ejector extends DummyItem {};
void wpnPrint(string s)
Definition Debug.c:1
Param4< int, int, string, int > TSelectableActionInfoWithColor
void AddAction(typename actionName)
void RemoveAction(typename actionName)
EActions
Definition EActions.c:2
FirearmActionLoadBullet FirearmActionBase FirearmActionLoadBulletQuick()
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
enum MagnumStableStateID init
const float MAGNUM_ROTATION_POSITION_2
Definition Magnum.c:4
const float MAGNUM_ROTATION_POSITION_1
Definition Magnum.c:3
const float MAGNUM_ROTATION_POSITION_3
Definition Magnum.c:5
const float MAGNUM_ROTATION_POSITION_4
Definition Magnum.c:6
const float MAGNUM_ROTATION_POSITION_6
Definition Magnum.c:8
MagnumStableStateID
Definition Magnum.c:17
@ UNKNOWN
Definition Magnum.c:18
@ DEFAULT
default weapon state
Definition Magnum.c:13
MagnumAnimState
Definition Magnum.c:12
const float MAGNUM_ROTATION_POSITION_M1
Definition Magnum.c:1
const float MAGNUM_ROTATION_POSITION_5
Definition Magnum.c:7
const float MAGNUM_ROTATION_POSITION_0
Definition Magnum.c:2
class SSPFireout extends WeaponStableState OnEntry
enum FSMTransition WeaponTransition
bool IsSingleState()
Special one for when the weapon only has one singular state (like Magnum)
bool IsChamberFiredOut(int idx)
bool IsChamberFull(int idx)
pair ( action, actionType )
Definition Weapon_Base.c:5
Super root of all classes in Enforce script.
Definition EnScript.c:11
static bool IsWeaponLogEnable()
Definition Debug.c:640
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition Magnum.c:372
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition Magnum.c:364
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
override void OnDebugSpawn()
Definition Magnum.c:350
int m_LastMuzzleloaded
Definition Magnum.c:53
void SetCylinderRotationAnimationPhase(float rot, bool reset=false)
Definition Magnum.c:222
override bool IsShowingChamberedBullet()
Definition Magnum.c:291
void SyncCylinderRotation(bool reset=true)
Definition Magnum.c:248
static float GetCylinderRotation(int muzzleIndex)
Definition Magnum.c:199
override void AssembleGun()
Definition Magnum.c:181
override void InitStateMachine()
Definition Magnum.c:88
ref WeaponStableState C
Definition Magnum.c:52
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition Magnum.c:253
void Magnum_Base()
Definition Magnum.c:73
void SetAttachmentsHealth()
Definition Magnum.c:264
override bool CanChamberBullet(int muzzleIndex, Magazine mag)
Definition Magnum.c:165
override void ShowBullet(int muzzleIndex)
Definition Magnum.c:306
override RecoilBase SpawnRecoilObject()
Definition Magnum.c:68
override void HideBullet(int muzzleIndex)
Definition Magnum.c:329
override bool CanEjectBullet()
Definition Magnum.c:296
int m_ActiveMuzzle
Definition Magnum.c:54
override void OnFire(int muzzle_index)
Definition Magnum.c:278
override void SetActions()
Definition Magnum.c:58
charging of weapon without ammo to be chambered
signalize mechanism manipulation
Definition Events.c:35
weapon finite state machine
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
Definition Crossbow.c:27
override int GetCurrentStateID()
Definition Crossbow.c:30
override void OnExit(WeaponEventBase e)
Definition Crossbow.c:29
override bool IsJammed()
Definition Crossbow.c:33
override bool HasBullet()
Definition Crossbow.c:31
override bool HasMagazine()
Definition Crossbow.c:32
represent weapon state base
Definition BulletHide.c:2
proto native CGame GetGame()
enum ShapeType ErrorEx
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float AbsFloat(float f)
Returns absolute value.
const int SAT_DEBUG_ACTION
Definition constants.c:408
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
WeaponActionChamberingTypes
Definition human.c:858
WeaponActions
actions
Definition human.c:798
WeaponActionFireTypes
Definition human.c:902