Skip to main content

ForgedModel<TB, TA>

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

A metal piece that's shaped by hammering. Each hit on its forged points adds progress (and heat on the server); when every point is done the piece is complete, gives forging XP along the way and raises an item forged event.

Constructors​

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

Fields​

18 private and internal fields
MemberWhat it is
private ImpactDetectorSettings coldEffectImpact effect for hitting the piece while it is too cold.
private float distanceDistributionFalloff distance for how a hit's damage spreads to forged points further from the impact.
private ImpactDetectorSettings doneEffectImpact effect when most of the hit lands on points that are already finished.
private DurabilityModule durabilityModuleDurability module on the item; disabled until the piece is complete.
private GameObject[] enableOnCompleteObjects that are hidden at start and shown once forging is complete.
private ForgedPointCollection forgedPointCollectionSyncs the forged points' progress to clients.
private List<ForgedPoint> forgedPointsBacking field for ForgedPoints: the points that must each reach full progress.
private bool hasDurabilityModuleCached flag for whether a durability module was found (client only).
private ImpactDetectorSettings hotEffectImpact effect for a normal hit on hot, unfinished metal.
private ImpactDetector impactDetectorThe parent ImpactDetector whose hits drive forging.
private bool isFirstEffectPlayedClient: whether the first done-impact effect has played.
private static Logger loggerNLog logger for this class.
private static List<Mesh> modifiedStatic list of meshes; not used in this file.
private AltaEvent onCompletedEvent fired when the piece becomes complete.
private PhysicalMaterialPart physicalMaterialPartParent PhysicalMaterialPart whose material changes are tracked.
private Pickup pickupParent Pickup, used to find the last player who held it for experience and events.
private bool provideExperienceWhether hits on this piece grant forging experience.
private MethodSyncStruct<bool> syncCompleteNetwork message used to tell clients the piece is complete.

Properties​

MemberWhat it is
ForgedPointCollection ForgedPointCollection { get; }Syncs the forged points' state.
List<ForgedPoint> ForgedPoints { get; }The points that take hammer hits.
ImpactDetector ImpactDetector { get; }The impact detector whose hits shape the piece.
bool IsDone { get; private set; }True once the piece is complete. Only done pieces stack with done pieces.
PooledParticleSystemMeshEmision MeshEffect { get; set; }The particle effect playing over the mesh after completion, if any.
MeshFilter MeshFilter { get; }The piece's mesh filter.
PhysicalMaterial PhysicalMaterial { get; set; }The piece's metal. Sets how much each hit does and which effects play.
protected override float DefaultGreen { get; }0: starting value for the colour model's green channel.
protected override List<ForgedPoint> GreenPoints { get; }The forged points, used for the colour model.

Methods​

MemberWhat it is
void ForceComplete(bool isPlayingEffects)Sets every point's progress to full and completes the piece. Also used by the forged spawn argument.
override void Initialize()Sets up completion sync, and keeps durability and on-complete objects off until done.
override void InitializeAsServer(SpawnData spawnData)Server: completes the piece straight away if all points are already done.
override void OnConnected(Player player)Tells a newly connected player the piece is complete, if it is.
protected override void Awake()Hooks material changes, durability visuals and hits.
protected virtual void OnValidate()Editor: finds the durability module if it's missing.
12 private and internal methods
MemberWhat it is
private void Alta.Utilities.ISpawnArguments.CheckArguments(string[] arguments)Spawn argument hook: the argument forged makes the item spawn already complete.
private void CheckComplete(bool isPlayingEffects)Calls SetComplete once every forged point has reached full progress.
private void Alta.Crafting.IAffectCrafting.ForceActive()Crafting hook: forces the item complete without effects.
private void HandleHit(ImpactHit impact)Impact handler: spreads hit damage over nearby forged points; on the server also adds heat, grants forging experience and checks for completion.
private void HandleSetCompleteEvents(bool isPlayingEffects)Server: syncs completion to clients and broadcasts an ItemForgedEvent for the last player who held it.
private bool Alta.Crafting.IAffectCrafting.IsActive()Crafting hook: true once the item is done.
private void MeshEffectReleased(PooledObject pooled)Clears MeshEffect when the pooled mesh particle effect is released.
private static void ProcessForgedEvent(IPlayer player, uint hash)Broadcasts an ItemForgedEvent on the township event bus (server or local test only).
private void SetComplete(bool isPlayingEffects)Marks the item done, enables the complete objects, fires onCompleted, turns on durability and, on clients, swaps materials and plays the done effect.
private void SyncComplete(IPlayer player, Stream stream, bool isPlayingEffects)Network handler: reads the completion message and calls SetComplete on remote clients.
private void UpdateDurabilityStage(DurabilityModule.DurabilityVisual durabilityStage)Client: switches the mesh used for heat colouring when the durability visual stage changes.
private void UpdateMaterial(PhysicalMaterial physicalMaterial, PhysicalMaterialChannel materialChannel)Handles a material change from the PhysicalMaterialPart: on clients updates atlased mesh and materials, then stores the material.