Improves the JobSpecial system. (#4626)
* Improves the JobSpecial system. * clean up code
This commit is contained in:
committed by
GitHub
parent
4fffb3c582
commit
078a62762f
@@ -1,12 +0,0 @@
|
|||||||
using Content.Shared.Roles;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
|
|
||||||
namespace Content.Client.Jobs
|
|
||||||
{
|
|
||||||
[UsedImplicitly]
|
|
||||||
public sealed class ClownSpecial : JobSpecial
|
|
||||||
{
|
|
||||||
// Dummy class that exists solely to avoid an exception on the client,
|
|
||||||
// but allow the server-side counterpart to exist.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using Content.Shared.Roles;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
|
|
||||||
namespace Content.Client.Jobs
|
|
||||||
{
|
|
||||||
[UsedImplicitly]
|
|
||||||
public class JanitorSpecial : JobSpecial
|
|
||||||
{
|
|
||||||
// Dummy class that exists solely to avoid an exception on the client,
|
|
||||||
// but allow the server-side counterpart to exist.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -97,7 +97,11 @@ namespace Content.Server.GameTicking
|
|||||||
AddManifestEntry(character.Name, jobId);
|
AddManifestEntry(character.Name, jobId);
|
||||||
AddSpawnedPosition(jobId);
|
AddSpawnedPosition(jobId);
|
||||||
EquipIdCard(mob, character.Name, jobPrototype);
|
EquipIdCard(mob, character.Name, jobPrototype);
|
||||||
jobPrototype.Special?.AfterEquip(mob);
|
|
||||||
|
foreach (var jobSpecial in jobPrototype.Special)
|
||||||
|
{
|
||||||
|
jobSpecial.AfterEquip(mob);
|
||||||
|
}
|
||||||
|
|
||||||
Preset?.OnSpawnPlayerCompleted(player, mob, lateJoin);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -50,8 +50,8 @@ namespace Content.Shared.Roles
|
|||||||
|
|
||||||
[DataField("icon")] public string Icon { get; } = string.Empty;
|
[DataField("icon")] public string Icon { get; } = string.Empty;
|
||||||
|
|
||||||
[DataField("special")]
|
[DataField("special", serverOnly:true)]
|
||||||
public JobSpecial? Special { get; private set; }
|
public JobSpecial[] Special { get; private set; } = Array.Empty<JobSpecial>();
|
||||||
|
|
||||||
[DataField("departments")]
|
[DataField("departments")]
|
||||||
public IReadOnlyCollection<string> Departments { get; } = Array.Empty<string>();
|
public IReadOnlyCollection<string> Departments { get; } = Array.Empty<string>();
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ namespace Content.Shared.Roles
|
|||||||
[ImplicitDataDefinitionForInheritors]
|
[ImplicitDataDefinitionForInheritors]
|
||||||
public abstract class JobSpecial
|
public abstract class JobSpecial
|
||||||
{
|
{
|
||||||
public virtual void AfterEquip(IEntity mob)
|
public abstract void AfterEquip(IEntity mob);
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
access:
|
access:
|
||||||
- Theatre
|
- Theatre
|
||||||
- Maintenance
|
- Maintenance
|
||||||
special: !type:ClownSpecial {}
|
special:
|
||||||
|
- !type:AddComponentSpecial
|
||||||
|
component: Clumsy # Adds ClumsyComponent to the mob.
|
||||||
|
|
||||||
- type: startingGear
|
- type: startingGear
|
||||||
id: ClownGear
|
id: ClownGear
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
- Janitor
|
- Janitor
|
||||||
- Maintenance
|
- Maintenance
|
||||||
special:
|
special:
|
||||||
!type:JanitorSpecial
|
- !type:GiveItemOnHolidaySpecial
|
||||||
holiday: GarbageDay
|
holiday: GarbageDay
|
||||||
prototype: RevolverInspector
|
prototype: RevolverInspector
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user