123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- // Wire type is used in the case of decrafting to give back the correct base Ingredient
- enum eWireMaterial
- {
- WIRE = 0,
- BARBED_WIRE = 1,
- ROPE = 2
- }
- class TripwireTrap : TrapBase
- {
- // Current state of the tripwire
- static const int FOLDED = 3;
- static const int DEPLOYED = 2;
- static const int TRIGGERED = 1;
- int m_State = FOLDED;
- private int m_WireMaterial;
-
- protected bool m_ResultOfAdvancedPlacing;
- protected vector m_TriggerPosition;
- protected vector m_TriggerOrientation;
-
- void TripwireTrap()
- {
- m_DamagePlayers = 0; //How much damage player gets when caught
- m_InitWaitTime = 0.0; //After this time after deployment, the trap is activated
- m_DefectRate = 15;
- m_NeedActivation = false;
- m_AnimationPhaseGrounded = "inventory";
- m_AnimationPhaseSet = "placing";
- m_AnimationPhaseTriggered = "triggered";
- m_InfoActivationTime = string.Format("#STR_TripwireTrap0%1#STR_TripwireTrap1", m_InitWaitTime.ToString()); // nefunguje dynamicke vyrazy mimo funkcii
-
- RegisterNetSyncVariableInt("m_State");
- }
-
- override void OnStoreSave(ParamsWriteContext ctx)
- {
- super.OnStoreSave(ctx);
-
- ctx.Write( m_State );
- }
-
- //----------------------------------------------------------------
- override bool OnStoreLoad(ParamsReadContext ctx, int version)
- {
- if ( !super.OnStoreLoad(ctx, version) )
- return false;
-
- int state = FOLDED;
- if ( !ctx.Read( state ) )
- state = FOLDED;
-
- SetState( state );
- RefreshState();
- return true;
- }
-
- override void CreateTrigger()
- {
- m_TrapTrigger = TripWireTrigger.Cast(GetGame().CreateObjectEx("TripWireTrigger", GetPosition(), SPAWN_FLAGS));
- vector mins = "-0.75 0.3 -0.01";
- vector maxs = "0.75 0.32 0.01";
- m_TrapTrigger.SetOrientation(GetOrientation());
- m_TrapTrigger.SetExtents(mins, maxs);
- m_TrapTrigger.SetParentObject(this);
-
- GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(DeferredEnableTrigger);
- }
-
- override void OnSteppedOn(EntityAI victim)
- {
- if (!victim)
- {
- return;
- }
-
- if (!victim.GetAllowDamage())
- {
- return;
- }
- // We must deal some damage, here 5 shock as melee damage in order to trigger hit animation
- if (GetGame().IsServer())
- {
- victim.ProcessDirectDamage(DamageType.CLOSE_COMBAT, this, "", "TripWireHit", "0 0 0", 1);
- SetState(TRIGGERED);
- SetInactive(false);
- }
-
- // We play the trap trigger sound
- #ifndef SERVER
- EffectSound sound = SEffectManager.PlaySound("TripwireTrap_Trigger_SoundSet", GetPosition());
- sound.SetAutodestroy(true);
- #endif
- }
-
- override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
- {
- super.OnItemLocationChanged(old_owner, new_owner);
- PlayerBase player = PlayerBase.Cast(new_owner);
- if (player)
- {
- StartDeactivate(player);
- return;
- }
- }
-
- override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
- {
- super.EEItemLocationChanged(oldLoc, newLoc);
-
- if (m_ResultOfAdvancedPlacing)
- {
- if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.GROUND)
- {
- SetActive();
- m_TrapTrigger.SetPosition(m_TriggerPosition);
- m_TrapTrigger.SetOrientation(m_TriggerOrientation);
- }
-
- m_ResultOfAdvancedPlacing = false;
- }
-
- if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.CARGO)
- {
- SetInactive();
- DeleteTrigger();
- SetState(FOLDED);
- RefreshState();
- }
- }
-
- override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
- {
- super.EEHealthLevelChanged(oldLevel, newLevel, zone);
- if (GetGame().IsServer())
- {
- if (newLevel == GameConstants.STATE_RUINED)
- {
- SetState(TRIGGERED);
- RefreshState();
- }
- }
- }
-
- override void SetInactive(bool stop_timer = true)
- {
- super.SetInactive(stop_timer);
- // de-attach attachments after "activating them"
- for (int att = 0; att < GetInventory().AttachmentCount(); att++)
- {
- ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(att));
- if (attachment)
- {
- if (attachment.IsLockedInSlot())
- {
- attachment.UnlockFromParent();
- }
-
- attachment.OnActivatedByItem(this);
- GetInventory().DropEntity(InventoryMode.SERVER, this, attachment);
- }
- }
- }
-
- void SetState(int state_ID)
- {
- m_State = state_ID;
- }
-
- int GetState()
- {
- return m_State;
- }
-
- void SetWireType( int wireType )
- {
- m_WireMaterial = wireType;
- }
-
- int GetWireType()
- {
- return m_WireMaterial;
- }
-
- override void RefreshState()
- {
- super.RefreshState();
-
- if (GetState() == FOLDED)
- {
- FoldTripWire();
- }
- }
-
- override void SetupTrapPlayer( PlayerBase player, bool set_position = true )
- {
- super.SetupTrapPlayer( player, set_position );
- SetState(DEPLOYED);
- }
-
- override void StartDeactivate(PlayerBase player)
- {
- super.StartDeactivate(player);
-
- DeleteTrigger();
- SetState(FOLDED);
- }
-
- // We do not want players to attach charges before trap is deployed
- override bool CanReceiveAttachment( EntityAI attachment, int slotId )
- {
- if ( GetState() != DEPLOYED )
- return false;
- return super.CanReceiveAttachment( attachment, slotId );
- }
-
- // As players cannot attch charges, we do not display the attachment slot before it is necessary
- override bool CanDisplayAttachmentSlot( int slot_id )
- {
- if ( GetState() != DEPLOYED )
- return false;
- return super.CanDisplayAttachmentSlot( slot_id );
- }
-
- override void EEItemAttached(EntityAI item, string slot_name)
- {
- super.EEItemAttached(item, slot_name);
-
- SetTakeable(false);
- }
-
- override void EEItemDetached(EntityAI item, string slot_name)
- {
- super.EEItemDetached(item, slot_name);
-
- SetTakeable(false);
- }
-
- override void EEKilled(Object killer)
- {
- if (m_TrapTrigger)
- {
- StartDeactivate(null);
- }
-
- super.EEKilled(killer);
- }
-
- // We reset the animation phases to see the tripwire as folded
- void FoldTripWire()
- {
- if ( m_AnimationPhaseGrounded != "" )
- {
- SetAnimationPhase( m_AnimationPhaseSet, 1 );
-
- if ( m_AnimationPhaseTriggered != m_AnimationPhaseGrounded )
- {
- SetAnimationPhase( m_AnimationPhaseTriggered, 1 );
- }
-
- SetAnimationPhase( m_AnimationPhaseGrounded, 0 );
- }
- }
-
- override void OnInventoryEnter( Man player )
- {
- SetState( FOLDED );
- }
-
- #ifdef PLATFORM_WINDOWS
- // How one sees the tripwire when in vicinity
- override int GetViewIndex()
- {
- if ( MemoryPointExists( "invView2" ) )
- {
- InventoryLocation il = new InventoryLocation;
- GetInventory().GetCurrentInventoryLocation( il );
- InventoryLocationType type = il.GetType();
- switch ( type )
- {
- case InventoryLocationType.CARGO:
- {
- return 0;
- }
- case InventoryLocationType.ATTACHMENT:
- {
- return 1;
- }
- case InventoryLocationType.HANDS:
- {
- return 0;
- }
- case InventoryLocationType.GROUND:
- {
- // Different view index depending on deployment state
- if ( GetState() == DEPLOYED )
- return 1;
- else if ( GetState() == TRIGGERED )
- return 2;
-
- // When folded
- return 0;
- }
- case InventoryLocationType.PROXYCARGO:
- {
- return 0;
- }
- default:
- {
- if ( GetState() == DEPLOYED )
- return 1;
- else if ( GetState() == TRIGGERED )
- return 2;
-
- // When folded
- return 0;
- }
- }
- }
- return 0;
- }
- #endif
-
- //================================================================
- // ADVANCED PLACEMENT
- //================================================================
-
- // On placement complete, set state, play sound, create trigger and synch to client
- override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
- {
- if (GetGame().IsServer())
- {
- SetState(DEPLOYED);
-
- m_TriggerPosition = position;
- m_TriggerOrientation = orientation;
- m_ResultOfAdvancedPlacing = true;
- }
-
- super.OnPlacementComplete(player, position, orientation);
- }
-
- override void OnPlacementCancelled(Man player)
- {
- super.OnPlacementCancelled(player);
-
- SetState(FOLDED);
-
- m_ResultOfAdvancedPlacing = false;
- }
-
- override bool IsDeployable()
- {
- return true;
- }
-
- // Tripwire cannot be taken if deployed with attachment
- override bool IsTakeable()
- {
- return GetState() != DEPLOYED || (GetInventory().AttachmentCount() == 0 && GetState() == DEPLOYED);
- }
-
- override string GetDeploySoundset()
- {
- return "tripwire_deploy_SoundSet";
- }
-
- override string GetLoopDeploySoundset()
- {
- return "tripwiretrap_deploy_SoundSet";
- }
-
- override void SetActions()
- {
- super.SetActions();
-
- AddAction(ActionTogglePlaceObject);
- AddAction(ActionDeployObject);
- }
-
- // ====================================
- // =========== DEPRECATED ===========
- // ====================================
-
- void UpdateProxySelections()
- {
- if ( GetInventory().AttachmentCount() > 0)
- {
- ItemBase attachment = ItemBase.Cast( GetInventory().GetAttachmentFromIndex(0) );
-
- if ( attachment )
- {
- // Hide all proxies
- for (int i = 1; i <= 3; i++)
- {
- HideSelection("s" + i + "_charge");
- }
-
- // Now show the one we need to see
- string proxy_to_show = string.Format("s%1_charge", GetState() );
- //Print(proxy_to_show);
- ShowSelection( proxy_to_show );
- }
- }
- }
- #ifdef DEVELOPER
- //================================================================
- // DEBUG
- //================================================================
-
- //Debug menu Spawn Ground Special
- override void OnDebugSpawn()
- {
- SetState(DEPLOYED);
- StartActivate(null);
- }
- override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
- {
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Activate", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DEACTIVATE_ENTITY, "Deactivate", FadeColors.LIGHT_GREY));
- outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
-
- super.GetDebugActions(outputList);
- }
-
- override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
- {
- if (super.OnAction(action_id, player, ctx))
- return true;
- if (GetGame().IsServer() || !GetGame().IsMultiplayer())
- {
- if (action_id == EActions.ACTIVATE_ENTITY)
- {
- StartActivate(null);
- }
- else if (action_id == EActions.DEACTIVATE_ENTITY)
- {
- SetInactive();
- }
- }
- return false;
- }
-
- #endif
- }
- class TripwireTrapDeployed : TripwireTrap
- {
-
- }
|