Wx78 Classified
Based on game build 722832 | Last updated: 2026-04-28
Overview
wx78_classified.lua registers a hidden entity prefab that serves as the networked data container for WX-78's upgrade system. The prefab is attached to WX-78 player entities and manages upgrade module slots, backup body count, shield state, and energy levels. Server-side logic handles body attachment/detachment while client-side logic manages UI updates and module activation states. The entity is created hidden (inst.entity:Hide()) and tagged CLASSIFIED to prevent normal entity interaction.
Usage example
-- Access from WX-78 player instance:
local wx78_classified = player.wx78_classified
if wx78_classified ~= nil then
-- Query energy state:
local energy = wx78_classified:GetEnergyLevel()
local max_energy = wx78_classified:GetMaxEnergy()
-- Query backup body capacity:
local max_bodies = wx78_classified:GetMaxBackupBodies()
local free_bodies = wx78_classified:GetNumFreeBackupBodies()
-- Client-side: get module configuration
local moddata = wx78_classified:GetModulesData()
end
-- Server-side: add/remove backup bodies
if TheWorld.ismastersim then
wx78_classified:TryToAddBackupBody(body_inst)
wx78_classified:TryToRemoveBackupBody(body_inst)
end
Dependencies & tags
External dependencies:
wx78_moduledefs-- providesGetModuleDefinitionFromNetID()for resolving module netvar IDs to definitionsprefabs/skilltree_defs-- providesSKILLTREE_DEFSfor computing max body count from skill tree
Components used:
linkeditem-- accessed on backup body entities to link/unlink from owner user IDskilltreeupdater-- accessed on owner player to check if body-count skills are activated
Tags:
CLASSIFIED-- added infn()to mark entity as hidden data container
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
MAX_BODY_COUNT | constant (local) | computed | Total number of skills tagged wx78_maxbody in SKILLTREE_DEFS.wx78. Determines max backup body capacity. |
MAX_BODY_COUNT_SKILLS | table (local) | {...} | Array of skill names that contribute to max body count. Iterated by GetMaxBackupBodies(). |
currentenergylevel | net_smallbyte | 0 | Current energy charge level. Dirty event: upgrademoduleenergyupdate. |
maxenergylevel | net_smallbyte | TUNING.WX78_INITIAL_MAXCHARGELEVEL | Maximum energy capacity. Dirty event: upgrademoduleenergyupdate. |
upgrademodulebars | table | {} | Nested table of net_smallbyte arrays per circuit bar type. Each slot holds a module net ID. Dirty event: upgrademoduleslistdirty. |
_activatedmods | table | {} | Tracks which module slots are currently active (true/false) per bar type and index. |
inspectupgrademodulebars | net_bool | false | Controls visibility of upgrade module widget. Dirty event: inspectupgrademodulebarsdirty. |
performedspinaction | net_bool | false | Tracks whether spin action was an attack. Dirty event: performedspinactiondirty. |
currentshield | net_ushortint | 0 | Current shield value. Dirty event: shielddirty. |
canshieldcharge | net_bool | false | Whether shield can currently charge. Dirty event: canshieldchargedirty. |
maxshield | net_ushortint | 1 | Maximum shield capacity. Dirty event: shielddirty. |
shieldpenetrationthreshold | net_ushortint | 15 | Damage threshold for shield penetration. Dirty event: shielddirty. |
numactivebodies | net_enum | 0 | Count of currently attached backup bodies. Dirty event: numactivebodiesdirty. |
numdronescouts | net_enum | 0 | Count of active scout drones. Dirty event: numdronescoutsdirty. |
poweroffoverlay | net_bool | false | Controls power-off overlay visibility. Dirty event: poweroffoverlaydirty. |
uirobotsparksevent | net_event | --- | Fires robot spark visual effect. No value storage; triggered via :push(). |
backupbodies | table | {} | (master only) Map of body entity to true for tracking attached backup bodies. |
_oldupgrademodulebars | table | {} | Cached module data for detecting changes between dirty events. |
_oldcurrentenergylevel | number | 0 | Cached previous energy level for delta computation in events. |
_oldmaxenergylevel | number | 0 | Cached previous max energy for delta computation in events. |
_oldshieldpercent | number | 0 | Cached previous shield percentage for delta computation in events. |
Main functions
fn()
- Description: Prefab constructor. Creates hidden entity, adds
CLASSIFIEDtag, initializes all netvars for energy, modules, shield, bodies, and drones. Attaches common interface methods toinst. On client, attaches client-only methods andOnEntityReplicated. On master, attaches server-only methods for body management. Returnsinstfor framework to complete initialization. - Parameters: None
- Returns: entity instance
- Error states: None — runs on every host (client and server).
SetValue(inst, name, value) (local)
- Description: Server-side helper to set a netvar value with range validation. Asserts if value is outside
0–65535range. Uses:set()to update netvar and fire dirty event. - Parameters:
inst-- entity instancename-- string netvar property name oninstvalue-- number to set (must be0 <= value <= 65535)
- Returns: None
- Error states: Asserts if
valueis outside valid range. Errors ifinst[name]is not a netvar with:set()method.
TryToAddBackupBody(inst, body) (local)
- Description: Server-side. Attempts to attach a backup body entity. Returns
falseif body is already tracked or no free body slots available. On success, adds body tobackupbodiestable, incrementsnumactivebodies, and pushesrefreshcraftingevent to owner HUD. - Parameters:
inst-- wx78_classified entitybody-- backup body entity instance
- Returns:
trueon success,falseon failure (already exists or no free slots) - Error states: None — gracefully returns
falseon failure conditions.
TryToRemoveBackupBody(inst, body) (local)
- Description: Server-side. Attempts to detach a backup body entity. Returns
falseif body is not tracked. On success, removes frombackupbodies, decrementsnumactivebodies, and pushesrefreshcraftingevent to owner HUD. - Parameters:
inst-- wx78_classified entitybody-- backup body entity instance
- Returns:
trueon success,falseif body was not tracked - Error states: None — gracefully returns
falseif body not found.
DetachBodiesToMaximumCount(inst, maxbodies) (local)
- Description: Server-side. Forces detachment of backup bodies if
numactivebodiesexceedsmaxbodies. Iterates throughbackupbodiestable and callsTryToRemoveBackupBody()until count matches threshold. Unlinks each removed body vialinkeditem:LinkToOwnerUserID(nil). Asserts if unable to remove enough bodies. - Parameters:
inst-- wx78_classified entitymaxbodies-- maximum allowed active body count
- Returns: None
- Error states: Asserts if
toremovecount > 0after exhausting all backup bodies (indicates data corruption).
GetOwningPlayer(inst) (local)
- Description: Common interface. Resolves the player entity that owns this classified data. Checks
inst._parent.isplayerfirst, then falls back tolinkeditem:GetOwnerInst()if parent has linkeditem component. - Parameters:
inst-- wx78_classified entity - Returns: Player entity instance or
nilif owner cannot be resolved - Error states: None — returns
nilgracefully if no owner found.
GetOwningWX78_Classified(inst) (local)
- Description: Common interface. Returns the wx78_classified entity for the owning player. If
instis already the classified entity, returnsinst. Otherwise resolves owner player and returnsowner.wx78_classified. - Parameters:
inst-- wx78_classified entity or child entity - Returns: wx78_classified entity instance
- Error states: None — returns
instas fallback if owner lookup fails.
GetMaxBackupBodies(inst) (local)
- Description: Common interface. Computes maximum backup body capacity by iterating
MAX_BODY_COUNT_SKILLSand checking if each skill is activated viaskilltreeupdater:IsActivated(). Requires owner player withskilltreeupdatercomponent. - Parameters:
inst-- wx78_classified entity - Returns: Integer max body count (0 if no skilltreeupdater or owner)
- Error states: None — returns
0if prerequisites not met.
GetNumFreeBackupBodies(inst) (local)
- Description: Common interface. Returns available backup body slots by computing
maxbodies - numactivebodies. Clamps result to minimum0. - Parameters:
inst-- wx78_classified entity - Returns: Integer free body count (minimum
0) - Error states: None.
GetNumFreeScoutingDrones(inst) (local)
- Description: Common interface. Returns available scout drone slots. Max count is
TUNING.SKILLS.WX78.SCOUTDRONE_MAX_COUNTifwx78_scoutdrone_1skill is activated, otherwise0. Subtractsnumdronescoutsfrom max. - Parameters:
inst-- wx78_classified entity - Returns: Integer free drone count (minimum
0) - Error states: None.
OnPowerOffOverlayDirty(inst) (local)
- Description: Event listener callback. Triggered when
poweroffoverlaynetvar changes. Callsinst._parent.HUD.wxpowerover:PowerOff()if true, orClear()if false. Requires parent with HUD. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None — guards against missing
_parentorHUD.
OnUnsocketShadowSlot(parent, socketposition) (local)
- Description: Client-side. Sends
RPC.UnplugModuleto server when a module is unsocketed from the shadow slot. - Parameters:
parent-- parent entity (WX-78 player)socketposition-- integer slot index
- Returns: None
- Error states: None.
OnEntityReplicated(inst) (local)
- Description: Client-side replication handler. Called when entity is replicated on client. Resolves
inst._parentfrom entity parent, registerssocketholder_unsocketlistener, and callsinst._parent:AttachClassified_wx78(inst)to complete attachment. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: Prints error if
inst._parentis nil (should not occur in normal operation).
TryActivateModule(inst, definition, bartype, moduleindex) (local)
- Description: Client-side. Activates a module slot if not already active. Sets
_activatedmodsflag and callsdefinition.client_activatefn()if defined. - Parameters:
inst-- wx78_classified entitydefinition-- module definition table fromwx78_moduledefsbartype-- circuit bar type keymoduleindex-- integer slot index
- Returns: None
- Error states: None — guards against already-active modules.
TryDeactivateModule(inst, definition, bartype, moduleindex) (local)
- Description: Client-side. Deactivates a module slot if active. Clears
_activatedmodsflag and callsdefinition.client_deactivatefn()if defined. - Parameters:
inst-- wx78_classified entitydefinition-- module definition table fromwx78_moduledefsbartype-- circuit bar type keymoduleindex-- integer slot index
- Returns: None
- Error states: None — guards against already-inactive modules.
UpdateActivatedModules(inst) (local)
- Description: Client-side. Recomputes active module states based on current energy level. Iterates all module slots, subtracts slot costs from remaining charge, and activates/deactivates modules accordingly. Modules beyond energy budget are deactivated.
- Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None.
GetModulesData(inst) (local)
- Description: Client-side. Returns a table of current module net IDs organized by bar type. Used for caching and change detection.
- Parameters:
inst-- wx78_classified entity - Returns: Table
{bartype = {netid, netid, ...}, ...} - Error states: None.
CanUpgradeWithModule(inst, moduleent) (local)
- Description: Client-side. Checks if a module can be added without exceeding max energy. Sums current slot usage from
upgrademodulebarsand compares againstmaxenergylevel. - Parameters:
inst-- wx78_classified entitymoduleent-- module entity to check
- Returns:
trueif module fits,falseotherwise - Error states: None.
GetModuleTypeCount(inst, module_name) (local)
- Description: Client-side. Counts how many modules of a specific name are currently active within energy budget. Iterates bars in order, tracking remaining charge, and increments count when matching module name is found before energy depletion.
- Parameters:
inst-- wx78_classified entitymodule_name-- string module definition name
- Returns: Integer count of active modules with matching name
- Error states: None.
UnplugModule(inst, moduletype, moduleindex) (local)
- Description: Client-side. Sends
RPC.UnplugModuleto server to remove a module from a slot. - Parameters:
inst-- wx78_classified entitymoduletype-- circuit bar type keymoduleindex-- integer slot index
- Returns: None
- Error states: None.
GetMaxEnergy(inst) (local)
- Description: Client-side. Returns the maximum energy capacity from
maxenergylevelnetvar. - Parameters:
inst-- wx78_classified entity - Returns: Integer max energy value
- Error states: None.
GetEnergyLevel(inst) (local)
- Description: Client-side. Returns the current energy level from
currentenergylevelnetvar. - Parameters:
inst-- wx78_classified entity - Returns: Integer current energy value
- Error states: None.
OnEnergyLevelDirty(inst) (local)
- Description: Event listener callback. Triggered when energy level changes. Computes delta data (old/new level, old/max level), calls
UpdateActivatedModules(), caches new values, and pushesenergylevelupdateevent to parent with delta data. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None — guards against missing
_parent.
OnPerformedSpinActionDirty(inst) (local)
- Description: Event listener callback. Triggered when
performedspinactionnetvar changes. Pusheswx_performedspinactionevent to parent with the new value. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None.
OnPerformedSpinAction_Server(parent, isattack) (local)
- Description: Server-side event handler. Sets
performedspinactionnetvar on the classified entity when parent triggers spin action. Uses:set_local()then:set()to ensure both local and networked update. - Parameters:
parent-- WX-78 player entityisattack-- boolean indicating if spin was an attack
- Returns: None
- Error states: None — guards against missing
parent.wx78_classified.
OnShieldDirty(inst) (local)
- Description: Event listener callback. Triggered when shield state changes. Computes shield percentage, caches old value, and pushes
wxshielddeltaevent to parent with old/new percent, max shield, and penetration threshold. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None — initializes
_oldshieldpercentto0if no parent.
OnCanShieldChargeDirty(inst) (local)
- Description: Event listener callback. Triggered when
canshieldchargenetvar changes. Pusheswx_canshieldchargeevent to parent with the new value. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None.
OnUIRobotSparks(inst) (local)
- Description: Event listener callback. Triggered by
uirobotsparksevent. Pushesdo_robot_sparkevent to parent to trigger visual effect. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None.
OnUpgradeModulesListDirty(inst) (local)
- Description: Event listener callback. Triggered when module slot configuration changes. Compares old vs new net IDs, deactivates modules that were removed, updates
_oldupgrademodulebarscache, callsUpdateActivatedModules(), and pushes eitherupgrademoduleowner_popallmodules(if all empty) orupgrademodulesdirty(with new data) to parent. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None.
OnInspectUpgradeModuleBarsDirty(inst) (local)
- Description: Event listener callback. Triggered when
inspectupgrademodulebarschanges. Shows or hides the upgrade module widget onThePlayer.HUDbased on the netvar value. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None — guards against missing
ThePlayerorHUD.
OnCraftingNetVarDirty(inst) (local)
- Description: Event listener callback. Triggered when
numactivebodiesornumdronescoutschanges. Pushesrefreshcraftingevent to parent HUD to update crafting UI. - Parameters:
inst-- wx78_classified entity - Returns: None
- Error states: None.
GetDebugString(inst) (local)
- Description: Returns debug information about body counts from both owner and body perspectives. Calls
AddDebugString()for relevant classified entities and appends:_GetDebugString()output. - Parameters:
inst-- wx78_classified entity - Returns: String debug output
- Error states: None.
Events & listeners
Listens to:
socketholder_unsocket-- triggersOnUnsocketShadowSlot()to unplug module from shadow slot (client only)wx_performedspinaction-- triggersOnPerformedSpinAction_Server()to update spin action state (master only)uirobotsparksevent-- triggersOnUIRobotSparks()to fire robot spark visual (client only)upgrademoduleenergyupdate-- triggersOnEnergyLevelDirty()to update module activation and notify parent (client only)upgrademoduleslistdirty-- triggersOnUpgradeModulesListDirty()to sync module configuration (client only)inspectupgrademodulebarsdirty-- triggersOnInspectUpgradeModuleBarsDirty()to show/hide module widget (client only)numactivebodiesdirty-- triggersOnCraftingNetVarDirty()to refresh crafting UI (client only)numdronescoutsdirty-- triggersOnCraftingNetVarDirty()to refresh crafting UI (client only)performedspinactiondirty-- triggersOnPerformedSpinActionDirty()to notify parent of spin action (client only)shielddirty-- triggersOnShieldDirty()to compute and notify shield delta (client only)canshieldchargedirty-- triggersOnCanShieldChargeDirty()to notify shield charge state (client only)poweroffoverlaydirty-- triggersOnPowerOffOverlayDirty()to update power-off overlay (common)
Pushes:
energylevelupdate-- Data:{old_level, new_level, old_max_level, new_max_level}. Fired when energy level changes.wxshielddelta-- Data:{oldpercent, newpercent, maxshield, penetrationthreshold}. Fired when shield state changes.wx_canshieldcharge-- Data: boolean value. Fired when shield charge capability changes.do_robot_spark-- Data: none. Fired to trigger robot spark visual effect.upgrademoduleowner_popallmodules-- Data: none. Fired when all module slots become empty.upgrademodulesdirty-- Data:{bartype = {netid, ...}, ...}. Fired when module configuration changes (not empty).refreshcrafting-- Data: none. Fired when body or drone count changes to update crafting UI.wx_performedspinaction-- Data: boolean isattack value. Fired when spin action state changes.