DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
WeaponAttachMagazine.c
См. документацию.
2{
3 Magazine m_newMagazine;
5
7 {
8 m_newMagazine = NULL;
9 m_newSrc = NULL;
10 }
11
12 override void OnEntry (WeaponEventBase e)
13 {
14 if(e)
15 {
16 if (!m_newSrc.IsValid())
17 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory m_newSrc=invalid, item not in bubble?");
18
19 if (m_newMagazine && m_newSrc && m_newSrc.IsValid())
20 {
22 m_newMagazine.GetInventory().GetCurrentInventoryLocation(curr);
23
24 if (m_newSrc.GetType() == InventoryLocationType.GROUND && curr.GetType() == InventoryLocationType.ATTACHMENT && curr.GetSlot() == InventorySlots.LEFTHAND)
25 {
26 // already in LH
27 }
28 else
29 {
33 {
34 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory, ok - new magazine removed from inv (inv->LHand)"); }
35 }
36 else
37 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory, error - cannot new remove mag from inv");
38 }
39 }
40 else
41 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory, error - no magazines configured for replace (m_old=m_new=NULL)");
42 }
43 super.OnEntry(e);
44 }
45
46 override void OnAbort (WeaponEventBase e)
47 {
48 m_newMagazine = NULL;
49 m_newSrc = NULL;
50
51 super.OnAbort(e);
52 }
53
54 override void OnExit (WeaponEventBase e)
55 {
56 m_weapon.ShowMagazine();
57
58 m_newMagazine = NULL;
59 m_newSrc = NULL;
60 super.OnExit(e);
61 }
62
64 {
65 if (!super.SaveCurrentFSMState(ctx))
66 return false;
67
68 if (!ctx.Write(m_newMagazine))
69 {
70 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory.SaveCurrentFSMState: cannot write m_newMagazine for weapon=" + m_weapon);
71 return false;
72 }
73
75 {
76 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory.SaveCurrentFSMState: cannot write m_newSrc for weapon=" + m_weapon);
77 return false;
78 }
79 return true;
80 }
81
82 override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
83 {
84 if (!super.LoadCurrentFSMState(ctx, version))
85 return false;
86
87 if (!ctx.Read(m_newMagazine))
88 {
89 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory.LoadCurrentFSMState: cannot read m_newMagazine for weapon=" + m_weapon);
90 return false;
91 }
92
94 {
95 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " RemoveNewMagazineFromInventory.LoadCurrentFSMState: cannot read m_newSrc for weapon=" + m_weapon);
96 return false;
97 }
98 return true;
99 }
100};
101
102
103class RemoveNewMagazineFromInventory_OnEntryShowMag extends RemoveNewMagazineFromInventory
104{
105 override void OnEntry (WeaponEventBase e)
106 {
107 if(e)
108 m_weapon.ShowMagazine();
109 super.OnEntry(e);
110 }
111};
112
113
114class WeaponAttachMagazine extends WeaponStateBase
115{
117 int m_actionType;
118
119 ref WeaponStartAction m_start;
121 ref WeaponChamberFromAttMag_W4T m_chamber;
122 ref WeaponCharging_CK m_onCK;
124
125 void WeaponAttachMagazine (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
126 {
127 m_action = action;
128 m_actionType = actionType;
129
130 // setup nested state machine
134 m_chamber = new WeaponChamberFromAttMag_W4T(m_weapon, this);
135 m_onCK = new WeaponCharging_CK(m_weapon, this);
136
137 // events: MS, MA, BE, CK
138 WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
139 WeaponEventBase __ms_ = new WeaponEventAnimMagazineShow;
140 WeaponEventBase __so_ = new WeaponEventAnimSliderOpen;
141 WeaponEventBase __ma_ = new WeaponEventAnimMagazineAttached;
142 WeaponEventBase __ck_ = new WeaponEventAnimCocked;
143
144 m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
145
146 m_fsm.AddTransition(new WeaponTransition( m_start, __ms_, m_attach));
147 m_fsm.AddTransition(new WeaponTransition( m_start, __so_, m_eject));
148 m_fsm.AddTransition(new WeaponTransition( m_eject, __ms_, m_attach));
149 m_fsm.AddTransition(new WeaponTransition( m_attach, __ck_, m_chamber, NULL, new GuardAnd(new WeaponGuardCurrentChamberEmpty(m_weapon), new WeaponGuardHasAmmo(m_weapon)))); // when opened, there is no __be_ event
150 m_fsm.AddTransition(new WeaponTransition( m_attach, __ck_, m_onCK, NULL, new GuardAnd(new WeaponGuardCurrentChamberEmpty(m_weapon), new GuardNot(new WeaponGuardHasAmmo(m_weapon)))));
151 m_fsm.AddTransition(new WeaponTransition( m_attach, _fin_, NULL));
152 m_fsm.AddTransition(new WeaponTransition( m_chamber, _fin_, NULL));
153 m_fsm.AddTransition(new WeaponTransition( m_onCK, _fin_, NULL));
154
155 // Safety exits
156 m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
157 m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
158
159
160 m_fsm.SetInitialState(m_start);
161 }
162
163 override void OnEntry (WeaponEventBase e)
164 {
165 if (e)
166 {
167 Magazine mag = e.m_magazine;
168
170 mag.GetInventory().GetCurrentInventoryLocation(newSrc);
171
172 // move to LH
174 lhand.SetAttachment(e.m_player, mag, InventorySlots.LEFTHAND);
175 if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
176 {
177 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, ok - new magazine removed from inv (inv->LHand)"); }
178 }
179 else
180 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, error - cannot new remove mag from inv");
181
183 il.SetAttachment(m_weapon, mag, InventorySlots.MAGAZINE);
184 m_attach.m_newMagazine = mag;
185 m_attach.m_newDst = il;
186 }
187 super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
188 }
189
190 override void OnAbort (WeaponEventBase e)
191 {
192 EntityAI leftHandItem = e.m_player.GetInventory().FindAttachment(InventorySlots.LEFTHAND);
193 Magazine mag = Magazine.Cast(leftHandItem);
194
195 if(mag)
196 {
197 e.m_player.GetInventory().ClearInventoryReservationEx( mag , null );
199 e.m_player.GetInventory().FindFreeLocationFor( mag, FindInventoryLocationType.CARGO, il );
200
201 if(!il || !il.IsValid())
202 {
203 if (DayZPlayerUtils.HandleDropMagazine(e.m_player, mag))
204 {
205 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, ok - no inventory space for old magazine - dropped to ground"); }
206 }
207 else
208 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, error - cannot drop magazine from left hand after not found inventory space for old magazine");
209
210 }
211 else
212 {
214 mag.GetInventory().GetCurrentInventoryLocation(oldSrc);
215
217 {
218 if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, ok - old magazine removed from wpn (LHand->inv)"); }
219 }
220 else
221 Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponAttachMagazine, error - cannot remove old mag from wpn");
222 }
223 }
224 super.OnAbort(e);
225 }
226};
227
void wpnDebugPrint(string s)
Определения Debug.c:9
void DayZPlayerUtils()
cannot be instantiated
Определения DayZPlayerUtils.c:465
class WeaponGuardIsDestroyed extends WeaponGuardBase m_weapon
Определения Guards.c:604
void WeaponGuardHasAmmo(Weapon_Base w=NULL)
Определения Guards.c:99
FindInventoryLocationType
flags for searching locations in inventory
Определения InventoryLocation.c:17
bool OptionalLocationReadFromContext(out InventoryLocation loc, notnull ParamsReadContext ctx)
Определения InventoryLocation.c:662
InventoryLocationType
types of Inventory Location
Определения InventoryLocation.c:4
bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
Определения InventoryLocation.c:640
enum FSMTransition WeaponTransition
ref WeaponStateBase m_start
Определения WeaponChambering.c:637
class WeaponEndAction extends WeaponStartAction m_action
Определения Building.c:6
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
synchronously removes item from current inventory location and adds it to destination no anims involv...
script counterpart to engine's class Inventory
Определения Inventory.c:79
proto native bool IsValid()
verify current set inventory location
proto native void SetAttachment(notnull EntityAI parent, EntityAI e, int slotId)
sets current inventory location type to Attachment with slot id set to <slotId>
proto native int GetSlot()
returns slot id if current type is Attachment
proto native int GetType()
returns type of InventoryLocation
InventoryLocation.
Определения InventoryLocation.c:29
provides access to slot configuration
Определения InventorySlots.c:6
static bool IsWeaponLogEnable()
Определения Debug.c:718
Определения Debug.c:594
Определения ObjectTyped.c:2
override void OnEntry(WeaponEventBase e)
Определения WeaponAttachMagazine.c:105
proto bool Write(void value_out)
proto bool Read(void value_in)
shorthand
Определения BoltActionRifle_Base.c:6
Magazine m_magazine
Определения Events.c:38
DayZPlayer m_player
Определения Events.c:37
signalize mechanism manipulation
Определения Events.c:35
weapon finite state machine
void AttachNewMagazine(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
ref InventoryLocation m_newSrc
magazine that will be removed from inventory
Определения WeaponAttachMagazine.c:4
int m_actionType
action to be played
Определения RifleChambering.c:4
void WeaponStateBase(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
internal state id used for load/restore
Определения WeaponStateBase.c:17
void RemoveNewMagazineFromInventory(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
Определения WeaponAttachMagazine.c:6
void WeaponStartAction(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
specific action sub-type
Определения WeaponStartAction.c:9
ref WeaponFSM m_fsm
hierarchical parent state of this state (or null)
Определения WeaponStateBase.c:14
WeaponActions m_action
Определения RifleChambering.c:3
ref AttachNewMagazine m_attach
Определения WeaponAttachMagazine.c:120
Weapon_Base m_weapon
Определения WeaponStateBase.c:12
void WeaponAttachMagazine(Weapon_Base w=NULL, WeaponStateBase parent=NULL, WeaponActions action=WeaponActions.NONE, int actionType=-1)
Определения WeaponAttachMagazine.c:125
ref WeaponChambering_Cartridge m_chamber
Определения RifleChambering.c:9
override void OnEntry(WeaponEventBase e)
Определения WeaponAttachMagazine.c:12
ref WeaponCharging_CK m_onCK
Определения WeaponAttachMagazine.c:122
ref WeaponStateBase m_start
source of the cartridge
Определения RifleChambering.c:7
override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
Определения WeaponAttachMagazine.c:82
ref WeaponEjectCasing m_eject
Определения RifleChambering.c:8
override void OnAbort(WeaponEventBase e)
Определения WeaponAttachMagazine.c:46
Magazine m_newMagazine
magazine that will be detached
Определения WeaponAttachMagazine.c:3
void WeaponEjectCasing(Weapon_Base w=NULL, WeaponStateBase parent=NULL)
override void OnExit(WeaponEventBase e)
Определения WeaponAttachMagazine.c:54
override bool SaveCurrentFSMState(ParamsWriteContext ctx)
Определения WeaponAttachMagazine.c:63
represent weapon state base
Определения BulletHide.c:2
Serializer ParamsReadContext
Определения gameplay.c:15
Serializer ParamsWriteContext
Определения gameplay.c:16
void Error(string err)
Messagebox with error message.
Определения EnDebug.c:90
WeaponActions
actions
Определения human.c:816