aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/_xp.gnut
blob: 97d993e6534c0b719b55a84cfc801f92bcdcd7ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
global function SvXP_Init
global function PlayerProgressionAllowed
global function HandleXPGainForScoreEvent
global function AddXP

void function SvXP_Init()
{
	AddCallback_OnClientConnected( SetupPlayerPreviousXPValues )
}

void function SetupPlayerPreviousXPValues( entity player )
{
	InitXP( player )

	foreach ( string xpFaction in GetAllFactionRefs() )
		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 ) )
}

bool function PlayerProgressionAllowed( entity player )
{
	return true
}

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 )
		AddWeaponXP( player, weaponXp )

	// if we specifically gain titan xp, then give titan xp no matter what, otherwise only give it when we're in a titan
	if ( titanXp != 0 )
		AddTitanXP( player, titanXp )

	if ( factionXp != 0 )
		AddFactionXP( player, factionXp )

	// global xp
	if ( xpValue != 0 )
		AddXP( player, xpValue )
}

void function AddXP( entity player, int amount )
{
	int oldXp = player.GetPersistentVarAsInt( "xp" )
	if( oldXp < 0 ) oldXp = 0
	int oldLevel = GetLevelForXP( oldXp )
	player.SetPersistentVar( "xp", min( oldXp + amount, PlayerGetMaxXPPerGen() ) )
	player.XPChanged() // network xp change to client, gen can't change here

	int newXp = player.GetPersistentVarAsInt( "xp" )
	int newLevel = GetLevelForXP( newXp )
	if ( newLevel != oldLevel )
	{
		Remote_CallFunction_NonReplay( player, "ServerCallback_PlayerLeveledUp", player.GetPersistentVarAsInt( "gen" ), newLevel )
		
		if( ProgressionEnabledForPlayer( player ) )
			AwardRandomItemsForPlayerLevels( player, player.GetPersistentVarAsInt( "gen" ), newLevel )
	}
}