Skip to main content

DecraftingComponent

An abstract class in Root.Township, Alta.Crafting.

Base for a station that takes crafted items apart by hitting them with a chisel tool. Hits near a joint knock off the outermost part there. The hit runs on the server and the effect syncs to clients.

Constructors​

MemberWhat it is
protected DecraftingComponent()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

8 private and internal fields
MemberWhat it is
private List<JointSlot> availableSlotsSlots whose attached part can be knocked off now.
private Chiselable currentChiseleableChiselable added to the current part so it can be hit.
private CraftingPart currentPartThe crafting part being decrafted.
private PositionEvent decraftingHitEffectEffect for a hit that lands near a removable part.
private PositionEvent innefectiveHitEffectEffect for a hit that is too weak or misses every slot.
private float maxDistanceFromInsertSquaredSquared distance from a slot a hit must land within.
private float minimumHitToDecraftLeast damage a hit needs to knock a part off.
private MethodSyncStruct<DecraftingComponent.HitTypePosition> syncDecraftingHitMessage sync for hit effects.

Properties​

MemberWhat it is
virtual bool CanPickupChangeWhileAdded { get; }Whether non-crafted items may be added. False by default.

Methods​

MemberWhat it is
void AddPickup(Pickup newPickup)Starts tracking a crafted item: adds a Chiselable to it and maps its joint slots. Uncrafted items need the forced overload or CanPickupChangeWhileAdded.
void AddPickup(Pickup newPickup, bool isForced)Starts tracking a crafted item: adds a Chiselable to it and maps its joint slots. Uncrafted items need the forced overload or CanPickupChangeWhileAdded.
override void Initialize()Sets up the synced hit effect message.
void RemoveCurrentPickup()Stops tracking the current item and removes its Chiselable.
protected void TryDecraft(float damage, Vector3 position, Vector3 direction, ChiselingTool tool, Collider hitCollider)Server: handles a chisel hit. A strong enough hit near a joint of an outer part fully disconnects that part; otherwise plays the ineffective effect.
protected virtual bool ValidateCraftingPart(CraftingPart part)Override to refuse removing a given part. Returns true by default.
5 private and internal methods
MemberWhat it is
private bool AddPartSlots(CraftingPart part)Adds the slots holding outermost parts (ones with nothing attached) to availableSlots. Returns true if the part has nothing attached.
private bool GetClosestSlot(ref JointSlot closestSlot, Vector3 position)Finds the available slot nearest the hit, within maxDistanceFromInsertSquared.
private void MapSlots()Rebuilds the list of slots that can be knocked off.
private void ReMapSlots(CraftingPart part, bool isLoad)Handler for the part being crafted: rebuilds the slot list.
private void SyncDecraftingHit(IPlayer player, Stream stream, DecraftingComponent.HitTypePosition hitTypePosition)Network message that plays the effective or ineffective hit effect on clients.