KF2-MSK-GS/MskGs/Classes/MskGsMut.uc

279 lines
6.4 KiB
Ucode
Raw Normal View History

2021-02-25 23:55:43 +00:00
Class MskGsMut extends KFMutator
config(MskGs);
2021-12-07 01:26:58 +00:00
const CurrentVersion = 3;
2021-04-14 01:28:23 +00:00
var config int ConfigVersion;
2022-08-11 00:53:52 +00:00
var config int WeapLifespan;
2021-12-09 16:55:19 +00:00
var config int DoshLifespan;
2021-04-14 01:28:23 +00:00
var config array<int> PerPlayerMaxMonsters;
2021-02-20 10:30:45 +00:00
2022-04-12 11:58:54 +00:00
var public bool bXpNotifications;
2022-03-21 17:49:44 +00:00
var bool bInitialized;
2022-01-03 21:16:16 +00:00
2021-12-09 04:34:12 +00:00
var array<MskGsRepInfo> RepClients;
var array<Controller> MskGsMemberList;
2022-03-24 05:07:21 +00:00
function InitMutator(string Options, out string ErrorMessage)
{
local int MaxPlayers, MaxPlayersAllowed;
super.InitMutator(Options, ErrorMessage);
if (MyKFGI == none)
{
`log("[MskGsMut] Error: can't init, MyKFGI is none");
return;
}
2022-07-05 13:14:50 +00:00
MaxPlayers = Clamp(MyKFGI.GetIntOption(Options, "MaxPlayers", MaxPlayers), 6, 256);
2022-03-24 05:07:21 +00:00
MaxPlayersAllowed = MaxPlayers;
MyKFGI.MaxPlayers = MaxPlayers;
MyKFGI.MaxPlayersAllowed = MaxPlayersAllowed;
}
2021-02-26 00:13:55 +00:00
2021-04-14 01:28:23 +00:00
function InitConfig()
{
// Update from config version to current version if needed
switch (ConfigVersion)
{
case 0: // which means there is no config right now
2021-12-09 16:55:19 +00:00
WeapLifespan = 60 * 60;
2022-08-11 00:53:52 +00:00
2021-04-14 01:28:23 +00:00
case 1:
if (PerPlayerMaxMonsters.Length != 6)
{
PerPlayerMaxMonsters.Length = 0;
PerPlayerMaxMonsters.AddItem(12);
PerPlayerMaxMonsters.AddItem(18);
PerPlayerMaxMonsters.AddItem(24);
PerPlayerMaxMonsters.AddItem(32);
PerPlayerMaxMonsters.AddItem(34);
PerPlayerMaxMonsters.AddItem(36);
}
2021-12-07 01:26:58 +00:00
case 2:
2021-12-09 16:55:19 +00:00
if (DoshLifespan == 0)
2021-12-07 01:26:58 +00:00
{
2021-12-09 16:55:19 +00:00
DoshLifespan = 60 * 5;
2021-12-07 01:26:58 +00:00
}
2021-04-14 01:28:23 +00:00
case 2147483647:
`log("[MskGsMut] Config updated to version"@CurrentVersion);
break;
case CurrentVersion:
`log("[MskGsMut] Config is up-to-date");
break;
default:
2021-06-22 21:58:28 +00:00
`log("[MskGsMut] Warn: The config version is higher than the current version");
2021-04-14 01:28:23 +00:00
`log("[MskGsMut] Warn: Config version is"@ConfigVersion@"but current version is"@CurrentVersion);
`log("[MskGsMut] Warn: The config version will be changed to "@CurrentVersion);
break;
}
ConfigVersion = CurrentVersion;
SaveConfig();
}
2021-02-20 10:30:45 +00:00
simulated event PostBeginPlay()
{
super.PostBeginPlay();
Initialize();
}
function Initialize()
{
2022-03-21 17:49:44 +00:00
if (bInitialized) return;
2021-02-20 10:30:45 +00:00
if (MyKFGI == None || MyKFGI.MyKFGRI == None)
{
2021-04-14 01:28:23 +00:00
SetTimer(1.f, false, nameof(Initialize));
2021-02-20 10:30:45 +00:00
return;
}
2022-03-21 17:49:44 +00:00
bInitialized = true;
2021-02-20 10:30:45 +00:00
2021-04-14 01:28:23 +00:00
InitConfig();
2022-01-03 21:16:16 +00:00
if (MskGs_Endless(MyKFGI) != None)
{
bXpNotifications = true;
MskGs_Endless(MyKFGI).Mut = Self;
}
else if (MskGs_Objective(MyKFGI) != None)
{
bXpNotifications = (MyKFGI.GameDifficulty != 3);
MskGs_Objective(MyKFGI).Mut = Self;
}
else if (MskGs_Survival(MyKFGI) != None)
{
bXpNotifications = (MyKFGI.GameDifficulty != 3);
MskGs_Survival(MyKFGI).Mut = Self;
}
else if (MskGs_VersusSurvival(MyKFGI) != None)
{
bXpNotifications = false;
MskGs_VersusSurvival(MyKFGI).Mut = Self;
}
else if (MskGs_WeeklySurvival(MyKFGI) != None)
{
bXpNotifications = true;
MskGs_WeeklySurvival(MyKFGI).Mut = Self;
}
2021-12-09 04:34:12 +00:00
2021-04-14 01:28:23 +00:00
ModifySpawnManager();
2021-02-20 10:30:45 +00:00
`Log("[MskGsMut] Mutator loaded.");
}
2021-04-14 01:28:23 +00:00
function ModifySpawnManager()
2021-02-20 10:30:45 +00:00
{
2021-04-14 01:28:23 +00:00
local int i, j;
if (MyKFGI.SpawnManager == None)
{
SetTimer(1.f, false, nameof(ModifySpawnManager));
2021-02-20 10:30:45 +00:00
return;
2021-04-14 01:28:23 +00:00
}
for (i = 0; i < MyKFGI.SpawnManager.PerDifficultyMaxMonsters.Length; i++)
for (j = 0; j < MyKFGI.SpawnManager.PerDifficultyMaxMonsters[i].MaxMonsters.Length; j++)
MyKFGI.SpawnManager.PerDifficultyMaxMonsters[i].MaxMonsters[j] = PerPlayerMaxMonsters[j];
}
function AddMutator(Mutator Mut)
{
if (Mut == Self) return;
2021-02-20 10:30:45 +00:00
if (Mut.Class == Class)
Mut.Destroy();
else
Super.AddMutator(Mut);
}
2021-06-22 21:58:28 +00:00
private function bool IsUID(String ID)
{
return (Left(ID, 2) ~= "0x");
}
2021-03-31 21:27:53 +00:00
function bool CheckRelevance(Actor Other)
{
local bool SuperRelevant;
SuperRelevant = super.CheckRelevance(Other);
// if this actor is going to be destroyed, return now
if (!SuperRelevant)
{
return SuperRelevant;
}
2021-12-26 01:46:30 +00:00
// otherwise modify dosh or weapon lifespan
if (KFDroppedPickup_Cash(Other) != None)
{
if (DoshLifespan != 0) Other.Lifespan = float(DoshLifespan);
}
else if (KFDroppedPickup(Other) != None)
2021-03-31 21:27:53 +00:00
{
2021-12-26 01:46:30 +00:00
if (WeapLifespan != 0) Other.Lifespan = float(WeapLifespan);
2021-03-31 21:27:53 +00:00
}
return SuperRelevant;
}
2021-12-26 04:18:50 +00:00
function AddMskGsMember(Controller C)
{
MskGsMemberList.AddItem(C);
2022-01-03 21:16:16 +00:00
if (bXpNotifications)
2021-12-26 04:18:50 +00:00
{
2022-01-03 21:16:16 +00:00
if (MskGsMemberList.Length >= 10)
{
if (C.PlayerReplicationInfo != NONE)
2022-04-12 11:58:54 +00:00
WorldInfo.Game.Broadcast(C, C.PlayerReplicationInfo.PlayerName$" gives a boost to this server! XP bonus: +100% (MAX!)");
2022-01-03 21:16:16 +00:00
else
2022-04-12 11:58:54 +00:00
WorldInfo.Game.Broadcast(C, "XP bonus: +100% (MAX!)");
2022-01-03 21:16:16 +00:00
}
2021-12-26 04:18:50 +00:00
else
2022-01-03 21:16:16 +00:00
{
if (C.PlayerReplicationInfo != NONE)
2022-04-12 11:58:54 +00:00
WorldInfo.Game.Broadcast(C, C.PlayerReplicationInfo.PlayerName$" gives a boost to this server! XP bonus: +"$string(MskGsMemberList.Length * 10)$"%");
2022-01-03 21:16:16 +00:00
else
2022-04-12 11:58:54 +00:00
WorldInfo.Game.Broadcast(C, "XP bonus: +"$string(MskGsMemberList.Length * 10)$"%");
2022-01-03 21:16:16 +00:00
}
2021-12-26 04:18:50 +00:00
}
2022-03-21 21:16:34 +00:00
MyKFGI.UpdateGameSettings();
2021-12-26 04:18:50 +00:00
}
2021-12-09 04:34:12 +00:00
function NotifyLogin(Controller C)
2021-06-22 21:58:28 +00:00
{
2021-12-09 04:34:12 +00:00
local MskGsRepInfo RepInfo;
if (C == None) return;
2022-03-21 17:49:44 +00:00
Initialize();
2022-06-15 21:14:29 +00:00
`log("NotifyLogin:" @ C);
2021-12-09 04:34:12 +00:00
RepInfo = Spawn(class'MskGsRepInfo', KFPlayerController(C));
RepInfo.C = C;
RepInfo.Mut = Self;
RepClients.AddItem(RepInfo);
super.NotifyLogin(C);
2021-06-22 21:58:28 +00:00
}
2021-12-09 04:34:12 +00:00
function NotifyLogout(Controller C)
2021-06-22 21:58:28 +00:00
{
2022-07-05 13:14:50 +00:00
local MskGsRepInfo RepInfo;
2021-12-09 04:34:12 +00:00
if (C == None) return;
2021-06-22 21:58:28 +00:00
2022-03-21 17:49:44 +00:00
Initialize();
2022-03-29 18:23:13 +00:00
if (MskGsMemberList.Find(C) != INDEX_NONE)
2021-12-26 04:18:50 +00:00
{
2022-03-29 18:23:13 +00:00
MskGsMemberList.RemoveItem(C);
if (bXpNotifications)
2022-01-03 21:16:16 +00:00
{
2022-03-29 18:23:13 +00:00
if (MskGsMemberList.Length >= 10)
{
if (C.PlayerReplicationInfo != NONE)
2022-04-12 11:58:54 +00:00
WorldInfo.Game.Broadcast(C, C.PlayerReplicationInfo.PlayerName$" left the game. XP bonus: +100% (MAX!)");
2022-03-29 18:23:13 +00:00
else
2022-04-12 11:58:54 +00:00
WorldInfo.Game.Broadcast(C, "XP bonus: +100% (MAX!)");
2022-03-29 18:23:13 +00:00
}
else if (MskGsMemberList.Length > 0)
{
if (C.PlayerReplicationInfo != NONE)
2022-04-12 11:58:54 +00:00
WorldInfo.Game.Broadcast(C, C.PlayerReplicationInfo.PlayerName$" left the game. XP bonus: +"$string(MskGsMemberList.Length * 10)$"%");
2022-03-29 18:23:13 +00:00
else
2022-04-12 11:58:54 +00:00
WorldInfo.Game.Broadcast(C, "XP bonus: +"$string(MskGsMemberList.Length * 10)$"%");
2022-03-29 18:23:13 +00:00
}
2022-01-03 21:16:16 +00:00
else
2022-03-29 18:23:13 +00:00
{
if (C.PlayerReplicationInfo != NONE)
WorldInfo.Game.Broadcast(C, C.PlayerReplicationInfo.PlayerName$" left the game. No XP bonus now.");
else
WorldInfo.Game.Broadcast(C, "No XP bonus now.");
}
2022-01-03 21:16:16 +00:00
}
2022-03-29 18:23:13 +00:00
MyKFGI.UpdateGameSettings();
2021-12-26 04:18:50 +00:00
}
2022-07-05 13:14:50 +00:00
foreach RepClients(RepInfo)
2021-12-09 04:34:12 +00:00
{
2022-07-05 13:14:50 +00:00
if (RepInfo.C == C)
2021-12-09 04:34:12 +00:00
{
2022-07-05 13:14:50 +00:00
RepClients.RemoveItem(RepInfo);
RepInfo.Destroy();
2021-12-09 04:34:12 +00:00
}
}
2022-07-05 13:14:50 +00:00
super.NotifyLogout(C);
2021-06-22 21:58:28 +00:00
}
2021-02-20 10:30:45 +00:00
defaultproperties
{
2022-03-21 17:49:44 +00:00
bInitialized=false
2021-02-20 10:30:45 +00:00
}