1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195 |
- // load 1 bullet
- class WeaponChambering_Start extends WeaponStartAction
- {
- override void OnEntry (WeaponEventBase e)
- {
- super.OnEntry(e);
- if (e)
- {
- m_weapon.SelectionBulletHide();
- m_weapon.ForceSyncSelectionState();
- }
- }
-
- override bool IsWaitingForActionFinish()
- {
- return true;
- }
- };
- class WeaponChambering_Base extends WeaponStateBase
- {
- float m_damage;
- string m_type;
- string m_magazineType;
- Magazine m_srcMagazine; /// source of the cartridge
-
- override bool SaveCurrentFSMState (ParamsWriteContext ctx)
- {
- if (!super.SaveCurrentFSMState(ctx))
- return false;
- if (!ctx.Write(m_damage))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_damage for weapon=" + m_weapon);
- return false;
- }
- if (!ctx.Write(m_type))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_type for weapon=" + m_weapon);
- return false;
- }
- if (!ctx.Write(m_magazineType))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_magazineType for weapon=" + m_weapon);
- return false;
- }
- if (!ctx.Write(m_srcMagazine))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_srcMagazine for weapon=" + m_weapon);
- return false;
- }
- return true;
- }
- override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
- {
- if (!super.LoadCurrentFSMState(ctx, version))
- return false;
- if (!ctx.Read(m_damage))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_damage for weapon=" + m_weapon);
- return false;
- }
- if (!ctx.Read(m_type))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_type for weapon=" + m_weapon);
- return false;
- }
- if (!ctx.Read(m_magazineType))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_magazineType for weapon=" + m_weapon);
- return false;
- }
- if (!ctx.Read(m_srcMagazine))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
- return false;
- }
- return true;
- }
- };
- class WeaponChambering_Cartridge extends WeaponChambering_Base
- {
- override bool IsWaitingForActionFinish () { return true; }
- override void OnEntry (WeaponEventBase e)
- {
- super.OnEntry(e);
- if (e)
- {
- if (m_srcMagazine)
- {
- m_magazineType = m_srcMagazine.GetType();
-
- if (m_srcMagazine.ServerAcquireCartridge(m_damage, m_type))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - cartridge acquired: dmg=" + m_damage + " type=" + m_type); }
- m_weapon.SelectionBulletShow();
- m_weapon.ShowBullet(m_weapon.GetCurrentMuzzle());
- m_weapon.EffectBulletShow( m_weapon.GetCurrentMuzzle(), m_damage, m_type);
- m_weapon.SetWeaponOpen(false);
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot take cartridge from magazine");
- }
- else
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - no magazine to load from (m_srcMagazine=NULL)");
- }
- }
- }
- override void OnAbort(WeaponEventBase e)
- {
- int mi = m_weapon.GetCurrentMuzzle();
-
- string magazineTypeName;
-
- if (m_magazineType.Length() > 0)
- magazineTypeName = m_magazineType;
- else
- magazineTypeName = m_weapon.GetChamberAmmoTypeName(mi);
-
- if ( GetGame().IsServer() )
- {
- if (DayZPlayerUtils.HandleDropCartridge(e.m_player, m_damage, m_type, magazineTypeName))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - aborting, chambering cartridge dropped to ground"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot abort removal from wpn (of old mag)");
- }
-
- m_weapon.EffectBulletHide(mi);
- m_weapon.SelectionBulletHide(); // force hide on abort
-
- m_magazineType = string.Empty;
- m_type = string.Empty;
- super.OnAbort(e);
- }
- override void OnExit (WeaponEventBase e)
- {
- int mi = m_weapon.GetCurrentMuzzle();
- //if ( m_weapon.IsChamberFiredOut(mi) )
- // m_weapon.EjectCasing(mi);
- if (m_weapon.PushCartridgeToChamber(mi, m_damage, m_type))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - loaded chamber"); }
- }
- else
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot load chamber chamber!"); }
- m_weapon.SetCharged(true);
- m_magazineType = string.Empty;
- m_type = string.Empty;
- super.OnExit(e);
- }
-
- };
- class WeaponChambering_Cartridge_ChambToMag extends WeaponChambering_Cartridge
- {
- override void OnExit (WeaponEventBase e)
- {
- float ammoDamage;
- string ammoTypeName;
- int mi = m_weapon.GetCurrentMuzzle();
- if (m_weapon.IsChamberFull(mi))
- {
- m_weapon.PopCartridgeFromChamber(mi, ammoDamage, ammoTypeName);
- if (m_weapon.PushCartridgeToInternalMagazine(mi, ammoDamage, ammoTypeName))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - loaded chamber"); }
- }
- else
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot load chamber chamber!"); }
- }
-
- m_weapon.SetWeaponOpen(false);
- super.OnExit(e);
- }
- }
- //-----------MAGNUM-----------
- class WeaponChambering_MultiMuzzleMagnum extends WeaponChambering_Cartridge
- {
- override bool IsWaitingForActionFinish () { return false; }
- override void OnEntry(WeaponEventBase e)
- {
- super.OnEntry(e);
- /*for(int i = 0; i < m_weapon.GetMuzzleCount(); i++ )
- {
- if(!m_weapon.IsChamberFull(i))
- {
- m_weapon.ShowBullet(i);
- m_weapon.EffectBulletShow(i, m_damage, m_type);
- return;
- }
- }*/
- }
-
- override void OnExit(WeaponEventBase e)
- {
- m_weapon.SelectionBulletHide();
- int muzzle = m_weapon.GetCurrentMuzzle();
-
- if (!m_weapon.IsChamberFull(muzzle))
- {
- if (m_weapon.PushCartridgeToChamber(muzzle, m_damage, m_type))
- {
- Magnum_Cylinder cylinder = Magnum_Cylinder.Cast(m_weapon.GetAttachmentByType(Magnum_Cylinder));
- if (cylinder)
- {
- string bullet = "bullet";
- string bullet_nose = "bullet_nose";
-
- if (muzzle > 0)
- {
- bullet = string.Format("bullet_" + ( muzzle + 1 ));
- bullet_nose = string.Format("bullet_nose_" + ( muzzle + 1 ));
- }
- cylinder.ShowSelection(bullet);
- cylinder.ShowSelection(bullet_nose);
- }
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_MultiMuzzleMagnum, ok - loaded chamber"); }
- }
- else
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_MultiMuzzleMagnum, error - cannot load chamber chamber!"); }
- m_type = string.Empty;
- return;
- }
- else
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_MultiMuzzleMagnum, error - cannot load chamber chamber!"); }
-
- //super.OnExit(e);
- }
- }
- //----------------------------
- class WeaponChambering_MultiMuzzle extends WeaponChambering_Cartridge
- {
- override bool IsWaitingForActionFinish () { return true; }
- override void OnEntry(WeaponEventBase e)
- {
- super.OnEntry(e);
- for(int i = 0; i < m_weapon.GetMuzzleCount(); i++ )
- {
- if(!m_weapon.IsChamberFull(i))
- {
- m_weapon.ShowBullet(i);
- m_weapon.EffectBulletShow(i, m_damage, m_type);
- return;
- }
- }
- }
-
- override void OnExit (WeaponEventBase e)
- {
- for(int i = 0; i < m_weapon.GetMuzzleCount(); i++ )
- {
- if(!m_weapon.IsChamberFull(i))
- {
- if (m_weapon.PushCartridgeToChamber(i, m_damage, m_type))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, ok - loaded chamber"); }
- }
- else
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge, error - cannot load chamber chamber!"); }
- m_type = string.Empty;
- return;
- }
- }
-
- super.OnExit(e);
- }
- }
- class WeaponChambering_MultiMuzzle_W4T extends WeaponChambering_MultiMuzzle
- {
- override bool IsWaitingForActionFinish () { return true; }
- };
- class WeaponChambering_Cartridge_InnerMag extends WeaponChambering_Base
- {
- override void OnEntry (WeaponEventBase e)
- {
- super.OnEntry(e);
- if (e)
- {
- if (m_srcMagazine)
- {
- m_magazineType = m_srcMagazine.GetType();
-
- if (m_srcMagazine.ServerAcquireCartridge(m_damage, m_type))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, ok - cartridge acquired: dmg=" + m_damage + " type=" + m_type); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, error - cannot take cartridge from magazine");
- }
- else
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, error - no magazine to load from (m_srcMagazine=NULL)");
- }
-
- m_weapon.SelectionBulletShow();
- m_weapon.EffectBulletShow(m_weapon.GetCurrentMuzzle(),m_damage,m_type);
- }
- }
- override void OnAbort(WeaponEventBase e)
- {
- int mi = m_weapon.GetCurrentMuzzle();
- string magazineTypeName;
-
- if (m_magazineType.Length() > 0)
- magazineTypeName = m_magazineType;
- else
- magazineTypeName = m_weapon.GetChamberAmmoTypeName(mi);
-
- if ( !GetGame().IsMultiplayer() || GetGame().IsServer() )
- {
- if (DayZPlayerUtils.HandleDropCartridge(e.m_player, m_damage, m_type, magazineTypeName))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, ok - aborting, chambering cartridge dropped to ground"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, error - cannot abort removal from wpn (of old mag)");
- }
- m_weapon.SelectionBulletHide(); // force hide on abort
- m_weapon.EffectBulletHide(m_weapon.GetCurrentMuzzle());
- m_magazineType = string.Empty;
- m_type = string.Empty;
- super.OnAbort(e);
- }
- override void OnExit (WeaponEventBase e)
- {
- float ammoDamage;
- string ammoTypeName;
- int mi = m_weapon.GetCurrentMuzzle();
- if (!m_weapon.IsInternalMagazineFull(mi))
- {
- if (m_weapon.PushCartridgeToInternalMagazine(mi, m_damage, m_type))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, ok - loaded chamber"); }
- }
- else
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering_Cartridge_InnerMag, error - cannot load chamber chamber!"); }
- }
- m_magazineType = string.Empty;
- super.OnExit(e);
- }
- };
- class WeaponChambering_W4T extends WeaponStateBase
- {
- override bool IsWaitingForActionFinish () { return true; }
- };
- class WeaponChambering extends WeaponStateBase
- {
- WeaponActions m_action;
- int m_actionType;
- Magazine m_srcMagazine; /// source of the cartridge
- ref InventoryLocation m_srcMagazinePrevLocation;
- ref WeaponStateBase m_start;
- ref WeaponEjectCasing m_eject;
- ref WeaponChambering_Cartridge m_chamber;
- ref WeaponChambering_W4T m_w4t;
- ref WeaponCharging_CK m_onCK;
- void WeaponChambering (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
- {
- m_action = action;
- m_actionType = actionType;
- // setup nested state machine
- m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_actionType);
- m_chamber = new WeaponChambering_Cartridge(m_weapon, this);
- m_w4t = new WeaponChambering_W4T(m_weapon, this);
- m_eject = new WeaponEjectCasing(m_weapon, this);
- m_onCK = new WeaponCharging_CK(m_weapon, this);
- // events
- WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
- WeaponEventAnimBulletInChamber __bc_ = new WeaponEventAnimBulletInChamber;
- WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
- WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
- WeaponEventAnimCocked __ck_ = new WeaponEventAnimCocked;
- m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
- m_fsm.AddTransition(new WeaponTransition(m_start , __be_, m_eject));
- m_fsm.AddTransition(new WeaponTransition(m_start , __ck_, m_onCK));
- m_fsm.AddTransition(new WeaponTransition(m_start , __bs_, m_chamber));
- m_fsm.AddTransition(new WeaponTransition(m_onCK , __be_, m_eject));
- m_fsm.AddTransition(new WeaponTransition(m_onCK , __bs_, m_chamber));
- m_fsm.AddTransition(new WeaponTransition(m_eject , __bs_, m_chamber));
- m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_w4t));
- m_fsm.AddTransition(new WeaponTransition(m_w4t , _fin_, null));
-
- // Safety exits
- m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, null));
- m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
- m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
- m_fsm.SetInitialState(m_start);
- }
- override void OnEntry (WeaponEventBase e)
- {
- if (e != NULL)
- {
- m_srcMagazine = e.m_magazine;
- if (m_srcMagazine != NULL)
- {
- InventoryLocation newSrc = new InventoryLocation;
- m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
-
- m_srcMagazinePrevLocation = newSrc;
-
- // move to LH
- InventoryLocation lhand = new InventoryLocation;
- lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
- if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from inv (inv->LHand)"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot remove ammo pile from inv");
-
- m_chamber.m_srcMagazine = m_srcMagazine;
- }
- else
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering m_srcMagazine = NULL"); }
- }
- }
- else
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString()); }
- }
- super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
- }
- override void OnAbort (WeaponEventBase e)
- {
- bool done = false;
- if (m_srcMagazine)
- {
- e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
-
- InventoryLocation leftHandIl = new InventoryLocation;
- m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
- if (leftHandIl.IsValid())
- {
- if (m_srcMagazinePrevLocation && m_srcMagazinePrevLocation.IsValid())
- {
- if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(),leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
- {
- if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort"); }
- done = true;
- }
- }
- }
- }
-
- if( !done)
- {
- InventoryLocation il = new InventoryLocation;
- e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
-
- if(!il || !il.IsValid())
- {
- if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - no inventory space for ammo pile - dropped to ground - abort"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
-
- }
- else
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from left hand (LHand->inv) - abort"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot remove ammo pile from wpn - abort");
- }
- }
- }
- }
-
- super.OnAbort(e);
- m_srcMagazine = NULL;
- m_chamber.m_srcMagazine = NULL;
- m_srcMagazinePrevLocation = NULL;
- }
- override void OnExit (WeaponEventBase e)
- {
- bool done = false;
- if (m_srcMagazine)
- {
- e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
-
- InventoryLocation leftHandIl = new InventoryLocation;
- m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
- if (leftHandIl.IsValid())
- {
- if (m_srcMagazinePrevLocation && m_srcMagazinePrevLocation.IsValid())
- {
- if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
- {
- if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit"); }
- done = true;
- }
- }
- }
- }
-
- if( !done)
- {
- InventoryLocation il = new InventoryLocation;
- e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
-
- if(!il || !il.IsValid())
- {
- if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - no inventory space for ammo pile - dropped to ground - exit"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
-
- }
- else
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, ok - ammo pile removed from left hand (LHand->inv) - exit"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering, error - cannot remove ammo pile from wpn - exit");
- }
- }
- }
- }
-
- super.OnExit(e);
- m_srcMagazine = NULL;
- m_chamber.m_srcMagazine = NULL;
- m_srcMagazinePrevLocation = NULL;
- }
- override bool SaveCurrentFSMState (ParamsWriteContext ctx)
- {
- if (!super.SaveCurrentFSMState(ctx))
- return false;
- if (!ctx.Write(m_srcMagazine))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
- return false;
- }
-
- if (!OptionalLocationWriteToContext(m_srcMagazinePrevLocation, ctx))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
- return false;
- }
- return true;
- }
- override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
- {
- if (!super.LoadCurrentFSMState(ctx, version))
- return false;
- if (!ctx.Read(m_srcMagazine))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
- return false;
- }
-
- if (!OptionalLocationReadFromContext(m_srcMagazinePrevLocation, ctx))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponChambering.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
- return false;
- }
- return true;
- }
- };
- //----------------------------------------------
- //----------------------------------------------
- //----------------------------------------------
- class WeaponEndAction extends WeaponStartAction
- {
- override bool IsWaitingForActionFinish()
- {
- return true;
- }
- }
- class ChamberMultiBullet extends WeaponStateBase
- {
- WeaponActions m_action;
- int m_startActionType;
- int m_endActionType;
- Magazine m_srcMagazine; /// source of the cartridge
- ref InventoryLocation m_srcMagazinePrevLocation;
- ref WeaponStateBase m_start;
- ref WeaponEjectCasingMultiMuzzle m_eject;
- ref WeaponChambering_Base m_chamber;
- ref WeaponChambering_Base m_chamber_end;
- ref LoopedChambering_Wait4ShowBullet2 m_w4sb2;
- ref WeaponEndAction m_endLoop;
- ref BulletShow_W4T m_showB;
- ref BulletShow2_W4T m_showB2;
- void ChamberMultiBullet (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int startActionType = -1, int endActionType = -1)
- {
- m_action = action;
- m_startActionType = startActionType;
- m_endActionType = endActionType;
- // setup nested state machine
- m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_startActionType);
- m_eject = new WeaponEjectCasingMultiMuzzle(m_weapon, this);
- m_chamber = new WeaponChambering_MultiMuzzle_W4T(m_weapon, this);
- m_chamber_end = new WeaponChambering_MultiMuzzle_W4T(m_weapon, this);
- m_w4sb2 = LoopedChambering_Wait4ShowBullet2(m_weapon, this);
- m_showB = new BulletShow_W4T(m_weapon, this);
- m_showB2= new BulletShow2_W4T(m_weapon, this);
-
- m_endLoop = new WeaponEndAction(m_weapon, this, m_action, m_endActionType); // @NOTE: termination playing action - dummy?
- // events
- WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
- WeaponEventContinuousLoadBulletStart __lS_ = new WeaponEventContinuousLoadBulletStart;
- WeaponEventContinuousLoadBulletEnd __lE_ = new WeaponEventContinuousLoadBulletEnd;
- WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
- WeaponEventAnimBulletShow2 _bs2_ = new WeaponEventAnimBulletShow2;
- WeaponEventAnimBulletHide __bh_ = new WeaponEventAnimBulletHide;
- WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
- WeaponEventAnimBulletInChamber __bc_ = new WeaponEventAnimBulletInChamber;
- m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
- m_fsm.AddTransition(new WeaponTransition(m_start , __be_, m_eject));
-
- m_fsm.AddTransition(new WeaponTransition(m_start , __bs_, m_chamber));
- m_fsm.AddTransition(new WeaponTransition(m_eject , __bs_, m_chamber));
-
- m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_w4sb2, NULL, new GuardAnd(new GuardAnd(new WeaponGuardHasAmmoInLoopedState(m_chamber), new WeaponGuardChamberMultiHasRoomBulltet(m_weapon)),new WeaponGuardWeaponManagerWantContinue())));
- m_fsm.AddTransition(new WeaponTransition(m_chamber, __bc_, m_endLoop));
- m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __bs_, m_chamber));
-
- m_fsm.AddTransition(new WeaponTransition(m_w4sb2 , _fin_, NULL));
- m_fsm.AddTransition(new WeaponTransition(m_chamber , _fin_, NULL));
- m_fsm.AddTransition(new WeaponTransition(m_endLoop , _fin_, NULL));
-
- // Safety exits
- m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
- m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
-
- m_fsm.SetInitialState(m_start);
- }
- override void OnEntry (WeaponEventBase e)
- {
- if (e != NULL)
- {
- m_srcMagazine = e.m_magazine;
- if (m_srcMagazine != NULL)
- {
- InventoryLocation newSrc = new InventoryLocation;
- m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
-
- m_srcMagazinePrevLocation = newSrc;
-
- // move to LH
- InventoryLocation lhand = new InventoryLocation;
- lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
- if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from inv (inv->LHand)"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot remove ammo pile from inv");
-
- m_chamber.m_srcMagazine = m_srcMagazine;
- }
- else
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet m_srcMagazine = NULL"); }
- }
- }
- else
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString()); }
- }
- super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
- }
- override void OnExit (WeaponEventBase e)
- {
- bool done = false;
- if (m_srcMagazine)
- {
- e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
-
- InventoryLocation leftHandIl = new InventoryLocation;
- m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
- if (leftHandIl.IsValid())
- {
- if (m_srcMagazinePrevLocation && m_srcMagazinePrevLocation.IsValid())
- {
- if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
- {
- if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit"); }
- done = true;
- }
- }
- }
- }
-
- if( !done)
- {
- InventoryLocation il = new InventoryLocation;
- e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
-
- if(!il || !il.IsValid())
- {
- if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - no inventory space for ammo pile - dropped to ground - exit"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
-
- }
- else
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from left hand (LHand->inv) - exit"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot remove ammo pile from wpn - exit");
- }
- }
- }
- }
-
- super.OnExit(e);
- m_srcMagazine = NULL;
- m_chamber.m_srcMagazine = NULL;
- m_srcMagazinePrevLocation = NULL;
- }
- override void OnAbort (WeaponEventBase e)
- {
- bool done = false;
- if (m_srcMagazine)
- {
- e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
-
- InventoryLocation leftHandIl = new InventoryLocation;
- m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
- if (leftHandIl.IsValid())
- {
- if (m_srcMagazinePrevLocation && m_srcMagazinePrevLocation.IsValid())
- {
- if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
- {
- if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort"); }
- done = true;
- }
- }
- }
- }
-
- if( !done)
- {
- InventoryLocation il = new InventoryLocation;
- e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
-
- if(!il || !il.IsValid())
- {
- if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - no inventory space for ammo pile - dropped to ground - abort"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
-
- }
- else
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, ok - ammo pile removed from left hand (LHand->inv) - abort"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet, error - cannot remove ammo pile from wpn - abort");
- }
- }
- }
- }
-
- super.OnAbort(e);
- m_srcMagazine = NULL;
- m_chamber.m_srcMagazine = NULL;
- m_srcMagazinePrevLocation = NULL;
- }
-
- override bool SaveCurrentFSMState (ParamsWriteContext ctx)
- {
- if (!super.SaveCurrentFSMState(ctx))
- return false;
- if (!ctx.Write(m_srcMagazine))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
- return false;
- }
-
- if (!OptionalLocationWriteToContext(m_srcMagazinePrevLocation, ctx))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
- return false;
- }
- return true;
- }
- override bool LoadCurrentFSMState (ParamsReadContext ctx, int version)
- {
- if (!super.LoadCurrentFSMState(ctx, version))
- return false;
- if (!ctx.Read(m_srcMagazine))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
- return false;
- }
-
- if (!OptionalLocationReadFromContext(m_srcMagazinePrevLocation, ctx))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " ChamberMultiBullet.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
- return false;
- }
- return true;
- }
- };
- //------------------------------------------------------
- //------------------ROTATE------------------------------
- //------------------------------------------------------
- class WeaponCylinderRotate extends WeaponStateBase
- {
- bool FindNextFreeMuzzle(int currentMuzzle, out int nextMuzzle)
- {
- nextMuzzle = currentMuzzle;
- int nMuzzles = m_weapon.GetMuzzleCount();
-
- for (int i = 0; i < nMuzzles; ++i)
- {
- --nextMuzzle;
- nextMuzzle = Math.WrapInt(nextMuzzle, 0, nMuzzles);
- if (m_weapon.IsChamberEmpty(nextMuzzle))
- return true;
- }
-
- return false;
- }
-
- override void OnEntry(WeaponEventBase e)
- {
- int nextMuzzle;
- if (FindNextFreeMuzzle(m_weapon.GetCurrentMuzzle(), nextMuzzle))
- {
- Magnum_Base magnum = Magnum_Base.Cast(m_weapon);
- magnum.SetCylinderRotationAnimationPhase(magnum.GetCylinderRotation(nextMuzzle));
- m_weapon.SetCurrentMuzzle(nextMuzzle);
- }
- else
- {
- Print("WTF");
- }
- super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
- }
- };
- //------------------------------------------------------
- //------------------MAGNUM------------------------------
- //------------------------------------------------------
- class WeaponMagnumChambering extends WeaponStateBase
- {
- WeaponActions m_action;
- int m_startActionType;
- int m_endActionType;
- Magazine m_srcMagazine; /// source of the cartridge
- ref InventoryLocation m_srcMagazinePrevLocation;
- ref WeaponStateBase m_start;
- ref WeaponEjectAllMuzzles m_eject;
- ref WeaponCylinderRotate m_rotate;
- ref WeaponChambering_Base m_chamber;
- ref LoopedChambering_Wait4ShowBullet2 m_w4sb2;
- ref WeaponStartAction m_endLoop;
- ref BulletHide_W4T m_hideB;
- void WeaponMagnumChambering(Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int startActionType = -1, int endActionType = -1)
- {
- m_action = action;
- m_startActionType = startActionType;
- m_endActionType = endActionType;
- // setup nested state machine
- m_start = new WeaponChambering_Start(m_weapon, this, m_action, m_startActionType);
- m_eject = new WeaponEjectAllMuzzles(m_weapon, this);
- m_rotate = new WeaponCylinderRotate(m_weapon, this);
- m_chamber = new WeaponChambering_MultiMuzzleMagnum(m_weapon, this);
- m_w4sb2 = LoopedChambering_Wait4ShowBullet2(m_weapon, this);
- m_hideB = new BulletHide_W4T(m_weapon, this);
- m_endLoop = new LoopedChambering_EndLoop(m_weapon, this, m_action, m_endActionType); // @NOTE: termination playing action - dummy?
- // events
- WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
- WeaponEventContinuousLoadBulletStart __lS_ = new WeaponEventContinuousLoadBulletStart;
- WeaponEventContinuousLoadBulletEnd __lE_ = new WeaponEventContinuousLoadBulletEnd;
- WeaponEventCylinderRotate __cr_ = new WeaponEventCylinderRotate;
- WeaponEventAnimBulletShow __bs_ = new WeaponEventAnimBulletShow;
- WeaponEventAnimBulletHide __bh_ = new WeaponEventAnimBulletHide;
- WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
- WeaponEventAnimBulletInMagazine __bM_ = new WeaponEventAnimBulletInMagazine;
- WeaponEventAnimBulletShow2 _bs2_ = new WeaponEventAnimBulletShow2;
- m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
- m_fsm.AddTransition(new WeaponTransition(m_start, __be_, m_eject));
- m_fsm.AddTransition(new WeaponTransition(m_start, __cr_, m_rotate));
-
- m_fsm.AddTransition(new WeaponTransition(m_eject, __cr_, m_rotate));
- m_fsm.AddTransition(new WeaponTransition(m_rotate, __be_, m_eject));
-
- m_fsm.AddTransition(new WeaponTransition(m_eject, __bs_, m_chamber));
- m_fsm.AddTransition(new WeaponTransition(m_rotate, __bs_, m_chamber));
-
- m_fsm.AddTransition(new WeaponTransition(m_chamber, __bM_, m_w4sb2, null, new GuardAnd(new GuardAnd(new WeaponGuardHasAmmoInLoopedState(m_chamber), new WeaponGuardChamberMultiHasRoomBulltet(m_weapon)),new WeaponGuardWeaponManagerWantContinue())));
- m_fsm.AddTransition(new WeaponTransition(m_chamber, __bM_, m_endLoop));
- //m_fsm.AddTransition(new WeaponTransition(m_rotate, __bh_, m_chamber));
- //m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __bh_, m_hideB));
- m_fsm.AddTransition(new WeaponTransition(m_w4sb2, __cr_, m_rotate));
-
- m_fsm.AddTransition(new WeaponTransition(m_endLoop, _fin_, null));
-
- // Safety exits
- m_fsm.AddTransition(new WeaponTransition(m_w4sb2, _fin_, null));
- m_fsm.AddTransition(new WeaponTransition(m_chamber, _fin_, null));
- m_fsm.AddTransition(new WeaponTransition(m_rotate, _fin_, null));
- m_fsm.AddTransition(new WeaponTransition(m_eject , _fin_, null));
- m_fsm.AddTransition(new WeaponTransition(m_start , _fin_, null));
- m_fsm.SetInitialState(m_start);
- }
- override void OnEntry(WeaponEventBase e)
- {
- if (e != NULL)
- {
-
- m_srcMagazine = e.m_magazine;
- if (m_srcMagazine != NULL)
- {
- InventoryLocation newSrc = new InventoryLocation;
- m_srcMagazine.GetInventory().GetCurrentInventoryLocation(newSrc);
-
- m_srcMagazinePrevLocation = newSrc;
-
- // move to LH
- InventoryLocation lhand = new InventoryLocation;
- lhand.SetAttachment(e.m_player, m_srcMagazine, InventorySlots.LEFTHAND);
- if (GameInventory.LocationSyncMoveEntity(newSrc, lhand))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from inv (inv->LHand)"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, error - cannot remove ammo pile from inv");
-
- m_chamber.m_srcMagazine = m_srcMagazine;
- }
- else
- {
- Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering m_srcMagazine = NULL");
- }
- }
- else
- {
- Print("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering (e=NULL), m_srcMagazine=" + m_srcMagazine.ToString());
- }
- super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
- }
-
- override void OnExit(WeaponEventBase e)
- {
- bool done = false;
- if (m_srcMagazine)
- {
- e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
-
- InventoryLocation leftHandIl = new InventoryLocation;
- m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
- if (leftHandIl.IsValid())
- {
- if (m_srcMagazinePrevLocation && m_srcMagazinePrevLocation.IsValid())
- {
- if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
- {
- if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - exit"); }
- done = true;
- }
- }
- }
- }
-
- if ( !done)
- {
- InventoryLocation il = new InventoryLocation;
- e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
-
- if (!il || !il.IsValid())
- {
- if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - no inventory space for ammo pile - dropped to ground - exit"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - exit");
-
- }
- else
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from left hand (LHand->inv) - exit"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, error - cannot remove ammo pile from wpn - exit");
- }
- }
- }
- }
-
- super.OnExit(e);
- m_srcMagazine = NULL;
- m_chamber.m_srcMagazine = NULL;
- m_srcMagazinePrevLocation = NULL;
- }
-
- override void OnAbort(WeaponEventBase e)
- {
- bool done = false;
- if (m_srcMagazine)
- {
- e.m_player.GetInventory().ClearInventoryReservationEx( m_srcMagazine , m_srcMagazinePrevLocation );
-
- InventoryLocation leftHandIl = new InventoryLocation;
- m_srcMagazine.GetInventory().GetCurrentInventoryLocation(leftHandIl);
- if (leftHandIl.IsValid())
- {
- if (m_srcMagazinePrevLocation && m_srcMagazinePrevLocation.IsValid())
- {
- if (vector.DistanceSq(m_srcMagazinePrevLocation.GetPos(), leftHandIl.GetPos()) < WeaponManager.MAX_DROP_MAGAZINE_DISTANCE_SQ)
- {
- if (GameInventory.LocationCanMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl,m_srcMagazinePrevLocation))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from left hand to previous location (LHand->inv) - abort"); }
- done = true;
- }
- }
- }
- }
-
- if ( !done)
- {
- InventoryLocation il = new InventoryLocation;
- e.m_player.GetInventory().FindFreeLocationFor( m_srcMagazine, FindInventoryLocationType.CARGO, il );
-
- if (!il || !il.IsValid())
- {
- if (DayZPlayerUtils.HandleDropMagazine(e.m_player, m_srcMagazine))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - no inventory space for ammo pile - dropped to ground - abort"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot drop ammo pile from left hand after not found inventory space for ammo pile - abort");
-
- }
- else
- {
- if (GameInventory.LocationSyncMoveEntity(leftHandIl, il))
- {
- if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering, ok - ammo pile removed from left hand (LHand->inv) - abort"); }
- }
- else
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " LoopedChambering, error - cannot remove ammo pile from wpn - abort");
- }
- }
- }
- }
-
- super.OnAbort(e);
- m_srcMagazine = NULL;
- m_chamber.m_srcMagazine = NULL;
- m_srcMagazinePrevLocation = NULL;
- }
-
- override bool SaveCurrentFSMState(ParamsWriteContext ctx)
- {
- if (!super.SaveCurrentFSMState(ctx))
- return false;
- if (!ctx.Write(m_srcMagazine))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering.SaveCurrentFSMState: cannot save m_srcMagazine for weapon=" + m_weapon);
- return false;
- }
-
- if (!OptionalLocationWriteToContext(m_srcMagazinePrevLocation, ctx))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering.SaveCurrentFSMState: cannot write m_srcMagazinePrevLocation for weapon=" + m_weapon);
- return false;
- }
-
- return true;
- }
- override bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
- {
- if (!super.LoadCurrentFSMState(ctx, version))
- return false;
- if (!ctx.Read(m_srcMagazine))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering.LoadCurrentFSMState: cannot read m_srcMagazine for weapon=" + m_weapon);
- return false;
- }
-
- if (!OptionalLocationReadFromContext(m_srcMagazinePrevLocation, ctx))
- {
- Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " WeaponMagnumChambering.LoadCurrentFSMState: cannot read m_srcMagazinePrevLocation for weapon=" + m_weapon);
- return false;
- }
- return true;
- }
- };
|