Engine
Class Pickup

source: c:\runehov\Engine\Classes\Pickup.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Inventory
         |
         +--Engine.Pickup
Direct Known Subclasses:Food, Runes, sbAdminTool, sbPlayerTool

class Pickup
extends Engine.Inventory

//============================================================================= // Pickup items. //=============================================================================
Variables
 String ExpireMessage
           Messages shown when pickup charge runs out
 Inventory Inv
 int NumCopies
 bool bAutoActivate
           Messages shown when pickup charge runs out
 bool bCanActivate
           Item can be selected and activated
 bool bCanHaveMultipleCopies
           if player can possess more than one of this

States
Activated, Pickup

Function Summary
 bool HandlePickupQuery(Inventory Item)
     
//
// Advanced function which lets existing items in a pawn's inventory
// prevent the pawn from picking something up. Return true to abort pickup
// or if item handles the pickup
 Inventory SpawnCopy(Pawn Other)
 void TravelPostAccept()
 float UseCharge(float Amount)


State Activated Function Summary
 void Activate()


State Pickup Function Summary
 void UsedUp()
     
//
// This is called when a usable inventory item has used up it's charge.
//
 void PickupFunction(Pawn Other)
 void BeginState()
 void Touch(Actor Other)



Source Code


00001	//=============================================================================
00002	// Pickup items.
00003	//=============================================================================
00004	class Pickup extends Inventory
00005		abstract
00006		native;
00007	//	nativereplication;
00008	
00009	var inventory Inv;
00010	var travel int NumCopies;
00011	var() bool bCanHaveMultipleCopies;  // if player can possess more than one of this
00012	var() bool bCanActivate;			// Item can be selected and activated
00013	var() localized String ExpireMessage; // Messages shown when pickup charge runs out
00014	var() bool bAutoActivate;
00015	
00016	replication
00017	{
00018		// Things the server should send to the client.
00019		reliable if( bNetOwner && (Role==ROLE_Authority) )
00020			NumCopies;
00021	}
00022	
00023	function TravelPostAccept()
00024	{
00025		Super.TravelPostAccept();
00026		PickupFunction(Pawn(Owner));
00027	}
00028	
00029	//
00030	// Advanced function which lets existing items in a pawn's inventory
00031	// prevent the pawn from picking something up. Return true to abort pickup
00032	// or if item handles the pickup
00033	function bool HandlePickupQuery( inventory Item )
00034	{
00035		if (item.class == class) 
00036		{
00037			if (bCanHaveMultipleCopies) 
00038			{   // for items like Artifact
00039				NumCopies++;
00040				if (Level.Game.LocalLog != None)
00041					Level.Game.LocalLog.LogPickup(Item, Pawn(Owner));
00042				if (Level.Game.WorldLog != None)
00043					Level.Game.WorldLog.LogPickup(Item, Pawn(Owner));
00044				if ( Item.PickupMessageClass == None )
00045					Pawn(Owner).ClientMessage(item.PickupMessage, 'Pickup');
00046				else
00047					Pawn(Owner).ReceiveLocalizedMessage( item.PickupMessageClass, 0, None, None, item.Class );
00048				Item.PlaySound (Item.PickupSound,,2.0);
00049				Item.SetRespawn();
00050			}
00051			else if ( bDisplayableInv ) 
00052			{		
00053				if ( Charge<Item.Charge )	
00054					Charge= Item.Charge;
00055				if (Level.Game.LocalLog != None)
00056					Level.Game.LocalLog.LogPickup(Item, Pawn(Owner));
00057				if (Level.Game.WorldLog != None)
00058					Level.Game.WorldLog.LogPickup(Item, Pawn(Owner));
00059				if ( Item.PickupMessageClass == None )
00060					Pawn(Owner).ClientMessage(item.PickupMessage, 'Pickup');
00061				else
00062					Pawn(Owner).ReceiveLocalizedMessage( item.PickupMessageClass, 0, None, None, item.Class );
00063				Item.PlaySound (item.PickupSound,,2.0);
00064				Item.SetReSpawn();
00065			}
00066			return true;				
00067		}
00068		if ( Inventory == None )
00069			return false;
00070	
00071		return Inventory.HandlePickupQuery(Item);
00072	}
00073	
00074	function float UseCharge(float Amount);
00075	
00076	function inventory SpawnCopy( pawn Other )
00077	{
00078		local inventory Copy;
00079	
00080		Copy = Super.SpawnCopy(Other);
00081		Copy.Charge = Charge;
00082		return Copy;
00083	}
00084	
00085	auto state Pickup
00086	{	
00087		function Touch( actor Other )
00088		{
00089			local Inventory Copy;
00090	
00091			// If touched by a player pawn, let him pick this up.
00092			if ( ValidTouch(Other) ) 
00093			{
00094				if (Level.Game.LocalLog != None)
00095					Level.Game.LocalLog.LogPickup(Self, Pawn(Other));
00096				if (Level.Game.WorldLog != None)
00097					Level.Game.WorldLog.LogPickup(Self, Pawn(Other));
00098				Copy = SpawnCopy(Pawn(Other));
00099				if (bActivatable && Pawn(Other).SelectedItem==None) 
00100					Pawn(Other).SelectedItem=Copy;
00101				if (bActivatable && bAutoActivate && Pawn(Other).bAutoActivate) 
00102					Copy.Activate();
00103				if ( PickupMessageClass == None )
00104					Pawn(Other).ClientMessage(PickupMessage, 'Pickup');
00105				else
00106					Pawn(Other).ReceiveLocalizedMessage( PickupMessageClass, 0, None, None, Self.Class );
00107				PlaySound (PickupSound,,2.0);	
00108				Pickup(Copy).PickupFunction(Pawn(Other));
00109			}
00110		}
00111	
00112		function BeginState()
00113		{
00114			Super.BeginState();
00115			NumCopies = 0;
00116		}
00117	}
00118	
00119	function PickupFunction(Pawn Other)
00120	{
00121	}
00122	
00123	//
00124	// This is called when a usable inventory item has used up it's charge.
00125	//
00126	function UsedUp()
00127	{
00128		if ( Pawn(Owner) != None )
00129		{
00130			bActivatable = false;
00131			Pawn(Owner).NextItem();
00132			if (Pawn(Owner).SelectedItem == Self) {
00133				Pawn(Owner).NextItem();	
00134				if (Pawn(Owner).SelectedItem == Self) Pawn(Owner).SelectedItem=None;
00135			}
00136			if (Level.Game.LocalLog != None)
00137				Level.Game.LocalLog.LogItemDeactivate(Self, Pawn(Owner));
00138			if (Level.Game.WorldLog != None)
00139				Level.Game.WorldLog.LogItemDeactivate(Self, Pawn(Owner));
00140			if ( ItemMessageClass != None )
00141				Pawn(Owner).ReceiveLocalizedMessage( ItemMessageClass, 0, None, None, Self.Class );
00142			else
00143				Pawn(Owner).ClientMessage(ExpireMessage);	
00144		}
00145	//	Owner.PlaySound(DeactivateSound);
00146		Destroy();
00147	}
00148	
00149	
00150	state Activated
00151	{
00152		function Activate()
00153		{
00154			if ( (Pawn(Owner) != None) && Pawn(Owner).bAutoActivate 
00155				&& bAutoActivate && (Charge>0) )
00156					return;
00157	
00158			Super.Activate();	
00159		}
00160	}
00161	
00162	defaultproperties
00163	{
00164	     bRotatingPickup=False
00165	}

End Source Code