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

FrightScript.KF_Roulette_Bet_Zone


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
00274
00275
/*
	--------------------------------------------------------------
	KF_Roulette_Bet_Zone
	--------------------------------------------------------------

	Represents a distinct betting area on the Roulette table. Cash
	thrown into this volume before the wheel spins will be considered
	a valid bet.

	Author :  Alex Quick

	--------------------------------------------------------------
*/

class KF_Roulette_Bet_Zone extends StaticMeshActor;

#exec OBJ LOAD FILE=Pier_SM.usx
#exec OBJ LOAD FILE=Pier_T.utx

/* A struct representing a player's bet on this number. */
struct SPlayerBetInfo
{
	var	PlayerController               BettingPlayer;
	var CashPickup                     BetPickup;   // the cash pickup representing our bet and winnings.
};


enum EBetType
{
    BET_Straight,
    BET_Even,
    BET_Odd,
    BET_Red,
    BET_Black,
    BET_1st,
    BET_2nd,
    BET_3rd,
    BET_Low,
    BET_High,
};

var () EBetType                                             ZoneType;

var () int                                                  ZoneNumber;

/* Reference to the table this zone belongs to */
var KF_Roulette_Wheel                                       OwningTable;

/* Array of all the bets in this zone in the current spin - Cleared after each spin.*/
var     array<SPlayerBetInfo>                               CurrentBets;

/* The amount this zone pays out when it hits. Set by OwningTable */
var     float                                               PayOutAmount;

var     StaticMesh                                          ChipPileSmall,ChipPileMedium,ChipPileHuge;


function OnActorLanded(Actor FallingActor)
{
    local CashPickup Dosh;
    Dosh = CashPickup(FallingActor);
    if(Dosh != none)
    {
        if(OwningTable != none &&
        OwningTable.AcceptNewBets())
        {
            AddBet(Dosh);
        }
        else
        {
            OwningTable.OnBetRejected();
        }
    }
}

/* We didn't win anything on this tile .. remove the cash */
function ClearOldBets()
{
    local int i,NumBets;

    Numbets = CurrentBets.length ;

    /* Remove all the old chips   */
    for(i = 0 ; i < NumBets ; i ++)
    {
        if(CurrentBets[i].BetPickup != none)
        {
            CurrentBets[i].BetPickup.Destroy();
        }
    }

    CurrentBets.length = 0 ;
}

function OnWheelSpin()
{
    local int i;

    for(i = 0 ; i < Currentbets.Length ; i ++)
    {
        if(CurrentBets[i].BetPickup != none)
        {
            SetChipState(Currentbets[i].BetPickup,false);
        }
    }
}

/* Allows or disables pickup of chips from the table */
function SetChipState( CashPickup ChipStack , bool AllowPickup)
{
    ChipStack.SetCollision(AllowPickup);
    OwningTable.ClientSetChipMaterial(ChipStack,AllowPickup);
}

function AddBet(CashPickup Dosh)
{
    local int ExistingIndex;
    local bool bPlayerAlreadyBet;

    if(Dosh == none ||
    Dosh.DroppedBy == none ||
    Dosh.DroppedBy.PlayerReplicationInfo == none)
    {
        return;
    }

    bPlayerAlreadyBet = FindExistingPlayer(Dosh,ExistingIndex);

    /* This guy already has a bet here, just update the amount he put down */
    if(bPlayerAlreadyBet)
    {
        CurrentBets[ExistingIndex].BetPickup.CashAmount += Dosh.CashAmount;
        /* also update the mesh on the table */

        CurrentBets[ExistingIndex].BetPickup.SetStaticMesh(GetChipMeshFor(CurrentBets[ExistingIndex].BetPickup.CashAmount));
    }
    else
    {
        CurrentBets.length = CurrentBets.length + 1;
        CurrentBets[CurrentBets.length - 1].BettingPlayer = PlayerController(Dosh.DroppedBy);
        Currentbets[CurrentBets.length - 1].BetPickup = Dosh;

        OwningTable.AddPlayer(CurrentBets[CurrentBets.length - 1].BettingPlayer);
    }


    log("Adding : $"$Dosh.CashAmount$" Bet to :"@GetZoneName());
    log("Current total on :"@GetZoneName()@" is : $"$CurrentBets[0].BetPickup.CashAmount);

    /* turn it into a stack of chips when it hits the table */

    if(!bPlayerAlreadyBet)
    {
        Dosh.bPreventFadeOut = true;
        Dosh.LifeSpan = 0;
        Dosh.SetStaticMesh(GetChipMeshFor(Dosh.CashAmount));

        SetChipState(Dosh,false);
        Dosh.bOnlyOwnerCanPickup = true;
        Dosh.CashAmount = 0;
    }
    else
    {
        Dosh.Destroy();
    }


    OwningTable.OnAddBet();
}

/* Returns the total amount of bets placed on this part of the table */
function int GetBetTotal()
{
    local int idx;
    local int BetTotal;

    for(idx = 0 ; idx < CurrentBets.length ; idx ++)
    {
        if(CurrentBets[idx].BetPickup != none &&
        !CurrentBets[idx].BetPickup.bHidden)
        {
            BetTotal += CurrentBets[idx].BetPickup.CashAmount;
        }
    }

    return BetTotal;
}

/* Determine which mesh to use for this cash pickup.  Large values means larger chip piles */
function StaticMesh GetChipMeshFor( int CashAmount)
{
    if(CashAmount <= 50)
    {
        return ChipPileSmall ;
    }
    else if(CashAmount <= 250)
    {
        return ChipPileMedium;
    }
    else
    {
        return ChipPileHuge;
    }
}

/* Convert the Enum for this Zone's Type into a human readable name */
function string GetZoneName()
{
    local String ZoneString;

    switch(ZoneType)
    {
        case BET_Straight   : ZoneString = string(ZoneNumber);  break;
        case BET_Even       : ZoneString = "Evens";             break;
        case BET_Odd        : ZoneString = "Odds";              break;
        case BET_Black      : ZoneString = "Black";             break;
        case BET_Red        : ZoneString = "Red" ;              break;
        case BET_1st        : ZoneString = "First12";           break;
        case BET_2nd        : ZoneString = "Second12";          break;
        case Bet_3rd        : ZoneString = "Third12";           break;
        case Bet_Low        : ZoneString = "Low";               break;
        case Bet_High       : ZoneString = "High";              break;
    }

    return ZoneString;
}

function PayOut()
{
    local int i;
    local int PayOutSum;

    for(i = 0 ; i < CurrentBets.length ; i ++)
    {
        if(CurrentBets[i].BettingPlayer != none )
        {
            PayOutSum = (CurrentBets[i].BetPickup.CashAmount + (CurrentBets[i].BetPickup.CashAmount * PayOutAmount));

            log("*************************");
            log(GetZoneName()@" Paid out $"$PayOutSum@" to - "@CurrentBets[i].BettingPlayer.PlayerReplicationInfo.PlayerName);

            CurrentBets[i].BetPickup.CashAmount = PayOutSum;
            CurrentBets[i].BetPickup.SetStaticMesh(GetChipMeshFor(PayOutSum));
            SetChipState(CurrentBets[i].BetPickup,true);
        }
    }
}

/* Has this player already placed a bet in this zone or not ? */
function bool FindExistingPlayer(CashPickup Dosh, optional out int ExistingIndex)
{
    local int i;

    for(i = 0 ; i < CurrentBets.length ; i ++)
    {
        if(CurrentBets[i].BettingPlayer == Dosh.DroppedBy &&
        CurrentBets[i].BetPickup != none &&
        !CurrentBets[i].BetPickup.bHidden )
        {
            ExistingIndex = i;
            return true;
        }
    }

    return false;
}

defaultproperties
{
     ChipPileSmall=StaticMesh'Pier_SM.Env_Pier_Chips_Small'
     ChipPileMedium=StaticMesh'Pier_SM.Env_Pier_Chips_Medium'
     ChipPileHuge=StaticMesh'Pier_SM.Env_Pier_Chips_Large'
     StaticMesh=StaticMesh'Pier_SM.1'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Fri 13-10-2023 03:17:26.000 - Creation time: Fri 13-10-2023 03:19:04.577 - Created with UnCodeX