Skip to content

Commit

Permalink
Настраиваемые турели (#174)
Browse files Browse the repository at this point in the history
* Start

* Done
  • Loading branch information
FireNameFN authored Dec 20, 2024
1 parent 1b7c8ca commit d6b89e7
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Content.Shared/Verbs/VerbCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@ public VerbCategory(string text, string? icon, bool iconsOnly = false)
public static readonly VerbCategory SelectType = new("verb-categories-select-type", null);

public static readonly VerbCategory PowerLevel = new("verb-categories-power-level", null);

public static readonly VerbCategory TurretControlMode = new("verb-categories-turret-control-mode", null); // Corvax-Next-TurretControl
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Shared._CorvaxNext.TurretControl;

[RegisterComponent]
public sealed partial class TurretControlComponent : Component;
64 changes: 64 additions & 0 deletions Content.Shared/_CorvaxNext/TurretControl/TurretControlSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Content.Shared.NPC.Components;
using Content.Shared.NPC.Prototypes;
using Content.Shared.NPC.Systems;
using Content.Shared.Tag;
using Content.Shared.Verbs;

namespace Content.Shared._CorvaxNext.TurretControl;

public sealed class TurretControlSystem : EntitySystem
{
[Dependency] private readonly NpcFactionSystem _faction = default!;
[Dependency] private readonly TagSystem _tag = default!;

[ValidatePrototypeId<TagPrototype>]
private const string ControlTag = "StationAi";

[ValidatePrototypeId<NpcFactionPrototype>]
private const string Passive = "TurretPassive";

[ValidatePrototypeId<NpcFactionPrototype>]
private const string Peace = "TurretPeace";

[ValidatePrototypeId<NpcFactionPrototype>]
private const string Hostile = "TurretHostile";

public override void Initialize()
{
SubscribeLocalEvent<TurretControlComponent, GetVerbsEvent<Verb>>(OnGetVerbs);
}

private void OnGetVerbs(Entity<TurretControlComponent> entity, ref GetVerbsEvent<Verb> e)
{
if (!_tag.HasTag(e.User, ControlTag))
return;

if (!TryComp<NpcFactionMemberComponent>(entity, out var factionMember))
return;

e.Verbs.Add(CreateVerb((entity, factionMember), "turret-control-mode-nobody", Passive, 3));
e.Verbs.Add(CreateVerb((entity, factionMember), "turret-control-mode-hostile", Peace, 2));
e.Verbs.Add(CreateVerb((entity, factionMember), "turret-control-mode-everybody", Hostile, 1));
}

private Verb CreateVerb(Entity<NpcFactionMemberComponent?> entity, string text, string faction, int priority)
{
return new()
{
Text = Loc.GetString(text),
Disabled = _faction.IsMember(entity, faction),
Category = VerbCategory.TurretControlMode,
Priority = priority,
Act = () => SetFaction(entity, faction)
};
}

private void SetFaction(Entity<NpcFactionMemberComponent?> entity, string faction)
{
_faction.RemoveFaction(entity, Passive);
_faction.RemoveFaction(entity, Peace);
_faction.RemoveFaction(entity, Hostile);

_faction.AddFaction(entity, faction);
}
}
3 changes: 3 additions & 0 deletions Resources/Locale/ru-RU/_corvaxnext/turret-control.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
turret-control-mode-nobody = Никто
turret-control-mode-hostile = Враждебные
turret-control-mode-everybody = Все
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/_corvaxnext/verbs.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
verb-categories-turret-control-mode = Задать цель
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ent-WeaponTurretControl = { ent-BaseWeaponTurret }
.desc = { ent-BaseWeaponTurret.desc }
.suffix = Управляемая
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- type: entity
parent: BaseWeaponTurret
id: WeaponTurretControl
suffix: Control
components:
- type: NpcFactionMember
factions:
- TurretPeace
- type: TurretControl
24 changes: 24 additions & 0 deletions Resources/Prototypes/_CorvaxNext/ai_factions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- type: npcFaction
id: TurretPassive

- type: npcFaction
id: TurretPeace
hostile:
- Dragon
- SimpleHostile
- Xeno

- type: npcFaction
id: TurretHostile
hostile:
- Dragon
- NanoTrasen
- Mouse
- Passive
- PetsNT
- SimpleHostile
- SimpleNeutral
- Syndicate
- Xeno
- Zombie
- Revolutionary

0 comments on commit d6b89e7

Please sign in to comment.