Skip to content

Commit

Permalink
Match Goals Tracking with XP
Browse files Browse the repository at this point in the history
  • Loading branch information
Zanieon committed Oct 22, 2023
1 parent 640d391 commit 28d409f
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Northstar.CustomServers/mod/scripts/vscripts/_xp.gnut
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ void function SetupPlayerPreviousXPValues( entity player )
player.SetPersistentVar( "previousFactionXP[" + xpFaction + "]", FactionGetXP( player, xpFaction ) )

foreach ( string xpTitan in shTitanXP.titanClasses )
{
player.SetPersistentVar( "previousTitanXP[" + xpTitan + "]", TitanGetXP( player, xpTitan ) )
player.SetPersistentVar( "fdPreviousTitanXP[" + xpTitan + "]", FD_TitanGetXP( player, xpTitan ) )
}

foreach ( string xpWeapon in shWeaponXP.weaponClassNames )
player.SetPersistentVar( GetItemPersistenceStruct( xpWeapon ) + ".previousWeaponXP", WeaponGetXP( player, xpWeapon ) )
Expand All @@ -30,11 +33,19 @@ bool function PlayerProgressionAllowed( entity player )
void function HandleXPGainForScoreEvent( entity player, ScoreEvent event )
{
// note: obviously all xp stuff can be cheated in if people want to on customs, this is mainly just here for fun for those who want it and feature completeness

int xpValue = ScoreEvent_GetXPValue( event )
int weaponXp = ScoreEvent_GetXPValueWeapon( event )
int titanXp = ScoreEvent_GetXPValueTitan( event )
int factionXp = ScoreEvent_GetXPValueFaction( event )

if ( player.GetPlayerNetInt( "xpMultiplier" ) > 0 || GetCurrentPlaylistVarInt( "double_xp_enabled", 0 ) == 1 )
{
xpValue *= 2
weaponXp *= 2
titanXp *= 2
factionXp *= 2
}

entity weapon = player.GetActiveWeapon()
if ( IsValid( weapon ) && ShouldTrackXPForWeapon( weapon.GetWeaponClassName() ) && weaponXp != 0 )
Expand Down Expand Up @@ -63,5 +74,8 @@ void function AddXP( entity player, int amount )
int newXp = player.GetPersistentVarAsInt( "xp" )
int newLevel = GetLevelForXP( newXp )
if ( newLevel != oldLevel )
{
Remote_CallFunction_NonReplay( player, "ServerCallback_PlayerLeveledUp", player.GetPersistentVarAsInt( "gen" ), newLevel )
AwardRandomItemsForPlayerLevels( player, player.GetPersistentVarAsInt( "gen" ), newLevel )
}
}
4 changes: 4 additions & 0 deletions Northstar.CustomServers/mod/scripts/vscripts/evac/_evac.gnut
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ void function Evac( int evacTeam, float initialWait, float arrivalTime, float wa
if ( !PlayerInDropship( player, dropship ) )
{
if ( player.GetTeam() == dropship.GetTeam() )
{
SetPlayerActiveObjective( player, "EG_DropshipExtractFailedEscape" )
SetPlayerChallengeEvacState( player, false )
}

continue
}
Expand All @@ -417,6 +420,7 @@ void function Evac( int evacTeam, float initialWait, float arrivalTime, float wa
Remote_CallFunction_NonReplay( player, "ServerCallback_DisableHudForEvac" )
Remote_CallFunction_NonReplay( player, "ServerCallback_SetClassicSkyScale", dropship.GetEncodedEHandle(), 0.7 )
Remote_CallFunction_NonReplay( player, "ServerCallback_SetMapSettings", 4.0, false, 0.4, 0.125 )
SetPlayerChallengeEvacState( player, true )

// display player [Evacuated] in killfeed
foreach ( entity otherPlayer in GetPlayerArray() )
Expand Down
7 changes: 7 additions & 0 deletions Northstar.CustomServers/mod/scripts/vscripts/faction_xp.gnut
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ void function AddFactionXP( entity player, int amount )
{
string faction = GetFactionChoice( player )
int oldLevel = FactionGetLevel( player, faction )
int FactionXPMatch = player.GetPersistentVarAsInt( "xp_match[" + XP_TYPE.FACTION_LEVELED + "]" )

// increment xp
player.SetPersistentVar( "factionXP[" + faction + "]", min( FactionGetXP( player, faction ) + amount, FactionGetMaxXP( faction ) ) )

// note: no notif for faction level up
if ( FactionGetLevel( player, faction ) != oldLevel )
{
AddPlayerScore( player, "FactionLevelUp" )
AwardRandomItemsForFactionLevels( player, faction, oldLevel, FactionGetLevel( player, faction ) )
IncrementPlayerChallengeFactionLeveledUp( player )
player.SetPersistentVar( "xp_match[" + XP_TYPE.FACTION_LEVELED + "]", FactionXPMatch + 1 )
}
}
178 changes: 178 additions & 0 deletions Northstar.CustomServers/mod/scripts/vscripts/mp/_challenges.gnut
Original file line number Diff line number Diff line change
@@ -1,6 +1,184 @@
global function InitChallenges
global function SetPlayerChallengeEvacState //Hooked in _evac.gnut
global function SetPlayerChallengeMatchWon //Hooked in _score.nut
global function SetPlayerChallengeMatchComplete //Hooked in _score.nut
global function SetPlayerChallengeSquadLeader //Hooked in _gamestate_mp.nut
global function SetPlayerChallengeMeritScore //Up to gamemodes to use this
global function IncrementPlayerChallengeTitanLeveledUp //Hooked in titan_xp.gnut
global function IncrementPlayerChallengeWeaponLeveledUp //Hooked in weapon_xp.gnut
global function IncrementPlayerChallengeFactionLeveledUp //Hooked in faction_xp.gnut (invisible but necessary for post-summary menu)
global function RegisterChallenges_OnMatchEnd //Hooked in _gamestate_mp.gnut
global function MatchChallenges_SetHappyHourActive //Quite sure this is called from Network code, which Northstar currently don't have

struct
{
table<entity,int> playerTotalMeritCount
bool isHappyHourActive
} file






/*=============================================================================================================
__ __ _ _ ____ _ _ _
| \/ | __ _ | |_ ___ | |__ / ___|| |__ __ _ | || | ___ _ __ __ _ ___ ___
| |\/| | / _` || __|/ __|| '_ \ | | | '_ \ / _` || || | / _ \| '_ \ / _` | / _ \/ __|
| | | || (_| || |_| (__ | | | | | |___ | | | || (_| || || || __/| | | || (_| || __/\__ \
|_| |_| \__,_| \__|\___||_| |_| \____||_| |_| \__,_||_||_| \___||_| |_| \__, | \___||___/
|___/
=============================================================================================================*/

void function InitChallenges()
{
#if (UI && CLIENT)

SCB_SetCompleteMeritState( 2 )
SCB_SetEvacMeritState( 2 )
SCB_SetMeritCount( 2 )
SCB_SetScoreMeritState( 2 )
SCB_SetWinMeritState( 2 )
SCB_SetWeaponMeritCount( -1 )
SCB_SetTitanMeritCount( -1 )

#elseif (SERVER && MP)

AddCallback_OnClientConnected( SetupPlayerMenuChallenges )
AddCallback_OnClientDisconnected( RemovePlayerFromChallengePool )

#endif
}

void function MatchChallenges_SetHappyHourActive()
{
file.isHappyHourActive = true
}

void function SetupPlayerMenuChallenges( entity player )
{
file.playerTotalMeritCount[ player ] <- 0

Remote_CallFunction_UI( player, "SCB_SetCompleteMeritState", 0 )
Remote_CallFunction_UI( player, "SCB_SetMeritCount", 0 )
Remote_CallFunction_UI( player, "SCB_SetScoreMeritState", 0 )
Remote_CallFunction_UI( player, "SCB_SetWinMeritState", 0 )
Remote_CallFunction_UI( player, "SCB_SetWeaponMeritCount", 0 )
Remote_CallFunction_UI( player, "SCB_SetTitanMeritCount", 0 )
}

void function RemovePlayerFromChallengePool( entity player )
{
if( player in file.playerTotalMeritCount )
delete file.playerTotalMeritCount[ player ]
}

void function RegisterChallenges_OnMatchEnd()
{
if( file.isHappyHourActive )
{
foreach( player in GetPlayerArray() )
{
AddPlayerScore( player, "HappyHourBonus" )
player.SetPersistentVar( "xp_match[" + XP_TYPE.HAPPY_HOUR + "]", 5 ) //The XP Given from Happy Hour Score is 5 merits
}
}
}






/*=============================================================================================================
____ _ _ _ _
/ ___| __ _ _ __ ___ ___ _ __ ___ ___ __| | ___ | | | | ___ ___ | | __ ___
| | _ / _` || '_ ` _ \ / _ \| '_ ` _ \ / _ \ / _` | / _ \ | |_| | / _ \ / _ \ | |/ // __|
| |_| || (_| || | | | | || __/| | | | | || (_) || (_| || __/ | _ || (_) || (_) || < \__ \
\____| \__,_||_| |_| |_| \___||_| |_| |_| \___/ \__,_| \___| |_| |_| \___/ \___/ |_|\_\|___/

=============================================================================================================*/

void function SetPlayerChallengeEvacState( entity player, bool successEvac )
{
if( successEvac )
{
file.playerTotalMeritCount[ player ]++
Remote_CallFunction_UI( player, "SCB_SetEvacMeritState", 1 )
player.SetPersistentVar( "xp_match[" + XP_TYPE.EVAC + "]", 1 )
Remote_CallFunction_UI( player, "SCB_SetMeritCount", file.playerTotalMeritCount[ player ] )
}
else
Remote_CallFunction_UI( player, "SCB_SetEvacMeritState", -1 )
}

void function SetPlayerChallengeMatchWon( entity player, bool playerWon )
{
if( playerWon )
{
file.playerTotalMeritCount[ player ]++
Remote_CallFunction_UI( player, "SCB_SetWinMeritState", 1 )
player.SetPersistentVar( "xp_match[" + XP_TYPE.MATCH_VICTORY + "]", 1 )
player.SetPersistentVar( "matchWin", true )
Remote_CallFunction_UI( player, "SCB_SetMeritCount", file.playerTotalMeritCount[ player ] )
}
else
Remote_CallFunction_UI( player, "SCB_SetWinMeritState", -1 )
}

void function SetPlayerChallengeMatchComplete( entity player )
{
file.playerTotalMeritCount[ player ]++
Remote_CallFunction_UI( player, "SCB_SetCompleteMeritState", 1 )
player.SetPersistentVar( "xp_match[" + XP_TYPE.MATCH_COMPLETED + "]", 1 )
player.SetPersistentVar( "matchComplete", true )
Remote_CallFunction_UI( player, "SCB_SetMeritCount", file.playerTotalMeritCount[ player ] )
}

void function SetPlayerChallengeSquadLeader( entity player )
{
Remote_CallFunction_NonReplay( player, "ServerCallback_SquadLeaderDoubleXP" )
Remote_CallFunction_NonReplay( player, "ServerCallback_SquadLeaderBonus", player.GetEncodedEHandle() )
player.SetPersistentVar( "matchSquadBonus", true )
Player_GiveDoubleXP( player, 1 )
foreach( entity teamplayer in GetPlayerArrayOfTeam( player.GetTeam() ) )
{
if( teamplayer == player )
continue

Remote_CallFunction_NonReplay( player, "ServerCallback_SquadLeaderBonus", teamplayer.GetEncodedEHandle() )
}
}

void function SetPlayerChallengeMeritScore( entity player )
{
file.playerTotalMeritCount[ player ]++
Remote_CallFunction_UI( player, "SCB_SetScoreMeritState", 1 )
player.SetPersistentVar( "xp_match[" + XP_TYPE.SCORE_MILESTONE + "]", 1 )
player.SetPersistentVar( "matchScoreEvent", true )
Remote_CallFunction_UI( player, "SCB_SetMeritCount", file.playerTotalMeritCount[ player ] )
}

void function IncrementPlayerChallengeTitanLeveledUp( entity player )
{
player.p.meritData.titanMerits++
file.playerTotalMeritCount[ player ]++

Remote_CallFunction_UI( player, "SCB_SetTitanMeritCount", player.p.meritData.titanMerits++ )
Remote_CallFunction_UI( player, "SCB_SetMeritCount", file.playerTotalMeritCount[ player ] )
}

void function IncrementPlayerChallengeWeaponLeveledUp( entity player )
{
player.p.meritData.weaponMerits++
file.playerTotalMeritCount[ player ]++

Remote_CallFunction_UI( player, "SCB_SetWeaponMeritCount", player.p.meritData.weaponMerits )
Remote_CallFunction_UI( player, "SCB_SetMeritCount", file.playerTotalMeritCount[ player ] )
}

void function IncrementPlayerChallengeFactionLeveledUp( entity player )
{
file.playerTotalMeritCount[ player ]++
Remote_CallFunction_UI( player, "SCB_SetMeritCount", file.playerTotalMeritCount[ player ] )
}
45 changes: 43 additions & 2 deletions Northstar.CustomServers/mod/scripts/vscripts/mp/_gamestate_mp.nut
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ void function GameStateEnter_WinnerDetermined_Threaded()
}
else
{
RegisterChallenges_OnMatchEnd()
if ( ClassicMP_ShouldRunEpilogue() )
{
ClassicMP_SetupEpilogue()
Expand Down Expand Up @@ -797,11 +798,51 @@ void function SetWinner( int team, string winningReason = "", string losingReaso
}

SetGameState( eGameState.WinnerDetermined )
ScoreEvent_RoundComplete( team )
}
else
{
SetGameState( eGameState.WinnerDetermined )

ScoreEvent_MatchComplete( team )
ScoreEvent_MatchComplete( team )

array<entity> players = GetPlayerArray()
int functionref( entity, entity ) compareFunc = GameMode_GetScoreCompareFunc( GAMETYPE )
if ( compareFunc != null )
{
players.sort( compareFunc )
int playerCount = players.len()
int currentPlace = 1
for ( int i = 0; i < 3; i++ )
{
if ( i >= playerCount )
continue

if ( i > 0 && compareFunc( players[i - 1], players[i] ) != 0 )
currentPlace += 1

switch( currentPlace )
{
case 1:
SetPlayerChallengeSquadLeader( players[i] )
UpdatePlayerStat( players[i], "game_stats", "mvp" )
UpdatePlayerStat( players[i], "game_stats", "top3OnTeam" )
break
case 2:
UpdatePlayerStat( players[i], "game_stats", "top3OnTeam" )
break
case 3:
UpdatePlayerStat( players[i], "game_stats", "top3OnTeam" )
break
}
}
}

foreach( entity xpplayer in players )
{
if ( xpplayer.GetPlayerNetInt( "xpMultiplier" ) > 0 || GetCurrentPlaylistVarInt( "double_xp_enabled", 0 ) == 1 )
xpplayer.SetPersistentVar( "matchSquadBonus", true )
}
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions Northstar.CustomServers/mod/scripts/vscripts/mp/_score.nut
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ global function ScoreEvent_TitanDoomed
global function ScoreEvent_TitanKilled
global function ScoreEvent_NPCKilled
global function ScoreEvent_MatchComplete
global function ScoreEvent_RoundComplete

global function ScoreEvent_SetEarnMeterValues
global function ScoreEvent_SetupEarnMeterValuesForMixedModes
Expand Down Expand Up @@ -241,8 +242,24 @@ void function ScoreEvent_MatchComplete( int winningTeam )
foreach( entity player in GetPlayerArray() )
{
AddPlayerScore( player, "MatchComplete" )
SetPlayerChallengeMatchComplete( player )
if ( player.GetTeam() == winningTeam )
{
AddPlayerScore( player, "MatchVictory" )
SetPlayerChallengeMatchWon( player, true )
}
else
SetPlayerChallengeMatchWon( player, false )
}
}

void function ScoreEvent_RoundComplete( int winningTeam )
{
foreach( entity player in GetPlayerArray() )
{
AddPlayerScore( player, "RoundComplete" )
if ( player.GetTeam() == winningTeam )
AddPlayerScore( player, "RoundVictory" )
}
}

Expand Down
18 changes: 18 additions & 0 deletions Northstar.CustomServers/mod/scripts/vscripts/titan_xp.gnut
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
global function AddTitanXP
global function AddFDTitanXP

void function AddTitanXP( entity player, int amount )
{
string titan = GetActiveTitanLoadout( player ).titanClass
int oldLevel = TitanGetLevel( player, titan )
int TitanXPMatch = player.GetPersistentVarAsInt( "xp_match[" + XP_TYPE.TITAN_LEVELED + "]" )

// increment xp
player.SetPersistentVar( "titanXP[" + titan + "]", min( TitanGetXP( player, titan ) + amount, TitanGetMaxXP( titan ) ) )
Remote_CallFunction_NonReplay( player, "ServerCallback_TitanXPAdded", shTitanXP.titanClasses.find( titan ), TitanGetXP( player, titan ), amount )

// level up notif
if ( TitanGetLevel( player, titan ) != oldLevel )
{
Remote_CallFunction_NonReplay( player, "ServerCallback_TitanLeveledUp", shTitanXP.titanClasses.find( titan ), TitanGetGen( player, titan ), TitanGetLevel( player, titan ) )
AddPlayerScore( player, "TitanLevelUp" )
IncrementPlayerChallengeTitanLeveledUp( player )
AwardRandomItemsForTitanLevels( player, titan, oldLevel, TitanGetLevel( player, titan ) )
player.SetPersistentVar( "xp_match[" + XP_TYPE.TITAN_LEVELED + "]", TitanXPMatch + 1 )
}
}

void function AddFDTitanXP( entity player, int fdXPamount )
{
string titanRef = GetActiveTitanLoadout( player ).titanClass

player.SetPersistentVar( "fdTitanXP[" + titanRef + "]", FD_TitanGetPreviousXP( player, titanRef ) + fdXPamount )
int startingLevel = FD_TitanGetLevelForXP( titanRef, FD_TitanGetPreviousXP( player, titanRef ) )
int endingLevel = FD_TitanGetLevelForXP( titanRef, FD_TitanGetXP( player, titanRef ) )

Player_GiveFDUnlockPoints( player, endingLevel - startingLevel )
AwardRandomItemsForFDTitanLevels( player, titanRef, startingLevel, endingLevel )
}
Loading

0 comments on commit 28d409f

Please sign in to comment.