Modular weapon crafting WIP (#611)
* data initalizing * modular assembling * grips and blades sprites * first prototypes * jewerly decoration * disassemble modular weapon * grip start stats * blade modifiers * inhand sprites generation * resprites inhand, add sickle, add attempt modify size * auto inhand sprite parsing * icon default parsing * spear blade * mace ball * sword blade * sharedization + autonetwork hotswipe * wielding sprite support! * iron long grip * wielded sickle, fix ERROR sprite if state not added * Update grips.yml * wielded spear + ruby rework * wielding damage bonus modifier * modular size fix * fix storedOffset rotation * parts offset * fix inheriting modifiers * some bugfix and balance tweaks * DPS Meter * fix dividing by zero * rebalance * replace baseknife to modular knife. Delete ice knife spell * sickle and mace modular replace * modular spear & sword replacement. add wielded icons * Update CP14DPSMeterSystem.cs * back to serverization * grip disassemble drop again * clothing sprite generation code * back slot long grips and mace * remove jewerly slot, add more clothing states * finish clothing states * shovel modular * YEEEEE * anvil modular craft * bugfixes * more integration check fixes
This commit is contained in:
169
Content.Server/_CP14/ModularCraft/CP14ModularCraftSystem.cs
Normal file
169
Content.Server/_CP14/ModularCraft/CP14ModularCraftSystem.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using Content.Server.Item;
|
||||
using Content.Shared._CP14.ModularCraft;
|
||||
using Content.Shared._CP14.ModularCraft.Components;
|
||||
using Content.Shared._CP14.ModularCraft.Prototypes;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server._CP14.ModularCraft;
|
||||
|
||||
public sealed class CP14ModularCraftSystem : CP14SharedModularCraftSystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
[Dependency] private readonly ThrowingSystem _throwing = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ItemSystem _item = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CP14ModularCraftStartPointComponent, MapInitEvent>(OnStartPointMapInit);
|
||||
SubscribeLocalEvent<CP14ModularCraftStartPointComponent, CP14ModularCraftAddPartDoAfter>(OnAddedPart);
|
||||
}
|
||||
|
||||
private void OnAddedPart(Entity<CP14ModularCraftStartPointComponent> ent, ref CP14ModularCraftAddPartDoAfter args)
|
||||
{
|
||||
if (args.Cancelled || args.Handled)
|
||||
return;
|
||||
|
||||
if (!TryComp<CP14ModularCraftPartComponent>(args.Used, out var partComp))
|
||||
return;
|
||||
|
||||
if (!TryAddPartToFirstSlot(ent, (args.Used.Value, partComp)))
|
||||
return;
|
||||
|
||||
//TODO: Sound
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnStartPointMapInit(Entity<CP14ModularCraftStartPointComponent> ent, ref MapInitEvent args)
|
||||
{
|
||||
foreach (var startSlot in ent.Comp.StartSlots)
|
||||
{
|
||||
ent.Comp.FreeSlots.Add(startSlot);
|
||||
}
|
||||
|
||||
if (TryComp<CP14ModularCraftAutoAssembleComponent>(ent, out var autoAssemble))
|
||||
{
|
||||
foreach (var detail in autoAssemble.Details)
|
||||
{
|
||||
TryAddPartToFirstSlot(ent, detail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryAddPartToFirstSlot(Entity<CP14ModularCraftStartPointComponent> start,
|
||||
Entity<CP14ModularCraftPartComponent> part)
|
||||
{
|
||||
foreach (var partProto in part.Comp.PossibleParts)
|
||||
{
|
||||
if (!_proto.TryIndex(partProto, out var partIndexed))
|
||||
continue;
|
||||
|
||||
if (partIndexed.TargetSlot is null)
|
||||
continue;
|
||||
|
||||
if (!start.Comp.FreeSlots.Contains(partIndexed.TargetSlot.Value))
|
||||
continue;
|
||||
|
||||
if (TryAddPartToSlot(start, part, partProto, partIndexed.TargetSlot.Value))
|
||||
{
|
||||
QueueDel(part);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private bool TryAddPartToFirstSlot(Entity<CP14ModularCraftStartPointComponent> start,
|
||||
ProtoId<CP14ModularCraftPartPrototype> partProto)
|
||||
{
|
||||
if (!_proto.TryIndex(partProto, out var partIndexed))
|
||||
return false;
|
||||
|
||||
if (partIndexed.TargetSlot is null)
|
||||
return false;
|
||||
|
||||
if (!start.Comp.FreeSlots.Contains(partIndexed.TargetSlot.Value))
|
||||
return false;
|
||||
|
||||
return TryAddPartToSlot(start, null, partProto, partIndexed.TargetSlot.Value);
|
||||
}
|
||||
|
||||
private bool TryAddPartToSlot(Entity<CP14ModularCraftStartPointComponent> start,
|
||||
Entity<CP14ModularCraftPartComponent>? part,
|
||||
ProtoId<CP14ModularCraftPartPrototype> partProto,
|
||||
ProtoId<CP14ModularCraftSlotPrototype> slot)
|
||||
{
|
||||
if (!start.Comp.FreeSlots.Contains(slot))
|
||||
return false;
|
||||
|
||||
var xform = Transform(start);
|
||||
if (xform.GridUid != xform.ParentUid)
|
||||
return false;
|
||||
|
||||
AddPartToSlot(start, part, partProto, slot);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void AddPartToSlot(Entity<CP14ModularCraftStartPointComponent> start,
|
||||
Entity<CP14ModularCraftPartComponent>? part,
|
||||
ProtoId<CP14ModularCraftPartPrototype> partProto,
|
||||
ProtoId<CP14ModularCraftSlotPrototype> slot)
|
||||
{
|
||||
start.Comp.FreeSlots.Remove(slot);
|
||||
start.Comp.InstalledParts.Add(partProto);
|
||||
|
||||
var indexedPart = _proto.Index(partProto);
|
||||
start.Comp.FreeSlots.AddRange(indexedPart.AddSlots);
|
||||
|
||||
foreach (var modifier in indexedPart.Modifiers)
|
||||
{
|
||||
modifier.Effect(EntityManager, start, part);
|
||||
}
|
||||
|
||||
_item.VisualsChanged(start);
|
||||
Dirty(start);
|
||||
}
|
||||
|
||||
public void DisassembleModular(EntityUid target)
|
||||
{
|
||||
if (!TryComp<CP14ModularCraftStartPointComponent>(target, out var modular))
|
||||
return;
|
||||
|
||||
var sourceCoord = _transform.GetMapCoordinates(target);
|
||||
|
||||
//Spawn start part
|
||||
if (modular.StartProtoPart is not null)
|
||||
{
|
||||
if (_random.Prob(0.5f)) //TODO: Dehardcode
|
||||
{
|
||||
var spawned = Spawn(modular.StartProtoPart, sourceCoord);
|
||||
_throwing.TryThrow(spawned, _random.NextAngle().ToWorldVec(), 1f);
|
||||
}
|
||||
}
|
||||
|
||||
//Spawn parts
|
||||
foreach (var part in modular.InstalledParts)
|
||||
{
|
||||
if (!_proto.TryIndex(part, out var indexedPart))
|
||||
continue;
|
||||
|
||||
if (_random.Prob(indexedPart.DestroyProb))
|
||||
continue;
|
||||
|
||||
if (indexedPart.SourcePart is null)
|
||||
continue;
|
||||
|
||||
var spawned = Spawn(indexedPart.SourcePart, sourceCoord);
|
||||
_throwing.TryThrow(spawned, _random.NextAngle().ToWorldVec(), 1f);
|
||||
}
|
||||
|
||||
//Delete
|
||||
QueueDel(target);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user