123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- class HescoBox extends Inventory_Base
- {
- static const int FOLDED = 0;
- static const int UNFOLDED = 1;
- static const int FILLED = 2;
- static const int PERCENTUAL_DAMAGE = 1;
-
- ref Timer m_Timer;
- protected int m_State;
-
- void HescoBox()
- {
- m_State = FOLDED;
- //synchronized variables
- RegisterNetSyncVariableInt( "m_State", FOLDED, FILLED );
- RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
- RegisterNetSyncVariableBool("m_IsDeploySound");
- }
-
- override bool HasProxyParts()
- {
- return true;
- }
-
- override bool CanPutIntoHands( EntityAI parent )
- {
- if( !super.CanPutIntoHands( parent ) )
- {
- return false;
- }
- return CanBeManipulated();
- }
-
- void Synchronize()
- {
- SetSynchDirty();
- }
- override void OnVariablesSynchronized()
- {
- super.OnVariablesSynchronized();
-
- //refresh visuals
- RefreshVisuals();
-
- if ( IsDeploySound() )
- {
- PlayDeploySound();
- }
- }
-
- void RefreshVisuals()
- {
- }
- int GetState()
- {
- return m_State;
- }
-
- void SetState( int state )
- {
- m_State = state;
- }
- bool CanBeFilledAtPosition( vector position )
- {
- string surface_type;
- GetGame().SurfaceGetType( position[0], position[2], surface_type );
-
- return GetGame().IsSurfaceDigable(surface_type);
- }
- bool CanBeManipulated()
- {
- if ( GetState() == FOLDED )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- void Fold()
- {
- this.ShowSelection( "inventory" );
- this.HideSelection( "placing" );
- this.HideSelection( "filled" );
-
- SetState( FOLDED );
- RefreshPhysics();
-
- if ( GetGame().IsServer() )
- {
- SetAllowDamage(true);
- Synchronize();
- float fold_damage = ( GetMaxHealth( "", "" ) / 100 ) * PERCENTUAL_DAMAGE;
- DecreaseHealth( "", "", fold_damage );
- }
- }
- void Unfold()
- {
- this.HideSelection( "inventory" );
- this.ShowSelection( "placing" );
- this.HideSelection( "filled" );
-
- SetState( UNFOLDED );
- RefreshPhysics();
-
- if ( GetGame().IsServer() )
- {
- SetAllowDamage(true);
- Synchronize();
- float unfold_damage = ( GetMaxHealth( "", "" ) / 100 ) * PERCENTUAL_DAMAGE;
- DecreaseHealth( "", "", unfold_damage );
- }
- }
- override void EEItemLocationChanged (notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
- {
- super.EEItemLocationChanged (oldLoc, newLoc);
-
- //RefreshPhysics();
- }
- override void RefreshPhysics()
- {
- super.RefreshPhysics();
-
- if ( this && !ToDelete() )
- {
- RemoveProxyPhysics( "inventory" );
- RemoveProxyPhysics( "placing" );
- RemoveProxyPhysics( "filled" );
-
- int state = GetState();
-
- switch (state)
- {
- case UNFOLDED:
- //ShowSelection( "placing" );
- AddProxyPhysics( "placing" );
-
- return;
-
- case FOLDED:
- AddProxyPhysics( "inventory" );
- return;
-
- case FILLED:
- AddProxyPhysics( "filled" );
- return;
- }
- }
- }
- void Fill()
- {
- this.HideSelection( "inventory" );
- this.HideSelection( "placing" );
- this.ShowSelection( "filled" );
-
- SetState( FILLED );
- RefreshPhysics();
-
- if ( GetGame().IsServer() )
- {
- Synchronize();
- DecreaseHealth( "", "", 5 ); //TODO Daniel implement soft skill bonus via useraction
- SetAllowDamage(false);
- }
- }
-
- override void OnStoreSave(ParamsWriteContext ctx)
- {
- super.OnStoreSave(ctx);
-
- // Save state
- ctx.Write( m_State );
- }
- override bool OnStoreLoad(ParamsReadContext ctx, int version)
- {
- if ( !super.OnStoreLoad(ctx, version) )
- return false;
-
- // Load folded/unfolded state
- int state = FOLDED;
- if ( !ctx.Read(state) )
- state = FOLDED;
-
- switch (state)
- {
- case FOLDED:
- {
- Fold();
- break;
- }
- case UNFOLDED:
- {
- Unfold();
- break;
- }
- case FILLED:
- {
- Fill();
- break;
- }
- }
- return true;
- }
-
- //================================================================
- // ADVANCED PLACEMENT
- //================================================================
-
- override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
- {
- super.OnPlacementComplete( player, position, orientation );
-
- if ( GetGame().IsServer() )
- {
- Unfold();
-
- SetIsDeploySound( true );
- }
- }
-
- override bool IsDeployable()
- {
- return true;
- }
- override string GetDeploySoundset()
- {
- return "placeHescoBox_SoundSet";
- }
-
- override string GetLoopDeploySoundset()
- {
- return "hescobox_deploy_SoundSet";
- }
-
- override void SetActions()
- {
- super.SetActions();
-
- AddAction(ActionTogglePlaceObject);
- AddAction(ActionFoldObject);
- AddAction(ActionDeployObject);
- }
-
- //!DEPRECATED
- protected ref EffectSound m_DeployLoopSound; //DEPRECATED in favor of m_DeployLoopSoundEx
-
- void PlayDeployLoopSound(); //!DEPRECATED
- void StopDeployLoopSound(); //!DEPRECATED
- }
|