Improves the JobSpecial system. (#4626)
* Improves the JobSpecial system. * clean up code
This commit is contained in:
committed by
GitHub
parent
4fffb3c582
commit
078a62762f
@@ -97,7 +97,11 @@ namespace Content.Server.GameTicking
|
||||
AddManifestEntry(character.Name, jobId);
|
||||
AddSpawnedPosition(jobId);
|
||||
EquipIdCard(mob, character.Name, jobPrototype);
|
||||
jobPrototype.Special?.AfterEquip(mob);
|
||||
|
||||
foreach (var jobSpecial in jobPrototype.Special)
|
||||
{
|
||||
jobSpecial.AfterEquip(mob);
|
||||
}
|
||||
|
||||
Preset?.OnSpawnPlayerCompleted(player, mob, lateJoin);
|
||||
}
|
||||
|
||||
26
Content.Server/Jobs/AddComponentSpecial.cs
Normal file
26
Content.Server/Jobs/AddComponentSpecial.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Content.Server.Interaction.Components;
|
||||
using Content.Shared.Roles;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Jobs
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class AddComponentSpecial : JobSpecial
|
||||
{
|
||||
// TODO: Type serializer that ensures the component exists.
|
||||
[DataField("component", required:true)]
|
||||
public string Component { get; } = string.Empty;
|
||||
|
||||
public override void AfterEquip(IEntity mob)
|
||||
{
|
||||
// Yes, this will throw if your component is invalid.
|
||||
var component = (Component)IoCManager.Resolve<IComponentFactory>().GetComponent(Component);
|
||||
component.Owner = mob;
|
||||
|
||||
IoCManager.Resolve<IComponentManager>().AddComponent(mob, component);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using Content.Server.Interaction.Components;
|
||||
using Content.Shared.Roles;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Jobs
|
||||
{
|
||||
// Used by clown job def.
|
||||
[UsedImplicitly]
|
||||
public sealed class ClownSpecial : JobSpecial
|
||||
{
|
||||
public override void AfterEquip(IEntity mob)
|
||||
{
|
||||
base.AfterEquip(mob);
|
||||
|
||||
mob.AddComponent<ClumsyComponent>();
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Content.Server/Jobs/GiveItemOnHolidaySpecial.cs
Normal file
41
Content.Server/Jobs/GiveItemOnHolidaySpecial.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Holiday;
|
||||
using Content.Server.Holiday.Interfaces;
|
||||
using Content.Server.Items;
|
||||
using Content.Shared.Roles;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Jobs
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class GiveItemOnHolidaySpecial : JobSpecial
|
||||
{
|
||||
[DataField("holiday", customTypeSerializer:typeof(PrototypeIdSerializer<HolidayPrototype>))]
|
||||
public string Holiday { get; } = string.Empty;
|
||||
|
||||
[DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string Prototype { get; } = string.Empty;
|
||||
|
||||
public override void AfterEquip(IEntity mob)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Holiday) || string.IsNullOrEmpty(Prototype))
|
||||
return;
|
||||
|
||||
if (!IoCManager.Resolve<IHolidayManager>().IsCurrentlyHoliday(Holiday))
|
||||
return;
|
||||
|
||||
var entity = mob.EntityManager.SpawnEntity(Prototype, mob.Transform.Coordinates);
|
||||
|
||||
if (!entity.TryGetComponent(out ItemComponent? item) || !mob.TryGetComponent(out HandsComponent? hands))
|
||||
return;
|
||||
|
||||
hands.PutInHand(item, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Holiday.Interfaces;
|
||||
using Content.Server.Items;
|
||||
using Content.Shared.Roles;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Jobs
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class JanitorSpecial : JobSpecial
|
||||
{
|
||||
[DataField("holiday")] private readonly string _holiday = string.Empty;
|
||||
[DataField("prototype")] private readonly string _prototype = string.Empty;
|
||||
|
||||
public override void AfterEquip(IEntity mob)
|
||||
{
|
||||
base.AfterEquip(mob);
|
||||
|
||||
if (string.IsNullOrEmpty(_holiday) || string.IsNullOrEmpty(_prototype)) return;
|
||||
if (!IoCManager.Resolve<IHolidayManager>().IsCurrentlyHoliday(_holiday)) return;
|
||||
|
||||
var item = mob.EntityManager.SpawnEntity(_prototype, mob.Transform.Coordinates);
|
||||
if (!item.TryGetComponent(out ItemComponent? itemComp)) return;
|
||||
if (!mob.TryGetComponent(out HandsComponent? handsComponent)) return;
|
||||
handsComponent.PutInHand(itemComp, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user