45 protected const float DEFAULT_DAMAGE_ON_SHOT = 0.05;
48 protected bool m_isJammed =
false;
49 protected bool m_LiftWeapon =
false;
52 protected bool m_Charged =
false;
53 protected bool m_WeaponOpen =
false;
57 protected int m_weaponAnimState = -1;
58 protected int m_magazineSimpleSelectionIndex = -1;
59 protected int m_weaponHideBarrelIdx = -1;
60 protected float m_DmgPerShot = 0;
68 protected float m_ChanceToJamSync = 0;
75 m_BayonetAttached =
false;
76 m_ButtstockAttached =
false;
77 m_BayonetAttachmentIdx = -1;
78 m_ButtstockAttachmentIdx = -1;
82 if (ConfigIsExisting(
"simpleHiddenSelections"))
94 for (
int i = 2;
i < 100;
i++)
106 InitWeaponLiftCheckVerticalOffset();
107 InitShoulderDistance();
108 InitDOFProperties(m_DOFProperties);
110 InitReliability(m_ChanceToJam);
128 SetWeaponOpen(!
initState.IsWeaponOpen());
129 SetGroundAnimFrameIndex(
initState.m_animState);
149 m_WeaponOpen =
value;
164 data1.SetCalcDetails(
"TWPN: " + m_ConfigWeight +
"(item weight) + " +
baseWeight +
"(contents weight)");
179 data2.AddCalcDetails(
g_Game.ConfigGetFloat(
"CfgMagazines " +
ammoTypeName +
" weight").ToString() +
"(chamber weight)");
227 int count = GetAbilityCount();
262 return CanProcessWeaponEvents() && GetCurrentState().IsWaitingForActionFinish();
267 return CanProcessWeaponEvents() && GetCurrentState().IsIdle();
276 SyncEventToRemote(
e);
281 SetNextMuzzleMode(GetCurrentMuzzle());
296 SyncEventToRemote(
e);
299 m_fsm.ProcessAbortEvent(
e,
aa);
310 m_weaponAnimState =
state;
311 SetGroundAnimFrameIndex(
state);
316 m_weaponAnimState = -1;
322 if (!
GetGame().IsDedicatedServer())
360 if (
rnd < GetSyncChanceToJam())
369 SetSimpleHiddenSelectionState(m_bulletSelectionIndex[
muzzleIndex], 1);
371 SelectionBulletShow();
377 SetSimpleHiddenSelectionState(m_bulletSelectionIndex[
muzzleIndex], 0);
379 SelectionBulletHide();
388 int level = GetHealthLevel();
390 if (
level >= 0 &&
level < m_ChanceToJam.Count())
391 return m_ChanceToJam[
level];
406 SelectionBulletShow();
411 SelectionBulletHide();
464 if (!
super.OnStoreLoad(
ctx, version))
473 Error(
"Weapon.OnStoreLoad " +
this +
" cannot read current muzzle!");
478 Error(
"Weapon.OnStoreLoad " +
this +
" trying to set muzzle index " +
current_muzzle +
" while it only has " + GetMuzzleCount() +
" muzzles!");
488 Error(
"Weapon.OnStoreLoad " +
this +
" cannot read mode count!");
497 Error(
"Weapon.OnStoreLoad " +
this +
" cannot read mode[" +
m +
"]");
502 SetCurrentMode(
m,
mode);
508 if (!
ctx.Read(m_isJammed))
510 Error(
"Weapon.OnStoreLoad cannot load jamming state");
517 if (!m_fsm.OnStoreLoad(
ctx, version))
522 SetGroundAnimFrameIndex(
wss.m_animState);
537 if (m_fsm && m_fsm.IsRunning())
539 if (m_fsm.SaveCurrentFSMState(
ctx))
544 Error(
"[wpnfsm] " +
Object.GetDebugName(
this) +
" Weapon=" +
this +
" state NOT saved.");
547 Error(
"[wpnfsm] " +
Object.GetDebugName(
this) +
" Weapon.SaveCurrentFSMState: trying to save weapon without FSM (or uninitialized weapon) this=" +
this +
" type=" +
GetType());
554 if (m_fsm.LoadCurrentFSMState(
ctx, version))
559 SyncSelectionState(
state.HasBullet(),
state.HasMagazine());
560 state.SyncAnimState();
572 Error(
"[wpnfsm] " +
Object.GetDebugName(
this) +
" Weapon=" +
this +
" did not load.");
578 Error(
"[wpnfsm] " +
Object.GetDebugName(
this) +
" Weapon.LoadCurrentFSMState: trying to load weapon without FSM (or uninitialized weapon) this=" +
this +
" type=" +
GetType());
587 int mi = GetCurrentMuzzle();
607 ctx.Write(GetCurrentMode(
m));
609 ctx.Write(m_isJammed);
612 m_fsm.OnStoreSave(
ctx);
626 return m_fsm.GetInternalStateID();
636 return m_fsm.GetCurrentStableStateID();
648 int mi = GetCurrentMuzzle();
655 ForceSyncSelectionState();
672 else if (IsChamberEmpty(
i))
675 ErrorEx(
string.Format(
"Unable to identify chamber state of muzzle %1",
i));
720 if (HasInternalMagazine(-1) && FillInnerMagazine(
magazineType, flags))
724 if (GetMagazineTypeCount(0) > 0 && SpawnAttachedMagazine(
magazineType, flags))
743 if (GetMagazineTypeCount(0) == 0)
745 ErrorEx(
string.Format(
"No 'magazines' config entry for %1.",
this));
799 if (!HasInternalMagazine(-1))
818 ammoType = GetRandomChamberableAmmoTypeName(0);
823 int ammoCount = GetInternalMagazineMaxCartridgeCount(
i);
837 ammoType = GetRandomChamberableAmmoTypeName(
i);
839 PushCartridgeToInternalMagazine(
i, 0,
ammoType);
870 if (IsChamberEmpty(
m))
904 ammoType = GetRandomChamberableAmmoTypeName(0);
909 if (!IsChamberEmpty(
i))
921 ammoType = GetRandomChamberableAmmoTypeName(
i);
954 int ac = GetInventory().AttachmentCount();
955 int sc = GetInventory().GetAttachmentSlotsCount() + GetMuzzleCount();
962 if (!m_PropertyModifierObject)
964 return m_PropertyModifierObject;
997 if (!
GetGame().IsDedicatedServer())
1006 eff.SetAutodestroy(
true);
1015 m_fsm.ValidateAndRepair();
1020 m_PropertyModifierObject =
null;
1022 ValidateAndRepair();
1029 m_PropertyModifierObject =
null;
1037 GetPropertyModifierObject().UpdateModifiers();
1044 GetPropertyModifierObject().UpdateModifiers();
1058 cm.SetMeleeBlock(
false);
1071 player.SetReturnToOptics(
false);
1079 HideWeaponBarrel(
false);
1092 if (
player.GetItemInHands() ==
this)
1112 if (GetInventory().GetCurrentInventoryLocation(
il))
1133 e.WriteToContext(
ctx);
1136 wpnDebugPrint(
"[wpnfsm] " +
Object.GetDebugName(
this) +
" send 2 remote: sending e=" +
e +
" id=" +
e.GetEventID() +
" p=" +
e.m_player +
" m=" +
e.m_magazine);
1138 p.StoreInputForRemotes(
ctx);
1166 return optic.HasWeaponIronsightsOverride();
1172 if (
GetGame().ConfigIsExisting(
"cfgWeapons " +
GetType() +
" PPDOFProperties"))
1174 GetGame().ConfigGetFloatArray(
"cfgWeapons " +
GetType() +
" PPDOFProperties", temp_array);
1182 if (
GetGame().ConfigIsExisting(
"cfgWeapons " +
GetType() +
" Reliability ChanceToJam"))
1193 if (ConfigIsExisting(
"WeaponLength"))
1195 m_WeaponLength = ConfigGetFloat(
"WeaponLength");
1198 m_WeaponLength = 0.8;
1205 if (ConfigIsExisting(
"WeaponLiftCheckVerticalOffset"))
1207 m_WeaponLiftCheckVerticalOffset = ConfigGetFloat(
"WeaponLiftCheckVerticalOffset");
1210 m_WeaponLiftCheckVerticalOffset = 0.0;
1217 if (ConfigIsExisting(
"ShoulderDistance"))
1219 m_ShoulderDistance = ConfigGetFloat(
"ShoulderDistance");
1223 m_ShoulderDistance = 0;
1229 return m_DOFProperties;
1250 m_LiftWeapon =
false;
1252 if (HasSelection(
"Usti hlavne"))
1257 Print(
"Error: No weapon owner, returning");
1279 hcw.GetBaseAimingAngleLR() +
player.GetOrientation()[0],
1280 hcw.GetBaseAimingAngleUD(),
1287 if (
player.GetInputController().CameraIsFreeLook())
1301 idx =
player.GetBoneIndexByName(
"Neck");
1330#ifdef DIAG_DEVELOPER
1379 if (m_WeaponLiftCheckVerticalOffset != 0)
1380 offset[1] =
offset[1] + m_WeaponLiftCheckVerticalOffset;
1391 distance = m_WeaponLength + GetEffectiveAttachmentLength();
1397#ifdef DIAG_DEVELOPER
1429#ifdef DIAG_DEVELOPER
1438 DbgUI.
Text(
" EntryName: " +
res.surface.GetEntryName());
1439 DbgUI.
Text(
" SurfaceType: " +
res.surface.GetSurfaceType());
1441 DbgUI.
Text(
" IsPassThrough: " +
res.surface.IsPassthrough());
1445 DbgUI.
Text(
"Intersection with no surface");
1451 if (LiftWeaponRaycastResultCheck(
res))
1471#ifdef DIAG_DEVELOPER
1551 m_LiftWeapon =
true;
1560 return res.surface.IsSolid();
1567 if (HasBayonetAttached())
1603 else if (GetInternalMagazineCartridgeCount(
muzzleIndex) > 0)
1616 for (
int mi = 0;
mi <
src.GetMuzzleCount(); ++
mi)
1618 if (!
src.IsChamberEmpty(
mi))
1621 PushCartridgeToChamber(
mi,
damage, type);
1624 for (
int ci = 0;
ci <
src.GetInternalMagazineCartridgeCount(
mi); ++
ci)
1626 if (
src.GetInternalMagazineCartridgeInfo(
mi,
ci,
damage, type))
1627 PushCartridgeToInternalMagazine(
mi,
damage, type);
1636 src.OnStoreSave(
ctx.GetWriteContext());
1644 m_BayonetAttached =
pState;
1650 return m_BayonetAttached;
1655 return m_BayonetAttachmentIdx;
1660 m_ButtstockAttached =
pState;
1661 m_ButtstockAttachmentIdx =
slot_idx;
1666 return m_ButtstockAttached;
1671 return m_ButtstockAttachmentIdx;
1676 if (!
GetGame().IsDedicatedServer())
1679 if (
optics && !
optics.AllowsDOF() && m_weaponHideBarrelIdx != -1)
1680 SetSimpleHiddenSelectionState(m_weaponHideBarrelIdx, !
state);
1686 if (m_magazineSimpleSelectionIndex > -1)
1687 SetSimpleHiddenSelectionState(m_magazineSimpleSelectionIndex, 1);
1689 SelectionMagazineShow();
1694 if (m_magazineSimpleSelectionIndex > -1)
1695 SetSimpleHiddenSelectionState(m_magazineSimpleSelectionIndex, 0);
1697 SelectionMagazineHide();
1707 super.ProcessMeleeItemDamage();
1711 attachment = GetInventory().FindAttachment(m_ButtstockAttachmentIdx);
1715 attachment = GetInventory().FindAttachment(m_BayonetAttachmentIdx);
1719 super.ProcessMeleeItemDamage();
1739 return m_BurstCount;
1763 if (!ConfigGetBool(
"isSuicideWeapon"))
1766 return super.CanBeUsedForSuicide();
1772 SpawnAmmo(
"", SAMF_DEFAULT);
eBleedingSourceType GetType()
void wpnDebugPrint(string s)
bool IsDamageDestroyed(ActionTarget target)
void AddAction(typename actionName)
const int ECE_PLACE_ON_SURFACE
WeaponEventID
identifier for events. mainly for rpc purposes
FirearmActionLoadBullet FirearmActionBase FirearmActionLoadBulletQuick()
void fsmDebugSpam(string s)
InventoryLocationType
types of Inventory Location
void IncreaseOverheating(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
bool OnStoreLoad(ParamsReadContext ctx, int version)
class JsonUndergroundAreaTriggerData GetPosition
@ AMMO_CHAMBER_RNG
Fully randomizes the ammo type instead of picking one random for all chambers (needs to have type as ...
@ CHAMBER
Chambers bullets.
@ CHAMBER_RNG_SPORADIC
Maybe chambers bullets (full random) example: 0 1 0 0 1 1.
@ MAX_CAPACITY_MAG
Instead of randomizing when type is empty, it looks for the one which has the highest capacity.
@ QUANTITY_RNG
Randomizes the quantity of the bullets in the spawned magazine.
@ CHAMBER_RNG
Maybe chambers bullets (sequential rng) example: 1 1 1 0 0 0.
@ NONE
Attached magazine will be full and no round will be chambered.
@ AMMO_MAG_RNG
Fully randomizes the ammo type instead of picking one random for the entire mag (needs to have type a...
enum FSMTransition WeaponTransition
bool IsChamberFiredOut(int idx)
bool IsChamberFull(int idx)
pair ( action, actionType )
void AbilityRecord(int a, int at)
corresponds to Human::actionTypes == CHAMBERING_ONEBULLET_CLOSED, MECHANISM_CLOSED....
int m_actionType
corresponds to Human::actions == RELOAD, MECHANISM, ...
static bool MagazineTypeToAmmoType(string magazineType, out string ammoType)
Helper method.
static float GetAmmoWeightByBulletType(string bulletType)
Super root of all classes in Enforce script.
static proto bool RaycastRVProxy(notnull RaycastRVParams in, out notnull array< ref RaycastRVResult > results, array< Object > excluded=null)
Wrapper class for managing sound through SEffectManager.
static bool IsWeaponLogEnable()
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
Serialization general interface. Serializer API works with:
override void InitStateMachine()
override void HideBullet(int muzzleIndex)
override void ShowBullet(int muzzleIndex)
override void AssembleGun()
signalize mechanism manipulation
weapon finite state machine
script counterpart to engine's class Weapon
override int GetBayonetAttachmentIdx()
override int GetButtstockAttachmentIdx()
ref array< float > GetWeaponDOF()
int GetCurrentStableStateID()
tries to return identifier of current stable state (or nearest stable state if unstable state is curr...
bool CopyWeaponStateFrom(notnull Weapon_Base src)
bool EjectCartridge(int muzzleIndex, out float ammoDamage, out string ammoTypeName)
unload bullet from chamber or internal magazine
bool IsShowingChamberedBullet()
bool JamCheck(int muzzleIndex)
void SyncEventToRemote(WeaponEventBase e)
override bool HasBayonetAttached()
void SetInitialState(WeaponStableState initState)
float m_WeaponLiftCheckVerticalOffset
void SyncSelectionState(bool has_bullet, bool has_mag)
float GetEffectiveAttachmentLength()
Returns effective length of attachments that influence total weapon length.
void EEFired(int muzzleType, int mode, string ammoType)
int GetWeaponSpecificCommand(int weaponAction, int subCommand)
bool InitWeaponLiftCheckVerticalOffset()
gets weapon vertical offset from config for weaponlift raycast
int m_BayonetAttachmentIdx
ref array< float > m_DOFProperties
bool FillInnerMagazine(string ammoType="", int flags=WeaponWithAmmoFlags.CHAMBER)
Try to fill the inner magazine.
float GetWeightSpecialized(bool forceRecalc=false)
override int GetSlotsCountCorrect()
Returns number of slots for attachments corrected for weapons.
void HideWeaponBarrel(bool state)
bool InitShoulderDistance()
gets approximate weapon distance from shoulder from config
override bool CanReleaseAttachment(EntityAI attachment)
void ShowBullet(int muzzleIndex)
bool CanProcessAction(int action, int actionType)
void HideBullet(int muzzleIndex)
array< MuzzleState > GetMuzzleStates()
Helper method for RandomizeFSMState.
void SetCharged(bool value)
bool InitDOFProperties(out array< float > temp_array)
Initializes DOF properties for weapon's ironsight/optics cameras.
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
vector m_LastLiftPosition
override void OnInventoryExit(Man player)
ref WeaponFSM m_fsm
weapon abilities
float GetSyncChanceToJam()
void SetSyncJammingChance(float jamming_chance)
override void OnDebugSpawn()
void SetWeaponAnimState(int state)
bool LiftWeaponRaycastResultCheck(notnull RaycastRVResult res)
Return whether provided material triggers weapon lift (true) or not (false).
void SetWeaponOpen(bool value)
bool HasActionAbility(int action, int actionType)
query if weapon supports action and actionType
void ForceSyncSelectionState()
bool LiftWeaponCheck(PlayerBase player)
override void AfterStoreLoad()
bool ProcessWeaponEvent(WeaponEventBase e)
weapon's fsm handling of events @NOTE: warning: ProcessWeaponEvent can be called only within DayZPlay...
AbilityRecord GetAbility(int index)
override bool CanRemoveFromHands(EntityAI parent)
bool CanProcessWeaponEvents()
override void SetButtstockAttached(bool pState, int slot_idx=-1)
Magazine SpawnAttachedMagazine(string magazineType="", int flags=WeaponWithAmmoFlags.CHAMBER)
Try to spawn and attach a magazine.
PropertyModifiers GetPropertyModifierObject()
bool SpawnAmmo(string magazineType="", int flags=WeaponWithAmmoFlags.CHAMBER)
General method trying to attch magazine, fill inner magazine and fill chamber.
WeaponStateBase GetCurrentState()
returns currently active state
void AssembleGun()
override on weapons with some assembly required
override bool CanBeUsedForSuicide()
RecoilBase SpawnRecoilObject()
bool FillChamber(string ammoType="", int flags=WeaponWithAmmoFlags.CHAMBER)
Try to fill the chamber.
override void EEItemDetached(EntityAI item, string slot_name)
bool ProcessWeaponAbortEvent(WeaponEventBase e)
ref PropertyModifiers m_PropertyModifierObject
void OnFire(int muzzle_index)
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
int m_ButtstockAttachmentIdx
override void SetActions()
void ResetWeaponAnimState()
bool LoadCurrentFSMState(ParamsReadContext ctx, int version)
bool CanEnterIronsights()
void RandomizeFSMState()
With the parameters given, selects a random suitable state for the FSM of the weapon @WARNING: Weapon...
override EntityAI ProcessMeleeItemDamage(int mode=0)
override bool OnStoreLoad(ParamsReadContext ctx, int version)
override void OnStoreSave(ParamsWriteContext ctx)
bool IsWaitingForActionFinish()
returns true if state machine started playing action/actionType and waits for finish
bool CanChamberBullet(int muzzleIndex, Magazine mag)
static Weapon_Base CreateWeaponWithAmmo(string weaponType, string magazineType="", int flags=WeaponWithAmmoFlags.CHAMBER)
Create weapon with ammo.
void SaveCurrentFSMState(ParamsWriteContext ctx)
void OnFireModeChange(int fireMode)
override bool HasButtstockAttached()
void SetJammed(bool value)
bool InitReliability(out array< float > reliability_array)
override void EEItemAttached(EntityAI item, string slot_name)
bool InitWeaponLength()
gets weapon length from config for weaponlift raycast
override void OnInventoryEnter(Man player)
override void SetBayonetAttached(bool pState, int slot_idx=-1)
attachment helpers (firearm melee)
represents weapon's stable state (i.e. the basic states that the weapon will spend the most time in)
represent weapon state base
static vector RotateAroundZeroDeg(vector vec, vector axis, float angle)
Rotate a vector around 0,0,0 by an angle in degrees.
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
static proto native vector Lerp(vector v1, vector v2, float t)
Lerp between two vectors.
override string GetDebugName()
DayZPlayerInstanceType
defined in C++
DayZPlayerConstants
defined in C++
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
proto void Print(void var)
Prints content of variable to console/log.
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)
static proto void BeginCleanupScope()
static proto native void EndCleanupScope()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
array< string > TStringArray
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto void YawPitchRollMatrix(vector ang, out vector mat[3])
Creates rotation matrix from angles.
static proto void MatrixMultiply3(vector mat0[3], vector mat1[3], out vector res[3])
Transforms rotation matrix.
static proto float Max(float x, float y)
Returns bigger of two given values.
static proto float Asin(float s)
Returns angle in radians from sinus.
static proto float Acos(float c)
Returns angle in radians from cosinus.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
static const float RAD2DEG
static const float DEG2RAD
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].