# SpatialFear.SFInvItemTrigger

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 |
    //=============================================================================
    // Spatial Fear
    // Class: SFInvItemTrigger
    // Descripton: Subclasses of SFTrigger, that gives the configured item to the
    //						the player upon touching.
    //
    // Author: Markus Nuebel
    //=============================================================================

    class SFInvItemTrigger extends SFTrigger;

    // Give/Take item
    var enum EDirection
    {
    	DT_Give,
    	DT_Take
    } DirectionType;

    var (SpatialFear) EDirection Type; // This trigger, gives/removes
    var (SpatialFear) class<Inventory> InventoryItem; // Inventory item to give to player upon touching.
    var (SpatialFear) name GiveEvent; // Fired, when the item is given to the player
    var (SpatialFear) name TakeEvent; // Fired, when the item is taken from the player

    // Checks if the item is already possessed
    function bool alreadyOwned(SFPlayer oPlayer)
    {
    	local Inventory oItem;

    	oItem = oPlayer.FindInventoryType(InventoryItem);

    	return (None != oItem);
    }

    // Gives the configured item to the player
    function giveToPlayer(SFPlayer oPlayer)
    {
    	local Inventory oInv;
    	local SFPickup	oSFPick;
    	local SFHUD		oHUD;

    	// Some inits
    	oHUD	= SFHUD(oPlayer.myHud);

    	if (!alreadyOwned(oPlayer))
    	{
    		// Spawn a copy of the new inventory item
    		oInv = Spawn(InventoryItem,,,oPlayer.Location);
    		if(oInv.IsA('SFPickup'))
    			SFPickup(oInv).bManualPickup=False;

    		if(None != oInv)
    		{
    			oInv.ReSpawnTime	= 0.0f;
    			oInv.GiveTo(oPlayer);
    			 if(oInv.IsA('SFPickup'))
    			 {
    				if(oPlayer.m_bVisorUnitUpgrade)
    					oHUD.showItemPickup(oInv);
    					oHUD.insertIntoBelt(SFPickup(oInv));
    			 }

    			FireEvent(oPlayer, GiveEvent);
    		}
    	}

    }

    // Removes an item from the players inventory
    function takeFromPlayer(SFPlayer oPlayer)
    {
    	local Inventory	inv;

    	if (None != oPlayer.Inventory)
    	{
    		inv = oPlayer.FindInventoryType(InventoryItem);
    		if(None != inv)
    		{
    			if(inv.IsA('SFPickup'))
    				SFHUD(oPlayer.myHUD).removeItemFromBelt(SFPickup(inv));
    			inv.Destroy();

    			FireEvent(oPlayer, TakeEvent);
    		}
    	}
    }

    function Trigger( actor Other, pawn EventInstigator )
    {
    	if(EventInstigator.IsA('SFPlayer'))
    		Touch(EventInstigator);
    }

    // Overwritten here to update the players inventory
    function Touch( actor Other )
    {
    	local SFPlayer	oPlayer;
    	local Inventory	oInv;

    	if(Other.IsA('SFPlayer'))
    	{
    		if( IsRelevant( Other ) )
    		{
    			oPlayer = SFPlayer(Other);
    			if(None != oPlayer)
    			{
    				if(Type == DT_Give)
    					giveToPlayer(oPlayer);
    				else
    					takeFromPlayer(oPlayer);
    			}

    		}
    	}

    	// Call to base class
    	Super.Touch(Other);
    }

    // Manually fires the actors event
    function FireEvent( actor Other, name evtFireEvent )
    {
    	local actor A;

    	if ( ReTriggerDelay > 0 )
    	{
    		if ( Level.TimeSeconds - TriggerTime < ReTriggerDelay )
    			return;
    		TriggerTime = Level.TimeSeconds;
    	}
    	// Broadcast the Trigger message to all matching actors.
    	if( Event != '' )
    		foreach AllActors( class 'Actor', A, evtFireEvent )
    			A.Trigger( Self, Pawn(Other));

    	if ( Other.IsA('Pawn') && (Pawn(Other).SpecialGoal == self) )
    		Pawn(Other).SpecialGoal = None;

    	if( Message != "" )
    		// Send a string message to the toucher.
    		Other.Instigator.ClientMessage( Message );

    	if( bTriggerOnceOnly )
    		// Ignore future touches.
    		SetCollision(False);
    	else if ( RepeatTriggerTime > 0 )
    		SetTimer(RepeatTriggerTime, false);
    }

    defaultproperties
    {
    }

class file time: 12/7/2003 3:58:24 PM - creation time: 12/7/2003 4:03:44 PM
Created with UnCodeX