forked from RMC-14/RMC-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add camouflage to Marine weapons, armor, and equipment (RMC-14#5054)
Co-authored-by: DrSmugleaf <[email protected]>
- Loading branch information
1 parent
4f6849e
commit fc1fee9
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rmc-patron-named-item = '{$name}' {$baseName} |
Oops, something went wrong.