KF2-MSK-GS/MSKGS-SRV/Classes/MSKGS.uc

571 lines
12 KiB
Ucode
Raw Normal View History

2022-08-16 06:59:16 +00:00
class MSKGS extends Info
2022-08-16 23:07:11 +00:00
implements(IMSKGS)
2022-08-16 06:59:16 +00:00
config(MSKGS);
2022-08-11 04:34:47 +00:00
const LatestVersion = 1;
2022-08-16 23:07:11 +00:00
const CfgCredits = class'CfgCredits';
2022-08-16 06:59:16 +00:00
const CfgLifespan = class'CfgLifespan';
const CfgSpawnManager = class'CfgSpawnManager';
const CfgXPBoost = class'CfgXPBoost';
const CfgSrvRank = class'CfgSrvRank';
2022-08-16 23:07:11 +00:00
const MSKGS_GameInfo = class'MSKGS_GameInfo';
struct ZedMap
{
var const class<KFPawn_Monster> Zed;
var const class<KFPawn_Monster> Proxy;
};
struct BoostMap
{
var const int BoostValue;
var const Array<ZedMap> Zeds;
};
var private Array<BoostMap> XPBoosts;
var private Array<ZedMap> ZedProxies;
var private int XPBoost;
var private bool XPNotifications;
2022-08-11 04:34:47 +00:00
var private config int Version;
var private config E_LogLevel LogLevel;
2022-08-16 06:59:16 +00:00
var private OnlineSubsystem OS;
2022-08-14 17:47:13 +00:00
var private KFGameInfo KFGI;
2022-08-11 04:34:47 +00:00
var private KFGameReplicationInfo KFGRI;
var private Array<MSKGS_RepInfo> RepInfos;
2022-08-16 06:59:16 +00:00
var private UniqueNetId OwnerID;
var private UniqueNetId GroupID;
2022-08-11 04:34:47 +00:00
public simulated function bool SafeDestroy()
{
`Log_Trace();
return (bPendingDelete || bDeleteMe || Destroy());
}
public event PreBeginPlay()
{
`Log_Trace();
if (WorldInfo.NetMode == NM_Client)
{
`Log_Fatal("NetMode:" @ WorldInfo.NetMode);
SafeDestroy();
return;
}
Super.PreBeginPlay();
PreInit();
}
public event PostBeginPlay()
{
`Log_Trace();
if (bPendingDelete || bDeleteMe) return;
Super.PostBeginPlay();
PostInit();
}
private function PreInit()
{
`Log_Trace();
if (Version == `NO_CONFIG)
{
LogLevel = LL_Info;
SaveConfig();
}
2022-08-16 23:07:11 +00:00
CfgCredits.static.InitConfig(Version, LatestVersion, LogLevel);
2022-08-16 06:59:16 +00:00
CfgLifespan.static.InitConfig(Version, LatestVersion, LogLevel);
CfgSpawnManager.static.InitConfig(Version, LatestVersion, LogLevel);
CfgXPBoost.static.InitConfig(Version, LatestVersion, LogLevel);
CfgSrvRank.static.InitConfig(Version, LatestVersion, LogLevel);
2022-08-11 04:34:47 +00:00
switch (Version)
{
case `NO_CONFIG:
`Log_Info("Config created");
case MaxInt:
`Log_Info("Config updated to version" @ LatestVersion);
break;
case LatestVersion:
`Log_Info("Config is up-to-date");
break;
default:
`Log_Warn("The config version is higher than the current version (are you using an old mutator?)");
`Log_Warn("Config version is" @ Version @ "but current version is" @ LatestVersion);
`Log_Warn("The config version will be changed to" @ LatestVersion);
break;
}
if (LatestVersion != Version)
{
Version = LatestVersion;
SaveConfig();
}
if (LogLevel == LL_WrongLevel)
{
LogLevel = LL_Info;
`Log_Warn("Wrong 'LogLevel', return to default value");
SaveConfig();
}
`Log_Base("LogLevel:" @ LogLevel);
2022-08-16 23:07:11 +00:00
CfgCredits.static.Load(LogLevel);
2022-08-16 06:59:16 +00:00
CfgLifespan.static.Load(LogLevel);
CfgSpawnManager.static.Load(LogLevel);
CfgXPBoost.static.Load(LogLevel);
CfgSrvRank.static.Load(LogLevel);
OS = class'GameEngine'.static.GetOnlineSubsystem();
if (OS == None)
{
`Log_Fatal("Can't get online subsystem!");
SafeDestroy();
return;
}
2022-08-16 23:07:11 +00:00
OwnerID = CfgCredits.static.LoadOwnerID(OS, LogLevel);
GroupID = CfgCredits.static.LoadGroupID(OS, LogLevel);
2022-08-11 04:34:47 +00:00
}
private function PostInit()
{
`Log_Trace();
if (WorldInfo == None || WorldInfo.Game == None)
{
SetTimer(1.0f, false, nameof(PostInit));
return;
}
KFGI = KFGameInfo(WorldInfo.Game);
if (KFGI == None)
{
`Log_Fatal("Incompatible gamemode:" @ WorldInfo.Game);
SafeDestroy();
return;
}
if (KFGI.GameReplicationInfo == None)
{
SetTimer(1.0f, false, nameof(PostInit));
return;
}
KFGRI = KFGameReplicationInfo(KFGI.GameReplicationInfo);
if (KFGRI == None)
{
`Log_Fatal("Incompatible Replication info:" @ KFGI.GameReplicationInfo);
SafeDestroy();
return;
}
2022-08-16 06:59:16 +00:00
if (MSKGS_GM_Endless(KFGI) != None)
{
XPNotifications = true;
MSKGS_GM_Endless(KFGI).MSKGS = Self;
2022-08-16 23:07:11 +00:00
MSKGS_GM_Endless(KFGI).GI = new MSKGS_GameInfo;
2022-08-16 06:59:16 +00:00
MSKGS_GM_Endless(KFGI).LogLevel = LogLevel;
}
else if (MSKGS_GM_Objective(KFGI) != None)
{
XPNotifications = (KFGI.GameDifficulty != 3);
MSKGS_GM_Objective(KFGI).MSKGS = Self;
2022-08-16 23:07:11 +00:00
MSKGS_GM_Objective(KFGI).GI = new MSKGS_GameInfo;
2022-08-16 06:59:16 +00:00
MSKGS_GM_Objective(KFGI).LogLevel = LogLevel;
}
else if (MSKGS_GM_Survival(KFGI) != None)
{
XPNotifications = (KFGI.GameDifficulty != 3);
MSKGS_GM_Survival(KFGI).MSKGS = Self;
2022-08-16 23:07:11 +00:00
MSKGS_GM_Survival(KFGI).GI = new MSKGS_GameInfo;
2022-08-16 06:59:16 +00:00
MSKGS_GM_Survival(KFGI).LogLevel = LogLevel;
}
else if (MSKGS_GM_VersusSurvival(KFGI) != None)
{
XPNotifications = false;
MSKGS_GM_VersusSurvival(KFGI).MSKGS = Self;
2022-08-16 23:07:11 +00:00
MSKGS_GM_VersusSurvival(KFGI).GI = new MSKGS_GameInfo;
2022-08-16 06:59:16 +00:00
MSKGS_GM_VersusSurvival(KFGI).LogLevel = LogLevel;
}
else if (MSKGS_GM_WeeklySurvival(KFGI) != None)
{
XPNotifications = true;
MSKGS_GM_WeeklySurvival(KFGI).MSKGS = Self;
2022-08-16 23:07:11 +00:00
MSKGS_GM_WeeklySurvival(KFGI).GI = new MSKGS_GameInfo;
2022-08-16 06:59:16 +00:00
MSKGS_GM_WeeklySurvival(KFGI).LogLevel = LogLevel;
}
2022-08-16 23:07:11 +00:00
`Log_Info("GameInfo initialized:" @ KFGI);
KFGI.UpdateGameSettings();
2022-08-16 06:59:16 +00:00
ModifySpawnManager();
2022-08-16 23:07:11 +00:00
`Log_Info("Initialized");
2022-08-16 06:59:16 +00:00
}
private function ModifySpawnManager()
{
local byte Difficulty, Players;
2022-08-16 23:07:11 +00:00
`Log_Trace();
2022-08-16 06:59:16 +00:00
if (KFGI.SpawnManager == None)
{
SetTimer(1.f, false, nameof(ModifySpawnManager));
return;
}
for (Difficulty = 0; Difficulty < KFGI.SpawnManager.PerDifficultyMaxMonsters.Length; Difficulty++)
{
for (Players = 0; Players < KFGI.SpawnManager.PerDifficultyMaxMonsters[Difficulty].MaxMonsters.Length; Players++)
{
2022-08-16 23:07:11 +00:00
KFGI.SpawnManager.PerDifficultyMaxMonsters[Difficulty].MaxMonsters[Players] = CfgSpawnManager.default.PerPlayerMaxMonsters[Players];
2022-08-16 06:59:16 +00:00
}
}
2022-08-16 23:07:11 +00:00
`Log_Info("SpawnManager modified");
}
public function class<KFPawn_Monster> PickProxyZed(class<KFPawn_Monster> MonsterClass)
{
local int Index;
Index = ZedProxies.Find('Zed', MonsterClass);
if (Index == INDEX_NONE)
{
`Log_Error("Can't find proxy for zed:" @ String(MonsterClass));
return MonsterClass;
}
`Log_Debug("Proxy Zed:" @ ZedProxies[Index].Proxy);
return ZedProxies[Index].Proxy;
}
public function int GetXPBoost()
{
return XPBoost;
}
public function bool GetXPNotifications()
{
return XPNotifications;
}
public function E_LogLevel GetLogLevel()
{
return LogLevel;
2022-08-16 06:59:16 +00:00
}
public function ModifyLifespan(Actor A)
{
2022-08-16 23:07:11 +00:00
`Log_Trace();
2022-08-16 06:59:16 +00:00
if (KFDroppedPickup_Cash(A) != None)
{
if (CfgLifespan.default.Dosh != 0)
{
A.Lifespan = float(CfgLifespan.default.Dosh);
}
}
else if (KFDroppedPickup(A) != None)
{
if (CfgLifespan.default.Weap != 0)
{
A.Lifespan = float(CfgLifespan.default.Weap);
}
}
}
public function SetMaxPlayers(int MaxPlayers)
{
2022-08-16 23:07:11 +00:00
`Log_Trace();
2022-08-16 06:59:16 +00:00
if (MaxPlayers != INDEX_NONE)
{
KFGI.MaxPlayers = MaxPlayers;
KFGI.MaxPlayersAllowed = MaxPlayers;
}
2022-08-11 04:34:47 +00:00
}
public function NotifyLogin(Controller C)
{
`Log_Trace();
if (!CreateRepInfo(C))
{
2022-08-16 23:07:11 +00:00
`Log_Error("Can't create RepInfo for:" @ C @ (C == None ? "" : String(C.PlayerReplicationInfo)));
2022-08-11 04:34:47 +00:00
}
}
public function NotifyLogout(Controller C)
{
`Log_Trace();
2022-08-16 23:07:11 +00:00
if (PlayerXPBoost(FindRepInfo(C)) > 0)
{
DecreaseXPBoost(C);
}
2022-08-11 04:34:47 +00:00
if (!DestroyRepInfo(C))
{
`Log_Error("Can't destroy RepInfo of:" @ C);
}
}
public function bool CreateRepInfo(Controller C)
{
local MSKGS_RepInfo RepInfo;
`Log_Trace();
2022-08-16 23:07:11 +00:00
if (C == None || C.PlayerReplicationInfo == None) return false;
2022-08-11 04:34:47 +00:00
RepInfo = Spawn(class'MSKGS_RepInfo', C);
if (RepInfo == None) return false;
2022-08-16 23:07:11 +00:00
RepInfo.Init(
LogLevel,
Self,
GroupID,
CfgXPBoost.default.CheckGroupTimer,
C.PlayerReplicationInfo.UniqueId == OwnerID);
2022-08-11 04:34:47 +00:00
RepInfos.AddItem(RepInfo);
return true;
}
public function bool DestroyRepInfo(Controller C)
{
local MSKGS_RepInfo RepInfo;
`Log_Trace();
if (C == None) return false;
2022-08-16 23:07:11 +00:00
RepInfo = FindRepInfo(C);
if (RepInfo != None)
2022-08-11 04:34:47 +00:00
{
2022-08-16 23:07:11 +00:00
RepInfo.SafeDestroy();
RepInfos.RemoveItem(RepInfo);
return true;
2022-08-11 04:34:47 +00:00
}
return false;
}
2022-08-16 06:59:16 +00:00
public function IncreaseXPBoost(KFPlayerController Booster)
{
2022-08-16 23:07:11 +00:00
local MSKGS_RepInfo BoosterRepInfo;
local String HexColor;
local int PlayerBoost;
local String PlayerBoostStr;
local String TotalBoostStr;
local String BoosterName;
`Log_Trace();
2022-08-16 06:59:16 +00:00
UpdateXPBoost();
2022-08-16 23:07:11 +00:00
KFGI.UpdateGameSettings();
BoosterRepInfo = FindRepInfo(Booster);
TotalBoostStr = String(XPBoost);
BoosterName = Booster.PlayerReplicationInfo.PlayerName;
HexColor = PlayerHexColor(BoosterRepInfo);
PlayerBoost = PlayerXPBoost(BoosterRepInfo);
PlayerBoostStr = String(PlayerBoost);
if (XPBoost >= CfgXPBoost.default.MaxBoost)
2022-08-16 06:59:16 +00:00
{
2022-08-16 23:07:11 +00:00
BroadcastChatLocalized(
MSKGS_PlayerGiveBoostToServerMax,
HexColor,
None,
BoosterName,
PlayerBoostStr,
String(CfgXPBoost.default.MaxBoost));
}
else if (PlayerBoost == XPBoost)
{
BroadcastChatLocalized(
MSKGS_PlayerGiveBoostToServerFirst,
HexColor,
None,
BoosterName,
TotalBoostStr);
}
else
{
BroadcastChatLocalized(
MSKGS_PlayerGiveBoostToServer,
HexColor,
None,
BoosterName,
PlayerBoostStr,
TotalBoostStr);
2022-08-16 06:59:16 +00:00
}
2022-08-16 23:07:11 +00:00
}
public function DecreaseXPBoost(Controller Booster)
{
local String HexColor;
local String TotalBoost;
local String BoosterName;
2022-08-16 06:59:16 +00:00
2022-08-16 23:07:11 +00:00
`Log_Trace();
UpdateXPBoost();
2022-08-16 06:59:16 +00:00
KFGI.UpdateGameSettings();
2022-08-16 23:07:11 +00:00
HexColor = CfgXPBoost.default.HexColorLeave;
BoosterName = Booster.PlayerReplicationInfo.PlayerName;
TotalBoost = String(XPBoost);
if (XPBoost >= CfgXPBoost.default.MaxBoost)
{
BroadcastChatLocalized(
MSKGS_BoosterLeaveServerMax,
HexColor,
Booster,
BoosterName,
String(CfgXPBoost.default.MaxBoost));
}
else if (XPBoost > 0)
{
BroadcastChatLocalized(
MSKGS_BoosterLeaveServer,
HexColor,
Booster,
BoosterName,
TotalBoost);
}
else
{
BroadcastChatLocalized(
MSKGS_BoosterLeaveServerNoBoost,
HexColor,
Booster,
BoosterName);
}
2022-08-16 06:59:16 +00:00
}
2022-08-16 23:07:11 +00:00
private function BroadcastChatLocalized(E_MSKGS_LocalMessageType LMT, String HexColor, optional Controller Except = None, optional String String1, optional String String2, optional String String3)
2022-08-16 06:59:16 +00:00
{
local MSKGS_RepInfo RepInfo;
foreach RepInfos(RepInfo)
{
2022-08-16 23:07:11 +00:00
if (RepInfo.Owner != Except)
2022-08-16 06:59:16 +00:00
{
2022-08-16 23:07:11 +00:00
RepInfo.WriteToChatLocalized(
LMT,
HexColor,
String1,
String2,
String3);
2022-08-16 06:59:16 +00:00
}
}
2022-08-16 23:07:11 +00:00
}
private function MSKGS_RepInfo FindRepInfo(Controller C)
{
local MSKGS_RepInfo RepInfo;
2022-08-16 06:59:16 +00:00
2022-08-16 23:07:11 +00:00
foreach RepInfos(RepInfo)
if (RepInfo.Owner == C)
break;
return RepInfo;
2022-08-16 06:59:16 +00:00
}
public function UpdateXPBoost()
{
local MSKGS_RepInfo RepInfo;
local int NextBoost;
2022-08-16 23:07:11 +00:00
local int Index;
`Log_Trace();
2022-08-16 06:59:16 +00:00
NextBoost = 0;
foreach RepInfos(RepInfo)
{
2022-08-16 23:07:11 +00:00
NextBoost += PlayerXPBoost(RepInfo);
2022-08-16 06:59:16 +00:00
}
2022-08-16 23:07:11 +00:00
if (NextBoost > 0)
2022-08-16 06:59:16 +00:00
{
2022-08-16 23:07:11 +00:00
Index = XPBoosts.Find('BoostValue', NextBoost);
if (Index == INDEX_NONE)
2022-08-16 06:59:16 +00:00
{
2022-08-16 23:07:11 +00:00
`Log_Error("Can't find boost proxy:" @ NextBoost);
2022-08-16 06:59:16 +00:00
}
else
{
2022-08-16 23:07:11 +00:00
ZedProxies = XPBoosts[Index].Zeds;
2022-08-16 06:59:16 +00:00
}
}
2022-08-16 23:07:11 +00:00
XPBoost = NextBoost;
}
private function int PlayerXPBoost(MSKGS_RepInfo RepInfo)
{
`Log_Trace();
if (RepInfo != None) switch (RepInfo.PlayerType())
{
case MSKGS_Owner: return CfgXPBoost.default.BoostOwner;
case MSKGS_Admin: return CfgXPBoost.default.BoostAdmin;
case MSKGS_Group: return CfgXPBoost.default.BoostGroup;
}
return CfgXPBoost.default.BoostPlayer;
2022-08-16 06:59:16 +00:00
}
2022-08-16 23:07:11 +00:00
private function String PlayerHexColor(MSKGS_RepInfo RepInfo)
2022-08-16 06:59:16 +00:00
{
2022-08-16 23:07:11 +00:00
`Log_Trace();
2022-08-16 06:59:16 +00:00
2022-08-16 23:07:11 +00:00
switch (RepInfo.PlayerType())
2022-08-16 06:59:16 +00:00
{
2022-08-16 23:07:11 +00:00
case MSKGS_Owner: return CfgXPBoost.default.HexColorOwner;
case MSKGS_Admin: return CfgXPBoost.default.HexColorAdmin;
case MSKGS_Group: return CfgXPBoost.default.HexColorGroup;
2022-08-16 06:59:16 +00:00
}
2022-08-16 23:07:11 +00:00
return CfgXPBoost.default.HexColorPlayer;
2022-08-16 06:59:16 +00:00
}
2022-08-11 04:34:47 +00:00
DefaultProperties
{
2022-08-16 23:07:11 +00:00
XPBoosts.Add({(
BoostValue=10,
Zeds[0]={(Zed=class'KFPawn_ZedBloat',Proxy=class'KFPawn_ZedBloat')},
Zeds[1]={(Zed=class'KFPawn_ZedBloat',Proxy=class'KFPawn_ZedBloat')}
)})
XPBoosts.Add({(
BoostValue=10,
Zeds[0]={(Zed=class'KFPawn_ZedBloat',Proxy=class'KFPawn_ZedBloat')},
Zeds[1]={(Zed=class'KFPawn_ZedBloat',Proxy=class'KFPawn_ZedBloat')}
)})
2022-08-11 04:34:47 +00:00
}