Browse Source

Change health API to lazily replace damage types

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
9bd8c09077
  1. 57
      sources/Gameplay/KF1Frontend/Health/KF1_HealthComponent.uc
  2. 2
      sources/ServerRealm/ServerGlobal.uc

57
sources/Gameplay/KF1Frontend/Health/KF1_HealthComponent.uc

@ -22,6 +22,7 @@ class KF1_HealthComponent extends AHealthComponent
config(AcediaSystem); config(AcediaSystem);
var private bool connectedToGameRules; var private bool connectedToGameRules;
var private bool replacedDamageTypes;
/** /**
* Unfortunately, thanks to the TWI's code, there's no way to catch events * Unfortunately, thanks to the TWI's code, there's no way to catch events
@ -56,39 +57,26 @@ var private const int TDAMAGE, TORIGINAL_DAMAGE, THIT_LOCATION, TMOMENTUM;
var private LoggerAPI.Definition infoReplacingDamageTypes, errNoServerLevelCore; var private LoggerAPI.Definition infoReplacingDamageTypes, errNoServerLevelCore;
var private LoggerAPI.Definition infoRestoringReplacingDamageTypes; var private LoggerAPI.Definition infoRestoringReplacingDamageTypes;
public function PseudoConstructor()
{
local LevelCore core;
if (!replaceBloatAndSirenDamageTypes) {
return;
}
_.logger.Auto(infoReplacingDamageTypes);
core = class'ServerLevelCore'.static.GetInstance();
if (core != none)
{
ReplaceDamageTypes(core);
core.OnShutdown(self).connect = RestoreDamageTypes;
}
else {
_.logger.Auto(errNoServerLevelCore);
}
}
protected function Finalizer() protected function Finalizer()
{ {
super.Finalizer(); super.Finalizer();
_.unreal.gameRules.OnNetDamage(self).Disconnect(); if (connectedToGameRules)
_.unreal.gameRules.OnScoreKill(self).Disconnect(); {
if (replaceBloatAndSirenDamageTypes) { _.unreal.gameRules.OnNetDamage(self).Disconnect();
_.unreal.gameRules.OnScoreKill(self).Disconnect();
connectedToGameRules = false;
}
if (replaceBloatAndSirenDamageTypes)
{
RestoreDamageTypes(); RestoreDamageTypes();
replacedDamageTypes = false;
} }
connectedToGameRules = false;
} }
public function Health_OnDamage_Slot OnDamage(AcediaObject receiver) public function Health_OnDamage_Slot OnDamage(AcediaObject receiver)
{ {
TryConnectToGameRules(); TryConnectToGameRules();
TryReplaceDamageTypes();
return super.OnDamage(receiver); return super.OnDamage(receiver);
} }
@ -103,6 +91,26 @@ private final function TryConnectToGameRules()
_.unreal.gameRules.OnScoreKill(self).connect = UpdateBileAchievement; _.unreal.gameRules.OnScoreKill(self).connect = UpdateBileAchievement;
} }
private final function TryReplaceDamageTypes()
{
local LevelCore core;
if (!replaceBloatAndSirenDamageTypes) return;
if (replacedDamageTypes) return;
replacedDamageTypes = true;
_.logger.Auto(infoReplacingDamageTypes);
core = class'ServerLevelCore'.static.GetInstance();
if (core != none)
{
ReplaceDamageTypes(core);
core.OnShutdown(self).connect = RestoreDamageTypes;
}
else {
_.logger.Auto(errNoServerLevelCore);
}
}
private final function ReplaceDamageTypes(LevelCore core) private final function ReplaceDamageTypes(LevelCore core)
{ {
local KFBloatVomit nextVomit; local KFBloatVomit nextVomit;
@ -145,6 +153,7 @@ private final function RestoreDamageTypes()
class'ZombieSiren_XMas'.default.screamDamageType = class'SirenScreamDamage'; class'ZombieSiren_XMas'.default.screamDamageType = class'SirenScreamDamage';
class'ZombieSiren_CIRCUS'.default.screamDamageType = class'ZombieSiren_CIRCUS'.default.screamDamageType =
class'SirenScreamDamage'; class'SirenScreamDamage';
replacedDamageTypes = false;
} }
private function int OnNetDamageHandler( private function int OnNetDamageHandler(
@ -248,7 +257,7 @@ defaultproperties
stringConstants(2) = "hitLocation" stringConstants(2) = "hitLocation"
TMOMENTUM = 3 TMOMENTUM = 3
stringConstants(3) = "momentum" stringConstants(3) = "momentum"
infoReplacingDamageTypes = (l=LOG_Info,m="Replacing bloat's and siren's damage types to dummy ones.") infoReplacingDamageTypes = (l=LOG_Info,m="Replacing bloat's and siren's damage types with dummy ones.")
infoRestoringReplacingDamageTypes = (l=LOG_Info,m="Restoring bloat and siren's damage types to their original values.") infoRestoringReplacingDamageTypes = (l=LOG_Info,m="Restoring bloat and siren's damage types to their original values.")
errNoServerLevelCore = (l=LOG_Error,m="Server level core is missing. Either this isn't a server or Acedia was wrongly initialized. Bloat and siren damage type will not be replaced.") errNoServerLevelCore = (l=LOG_Error,m="Server level core is missing. Either this isn't a server or Acedia was wrongly initialized. Bloat and siren damage type will not be replaced.")
} }

2
sources/ServerRealm/ServerGlobal.uc

@ -49,8 +49,6 @@ protected function Initialize()
super.Initialize(); super.Initialize();
_ = class'Global'.static.GetInstance(); _ = class'Global'.static.GetInstance();
kf = KFFrontend(_.memory.Allocate(class'KF1_Frontend')); kf = KFFrontend(_.memory.Allocate(class'KF1_Frontend'));
// TODO: this is hack, needs to be redone later
KF1_HealthComponent(kf.health).PseudoConstructor();
initialized = true; initialized = true;
} }

Loading…
Cancel
Save