KF2-DroppedPickupLifespan/DPL/Classes/DPL.uc

154 lines
2.6 KiB
Ucode
Raw Normal View History

2022-09-19 03:01:26 +00:00
class DPL extends Info
config(DPL);
const LatestVersion = 1;
const CfgLifespan = class'Lifespan';
enum E_PickupType
{
PT_NotPickup,
PT_Weapon,
2022-09-19 03:41:08 +00:00
PT_Dosh,
PT_Carryable
2022-09-19 03:01:26 +00:00
};
var private config int Version;
var private config E_LogLevel LogLevel;
public simulated function bool SafeDestroy()
{
`Log_Trace();
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
return (bPendingDelete || bDeleteMe || Destroy());
}
public event PreBeginPlay()
{
`Log_Trace();
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
if (WorldInfo.NetMode == NM_Client)
{
`Log_Fatal("NetMode:" @ WorldInfo.NetMode);
SafeDestroy();
return;
}
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
Super.PreBeginPlay();
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
Init();
}
private function Init()
{
`Log_Trace();
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
if (Version == `NO_CONFIG)
{
LogLevel = LL_Info;
SaveConfig();
}
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
CfgLifespan.static.InitConfig(Version, LatestVersion, LogLevel);
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
switch (Version)
{
case `NO_CONFIG:
`Log_Info("Config created");
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
case MaxInt:
`Log_Info("Config updated to version" @ LatestVersion);
break;
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
case LatestVersion:
`Log_Info("Config is up-to-date");
break;
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
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;
}
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
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);
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
CfgLifespan.static.Load(LogLevel);
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
`Log_Info("Initialized");
}
public function ModifyLifespan(Actor A)
{
`Log_Trace();
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
switch (PickupType(A))
{
case PT_Dosh:
if (CfgLifespan.default.Dosh > 0)
{
`Log_Debug("Modify dosh lifespan:" @ int(A.Lifespan) @ "->" @ CfgLifespan.default.Dosh);
A.Lifespan = float(CfgLifespan.default.Dosh);
}
else
{
`Log_Debug("Skip modify dosh lifespan");
}
break;
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
case PT_Weapon:
if (CfgLifespan.default.Weap > 0)
{
`Log_Debug("Modify weapon lifespan:" @ int(A.Lifespan) @ "->" @ CfgLifespan.default.Weap);
A.Lifespan = float(CfgLifespan.default.Weap);
}
else
{
`Log_Debug("Skip modify weapon lifespan");
}
break;
2023-05-14 01:10:08 +00:00
2022-09-19 03:41:08 +00:00
case PT_Carryable:
2022-09-19 03:01:26 +00:00
case PT_NotPickup:
default:
break;
}
}
private function E_PickupType PickupType(Actor A)
{
`Log_Trace();
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
if (KFDroppedPickup_Cash(A) != None)
{
return PT_Dosh;
}
2022-09-19 03:41:08 +00:00
else if (KFDroppedPickup_Carryable(A) != None)
{
return PT_Carryable;
}
2022-09-19 03:01:26 +00:00
else if (KFDroppedPickup(A) != None)
{
return PT_Weapon;
}
2023-05-14 01:10:08 +00:00
2022-09-19 03:01:26 +00:00
return PT_NotPickup;
}
defaultproperties
{
}