-
Notifications
You must be signed in to change notification settings - Fork 19
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
MichaelJRM
wants to merge
8
commits into
acemod:master
Choose a base branch
from
MichaelJRM:medical/refactoring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9004433
Backblast - Fixes for experimental (#64)
Kexanone c2a2878
Trenches - Fixes for experimental (#66)
Kexanone d8d6ece
Medical - Fixes for experimental (#67)
Kexanone 3e15bda
Replication cleanup
MichaelJRM 2972ae9
Refactoring
MichaelJRM befd3ff
Remove attribute
MichaelJRM fbd2304
Added proxy checks to prevent useless calls.
MichaelJRM 482911d
Remove replication changes
MichaelJRM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ Jonpas <[email protected]> | |
LorenLuke | ||
OverlordZorn | ||
Zelik | ||
FailNot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 0 additions & 58 deletions
58
addons/medical/scripts/Game/ACE_Medical/Character/SCR_CharacterControllerComponent.c
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
[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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------ | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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 | ||
|
@@ -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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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