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

352 lines
9.7 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-03-21 21:16:34 +00:00
var config bool bEnableMapStats; var config string SortStats; var config bool bOfficialNextMapOnly; var config bool bRandomizeNextMap; var config int WeapLifespan;
2021-12-09 16:55:19 +00:00
var config int DoshLifespan;
2021-04-14 01:28:23 +00:00
2021-06-22 21:58:28 +00:00
var config array<string> KickProtectedList;
2022-03-21 17:10:41 +00:00
var config array<string> AdminList;
2021-04-14 01:28:23 +00:00
var config array<int> PerPlayerMaxMonsters;
2021-02-20 10:30:45 +00:00
2022-01-03 21:16:16 +00:00
var 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-21 17:10:41 +00:00
var array<UniqueNetId> AdminUIDList;
2021-12-09 04:34:12 +00:00
2022-03-21 21:16:34 +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; } MaxPlayers = Clamp(MyKFGI.GetIntOption(Options, "MaxPlayers", MaxPlayers), 6, 128); 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
bEnableMapStats = True;
SortStats = "CounterDesc";
bOfficialNextMapOnly = True;
bRandomizeNextMap = True;
2021-12-09 16:55:19 +00:00
WeapLifespan = 60 * 60;
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;
}
// Check and correct some values
if (!(SortStats ~= "CounterAsc"
|| SortStats ~= "CounterDesc"
|| SortStats ~= "NameAsc"
|| SortStats ~= "NameDesc"
|| SortStats ~= "False"))
{
`log("[MskGsMut] Warn: SortStats value not recognized ("$SortStats$") and will be set to False");
`log("[MskGsMut] Warn: Valid values for SortStats: False CounterAsc CounterDesc NameAsc NameDesc");
SortStats = "False";
}
ConfigVersion = CurrentVersion;
SaveConfig();
}
2021-02-20 10:30:45 +00:00
simulated event PostBeginPlay()
{
super.PostBeginPlay();
if (WorldInfo.Game.BaseMutator == None)
WorldInfo.Game.BaseMutator = Self;
else
WorldInfo.Game.BaseMutator.AddMutator(Self);
2021-04-14 01:28:23 +00:00
if (bDeleteMe) return;
2021-02-20 10:30:45 +00:00
Initialize();
}
function Initialize()
{
2021-02-25 23:55:43 +00:00
local MskGsVoteCollector VoteCollector;
local OnlineSubsystem steamworks;
local string Person;
local UniqueNetId PersonUID;
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();
2021-02-20 10:30:45 +00:00
MyKFGI.KFGFxManagerClass = class'MskGsGFxMoviePlayer_Manager';
MyKFGI.MyKFGRI.VoteCollectorClass = class'MskGsVoteCollector';
2021-04-14 01:28:23 +00:00
MyKFGI.MyKFGRI.VoteCollector = new(MyKFGI.MyKFGRI) MyKFGI.MyKFGRI.VoteCollectorClass;
2021-02-25 23:55:43 +00:00
VoteCollector = MskGsVoteCollector(MyKFGI.MyKFGRI.VoteCollector);
2021-04-14 01:28:23 +00:00
VoteCollector.bEnableMapStats = bEnableMapStats;
VoteCollector.bOfficialNextMapOnly = bOfficialNextMapOnly;
VoteCollector.bRandomizeNextMap = bRandomizeNextMap;
VoteCollector.SortPolicy = SortStats;
2021-02-25 23:55:43 +00:00
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
steamworks = class'GameEngine'.static.GetOnlineSubsystem();
2021-02-25 23:55:43 +00:00
2021-06-22 21:58:28 +00:00
foreach KickProtectedList(Person)
2021-02-25 23:55:43 +00:00
{
2021-06-22 21:58:28 +00:00
if (IsUID(Person) && steamworks.StringToUniqueNetId(Person, PersonUID))
2021-02-25 23:55:43 +00:00
{
2021-06-22 21:58:28 +00:00
if (VoteCollector.KickProtectedList.Find('Uid', PersonUID.Uid) == -1)
VoteCollector.KickProtectedList.AddItem(PersonUID);
2021-02-25 23:55:43 +00:00
}
2021-06-22 21:58:28 +00:00
else if (steamworks.Int64ToUniqueNetId(Person, PersonUID))
2021-02-25 23:55:43 +00:00
{
2021-06-22 21:58:28 +00:00
if (VoteCollector.KickProtectedList.Find('Uid', PersonUID.Uid) == -1)
VoteCollector.KickProtectedList.AddItem(PersonUID);
2021-02-25 23:55:43 +00:00
}
else `Log("[MskGsMut] WARN: Can't add person:"@Person);
}
2021-04-14 01:28:23 +00:00
2022-03-21 17:10:41 +00:00
foreach AdminList(Person)
{
if (IsUID(Person) && steamworks.StringToUniqueNetId(Person, PersonUID))
{
if (AdminUIDList.Find('Uid', PersonUID.Uid) == -1)
AdminUIDList.AddItem(PersonUID);
}
else if (steamworks.Int64ToUniqueNetId(Person, PersonUID))
{
if (AdminUIDList.Find('Uid', PersonUID.Uid) == -1)
AdminUIDList.AddItem(PersonUID);
}
else `Log("[MskGsMut] WARN: Can't add admin:"@Person);
}
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-03-31 21:29:35 +00:00
function bool PreventDeath(Pawn Killed, Controller Killer, class<DamageType> damageType, vector HitLocation)
{
local KFWeapon TempWeapon;
local KFPawn_Human KFP;
KFP = KFPawn_Human(Killed);
if (Role >= ROLE_Authority && KFP != None && KFP.InvManager != none)
foreach KFP.InvManager.InventoryActors(class'KFWeapon', TempWeapon)
if (TempWeapon != none && TempWeapon.bDropOnDeath && TempWeapon.CanThrow())
KFP.TossInventory(TempWeapon);
return Super.PreventDeath(Killed, Killer, damageType, HitLocation);
}
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)
WorldInfo.Game.Broadcast(C, C.PlayerReplicationInfo.PlayerName$" gives a boost to this server! XP bonus: +50% (MAX!)");
else
WorldInfo.Game.Broadcast(C, "XP bonus: +50% (MAX!)");
}
2021-12-26 04:18:50 +00:00
else
2022-01-03 21:16:16 +00:00
{
if (C.PlayerReplicationInfo != NONE)
WorldInfo.Game.Broadcast(C, C.PlayerReplicationInfo.PlayerName$" gives a boost to this server! XP bonus: +"$string(MskGsMemberList.Length * 5)$"%");
else
WorldInfo.Game.Broadcast(C, "XP bonus: +"$string(MskGsMemberList.Length * 5)$"%");
}
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();
2021-12-09 04:34:12 +00:00
RepInfo = Spawn(class'MskGsRepInfo', KFPlayerController(C));
RepInfo.C = C;
RepInfo.Mut = Self;
RepClients.AddItem(RepInfo);
2022-03-21 17:10:41 +00:00
if (AdminUIDList.Find('Uid', C.PlayerReplicationInfo.UniqueId.Uid) != -1)
C.PlayerReplicationInfo.bAdmin = true;
2021-12-09 04:34:12 +00:00
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
{
local MskGsVoteCollector VoteCollector;
2021-12-26 04:18:50 +00:00
local int i;
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();
2021-06-22 21:58:28 +00:00
VoteCollector = MskGsVoteCollector(MyKFGI.MyKFGRI.VoteCollector);
2021-12-09 04:34:12 +00:00
VoteCollector.NotifyLogout(C);
2021-06-22 21:58:28 +00:00
2021-12-09 04:34:12 +00:00
MskGsMemberList.RemoveItem(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)
WorldInfo.Game.Broadcast(C, C.PlayerReplicationInfo.PlayerName$" left the game. XP bonus: +50% (MAX!)");
else
WorldInfo.Game.Broadcast(C, "XP bonus: +50% (MAX!)");
}
else if (MskGsMemberList.Length > 0)
{
if (C.PlayerReplicationInfo != NONE)
WorldInfo.Game.Broadcast(C, C.PlayerReplicationInfo.PlayerName$" left the game. XP bonus: +"$string(MskGsMemberList.Length * 5)$"%");
else
WorldInfo.Game.Broadcast(C, "XP bonus: +"$string(MskGsMemberList.Length * 5)$"%");
}
2021-12-26 04:18:50 +00:00
else
2022-01-03 21:16:16 +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.");
}
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
for (i = RepClients.Length - 1; i >= 0; i--)
2021-12-09 04:34:12 +00:00
{
2021-12-26 04:18:50 +00:00
if (RepClients[i].C == C)
2021-12-09 04:34:12 +00:00
{
2021-12-26 04:18:50 +00:00
RepClients[i].Destroy();
RepClients.Remove(i, 1);
2021-12-09 04:34:12 +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
}