Advertisement
Guest User

UPakScubaGear.uc

a guest
Mar 31st, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // UPakScubaGear.
  3. //=============================================================================
  4. class UPakScubaGear expands Pickup;
  5.  
  6. var vector X,Y,Z;
  7. var Actor EffectsActor;
  8. var bool bWarningSignaled, bUseRechargedMessage;
  9. var localized string RechargedMessage;
  10. var localized string LowOxygenMessage;
  11.  
  12. function inventory PrioritizeArmor( int Damage, name DamageType, vector HitLocation )
  13. {
  14.     if( DamageType == 'Breathe' )
  15.     {
  16.         if ( Pawn( Owner )!= None && IsInState( 'Activated' )
  17.             && !Pawn( Owner ).FootRegion.Zone.bPainZone ) Pawn( Owner ).PainTime = 12;
  18.         GotoState( 'Deactivated' );
  19.     }
  20.     else if( DamageType == 'Drowned' && Damage == 0 )
  21.     {
  22.         GoToState( 'Activated' );
  23.     }
  24.     if( DamageType == 'Drowned' )
  25.     {
  26.         NextArmor = None;
  27.         Return Self;
  28.     }
  29.     return Super.PrioritizeArmor( Damage, DamageType, HitLocation );
  30. }
  31.  
  32. function Activate()
  33. {
  34.     if (Charge > 0 && Pawn(Owner).HeadRegion.Zone.bWaterZone && !Pawn(Owner).FootRegion.Zone.bPainZone)
  35.         Super.Activate();
  36. }
  37.  
  38. function UsedUp()
  39. {
  40.     local Pawn OwnerPawn;
  41.  
  42.     OwnerPawn = Pawn(Owner);
  43.     if (Charge <= 0 && OwnerPawn != none && 0 < OwnerPawn.PainTime && OwnerPawn.PainTime < 15 &&
  44.         !OwnerPawn.FootRegion.Zone.bPainZone && OwnerPawn.HeadRegion.Zone.bWaterZone)
  45.     {
  46.         OwnerPawn.PainTime = 15;
  47.     }
  48.     GotoState( 'DeActivated' );
  49. }
  50.  
  51. function bool UseSpecialEffectsActor()
  52. {
  53.     return Class == class'UPakScubaGear';
  54. }
  55.  
  56. function EnableInventoryEffects()
  57. {
  58.     local Triggers SoundActor;
  59.  
  60.     if (!UseSpecialEffectsActor())
  61.         EffectsActor = Owner;
  62.     else if (EffectsActor == none || EffectsActor.bDeleteMe)
  63.     {
  64.         // trying to find a sound source of other scuba gear
  65.         foreach Owner.ChildActors(class'Triggers', SoundActor)
  66.             if (SoundActor.Tag == 'SCUBAGear_EffectsActor') // name of the tag intentionally matches the one for UnrealShare.SCUBAGear
  67.             {
  68.                 EffectsActor = SoundActor; // EffectsActor is shared between different scuba gears
  69.                 SetScubaAmbientSound();
  70.                 return;
  71.             }
  72.  
  73.         EffectsActor = Spawn(class'Triggers', Owner, 'SCUBAGear_EffectsActor', Owner.Location);
  74.         if (EffectsActor != none)
  75.         {
  76.             EffectsActor.SetPhysics(PHYS_Trailer);
  77.             EffectsActor.RemoteRole = ROLE_SimulatedProxy;
  78.             EffectsActor.SoundVolume = Owner.default.SoundVolume;
  79.         }
  80.         else
  81.             EffectsActor = Owner;
  82.     }
  83.  
  84.     SetScubaAmbientSound();
  85. }
  86.  
  87. function SetScubaAmbientSound()
  88. {
  89.     if (EffectsActor == none || Pawn(Owner) == none)
  90.         return;
  91.     if (EffectsActor != Owner && (Owner.AmbientSound == ActivateSound || Owner.AmbientSound == RespawnSound))
  92.         EffectsActor.AmbientSound = none;
  93.     else if (Pawn(Owner).HeadRegion.Zone.bWaterZone)
  94.         EffectsActor.AmbientSound = ActivateSound;
  95.     else
  96.         EffectsActor.AmbientSound = RespawnSound;
  97. }
  98.  
  99. function DisableInventoryEffects()
  100. {
  101.     if (Owner != none && (!UseSpecialEffectsActor() || EffectsActor == Owner))
  102.         Owner.AmbientSound = none;
  103.     if (EffectsActor != none && EffectsActor != Owner)
  104.         EffectsActor.Destroy();
  105.     EffectsActor = none;
  106. }
  107.  
  108. state Sleeping
  109. {
  110.     ignores Touch;
  111.  
  112. Begin:
  113.     Sleep(ReSpawnTime);
  114.     if (RespawnSound != sound'UnrealShare.Pickups.Scubal2')
  115.         PlaySound(RespawnSound);
  116.     Sleep(Level.Game.PlaySpawnEffect(self));
  117.     GoToState('Pickup');
  118. }
  119.  
  120. state Activated
  121. {
  122.     function EndState()
  123.     {
  124.         if (Owner != none)
  125.             Owner.PlaySound(DeactivateSound);
  126.         DisableInventoryEffects();
  127.         bActive = false;       
  128.     }
  129.  
  130.     function Timer()
  131.     {
  132.         local float LocalTime;
  133.         local Bubble1 b;
  134.         local Pawn OwnerPawn;
  135.  
  136.         OwnerPawn = Pawn(Owner);
  137.         if (OwnerPawn == none)
  138.         {
  139.             UsedUp();
  140.             return;
  141.         }
  142.         Charge -= 1;
  143.         if( Charge<-0 )
  144.         {
  145.             OwnerPawn.ClientMessage( ExpireMessage );
  146.             UsedUp();  
  147.         }
  148.         if (UseSpecialEffectsActor() && Charge > 0)
  149.             EnableInventoryEffects();
  150.         LocalTime += 0.1;
  151.         LocalTime = LocalTime - int( LocalTime );
  152.         if (OwnerPawn.HeadRegion.Zone.bWaterZone && !OwnerPawn.FootRegion.Zone.bPainZone)
  153.         {
  154.             if (0 < OwnerPawn.PainTime && OwnerPawn.PainTime < OwnerPawn.UnderWaterTime)
  155.             {
  156.                 OwnerPawn.PainTime = FMin(OwnerPawn.PainTime + 0.1, OwnerPawn.UnderWaterTime);
  157.                 if (OwnerPawn.PainTime < 1)
  158.                 {
  159.                     Charge -= (1 - OwnerPawn.PainTime) * 10;
  160.                     OwnerPawn.PainTime = 1;
  161.                 }
  162.             }
  163.  
  164.             if( FRand() < LocalTime )
  165.             {
  166.                 GetAxes(OwnerPawn.ViewRotation, X, Y, Z )
  167.                 b = Spawn( class'Bubble1', Owner, '', OwnerPawn.Location
  168.                     + 20.0 * X - ( FRand() * 6 + 5 ) * Y - ( FRand() * 6 + 5 ) * Z );
  169.                 if( b != None )
  170.                 {
  171.                     b.DrawScale = FRand() * 0.1 + 0.05;
  172.                 }
  173.             }
  174.             if( FRand() < LocalTime )
  175.             {
  176.                 GetAxes(OwnerPawn.ViewRotation, X, Y, Z);  
  177.                 b = Spawn( class'Bubble1', Owner, '', OwnerPawn.Location
  178.                     + 20.0 * X + ( FRand() * 6 + 5 ) * Y - ( FRand() * 6 + 5 ) * Z );
  179.                 if( b != None )
  180.                 {
  181.                     b.DrawScale = FRand() * 0.1 + 0.05;
  182.                 }
  183.             }
  184.         }
  185.         if( Charge < ( Default.Charge * 0.25 ) && !bWarningSignaled )
  186.         {
  187.             bWarningSignaled = True;
  188.             OwnerPawn.ClientMessage( LowOxygenMessage );
  189.         }
  190.     }
  191. Begin:
  192.     if (Owner == none)
  193.         GotoState('');
  194.     if (Pawn(Owner).HeadRegion.Zone.bWaterZone && !Pawn(Owner).FootRegion.Zone.bPainZone)
  195.     {
  196.         SetTimer(0.1, true);
  197.         EnableInventoryEffects();
  198.     }
  199. }
  200.  
  201. state DeActivated
  202. {
  203.     function Timer()
  204.     {
  205.         if( Pawn( Owner ) == None )
  206.         {
  207.             UsedUp();
  208.             return;
  209.         }
  210.         if( Charge < Default.Charge && !Pawn( Owner ).HeadRegion.Zone.bWaterZone )
  211.             Charge = Min(Default.Charge, Charge + 5);
  212.         else if( Charge == Default.Charge && bUseRechargedMessage )
  213.         {
  214.             Pawn( Owner ).ClientMessage( RechargedMessage );
  215.             bUseRechargedMessage = false;
  216.             Disable( 'Timer' );
  217.         }
  218.     }
  219.  
  220. Begin:
  221.  
  222.     bWarningSignaled = False;
  223.    
  224.     if( Owner == None )
  225.         GotoState( '' );
  226.     if( Charge < Default.Charge )
  227.     {
  228.         SetTimer( 0.05,True );
  229.         if( Charge < Default.Charge - 20 )
  230.             bUseRechargedMessage = true;
  231.     }
  232. }
  233.  
  234. defaultproperties
  235. {
  236.     RechargedMessage="ScubaGear fully recharged."
  237.     LowOxygenMessage="Oxygen supply critically low"
  238.     bActivatable=True
  239.     bDisplayableInv=True
  240.     PickupMessage="You picked up the SCUBA gear"
  241.     ItemName="Marine SCUBAGear"
  242.     RespawnTime=20.000000
  243.     PickupViewMesh=LodMesh'UnrealShare.Scuba'
  244.     Charge=1250
  245.     PickupSound=Sound'UnrealShare.Pickups.GenPickSnd'
  246.     ActivateSound=Sound'UnrealShare.Pickups.Scubal1'
  247.     DeActivateSound=Sound'UnrealShare.Pickups.Scubada1'
  248.     RespawnSound=Sound'UnrealShare.Pickups.Scubal2'
  249.     Icon=Texture'UnrealShare.Icons.I_Scuba'
  250.     M_Deactivated="deactivated... Recharging."
  251.     Mesh=LodMesh'UnrealShare.Scuba'
  252.     CollisionRadius=18.000000
  253.     CollisionHeight=15.000000
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement