Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medical - Refactoring #73

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replication cleanup
MichaelJRM committed Jun 11, 2024
commit 3e15bdaa318ec756dcdf46b38c0ce395a7feb949

This file was deleted.

Original file line number Diff line number Diff line change
@@ -2,9 +2,11 @@
//! Introduce a second chance, which gets triggered when the character would have died without
//! falling unconscious.
//! Add methods for interacting with pain hit zone.
modded class SCR_CharacterDamageManagerComponent : SCR_DamageManagerComponent
modded class SCR_CharacterDamageManagerComponent
{
[RplProp(), Attribute(defvalue: "0", desc: "Resilience regeneration scale when second chance was triggered. The default regeneration rate will be multiplied by this factor.", category: "ACE Medical")]
private static const float ACE_MEDICAL_SECOND_CHANCE_DEACTIVATION_TIMEOUT_MS = 1000;

[Attribute(defvalue: "0", desc: "Resilience regeneration scale when second chance was triggered. The default regeneration rate will be multiplied by this factor.", category: "ACE Medical")]
protected float m_fACE_Medical_SecondChanceRegenScale;

protected HitZone m_pACE_Medical_HealthHitZone;
@@ -14,66 +16,58 @@ modded class SCR_CharacterDamageManagerComponent : SCR_DamageManagerComponent
protected ACE_Medical_PainHitZone m_pACE_Medical_PainHitZone;
protected float m_fACE_Medical_ModeratePainThreshold;
protected float m_fACE_Medical_SeriousPainThreshold;

// We only notify the replication system about changes of these members on initialization
// After init, each proxy is itself responsible for updating these members
// Having them as RplProp also ensures that JIPs receive the current state from the server
[RplProp()]
protected bool m_bACE_Medical_Initialized = false;
[RplProp()]

protected bool m_bACE_Medical_HasSecondChance = false;
[RplProp()]
protected bool m_bACE_Medical_SecondChanceOnHeadEnabled = false;
[RplProp()]
protected bool m_bACE_Medical_SecondChanceTriggered = false;

private RplComponent m_RplComponent;

//-----------------------------------------------------------------------------------------------------------
//! Initialize member variables
override void OnInit(IEntity owner)
{
super.OnInit(owner);

m_RplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));

m_pACE_Medical_HealthHitZone = GetHitZoneByName("Health");
if (!m_pACE_Medical_HealthHitZone)
return;

m_fACE_Medical_CriticalHealth = m_pACE_Medical_HealthHitZone.GetDamageStateThreshold(ECharacterHealthState.CRITICAL);

GetPhysicalHitZones(m_aACE_Medical_PhysicalHitZones);

if (ACE_Medical_IsProxy())
return;

ACE_Medical_Initialize();
}

//-----------------------------------------------------------------------------------------------------------
//! Initialize ACE medical on a character damage manager (Called on the server)
void ACE_Medical_Initialize()
{
if (m_bACE_Medical_Initialized)
return;

ACE_Medical_Settings settings = ACE_SettingsHelperT<ACE_Medical_Settings>.GetModSettings();
const ACE_Medical_Settings settings = ACE_SettingsHelperT<ACE_Medical_Settings>.GetModSettings();
if (settings)
{
m_bACE_Medical_SecondChanceOnHeadEnabled = settings.m_bSecondChanceOnHeadEnabled;
m_fACE_Medical_SecondChanceRegenScale = settings.m_fSecondChanceRegenScale;
}

ACE_Medical_EnableSecondChance(true);
// Damage calculations are done on all machines, so we have to broadcast the init
m_bACE_Medical_Initialized = true;
Replication.BumpMe();
}

//------------------------------------------------------------------------------------------------
// Reduce regeneration rate when second chance was triggered
override float GetResilienceRegenScale()
{
float scale = super.GetResilienceRegenScale();
const float scale = super.GetResilienceRegenScale();
if (m_bACE_Medical_SecondChanceTriggered && scale > 0)
{
return m_fACE_Medical_SecondChanceRegenScale;
}
else
{
return scale;
}
}

//------------------------------------------------------------------------------------------------
@@ -124,7 +118,7 @@ modded class SCR_CharacterDamageManagerComponent : SCR_DamageManagerComponent
float ACE_Medical_GetPainIntensity()
{
// Clamp between serious damage and full health
float scaledHealth = Math.Clamp(m_pACE_Medical_PainHitZone.GetHealthScaled(), m_fACE_Medical_SeriousPainThreshold, 1);
const float scaledHealth = Math.Clamp(m_pACE_Medical_PainHitZone.GetHealthScaled(), m_fACE_Medical_SeriousPainThreshold, 1);

if (scaledHealth > m_fACE_Medical_ModeratePainThreshold)
{
@@ -137,13 +131,6 @@ modded class SCR_CharacterDamageManagerComponent : SCR_DamageManagerComponent
return Math.InverseLerp(1, m_fACE_Medical_SeriousPainThreshold, scaledHealth);
}
}

//------------------------------------------------------------------------------------------------
//! Returns true if ACE Medical has been initialized
bool ACE_Medical_IsInitialized()
{
return m_bACE_Medical_Initialized;
}

//------------------------------------------------------------------------------------------------
//! Enable/disable second chance
@@ -185,4 +172,45 @@ modded class SCR_CharacterDamageManagerComponent : SCR_DamageManagerComponent
{
return m_bACE_Medical_SecondChanceTriggered;
}

//------------------------------------------------------------------------------------------------
override void OnLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
{
super.OnLifeStateChanged(previousLifeState, newLifeState);

if (previousLifeState == newLifeState)
return;

switch (newLifeState)
{
// Add second chance when revived
case ECharacterLifeState.ALIVE:
{
GetGame().GetCallqueue().Remove(ACE_Medical_EnableSecondChance);
ACE_Medical_EnableSecondChance(true);
ACE_Medical_SetSecondChanceTrigged(false);
break;
}

// Schedule removal of second chance when falling unconscious
case ECharacterLifeState.INCAPACITATED:
{
GetGame().GetCallqueue().CallLater(ACE_Medical_EnableSecondChance, ACE_MEDICAL_SECOND_CHANCE_DEACTIVATION_TIMEOUT_MS, false, false);
break;
}

// Remove second chance when dead
case ECharacterLifeState.DEAD:
{
GetGame().GetCallqueue().Remove(ACE_Medical_EnableSecondChance);
ACE_Medical_EnableSecondChance(false);
break;
}
}
}

private bool ACE_Medical_IsProxy()
{
return m_RplComponent && m_RplComponent.IsProxy();
}
}
Original file line number Diff line number Diff line change
@@ -9,6 +9,13 @@ class ACE_Medical_ConsumableEpinephrine : SCR_ConsumableEffectHealthItems
ChimeraCharacter char = ChimeraCharacter.Cast(target);
if (!char)
return false;

SCR_CharacterControllerComponent charCtrl = SCR_CharacterControllerComponent.Cast(char.GetCharacterController());
if (charCtrl.GetLifeState() != ECharacterLifeState.INCAPACITATED)
{
failReason = SCR_EConsumableFailReason.ACE_MEDICAL_NOT_INCAPACITATED;
return false;
}

SCR_CharacterDamageManagerComponent damageManager = SCR_CharacterDamageManagerComponent.Cast(char.GetDamageManager());
if (!damageManager)
@@ -41,12 +48,7 @@ class ACE_Medical_ConsumableEpinephrine : SCR_ConsumableEffectHealthItems
return false;
}

SCR_CharacterControllerComponent charCtrl = SCR_CharacterControllerComponent.Cast(char.GetCharacterController());
if (charCtrl.GetLifeState() == ECharacterLifeState.INCAPACITATED)
return true;

failReason = SCR_EConsumableFailReason.ACE_MEDICAL_NOT_INCAPACITATED;
return false;
return true;
}

//------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@ modded class SCR_HealSupportStationComponent : SCR_BaseDamageHealSupportStationC
{
super.DelayedInit(owner);

ACE_Medical_Settings settings = ACE_SettingsHelperT<ACE_Medical_Settings>.GetModSettings();
const ACE_Medical_Settings settings = ACE_SettingsHelperT<ACE_Medical_Settings>.GetModSettings();
if (!settings)
return;

SCR_ResourceComponent resource = SCR_ResourceComponent.Cast(GetOwner().FindComponent(SCR_ResourceComponent));
const SCR_ResourceComponent resource = SCR_ResourceComponent.Cast(GetOwner().FindComponent(SCR_ResourceComponent));
if (!resource)
return;

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ class ACE_Medical_PainHitZone : SCR_RegeneratingHitZone
override void OnInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
{
super.OnInit(pOwnerEntity, pManagerComponent);
SCR_CharacterDamageManagerComponent characterDamageManager = SCR_CharacterDamageManagerComponent.Cast(pManagerComponent);
const SCR_CharacterDamageManagerComponent characterDamageManager = SCR_CharacterDamageManagerComponent.Cast(pManagerComponent);
if (characterDamageManager)
characterDamageManager.ACE_Medical_SetPainHitZone(this);
}
@@ -16,7 +16,7 @@ class ACE_Medical_PainHitZone : SCR_RegeneratingHitZone
//! Suppress passive regeneration while bleeding
override float CalculatePassiveRegenDPS(bool considerRegenScale = true)
{
SCR_CharacterDamageManagerComponent damageManager = SCR_CharacterDamageManagerComponent.Cast(GetHitZoneContainer());
const SCR_CharacterDamageManagerComponent damageManager = SCR_CharacterDamageManagerComponent.Cast(GetHitZoneContainer());
if (damageManager && damageManager.IsBleeding())
return 0;

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------------------------------------
//! health hitzone - Receives damage from physical hitzones
modded class SCR_CharacterHealthHitZone : SCR_HitZone
modded class SCR_CharacterHealthHitZone
{
protected SCR_CharacterDamageManagerComponent m_pACE_Medical_DamageManager;
protected bool m_bACE_Medical_HasSecondChanceOnHead;
@@ -32,11 +32,11 @@ modded class SCR_CharacterHealthHitZone : SCR_HitZone
//! Triggers second chance if damage had to be rescaled
protected float ACE_Medical_ComputeSecondChanceEffectiveDamage(notnull BaseDamageContext damageContext, bool isDOT)
{
float effectiveDamage = super.ComputeEffectiveDamage(damageContext, isDOT);
const float effectiveDamage = super.ComputeEffectiveDamage(damageContext, isDOT);
if (GetHealth() - effectiveDamage >= ACE_MEDICAL_SECOND_CHANCE_MIN_HEALTH)
return effectiveDamage;

SCR_CharacterHitZone hitZone = SCR_CharacterHitZone.Cast(damageContext.struckHitZone);
const SCR_CharacterHitZone hitZone = SCR_CharacterHitZone.Cast(damageContext.struckHitZone);
if (hitZone && !m_pACE_Medical_DamageManager.ACE_Medical_WasSecondChanceTrigged())
{
m_pACE_Medical_DamageManager.ACE_Medical_SetSecondChanceTrigged(true);
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ modded class SCR_CharacterResilienceHitZone : SCR_RegeneratingHitZone
{
float regenDPS = super.CalculatePassiveRegenDPS(considerRegenScale);

SCR_CharacterDamageManagerComponent damageManager = SCR_CharacterDamageManagerComponent.Cast(GetHitZoneContainer());
const SCR_CharacterDamageManagerComponent damageManager = SCR_CharacterDamageManagerComponent.Cast(GetHitZoneContainer());
if (damageManager)
regenDPS *= damageManager.GetResilienceRegenScale();

This file was deleted.

Original file line number Diff line number Diff line change
@@ -15,11 +15,11 @@ class ACE_Medical_EpinephrineUserAction : SCR_MorphineUserAction
override bool CanBePerformedScript(IEntity user)
{
// Medic character
ChimeraCharacter userCharacter = ChimeraCharacter.Cast(user);
const ChimeraCharacter userCharacter = ChimeraCharacter.Cast(user);
if (!userCharacter)
return false;

SCR_ConsumableItemComponent consumableComponent = GetConsumableComponent(userCharacter);
const SCR_ConsumableItemComponent consumableComponent = GetConsumableComponent(userCharacter);
if (!consumableComponent)
return false;

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ class ACE_Medical_EpinephrineDamageEffect: SCR_DotDamageEffect
//------------------------------------------------------------------------------------------------
override bool HijackDamageEffect(SCR_ExtendedDamageManagerComponent dmgManager)
{
SCR_CharacterDamageManagerComponent charDmgManager = SCR_CharacterDamageManagerComponent.Cast(dmgManager);
const SCR_CharacterDamageManagerComponent charDmgManager = SCR_CharacterDamageManagerComponent.Cast(dmgManager);
if (charDmgManager)
SetAffectedHitZone(charDmgManager.GetResilienceHitZone());

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ class ACE_Medical_MorphineDamageEffect: SCR_DotDamageEffect
//------------------------------------------------------------------------------------------------
override bool HijackDamageEffect(SCR_ExtendedDamageManagerComponent dmgManager)
{
SCR_CharacterDamageManagerComponent charDmgManager = SCR_CharacterDamageManagerComponent.Cast(dmgManager);
const SCR_CharacterDamageManagerComponent charDmgManager = SCR_CharacterDamageManagerComponent.Cast(dmgManager);
if (charDmgManager)
SetAffectedHitZone(charDmgManager.ACE_Medical_GetPainHitZone());