Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

JBAddonJailCard.JBGameRulesJailCard


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
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
// ============================================================================
// JBGameRulesJailCard
// Copyright 2007 by [GSF]JohnDoe <gsfjohndoe@hotmail.com>
// Created by ?? (Someone from the Jailbreak community, most likely either
// Kartoshka or tarquin)
// $Id: JBGameRulesJailCard.uc,v 1.6 2007-05-19 15:06:55 johndoe Exp $
//
// GameRules class for the Jailbreak Addon JailCard (Get out of jail free card)
//
// CHANGELOG:
// 22 jan 2007 - Added first notifyround code, spawns jailcard(s) each round
//               Added reference to the JBAddon object
// 10 feb 2007 - Added AddPRI, RemovePRI and HasJailCard methods
//               Fixed CardHolder reset on new rounds
//               Added CanSendToJail code to force card-use when a player is
//               the last one to die
// 11 feb 2007 - Added PreventDeath code to allow people to steal JailCards by
//               fragging the carrier with the shieldgun
//               Added check for forced card-use if bAutoUseCard is set to True
// 12 feb 2007 - Added UseCard method
//               Modified NotifyPlayerJaied according to changes in the the
//               JailCard (weapon) code
//               Fixed a bug in PreventDeath that caused dropped pickups not to
//               register with the SpawnedPickups list.
// 19 may 2007 - Small change in NotifyPlayerJailed because of changes in
//               JBWeaponJailCard
// ============================================================================

class JBGameRulesJailCard extends JBGameRules;


//=============================================================================
// Properties
//=============================================================================

var class<LocalMessage> ConsoleMessageClass;


//=============================================================================
// Variables
//=============================================================================

var JBAddonJailCard myAddon;
var Array<PlayerReplicationInfo> CardHolders; // all PRI's of players who picked up a jailcard


//=============================================================================
// SetAddon
//=============================================================================

function SetAddon(JBAddonJailCard JBAJC)
{
    myAddon = JBAJC;
}


//=============================================================================
// AddPRI
//=============================================================================

function AddPRI(PlayerReplicationInfo myPRI)
{
    CardHolders.Insert(CardHolders.length, 1);
    CardHolders[CardHolders.length - 1] = myPRI;
    //log("PRI added: " $ myPRI.GetHumanReadableName());
    //log("CardHolders length: "$CardHolders.length);
}


//=============================================================================
// RemovePRI
//=============================================================================

function RemovePRI(PlayerReplicationInfo myPRI)
{
    local int i;
    i = HasJailCard(myPRI);

    if(i > -1)
        RemoveFromList(i);
}


//=============================================================================
// RemoveFromList
//=============================================================================

function RemoveFromList(int i)
{
    //log("PRI removed: " $ CardHolders[i].GetHumanReadableName());
    CardHolders.Remove(i, 1);
}


//=============================================================================
// HasJailCard
//
// Checks wether a given PRI is present in our CardHolders list
// If it is present, it returns its position in the list, otherwise returns -1
//=============================================================================

function int HasJailCard(PlayerReplicationInfo myPRI)
{
    local int result, i;
    result = -1;

    for(i = 0; i < CardHolders.length; i++) {
        if(CardHolders[i] == myPRI)
            result = i;
    }

    return result;
}


//=============================================================================
// UseCard
//
// Removes the PRI of the user from the list and spawns a new card
//=============================================================================

function UseCard(PlayerReplicationInfo myPRI, int i)
{
    if(i > -1)
        RemoveFromList(i);
    else
        RemovePRI(myPRI);

    BroadcastLocalizedMessage(ConsoleMessageClass, 200, myPRI);
    if(PlayerController(myPRI.Owner) != none)
        PlayerController(myPRI.Owner).ReceiveLocalizedMessage(MessageClass, 200, myPRI);

    myAddon.SpawnCard(myAddon.FindSpawnPoint());
}


// ============================================================================
// NotifyRound
//
// Called when a game round starts, including the first round in a game.
// ============================================================================

function NotifyRound()
{
    CardHolders.Remove(0, CardHolders.length);

    if(myAddon != none) {
        myAddon.ClearCards();
        myAddon.SpawnCards();
    }

    Super.NotifyRound();
}


// ============================================================================
// CanSendToJail
//
// Called when a player is about to be sent to jail by the game. Checks if the
// player has a Jail Card and if he is the last person of his team to die while
// free or bAutoUseCard is set to True (forced use).
// ============================================================================

function bool CanSendToJail(JBTagPlayer TagPlayer)
{
    local int i;
    local PlayerReplicationInfo myPRI;

    super.CanSendToJail(TagPlayer);

    myPRI = TagPlayer.GetPlayerReplicationInfo();
    i = HasJailCard(myPRI);
    if( (i > -1) &&
        (TagPlayer.IsFree()) &&
        ( (Jailbreak(Level.Game).CountPlayersJailed(TagPlayer.GetTeam()) == TagPlayer.GetTeam().Size - 1)  ||
        (myAddon.bAutoUseCard) ) ) {
        UseCard(myPRI, i);
        return false;
    }

    return true;
}


//=============================================================================
// PreventDeath
//
// Check if the killed person was carrying a JailCard and if he was killed with
// the shieldgun. If so, drop the JailCard.
//=============================================================================

function bool PreventDeath (Pawn Killed, Controller Killer, class<DamageType> myDamageType, vector HitLocation) {
    local int i;
    local PlayerReplicationInfo myPRI;

    Super.PreventDeath(Killed, Killer, myDamageType, HitLocation);

    myPRI = Killed.PlayerReplicationInfo;
    i = HasJailCard(myPRI);
    if(i > -1 && myDamageType == class'DamTypeShieldImpact' && myAddon.bAllowDropCard) { // shieldgun kill
        myAddon.SpawnCard(Killed.Location);
        RemoveFromList(i);
        BroadcastLocalizedMessage(ConsoleMessageClass, 400, myPRI);
    }

    return false;
}


//=============================================================================
// NotifyPlayerJailed
//
// Spawn the Jail Card in the jailed players inventory, if he picked it up
//=============================================================================

function NotifyPlayerJailed(JBTagPlayer TagPlayer)
{
    local JBWeaponJailCard myWeapon;
    local Pawn myP;

    Super.NotifyPlayerJailed(TagPlayer);

    if(HasJailCard(TagPlayer.GetController().PlayerReplicationInfo) > -1)
    {
        myP = TagPlayer.GetController().Pawn;
        myWeapon = Spawn(class'JBAddonJailCard.JBWeaponJailCard');
        myWeapon.setVars(Self, myP);
        myWeapon.GiveTo(myP);

        if(PlayerController(TagPlayer.GetController()) != none)
           PlayerController(TagPlayer.GetController()).ReceiveLocalizedMessage(MessageClass, 300, TagPlayer.GetController().PlayerReplicationInfo);
    }
}


// ============================================================================
// NotifyPlayerReleased
//
// We remove any jailcards the player may be holding
// ============================================================================

function NotifyPlayerReleased(JBTagPlayer TagPlayer, JBInfoJail Jail)
{
  local Inventory inv;
  local Pawn myPawn;

  Super.NotifyPlayerReleased(TagPlayer, Jail);
  log ("oh noes!");
  myPawn = TagPlayer.GetController().Pawn;

  for( inv=myPawn.Inventory;inv!=none;inv=inv.Inventory )
  {
    if( inv.IsA('JBWeaponJailCard') )
    {
        myPawn.DeleteInventory(inv);
        myPawn.NextWeapon();
        break;
    }
  }
}


// ============================================================================
// Default properties
// ============================================================================

defaultproperties
{
    RemoteRole = ROLE_SimulatedProxy;
    MessageClass=class'JBJailCardMessageScreen';
    ConsoleMessageClass=class'JBJailCardMessageConsole';
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: So 16.3.2008 13:48:06.000 - Creation time: Do 14.8.2014 09:58:42.221 - Created with UnCodeX