DurabilityModule
A class in Root.Township, the global namespace.
Wears a tool or weapon down with each hit, swaps its damage stage visuals and breaks it at zero. Wear is worked out on the server; clients get the stage. Get it with pickup.DurabilityModule.
- Listed in Global namespace: C to D
- Inherits or implements
NetworkEntityBehaviour,ISavable<DurabilityModuleSaveData>,ISavableSave<DurabilityModuleSaveData>,ISavableSaveBase,IEntityReplaceHandler,IReferenceRenderer,IBuildRendererPostBake,IBuildBakeable - Derived types
DurabilityModuleSaveData - Nested types
DurabilityVisual
Constructors
| Member | What it is |
|---|---|
DurabilityModule() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
AltaEvent brokeOnServer | Event raised on the server when the item breaks. |
12 private and internal fields
| Member | What it is |
|---|---|
private HashSet<DurabilityModule> attachedModules | Modules attached to this one; their durability adds to this one's and damage is shared with them. |
private float baseDurability | Starting durability from the settings, scaled by the physical material. |
private bool canDockWhenDamaged | Lets damaged stackables dock, but only with items at the same stage. |
private float currentDurability | Remaining durability; damage is divided by this to get the integrity loss. |
private DurabilitySettings durabilitySettings | The durability settings asset: durability, damage conversion and chance-based mode. |
private float integrity | Health of the item from 0 to 1; saved, and the pickup breaks at 0. Backing field for Integrity. |
private static Logger logger | Class logger. |
private SoundEffectSet overrideStateChangeSound | Sound to play on a stage change instead of the global default. |
private int stagesCount | Number of stage visuals. |
private DurabilityModule.DurabilityVisual[] stageVisuals | Renderer sets for each damage stage with the integrity threshold for each. |
private PickupEvent stateChangeEffect | Pickup event invoked on a stage change, client side. |
private MethodSyncStruct<bool> syncStage | Method sync that sends the current stage to players. |
Properties
| Member | What it is |
|---|---|
DurabilityModule AttachedTo { get; private set; } | The module this one is attached to, or null. |
int CurrentStage { get; private set; } | Index of the damage stage shown. |
float Integrity { get; } | How intact the item is, from 1 (new) to 0 (broken). This is what saves. |
Pickup Pickup { get; } | The entity's pickup. |
1 private and internal property
| Member | What it is |
|---|---|
private NetworkEntity Alta.Networking.IEntityReplaceHandler.Entity { get; } | The entity this module is on. |
Events
| Member | What it is |
|---|---|
event Action<DurabilityModule.DurabilityVisual> OnChangedStage | Raised when the damage stage changes. |
Methods
| Member | What it is |
|---|---|
void AffectDurability(float damage) | Server: applies wear from a hit, passing it to the item this is attached to if any, then updates the stage or breaks. |
void AttachTo(DurabilityModule to) | Joins this module's durability onto another (a crafted part joining the whole). |
bool CheckBreak() | Breaks the pickup if integrity is 0 or less, raising brokeOnServer on the server. Returns whether it broke. |
void Detach() | Splits this module's durability back out and checks if the other breaks. |
override void Initialize() | Sets up the stage sync message. |
override void InitializeAsServer(SpawnData spawnData) | Server: listens for durability hits from the pickup and sets the starting stage. |
override void OnConnected(Player player) | Server: sends the current stage to a joining player. |
void UpdateMaterial(PhysicalMaterial physicalMaterial) | Scales the base durability by a material's multiplier. Has no effect on wear in this build. |
14 private and internal methods
| Member | What it is |
|---|---|
private void AnimateStateChange(int stage) | Client: plays the stage change sound (override or global default) and the stage change effect. |
private void Awake() | Loads durability from the settings, resets visuals and hooks the dock filter and break effect where needed. |
private void OnDurabilityChanged(bool hasEffects = true) | Breaks the pickup if integrity is gone, otherwise moves to the stage that matches the new integrity. |
private void OnValidate() | Empty. |
private void IBuildRendererPostBake.PostBake() | Build step: drops missing renderers from every stage visual. |
private void ReevaluateRemainingDurabilityFromIntegrity() | Recomputes remaining durability from integrity plus attached modules. Not called anywhere in this build. |
private void RemoveIntegrity(float amount) | Scales integrity and remaining durability down by the given fraction. |
private void Alta.Networking.IEntityReplaceHandler.ReplacedWith(NetworkEntity entity, ReplaceAvoidFlags replaceFlags) | Copies a damaged module's integrity onto the replacement entity and updates its stage without effects. |
private void ResetVisuals() | Shows stage 0's renderers and hides every other stage. |
private void SetStage(int stage, bool hasEffects = true) | Switches the visible stage, syncs it to chunks on the server, raises OnChangedStage and plays effects on clients. |
private void SetupEffect(PooledObject effect) | Gives the break effect the mesh of the current stage. |
private void StageStackFilter(Interactor interactor, PickupDock dock, ref bool result) | Dock filter for stackable items: stops damaged items stacking, or stacking with a different stage when canDockWhenDamaged is set. |
private void SyncStage(IPlayer player, Stream stream, bool hasEffects) | Network handler for the stage message; clients apply the received stage. |
private void IReferenceRenderer.UpdateRenderers(Renderer[] oldFirstRenderers, Renderer[] newFirstRenderers) | Swaps renderer references in every stage visual when renderers are replaced, for example by atlasing. |
Used in
Members of other types that take, return or hold a DurabilityModule: