|
typedef ItemBase Inventory_Base; |
|
|
|
class DummyItem extends ItemBase |
|
{ |
|
override bool CanPutAsAttachment(EntityAI parent) |
|
{ |
|
return true; |
|
} |
|
}; |
|
|
|
|
|
|
|
class ItemBase extends InventoryItem |
|
{ |
|
static ref map<typename, ref TInputActionMap> m_ItemTypeActionsMap = new map<typename, ref TInputActionMap>; |
|
TInputActionMap m_InputActionMap; |
|
bool m_ActionsInitialize; |
|
|
|
static int m_DebugActionsMask; |
|
bool m_RecipesInitialized; |
|
|
|
|
|
|
|
|
|
|
|
int m_VariablesMask; |
|
|
|
|
|
float m_VarQuantity; |
|
float m_VarQuantityPrev; |
|
int m_VarQuantityInit; |
|
int m_VarQuantityMin; |
|
int m_VarQuantityMax; |
|
int m_Count; |
|
float m_VarStackMax; |
|
float m_StoreLoadedQuantity = float.LOWEST; |
|
|
|
float m_VarTemperature; |
|
float m_VarTemperatureInit; |
|
float m_VarTemperatureMin; |
|
float m_VarTemperatureMax; |
|
|
|
float m_VarWet; |
|
float m_VarWetPrev; |
|
float m_VarWetInit; |
|
float m_VarWetMin; |
|
float m_VarWetMax; |
|
|
|
int m_Cleanness; |
|
int m_CleannessInit; |
|
int m_CleannessMin; |
|
int m_CleannessMax; |
|
|
|
bool m_WantPlayImpactSound; |
|
bool m_CanPlayImpactSound = true; |
|
float m_ImpactSpeed; |
|
int m_ImpactSoundSurfaceHash; |
|
|
|
float m_HeatIsolation; |
|
float m_ItemModelLength; |
|
float m_ItemAttachOffset; |
|
int m_VarLiquidType; |
|
int m_ItemBehaviour = -1; |
|
int m_QuickBarBonus = 0; |
|
bool m_IsBeingPlaced; |
|
bool m_IsHologram; |
|
bool m_IsPlaceSound; |
|
bool m_IsDeploySound; |
|
bool m_IsTakeable; |
|
bool m_IsSoundSynchRemote; |
|
bool m_ThrowItemOnDrop; |
|
bool m_ItemBeingDroppedPhys; |
|
bool m_CanBeMovedOverride; |
|
bool m_FixDamageSystemInit = false; |
|
bool can_this_be_combined = false; |
|
bool m_CanThisBeSplit = false; |
|
bool m_IsStoreLoad = false; |
|
bool m_CanShowQuantity; |
|
bool m_HasQuantityBar; |
|
protected bool m_CanBeDigged; |
|
protected bool m_IsResultOfSplit |
|
|
|
protected EffectSound m_DeployLoopSoundEx; |
|
|
|
string m_SoundAttType; |
|
|
|
int m_ColorComponentR; |
|
int m_ColorComponentG; |
|
int m_ColorComponentB; |
|
int m_ColorComponentA; |
|
|
|
|
|
|
|
ItemBase m_LightSourceItem; |
|
|
|
ref TIntArray m_SingleUseActions; |
|
ref TIntArray m_ContinuousActions; |
|
ref TIntArray m_InteractActions; |
|
|
|
|
|
|
|
private int m_AttachedAgents; |
|
|
|
|
|
void TransferModifiers(PlayerBase reciever); |
|
|
|
|
|
|
|
ref static map<int, ref array<ref WeaponParticlesOnFire>> m_OnFireEffect; |
|
ref static map<int, ref array<ref WeaponParticlesOnBulletCasingEject>> m_OnBulletCasingEjectEffect; |
|
ref map<int, ref array<ref WeaponParticlesOnOverheating>> m_OnOverheatingEffect; |
|
ref static map<string, int> m_WeaponTypeToID; |
|
static int m_LastRegisteredWeaponID = 0; |
|
|
|
|
|
bool m_IsOverheatingEffectActive; |
|
float m_OverheatingShots; |
|
ref Timer m_CheckOverheating; |
|
int m_ShotsToStartOverheating = 0; |
|
int m_MaxOverheatingValue = 0; |
|
float m_OverheatingDecayInterval = 1; |
|
ref array <ref OverheatingParticle> m_OverheatingParticles; |
|
|
|
protected ref TStringArray m_HeadHidingSelections; |
|
protected bool m_HideSelectionsBySlot; |
|
|
|
|
|
PluginAdminLog m_AdminLog; |
|
|
|
|
|
ref Timer m_PhysDropTimer; |
|
|
|
|
|
ref array<int> m_CompatibleLocks = new array<int>; |
|
protected int m_LockType; |
|
protected ref EffectSound m_LockingSound; |
|
protected string m_LockSoundSet = ""; |
|
|
|
protected EffectSound m_SoundPlace; |
|
protected EffectSound m_SoundDeploy; |
|
protected EffectSound m_SoundDeployFinish; |
|
|
|
|
|
void ItemBase() |
|
{ |
|
SetEventMask(EntityEvent.INIT); |
|
InitItemVariables(); |
|
|
|
m_SingleUseActions = new TIntArray; |
|
m_ContinuousActions = new TIntArray; |
|
m_InteractActions = new TIntArray; |
|
|
|
if (!GetGame().IsDedicatedServer()) |
|
{ |
|
if (HasMuzzle()) |
|
{ |
|
LoadParticleConfigOnFire(GetMuzzleID()); |
|
|
|
if (m_ShotsToStartOverheating == 0) |
|
{ |
|
LoadParticleConfigOnOverheating(GetMuzzleID()); |
|
} |
|
} |
|
|
|
PreLoadSoundAttachmentType(); |
|
m_ActionsInitialize = false; |
|
} |
|
|
|
m_OldLocation = null; |
|
|
|
if (GetGame().IsServer()) |
|
{ |
|
m_AdminLog = PluginAdminLog.Cast(GetPlugin(PluginAdminLog)); |
|
} |
|
|
|
if (ConfigIsExisting("headSelectionsToHide")) |
|
{ |
|
m_HeadHidingSelections = new TStringArray; |
|
ConfigGetTextArray("headSelectionsToHide",m_HeadHidingSelections); |
|
} |
|
|
|
m_HideSelectionsBySlot = false; |
|
if (ConfigIsExisting("hideSelectionsByinventorySlot")) |
|
{ |
|
m_HideSelectionsBySlot = ConfigGetBool("hideSelectionsByinventorySlot"); |
|
} |
|
|
|
|
|
|
|
m_QuickBarBonus = Math.Max(0, ConfigGetInt("quickBarBonus")); |
|
|
|
m_IsResultOfSplit = false; |
|
} |
|
|
|
void InitItemVariables() |
|
{ |
|
m_VarQuantityInit = ConfigGetInt("varQuantityInit"); |
|
m_VarQuantity = m_VarQuantityInit; |
|
m_VarQuantityMin = ConfigGetInt("varQuantityMin"); |
|
m_VarQuantityMax = ConfigGetInt("varQuantityMax"); |
|
m_VarStackMax = ConfigGetFloat("varStackMax"); |
|
m_Count = ConfigGetInt("count"); |
|
|
|
m_CanShowQuantity = ConfigGetBool("quantityShow"); |
|
m_HasQuantityBar = ConfigGetBool("quantityBar"); |
|
|
|
m_VarTemperatureInit = ConfigGetFloat("varTemperatureInit"); |
|
m_VarTemperature = m_VarTemperatureInit; |
|
m_VarTemperatureMin = ConfigGetFloat("varTemperatureMin"); |
|
m_VarTemperatureMax = ConfigGetFloat("varTemperatureMax"); |
|
|
|
|
|
m_CleannessInit = ConfigGetInt("varCleannessInit"); |
|
m_Cleanness = m_CleannessInit; |
|
m_CleannessMin = ConfigGetInt("varCleannessMin"); |
|
m_CleannessMax = ConfigGetInt("varCleannessMax"); |
|
|
|
m_WantPlayImpactSound = false; |
|
m_ImpactSpeed = 0.0; |
|
|
|
m_VarWetInit = ConfigGetFloat("varWetInit"); |
|
m_VarWet = m_VarWetInit; |
|
m_VarWetMin = ConfigGetFloat("varWetMin"); |
|
m_VarWetMax = ConfigGetFloat("varWetMax"); |
|
|
|
m_VarLiquidType = GetLiquidTypeInit(); |
|
m_IsBeingPlaced = false; |
|
m_IsHologram = false; |
|
m_IsPlaceSound = false; |
|
m_IsDeploySound = false; |
|
m_IsTakeable = true; |
|
m_IsSoundSynchRemote = false; |
|
m_CanBeMovedOverride = false; |
|
m_HeatIsolation = GetHeatIsolationInit(); |
|
m_ItemModelLength = GetItemModelLength(); |
|
m_ItemAttachOffset = GetItemAttachOffset(); |
|
m_CanBeDigged = ConfigGetBool("canBeDigged"); |
|
|
|
ConfigGetIntArray("compatibleLocks", m_CompatibleLocks); |
|
m_LockType = ConfigGetInt("lockType"); |
|
|
|
|
|
if (ConfigIsExisting("canBeSplit")) |
|
{ |
|
can_this_be_combined = ConfigGetBool("canBeSplit"); |
|
m_CanThisBeSplit = can_this_be_combined; |
|
} |
|
|
|
if (ConfigIsExisting("itemBehaviour")) |
|
m_ItemBehaviour = ConfigGetInt("itemBehaviour"); |
|
|
|
|
|
if (HasQuantity()) RegisterNetSyncVariableFloat("m_VarQuantity", GetQuantityMin(), m_VarQuantityMax); |
|
RegisterNetSyncVariableFloat("m_VarTemperature", GetTemperatureMin(),GetTemperatureMax()); |
|
RegisterNetSyncVariableFloat("m_VarWet", GetWetMin(), GetWetMax(), 2); |
|
RegisterNetSyncVariableInt("m_VarLiquidType"); |
|
RegisterNetSyncVariableInt("m_Cleanness",0,1); |
|
|
|
RegisterNetSyncVariableBoolSignal("m_WantPlayImpactSound"); |
|
RegisterNetSyncVariableFloat("m_ImpactSpeed"); |
|
RegisterNetSyncVariableInt("m_ImpactSoundSurfaceHash"); |
|
|
|
RegisterNetSyncVariableInt("m_ColorComponentR", 0, 255); |
|
RegisterNetSyncVariableInt("m_ColorComponentG", 0, 255); |
|
RegisterNetSyncVariableInt("m_ColorComponentB", 0, 255); |
|
RegisterNetSyncVariableInt("m_ColorComponentA", 0, 255); |
|
|
|
RegisterNetSyncVariableBool("m_IsBeingPlaced"); |
|
RegisterNetSyncVariableBool("m_IsTakeable"); |
|
RegisterNetSyncVariableBool("m_IsHologram"); |
|
|
|
if (UsesGlobalDeploy()) |
|
{ |
|
RegisterNetSyncVariableBool("m_IsSoundSynchRemote"); |
|
RegisterNetSyncVariableBool("m_IsDeploySound"); |
|
} |
|
|
|
m_LockSoundSet = ConfigGetString("lockSoundSet"); |
|
} |
|
|
|
|
|
protected bool UsesGlobalDeploy() |
|
{ |
|
return false; |
|
} |
|
|
|
override int GetQuickBarBonus() |
|
{ |
|
return m_QuickBarBonus; |
|
} |
|
|
|
void InitializeActions() |
|
{ |
|
m_InputActionMap = m_ItemTypeActionsMap.Get(this.Type()); |
|
if (!m_InputActionMap) |
|
{ |
|
TInputActionMap iam = new TInputActionMap; |
|
m_InputActionMap = iam; |
|
SetActions(); |
|
m_ItemTypeActionsMap.Insert(this.Type(), m_InputActionMap); |
|
} |
|
} |
|
|
|
override void GetActions(typename action_input_type, out array<ActionBase_Basic> actions) |
|
{ |
|
if (!m_ActionsInitialize) |
|
{ |
|
m_ActionsInitialize = true; |
|
InitializeActions(); |
|
} |
|
|
|
actions = m_InputActionMap.Get(action_input_type); |
|
} |
|
|
|
void SetActions() |
|
{ |
|
AddAction(ActionTakeItem); |
|
AddAction(ActionTakeItemToHands); |
|
AddAction(ActionWorldCraft); |
|
AddAction(ActionDropItem); |
|
AddAction(ActionAttachWithSwitch); |
|
} |
|
|
|
void AddAction(typename actionName) |
|
{ |
|
ActionBase action = ActionManagerBase.GetAction(actionName); |
|
|
|
if (!action) |
|
{ |
|
Debug.LogError("Action " + actionName + " dosn't exist!"); |
|
return; |
|
} |
|
|
|
typename ai = action.GetInputType(); |
|
if (!ai) |
|
{ |
|
m_ActionsInitialize = false; |
|
return; |
|
} |
|
|
|
array<ActionBase_Basic> action_array = m_InputActionMap.Get(ai); |
|
if (!action_array) |
|
{ |
|
action_array = new array<ActionBase_Basic>; |
|
m_InputActionMap.Insert(ai, action_array); |
|
} |
|
if (LogManager.IsActionLogEnable()) |
|
{ |
|
Debug.ActionLog(action.ToString() + " -> " + ai, this.ToString() , "n/a", "Add action"); |
|
} |
|
|
|
if (action_array.Find(action) != -1) |
|
{ |
|
Debug.Log("Action " + action.Type() + " already added to " + this + ", skipping!"); |
|
} |
|
else |
|
{ |
|
action_array.Insert(action); |
|
} |
|
} |
|
|
|
void RemoveAction(typename actionName) |
|
{ |
|
PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer()); |
|
ActionBase action = player.GetActionManager().GetAction(actionName); |
|
typename ai = action.GetInputType(); |
|
array<ActionBase_Basic> action_array = m_InputActionMap.Get(ai); |
|
|
|
if (action_array) |
|
{ |
|
action_array.RemoveItem(action); |
|
} |
|
} |
|
|
|
void OnItemInHandsPlayerSwimStart(PlayerBase player); |
|
|
|
ScriptedLightBase GetLight(); |
|
|
|
|
|
void LoadParticleConfigOnFire(int id) |
|
{ |
|
if (!m_OnFireEffect) |
|
m_OnFireEffect = new map<int, ref array<ref WeaponParticlesOnFire>>; |
|
|
|
if (!m_OnBulletCasingEjectEffect) |
|
m_OnBulletCasingEjectEffect = new map<int, ref array<ref WeaponParticlesOnBulletCasingEject>>; |
|
|
|
string config_to_search = "CfgVehicles"; |
|
string muzzle_owner_config; |
|
|
|
if (!m_OnFireEffect.Contains(id)) |
|
{ |
|
if (IsInherited(Weapon)) |
|
config_to_search = "CfgWeapons"; |
|
|
|
muzzle_owner_config = config_to_search + " " + GetType() + " "; |
|
|
|
string config_OnFire_class = muzzle_owner_config + "Particles " + "OnFire "; |
|
|
|
int config_OnFire_subclass_count = GetGame().ConfigGetChildrenCount(config_OnFire_class); |
|
|
|
if (config_OnFire_subclass_count > 0) |
|
{ |
|
array<ref WeaponParticlesOnFire> WPOF_array = new array<ref WeaponParticlesOnFire>; |
|
|
|
for (int i = 0; i < config_OnFire_subclass_count; i++) |
|
{ |
|
string particle_class = ""; |
|
GetGame().ConfigGetChildName(config_OnFire_class, i, particle_class); |
|
string config_OnFire_entry = config_OnFire_class + particle_class; |
|
WeaponParticlesOnFire WPOF = new WeaponParticlesOnFire(this, config_OnFire_entry); |
|
WPOF_array.Insert(WPOF); |
|
} |
|
|
|
|
|
m_OnFireEffect.Insert(id, WPOF_array); |
|
} |
|
} |
|
|
|
if (!m_OnBulletCasingEjectEffect.Contains(id)) |
|
{ |
|
config_to_search = "CfgWeapons"; |
|
muzzle_owner_config = config_to_search + " " + GetType() + " "; |
|
|
|
string config_OnBulletCasingEject_class = muzzle_owner_config + "Particles " + "OnBulletCasingEject "; |
|
|
|
int config_OnBulletCasingEject_count = GetGame().ConfigGetChildrenCount(config_OnBulletCasingEject_class); |
|
|
|
if (config_OnBulletCasingEject_count > 0 && IsInherited(Weapon)) |
|
{ |
|
array<ref WeaponParticlesOnBulletCasingEject> WPOBE_array = new array<ref WeaponParticlesOnBulletCasingEject>; |
|
|
|
for (i = 0; i < config_OnBulletCasingEject_count; i++) |
|
{ |
|
string particle_class2 = ""; |
|
GetGame().ConfigGetChildName(config_OnBulletCasingEject_class, i, particle_class2); |
|
string config_OnBulletCasingEject_entry = config_OnBulletCasingEject_class + particle_class2; |
|
WeaponParticlesOnBulletCasingEject WPOBE = new WeaponParticlesOnBulletCasingEject(this, config_OnBulletCasingEject_entry); |
|
WPOBE_array.Insert(WPOBE); |
|
} |
|
|
|
|
|
m_OnBulletCasingEjectEffect.Insert(id, WPOBE_array); |
|
} |
|
} |
|
} |
|
|
|
|
|
void LoadParticleConfigOnOverheating(int id) |
|
{ |
|
if (!m_OnOverheatingEffect) |
|
m_OnOverheatingEffect = new map<int, ref array<ref WeaponParticlesOnOverheating>>; |
|
|
|
if (!m_OnOverheatingEffect.Contains(id)) |
|
{ |
|
string config_to_search = "CfgVehicles"; |
|
|
|
if (IsInherited(Weapon)) |
|
config_to_search = "CfgWeapons"; |
|
|
|
string muzzle_owner_config = config_to_search + " " + GetType() + " "; |
|
string config_OnOverheating_class = muzzle_owner_config + "Particles " + "OnOverheating "; |
|
|
|
if (GetGame().ConfigIsExisting(config_OnOverheating_class)) |
|
{ |
|
|
|
m_ShotsToStartOverheating = GetGame().ConfigGetFloat(config_OnOverheating_class + "shotsToStartOverheating"); |
|
|
|
if (m_ShotsToStartOverheating == 0) |
|
{ |
|
m_ShotsToStartOverheating = -1; |
|
string error = "Error reading config " + GetType() + ">Particles>OnOverheating - Parameter shotsToStartOverheating is configured wrong or is missing! Its value must be 1 or higher!"; |
|
Error(error); |
|
return; |
|
} |
|
|
|
m_OverheatingDecayInterval = GetGame().ConfigGetFloat(config_OnOverheating_class + "overheatingDecayInterval"); |
|
m_MaxOverheatingValue = GetGame().ConfigGetFloat(config_OnOverheating_class + "maxOverheatingValue"); |
|
|
|
|
|
|
|
int config_OnOverheating_subclass_count = GetGame().ConfigGetChildrenCount(config_OnOverheating_class); |
|
array<ref WeaponParticlesOnOverheating> WPOOH_array = new array<ref WeaponParticlesOnOverheating>; |
|
|
|
for (int i = 0; i < config_OnOverheating_subclass_count; i++) |
|
{ |
|
string particle_class = ""; |
|
GetGame().ConfigGetChildName(config_OnOverheating_class, i, particle_class); |
|
string config_OnOverheating_entry = config_OnOverheating_class + particle_class; |
|
int entry_type = GetGame().ConfigGetType(config_OnOverheating_entry); |
|
|
|
if (entry_type == CT_CLASS) |
|
{ |
|
WeaponParticlesOnOverheating WPOF = new WeaponParticlesOnOverheating(this, config_OnOverheating_entry); |
|
WPOOH_array.Insert(WPOF); |
|
} |
|
} |
|
|
|
|
|
m_OnOverheatingEffect.Insert(id, WPOOH_array); |
|
} |
|
} |
|
} |
|
|
|
float GetOverheatingValue() |
|
{ |
|
return m_OverheatingShots; |
|
} |
|
|
|
void IncreaseOverheating(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search) |
|
{ |
|
if (m_MaxOverheatingValue > 0) |
|
{ |
|
m_OverheatingShots++; |
|
|
|
if (!m_CheckOverheating) |
|
m_CheckOverheating = new Timer(CALL_CATEGORY_SYSTEM); |
|
|
|
m_CheckOverheating.Stop(); |
|
m_CheckOverheating.Run(m_OverheatingDecayInterval, this, "OnOverheatingDecay"); |
|
|
|
CheckOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search); |
|
} |
|
} |
|
|
|
void CheckOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "") |
|
{ |
|
if (m_OverheatingShots >= m_ShotsToStartOverheating && IsOverheatingEffectActive()) |
|
UpdateOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search); |
|
|
|
if (m_OverheatingShots >= m_ShotsToStartOverheating && !IsOverheatingEffectActive()) |
|
StartOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search); |
|
|
|
if (m_OverheatingShots < m_ShotsToStartOverheating && IsOverheatingEffectActive()) |
|
StopOverheating(weapon, ammoType, muzzle_owner, suppressor, config_to_search); |
|
|
|
if (m_OverheatingShots > m_MaxOverheatingValue) |
|
{ |
|
m_OverheatingShots = m_MaxOverheatingValue; |
|
} |
|
} |
|
|
|
bool IsOverheatingEffectActive() |
|
{ |
|
return m_IsOverheatingEffectActive; |
|
} |
|
|
|
void OnOverheatingDecay() |
|
{ |
|
if (m_MaxOverheatingValue > 0) |
|
m_OverheatingShots -= 1 + m_OverheatingShots / m_MaxOverheatingValue; |
|
else |
|
m_OverheatingShots--; |
|
|
|
if (m_OverheatingShots <= 0) |
|
{ |
|
m_CheckOverheating.Stop(); |
|
m_OverheatingShots = 0; |
|
} |
|
else |
|
{ |
|
if (!m_CheckOverheating) |
|
m_CheckOverheating = new Timer(CALL_CATEGORY_GAMEPLAY); |
|
|
|
m_CheckOverheating.Stop(); |
|
m_CheckOverheating.Run(m_OverheatingDecayInterval, this, "OnOverheatingDecay"); |
|
} |
|
|
|
CheckOverheating(this, "", this); |
|
} |
|
|
|
void StartOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "") |
|
{ |
|
m_IsOverheatingEffectActive = true; |
|
ItemBase.PlayOverheatingParticles(this, ammoType, this, suppressor, "CfgWeapons"); |
|
} |
|
|
|
void UpdateOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "") |
|
{ |
|
KillAllOverheatingParticles(); |
|
ItemBase.UpdateOverheatingParticles(this, ammoType, this, suppressor, "CfgWeapons"); |
|
UpdateAllOverheatingParticles(); |
|
} |
|
|
|
void StopOverheating(ItemBase weapon = null, string ammoType = "", ItemBase muzzle_owner = null, ItemBase suppressor = null, string config_to_search = "") |
|
{ |
|
m_IsOverheatingEffectActive = false; |
|
ItemBase.StopOverheatingParticles(weapon, ammoType, muzzle_owner, suppressor, config_to_search); |
|
} |
|
|
|
void RegisterOverheatingParticle(Particle p, float min_heat_coef, float max_heat_coef, int particle_id, Object parent, vector local_pos, vector local_ori) |
|
{ |
|
if (!m_OverheatingParticles) |
|
m_OverheatingParticles = new array<ref OverheatingParticle>; |
|
|
|
OverheatingParticle OP = new OverheatingParticle(); |
|
OP.RegisterParticle(p); |
|
OP.SetOverheatingLimitMin(min_heat_coef); |
|
OP.SetOverheatingLimitMax(max_heat_coef); |
|
OP.SetParticleParams(particle_id, parent, local_pos, local_ori); |
|
|
|
m_OverheatingParticles.Insert(OP); |
|
} |
|
|
|
float GetOverheatingCoef() |
|
{ |
|
if (m_MaxOverheatingValue > 0) |
|
return (m_OverheatingShots - m_ShotsToStartOverheating) / m_MaxOverheatingValue; |
|
|
|
return -1; |
|
} |
|
|
|
void UpdateAllOverheatingParticles() |
|
{ |
|
if (m_OverheatingParticles) |
|
{ |
|
float overheat_coef = GetOverheatingCoef(); |
|
int count = m_OverheatingParticles.Count(); |
|
|
|
for (int i = count; i > 0; --i) |
|
{ |
|
int id = i - 1; |
|
OverheatingParticle OP = m_OverheatingParticles.Get(id); |
|
Particle p = OP.GetParticle(); |
|
|
|
float overheat_min = OP.GetOverheatingLimitMin(); |
|
float overheat_max = OP.GetOverheatingLimitMax(); |
|
|
|
if (overheat_coef < overheat_min && overheat_coef >= overheat_max) |
|
{ |
|
if (p) |
|
{ |
|
p.Stop(); |
|
OP.RegisterParticle(null); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
void KillAllOverheatingParticles() |
|
{ |
|
if (m_OverheatingParticles) |
|
{ |
|
for (int i = m_OverheatingParticles.Count(); i > 0; i--) |
|
{ |
|
int id = i - 1; |
|
OverheatingParticle OP = m_OverheatingParticles.Get(id); |
|
|
|
if (OP) |
|
{ |
|
Particle p = OP.GetParticle(); |
|
|
|
if (p) |
|
{ |
|
p.Stop(); |
|
} |
|
|
|
delete OP; |
|
} |
|
} |
|
|
|
m_OverheatingParticles.Clear(); |
|
delete m_OverheatingParticles; |
|
} |
|
} |
|
|
|
|
|
float GetInfectionChance(int system = 0, Param param = null) |
|
{ |
|
return 0.0; |
|
} |
|
|
|
|
|
float GetDisinfectQuantity(int system = 0, Param param1 = null) |
|
{ |
|
return 250; |
|
} |
|
|
|
float GetFilterDamageRatio() |
|
{ |
|
return 0; |
|
} |
|
|
|
|
|
bool HasMuzzle() |
|
{ |
|
if (IsInherited(Weapon) || IsInherited(SuppressorBase)) |
|
return true; |
|
|
|
return false; |
|
} |
|
|
|
|
|
int GetMuzzleID() |
|
{ |
|
if (!m_WeaponTypeToID) |
|
m_WeaponTypeToID = new map<string, int>; |
|
|
|
if (m_WeaponTypeToID.Contains(GetType())) |
|
{ |
|
return m_WeaponTypeToID.Get(GetType()); |
|
} |
|
else |
|
{ |
|
|
|
m_WeaponTypeToID.Insert(GetType(), ++m_LastRegisteredWeaponID); |
|
} |
|
|
|
return m_LastRegisteredWeaponID; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
int GetDamageSystemVersionChange() |
|
{ |
|
return -1; |
|
} |
|
|
|
|
|
|
|
|
|
void ~ItemBase() |
|
{ |
|
#ifndef SERVER |
|
if (m_DeployLoopSoundEx) |
|
m_DeployLoopSoundEx.SoundStop(); |
|
#endif |
|
|
|
if (GetGame() && GetGame().GetPlayer() && (!GetGame().IsDedicatedServer())) |
|
{ |
|
PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer()); |
|
int r_index = player.GetHumanInventory().FindUserReservedLocationIndex(this); |
|
|
|
if (r_index >= 0) |
|
{ |
|
InventoryLocation r_il = new InventoryLocation; |
|
player.GetHumanInventory().GetUserReservedLocation(r_index,r_il); |
|
|
|
player.GetHumanInventory().ClearUserReservedLocationAtIndex(r_index); |
|
int r_type = r_il.GetType(); |
|
if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO) |
|
{ |
|
r_il.GetParent().GetOnReleaseLock().Invoke(this); |
|
} |
|
else if (r_type == InventoryLocationType.ATTACHMENT) |
|
{ |
|
r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(this, r_il.GetSlot()); |
|
} |
|
|
|
} |
|
|
|
player.GetHumanInventory().ClearUserReservedLocation(this); |
|
} |
|
|
|
SEffectManager.DestroyEffect(m_LockingSound); |
|
} |
|
|
|
|
|
|
|
|
|
static int GetDebugActionsMask() |
|
{ |
|
return ItemBase.m_DebugActionsMask; |
|
} |
|
|
|
static bool HasDebugActionsMask(int mask) |
|
{ |
|
return ItemBase.m_DebugActionsMask & mask; |
|
} |
|
|
|
static void SetDebugActionsMask(int mask) |
|
{ |
|
ItemBase.m_DebugActionsMask = mask; |
|
} |
|
|
|
static void AddDebugActionsMask(int mask) |
|
{ |
|
ItemBase.m_DebugActionsMask |= mask; |
|
} |
|
|
|
static void RemoveDebugActionsMask(int mask) |
|
{ |
|
ItemBase.m_DebugActionsMask &= ~mask; |
|
} |
|
|
|
static void ToggleDebugActionsMask(int mask) |
|
{ |
|
if (HasDebugActionsMask(mask)) |
|
{ |
|
RemoveDebugActionsMask(mask); |
|
} |
|
else |
|
{ |
|
AddDebugActionsMask(mask); |
|
} |
|
} |
|
|
|
|
|
void SetCEBasedQuantity() |
|
{ |
|
if (GetEconomyProfile()) |
|
{ |
|
float q_max = GetEconomyProfile().GetQuantityMax(); |
|
if (q_max > 0) |
|
{ |
|
float q_min = GetEconomyProfile().GetQuantityMin(); |
|
float quantity_randomized = Math.RandomFloatInclusive(q_min, q_max); |
|
|
|
if (HasComponent(COMP_TYPE_ENERGY_MANAGER)) |
|
{ |
|
ComponentEnergyManager comp = GetCompEM(); |
|
if (comp && (comp.GetEnergyMaxPristine() || comp.GetEnergyAtSpawn())) |
|
{ |
|
|
|
comp.SetEnergy0To1(quantity_randomized); |
|
} |
|
|
|
|
|
|
|
|
|
} |
|
else if (HasQuantity()) |
|
{ |
|
SetQuantityNormalized(quantity_randomized, false); |
|
|
|
} |
|
|
|
} |
|
} |
|
} |
|
|
|
|
|
void LockToParent() |
|
{ |
|
EntityAI parent = GetHierarchyParent(); |
|
|
|
if (parent) |
|
{ |
|
InventoryLocation inventory_location_to_lock = new InventoryLocation; |
|
GetInventory().GetCurrentInventoryLocation(inventory_location_to_lock); |
|
parent.GetInventory().SetSlotLock(inventory_location_to_lock.GetSlot(), true); |
|
} |
|
} |
|
|
|
|
|
void UnlockFromParent() |
|
{ |
|
EntityAI parent = GetHierarchyParent(); |
|
|
|
if (parent) |
|
{ |
|
InventoryLocation inventory_location_to_unlock = new InventoryLocation; |
|
GetInventory().GetCurrentInventoryLocation(inventory_location_to_unlock); |
|
parent.GetInventory().SetSlotLock(inventory_location_to_unlock.GetSlot(), false); |
|
} |
|
} |
|
|
|
override void CombineItemsClient(EntityAI entity2, bool use_stack_max = true) |
|
{ |
|
|
|
|
|
|
|
|
|
ItemBase item2 = ItemBase.Cast(entity2); |
|
|
|
if (GetGame().IsClient()) |
|
{ |
|
if (ScriptInputUserData.CanStoreInputUserData()) |
|
{ |
|
ScriptInputUserData ctx = new ScriptInputUserData; |
|
ctx.Write(INPUT_UDT_ITEM_MANIPULATION); |
|
ctx.Write(-1); |
|
ItemBase i1 = this; |
|
ctx.Write(i1); |
|
ctx.Write(item2); |
|
ctx.Write(use_stack_max); |
|
ctx.Write(-1); |
|
ctx.Send(); |
|
|
|
if (IsCombineAll(item2, use_stack_max)) |
|
{ |
|
GetGame().GetPlayer().GetInventory().AddInventoryReservationEx(item2,null,GameInventory.c_InventoryReservationTimeoutShortMS); |
|
} |
|
} |
|
} |
|
else if (!GetGame().IsMultiplayer()) |
|
{ |
|
CombineItems(item2, use_stack_max); |
|
} |
|
} |
|
|
|
bool IsLiquidPresent() |
|
{ |
|
|
|
return (GetLiquidType() != 0 && HasQuantity()); |
|
} |
|
|
|
bool IsLiquidContainer() |
|
{ |
|
return (ConfigGetFloat("liquidContainerType") != 0); |
|
} |
|
|
|
bool IsBloodContainer() |
|
{ |
|
return false; |
|
} |
|
|
|
bool IsNVG() |
|
{ |
|
return false; |
|
} |
|
|
|
|
|
|
|
bool IsExplosive() |
|
{ |
|
return false; |
|
} |
|
|
|
string GetExplosiveTriggerSlotName() |
|
{ |
|
return ""; |
|
} |
|
|
|
|
|
|
|
bool IsLightSource() |
|
{ |
|
return false; |
|
} |
|
|
|
bool CanBeRepairedByCrafting() |
|
{ |
|
return true; |
|
} |
|
|
|
|
|
|
|
bool IsFacingPlayer(PlayerBase player, string selection) |
|
{ |
|
return true; |
|
} |
|
|
|
bool IsPlayerInside(PlayerBase player, string selection) |
|
{ |
|
return true; |
|
} |
|
|
|
override bool CanObstruct() |
|
{ |
|
PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer()); |
|
return !player || !IsPlayerInside(player, ""); |
|
} |
|
|
|
override bool IsBeingPlaced() |
|
{ |
|
return m_IsBeingPlaced; |
|
} |
|
|
|
void SetIsBeingPlaced(bool is_being_placed) |
|
{ |
|
m_IsBeingPlaced = is_being_placed; |
|
if (!is_being_placed) |
|
OnEndPlacement(); |
|
SetSynchDirty(); |
|
} |
|
|
|
|
|
void OnEndPlacement() {} |
|
|
|
override bool IsHologram() |
|
{ |
|
return m_IsHologram; |
|
} |
|
|
|
bool CanBeDigged() |
|
{ |
|
return m_CanBeDigged; |
|
} |
|
|
|
bool CanMakeGardenplot() |
|
{ |
|
return false; |
|
} |
|
|
|
void SetIsHologram(bool is_hologram) |
|
{ |
|
m_IsHologram = is_hologram; |
|
SetSynchDirty(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override void OnMovedInsideCargo(EntityAI container) |
|
{ |
|
super.OnMovedInsideCargo(container); |
|
|
|
MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(this, {Bolt_Base}); |
|
} |
|
|
|
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc) |
|
{ |
|
super.EEItemLocationChanged(oldLoc,newLoc); |
|
|
|
PlayerBase new_player = null; |
|
PlayerBase old_player = null; |
|
|
|
if (newLoc.GetParent()) |
|
new_player = PlayerBase.Cast(newLoc.GetParent().GetHierarchyRootPlayer()); |
|
|
|
if (oldLoc.GetParent()) |
|
old_player = PlayerBase.Cast(oldLoc.GetParent().GetHierarchyRootPlayer()); |
|
|
|
if (old_player && oldLoc.GetType() == InventoryLocationType.HANDS) |
|
{ |
|
int r_index = old_player.GetHumanInventory().FindUserReservedLocationIndex(this); |
|
|
|
if (r_index >= 0) |
|
{ |
|
InventoryLocation r_il = new InventoryLocation; |
|
old_player.GetHumanInventory().GetUserReservedLocation(r_index,r_il); |
|
|
|
old_player.GetHumanInventory().ClearUserReservedLocationAtIndex(r_index); |
|
int r_type = r_il.GetType(); |
|
if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO) |
|
{ |
|
r_il.GetParent().GetOnReleaseLock().Invoke(this); |
|
} |
|
else if (r_type == InventoryLocationType.ATTACHMENT) |
|
{ |
|
r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(this, r_il.GetSlot()); |
|
} |
|
|
|
} |
|
} |
|
|
|
if (newLoc.GetType() == InventoryLocationType.HANDS) |
|
{ |
|
if (new_player) |
|
new_player.ForceStandUpForHeavyItems(newLoc.GetItem()); |
|
|
|
if (new_player == old_player) |
|
{ |
|
|
|
if (oldLoc.GetParent() && !(oldLoc.GetParent() != new_player && oldLoc.GetType() == InventoryLocationType.ATTACHMENT) && new_player.GetHumanInventory().LocationGetEntity(oldLoc) == NULL) |
|
{ |
|
if (oldLoc.GetType() == InventoryLocationType.CARGO) |
|
{ |
|
if (oldLoc.GetParent().GetInventory().TestAddEntityInCargoExLoc(oldLoc, false, false, false, true, false, false)) |
|
{ |
|
new_player.GetHumanInventory().SetUserReservedLocation(this,oldLoc); |
|
} |
|
} |
|
else |
|
{ |
|
new_player.GetHumanInventory().SetUserReservedLocation(this,oldLoc); |
|
} |
|
} |
|
|
|
if (new_player.GetHumanInventory().FindUserReservedLocationIndex(this) >= 0) |
|
{ |
|
int type = oldLoc.GetType(); |
|
if (type == InventoryLocationType.CARGO || type == InventoryLocationType.PROXYCARGO) |
|
{ |
|
oldLoc.GetParent().GetOnSetLock().Invoke(this); |
|
} |
|
else if (type == InventoryLocationType.ATTACHMENT) |
|
{ |
|
oldLoc.GetParent().GetOnAttachmentSetLock().Invoke(this, oldLoc.GetSlot()); |
|
} |
|
} |
|
if (!m_OldLocation) |
|
{ |
|
m_OldLocation = new InventoryLocation; |
|
} |
|
m_OldLocation.Copy(oldLoc); |
|
} |
|
else |
|
{ |
|
if (m_OldLocation) |
|
{ |
|
m_OldLocation.Reset(); |
|
} |
|
} |
|
|
|
GetGame().GetAnalyticsClient().OnItemAttachedAtPlayer(this,"Hands"); |
|
} |
|
else |
|
{ |
|
if (new_player) |
|
{ |
|
int res_index = new_player.GetHumanInventory().FindCollidingUserReservedLocationIndex(this, newLoc); |
|
if (res_index >= 0) |
|
{ |
|
InventoryLocation il = new InventoryLocation; |
|
new_player.GetHumanInventory().GetUserReservedLocation(res_index,il); |
|
ItemBase it = ItemBase.Cast(il.GetItem()); |
|
new_player.GetHumanInventory().ClearUserReservedLocationAtIndex(res_index); |
|
int rel_type = il.GetType(); |
|
if (rel_type == InventoryLocationType.CARGO || rel_type == InventoryLocationType.PROXYCARGO) |
|
{ |
|
il.GetParent().GetOnReleaseLock().Invoke(it); |
|
} |
|
else if (rel_type == InventoryLocationType.ATTACHMENT) |
|
{ |
|
il.GetParent().GetOnAttachmentReleaseLock().Invoke(it, il.GetSlot()); |
|
} |
|
|
|
} |
|
} |
|
else if (old_player && newLoc.GetType() == InventoryLocationType.GROUND && m_ThrowItemOnDrop) |
|
{ |
|
|
|
|
|
m_ThrowItemOnDrop = false; |
|
} |
|
|
|
if (m_OldLocation) |
|
{ |
|
m_OldLocation.Reset(); |
|
} |
|
} |
|
} |
|
|
|
override void EOnContact(IEntity other, Contact extra) |
|
{ |
|
if (m_CanPlayImpactSound) |
|
{ |
|
int liquidType = -1; |
|
float impactSpeed = ProcessImpactSoundEx(other, extra, m_ConfigWeight, m_ImpactSoundSurfaceHash, liquidType); |
|
if (impactSpeed > 0.0) |
|
{ |
|
m_ImpactSpeed = impactSpeed; |
|
#ifndef SERVER |
|
PlayImpactSound(m_ConfigWeight, m_ImpactSpeed, m_ImpactSoundSurfaceHash); |
|
#else |
|
m_WantPlayImpactSound = true; |
|
SetSynchDirty(); |
|
#endif |
|
m_CanPlayImpactSound = (liquidType == -1); |
|
} |
|
} |
|
|
|
#ifdef SERVER |
|
if (GetCompEM() && GetCompEM().IsPlugged()) |
|
{ |
|
if (GetCompEM().GetCordLength() < vector.Distance(GetPosition(), GetCompEM().GetEnergySource().GetPosition())) |
|
GetCompEM().UnplugThis(); |
|
} |
|
#endif |
|
} |
|
|
|
void RefreshPhysics(); |
|
|
|
override void OnCreatePhysics() |
|
{ |
|
RefreshPhysics(); |
|
} |
|
|
|
override void OnItemAttachmentSlotChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc) |
|
{ |
|
|
|
} |
|
|
|
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner) |
|
{ |
|
super.OnItemLocationChanged(old_owner, new_owner); |
|
|
|
Man ownerPlayerOld = null; |
|
Man ownerPlayerNew = null; |
|
|
|
if (old_owner) |
|
{ |
|
if (old_owner.IsMan()) |
|
{ |
|
ownerPlayerOld = Man.Cast(old_owner); |
|
} |
|
else |
|
{ |
|
ownerPlayerOld = Man.Cast(old_owner.GetHierarchyRootPlayer()); |
|
} |
|
} |
|
|
|
if (new_owner) |
|
{ |
|
if (new_owner.IsMan()) |
|
{ |
|
ownerPlayerNew = Man.Cast(new_owner); |
|
} |
|
else |
|
{ |
|
ownerPlayerNew = Man.Cast(new_owner.GetHierarchyRootPlayer()); |
|
} |
|
} |
|
|
|
if (ownerPlayerOld != ownerPlayerNew) |
|
{ |
|
if (ownerPlayerOld) |
|
{ |
|
array<EntityAI> subItemsExit = new array<EntityAI>; |
|
GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER,subItemsExit); |
|
for (int i = 0; i < subItemsExit.Count(); i++) |
|
{ |
|
ItemBase itemExit = ItemBase.Cast(subItemsExit.Get(i)); |
|
itemExit.OnInventoryExit(ownerPlayerOld); |
|
} |
|
} |
|
|
|
if (ownerPlayerNew) |
|
{ |
|
array<EntityAI> subItemsEnter = new array<EntityAI>; |
|
GetInventory().EnumerateInventory(InventoryTraversalType.PREORDER,subItemsEnter); |
|
for (int j = 0; j < subItemsEnter.Count(); j++) |
|
{ |
|
ItemBase itemEnter = ItemBase.Cast(subItemsEnter.Get(j)); |
|
itemEnter.OnInventoryEnter(ownerPlayerNew); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
override void EEDelete(EntityAI parent) |
|
{ |
|
super.EEDelete(parent); |
|
PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer()); |
|
if (player) |
|
{ |
|
OnInventoryExit(player); |
|
|
|
if (player.IsAlive()) |
|
{ |
|
int r_index = player.GetHumanInventory().FindUserReservedLocationIndex(this); |
|
if (r_index >= 0) |
|
{ |
|
InventoryLocation r_il = new InventoryLocation; |
|
player.GetHumanInventory().GetUserReservedLocation(r_index,r_il); |
|
|
|
player.GetHumanInventory().ClearUserReservedLocationAtIndex(r_index); |
|
int r_type = r_il.GetType(); |
|
if (r_type == InventoryLocationType.CARGO || r_type == InventoryLocationType.PROXYCARGO) |
|
{ |
|
r_il.GetParent().GetOnReleaseLock().Invoke(this); |
|
} |
|
else if (r_type == InventoryLocationType.ATTACHMENT) |
|
{ |
|
r_il.GetParent().GetOnAttachmentReleaseLock().Invoke(this, r_il.GetSlot()); |
|
} |
|
|
|
} |
|
|
|
player.RemoveQuickBarEntityShortcut(this); |
|
} |
|
} |
|
} |
|
|
|
override void EEKilled(Object killer) |
|
{ |
|
super.EEKilled(killer); |
|
|
|
|
|
if (killer && killer.IsFireplace() && CanExplodeInFire()) |
|
{ |
|
if (GetTemperature() >= GameConstants.ITEM_TEMPERATURE_TO_EXPLODE_MIN) |
|
{ |
|
if (IsMagazine()) |
|
{ |
|
if (Magazine.Cast(this).GetAmmoCount() > 0) |
|
{ |
|
ExplodeAmmo(); |
|
} |
|
} |
|
else |
|
{ |
|
Explode(DamageType.EXPLOSION); |
|
} |
|
} |
|
} |
|
} |
|
|
|
override void OnWasAttached(EntityAI parent, int slot_id) |
|
{ |
|
MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(this, {Bolt_Base}); |
|
|
|
super.OnWasAttached(parent, slot_id); |
|
|
|
if (HasQuantity()) |
|
UpdateNetSyncVariableFloat("m_VarQuantity", GetQuantityMin(), m_VarQuantityMax); |
|
|
|
PlayAttachSound(InventorySlots.GetSlotName(slot_id)); |
|
} |
|
|
|
override void OnWasDetached(EntityAI parent, int slot_id) |
|
{ |
|
super.OnWasDetached(parent, slot_id); |
|
|
|
if (HasQuantity()) |
|
UpdateNetSyncVariableFloat("m_VarQuantity", GetQuantityMin(), m_VarQuantityMax); |
|
} |
|
|
|
override string ChangeIntoOnAttach(string slot) |
|
{ |
|
int idx; |
|
TStringArray inventory_slots = new TStringArray; |
|
TStringArray attach_types = new TStringArray; |
|
|
|
ConfigGetTextArray("ChangeInventorySlot",inventory_slots); |
|
if (inventory_slots.Count() < 1) |
|
{ |
|
inventory_slots.Insert(ConfigGetString("ChangeInventorySlot")); |
|
attach_types.Insert(ConfigGetString("ChangeIntoOnAttach")); |
|
} |
|
else |
|
{ |
|
ConfigGetTextArray("ChangeIntoOnAttach",attach_types); |
|
} |
|
|
|
idx = inventory_slots.Find(slot); |
|
if (idx < 0) |
|
return ""; |
|
|
|
return attach_types.Get(idx); |
|
} |
|
|
|
override string ChangeIntoOnDetach() |
|
{ |
|
int idx = -1; |
|
string slot; |
|
|
|
TStringArray inventory_slots = new TStringArray; |
|
TStringArray detach_types = new TStringArray; |
|
|
|
this.ConfigGetTextArray("ChangeInventorySlot",inventory_slots); |
|
if (inventory_slots.Count() < 1) |
|
{ |
|
inventory_slots.Insert(this.ConfigGetString("ChangeInventorySlot")); |
|
detach_types.Insert(this.ConfigGetString("ChangeIntoOnDetach")); |
|
} |
|
else |
|
{ |
|
this.ConfigGetTextArray("ChangeIntoOnDetach",detach_types); |
|
if (detach_types.Count() < 1) |
|
detach_types.Insert(this.ConfigGetString("ChangeIntoOnDetach")); |
|
} |
|
|
|
for (int i = 0; i < inventory_slots.Count(); i++) |
|
{ |
|
slot = inventory_slots.Get(i); |
|
} |
|
|
|
if (slot != "") |
|
{ |
|
if (detach_types.Count() == 1) |
|
idx = 0; |
|
else |
|
idx = inventory_slots.Find(slot); |
|
} |
|
if (idx < 0) |
|
return ""; |
|
|
|
return detach_types.Get(idx); |
|
} |
|
|
|
void ExplodeAmmo() |
|
{ |
|
|
|
ref Timer explode_timer = new Timer(CALL_CATEGORY_SYSTEM); |
|
|
|
|
|
float min_time = 1; |
|
float max_time = 3; |
|
float delay = Math.RandomFloat(min_time, max_time); |
|
|
|
explode_timer.Run(delay, this, "DoAmmoExplosion"); |
|
} |
|
|
|
void DoAmmoExplosion() |
|
{ |
|
Magazine magazine = Magazine.Cast(this); |
|
int pop_sounds_count = 6; |
|
string pop_sounds[ 6 ] = { "ammopops_1","ammopops_2","ammopops_3","ammopops_4","ammopops_5","ammopops_6" }; |
|
|
|
|
|
int sound_idx = Math.RandomInt(0, pop_sounds_count - 1); |
|
string sound_name = pop_sounds[ sound_idx ]; |
|
GetGame().CreateSoundOnObject(this, sound_name, 20, false); |
|
|
|
|
|
magazine.ServerAddAmmoCount(-1); |
|
|
|
|
|
float min_temp_to_explode = 100; |
|
|
|
if (magazine.GetAmmoCount() > 0 && GetTemperature() >= min_temp_to_explode) |
|
{ |
|
ExplodeAmmo(); |
|
} |
|
} |
|
|
|
|
|
override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef) |
|
{ |
|
super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef); |
|
|
|
const int CHANCE_DAMAGE_CARGO = 4; |
|
const int CHANCE_DAMAGE_ATTACHMENT = 1; |
|
const int CHANCE_DAMAGE_NOTHING = 2; |
|
|
|
if (IsClothing() || IsContainer() || IsItemTent()) |
|
{ |
|
float dmg = damageResult.GetDamage("","Health") * -0.5; |
|
int chances; |
|
int rnd; |
|
|
|
if (GetInventory().GetCargo()) |
|
{ |
|
chances = CHANCE_DAMAGE_CARGO + CHANCE_DAMAGE_ATTACHMENT + CHANCE_DAMAGE_NOTHING; |
|
rnd = Math.RandomInt(0,chances); |
|
|
|
if (rnd < CHANCE_DAMAGE_CARGO) |
|
{ |
|
DamageItemInCargo(dmg); |
|
} |
|
else if (rnd < (chances - CHANCE_DAMAGE_NOTHING)) |
|
{ |
|
DamageItemAttachments(dmg); |
|
} |
|
} |
|
else |
|
{ |
|
chances = CHANCE_DAMAGE_ATTACHMENT + CHANCE_DAMAGE_NOTHING; |
|
rnd = Math.RandomInt(0,chances); |
|
|
|
if (rnd < CHANCE_DAMAGE_ATTACHMENT) |
|
{ |
|
DamageItemAttachments(dmg); |
|
} |
|
} |
|
} |
|
} |
|
|
|
bool DamageItemInCargo(float damage) |
|
{ |
|
if (GetInventory().GetCargo()) |
|
{ |
|
int item_count = GetInventory().GetCargo().GetItemCount(); |
|
if (item_count > 0) |
|
{ |
|
int random_pick = Math.RandomInt(0, item_count); |
|
ItemBase item = ItemBase.Cast(GetInventory().GetCargo().GetItem(random_pick)); |
|
if (!item.IsExplosive()) |
|
{ |
|
item.AddHealth("","",damage); |
|
return true; |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
bool DamageItemAttachments(float damage) |
|
{ |
|
int attachment_count = GetInventory().AttachmentCount(); |
|
if (attachment_count > 0) |
|
{ |
|
int random_pick = Math.RandomInt(0, attachment_count); |
|
ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(random_pick)); |
|
if (!attachment.IsExplosive()) |
|
{ |
|
attachment.AddHealth("","",damage); |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
|
|
override bool CanBeSplit() |
|
{ |
|
if (m_CanThisBeSplit) |
|
return (GetQuantity() > 1); |
|
|
|
return false; |
|
} |
|
|
|
void SplitIntoStackMaxClient(EntityAI destination_entity, int slot_id ) |
|
{ |
|
if (GetGame().IsClient()) |
|
{ |
|
if (ScriptInputUserData.CanStoreInputUserData()) |
|
{ |
|
ScriptInputUserData ctx = new ScriptInputUserData; |
|
ctx.Write(INPUT_UDT_ITEM_MANIPULATION); |
|
ctx.Write(1); |
|
ItemBase i1 = this; |
|
ctx.Write(i1); |
|
ctx.Write(destination_entity); |
|
ctx.Write(true); |
|
ctx.Write(slot_id); |
|
ctx.Send(); |
|
} |
|
} |
|
else if (!GetGame().IsMultiplayer()) |
|
{ |
|
SplitIntoStackMax(destination_entity, slot_id, PlayerBase.Cast(GetGame().GetPlayer())); |
|
} |
|
} |
|
|
|
void SplitIntoStackMax(EntityAI destination_entity, int slot_id, PlayerBase player) |
|
{ |
|
float split_quantity_new; |
|
ref ItemBase new_item; |
|
float quantity = GetQuantity(); |
|
float stack_max = GetTargetQuantityMax(slot_id); |
|
InventoryLocation loc = new InventoryLocation; |
|
|
|
if (destination_entity && slot_id != -1 && InventorySlots.IsSlotIdValid(slot_id)) |
|
{ |
|
if (stack_max <= GetQuantity()) |
|
split_quantity_new = stack_max; |
|
else |
|
split_quantity_new = GetQuantity(); |
|
|
|
new_item = ItemBase.Cast(destination_entity.GetInventory().CreateAttachmentEx(this.GetType(), slot_id)); |
|
if (new_item) |
|
{ |
|
new_item.SetResultOfSplit(true); |
|
MiscGameplayFunctions.TransferItemProperties(this, new_item); |
|
AddQuantity(-split_quantity_new); |
|
new_item.SetQuantity(split_quantity_new); |
|
} |
|
} |
|
else if (destination_entity && slot_id == -1) |
|
{ |
|
if (quantity > stack_max) |
|
split_quantity_new = stack_max; |
|
else |
|
split_quantity_new = quantity; |
|
|
|
if (destination_entity.GetInventory().FindFreeLocationFor(this, FindInventoryLocationType.ANY, loc)) |
|
{ |
|
Object o = destination_entity.GetInventory().LocationCreateEntity(loc, GetType(), ECE_IN_INVENTORY, RF_DEFAULT); |
|
new_item = ItemBase.Cast(o); |
|
} |
|
|
|
if (new_item) |
|
{ |
|
new_item.SetResultOfSplit(true); |
|
MiscGameplayFunctions.TransferItemProperties(this, new_item); |
|
AddQuantity(-split_quantity_new); |
|
new_item.SetQuantity(split_quantity_new); |
|
} |
|
} |
|
else |
|
{ |
|
if (stack_max != 0) |
|
{ |
|
if (stack_max < GetQuantity()) |
|
{ |
|
split_quantity_new = GetQuantity() - stack_max; |
|
} |
|
|
|
if (split_quantity_new == 0) |
|
{ |
|
if (!GetGame().IsMultiplayer()) |
|
player.PhysicalPredictiveDropItem(this); |
|
else |
|
player.ServerDropEntity(this); |
|
return; |
|
} |
|
|
|
new_item = ItemBase.Cast(GetGame().CreateObjectEx(GetType(), player.GetWorldPosition(), ECE_PLACE_ON_SURFACE)); |
|
|
|
if (new_item) |
|
{ |
|
new_item.SetResultOfSplit(true); |
|
MiscGameplayFunctions.TransferItemProperties(this, new_item); |
|
SetQuantity(split_quantity_new); |
|
new_item.SetQuantity(stack_max); |
|
new_item.PlaceOnSurface(); |
|
} |
|
} |
|
} |
|
} |
|
|
|
void SplitIntoStackMaxToInventoryLocationClient(notnull InventoryLocation dst) |
|
{ |
|
if (GetGame().IsClient()) |
|
{ |
|
if (ScriptInputUserData.CanStoreInputUserData()) |
|
{ |
|
ScriptInputUserData ctx = new ScriptInputUserData; |
|
ctx.Write(INPUT_UDT_ITEM_MANIPULATION); |
|
ctx.Write(4); |
|
ItemBase thiz = this; |
|
ctx.Write(thiz); |
|
dst.WriteToContext(ctx); |
|
ctx.Send(); |
|
} |
|
} |
|
else if (!GetGame().IsMultiplayer()) |
|
{ |
|
SplitIntoStackMaxToInventoryLocation(dst); |
|
} |
|
} |
|
|
|
void SplitIntoStackMaxCargoClient(EntityAI destination_entity, int idx, int row, int col) |
|
{ |
|
if (GetGame().IsClient()) |
|
{ |
|
if (ScriptInputUserData.CanStoreInputUserData()) |
|
{ |
|
ScriptInputUserData ctx = new ScriptInputUserData; |
|
ctx.Write(INPUT_UDT_ITEM_MANIPULATION); |
|
ctx.Write(2); |
|
ItemBase dummy = this; |
|
ctx.Write(dummy); |
|
ctx.Write(destination_entity); |
|
ctx.Write(true); |
|
ctx.Write(idx); |
|
ctx.Write(row); |
|
ctx.Write(col); |
|
ctx.Send(); |
|
} |
|
} |
|
else if (!GetGame().IsMultiplayer()) |
|
{ |
|
SplitIntoStackMaxCargo(destination_entity, idx, row, col); |
|
} |
|
} |
|
|
|
void SplitIntoStackMaxToInventoryLocation(notnull InventoryLocation dst) |
|
{ |
|
SplitIntoStackMaxToInventoryLocationEx(dst); |
|
} |
|
|
|
ItemBase SplitIntoStackMaxToInventoryLocationEx(notnull InventoryLocation dst) |
|
{ |
|
float quantity = GetQuantity(); |
|
float split_quantity_new; |
|
ItemBase new_item; |
|
if (dst.IsValid()) |
|
{ |
|
int slot_id = dst.GetSlot(); |
|
float stack_max = GetTargetQuantityMax(slot_id); |
|
|
|
if (quantity > stack_max) |
|
split_quantity_new = stack_max; |
|
else |
|
split_quantity_new = quantity; |
|
|
|
new_item = ItemBase.Cast(GameInventory.LocationCreateEntity(dst, this.GetType(), ECE_IN_INVENTORY, RF_DEFAULT)); |
|
|
|
if (new_item) |
|
{ |
|
new_item.SetResultOfSplit(true); |
|
MiscGameplayFunctions.TransferItemProperties(this,new_item); |
|
AddQuantity(-split_quantity_new); |
|
new_item.SetQuantity(split_quantity_new); |
|
} |
|
|
|
return new_item; |
|
} |
|
|
|
return null; |
|
} |
|
|
|
void SplitIntoStackMaxCargo(EntityAI destination_entity, int idx, int row, int col) |
|
{ |
|
float quantity = GetQuantity(); |
|
float split_quantity_new; |
|
ref ItemBase new_item; |
|
if (destination_entity) |
|
{ |
|
float stackable = GetTargetQuantityMax(); |
|
if (quantity > stackable) |
|
split_quantity_new = stackable; |
|
else |
|
split_quantity_new = quantity; |
|
|
|
new_item = ItemBase.Cast(destination_entity.GetInventory().CreateEntityInCargoEx(this.GetType(), idx, row, col, false)); |
|
if (new_item) |
|
{ |
|
new_item.SetResultOfSplit(true); |
|
MiscGameplayFunctions.TransferItemProperties(this,new_item); |
|
AddQuantity(-split_quantity_new); |
|
new_item.SetQuantity(split_quantity_new); |
|
} |
|
} |
|
} |
|
|
|
void SplitIntoStackMaxHandsClient(PlayerBase player) |
|
{ |
|
if (GetGame().IsClient()) |
|
{ |
|
if (ScriptInputUserData.CanStoreInputUserData()) |
|
{ |
|
ScriptInputUserData ctx = new ScriptInputUserData; |
|
ctx.Write(INPUT_UDT_ITEM_MANIPULATION); |
|
ctx.Write(3); |
|
ItemBase i1 = this; |
|
ctx.Write(i1); |
|
ItemBase destination_entity = this; |
|
ctx.Write(destination_entity); |
|
ctx.Write(true); |
|
ctx.Write(0); |
|
ctx.Send(); |
|
} |
|
} |
|
else if (!GetGame().IsMultiplayer()) |
|
{ |
|
SplitIntoStackMaxHands(player); |
|
} |
|
} |
|
|
|
void SplitIntoStackMaxHands(PlayerBase player) |
|
{ |
|
float quantity = GetQuantity(); |
|
float split_quantity_new; |
|
ref ItemBase new_item; |
|
if (player) |
|
{ |
|
float stackable = GetTargetQuantityMax(); |
|
if (quantity > stackable) |
|
split_quantity_new = stackable; |
|
else |
|
split_quantity_new = quantity; |
|
|
|
EntityAI in_hands = player.GetHumanInventory().CreateInHands(this.GetType()); |
|
new_item = ItemBase.Cast(in_hands); |
|
if (new_item) |
|
{ |
|
new_item.SetResultOfSplit(true); |
|
MiscGameplayFunctions.TransferItemProperties(this,new_item); |
|
AddQuantity(-split_quantity_new); |
|
new_item.SetQuantity(split_quantity_new); |
|
} |
|
} |
|
} |
|
|
|
void SplitItemToInventoryLocation(notnull InventoryLocation dst) |
|
{ |
|
if (!CanBeSplit()) |
|
return; |
|
|
|
float quantity = GetQuantity(); |
|
float split_quantity_new = Math.Floor(quantity * 0.5); |
|
|
|
ItemBase new_item = ItemBase.Cast(GameInventory.LocationCreateEntity(dst, GetType(), ECE_IN_INVENTORY, RF_DEFAULT)); |
|
|
|
if (new_item) |
|
{ |
|
if (new_item.GetQuantityMax() < split_quantity_new) |
|
{ |
|
split_quantity_new = new_item.GetQuantityMax(); |
|
} |
|
|
|
new_item.SetResultOfSplit(true); |
|
MiscGameplayFunctions.TransferItemProperties(this, new_item); |
|
|
|
if (dst.IsValid() && dst.GetType() == InventoryLocationType.ATTACHMENT && split_quantity_new > 1) |
|
{ |
|
AddQuantity(-1); |
|
new_item.SetQuantity(1); |
|
} |
|
else |
|
{ |
|
AddQuantity(-split_quantity_new); |
|
new_item.SetQuantity(split_quantity_new); |
|
} |
|
} |
|
} |
|
|
|
void SplitItem(PlayerBase player) |
|
{ |
|
if (!CanBeSplit()) |
|
{ |
|
return; |
|
} |
|
|
|
float quantity = GetQuantity(); |
|
float split_quantity_new = Math.Floor(quantity / 2); |
|
|
|
InventoryLocation invloc = new InventoryLocation; |
|
bool found = player.GetInventory().FindFirstFreeLocationForNewEntity(GetType(), FindInventoryLocationType.ATTACHMENT, invloc); |
|
|
|
ItemBase new_item; |
|
new_item = player.CreateCopyOfItemInInventoryOrGroundEx(this, true); |
|
|
|
if (new_item) |
|
{ |
|
if (new_item.GetQuantityMax() < split_quantity_new) |
|
{ |
|
split_quantity_new = new_item.GetQuantityMax(); |
|
} |
|
if (found && invloc.IsValid() && invloc.GetType() == InventoryLocationType.ATTACHMENT && split_quantity_new > 1) |
|
{ |
|
AddQuantity(-1); |
|
new_item.SetQuantity(1); |
|
} |
|
else |
|
{ |
|
AddQuantity(-split_quantity_new); |
|
new_item.SetQuantity(split_quantity_new); |
|
} |
|
} |
|
} |
|
|
|
|
|
void OnQuantityChanged(float delta) |
|
{ |
|
SetWeightDirty(); |
|
ItemBase parent = ItemBase.Cast(GetHierarchyParent()); |
|
|
|
if (parent) |
|
{ |
|
parent.OnAttachmentQuantityChangedEx(this, delta); |
|
} |
|
} |
|
|
|
|
|
void OnAttachmentQuantityChanged(ItemBase item) |
|
{ |
|
|
|
} |
|
|
|
|
|
void OnAttachmentQuantityChangedEx(ItemBase item , float delta) |
|
{ |
|
OnAttachmentQuantityChanged(item); |
|
} |
|
|
|
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone) |
|
{ |
|
super.EEHealthLevelChanged(oldLevel,newLevel,zone); |
|
|
|
if (GetGame().IsServer()) |
|
{ |
|
if (newLevel == GameConstants.STATE_RUINED) |
|
{ |
|
|
|
EntityAI parent = GetHierarchyParent(); |
|
if (parent && parent.IsFireplace()) |
|
{ |
|
CargoBase cargo = GetInventory().GetCargo(); |
|
if (cargo) |
|
{ |
|
for (int i = 0; i < cargo.GetItemCount(); ++i) |
|
{ |
|
parent.GetInventory().TakeEntityToInventory(InventoryMode.SERVER, FindInventoryLocationType.CARGO, cargo.GetItem(i)); |
|
} |
|
} |
|
} |
|
} |
|
|
|
if (IsResultOfSplit()) |
|
{ |
|
|
|
SetResultOfSplit(false); |
|
return; |
|
} |
|
|
|
if (m_Cleanness != 0 && oldLevel < newLevel && newLevel != 0) |
|
{ |
|
SetCleanness(0); |
|
} |
|
} |
|
} |
|
|
|
|
|
override void OnRightClick() |
|
{ |
|
super.OnRightClick(); |
|
|
|
if (CanBeSplit() && !GetDayZGame().IsLeftCtrlDown() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(this,null)) |
|
{ |
|
if (GetGame().IsClient()) |
|
{ |
|
if (ScriptInputUserData.CanStoreInputUserData()) |
|
{ |
|
vector m4[4]; |
|
PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer()); |
|
|
|
EntityAI root = GetHierarchyRoot(); |
|
|
|
InventoryLocation dst = new InventoryLocation; |
|
if (!player.GetInventory().FindFirstFreeLocationForNewEntity(GetType(), FindInventoryLocationType.CARGO, dst)) |
|
{ |
|
if (root) |
|
{ |
|
root.GetTransform(m4); |
|
dst.SetGround(this, m4); |
|
} |
|
else |
|
GetInventory().GetCurrentInventoryLocation(dst); |
|
} |
|
else |
|
{ |
|
dst.SetCargo(dst.GetParent(), this, dst.GetIdx(), dst.GetRow(), dst.GetCol(), dst.GetFlip()); |
|
if (GetGame().GetPlayer().GetInventory().HasInventoryReservation(null, dst)) |
|
{ |
|
if (root) |
|
{ |
|
root.GetTransform(m4); |
|
dst.SetGround(this, m4); |
|
} |
|
else |
|
GetInventory().GetCurrentInventoryLocation(dst); |
|
} |
|
else |
|
{ |
|
GetGame().GetPlayer().GetInventory().AddInventoryReservationEx(null, dst, GameInventory.c_InventoryReservationTimeoutShortMS); |
|
} |
|
} |
|
|
|
ScriptInputUserData ctx = new ScriptInputUserData; |
|
ctx.Write(INPUT_UDT_ITEM_MANIPULATION); |
|
ctx.Write(4); |
|
ItemBase thiz = this; |
|
ctx.Write(thiz); |
|
dst.WriteToContext(ctx); |
|
ctx.Write(true); |
|
ctx.Send(); |
|
} |
|
} |
|
else if (!GetGame().IsMultiplayer()) |
|
{ |
|
SplitItem(PlayerBase.Cast(GetGame().GetPlayer())); |
|
} |
|
} |
|
} |
|
|
|
override bool CanBeCombined(EntityAI other_item, bool reservation_check = true, bool stack_max_limit = false) |
|
{ |
|
|
|
|
|
if (!other_item || GetType() != other_item.GetType() || (IsFullQuantity() && other_item.GetQuantity() > 0) || other_item == this) |
|
return false; |
|
|
|
if (GetHealthLevel() == GameConstants.STATE_RUINED || other_item.GetHealthLevel() == GameConstants.STATE_RUINED) |
|
return false; |
|
|
|
|
|
if (!can_this_be_combined) |
|
return false; |
|
|
|
|
|
Magazine mag = Magazine.Cast(this); |
|
if (mag) |
|
{ |
|
if (mag.GetAmmoCount() >= mag.GetAmmoMax()) |
|
return false; |
|
|
|
if (stack_max_limit) |
|
{ |
|
Magazine other_mag = Magazine.Cast(other_item); |
|
if (other_item) |
|
{ |
|
if (mag.GetAmmoCount() + other_mag.GetAmmoCount() > mag.GetAmmoMax()) |
|
return false; |
|
} |
|
|
|
} |
|
} |
|
else |
|
{ |
|
|
|
if (GetQuantity() >= GetQuantityMax() && other_item.GetQuantity() > 0 ) |
|
return false; |
|
|
|
if (stack_max_limit && (GetQuantity() + other_item.GetQuantity() > GetQuantityMax())) |
|
return false; |
|
} |
|
|
|
PlayerBase player = null; |
|
if (CastTo(player, GetHierarchyRootPlayer())) |
|
{ |
|
if (player.GetInventory().HasAttachment(this)) |
|
return false; |
|
|
|
if (player.IsItemsToDelete()) |
|
return false; |
|
} |
|
|
|
if (reservation_check && (GetInventory().HasInventoryReservation(this, null) || other_item.GetInventory().HasInventoryReservation(other_item, null))) |
|
return false; |
|
|
|
int slotID; |
|
string slotName; |
|
if (GetInventory().GetCurrentAttachmentSlotInfo(slotID,slotName) && GetHierarchyParent().GetInventory().GetSlotLock(slotID)) |
|
return false; |
|
|
|
return true; |
|
} |
|
|
|
bool IsCombineAll(ItemBase other_item, bool use_stack_max = false) |
|
{ |
|
return ComputeQuantityUsed(other_item, use_stack_max) == other_item.GetQuantity(); |
|
} |
|
|
|
bool IsResultOfSplit() |
|
{ |
|
return m_IsResultOfSplit; |
|
} |
|
|
|
void SetResultOfSplit(bool value) |
|
{ |
|
m_IsResultOfSplit = value; |
|
} |
|
|
|
int ComputeQuantityUsed(ItemBase other_item, bool use_stack_max = true) |
|
{ |
|
return ComputeQuantityUsedEx(other_item, use_stack_max); |
|
} |
|
|
|
float ComputeQuantityUsedEx(ItemBase other_item, bool use_stack_max = true) |
|
{ |
|
float other_item_quantity = other_item.GetQuantity(); |
|
float this_free_space; |
|
|
|
float stack_max = GetQuantityMax(); |
|
|
|
this_free_space = stack_max - GetQuantity(); |
|
|
|
if (other_item_quantity > this_free_space) |
|
{ |
|
return this_free_space; |
|
} |
|
else |
|
{ |
|
return other_item_quantity; |
|
} |
|
} |
|
|
|
void CombineItems(ItemBase other_item, bool use_stack_max = true) |
|
{ |
|
if (!CanBeCombined(other_item, false)) |
|
return; |
|
|
|
if (!IsMagazine() && other_item) |
|
{ |
|
float quantity_used = ComputeQuantityUsedEx(other_item,use_stack_max); |
|
if (quantity_used != 0) |
|
{ |
|
float hp1 = GetHealth01("",""); |
|
float hp2 = other_item.GetHealth01("",""); |
|
float hpResult = ((hp1*GetQuantity()) + (hp2*quantity_used)); |
|
hpResult = hpResult / (GetQuantity() + quantity_used); |
|
|
|
hpResult *= GetMaxHealth(); |
|
Math.Round(hpResult); |
|
SetHealth("", "Health", hpResult); |
|
|
|
AddQuantity(quantity_used); |
|
other_item.AddQuantity(-quantity_used); |
|
} |
|
} |
|
OnCombine(other_item); |
|
} |
|
|
|
void OnCombine(ItemBase other_item) |
|
{ |
|
#ifdef SERVER |
|
if (!GetHierarchyRootPlayer() && GetHierarchyParent()) |
|
GetHierarchyParent().IncreaseLifetimeUp(); |
|
#endif |
|
}; |
|
|
|
void GetRecipesActions(Man player, out TSelectableActionInfoArray outputList) |
|
{ |
|
PlayerBase p = PlayerBase.Cast(player); |
|
|
|
array<int> recipesIds = p.m_Recipes; |
|
PluginRecipesManager moduleRecipesManager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager)); |
|
if (moduleRecipesManager) |
|
{ |
|
EntityAI itemInHands = player.GetHumanInventory().GetEntityInHands(); |
|
moduleRecipesManager.GetValidRecipes(ItemBase.Cast(this), ItemBase.Cast(itemInHands), recipesIds, p); |
|
} |
|
|
|
for (int i = 0;i < recipesIds.Count(); i++) |
|
{ |
|
int key = recipesIds.Get(i); |
|
string recipeName = moduleRecipesManager.GetRecipeName(key); |
|
outputList.Insert(new TSelectableActionInfo(SAT_CRAFTING, key, recipeName)); |
|
} |
|
} |
|
|
|
|
|
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList) |
|
{ |
|
super.GetDebugActions(outputList); |
|
|
|
|
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_QUANTITY, "Quantity +20%", FadeColors.LIGHT_GREY)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_QUANTITY, "Quantity -20%", FadeColors.LIGHT_GREY)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SET_QUANTITY_0, "Set Quantity 0", FadeColors.LIGHT_GREY)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SET_MAX_QUANTITY, "Set Quantity Max", FadeColors.LIGHT_GREY)); |
|
|
|
|
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_HEALTH, "Health +20%", FadeColors.LIGHT_GREY)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_HEALTH, "Health -20%", FadeColors.LIGHT_GREY)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DESTROY_HEALTH, "Health 0", FadeColors.LIGHT_GREY)); |
|
|
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_TEMPERATURE, "Temperature +20", FadeColors.LIGHT_GREY)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_TEMPERATURE, "Temperature -20", FadeColors.LIGHT_GREY)); |
|
|
|
|
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ADD_WETNESS, "Wetness +20", FadeColors.LIGHT_GREY)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.REMOVE_WETNESS, "Wetness -20", FadeColors.LIGHT_GREY)); |
|
|
|
|
|
if (IsLiquidContainer()) |
|
{ |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.LIQUIDTYPE_UP, "LiquidType Next", FadeColors.LIGHT_GREY)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.LIQUIDTYPE_DOWN, "LiquidType Previous", FadeColors.LIGHT_GREY)); |
|
} |
|
|
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.MAKE_SPECIAL, "Make Special", FadeColors.LIGHT_GREY)); |
|
|
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.WATCH_ITEM, "Watch (CTRL-Z)", FadeColors.LIGHT_GREY)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.WATCH_PLAYER, "Watch Player", FadeColors.LIGHT_GREY)); |
|
|
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.RED)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DELETE, "Delete", FadeColors.RED)); |
|
outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "", FadeColors.RED)); |
|
} |
|
|
|
|
|
|
|
|
|
override bool OnAction(int action_id, Man player, ParamsReadContext ctx) |
|
{ |
|
super.OnAction(action_id, player, ctx); |
|
if (action_id >= EActions.RECIPES_RANGE_START && action_id < EActions.RECIPES_RANGE_END) |
|
{ |
|
PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager)); |
|
int idWithoutOffset = action_id - EActions.RECIPES_RANGE_START; |
|
PlayerBase p = PlayerBase.Cast(player); |
|
if (EActions.RECIPES_RANGE_START < 1000) |
|
{ |
|
float anim_length = plugin_recipes_manager.GetRecipeLengthInSecs(idWithoutOffset); |
|
float specialty_weight = plugin_recipes_manager.GetRecipeSpecialty(idWithoutOffset); |
|
} |
|
} |
|
#ifndef SERVER |
|
else if (action_id == EActions.WATCH_PLAYER) |
|
{ |
|
PluginDeveloper.SetDeveloperItemClientEx(player); |
|
} |
|
#endif |
|
if (GetGame().IsServer()) |
|
{ |
|
if (action_id >= EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_START && action_id < EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_END) |
|
{ |
|
int id = action_id - EActions.DEBUG_ITEM_WATCH_BUTTON_RANGE_START; |
|
OnDebugButtonPressServer(id + 1); |
|
} |
|
|
|
else if (action_id >= EActions.DEBUG_AGENTS_RANGE_INJECT_START && action_id < EActions.DEBUG_AGENTS_RANGE_INJECT_END) |
|
{ |
|
int agent_id = action_id - EActions.DEBUG_AGENTS_RANGE_INJECT_START; |
|
InsertAgent(agent_id,100); |
|
} |
|
|
|
else if (action_id >= EActions.DEBUG_AGENTS_RANGE_REMOVE_START && action_id < EActions.DEBUG_AGENTS_RANGE_REMOVE_END) |
|
{ |
|
int agent_id2 = action_id - EActions.DEBUG_AGENTS_RANGE_REMOVE_START; |
|
RemoveAgent(agent_id2); |
|
} |
|
|
|
else if (action_id == EActions.ADD_QUANTITY) |
|
{ |
|
if (IsMagazine()) |
|
{ |
|
Magazine mag = Magazine.Cast(this); |
|
mag.ServerSetAmmoCount(mag.GetAmmoCount() + mag.GetAmmoMax() * 0.2); |
|
} |
|
else |
|
{ |
|
AddQuantity(GetQuantityMax() * 0.2); |
|
} |
|
|
|
if (m_EM) |
|
{ |
|
m_EM.AddEnergy(m_EM.GetEnergyMax() * 0.2); |
|
} |
|
|
|
} |
|
|
|
else if (action_id == EActions.REMOVE_QUANTITY) |
|
{ |
|
if (IsMagazine()) |
|
{ |
|
Magazine mag2 = Magazine.Cast(this); |
|
mag2.ServerSetAmmoCount(mag2.GetAmmoCount() - mag2.GetAmmoMax() * 0.2); |
|
} |
|
else |
|
{ |
|
AddQuantity(- GetQuantityMax() * 0.2); |
|
} |
|
if (m_EM) |
|
{ |
|
m_EM.AddEnergy(- m_EM.GetEnergyMax() * 0.2); |
|
} |
|
|
|
} |
|
|
|
else if (action_id == EActions.SET_QUANTITY_0) |
|
{ |
|
SetQuantity(0); |
|
|
|
if (m_EM) |
|
{ |
|
m_EM.SetEnergy(0); |
|
} |
|
} |
|
|
|
else if (action_id == EActions.SET_MAX_QUANTITY) |
|
{ |
|
SetQuantityMax(); |
|
|
|
if (m_EM) |
|
{ |
|
m_EM.SetEnergy(m_EM.GetEnergyMax()); |
|
} |
|
} |
|
|
|
else if (action_id == EActions.ADD_HEALTH) |
|
{ |
|
AddHealth("","",GetMaxHealth("","Health")/5); |
|
} |
|
else if (action_id == EActions.REMOVE_HEALTH) |
|
{ |
|
AddHealth("","",-GetMaxHealth("","Health")/5); |
|
} |
|
else if (action_id == EActions.DESTROY_HEALTH) |
|
{ |
|
SetHealth01("","",0); |
|
} |
|
else if (action_id == EActions.WATCH_ITEM) |
|
{ |
|
PluginItemDiagnostic mid = PluginItemDiagnostic.Cast(GetPlugin(PluginItemDiagnostic)); |
|
mid.RegisterDebugItem(ItemBase.Cast(this), PlayerBase.Cast(player)); |
|
#ifdef DEVELOPER |
|
SetDebugDeveloper_item(this); |
|
#endif |
|
} |
|
|
|
else if (action_id == EActions.ADD_TEMPERATURE) |
|
{ |
|
AddTemperature(20); |
|
|
|
} |
|
|
|
else if (action_id == EActions.REMOVE_TEMPERATURE) |
|
{ |
|
AddTemperature(-20); |
|
|
|
} |
|
|
|
else if (action_id == EActions.ADD_WETNESS) |
|
{ |
|
AddWet(GetWetMax()/5); |
|
|
|
} |
|
|
|
else if (action_id == EActions.REMOVE_WETNESS) |
|
{ |
|
AddWet(-GetWetMax()/5); |
|
|
|
} |
|
|
|
else if (action_id == EActions.LIQUIDTYPE_UP) |
|
{ |
|
int curr_type = GetLiquidType(); |
|
SetLiquidType(curr_type * 2); |
|
|
|
|
|
} |
|
|
|
else if (action_id == EActions.LIQUIDTYPE_DOWN) |
|
{ |
|
int curr_type2 = GetLiquidType(); |
|
SetLiquidType(curr_type2 / 2); |
|
} |
|
|
|
else if (action_id == EActions.MAKE_SPECIAL) |
|
{ |
|
auto debugParams = DebugSpawnParams.WithPlayer(player); |
|
OnDebugSpawnEx(debugParams); |
|
} |
|
|
|
else if (action_id == EActions.DELETE) |
|
{ |
|
Delete(); |
|
} |
|
|
|
} |
|
|
|
|
|
return false; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
void OnActivatedByTripWire(); |
|
|
|
|
|
void OnActivatedByItem(notnull ItemBase item); |
|
|
|
|
|
|
|
bool CanExplodeInFire() |
|
{ |
|
return false; |
|
} |
|
|
|
|
|
bool CanEat() |
|
{ |
|
return true; |
|
} |
|
|
|
|
|
override bool IsIgnoredByConstruction() |
|
{ |
|
return true; |
|
} |
|
|
|
|
|
|
|
bool HasFoodStage() |
|
{ |
|
string config_path = string.Format("CfgVehicles %1 Food FoodStages", GetType()); |
|
return GetGame().ConfigIsExisting(config_path); |
|
} |
|
|
|
bool CanBeCooked() |
|
{ |
|
return false; |
|
} |
|
|
|
bool CanBeCookedOnStick() |
|
{ |
|
return false; |
|
} |
|
|
|
|
|
bool CanRepair(ItemBase item_repair_kit) |
|
{ |
|
PluginRepairing module_repairing = PluginRepairing.Cast(GetPlugin(PluginRepairing)); |
|
return module_repairing.CanRepair(this, item_repair_kit); |
|
} |
|
|
|
|
|
bool Repair(PlayerBase player, ItemBase item_repair_kit, float specialty_weight) |
|
{ |
|
PluginRepairing module_repairing = PluginRepairing.Cast(GetPlugin(PluginRepairing)); |
|
return module_repairing.Repair(player, this, item_repair_kit, specialty_weight); |
|
} |
|
|
|
|
|
int GetItemSize() |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1; |
|
} |
|
|
|
|
|
|
|
bool CanBeMovedOverride() |
|
{ |
|
return m_CanBeMovedOverride; |
|
} |
|
|
|
|
|
|
|
void SetCanBeMovedOverride(bool setting) |
|
{ |
|
m_CanBeMovedOverride = setting; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MessageToOwnerStatus(string text) |
|
{ |
|
PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer()); |
|
|
|
if (player) |
|
{ |
|
player.MessageStatus(text); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MessageToOwnerAction(string text) |
|
{ |
|
PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer()); |
|
|
|
if (player) |
|
{ |
|
player.MessageAction(text); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MessageToOwnerFriendly(string text) |
|
{ |
|
PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer()); |
|
|
|
if (player) |
|
{ |
|
player.MessageFriendly(text); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MessageToOwnerImportant(string text) |
|
{ |
|
PlayerBase player = PlayerBase.Cast(this.GetHierarchyRootPlayer()); |
|
|
|
if (player) |
|
{ |
|
player.MessageImportant(text); |
|
} |
|
} |
|
|
|
override bool IsItemBase() |
|
{ |
|
return true; |
|
} |
|
|
|
|
|
override bool KindOf(string tag) |
|
{ |
|
bool found = false; |
|
string item_name = this.GetType(); |
|
ref TStringArray item_tag_array = new TStringArray; |
|
GetGame().ConfigGetTextArray("cfgVehicles " + item_name + " itemInfo", item_tag_array); |
|
|
|
int array_size = item_tag_array.Count(); |
|
for (int i = 0; i < array_size; i++) |
|
{ |
|
if (item_tag_array.Get(i) == tag) |
|
{ |
|
found = true; |
|
break; |
|
} |
|
} |
|
return found; |
|
} |
|
|
|
|
|
override void OnRPC(PlayerIdentity sender, int rpc_type,ParamsReadContext ctx) |
|
{ |
|
|
|
super.OnRPC(sender, rpc_type,ctx); |
|
|
|
|
|
switch (rpc_type) |
|
{ |
|
#ifndef SERVER |
|
case ERPCs.RPC_SOUND_LOCK_ATTACH: |
|
Param2<bool, string> p = new Param2<bool, string>(false, ""); |
|
|
|
if (!ctx.Read(p)) |
|
return; |
|
|
|
bool play = p.param1; |
|
string soundSet = p.param2; |
|
|
|
if (play) |
|
{ |
|
if (m_LockingSound) |
|
{ |
|
if (!m_LockingSound.IsSoundPlaying()) |
|
{ |
|
m_LockingSound = SEffectManager.PlaySound(soundSet, GetPosition(), 0, 0, true); |
|
} |
|
} |
|
else |
|
{ |
|
m_LockingSound = SEffectManager.PlaySound(soundSet, GetPosition(), 0, 0, true); |
|
} |
|
} |
|
else |
|
{ |
|
SEffectManager.DestroyEffect(m_LockingSound); |
|
} |
|
|
|
break; |
|
#endif |
|
|
|
} |
|
|
|
if (GetWrittenNoteData()) |
|
{ |
|
GetWrittenNoteData().OnRPC(sender, rpc_type,ctx); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TransferVariablesFloat(array<float> float_vars) |
|
{ |
|
DeSerializeNumericalVars(float_vars); |
|
} |
|
|
|
array<float> GetVariablesFloat() |
|
{ |
|
CachedObjectsArrays.ARRAY_FLOAT.Clear(); |
|
SerializeNumericalVars(CachedObjectsArrays.ARRAY_FLOAT); |
|
return CachedObjectsArrays.ARRAY_FLOAT; |
|
} |
|
|
|
int NameToID(string name) |
|
{ |
|
PluginVariables plugin = PluginVariables.Cast(GetPlugin(PluginVariables)); |
|
return plugin.GetID(name); |
|
} |
|
|
|
string IDToName(int id) |
|
{ |
|
PluginVariables plugin = PluginVariables.Cast(GetPlugin(PluginVariables)); |
|
return plugin.GetName(id); |
|
} |
|
|
|
void OnSyncVariables(ParamsReadContext ctx) |
|
{ |
|
|
|
|
|
|
|
int varFlags; |
|
if (!ctx.Read(varFlags)) |
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (varFlags & ItemVariableFlags.FLOAT) |
|
{ |
|
ReadVarsFromCTX(ctx); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
void SerializeNumericalVars(array<float> floats_out) |
|
{ |
|
|
|
floats_out.Insert(m_VariablesMask); |
|
|
|
if (IsVariableSet(VARIABLE_QUANTITY)) |
|
{ |
|
floats_out.Insert(m_VarQuantity); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_TEMPERATURE)) |
|
{ |
|
floats_out.Insert(m_VarTemperature); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_WET)) |
|
{ |
|
floats_out.Insert(m_VarWet); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_LIQUIDTYPE)) |
|
{ |
|
floats_out.Insert(m_VarLiquidType); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_COLOR)) |
|
{ |
|
floats_out.Insert(m_ColorComponentR); |
|
floats_out.Insert(m_ColorComponentG); |
|
floats_out.Insert(m_ColorComponentB); |
|
floats_out.Insert(m_ColorComponentA); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_CLEANNESS)) |
|
{ |
|
floats_out.Insert(m_Cleanness); |
|
} |
|
|
|
} |
|
|
|
void DeSerializeNumericalVars(array<float> floats) |
|
{ |
|
|
|
int index = 0; |
|
int mask = Math.Round(floats.Get(index)); |
|
|
|
index++; |
|
|
|
if (mask & VARIABLE_QUANTITY) |
|
{ |
|
if (m_IsStoreLoad) |
|
{ |
|
m_StoreLoadedQuantity = floats.Get(index); |
|
} |
|
else |
|
{ |
|
float quantity = floats.Get(index); |
|
SetQuantity(quantity, true, false, false, false); |
|
} |
|
index++; |
|
} |
|
|
|
if (mask & VARIABLE_TEMPERATURE) |
|
{ |
|
float temperature = floats.Get(index); |
|
SetTemperature(temperature); |
|
index++; |
|
} |
|
|
|
if (mask & VARIABLE_WET) |
|
{ |
|
float wet = floats.Get(index); |
|
SetWet(wet); |
|
index++; |
|
} |
|
|
|
if (mask & VARIABLE_LIQUIDTYPE) |
|
{ |
|
int liquidtype = Math.Round(floats.Get(index)); |
|
SetLiquidType(liquidtype); |
|
index++; |
|
} |
|
|
|
if (mask & VARIABLE_COLOR) |
|
{ |
|
m_ColorComponentR = Math.Round(floats.Get(index)); |
|
index++; |
|
m_ColorComponentG = Math.Round(floats.Get(index)); |
|
index++; |
|
m_ColorComponentB = Math.Round(floats.Get(index)); |
|
index++; |
|
m_ColorComponentA = Math.Round(floats.Get(index)); |
|
index++; |
|
} |
|
if (mask & VARIABLE_CLEANNESS) |
|
{ |
|
int cleanness = Math.Round(floats.Get(index)); |
|
SetCleanness(cleanness); |
|
index++; |
|
} |
|
|
|
} |
|
|
|
|
|
void WriteVarsToCTX(ParamsWriteContext ctx) |
|
{ |
|
ctx.Write(m_VariablesMask); |
|
|
|
|
|
if (IsVariableSet(VARIABLE_QUANTITY)) |
|
{ |
|
ctx.Write(m_VarQuantity); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_TEMPERATURE)) |
|
{ |
|
ctx.Write(m_VarTemperature); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_WET)) |
|
{ |
|
ctx.Write(m_VarWet); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_LIQUIDTYPE)) |
|
{ |
|
ctx.Write(m_VarLiquidType); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_COLOR)) |
|
{ |
|
ctx.Write(m_ColorComponentR); |
|
ctx.Write(m_ColorComponentG); |
|
ctx.Write(m_ColorComponentB); |
|
ctx.Write(m_ColorComponentA); |
|
} |
|
|
|
if (IsVariableSet(VARIABLE_CLEANNESS)) |
|
{ |
|
ctx.Write(m_Cleanness); |
|
} |
|
} |
|
|
|
bool ReadVarsFromCTX(ParamsReadContext ctx, int version = -1) |
|
{ |
|
int numOfItems; |
|
int intValue; |
|
float value; |
|
if (version <= 108 && version!= -1) |
|
{ |
|
if (!ctx.Read(CachedObjectsParams.PARAM1_INT)) |
|
return false; |
|
|
|
numOfItems = CachedObjectsParams.PARAM1_INT.param1; |
|
CachedObjectsArrays.ARRAY_FLOAT.Clear(); |
|
|
|
for (int i = 0; i < numOfItems; i++) |
|
{ |
|
if (!ctx.Read(CachedObjectsParams.PARAM1_FLOAT)) |
|
return false; |
|
value = CachedObjectsParams.PARAM1_FLOAT.param1; |
|
|
|
CachedObjectsArrays.ARRAY_FLOAT.Insert(value); |
|
} |
|
|
|
DeSerializeNumericalVars(CachedObjectsArrays.ARRAY_FLOAT); |
|
return true; |
|
} |
|
else if (version <= 116 && version!= -1) |
|
{ |
|
if (!ctx.Read(numOfItems)) |
|
return false; |
|
|
|
CachedObjectsArrays.ARRAY_FLOAT.Clear(); |
|
|
|
for (int j = 0; j < numOfItems; j++) |
|
{ |
|
if (!ctx.Read(value)) |
|
return false; |
|
CachedObjectsArrays.ARRAY_FLOAT.Insert(value); |
|
} |
|
|
|
DeSerializeNumericalVars(CachedObjectsArrays.ARRAY_FLOAT); |
|
return true; |
|
} |
|
else |
|
{ |
|
int mask; |
|
if (!ctx.Read(mask)) |
|
return false; |
|
|
|
if (mask & VARIABLE_QUANTITY) |
|
{ |
|
if (!ctx.Read(value)) |
|
return false; |
|
|
|
if (m_IsStoreLoad) |
|
{ |
|
m_StoreLoadedQuantity = value; |
|
} |
|
else |
|
{ |
|
SetQuantity(value, true, false, false, false); |
|
} |
|
} |
|
|
|
if (mask & VARIABLE_TEMPERATURE) |
|
{ |
|
if (!ctx.Read(value)) |
|
return false; |
|
SetTemperature(value); |
|
} |
|
|
|
if (mask & VARIABLE_WET) |
|
{ |
|
if (!ctx.Read(value)) |
|
return false; |
|
SetWet(value); |
|
} |
|
|
|
if (mask & VARIABLE_LIQUIDTYPE) |
|
{ |
|
if (!ctx.Read(intValue)) |
|
return false; |
|
SetLiquidType(intValue); |
|
} |
|
|
|
if (mask & VARIABLE_COLOR) |
|
{ |
|
if (!ctx.Read(intValue)) |
|
return false; |
|
|
|
m_ColorComponentR = intValue; |
|
if (!ctx.Read(value)) |
|
return false; |
|
|
|
m_ColorComponentG = intValue; |
|
if (!ctx.Read(value)) |
|
return false; |
|
|
|
m_ColorComponentB = intValue; |
|
if (!ctx.Read(value)) |
|
return false; |
|
|
|
m_ColorComponentA = intValue; |
|
} |
|
|
|
if (mask & VARIABLE_CLEANNESS) |
|
{ |
|
if (!ctx.Read(intValue)) |
|
return false; |
|
SetCleanness(intValue); |
|
} |
|
} |
|
return true; |
|
} |
|
|
|
void SaveVariables(ParamsWriteContext ctx) |
|
{ |
|
|
|
|
|
|
|
|
|
int varFlags = 0; |
|
|
|
if (m_VariablesMask) |
|
varFlags = ItemVariableFlags.FLOAT; |
|
|
|
ctx.Write(varFlags); |
|
|
|
|
|
|
|
|
|
|
|
if (m_VariablesMask) |
|
WriteVarsToCTX(ctx); |
|
} |
|
|
|
|
|
|
|
bool LoadVariables(ParamsReadContext ctx, int version = -1) |
|
{ |
|
int varFlags; |
|
if (version <= 108 && version != -1) |
|
{ |
|
|
|
if (!ctx.Read(CachedObjectsParams.PARAM1_INT)) |
|
{ |
|
return false; |
|
} |
|
else |
|
{ |
|
varFlags = CachedObjectsParams.PARAM1_INT.param1; |
|
|
|
if (varFlags & ItemVariableFlags.FLOAT) |
|
{ |
|
if (!ReadVarsFromCTX(ctx, version)) |
|
return false; |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
|
|
if (!ctx.Read(varFlags)) |
|
{ |
|
return false; |
|
} |
|
else |
|
{ |
|
|
|
if (varFlags & ItemVariableFlags.FLOAT) |
|
{ |
|
if (!ReadVarsFromCTX(ctx, version)) |
|
return false; |
|
} |
|
} |
|
} |
|
return true; |
|
} |
|
|
|
|
|
|
|
override bool OnStoreLoad(ParamsReadContext ctx, int version) |
|
{ |
|
m_IsStoreLoad = true; |
|
|
|
if (GetDamageSystemVersionChange() != -1 && version < GetDamageSystemVersionChange()) |
|
{ |
|
m_FixDamageSystemInit = true; |
|
} |
|
|
|
if (!super.OnStoreLoad(ctx, version)) |
|
{ |
|
m_IsStoreLoad = false; |
|
return false; |
|
} |
|
|
|
if (version >= 114) |
|
{ |
|
bool hasQuickBarIndexSaved; |
|
|
|
if (!ctx.Read(hasQuickBarIndexSaved)) |
|
{ |
|
m_IsStoreLoad = false; |
|
return false; |
|
} |
|
|
|
if (hasQuickBarIndexSaved) |
|
{ |
|
int itmQBIndex; |
|
|
|
|
|
if (!ctx.Read(itmQBIndex)) |
|
{ |
|
m_IsStoreLoad = false; |
|
return false; |
|
} |
|
|
|
PlayerBase parentPlayer = PlayerBase.Cast(GetHierarchyRootPlayer()); |
|
if (itmQBIndex != -1 && parentPlayer) |
|
parentPlayer.SetLoadedQuickBarItemBind(this, itmQBIndex); |
|
} |
|
} |
|
else |
|
{ |
|
|
|
PlayerBase player; |
|
int itemQBIndex; |
|
if (version == int.MAX) |
|
{ |
|
if (!ctx.Read(itemQBIndex)) |
|
{ |
|
m_IsStoreLoad = false; |
|
return false; |
|
} |
|
} |
|
else if (Class.CastTo(player, GetHierarchyRootPlayer())) |
|
{ |
|
|
|
if (!ctx.Read(itemQBIndex)) |
|
{ |
|
m_IsStoreLoad = false; |
|
return false; |
|
} |
|
if (itemQBIndex != -1 && player) |
|
player.SetLoadedQuickBarItemBind(this,itemQBIndex); |
|
} |
|
} |
|
|
|
|
|
if (!LoadVariables(ctx, version)) |
|
{ |
|
m_IsStoreLoad = false; |
|
return false; |
|
} |
|
|
|
|
|
if (!LoadAgents(ctx, version)) |
|
{ |
|
m_IsStoreLoad = false; |
|
return false; |
|
} |
|
if (version >= 132) |
|
{ |
|
RemotelyActivatedItemBehaviour raib = GetRemotelyActivatedItemBehaviour(); |
|
if (raib) |
|
{ |
|
if (!raib.OnStoreLoad(ctx,version)) |
|
{ |
|
m_IsStoreLoad = false; |
|
return false; |
|
} |
|
} |
|
} |
|
|
|
m_IsStoreLoad = false; |
|
return true; |
|
} |
|
|
|
|
|
|
|
override void OnStoreSave(ParamsWriteContext ctx) |
|
{ |
|
super.OnStoreSave(ctx); |
|
PlayerBase player; |
|
if (PlayerBase.CastTo(player,GetHierarchyRootPlayer())) |
|
{ |
|
ctx.Write(true); |
|
|
|
int itemQBIndex = -1; |
|
itemQBIndex = player.FindQuickBarEntityIndex(this); |
|
ctx.Write(itemQBIndex); |
|
} |
|
else |
|
{ |
|
ctx.Write(false); |
|
} |
|
|
|
SaveVariables(ctx); |
|
SaveAgents(ctx); |
|
|
|
RemotelyActivatedItemBehaviour raib = GetRemotelyActivatedItemBehaviour(); |
|
if (raib) |
|
{ |
|
raib.OnStoreSave(ctx); |
|
} |
|
} |
|
|
|
|
|
override void AfterStoreLoad() |
|
{ |
|
super.AfterStoreLoad(); |
|
|
|
if (m_FixDamageSystemInit) |
|
{ |
|
PerformDamageSystemReinit(); |
|
} |
|
|
|
if (m_StoreLoadedQuantity != float.LOWEST) |
|
{ |
|
SetQuantity(m_StoreLoadedQuantity); |
|
m_StoreLoadedQuantity = float.LOWEST; |
|
} |
|
} |
|
|
|
override void EEOnAfterLoad() |
|
{ |
|
super.EEOnAfterLoad(); |
|
|
|
if (m_FixDamageSystemInit) |
|
{ |
|
m_FixDamageSystemInit = false; |
|
} |
|
|
|
if (GetRemotelyActivatedItemBehaviour()) |
|
GetRemotelyActivatedItemBehaviour().OnAfterLoad(); |
|
} |
|
|
|
bool CanBeDisinfected() |
|
{ |
|
return false; |
|
} |
|
|
|
|
|
|
|
override void OnVariablesSynchronized() |
|
{ |
|
if (m_Initialized) |
|
{ |
|
#ifdef PLATFORM_CONSOLE |
|
|
|
if (m_CanThisBeSplit) |
|
{ |
|
UIScriptedMenu menu = GetGame().GetUIManager().FindMenu(MENU_INVENTORY); |
|
if (menu) |
|
{ |
|
menu.Refresh(); |
|
} |
|
} |
|
#endif |
|
} |
|
|
|
if (CanPlayDeployLoopSound()) |
|
{ |
|
PlayDeployLoopSoundEx(); |
|
} |
|
|
|
if (m_DeployLoopSoundEx && !CanPlayDeployLoopSound()) |
|
{ |
|
StopDeployLoopSoundEx(); |
|
} |
|
|
|
if (IsDeploySound()) |
|
{ |
|
PlayDeploySound(); |
|
} |
|
|
|
if (!dBodyIsDynamic(this) && m_WantPlayImpactSound) |
|
{ |
|
PlayImpactSound(m_ConfigWeight, m_ImpactSpeed, m_ImpactSoundSurfaceHash); |
|
m_WantPlayImpactSound = false; |
|
} |
|
|
|
if (m_VarQuantity != m_VarQuantityPrev) |
|
{ |
|
SetWeightDirty(); |
|
m_VarQuantityPrev = m_VarQuantity; |
|
} |
|
if (m_VarWet != m_VarWetPrev) |
|
{ |
|
OnWetChanged(m_VarWet,m_VarWetPrev); |
|
m_VarWetPrev = m_VarWet; |
|
} |
|
|
|
super.OnVariablesSynchronized(); |
|
} |
|
|
|
|
|
|
|
|
|
bool SetQuantity(float value, bool destroy_config = true, bool destroy_forced = false, bool allow_client = false, bool clamp_to_stack_max = true) |
|
{ |
|
if (!IsServerCheck(allow_client)) |
|
return false; |
|
|
|
if (!HasQuantity()) |
|
return false; |
|
|
|
if (IsLiquidContainer() && GetLiquidType() == 0) |
|
{ |
|
Debug.LogError("No LiquidType specified, try setting 'varLiquidTypeInit' to a particular liquid type"); |
|
return false; |
|
} |
|
|
|
float min = GetQuantityMin(); |
|
float max = GetQuantityMax(); |
|
|
|
if (value <= (min + 0.001)) |
|
value = min; |
|
|
|
if (value == min) |
|
{ |
|
if (destroy_config) |
|
{ |
|
bool dstr = ConfigGetBool("varQuantityDestroyOnMin"); |
|
if (dstr) |
|
{ |
|
m_VarQuantity = Math.Clamp(value, min, max); |
|
this.Delete(); |
|
return true; |
|
} |
|
} |
|
else if (destroy_forced) |
|
{ |
|
m_VarQuantity = Math.Clamp(value, min, max); |
|
this.Delete(); |
|
return true; |
|
} |
|
|
|
RemoveAllAgents(); |
|
} |
|
|
|
float delta = m_VarQuantity; |
|
m_VarQuantity = Math.Clamp(value, min, max); |
|
|
|
if (m_StoreLoadedQuantity == float.LOWEST) |
|
{ |
|
delta = m_VarQuantity - delta; |
|
|
|
if (delta) |
|
{ |
|
OnQuantityChanged(delta); |
|
} |
|
} |
|
|
|
SetVariableMask(VARIABLE_QUANTITY); |
|
|
|
return false; |
|
} |
|
|
|
|
|
|
|
bool AddQuantity(float value, bool destroy_config = true, bool destroy_forced = false) |
|
{ |
|
return SetQuantity(GetQuantity() + value, destroy_config, destroy_forced); |
|
} |
|
|
|
void SetQuantityMax() |
|
{ |
|
float max = GetQuantityMax(); |
|
SetQuantity(max); |
|
} |
|
|
|
override void SetQuantityToMinimum() |
|
{ |
|
float min = GetQuantityMin(); |
|
SetQuantity(min); |
|
} |
|
|
|
|
|
void SetQuantityNormalized(float value, bool destroy_config = true, bool destroy_forced = false) |
|
{ |
|
float value_clamped = Math.Clamp(value, 0, 1); |
|
int result = Math.Round(Math.Lerp(GetQuantityMin(), GetQuantityMax(), value_clamped)); |
|
SetQuantity(result, destroy_config, destroy_forced); |
|
} |
|
|
|
|
|
|
|
float GetQuantityNormalized() |
|
{ |
|
return Math.InverseLerp(GetQuantityMin(), GetQuantityMax(),m_VarQuantity); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override int GetQuantityMax() |
|
{ |
|
float max = 0; |
|
|
|
InventoryLocation il = new InventoryLocation; |
|
if (GetInventory()) |
|
GetInventory().GetCurrentInventoryLocation(il); |
|
|
|
int slot = il.GetSlot(); |
|
|
|
if (slot != -1) |
|
max = InventorySlots.GetStackMaxForSlotId(slot); |
|
|
|
if (max <= 0) |
|
max = m_VarStackMax; |
|
|
|
if (max <= 0) |
|
max = m_VarQuantityMax; |
|
|
|
return max; |
|
} |
|
|
|
override int GetTargetQuantityMax(int attSlotID = -1) |
|
{ |
|
float quantity_max = 0; |
|
|
|
if (attSlotID != -1) |
|
quantity_max = InventorySlots.GetStackMaxForSlotId(attSlotID); |
|
|
|
if (quantity_max <= 0) |
|
quantity_max = m_VarStackMax; |
|
|
|
if (quantity_max <= 0) |
|
quantity_max = m_VarQuantityMax; |
|
|
|
return quantity_max; |
|
} |
|
|
|
int GetQuantityMin() |
|
{ |
|
return m_VarQuantityMin; |
|
} |
|
|
|
int GetQuantityInit() |
|
{ |
|
return m_VarQuantityInit; |
|
} |
|
|
|
|
|
bool HasQuantity() |
|
{ |
|
return !(GetQuantityMax() - GetQuantityMin() == 0); |
|
} |
|
|
|
override float GetQuantity() |
|
{ |
|
return m_VarQuantity; |
|
} |
|
|
|
bool IsFullQuantity() |
|
{ |
|
return GetQuantity() >= GetQuantityMax(); |
|
} |
|
|
|
|
|
override float GetSingleInventoryItemWeightEx() |
|
{ |
|
|
|
float weightEx = GetWeightEx(); |
|
float special = GetInventoryAndCargoWeight(); |
|
return weightEx - special; |
|
} |
|
|
|
|
|
float GetSingleInventoryItemWeight() |
|
{ |
|
return GetSingleInventoryItemWeightEx(); |
|
} |
|
|
|
override protected float GetWeightSpecialized(bool forceRecalc = false) |
|
{ |
|
if (m_CanThisBeSplit) |
|
{ |
|
#ifdef DEVELOPER |
|
if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED) |
|
{ |
|
WeightDebugData data1 = WeightDebug.GetWeightDebug(this); |
|
data1.SetCalcDetails("TIB1: " + GetConfigWeightModifiedDebugText() +" * " + GetQuantity()+"(quantity)"); |
|
} |
|
#endif |
|
|
|
return GetQuantity() * GetConfigWeightModified(); |
|
} |
|
else if (HasEnergyManager()) |
|
{ |
|
#ifdef DEVELOPER |
|
if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED) |
|
{ |
|
WeightDebugData data2 = WeightDebug.GetWeightDebug(this); |
|
data2.SetCalcDetails("TIB2: "+super.GetWeightSpecialized(forceRecalc)+"(contents weight) + " + GetConfigWeightModifiedDebugText() +" + " + GetCompEM().GetEnergy()+"(energy) * " + ConfigGetFloat("weightPerQuantityUnit") +"(weightPerQuantityUnit)"); |
|
} |
|
#endif |
|
return super.GetWeightSpecialized(forceRecalc) + (GetCompEM().GetEnergy() * ConfigGetFloat("weightPerQuantityUnit")) + GetConfigWeightModified()); |
|
} |
|
else |
|
{ |
|
#ifdef DEVELOPER |
|
if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED) |
|
{ |
|
WeightDebugData data3 = WeightDebug.GetWeightDebug(this); |
|
data3.SetCalcDetails("TIB3: "+super.GetWeightSpecialized(forceRecalc)+"(contents weight) + " + GetConfigWeightModifiedDebugText() +" + " + GetQuantity()+"(quantity) * " + ConfigGetFloat("weightPerQuantityUnit") +"(weightPerQuantityUnit))"); |
|
} |
|
#endif |
|
return super.GetWeightSpecialized(forceRecalc) + (GetQuantity() * ConfigGetFloat("weightPerQuantityUnit")) + GetConfigWeightModified()); |
|
} |
|
} |
|
|
|
|
|
int GetNumberOfItems() |
|
{ |
|
int item_count = 0; |
|
ItemBase item; |
|
|
|
if (GetInventory().GetCargo() != NULL) |
|
{ |
|
item_count = GetInventory().GetCargo().GetItemCount(); |
|
} |
|
|
|
for (int i = 0; i < GetInventory().AttachmentCount(); i++) |
|
{ |
|
Class.CastTo(item,GetInventory().GetAttachmentFromIndex(i)); |
|
if (item) |
|
item_count += item.GetNumberOfItems(); |
|
} |
|
return item_count; |
|
} |
|
|
|
|
|
float GetUnitWeight(bool include_wetness = true) |
|
{ |
|
float weight = 0; |
|
float wetness = 1; |
|
if (include_wetness) |
|
wetness += GetWet(); |
|
if (m_CanThisBeSplit) |
|
{ |
|
weight = wetness * m_ConfigWeight; |
|
} |
|
else if (ConfigGetFloat("liquidContainerType") > 0) |
|
{ |
|
weight = 1; |
|
} |
|
return weight; |
|
} |
|
|
|
void SetVariableMask(int variable) |
|
{ |
|
m_VariablesMask = variable | m_VariablesMask; |
|
if (GetGame().IsServer()) |
|
{ |
|
SetSynchDirty(); |
|
} |
|
} |
|
|
|
|
|
void RemoveItemVariable(int variable) |
|
{ |
|
m_VariablesMask = ~variable & m_VariablesMask; |
|
} |
|
|
|
|
|
bool IsVariableSet(int variable) |
|
{ |
|
return (variable & m_VariablesMask); |
|
} |
|
|
|
|
|
|
|
override void ClearInventory() |
|
{ |
|
if ((GetGame().IsServer() || !GetGame().IsMultiplayer()) && GetInventory()) |
|
{ |
|
GameInventory inv = GetInventory(); |
|
array<EntityAI> items = new array<EntityAI>; |
|
inv.EnumerateInventory(InventoryTraversalType.INORDER, items); |
|
for (int i = 0; i < items.Count(); i++) |
|
{ |
|
ItemBase item = ItemBase.Cast(items.Get(i)); |
|
if (item) |
|
{ |
|
GetGame().ObjectDelete(item); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
float GetEnergy() |
|
{ |
|
float energy = 0; |
|
if (HasEnergyManager()) |
|
{ |
|
energy = GetCompEM().GetEnergy(); |
|
} |
|
return energy; |
|
} |
|
|
|
|
|
override void OnEnergyConsumed() |
|
{ |
|
super.OnEnergyConsumed(); |
|
|
|
ConvertEnergyToQuantity(); |
|
} |
|
|
|
override void OnEnergyAdded() |
|
{ |
|
super.OnEnergyAdded(); |
|
|
|
ConvertEnergyToQuantity(); |
|
} |
|
|
|
|
|
void ConvertEnergyToQuantity() |
|
{ |
|
if (GetGame().IsServer() && HasEnergyManager() && GetCompEM().HasConversionOfEnergyToQuantity()) |
|
{ |
|
if (HasQuantity()) |
|
{ |
|
float energy_0to1 = GetCompEM().GetEnergy0To1(); |
|
SetQuantityNormalized(energy_0to1); |
|
} |
|
} |
|
} |
|
|
|
override void SetTemperature(float value, bool allow_client = false) |
|
{ |
|
if (!IsServerCheck(allow_client)) |
|
return; |
|
|
|
float min = GetTemperatureMin(); |
|
float max = GetTemperatureMax(); |
|
|
|
float previousValue = m_VarTemperature; |
|
|
|
m_VarTemperature = Math.Clamp(value, min, max); |
|
|
|
if (previousValue != m_VarTemperature) |
|
SetVariableMask(VARIABLE_TEMPERATURE); |
|
} |
|
|
|
override void AddTemperature(float value) |
|
{ |
|
SetTemperature(value + GetTemperature()); |
|
} |
|
|
|
override void SetTemperatureMax() |
|
{ |
|
SetTemperature(m_VarTemperatureMax); |
|
} |
|
|
|
override float GetTemperature() |
|
{ |
|
return m_VarTemperature; |
|
} |
|
|
|
override float GetTemperatureInit() |
|
{ |
|
return m_VarTemperatureInit; |
|
} |
|
|
|
override float GetTemperatureMin() |
|
{ |
|
return m_VarTemperatureMin; |
|
} |
|
|
|
override float GetTemperatureMax() |
|
{ |
|
return m_VarTemperatureMax; |
|
} |
|
|
|
float GetHeatIsolationInit() |
|
{ |
|
return ConfigGetFloat("heatIsolation"); |
|
} |
|
|
|
float GetHeatIsolation() |
|
{ |
|
return m_HeatIsolation; |
|
} |
|
|
|
float GetDryingIncrement(string pIncrementName) |
|
{ |
|
string paramPath = string.Format("CfgVehicles %1 EnvironmentWetnessIncrements Drying %2", GetType(), pIncrementName); |
|
if (GetGame().ConfigIsExisting(paramPath)) |
|
return GetGame().ConfigGetFloat(paramPath); |
|
|
|
return 0.0; |
|
} |
|
|
|
float GetSoakingIncrement(string pIncrementName) |
|
{ |
|
string paramPath = string.Format("CfgVehicles %1 EnvironmentWetnessIncrements Soaking %2", GetType(), pIncrementName); |
|
if (GetGame().ConfigIsExisting(paramPath)) |
|
return GetGame().ConfigGetFloat(paramPath); |
|
|
|
return 0.0; |
|
} |
|
|
|
override void SetWet(float value, bool allow_client = false) |
|
{ |
|
if (!IsServerCheck(allow_client)) |
|
return; |
|
|
|
float min = GetWetMin(); |
|
float max = GetWetMax(); |
|
|
|
float previousValue = m_VarWet; |
|
|
|
m_VarWet = Math.Clamp(value, min, max); |
|
|
|
if (previousValue != m_VarWet) |
|
{ |
|
SetVariableMask(VARIABLE_WET); |
|
OnWetChanged(m_VarWet, previousValue); |
|
} |
|
} |
|
|
|
override void AddWet(float value) |
|
{ |
|
SetWet(GetWet() + value); |
|
} |
|
|
|
override void SetWetMax() |
|
{ |
|
SetWet(m_VarWetMax); |
|
} |
|
|
|
override float GetWet() |
|
{ |
|
return m_VarWet; |
|
} |
|
|
|
override float GetWetMax() |
|
{ |
|
return m_VarWetMax; |
|
} |
|
|
|
override float GetWetMin() |
|
{ |
|
return m_VarWetMin; |
|
} |
|
|
|
override float GetWetInit() |
|
{ |
|
return m_VarWetInit; |
|
} |
|
|
|
override void OnWetChanged(float newVal, float oldVal) |
|
{ |
|
EWetnessLevel newLevel = GetWetLevelInternal(newVal); |
|
EWetnessLevel oldLevel = GetWetLevelInternal(oldVal); |
|
if (newLevel != oldLevel) |
|
{ |
|
OnWetLevelChanged(newLevel,oldLevel); |
|
} |
|
} |
|
|
|
override void OnWetLevelChanged(EWetnessLevel newLevel, EWetnessLevel oldLevel) |
|
{ |
|
SetWeightDirty(); |
|
} |
|
|
|
override EWetnessLevel GetWetLevel() |
|
{ |
|
return GetWetLevelInternal(m_VarWet); |
|
} |
|
|
|
|
|
bool IsServerCheck(bool allow_client) |
|
{ |
|
if (g_Game.IsServer()) |
|
return true; |
|
|
|
if (allow_client) |
|
return true; |
|
|
|
if (GetGame().IsClient() && GetGame().IsMultiplayer()) |
|
{ |
|
Error("Attempting to change variable client side, variables are supposed to be changed on server only !!"); |
|
return false; |
|
} |
|
|
|
return true; |
|
} |
|
|
|
float GetItemModelLength() |
|
{ |
|
if (ConfigIsExisting("itemModelLength")) |
|
{ |
|
return ConfigGetFloat("itemModelLength"); |
|
} |
|
return 0; |
|
} |
|
|
|
float GetItemAttachOffset() |
|
{ |
|
if (ConfigIsExisting("itemAttachOffset")) |
|
{ |
|
return ConfigGetFloat("itemAttachOffset"); |
|
} |
|
return 0; |
|
} |
|
|
|
void SetCleanness(int value, bool allow_client = false) |
|
{ |
|
if (!IsServerCheck(allow_client)) |
|
return; |
|
|
|
int previousValue = m_Cleanness; |
|
|
|
m_Cleanness = Math.Clamp(value, m_CleannessMin, m_CleannessMax); |
|
|
|
if (previousValue != m_Cleanness) |
|
SetVariableMask(VARIABLE_CLEANNESS); |
|
} |
|
|
|
|
|
bool AllowFoodConsumption() |
|
{ |
|
return true; |
|
} |
|
|
|
|
|
|
|
|
|
int GetLockType() |
|
{ |
|
return m_LockType; |
|
} |
|
|
|
string GetLockSoundSet() |
|
{ |
|
return m_LockSoundSet; |
|
} |
|
|
|
|
|
|
|
|
|
void SetColor(int r, int g, int b, int a) |
|
{ |
|
m_ColorComponentR = r; |
|
m_ColorComponentG = g; |
|
m_ColorComponentB = b; |
|
m_ColorComponentA = a; |
|
SetVariableMask(VARIABLE_COLOR); |
|
} |
|
|
|
void GetColor(out int r,out int g,out int b,out int a) |
|
{ |
|
r = m_ColorComponentR; |
|
g = m_ColorComponentG; |
|
b = m_ColorComponentB; |
|
a = m_ColorComponentA; |
|
} |
|
|
|
bool IsColorSet() |
|
{ |
|
return IsVariableSet(VARIABLE_COLOR); |
|
} |
|
|
|
|
|
string GetColorString() |
|
{ |
|
int r,g,b,a; |
|
GetColor(r,g,b,a); |
|
r = r/255; |
|
g = g/255; |
|
b = b/255; |
|
a = a/255; |
|
return MiscGameplayFunctions.GetColorString(r, g, b, a); |
|
} |
|
|
|
|
|
|
|
void SetLiquidType(int value, bool allow_client = false) |
|
{ |
|
if (!IsServerCheck(allow_client)) |
|
return; |
|
|
|
m_VarLiquidType = value; |
|
SetVariableMask(VARIABLE_LIQUIDTYPE); |
|
} |
|
|
|
int GetLiquidTypeInit() |
|
{ |
|
return ConfigGetInt("varLiquidTypeInit"); |
|
} |
|
|
|
int GetLiquidType() |
|
{ |
|
return m_VarLiquidType; |
|
} |
|
|
|
|
|
|
|
void OnInventoryEnter(Man player) |
|
{ |
|
PlayerBase nplayer; |
|
if (PlayerBase.CastTo(nplayer, player)) |
|
{ |
|
m_CanPlayImpactSound = true; |
|
|
|
nplayer.SetEnableQuickBarEntityShortcut(this,true); |
|
} |
|
} |
|
|
|
|
|
|
|
void OnInventoryExit(Man player) |
|
{ |
|
PlayerBase nplayer; |
|
if (PlayerBase.CastTo(nplayer,player)) |
|
{ |
|
|
|
nplayer.SetEnableQuickBarEntityShortcut(this,false); |
|
|
|
} |
|
|
|
|
|
player.GetHumanInventory().ClearUserReservedLocationForContainer(this); |
|
|
|
|
|
if (HasEnergyManager()) |
|
{ |
|
GetCompEM().UpdatePlugState(); |
|
} |
|
} |
|
|
|
|
|
override void OnPlacementStarted(Man player) |
|
{ |
|
super.OnPlacementStarted(player); |
|
|
|
SetTakeable(false); |
|
} |
|
|
|
override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0") |
|
{ |
|
if (m_AdminLog) |
|
{ |
|
m_AdminLog.OnPlacementComplete(player, this); |
|
} |
|
if (GetGame().IsServer()) |
|
{ |
|
SetIsDeploySound(true); |
|
} |
|
super.OnPlacementComplete(player, position, orientation); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ContainsAgent(int agent_id) |
|
{ |
|
if (agent_id & m_AttachedAgents) |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
|
|
override void RemoveAgent(int agent_id) |
|
{ |
|
if (ContainsAgent(agent_id)) |
|
{ |
|
m_AttachedAgents = ~agent_id & m_AttachedAgents; |
|
} |
|
} |
|
|
|
|
|
override void RemoveAllAgents() |
|
{ |
|
m_AttachedAgents = 0; |
|
} |
|
|
|
override void RemoveAllAgentsExcept(int agents_to_keep_mask) |
|
{ |
|
m_AttachedAgents = m_AttachedAgents & agent_to_keep; |
|
} |
|
|
|
override void InsertAgent(int agent, float count = 1) |
|
{ |
|
if (count < 1) |
|
return; |
|
|
|
m_AttachedAgents = (agent | m_AttachedAgents); |
|
} |
|
|
|
|
|
void TransferAgents(int agents) |
|
{ |
|
m_AttachedAgents = (m_AttachedAgents | agents); |
|
} |
|
|
|
|
|
override int GetAgents() |
|
{ |
|
return m_AttachedAgents; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LoadAgents(ParamsReadContext ctx, int version) |
|
{ |
|
if (!ctx.Read(m_AttachedAgents)) |
|
return false; |
|
return true; |
|
} |
|
|
|
void SaveAgents(ParamsWriteContext ctx) |
|
{ |
|
|
|
ctx.Write(m_AttachedAgents); |
|
} |
|
|
|
|
|
|
|
|
|
float GetProtectionLevel(int type, bool consider_filter = false, int system = 0) |
|
{ |
|
if (IsDamageDestroyed() || (HasQuantity() && GetQuantity() <= 0)) |
|
{ |
|
return 0; |
|
} |
|
|
|
if (GetInventory().GetAttachmentSlotsCount() != 0) |
|
{ |
|
ItemBase filter = ItemBase.Cast(FindAttachmentBySlotName("GasMaskFilter")); |
|
if (filter) |
|
return filter.GetProtectionLevel(type, false, system); |
|
else |
|
return 0; |
|
} |
|
|
|
string subclassPath, entryName; |
|
|
|
switch (type) |
|
{ |
|
case DEF_BIOLOGICAL: |
|
entryName = "biological"; |
|
break; |
|
case DEF_CHEMICAL: |
|
entryName = "chemical"; |
|
break; |
|
default: |
|
entryName = "biological"; |
|
break; |
|
} |
|
|
|
subclassPath = "CfgVehicles " + this.GetType() + " Protection "; |
|
|
|
return GetGame().ConfigGetFloat(subclassPath + entryName); |
|
} |
|
|
|
|
|
|
|
|
|
override void EEOnCECreate() |
|
{ |
|
|
|
if (!IsMagazine()) |
|
SetCEBasedQuantity(); |
|
|
|
SetZoneDamageCEInit(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
void Open(); |
|
void Close(); |
|
bool IsOpen() |
|
{ |
|
return true; |
|
} |
|
|
|
override bool CanDisplayCargo() |
|
{ |
|
return IsOpen(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
override bool CanPutInCargo(EntityAI parent) |
|
{ |
|
if (parent) |
|
{ |
|
if (parent.IsInherited(DayZInfected)) |
|
return true; |
|
|
|
if (!parent.IsRuined()) |
|
return true; |
|
} |
|
|
|
return true; |
|
} |
|
|
|
override bool CanPutAsAttachment(EntityAI parent) |
|
{ |
|
if (!super.CanPutAsAttachment(parent)) |
|
{ |
|
return false; |
|
} |
|
|
|
if (!IsRuined() && !parent.IsRuined()) |
|
{ |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
override bool CanReceiveItemIntoCargo(EntityAI item) |
|
{ |
|
|
|
|
|
|
|
|
|
return super.CanReceiveItemIntoCargo(item); |
|
} |
|
|
|
override bool CanReceiveAttachment(EntityAI attachment, int slotId) |
|
{ |
|
|
|
|
|
|
|
|
|
GameInventory attachmentInv = attachment.GetInventory(); |
|
if (attachmentInv && attachmentInv.GetCargo() && attachmentInv.GetCargo().GetItemCount() > 0) |
|
{ |
|
if (GetHierarchyParent() && !GetHierarchyParent().IsInherited(PlayerBase)) |
|
return false; |
|
} |
|
|
|
return super.CanReceiveAttachment(attachment, slotId); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void PlayFireParticles(ItemBase weapon, int muzzle_index, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search) |
|
{ |
|
int id = muzzle_owner.GetMuzzleID(); |
|
array<ref WeaponParticlesOnFire> WPOF_array = m_OnFireEffect.Get(id); |
|
|
|
if (WPOF_array) |
|
{ |
|
for (int i = 0; i < WPOF_array.Count(); i++) |
|
{ |
|
WeaponParticlesOnFire WPOF = WPOF_array.Get(i); |
|
|
|
if (WPOF) |
|
{ |
|
WPOF.OnActivate(weapon, muzzle_index, ammoType, muzzle_owner, suppressor, config_to_search); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
static void PlayBulletCasingEjectParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search) |
|
{ |
|
int id = muzzle_owner.GetMuzzleID(); |
|
array<ref WeaponParticlesOnBulletCasingEject> WPOBE_array = m_OnBulletCasingEjectEffect.Get(id); |
|
|
|
if (WPOBE_array) |
|
{ |
|
for (int i = 0; i < WPOBE_array.Count(); i++) |
|
{ |
|
WeaponParticlesOnBulletCasingEject WPOBE = WPOBE_array.Get(i); |
|
|
|
if (WPOBE) |
|
{ |
|
WPOBE.OnActivate(weapon, 0, ammoType, muzzle_owner, suppressor, config_to_search); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
static void PlayOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search) |
|
{ |
|
int id = muzzle_owner.GetMuzzleID(); |
|
array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id); |
|
|
|
if (WPOOH_array) |
|
{ |
|
for (int i = 0; i < WPOOH_array.Count(); i++) |
|
{ |
|
WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i); |
|
|
|
if (WPOOH) |
|
{ |
|
WPOOH.OnActivate(weapon, 0, ammoType, muzzle_owner, suppressor, config_to_search); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
static void UpdateOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search) |
|
{ |
|
int id = muzzle_owner.GetMuzzleID(); |
|
array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id); |
|
|
|
if (WPOOH_array) |
|
{ |
|
for (int i = 0; i < WPOOH_array.Count(); i++) |
|
{ |
|
WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i); |
|
|
|
if (WPOOH) |
|
{ |
|
WPOOH.OnUpdate(weapon, ammoType, muzzle_owner, suppressor, config_to_search); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
static void StopOverheatingParticles(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search) |
|
{ |
|
int id = muzzle_owner.GetMuzzleID(); |
|
array<ref WeaponParticlesOnOverheating> WPOOH_array = weapon.m_OnOverheatingEffect.Get(id); |
|
|
|
if (WPOOH_array) |
|
{ |
|
for (int i = 0; i < WPOOH_array.Count(); i++) |
|
{ |
|
WeaponParticlesOnOverheating WPOOH = WPOOH_array.Get(i); |
|
|
|
if (WPOOH) |
|
{ |
|
WPOOH.OnDeactivate(weapon, ammoType, muzzle_owner, suppressor, config_to_search); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
override bool IsHeavyBehaviour() |
|
{ |
|
if (m_ItemBehaviour == 0) |
|
{ |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
override bool IsOneHandedBehaviour() |
|
{ |
|
if (m_ItemBehaviour == 1) |
|
{ |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
override bool IsTwoHandedBehaviour() |
|
{ |
|
if (m_ItemBehaviour == 2) |
|
{ |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
bool IsDeployable() |
|
{ |
|
return false; |
|
} |
|
|
|
|
|
float GetDeployTime() |
|
{ |
|
return UATimeSpent.DEFAULT_DEPLOY; |
|
} |
|
|
|
|
|
|
|
|
|
override void SetTakeable(bool pState) |
|
{ |
|
m_IsTakeable = pState; |
|
SetSynchDirty(); |
|
} |
|
|
|
override bool IsTakeable() |
|
{ |
|
return m_IsTakeable; |
|
} |
|
|
|
|
|
protected void PreLoadSoundAttachmentType() |
|
{ |
|
string att_type = "None"; |
|
|
|
if (ConfigIsExisting("soundAttType")) |
|
{ |
|
att_type = ConfigGetString("soundAttType"); |
|
} |
|
|
|
m_SoundAttType = att_type; |
|
} |
|
|
|
override string GetAttachmentSoundType() |
|
{ |
|
return m_SoundAttType; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SoundSynchRemoteReset() |
|
{ |
|
m_IsSoundSynchRemote = false; |
|
|
|
SetSynchDirty(); |
|
} |
|
|
|
void SoundSynchRemote() |
|
{ |
|
m_IsSoundSynchRemote = true; |
|
|
|
SetSynchDirty(); |
|
} |
|
|
|
bool IsSoundSynchRemote() |
|
{ |
|
return m_IsSoundSynchRemote; |
|
} |
|
|
|
string GetDeploySoundset(); |
|
string GetPlaceSoundset(); |
|
string GetLoopDeploySoundset(); |
|
string GetDeployFinishSoundset(); |
|
|
|
void SetIsPlaceSound(bool is_place_sound) |
|
{ |
|
m_IsPlaceSound = is_place_sound; |
|
} |
|
|
|
bool IsPlaceSound() |
|
{ |
|
return m_IsPlaceSound; |
|
} |
|
|
|
void SetIsDeploySound(bool is_deploy_sound) |
|
{ |
|
m_IsDeploySound = is_deploy_sound; |
|
} |
|
|
|
bool IsDeploySound() |
|
{ |
|
return m_IsDeploySound; |
|
} |
|
|
|
void PlayDeployLoopSoundEx() |
|
{ |
|
if (!GetGame().IsDedicatedServer() && !m_DeployLoopSoundEx) |
|
{ |
|
m_DeployLoopSoundEx = SEffectManager.PlaySound(GetLoopDeploySoundset(), GetPosition()); |
|
if (m_DeployLoopSoundEx) |
|
m_DeployLoopSoundEx.SetAutodestroy(true); |
|
else |
|
Debug.Log("dbgSounds | null m_DeployLoopSoundEx from sound set: " + GetLoopDeploySoundset()); |
|
} |
|
} |
|
|
|
void StopDeployLoopSoundEx() |
|
{ |
|
if (!GetGame().IsDedicatedServer()) |
|
{ |
|
m_DeployLoopSoundEx.SetSoundFadeOut(0.5); |
|
m_DeployLoopSoundEx.SoundStop(); |
|
} |
|
} |
|
|
|
void PlayDeploySound() |
|
{ |
|
if (!GetGame().IsDedicatedServer() && !m_SoundDeploy) |
|
{ |
|
m_SoundDeploy = SEffectManager.PlaySound(GetDeploySoundset(), GetPosition()); |
|
if (m_SoundDeploy) |
|
m_SoundDeploy.SetAutodestroy(true); |
|
else |
|
Debug.Log("dbgSounds | null m_SoundDeploy from sound set: " + GetDeploySoundset()); |
|
} |
|
} |
|
|
|
void PlayDeployFinishSound() |
|
{ |
|
if (!GetGame().IsDedicatedServer() && !m_SoundDeployFinish) |
|
{ |
|
m_SoundDeployFinish = SEffectManager.PlaySound(GetDeployFinishSoundset(), GetPosition()); |
|
if (m_SoundDeployFinish) |
|
m_SoundDeployFinish.SetAutodestroy(true); |
|
else |
|
Debug.Log("dbgSounds | null m_SoundDeployFinish from sound set: " + GetDeployFinishSoundset()); |
|
} |
|
} |
|
|
|
void PlayPlaceSound() |
|
{ |
|
if (!GetGame().IsDedicatedServer() && !m_SoundPlace) |
|
{ |
|
m_SoundPlace = SEffectManager.PlaySound(GetPlaceSoundset(), GetPosition()); |
|
if (m_SoundPlace) |
|
m_SoundPlace.SetAutodestroy(true); |
|
else |
|
Debug.Log("dbgSounds | null m_SoundPlace from sound set: " + GetPlaceSoundset()); |
|
} |
|
} |
|
|
|
bool CanPlayDeployLoopSound() |
|
{ |
|
return IsBeingPlaced() && IsSoundSynchRemote(); |
|
} |
|
|
|
|
|
void PlayAttachSound(string slot_type) |
|
{ |
|
if (!GetGame().IsDedicatedServer()) |
|
{ |
|
if (ConfigIsExisting("attachSoundSet")) |
|
{ |
|
string cfg_path = ""; |
|
string soundset = ""; |
|
string type_name = GetType(); |
|
|
|
TStringArray cfg_soundset_array = new TStringArray; |
|
TStringArray cfg_slot_array = new TStringArray; |
|
ConfigGetTextArray("attachSoundSet",cfg_soundset_array); |
|
ConfigGetTextArray("attachSoundSlot",cfg_slot_array); |
|
|
|
if (cfg_soundset_array.Count() > 0 && cfg_soundset_array.Count() == cfg_slot_array.Count()) |
|
{ |
|
for (int i = 0; i < cfg_soundset_array.Count(); i++) |
|
{ |
|
if (cfg_slot_array[i] == slot_type) |
|
{ |
|
soundset = cfg_soundset_array[i]; |
|
break; |
|
} |
|
} |
|
} |
|
|
|
if (soundset != "") |
|
{ |
|
EffectSound sound = SEffectManager.PlaySound(soundset, GetPosition()); |
|
sound.SetAutodestroy(true); |
|
} |
|
} |
|
} |
|
} |
|
|
|
void PlayDetachSound(string slot_type) |
|
{ |
|
|
|
} |
|
|
|
void OnApply(PlayerBase player); |
|
|
|
float GetBandagingEffectivity() |
|
{ |
|
return 1.0; |
|
}; |
|
|
|
array<string> GetHeadHidingSelection() |
|
{ |
|
return m_HeadHidingSelections; |
|
} |
|
|
|
bool HidesSelectionBySlot() |
|
{ |
|
return m_HideSelectionsBySlot; |
|
} |
|
|
|
WrittenNoteData GetWrittenNoteData() {}; |
|
|
|
void StopItemDynamicPhysics() |
|
{ |
|
SetDynamicPhysicsLifeTime(0.01); |
|
m_ItemBeingDroppedPhys = false; |
|
} |
|
|
|
void PerformDamageSystemReinit() |
|
{ |
|
array<string> zone_names = new array<string>; |
|
GetDamageZones(zone_names); |
|
for (int i = 0; i < zone_names.Count(); i++) |
|
{ |
|
SetHealthMax(zone_names.Get(i),"Health"); |
|
} |
|
SetHealthMax("","Health"); |
|
} |
|
|
|
|
|
void SetZoneDamageCEInit() |
|
{ |
|
float global_health = GetHealth01("","Health"); |
|
array<string> zones = new array<string>; |
|
GetDamageZones(zones); |
|
|
|
for (int i = 0; i < zones.Count(); i++) |
|
{ |
|
SetHealth01(zones.Get(i),"Health",global_health); |
|
} |
|
} |
|
|
|
|
|
bool IsCoverFaceForShave(string slot_name) |
|
{ |
|
return IsExclusionFlagPresent(PlayerBase.GetFaceCoverageShaveValues()); |
|
} |
|
|
|
void ProcessItemWetness(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB) |
|
{ |
|
if (!hasRootAsPlayer) |
|
{ |
|
if (refParentIB) |
|
{ |
|
|
|
if ((refParentIB.GetWet() >= GameConstants.STATE_SOAKING_WET) && (m_VarWet < m_VarWetMax)) |
|
AddWet(delta * GameConstants.WETNESS_RATE_WETTING_INSIDE); |
|
|
|
else if ((refParentIB.GetLiquidType() != 0) && (refParentIB.GetQuantity() > 0) && (m_VarWet < m_VarWetMax)) |
|
AddWet(delta * GameConstants.WETNESS_RATE_WETTING_LIQUID); |
|
|
|
else if (m_VarWet > m_VarWetMin) |
|
AddWet(-1 * delta * GetDryingIncrement("ground") * 2); |
|
} |
|
else |
|
{ |
|
|
|
if (m_VarWet > m_VarWetMin) |
|
AddWet(-1 * delta * GetDryingIncrement("ground")); |
|
} |
|
} |
|
} |
|
|
|
void ProcessItemTemperature(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB) |
|
{ |
|
if (!hasRootAsPlayer && GetTemperature() > GetTemperatureMin() && !IsFireplace()) |
|
{ |
|
if (refParentIB) |
|
{ |
|
|
|
if (GetTemperature() > refParentIB.GetTemperature()) |
|
AddTemperature(delta * GameConstants.TEMPERATURE_RATE_COOLING_INSIDE); |
|
} |
|
else |
|
{ |
|
|
|
AddTemperature(delta * GameConstants.TEMPERATURE_RATE_COOLING_INSIDE); |
|
} |
|
} |
|
} |
|
|
|
|
|
void ProcessItemWetnessAndTemperature(float delta, bool hasParent, bool hasRootAsPlayer, ItemBase refParentIB) |
|
{ |
|
ProcessItemWetness(delta, hasParent, hasRootAsPlayer, refParentIB); |
|
ProcessItemTemperature(delta, hasParent, hasRootAsPlayer, refParentIB); |
|
} |
|
|
|
void HierarchyCheck(out bool hasParent, out bool hasRootAsPlayer, out ItemBase refParentIB) |
|
{ |
|
|
|
EntityAI parent = GetHierarchyParent(); |
|
if (!parent) |
|
{ |
|
hasParent = false; |
|
hasRootAsPlayer = false; |
|
} |
|
else |
|
{ |
|
hasParent = true; |
|
hasRootAsPlayer = (GetHierarchyRootPlayer() != null); |
|
refParentIB = ItemBase.Cast(parent); |
|
} |
|
} |
|
|
|
protected void ProcessDecay(float delta, bool hasRootAsPlayer) |
|
{ |
|
|
|
} |
|
|
|
bool CanDecay() |
|
{ |
|
|
|
return false; |
|
} |
|
|
|
protected bool CanProcessDecay() |
|
{ |
|
|
|
|
|
return false; |
|
} |
|
|
|
protected bool CanHaveWetness() |
|
{ |
|
|
|
return false; |
|
} |
|
|
|
protected bool CanHaveTemperature() |
|
{ |
|
|
|
return false; |
|
} |
|
|
|
override void OnCEUpdate() |
|
{ |
|
super.OnCEUpdate(); |
|
|
|
bool hasParent = false, hasRootAsPlayer = false; |
|
ItemBase refParentIB; |
|
|
|
bool wwtu = g_Game.IsWorldWetTempUpdateEnabled(); |
|
bool foodDecay = g_Game.IsFoodDecayEnabled(); |
|
|
|
if (wwtu || foodDecay) |
|
{ |
|
bool processWetness = wwtu && CanHaveWetness(); |
|
bool processTemperature = wwtu && CanHaveTemperature(); |
|
bool processDecay = foodDecay && CanDecay() && CanProcessDecay(); |
|
|
|
if (processWetness || processTemperature || processDecay) |
|
{ |
|
HierarchyCheck(hasParent, hasRootAsPlayer, refParentIB); |
|
|
|
if (processWetness) |
|
ProcessItemWetness(m_ElapsedSinceLastUpdate, hasParent, hasRootAsPlayer, refParentIB); |
|
|
|
if (processTemperature) |
|
ProcessItemTemperature(m_ElapsedSinceLastUpdate, hasParent, hasRootAsPlayer, refParentIB); |
|
|
|
if (processDecay) |
|
ProcessDecay(m_ElapsedSinceLastUpdate, hasRootAsPlayer); |
|
} |
|
} |
|
} |
|
|
|
bool IsCargoException4x3(EntityAI item) |
|
{ |
|
return (item.IsKindOf("Cauldron") || item.IsKindOf("Pot") || item.IsKindOf("FryingPan") || item.IsKindOf("SmallProtectorCase") || (item.IsKindOf("PortableGasStove") && item.FindAttachmentBySlotName("CookingEquipment"))); |
|
} |
|
|
|
void CopyScriptPropertiesFrom(EntityAI oldItem) |
|
{ |
|
MiscGameplayFunctions.TransferItemProperties(oldItem, this); |
|
} |
|
|
|
|
|
void AddLightSourceItem(ItemBase lightsource) |
|
{ |
|
m_LightSourceItem = lightsource; |
|
} |
|
|
|
void RemoveLightSourceItem() |
|
{ |
|
m_LightSourceItem = null; |
|
} |
|
|
|
ItemBase GetLightSourceItem() |
|
{ |
|
return m_LightSourceItem; |
|
} |
|
|
|
|
|
array<int> GetValidFinishers() |
|
{ |
|
return null; |
|
} |
|
|
|
|
|
bool GetActionWidgetOverride(out typename name) |
|
{ |
|
return false; |
|
} |
|
|
|
bool PairWithDevice(notnull ItemBase otherDevice) |
|
{ |
|
if (GetGame().IsServer()) |
|
{ |
|
ItemBase explosive = otherDevice; |
|
RemoteDetonatorTrigger trg = RemoteDetonatorTrigger.Cast(this); |
|
if (!trg) |
|
{ |
|
trg = RemoteDetonatorTrigger.Cast(otherDevice); |
|
explosive = this; |
|
} |
|
|
|
explosive.PairRemote(trg); |
|
trg.SetControlledDevice(explosive); |
|
|
|
int persistentID = RemotelyActivatedItemBehaviour.GeneratePersistentID(); |
|
trg.SetPersistentPairID(persistentID); |
|
explosive.SetPersistentPairID(persistentID); |
|
|
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
#ifdef DEVELOPER |
|
override void SetDebugItem() |
|
{ |
|
super.SetDebugItem(); |
|
_itemBase = this; |
|
} |
|
#endif |
|
|
|
bool CanBeUsedForSuicide() |
|
{ |
|
return true; |
|
} |
|
} |
|
|
|
EntityAI SpawnItemOnLocation(string object_name, notnull InventoryLocation loc, bool full_quantity) |
|
{ |
|
EntityAI entity = SpawnEntity(object_name, loc, ECE_IN_INVENTORY, RF_DEFAULT); |
|
if (entity) |
|
{ |
|
bool is_item = entity.IsInherited(ItemBase); |
|
if (is_item && full_quantity) |
|
{ |
|
ItemBase item = ItemBase.Cast(entity); |
|
item.SetQuantity(item.GetQuantityInit()); |
|
} |
|
} |
|
else |
|
{ |
|
Print("Cannot spawn entity: " + object_name); |
|
return NULL; |
|
} |
|
return entity; |
|
} |
|
|
|
void SetupSpawnedItem(ItemBase item, float health, float quantity) |
|
{ |
|
if (item) |
|
{ |
|
if (health > 0) |
|
item.SetHealth("", "", health); |
|
|
|
|
|
if (item.HasEnergyManager()) |
|
{ |
|
if (quantity >= 0) |
|
{ |
|
item.GetCompEM().SetEnergy0To1(quantity); |
|
} |
|
else |
|
{ |
|
item.GetCompEM().SetEnergy(Math.AbsFloat(quantity)); |
|
} |
|
} |
|
else if (item.IsMagazine()) |
|
{ |
|
Magazine mag = Magazine.Cast(item); |
|
if (quantity >= 0) |
|
{ |
|
mag.ServerSetAmmoCount(mag.GetAmmoMax() * quantity); |
|
} |
|
else |
|
{ |
|
mag.ServerSetAmmoCount(Math.AbsFloat(quantity)); |
|
} |
|
|
|
} |
|
else |
|
{ |
|
if (quantity >= 0) |
|
{ |
|
item.SetQuantityNormalized(quantity, false); |
|
} |
|
else |
|
{ |
|
item.SetQuantity(Math.AbsFloat(quantity)); |
|
} |
|
|
|
} |
|
} |
|
} |
|
|
|
#ifdef DEVELOPER |
|
ItemBase _itemBase; |
|
#endif |
|
|