Wx78 Shield
Based on game build 722832 | Last updated: 2026-04-28
Overview
Wx78_Shield manages the shield mechanic for the WX-78 character. It tracks current and maximum shield values, handles charge generation from multiple sources via SourceModifierList, and absorbs incoming damage when the shield is at or above the penetration threshold. The component syncs state to the wx78_classified component for client replication and pushes events when shield values change. Shield charging is gated by combat and hurt status checks.
Usage example
local inst = CreateEntity()
inst:AddComponent("wx78_shield")
inst.components.wx78_shield:SetMax(150)
inst.components.wx78_shield:AddChargeSource(inst, 5, "circuit_bonus")
inst.components.wx78_shield:DoDelta(25)
print(inst.components.wx78_shield:GetPercent())
Dependencies & tags
External dependencies:
util/sourcemodifierlist— manages additive charge generation modifiers from multiple sources
Components used:
combat— checked inIsInCombat()for last attacker and attack timestampshealth— checked viaIsHurt()to gate shield chargingwx78_classified— custom component for syncing shield values to clients
Tags:
wx78_shield— added on construction; identifies entities with shield capability
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
penetrationthreshold | number | 15 | Shield value at which damage is fully absorbed. Assignment fires on_penetrationthreshold watcher. |
currentshield | number | 0 | Current shield health. Clamped to 0–maxshield. Assignment fires on_currentshield watcher. |
maxshield | number | 100 | Maximum shield capacity. Assignment fires on_maxshield watcher. |
canshieldcharge | boolean | false | Whether shield can currently regenerate. Assignment fires on_canshieldcharge watcher and pushes wx_canshieldcharge event. |
chargegenerationsources | SourceModifierList | base 0 | Tracks per-source charge rate modifiers; combined additively. Call Get() for effective charge rate. |
effect_cooldown | number | 5 | Cooldown timer in seconds between shield visual effects. |
updating | boolean | false | Internal flag indicating if component update loop is active. |
COMBAT_TIMEOUT | constant (local) | 6 | Seconds after last combat action to consider entity "in combat" for charge gating. |
EFFECT_TIME | constant (local) | 10 | Base interval in seconds between shield visual effect spawns. |
EFFECT_TIME_VAR | constant (local) | 8 | Random variance added to EFFECT_TIME for effect spawn timing. |
Main functions
ChargeSourceChanged_Internal()
- Description: Internal method that checks if charge generation sources are active. Starts or stops the component update loop based on whether total charge rate is non-zero.
- Parameters: None
- Returns: nil
- Error states: None
AddChargeSource(source, amount, reason)
- Description: Adds a charge generation modifier from a specific source. Triggers
ChargeSourceChanged_Internal()to update the component update state. - Parameters:
source— entity or identifier for the charge sourceamount— number; charge rate contribution from this sourcereason— string key identifying the modifier type
- Returns: nil
- Error states: None
RemoveChargeSource(source, reason)
- Description: Removes a charge generation modifier from a specific source. Triggers
ChargeSourceChanged_Internal()to update the component update state. - Parameters:
source— entity or identifier for the charge sourcereason— string key identifying the modifier type to remove
- Returns: nil
- Error states: None
SetMax(amount)
- Description: Sets the maximum shield capacity. Calls
DoDelta(0)to trigger shield value event pushes. Asserts that amount is positive. - Parameters:
amount— number; must be greater than 0 - Returns: nil
- Error states: Errors if
amount <= 0due toassert()statement.
SetCurrent(amount)
- Description: Sets the current shield value, clamped between
0andmaxshield. Pusheswxshielddeltaevent with percentage change data. Spawns shield visual effects based on threshold crossings. - Parameters:
amount— number; new shield value (will be clamped) - Returns: nil
- Error states: None
- Effect spawn logic:
currentshield >= penetrationthresholdandold <= 0— spawnswx78_shield_fullcurrentshield >= penetrationthresholdandold <= penetrationthreshold— spawnswx78_shield_half_to_fullcurrentshield < penetrationthresholdandcurrentshield == 0andwas_over_threshold— spawnswx78_shield_full_to_emptycurrentshield < penetrationthresholdandcurrentshield > 0andwas_over_threshold— spawnswx78_shield_full_to_halfcurrentshield < penetrationthresholdandcurrentshield == 0andnot was_over_threshold— spawnswx78_shield_half_to_emptycurrentshield < penetrationthresholdandcurrentshield > 0andold <= 0— spawnswx78_shield_half
GetMax()
- Description: Returns the maximum shield capacity.
- Parameters: None
- Returns: number; current
maxshieldvalue - Error states: None
GetCurrent()
- Description: Returns the current shield value.
- Parameters: None
- Returns: number; current
currentshieldvalue - Error states: None
GetPenetrationThreshold()
- Description: Returns the shield penetration threshold value.
- Parameters: None
- Returns: number; current
penetrationthresholdvalue - Error states: None
GetPercent()
- Description: Returns the current shield as a percentage of maximum.
- Parameters: None
- Returns: number;
currentshield / maxshield(0.0 to 1.0) - Error states: None
SetPercent(p)
- Description: Sets the current shield value based on a percentage of maximum.
- Parameters:
p— number; percentage value (0.0 to 1.0 recommended) - Returns: nil
- Error states: None
Impenetrable()
- Description: Checks if the current shield is at or above the penetration threshold, meaning incoming damage will be fully absorbed.
- Parameters: None
- Returns: boolean;
trueifcurrentshield >= penetrationthreshold - Error states: None
DoDelta(delta)
- Description: Applies a delta value to the current shield by calling
SetCurrent(currentshield + delta). - Parameters:
delta— number; positive or negative change to apply - Returns: nil
- Error states: None
UpdateCanShieldCharge()
- Description: Updates the
canshieldchargeproperty based on current state. Shield can charge only if: component is updating, current shield is below max, entity is not in combat, and entity is not hurt. - Parameters: None
- Returns: nil
- Error states: Errors if
inst.components.combatorinst.components.healthis nil whenIsInCombat()orIsHurt()is called — no nil guards present in those helper functions.
GetCanShieldCharge()
- Description: Returns whether the shield can currently regenerate charge.
- Parameters: None
- Returns: boolean; current
canshieldchargevalue - Error states: None
OnTakeDamage(amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb)
- Description: Damage handler called by the combat system. Returns modified damage value based on shield state.
- Parameters:
amount— number; incoming damage (negative values indicate damage)overtime— boolean; whether damage is over-time effectcause— string; damage source typeignore_invincible— boolean; whether to bypass invincibilityafflicter— entity; source of the damageignore_absorb— boolean; whether to bypass shield absorption
- Returns: number; damage value to apply to health (0 if fully absorbed, or
amount + currentif partially absorbed) - Error states: None —
afflicternil case is guarded by early return (afflicter == nilcheck at start of function body). - Damage calculation logic:
- If
ignore_absorboramount >= 0orovertimeorafflicter == nil— returnsamountunchanged (no shield absorption) - If
Impenetrable()— applies full damage to shield viaDoDelta(amount)and returns0(health takes no damage) - Otherwise — applies damage to shield and returns
amount + current(health takes damage plus shield depletion)
- If
OnUpdate(dt)
- Description: Periodic update called when component is active. Updates charge eligibility, applies charge generation if eligible, and manages visual effect cooldown.
- Parameters:
dt— number; delta time in seconds since last update - Returns: nil
- Error states: None
- Effect spawn logic: When
effect_cooldown <= 0andcurrentshield > 0, spawnswx78_shield_halfif below threshold orwx78_shield_fullif at/above threshold. Resets cooldown toEFFECT_TIME + random(0, EFFECT_TIME_VAR).
OnSave()
- Description: Returns save data for the shield component. Only saves if current shield is non-zero.
- Parameters: None
- Returns: table
{ current = number }ornilif current shield is 0 - Error states: None
OnLoad(data)
- Description: Restores shield state from save data.
- Parameters:
data— table; saved data fromOnSave() - Returns: nil
- Error states: None
GetDebugString()
- Description: Returns a formatted debug string showing current and maximum shield values.
- Parameters: None
- Returns: string; format
"%2.2f / %2.2f"with current and max values - Error states: None
on_penetrationthreshold(self, threshold, old_threshold) (local)
- Description: Property watcher callback fired when
penetrationthresholdis assigned. Syncs the new value towx78_classifiedcomponent. - Parameters:
threshold— number; new threshold valueold_threshold— number; previous threshold value
- Returns: nil
- Error states: None; guards against
wx78_classifiedbeing nil.
on_currentshield(self, current, old_current) (local)
- Description: Property watcher callback fired when
currentshieldis assigned. Syncs the new value towx78_classifiedcomponent. - Parameters:
current— number; new shield valueold_current— number; previous shield value
- Returns: nil
- Error states: None; guards against
wx78_classifiedbeing nil.
on_maxshield(self, max, old_max) (local)
- Description: Property watcher callback fired when
maxshieldis assigned. Syncs the new value towx78_classifiedcomponent. - Parameters:
max— number; new max shield valueold_max— number; previous max shield value
- Returns: nil
- Error states: None; guards against
wx78_classifiedbeing nil.
on_canshieldcharge(self, val) (local)
- Description: Property watcher callback fired when
canshieldchargeis assigned. Syncs the value towx78_classified.canshieldchargenetvar and pusheswx_canshieldchargeevent. - Parameters:
val— boolean; new charge eligibility state - Returns: nil
- Error states: None; guards against
wx78_classifiedbeing nil.
IsInCombat(inst) (local)
- Description: Helper function that determines if an entity is currently in combat. Checks last attacker validity, target relationship, and combat timeout.
- Parameters:
inst— entity; the entity to check - Returns: boolean;
trueif entity is in combat - Error states: Errors if
inst.components.combatis nil — returnsfalseearly with guard. Errors iflastattacker.components.healthorlastattacker.components.combatis nil when accessed — no nil guards present for those chained accesses.
IsHurt(inst) (local)
- Description: Helper function that checks if an entity's health is below maximum.
- Parameters:
inst— entity; the entity to check - Returns: boolean;
trueif health is below max - Error states: None; guards against
inst.components.healthbeing nil.
Events & listeners
- Pushes:
wx_canshieldcharge— fired whencanshieldchargeproperty changes; data: direct boolean param (val) — not a data table - Pushes:
wxshielddelta— fired whenSetCurrent()changes shield value; data includesoldpercent,newpercent,maxshield,penetrationthreshold