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

235 lines
6.0 KiB
Ucode
Raw Normal View History

2021-02-25 23:55:43 +00:00
Class MskGsMut extends KFMutator
config(MskGs);
2021-06-22 21:58:28 +00:00
const CurrentVersion = 2;
2021-04-14 01:28:23 +00:00
var config int ConfigVersion;
var config bool bEnableMapStats;
var config string SortStats;
var config bool bOfficialNextMapOnly;
var config bool bRandomizeNextMap;
var config int WeapDespawnTime;
2021-06-22 21:58:28 +00:00
var config array<string> KickProtectedList;
2021-04-14 01:28:23 +00:00
var config array<int> PerPlayerMaxMonsters;
2021-02-20 10:30:45 +00:00
2021-02-26 00:13:55 +00:00
function InitMutator(string Options, out string ErrorMessage)
{
local int MaxPlayers, MaxPlayersAllowed;
super.InitMutator(Options, ErrorMessage);
if (MyKFGI == none)
{
return;
}
2021-03-02 16:15:55 +00:00
MaxPlayers = Clamp(MyKFGI.GetIntOption(Options, "MaxPlayers", MaxPlayers), 6, 128);
2021-02-26 00:13:55 +00:00
MaxPlayersAllowed = MaxPlayers;
MyKFGI.MaxPlayers = MaxPlayers;
MyKFGI.MaxPlayersAllowed = MaxPlayersAllowed;
}
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;
WeapDespawnTime = 2147483647;
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);
}
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;
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;
}
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
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
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;
local KFDroppedPickup PlayerWeap;
SuperRelevant = super.CheckRelevance(Other);
// if this actor is going to be destroyed, return now
if (!SuperRelevant)
{
return SuperRelevant;
}
PlayerWeap = KFDroppedPickup(Other);
// otherwise modify weapon lifespan
if (PlayerWeap != None)
{
2021-04-14 01:28:23 +00:00
PlayerWeap.Lifespan = WeapDespawnTime;
2021-03-31 21:27:53 +00:00
return SuperRelevant;
}
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-06-22 21:58:28 +00:00
function NotifyLogin(Controller NewPlayer)
{
super.NotifyLogin(NewPlayer);
}
function NotifyLogout(Controller Exiting)
{
local MskGsVoteCollector VoteCollector;
VoteCollector = MskGsVoteCollector(MyKFGI.MyKFGRI.VoteCollector);
VoteCollector.NotifyLogout(Exiting);
super.NotifyLogout(Exiting);
}
2021-02-20 10:30:45 +00:00
defaultproperties
{
2021-06-22 21:58:28 +00:00
2021-02-20 10:30:45 +00:00
}