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
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Jonpas <[email protected]>
LorenLuke
OverlordZorn
Zelik
FailNot
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ACE_BackblastComponent : ScriptComponent

foreach (SCR_ChimeraCharacter character : affectedEntities)
{
SCR_DamageManagerComponent damageManager = character.GetDamageManager();
SCR_CharacterDamageManagerComponent damageManager = SCR_CharacterDamageManagerComponent.Cast(character.GetDamageManager());
if (!damageManager)
continue;

Expand Down Expand Up @@ -119,8 +119,8 @@ class ACE_BackblastComponent : ScriptComponent
if (!charHitZone)
continue;

charHitZone.AddBleeding(nodes[0]);
};
damageManager.AddBleedingEffectOnHitZone(charHitZone, nodes[0]);
}
}

if (m_bDebugModeEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ GenericEntity : "{3238FC0BDB67AA78}Prefabs/Items/Medicine/MorphineInjection_01/M
}
SCR_ConsumableItemComponent "{59E68C74C5CEE74F}" {
m_ConsumableEffect ACE_Medical_ConsumableEpinephrine "{59E68C74C1F3910E}" {
m_fItemRegenerationSpeed 5
m_fItemRegenerationDuration 30
m_aDamageEffectsToLoad {
ACE_Medical_EpinephrineDamageEffect "{6122D60861B541E7}" {
}
}
m_fItemRegenerationSpeedDPS 5
m_fItemRegenerationDurationS 30
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ GenericEntity : "{3238FC0BDB67AA78}Prefabs/Items/Medicine/MorphineInjection_01/M
}
SCR_ConsumableItemComponent "{59E68C74C5CEE74F}" {
m_ConsumableEffect ACE_Medical_ConsumableMorphine "{59E68C74C1F3910E}" {
m_fItemRegenerationSpeed 5
m_fItemRegenerationDuration 60
m_aDamageEffectsToLoad {
ACE_Medical_MorphineDamageEffect "{6122D60861B541E7}" {
}
}
m_fItemRegenerationSpeedDPS 5
m_fItemRegenerationDurationS 60
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,74 @@
//! 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer to have the parent class specification for clarity.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that makes sense, actually I didn't know this was possible. I wish I knew it before

{
[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")]
protected float m_fACE_Medical_SecondChanceRegenScale;
private static const float ACE_MEDICAL_SECOND_CHANCE_DEACTIVATION_TIMEOUT_MS = 1000;

protected HitZone m_pACE_Medical_HealthHitZone;
protected float m_fACE_Medical_CriticalHealth;
protected ref array<HitZone> m_aACE_Medical_PhysicalHitZones = {};

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 float m_fACE_Medical_SecondChanceRegenScale;
[RplProp()]
protected bool m_bACE_Medical_HasSecondChance = false;
[RplProp()]
protected bool m_bACE_Medical_SecondChanceOnHeadEnabled = false;
[RplProp()]
protected bool m_bACE_Medical_SecondChanceTriggered = false;



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

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);
}

//-----------------------------------------------------------------------------------------------------------
//! 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While thinking about constant correctness isn't inherently bad, we prefer to have it more consistent with the rest of the code base. The current convention for this repo is to have const only for primitive members.

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;
}
}

//------------------------------------------------------------------------------------------------
Expand All @@ -87,12 +83,15 @@ modded class SCR_CharacterDamageManagerComponent : SCR_DamageManagerComponent
//! Returns true if at least one physical hit zone is injured
bool ACE_Medical_CanBeHealed()
{
foreach (HitZone hitZone : m_aACE_Medical_PhysicalHitZones)
array<HitZone> physicalHitZones = {};
GetPhysicalHitZones(physicalHitZones);

foreach (HitZone hitZone : physicalHitZones)
{
if (hitZone.GetHealthScaled() < 0.999)
return true;
}

return false;
}

Expand All @@ -111,21 +110,21 @@ modded class SCR_CharacterDamageManagerComponent : SCR_DamageManagerComponent
{
return m_pACE_Medical_PainHitZone;
}

//-----------------------------------------------------------------------------------------------------------
//! Returns true if pain hit zone is at least moderately damaged
bool ACE_Medical_IsInPain()
{
return m_pACE_Medical_PainHitZone.GetHealthScaled() <= m_fACE_Medical_ModeratePainThreshold;
}

//-----------------------------------------------------------------------------------------------------------
//! Returns intensity of pain used for ACE_Medical_PainScreenEffect
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)
{
// No effect when less than moderate damage
Expand All @@ -137,52 +136,88 @@ 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
void ACE_Medical_EnableSecondChance(bool enable)
{
m_bACE_Medical_HasSecondChance = enable;
}

//------------------------------------------------------------------------------------------------
//! Check if second chance is enabled
bool ACE_Medical_HasSecondChance()
{
return m_bACE_Medical_HasSecondChance;
}

//-----------------------------------------------------------------------------------------------------------
//! Returns true if second chance is enabled for the given hit zone
bool ACE_Medical_HasSecondChanceOnHitZone(HitZone hitZone)
{
if (!m_bACE_Medical_HasSecondChance)
return false;

if (m_bACE_Medical_SecondChanceOnHeadEnabled)
return true;

return (hitZone != m_pHeadHitZone);
}

//------------------------------------------------------------------------------------------------
//! To be set true when second chance was used
void ACE_Medical_SetSecondChanceTrigged(bool isTriggered)
{
m_bACE_Medical_SecondChanceTriggered = isTriggered;
}

//------------------------------------------------------------------------------------------------
//! Check if second chance was used
bool ACE_Medical_WasSecondChanceTrigged()
{
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().Remove(ACE_Medical_EnableSecondChance);
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;
}
}
}

//------------------------------------------------------------------------------------------------
void ~SCR_CharacterDamageManagerComponent()
{
GetGame().GetCallqueue().Remove(ACE_Medical_EnableSecondChance);
}
}
File renamed without changes.
Loading