123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- class Plastic_Explosive : ExplosivesBase
- {
- protected const string SLOT_TRIGGER = "TriggerRemoteDetonator_Receiver";
- protected const string ANIM_PHASE_TRIGGER_REMOTE = "TriggerRemote";
-
- protected bool m_UsedAsCharge;
-
- protected ref RemotelyActivatedItemBehaviour m_RAIB;
- void Plastic_Explosive()
- {
- m_RAIB = new RemotelyActivatedItemBehaviour(this);
-
- SetAmmoType("Plastic_Explosive_Ammo");
- SetParticleExplosion(ParticleList.PLASTIC_EXPLOSION);
- RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdLow");
- RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdHigh");
- }
-
- override void EOnInit(IEntity other, int extra)
- {
- if (!g_Game.IsMultiplayer())
- LockTriggerSlots();
- }
-
- //! special behaviour - do not call super from ExplosivesBase
- override void EEKilled(Object killer)
- {
- //analytics (behaviour from EntityAI)
- GetGame().GetAnalyticsServer().OnEntityKilled(killer, this);
- }
- override bool HasLockedTriggerSlots()
- {
- return GetInventory().GetSlotLock(InventorySlots.GetSlotIdFromString(SLOT_TRIGGER));
- }
-
- override void LockTriggerSlots()
- {
- GetInventory().SetSlotLock(InventorySlots.GetSlotIdFromString(SLOT_TRIGGER), true);
- }
-
- override void UnlockTriggerSlots()
- {
- GetInventory().SetSlotLock(InventorySlots.GetSlotIdFromString(SLOT_TRIGGER), false);
- }
-
- override bool OnStoreLoad(ParamsReadContext ctx, int version)
- {
- if (!super.OnStoreLoad(ctx, version))
- return false;
- if (version <= 134) // up to 1.21
- {
- int slotId = InventorySlots.GetSlotIdFromString(SLOT_TRIGGER);
- bool locked = GetInventory().GetSlotLock(slotId);
- while (locked)
- {
- GetInventory().SetSlotLock(slotId, false);
- locked = GetInventory().GetSlotLock(slotId);
- }
- }
-
- return true;
- }
-
- override void OnStoreSave(ParamsWriteContext ctx)
- {
- super.OnStoreSave(ctx);
-
- LockTriggerSlots();
- }
- override void OnVariablesSynchronized()
- {
- super.OnVariablesSynchronized();
-
- if (m_RAIB)
- {
- m_RAIB.OnVariableSynchronized();
- }
-
- int slotId = InventorySlots.GetSlotIdFromString(SLOT_TRIGGER);
- UpdateVisuals(GetInventory().FindAttachment(slotId));
- }
-
- override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
- {
- super.EEItemLocationChanged(oldLoc, newLoc);
- if (m_RAIB)
- {
- m_RAIB.Pair();
- }
- }
-
- override bool CanReceiveAttachment(EntityAI attachment, int slotId)
- {
- InventoryLocation il = new InventoryLocation();
- GetInventory().GetCurrentInventoryLocation(il);
- if (il.GetType() == InventoryLocationType.HANDS)
- {
- return false;
- }
-
- ClockBase timer = ClockBase.Cast(attachment);
- if (timer && !timer.IsAlarmOn())
- {
- return false;
- }
- return !GetArmed();
- }
-
- override bool CanDisplayAttachmentSlot(int slot_id)
- {
- string slotName = InventorySlots.GetSlotName(slot_id);
- switch (slotName)
- {
- case SLOT_TRIGGER:
- return FindAttachmentBySlotName(slotName) != null;
- break;
- }
- return true;
- }
-
- override bool IsTakeable()
- {
- return !GetArmed() && super.IsTakeable();
- }
-
- override bool IsDeployable()
- {
- return !GetArmed();
- }
-
- override void SetActions()
- {
- super.SetActions();
- AddAction(ActionTogglePlaceObject);
- AddAction(ActionDeployObject);
- }
-
- override void OnWasAttached(EntityAI parent, int slot_id)
- {
- super.OnWasAttached(parent, slot_id);
-
- m_UsedAsCharge = false;
- if (parent && parent.IsInherited(ExplosivesBase))
- {
- m_UsedAsCharge = true;
- }
- }
-
- override void OnWasDetached(EntityAI parent, int slot_id)
- {
- super.OnWasDetached(parent, slot_id);
- if (parent && !parent.IsInherited(ExplosivesBase))
- {
- m_UsedAsCharge = false;
- }
- }
-
- override bool EEOnDamageCalculated(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
- {
- //! ignores explosion damage from other Plastic_Explosive that are used as charge(like 2 PE fired via IED)
- if (damageType == DamageType.EXPLOSION)
- {
- return !m_UsedAsCharge;
- }
-
- return true;
- }
-
- override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
- {
- super.EEHealthLevelChanged(oldLevel, newLevel, zone);
- if (GetGame().IsServer())
- {
- if (newLevel == GameConstants.STATE_RUINED)
- {
- for (int attachmentIdx = 0; attachmentIdx < GetInventory().AttachmentCount(); attachmentIdx++)
- {
- ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(attachmentIdx));
- if (attachment)
- {
- attachment.UnlockFromParent();
- attachment.SetHealth("", "", 0.0);
- }
- }
-
- SetArmed(false);
- SetTakeable(true);
- }
- }
- }
-
- override RemotelyActivatedItemBehaviour GetRemotelyActivatedItemBehaviour()
- {
- return m_RAIB;
- }
-
- override void PairRemote(notnull EntityAI trigger)
- {
- m_RAIB.Pair(trigger);
- }
-
- override EntityAI GetPairDevice()
- {
- return m_RAIB.GetPairDevice();
- }
-
- override bool CanBeArmed()
- {
- if (!super.CanBeArmed())
- {
- return false;
- }
- return HasLockedTriggerSlots() && !GetArmed();
- }
-
- override bool CanBeDisarmed()
- {
- return GetArmed();
- }
-
- override void OnActivatedByItem(notnull ItemBase item)
- {
- if (GetGame().IsServer())
- {
- if (GetHealthLevel("") == GameConstants.STATE_RUINED)
- {
- return;
- }
-
- if (item == this)
- {
- SetHealth("", "", 0.0);
- InitiateExplosion();
- return;
- }
-
- if (m_RAIB.IsPaired() && GetArmed())
- {
- if (GetPairDevice() == item)
- {
- SetHealth("", "", 0.0);
- InitiateExplosion();
- }
- }
- }
- }
-
- override void OnDisarmed(bool pWithTool)
- {
- super.OnDisarmed(pWithTool);
-
- UnpairRemote();
- UpdateVisuals(null);
-
- for (int att = 0; att < GetInventory().AttachmentCount(); att++)
- {
- ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(att));
- if (attachment)
- {
- attachment.UnlockFromParent();
- if (attachment.IsInherited(RemoteDetonator))
- {
- if (pWithTool)
- {
- GetInventory().DropEntity(InventoryMode.SERVER, this, attachment);
- attachment.SetHealth("", "", 0.0);
- }
- else
- {
- attachment.Delete();
- }
- }
- }
- }
-
- LockTriggerSlots();
- SetTakeable(true);
- }
-
- override void EEItemAttached(EntityAI item, string slot_name)
- {
- super.EEItemAttached(item, slot_name);
- if (slot_name == SLOT_TRIGGER)
- OnTriggerAttached(item);
- }
-
- override void EEItemDetached(EntityAI item, string slot_name)
- {
- super.EEItemDetached(item, slot_name);
- if (slot_name == SLOT_TRIGGER)
- OnTriggerDetached(item);
- }
-
- override void UpdateLED(int pState)
- {
- RemoteDetonatorReceiver receiver = RemoteDetonatorReceiver.Cast(FindAttachmentBySlotName(SLOT_TRIGGER));
- if (receiver)
- {
- receiver.UpdateLED(pState, true);
- }
- }
- protected void OnTriggerAttached(EntityAI entity)
- {
- Arm();
- UpdateVisuals(entity);
- UpdateLED(ERemoteDetonatorLEDState.LIT);
-
- for (int att = 0; att < GetInventory().AttachmentCount(); att++)
- {
- ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(att));
- if (attachment)
- {
- attachment.LockToParent();
- }
- }
- }
-
- protected void OnTriggerDetached(EntityAI entity)
- {
- UpdateVisuals(null);
- UpdateLED(ERemoteDetonatorLEDState.OFF);
- }
-
- protected void UpdateVisuals(EntityAI entity)
- {
- if (entity)
- {
- SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 0.0);
- }
- else
- {
- SetAnimationPhase(ANIM_PHASE_TRIGGER_REMOTE, 1.0);
- }
- }
-
-
- override string GetDeploySoundset()
- {
- return "placeImprovisedExplosive_SoundSet";
- }
-
- override string GetLoopDeploySoundset()
- {
- return "improvisedexplosive_deploy_SoundSet";
- }
-
- override protected bool UsesGlobalDeploy()
- {
- return true;
- }
- }
- class Plastic_Explosive_Placing : Plastic_Explosive {}
|