Skip to content

Commit

Permalink
Merge pull request #500 from Timfa2112/gladiabot-teams
Browse files Browse the repository at this point in the history
Gladiabot Teams
  • Loading branch information
FoxxoTrystan authored Jan 24, 2025
2 parents 55dacf3 + 8b764d4 commit 51bf7f1
Show file tree
Hide file tree
Showing 18 changed files with 232 additions and 4 deletions.
25 changes: 25 additions & 0 deletions Content.Client/NPC/Systems/NpcFactionSpriteStateSetterSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

using Content.Shared.NPC.Components;
using Content.Shared.NPC.Events;
using Robust.Client.GameObjects;

namespace Content.Client.NPC.Systems;
public sealed partial class NpcFactionSpriteStateSetterSystem : EntitySystem
{

public override void Initialize()
{
base.Initialize();

SubscribeNetworkEvent<NpcFactionAddedEvent>(OnFactionAdded);
}

private void OnFactionAdded(NpcFactionAddedEvent ev)
{
if (!TryGetEntity(ev.EntityUid, out var entity) || !TryComp<SpriteComponent>(entity.Value, out var sprite) || !TryComp<NpcFactionSpriteStateSetterComponent>(entity.Value, out var _)|| !TryComp<NpcFactionSelectorComponent>(entity.Value, out var factionSelector))
return;

if(factionSelector.SelectableFactions.Contains(ev.FactionID))
sprite.LayerSetState(0, new (ev.FactionID));
}
}
59 changes: 59 additions & 0 deletions Content.Server/NPC/Systems/NpcFactionSelectorSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Content.Server.NPC.Components;
using Content.Shared.Database;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Robust.Shared.Prototypes;
using System.Linq;
using Content.Shared.NPC.Components;


namespace Content.Server.NPC.Systems;
public sealed partial class NpcFactionSelectorSystem : EntitySystem
{

[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly NpcFactionSystem _factionSystem = default!;
[Dependency] private readonly EntityManager _entityManager = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<NpcFactionSelectorComponent, GetVerbsEvent<Verb>>(OnGetVerb);
}

private void OnGetVerb(Entity<NpcFactionSelectorComponent> entity, ref GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
return;

if (!TryComp<NpcFactionSelectorComponent>(entity, out var factionSelectorComponent) || factionSelectorComponent.SelectableFactions.Count < 2)
return;

foreach (var type in factionSelectorComponent.SelectableFactions)
{
var proto = _prototype.Index<NpcFactionPrototype>(type);

var v = new Verb
{
Priority = 1,
Category = VerbCategory.SelectFaction,
Text = proto.ID,
Impact = LogImpact.Medium,
DoContactInteraction = true,
Act = () =>
{
_popup.PopupPredicted(Loc.GetString("npcfaction-component-faction-set", ("faction", proto.ID)), entity.Owner, null);
foreach (var type in factionSelectorComponent.SelectableFactions)
{
_factionSystem.RemoveFaction(entity.Owner, type);
}

_factionSystem.AddFaction(entity.Owner, proto.ID);
}
};
args.Verbs.Add(v);
}
}
}
9 changes: 8 additions & 1 deletion Content.Server/NPC/Systems/NpcFactionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.NPC.Events;
using System.Collections.Frozen;
using System.Linq;
using Content.Server.NPC.Components;
Expand All @@ -8,7 +9,7 @@ namespace Content.Server.NPC.Systems;

/// <summary>
/// Outlines faction relationships with each other.
/// part of psionics rework was making this a partial class. Should've already been handled upstream, based on the linter.
/// part of psionics rework was making this a partial class. Should've already been handled upstream, based on the linter.
/// </summary>
public sealed partial class NpcFactionSystem : EntitySystem
{
Expand Down Expand Up @@ -76,6 +77,9 @@ public void AddFaction(EntityUid uid, string faction, bool dirty = true)
if (!comp.Factions.Add(faction))
return;

if(TryGetNetEntity(uid, out var netEntity)) // Floofstation
RaiseNetworkEvent(new NpcFactionAddedEvent(netEntity.Value, faction));

if (dirty)
{
RefreshFactions(comp);
Expand All @@ -99,6 +103,9 @@ public void RemoveFaction(EntityUid uid, string faction, bool dirty = true)
if (!component.Factions.Remove(faction))
return;

if(_lookup.TryGetNetEntity(uid, out var netEntity))
RaiseNetworkEvent(new NpcFactionRemovedEvent(netEntity.Value, faction));

if (dirty)
{
RefreshFactions(component);
Expand Down
35 changes: 35 additions & 0 deletions Content.Shared/NPC/Events/NpcFactionChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Robust.Shared.Serialization;

namespace Content.Shared.NPC.Events;

/// <summary>
/// Raised from client to server to notify a faction was added to an NPC.
/// </summary>
[Serializable, NetSerializable]
public sealed class NpcFactionAddedEvent : EntityEventArgs
{
public readonly string FactionID;
public readonly NetEntity EntityUid;

public NpcFactionAddedEvent(NetEntity entity, string factionId)
{
FactionID = factionId;
EntityUid = entity;
}
}

/// <summary>
/// Raised from client to server to notify a faction was removed from an NPC.
/// </summary>
[Serializable, NetSerializable]
public sealed class NpcFactionRemovedEvent : EntityEventArgs
{
public readonly string FactionID;
public readonly NetEntity EntityUid;

public NpcFactionRemovedEvent(NetEntity entity, string factionId)
{
FactionID = factionId;
EntityUid = entity;
}
}
9 changes: 9 additions & 0 deletions Content.Shared/NPC/NpcFactionSelectorComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Shared.NPC.Components;

[RegisterComponent]
public sealed partial class NpcFactionSelectorComponent : Component
{
[DataField]
public List<string> SelectableFactions = new();
}

7 changes: 7 additions & 0 deletions Content.Shared/NPC/NpcFactionSpriteStateSetterComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Robust.Shared.GameStates;

namespace Content.Shared.NPC.Components;

[RegisterComponent]
public sealed partial class NpcFactionSpriteStateSetterComponent : Component {}

2 changes: 2 additions & 0 deletions Content.Shared/Verbs/VerbCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,7 @@ public VerbCategory(string text, string? icon, bool iconsOnly = false)
public static readonly VerbCategory Interaction = new("verb-categories-interaction", null);

public static readonly VerbCategory Vore = new("verb-categories-vore", null); // Floofstation

public static readonly VerbCategory SelectFaction = new("verb-categories-select-faction", null); // Floofstation
}
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/npc/factions.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npcfaction-component-faction-set = Faction set to: {$faction}
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/verbs/verb-system.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ verb-categories-set-sensor = Sensor
verb-categories-timer = Set Delay
verb-categories-lever = Lever
verb-categories-select-type = Select Type
verb-categories-select-faction = Select Faction
verb-categories-fax = Set Destination
verb-categories-power-level = Power Level
verb-categories-interaction = Interact
verb-categories-blood-cult = Blood Cult
verb-common-toggle-light = Toggle light
verb-common-close = Close
Expand Down
10 changes: 9 additions & 1 deletion Resources/Prototypes/Entities/Mobs/NPCs/gladiabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
components:
- type: Sprite
sprite: Mobs/Silicon/Bots/gladiabot.rsi
state: gladiabot
state: GladiabotFFA
- type: Inventory
templateId: gladiabot
- type: InventorySlots
Expand All @@ -26,6 +26,14 @@
- type: NpcFactionMember
factions:
- GladiabotFFA
- type: NpcFactionSelector
selectableFactions:
- GladiabotFFA
- GladiabotRed
- GladiabotBlue
- GladiabotGreen
- GladiabotYellow
- type: NpcFactionSpriteStateSetter
- type: CombatMode
- type: MeleeWeapon
altDisarm: false
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/Recipes/Crafting/bots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
description: This bot fights for honour and glory!
icon:
sprite: Mobs/Silicon/Bots/gladiabot.rsi
state: gladiabot
state: GladiabotFFA
37 changes: 37 additions & 0 deletions Resources/Prototypes/ai_factions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,40 @@
id: GladiabotFFA
hostile:
- GladiabotFFA
- GladiabotRed
- GladiabotGreen
- GladiabotBlue
- GladiabotYellow

- type: npcFaction
id: GladiabotRed
hostile:
- GladiabotFFA
- GladiabotGreen
- GladiabotBlue
- GladiabotYellow

- type: npcFaction
id: GladiabotGreen
hostile:
- GladiabotFFA
- GladiabotRed
- GladiabotBlue
- GladiabotYellow

- type: npcFaction
id: GladiabotBlue
hostile:
- GladiabotFFA
- GladiabotRed
- GladiabotGreen
- GladiabotYellow

- type: npcFaction
id: GladiabotYellow
hostile:
- GladiabotFFA
- GladiabotRed
- GladiabotGreen
- GladiabotBlue

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 37 additions & 1 deletion Resources/Textures/Mobs/Silicon/Bots/gladiabot.rsi/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,43 @@
"copyright": "Tim Falken",
"states": [
{
"name": "gladiabot",
"name": "GladiabotFFA",
"delays": [
[
0.5,
0.2
]
]
},
{
"name": "GladiabotRed",
"delays": [
[
0.5,
0.2
]
]
},
{
"name": "GladiabotGreen",
"delays": [
[
0.5,
0.2
]
]
},
{
"name": "GladiabotBlue",
"delays": [
[
0.5,
0.2
]
]
},
{
"name": "GladiabotYellow",
"delays": [
[
0.5,
Expand Down

0 comments on commit 51bf7f1

Please sign in to comment.