Skip to content

Commit

Permalink
Add camouflage to Marine weapons, armor, and equipment (RMC-14#5054)
Browse files Browse the repository at this point in the history
Co-authored-by: DrSmugleaf <[email protected]>
  • Loading branch information
MACMAN2003 and DrSmugleaf authored Dec 13, 2024
1 parent 4f6849e commit fc1fee9
Show file tree
Hide file tree
Showing 3,014 changed files with 21,420 additions and 491 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
9 changes: 9 additions & 0 deletions Content.Server/_RMC14/NamedItems/RMCNamedItemComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Server._RMC14.NamedItems;

[RegisterComponent]
[Access(typeof(RMCNamedItemSystem))]
public sealed partial class RMCNamedItemComponent : Component
{
[DataField, AutoNetworkedField]
public string Name = string.Empty;
}
34 changes: 29 additions & 5 deletions Content.Server/_RMC14/NamedItems/RMCNamedItemSystem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Linq;
using Content.Server._RMC14.LinkAccount;
using Content.Server.Administration.Logs;
using Content.Shared._RMC14.Item;
using Content.Shared._RMC14.NamedItems;
using Content.Shared._RMC14.Sentry;
using Content.Shared._RMC14.Vendors;
using Content.Shared.Database;
using Content.Shared.GameTicking;
using Content.Shared.NameModifier.EntitySystems;
using Content.Shared.Storage;

namespace Content.Server._RMC14.NamedItems;
Expand All @@ -14,7 +16,7 @@ public sealed class RMCNamedItemSystem : EntitySystem
{
[Dependency] private readonly IAdminLogManager _adminLogs = default!;
[Dependency] private readonly LinkAccountManager _linkAccount = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly NameModifierSystem _nameModifier = default!;

private EntityQuery<RMCNameItemOnVendComponent> _nameItemOnVendQuery;

Expand All @@ -26,6 +28,9 @@ public override void Initialize()

SubscribeLocalEvent<RMCUserNamedItemsComponent, RMCAutomatedVendedUserEvent>(OnAutomatedVenderUser);
SubscribeLocalEvent<RMCNameItemOnVendComponent, SentryUpgradedEvent>(OnSentryUpgraded);

SubscribeLocalEvent<RMCNamedItemComponent, ItemCamouflageEvent>(OnItemCamouflage);
SubscribeLocalEvent<RMCNamedItemComponent, RefreshNameModifiersEvent>(OnItemRefreshNameModifiers);
}

private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent ev)
Expand Down Expand Up @@ -69,6 +74,22 @@ private void OnSentryUpgraded(Entity<RMCNameItemOnVendComponent> ent, ref Sentry
NameItem(args.User, args.NewSentry, name);
}

private void OnItemCamouflage(Entity<RMCNamedItemComponent> ent, ref ItemCamouflageEvent args)
{
if (!TryComp(args.Old, out RMCNamedItemComponent? old))
return;

var namedNew = EnsureComp<RMCNamedItemComponent>(args.New);
namedNew.Name = old.Name;

_nameModifier.RefreshNameModifiers(args.New);
}

private void OnItemRefreshNameModifiers(Entity<RMCNamedItemComponent> ent, ref RefreshNameModifiersEvent args)
{
args.AddModifier("rmc-patron-named-item", extraArgs: ("name", ent.Comp.Name));
}

private bool TryNameItem(Entity<RMCUserNamedItemsComponent> ent, Entity<RMCNameItemOnVendComponent> item)
{
var names = ent.Comp.Names;
Expand Down Expand Up @@ -109,16 +130,19 @@ private bool TryNameItem(Entity<RMCUserNamedItemsComponent> ent, Entity<RMCNameI
return true;
}

private bool NameItem(EntityUid player, EntityUid item, string? name)
private void NameItem(EntityUid player, EntityUid item, string? name)
{
if (string.IsNullOrWhiteSpace(name))
return false;
return;

name = name.Trim();
var metaData = MetaData(item);
var newName = $"'{name}' {metaData.EntityName}";
_metaData.SetEntityName(item, newName, metaData);

var named = EnsureComp<RMCNamedItemComponent>(item);
named.Name = name;
_nameModifier.RefreshNameModifiers(item);

_adminLogs.Add(LogType.RMCNamedItem, $"{ToPrettyString(player):player} named item {ToPrettyString(item):item} with name {newName}");
return true;
}
}
19 changes: 19 additions & 0 deletions Content.Server/_RMC14/Rules/CMDistressSignalRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Content.Shared._RMC14.Bioscan;
using Content.Shared._RMC14.CCVar;
using Content.Shared._RMC14.Dropship;
using Content.Shared._RMC14.Item;
using Content.Shared._RMC14.Map;
using Content.Shared._RMC14.Marines;
using Content.Shared._RMC14.Marines.HyperSleep;
Expand Down Expand Up @@ -83,6 +84,7 @@ public sealed class CMDistressSignalRuleSystem : GameRuleSystem<CMDistressSignal
[Dependency] private readonly GunIFFSystem _gunIFF = default!;
[Dependency] private readonly XenoHiveSystem _hive = default!;
[Dependency] private readonly HungerSystem _hunger = default!;
[Dependency] private readonly ItemCamouflageSystem _camo = default!;
[Dependency] private readonly SharedJobSystem _job = default!;
[Dependency] private readonly MarineSystem _marines = default!;
[Dependency] private readonly MindSystem _mind = default!;
Expand Down Expand Up @@ -224,6 +226,8 @@ private void OnRulePlayerSpawning(RulePlayerSpawningEvent ev)

SetFriendlyHives(comp.Hive);

SetCamoType();

SpawnSquads((uid, comp));
SpawnAdminFaxArea();

Expand Down Expand Up @@ -557,6 +561,21 @@ private void SpawnSquads(Entity<CMDistressSignalRuleComponent> rule)
}
}

public void SetCamoType(CamouflageType? ct = null)
{
if (ct != null)
{
_camo.CurrentMapCamouflage = ct.Value;
return;
}

if (SelectedPlanetMap != null &&
_rmcPlanet.PlanetPaths.TryGetValue(SelectedPlanetMap, out var planet))
{
_camo.CurrentMapCamouflage = planet.Camouflage;
}
}

private void OnPlayerSpawning(PlayerSpawningEvent ev)
{
if (ev.Job is not { } jobId ||
Expand Down
23 changes: 23 additions & 0 deletions Content.Shared/_RMC14/Item/ItemCamouflageComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;

namespace Content.Shared._RMC14.Item;

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class ItemCamouflageComponent : Component
{
//you have to add a prototype for each camo type.
[DataField(required: true), AutoNetworkedField]
public Dictionary<CamouflageType, EntProtoId> CamouflageVariations = new();
}

[Serializable, NetSerializable]
public enum CamouflageType : byte
{
Jungle = 1, //default
Desert = 2,
Snow = 3,
Classic = 4,
Urban = 5,
}
4 changes: 4 additions & 0 deletions Content.Shared/_RMC14/Item/ItemCamouflageEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Shared._RMC14.Item;

[ByRefEvent]
public readonly record struct ItemCamouflageEvent(EntityUid Old, EntityUid New);
104 changes: 104 additions & 0 deletions Content.Shared/_RMC14/Item/ItemCamouflageSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Robust.Shared.Containers;
using Robust.Shared.Network;
using Robust.Shared.Timing;

namespace Content.Shared._RMC14.Item;

public sealed class ItemCamouflageSystem : EntitySystem
{
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedContainerSystem _cont = default!;
[Dependency] private readonly IGameTiming _time = default!;

[ViewVariables(VVAccess.ReadWrite)]
public CamouflageType CurrentMapCamouflage { get; set; } = CamouflageType.Jungle;

private readonly Queue<Entity<ItemCamouflageComponent>> _items = new();

public override void Initialize()
{
SubscribeLocalEvent<ItemCamouflageComponent, MapInitEvent>(OnMapInit);
}

//thank you smugleaf!
public override void Update(float frameTime)
{
if (_items.Count == 0)
return;

foreach (var ent in _items)
{
if (!TryComp(ent.Owner, out MetaDataComponent? meta))
continue;

if (meta.LastModifiedTick == _time.CurTick)
continue;

Replace(ent);
_items.Dequeue();
break;
}
}

private void Replace(Entity<ItemCamouflageComponent> ent)
{
if (_net.IsClient)
return;

switch (CurrentMapCamouflage)
{
case CamouflageType.Jungle:
ReplaceWithCamouflaged(ent, CamouflageType.Jungle);
break;
case CamouflageType.Desert:
ReplaceWithCamouflaged(ent, CamouflageType.Desert);
break;
case CamouflageType.Snow:
ReplaceWithCamouflaged(ent, CamouflageType.Snow);
break;
case CamouflageType.Classic:
ReplaceWithCamouflaged(ent, CamouflageType.Classic);
break;
case CamouflageType.Urban:
ReplaceWithCamouflaged(ent, CamouflageType.Urban);
break;
}
}

private void OnMapInit(Entity<ItemCamouflageComponent> ent, ref MapInitEvent args)
{
if (_net.IsClient)
return;

_items.Enqueue(ent);
}

private void ReplaceWithCamouflaged(Entity<ItemCamouflageComponent> ent, CamouflageType type)
{
if (!ent.Comp.CamouflageVariations.TryGetValue(type, out var spawn))
{
Log.Error($"No {type} camouflage variation found for {ToPrettyString(ent)}");
return;
}

EntityUid newEnt;
if (_cont.IsEntityInContainer(ent.Owner))
{
_cont.TryGetContainingContainer((ent.Owner, null), out var cont);
if (cont == null)
return;

_cont.Remove(ent.Owner, cont, true, true);
newEnt = SpawnInContainerOrDrop(spawn, cont.Owner, cont.ID);
}
else
{
newEnt = SpawnNextToOrDrop(ent.Comp.CamouflageVariations[type], ent.Owner);
}

var ev = new ItemCamouflageEvent(ent, newEnt);
RaiseLocalEvent(ent, ref ev);

QueueDel(ent.Owner);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Robust.Shared.GameStates;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
using Content.Shared._RMC14.Item;

namespace Content.Shared._RMC14.Rules;

Expand All @@ -10,6 +11,9 @@ public sealed partial class RMCPlanetMapPrototypeComponent : Component
[DataField(required: true), AutoNetworkedField]
public ResPath Map;

[DataField, AutoNetworkedField]
public CamouflageType Camouflage = CamouflageType.Jungle;

[DataField(required: true), AutoNetworkedField]
public string Announcement = string.Empty;
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/_RMC14/rmc-patron.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rmc-patron-named-item = '{$name}' {$baseName}
Loading

0 comments on commit fc1fee9

Please sign in to comment.