Add inhands support for startingGear (#1166)

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2020-06-22 06:37:03 +10:00
committed by GitHub
parent d91a8c4925
commit b6966a9b7f
2 changed files with 19 additions and 1 deletions

View File

@@ -476,9 +476,10 @@ namespace Content.Server.GameTicking
{ {
GridCoordinates coordinates = lateJoin ? GetLateJoinSpawnPoint() : GetJobSpawnPoint(job.Prototype.ID); GridCoordinates coordinates = lateJoin ? GetLateJoinSpawnPoint() : GetJobSpawnPoint(job.Prototype.ID);
var entity = _entityManager.SpawnEntity(PlayerPrototypeName, coordinates); var entity = _entityManager.SpawnEntity(PlayerPrototypeName, coordinates);
var startingGear = _prototypeManager.Index<StartingGearPrototype>(job.StartingGear);
if (entity.TryGetComponent(out InventoryComponent inventory)) if (entity.TryGetComponent(out InventoryComponent inventory))
{ {
var gear = _prototypeManager.Index<StartingGearPrototype>(job.StartingGear).Equipment; var gear = startingGear.Equipment;
foreach (var (slot, equipmentStr) in gear) foreach (var (slot, equipmentStr) in gear)
{ {
@@ -487,6 +488,16 @@ namespace Content.Server.GameTicking
} }
} }
if (entity.TryGetComponent(out HandsComponent handsComponent))
{
var inhand = startingGear.Inhand;
foreach (var (hand, prototype) in inhand)
{
var inhandEntity = _entityManager.SpawnEntity(prototype, entity.Transform.GridPosition);
handsComponent.PutInHand(inhandEntity.GetComponent<ItemComponent>(), hand);
}
}
return entity; return entity;
} }

View File

@@ -15,6 +15,12 @@ namespace Content.Shared.Jobs
private string _id; private string _id;
private Dictionary<Slots, string> _equipment; private Dictionary<Slots, string> _equipment;
public IReadOnlyDictionary<string, string> Inhand => _inHand;
/// <summary>
/// hand index, item prototype
/// </summary>
private Dictionary<string, string> _inHand;
[ViewVariables] public string ID => _id; [ViewVariables] public string ID => _id;
[ViewVariables] public IReadOnlyDictionary<Slots, string> Equipment => _equipment; [ViewVariables] public IReadOnlyDictionary<Slots, string> Equipment => _equipment;
@@ -24,6 +30,7 @@ namespace Content.Shared.Jobs
var serializer = YamlObjectSerializer.NewReader(mapping); var serializer = YamlObjectSerializer.NewReader(mapping);
serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _id, "id", string.Empty);
serializer.DataField(ref _inHand, "inhand", new Dictionary<string, string>(0));
var equipment = serializer.ReadDataField<Dictionary<string, string>>("equipment"); var equipment = serializer.ReadDataField<Dictionary<string, string>>("equipment");