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

KFStoryGame.ObjCondition_Counter


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
/*
	--------------------------------------------------------------
	Condition_Counter
	--------------------------------------------------------------

    A Condition which increments each time its owning Objective is
    triggered.

	Author :  Alex Quick

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

class ObjCondition_Counter extends KF_ObjectiveCondition
editinlinenew;

enum ECounterType
{
	CT_Default,         	// default setting - NumToCount is user defined and NumCounted represents the number of times this objective has been triggered .
	CT_Cash,				// NumCounted becomes the total cash sum accrued by all players. NumToCount is whatever sum of cash you expect them to accumulate.
	CT_PlayerCount,        // NumCounted becomes the number of unique players who triggered this Objective.  NumToCount is the total number of active players in the match.
};


var	()	 ECounterType											CountType;

var ()	             int										NumToCount;

var                  int                                        NumCounted,SavedNumCounted;

/* if SuccessCondition is set to OBJ_Counter and CountType is CT_PlayerCount, this array will store unique player IDs for each
played who has been 'counted' so far. */
var											array<int>			CountedPlayerIDs;


function SaveState()
{
    Super.SaveState();
    SavedNumCounted = NumCounted;
}

function Reset()
{
    Super.Reset();
    NumCounted = SavedNumCounted;
    CountedPlayerIDs.length = 0;
}



/* returns the percentage of completion for this condition */
function       float        GetCompletionPct()
{
    local float Numerator;
    local float Denominator;

    switch(CountType)
    {
        case CT_Default 			:	break;
		case CT_Cash 				:	NumCounted = GetObjOwner().StoryGI.GetTotalCashSum();						break;
		case CT_PlayerCount		    :	NumToCount = Max(GetObjOwner().StoryGI.GetTotalActivePlayers(),1);	 	    break;
    }

    Numerator = float(NumCounted);
    // Take the floor of the modified amount to ensure accuracy. Also, there's no floor function available.
    Denominator = float(int(float(NumToCount) * GetTotalDifficultyModifier()));
    return FClamp(Numerator/Denominator,0.f,1.f) ;
}


function Trigger( actor Other, pawn EventInstigator)
{
    Super.Trigger(Other,EventInstigator);

	/* each trigger increments the 'counter' for objectives of that type */
	if(ConditionIsActive() && ValidForCounting(EventInstigator))
	{
        SetTargetActor(InstigatorName,EventInstigator);
		NumCounted = Min(NumCounted + 1,Round(NumToCount * GetTotalDifficultyModifier())) ;
	}
}

/* 	Relevant if this Objective is configured to count players -
	returns true if this is the first time the supplied pawn has triggered us
*/

function bool		ValidForCounting(Pawn	CountedPawn)
{
	local int i;

	if(CountType == CT_PlayerCount &&
    CountedPawn.PlayerReplicationInfo != none)
	{
		for( i = 0 ; i < CountedPlayerIDs.length ; i ++)
		{
			/* this guy has already been counted.  ignore him */
			if(CountedPlayerIDs[i] == CountedPawn.PlayerReplicationInfo.PlayerID)
			{
				return false;
			}
		}

		/* If we got this far CountedPawn is unique - add his ID to the array */
		CountedPlayerIDs[CountedPlayerIDs.length] = CountedPawn.PlayerReplicationInfo.PlayerID ;
	}

	return true;
}

function        string      GetDataString()
{
    if(HUD_Screen.Screen_CountStyle < 1)
    {
       return NumCounted$"/"$int(NumToCount * GetTotalDifficultyModifier()) ;
    }

    return string(Max((int(NumToCount * GetTotalDifficultyModifier()))-NumCounted,0)) ;
}

defaultproperties
{
     NumToCount=1
}

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