* initial commit - species prototype modifications - markings points as its own file - shared humanoid component * adds a tool to convert sprite accessories to markings (in go) * removes a fmt call * converts sprite accessory to markings * adds hair and facial hair to marking categories * multiple changes - humanoid visualizer system - markings modifications for visualizer - modifications to shared humanoid component - lays out a base for humanoid system * hidden layers, ports some properties from appearance component, shrinks DefaultMarkings a little * squishes the initialize event calls into one function adds stuff to set species/skin color externally from a server message - currently laid out as if it a dirty call to a networked component, may be subject to change (server-side has not been implemented yet) * makes the sprite pipeline more obvious * apply all markings, hidden layer set replacement * ensures that markings are cleared when the new set is applied * starts refactoring markingsset (unfinished) * more additions to the markingset api * adds constructor logic to markingset * adds a method to filter out markings in a set based on a given species * fixes enumerators in markingset * adds validator into MarkingSet, fixes ForwardMarkingEnumerator * modifications to the humanoid visual system * ensuredefault in markingset * oop * fixes up data keys, populates OnAppearanceChange in visualizer * changes to humanoid component, markings marking equality is now more strict, humanoidcomponent is now implemented for client as a child of sharedhumanoidcomponent * markings are now applied the visualizer by diffing them * base sprites are now applied to humanoids from humanoidvisualizer * passes along base sprite settings to the marking application so that markings know to follow skin color/alpha or not (see: slimes) * custom base layers on humanoids * merges all data keys into one data class for humanoid visualizers * setappearance in sharedhumanoidsystem, removes custombaselayercolors * humanoidcomponent, system (empty) in server * adds some basic public API functions to HumanoidSystem * add marking, remove marking * changes appearance MarkingsSet to a List<Marking>, adds listener for PlayerSpawnCompleteEvent in HumanoidSystem * ensuredefaultmarkings, oninit for humanoids * markingmanager API changes * removes MarkingsSet * LoadProfile, adjusts randomization in humanoid appearance to account for species * base layer settings in humanoidsystem, eye color from profile * rearranges files to centralize under Humanoid namespace * more reorganization, deletes some stuff gotta break stuff to make other things work, right? goodbye SpriteAccessory... * fixes a good chunk of server-side issues still does not compile, yet * singlemarkingpicker xaml layout * singlemarkingpicker logic * magic mirror window (varying pieces of it, mostly client-oriented) * removes some imports, gives MagicMirror a BUI class (not filled in yet) * populates magic mirror BUI functionality / window callbacks * fixes up some errors in humanoidprofileeditor * changes to SingleMarkingPicker SingleMarkingPicker now accepts a List<Marking>, species, and total possible markings available in that marking category * fixes up hair pickers on humanoid profile editor * fixes the errors in markingpicker * markingsystem is now gone * fixes a bunch of build errors * so that's why i did it like that * namespace issues, adds robustxamlloader to singlemarkingpicker * another robustxamlloader * human, lizard sprites/points * prototype fixes, deletion of old spriteaccessory * component registration, fixes dwarf skin toning no, 'ReptilianToned' does not exist * removes component registration from abstract humanoid component * visualizer data now cloneable * serialize for visualizer key * zero-count edge case * missing semi-colon moment * setspecies in humanoidsystem * ensures that default markings, if empty, will cause ensuredefault to skip over that given category * tryadd instead of add * whoops * diff and apply should properly apply markings now * always ensure default, fixes double load for player spawning * apply skin color now sets the skin color property in humanoidcomponent * removes sprite from a few species prototypes * sprite changes for specific base layers based on humanoid sex * layer ordering fix, and a missing base layer should now disallow markings on that layer * anymarking base layer, adds the right leg/foot for humans * loading a profile will now clear all markings on that humanoid * adds missing layers for humans * separates species.yml into respective species prototype files * ensures that if layer visibility was changed, all markings have to be reapplied * server-side enforcement of hiding hair (and other head-related markings) when equipping things that hide hair * slime fix, clothingsystem now dictates layer visibility server side * sussy * layer settings should now ensure a marking should match the skin tone * whoops * skincolor static class and functions in UI * skin color validation in humanoidcharacterappearance * markingpicker now shows only the markings for the selected category in used * getter for slot in singlemarkingpicker now ensures slot is 0 if markings exists * FilterSpecies no longer attempts to do removal while iterating * expands for SingleMarkingPicker * humanoid base dummy has blank layers now (and snout/tail/headside/headtop) * fixes an issue with visualizer system if the marking count was different but the markings themselves were (somewhat) the same * whoops * adds edge case handlers for count differences in humanoid markings * preview now loads profile instead of directly setting appearance * moves marking set loading to update controls * clones a marking set in markingpicker by using the deep clone constructor * whoops (deep cloning a marking now copies the marking id) * adds replace function for markingset * points should now update after the markings are remove/added * merging base layer sprites into a humanoid should now clear them before merging * sets dirty range start to count only if the dirty range start was never set above 0 * fixes up some issues with singlemarkingpicker * color selector sliders in single marking picker should now expand * hair from hair pickers should now apply in profile loading (client-side) * category in singlemarkingpicker now sets the private category variable * slot selector should now populate * single marking picker buttons now have text, also shows the category name over all user-clickable elements * removes a comment * removing hair slots now sets it to bald, defaults to zero used slots if current hair is bald on hair/facial hair * random skin color, eye color * populate colors now checks if the marking count is greater than zero in singlemarkingpicker * hair/facial hair pickers now just get the first possible hair from the respective species list * different approach to random skin color * oh, that's why it wasn't working * randomize everything now just updates every single control * selecting a new marking in SingleMarkingPicker should attempt to copy over old colors, populate list now uses cache, * markingmanager now uses OnlyWhitelisted to populate by category and species * filterspecies now uses onlyWhitelist to filter markings based on whitelist or not * oops * ui fix for singlemarkingpicker, ensures that cache is not null if it is null when populatelist is called * order of operations for the horizontal expand for add/remove * hair pickers should now update when you add/remove the hair slot * fixes variable naming error in character appearance * loc string fix in singlemarkingpicker * lizards, vox now have onlyWhitelist, vox restriction for hair/facialhairs * having zero possible hairs should no longer cause an exception in randomization * setting species should now update hair pickers * ignore categories for marking picker * and a clear as well for the category button * places that functionality in its own function instead * adds eye base sprite, vox now also have their own custom eye sprites * loading a profile client-side should do FilterSpecies for markings now * client-side load profile does filter species after adding in the hairs now * magic mirror * callbacks now call the callback instead of adding it on construct * whoops * in removemarking too * adds missing synchronize calls * comments out an updateinterface call in magic mirror * magic mirror window title, minimum sizing * fixes minsize, adds warning for players who try to set their hair for species that have no hair * removes spaces in xaml * namespace changes/organization * whoopsie (merge conflicts) * re-enables identity from humanoid component * damagevisuals now uses the enum given to it instead of the layerstate given on that layer tied to the enum * removes commas from json * changes to visuals system so the change is consistent * chest * reptilian * visualizer system now handles body sprite setting/coloration, similar to how characterappearance did it not a big fan of this * adds a check in applybasesprites * adding/removing parts should now make them invisible on a humanoid * body part removal/adding now enumerates over sublayers instead * synchro now runs in bodycomponent startup * parts instead of slots * humanoidcompnent check * switches from rsi to actualrsi * removes all the body stuff (too slow) * cleans up resolves from humanoid visualizer system * merging sprites now checks if the base sprites have been modified or not (through things like species changes, or custom base sprite changes) * not forgetting that one again * merging now returns an actual dirty value * replaces the sequenceequal with a more accurate solution * permanent layers, layer visibility on add/remove part in body * should send all hidden layers over now * isdirty in visualizer system for base layers * isdirty checks count as well * ok, IsDirty should now set the base layers if the merged sprites are different * equals override in HumanoidSpritePrototypes.cs temporary until record prototypes :heck: * makes fields readonly, equates IDs instead * adds forced markings through marking picker * forced in humanoidsystem api, ignorespecies in markingpicker * marking bui * makes that serializable as well * ignore species/forced toggles now work * adds icon to modifier verb, interface and keys to humanoid bases * needs the actual enum value to open, no? * makes the key the actual key * actions now propagate upwards * ignore species when set now repopulates markingpicker * modifiable base layers in the markings window * oops! * layout changes * info box should now appear * adds ignorespecies for marking picker, collapsible for base layer section of appearance modification window * collapsible layout moment * if base layers have changed, all markings are now dirty (and if a base layer is missing, the marking is still 'applied' but it's now just invisible * small change to marking visibility * small changes to modifier UI * markings now match skin on zombification * zombie stuff * makes the line edit in marking modifier window more obvious * disables vox on round start * horizontal expand on the single label in base layer modifiers * humanoid profiles in prototypes * randomhumanoidappearance won't work if the humanoid has a profile already stored * removes unused code * documentation in humanoidsystem server-side * documentation in shared/client * whoops * converts accessory into marking in locale files (also adds marking loc string into single marking picker) * be gone, shared humanoid appearance system from the last upstream merge * species ignore on randomization (defaults to no ignored species) * more upstream merge parts that bypassed any errors before merge * addresses review (also just adds typeserializers in some places) * submodule moment * upstream merge issues
477 lines
18 KiB
C#
477 lines
18 KiB
C#
using System.Linq;
|
|
using Content.Server.GameTicking;
|
|
using Content.Shared.Humanoid;
|
|
using Content.Shared.Humanoid.Markings;
|
|
using Content.Shared.Humanoid.Prototypes;
|
|
using Content.Shared.Inventory.Events;
|
|
using Content.Shared.Preferences;
|
|
using Content.Shared.Tag;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Shared.GameObjects.Components.Localization;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.Humanoid;
|
|
|
|
public sealed partial class HumanoidSystem : SharedHumanoidSystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly MarkingManager _markingManager = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<HumanoidComponent, ComponentInit>(OnInit);
|
|
SubscribeLocalEvent<HumanoidComponent, HumanoidMarkingModifierMarkingSetMessage>(OnMarkingsSet);
|
|
SubscribeLocalEvent<HumanoidComponent, HumanoidMarkingModifierBaseLayersSetMessage>(OnBaseLayersSet);
|
|
SubscribeLocalEvent<HumanoidComponent, GetVerbsEvent<Verb>>(OnVerbsRequest);
|
|
}
|
|
|
|
private void Synchronize(EntityUid uid, HumanoidComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
{
|
|
return;
|
|
}
|
|
|
|
SetAppearance(uid,
|
|
component.Species,
|
|
component.CustomBaseLayers,
|
|
component.SkinColor,
|
|
component.AllHiddenLayers.ToList(),
|
|
component.CurrentMarkings.GetForwardEnumerator().ToList());
|
|
}
|
|
|
|
private void OnInit(EntityUid uid, HumanoidComponent humanoid, ComponentInit args)
|
|
{
|
|
if (string.IsNullOrEmpty(humanoid.Species))
|
|
{
|
|
return;
|
|
}
|
|
|
|
SetSpecies(uid, humanoid.Species, false, humanoid);
|
|
|
|
if (!string.IsNullOrEmpty(humanoid.Initial)
|
|
&& _prototypeManager.TryIndex(humanoid.Initial, out HumanoidProfilePrototype? startingSet))
|
|
{
|
|
// Do this first, because profiles currently do not support custom base layers
|
|
foreach (var (layer, info) in startingSet.CustomBaseLayers)
|
|
{
|
|
humanoid.CustomBaseLayers.Add(layer, info);
|
|
}
|
|
|
|
LoadProfile(uid, startingSet.Profile, humanoid);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loads a humanoid character profile directly onto this humanoid mob.
|
|
/// </summary>
|
|
/// <param name="uid">The mob's entity UID.</param>
|
|
/// <param name="profile">The character profile to load.</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void LoadProfile(EntityUid uid, HumanoidCharacterProfile profile, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
SetSpecies(uid, profile.Species, false, humanoid);
|
|
humanoid.Sex = profile.Sex;
|
|
|
|
SetSkinColor(uid, profile.Appearance.SkinColor, false);
|
|
SetBaseLayerColor(uid, HumanoidVisualLayers.Eyes, profile.Appearance.EyeColor, false);
|
|
|
|
humanoid.CurrentMarkings.Clear();
|
|
|
|
// Hair/facial hair - this may eventually be deprecated.
|
|
|
|
AddMarking(uid, profile.Appearance.HairStyleId, profile.Appearance.HairColor, false);
|
|
AddMarking(uid, profile.Appearance.FacialHairStyleId, profile.Appearance.FacialHairColor, false);
|
|
|
|
foreach (var marking in profile.Appearance.Markings)
|
|
{
|
|
AddMarking(uid, marking.MarkingId, marking.MarkingColors, false);
|
|
}
|
|
|
|
EnsureDefaultMarkings(uid, humanoid);
|
|
|
|
humanoid.Gender = profile.Gender;
|
|
|
|
if (TryComp<GrammarComponent>(uid, out var grammar))
|
|
{
|
|
grammar.Gender = profile.Gender;
|
|
}
|
|
|
|
humanoid.Age = profile.Age;
|
|
|
|
Synchronize(uid);
|
|
}
|
|
|
|
// this was done enough times that it only made sense to do it here
|
|
|
|
/// <summary>
|
|
/// Clones a humanoid's appearance to a target mob, provided they both have humanoid components.
|
|
/// </summary>
|
|
/// <param name="source">Source entity to fetch the original appearance from.</param>
|
|
/// <param name="target">Target entity to apply the source entity's appearance to.</param>
|
|
/// <param name="sourceHumanoid">Source entity's humanoid component.</param>
|
|
/// <param name="targetHumanoid">Target entity's humanoid component.</param>
|
|
public void CloneAppearance(EntityUid source, EntityUid target, HumanoidComponent? sourceHumanoid = null,
|
|
HumanoidComponent? targetHumanoid = null)
|
|
{
|
|
if (!Resolve(source, ref sourceHumanoid) || !Resolve(target, ref targetHumanoid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
targetHumanoid.Species = sourceHumanoid.Species;
|
|
targetHumanoid.SkinColor = sourceHumanoid.SkinColor;
|
|
targetHumanoid.Sex = sourceHumanoid.Sex;
|
|
targetHumanoid.CustomBaseLayers = new(sourceHumanoid.CustomBaseLayers);
|
|
targetHumanoid.CurrentMarkings = new(sourceHumanoid.CurrentMarkings);
|
|
|
|
Synchronize(target, targetHumanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set a humanoid mob's species. This will change their base sprites, as well as their current
|
|
/// set of markings to fit against the mob's new species.
|
|
/// </summary>
|
|
/// <param name="uid">The humanoid mob's UID.</param>
|
|
/// <param name="species">The species to set the mob to. Will return if the species prototype was invalid.</param>
|
|
/// <param name="sync">Whether to immediately synchronize this to the humanoid mob, or not.</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void SetSpecies(EntityUid uid, string species, bool sync = true, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid) || !_prototypeManager.TryIndex<SpeciesPrototype>(species, out var prototype))
|
|
{
|
|
return;
|
|
}
|
|
|
|
humanoid.Species = species;
|
|
humanoid.CurrentMarkings.FilterSpecies(species, _markingManager);
|
|
var oldMarkings = humanoid.CurrentMarkings.GetForwardEnumerator().ToList();
|
|
humanoid.CurrentMarkings = new(oldMarkings, prototype.MarkingPoints, _markingManager, _prototypeManager);
|
|
|
|
if (sync)
|
|
{
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the skin color of this humanoid mob. Will only affect base layers that are not custom,
|
|
/// custom base layers should use <see cref="SetBaseLayerColor"/> instead.
|
|
/// </summary>
|
|
/// <param name="uid">The humanoid mob's UID.</param>
|
|
/// <param name="skinColor">Skin color to set on the humanoid mob.</param>
|
|
/// <param name="sync">Whether to synchronize this to the humanoid mob, or not.</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void SetSkinColor(EntityUid uid, Color skinColor, bool sync = true, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
humanoid.SkinColor = skinColor;
|
|
|
|
if (sync)
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the base layer ID of this humanoid mob. A humanoid mob's 'base layer' is
|
|
/// the skin sprite that is applied to the mob's sprite upon appearance refresh.
|
|
/// </summary>
|
|
/// <param name="uid">The humanoid mob's UID.</param>
|
|
/// <param name="layer">The layer to target on this humanoid mob.</param>
|
|
/// <param name="id">The ID of the sprite to use. See <see cref="HumanoidSpeciesSpriteLayer"/>.</param>
|
|
/// <param name="sync">Whether to synchronize this to the humanoid mob, or not.</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void SetBaseLayerId(EntityUid uid, HumanoidVisualLayers layer, string id, bool sync = true,
|
|
HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid)
|
|
|| !_prototypeManager.HasIndex<HumanoidSpeciesSpriteLayer>(id))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (humanoid.CustomBaseLayers.TryGetValue(layer, out var info))
|
|
{
|
|
humanoid.CustomBaseLayers[layer] = new(id, info.Color);
|
|
}
|
|
else
|
|
{
|
|
var layerInfo = new CustomBaseLayerInfo(id, humanoid.SkinColor);
|
|
humanoid.CustomBaseLayers.Add(layer, layerInfo);
|
|
}
|
|
|
|
if (sync)
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the color of this humanoid mob's base layer. See <see cref="SetBaseLayerId"/> for a
|
|
/// description of how base layers work.
|
|
/// </summary>
|
|
/// <param name="uid">The humanoid mob's UID.</param>
|
|
/// <param name="layer">The layer to target on this humanoid mob.</param>
|
|
/// <param name="color">The color to set this base layer to.</param>
|
|
public void SetBaseLayerColor(EntityUid uid, HumanoidVisualLayers layer, Color color, bool sync = true, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (humanoid.CustomBaseLayers.TryGetValue(layer, out var info))
|
|
{
|
|
humanoid.CustomBaseLayers[layer] = new(info.ID, color);
|
|
}
|
|
else
|
|
{
|
|
var layerInfo = new CustomBaseLayerInfo(string.Empty, color);
|
|
humanoid.CustomBaseLayers.Add(layer, layerInfo);
|
|
}
|
|
|
|
if (sync)
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Toggles a humanoid's sprite layer visibility.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="layer">Layer to toggle visibility for</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void ToggleHiddenLayer(EntityUid uid, HumanoidVisualLayers layer, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (humanoid.HiddenLayers.Contains(layer))
|
|
{
|
|
humanoid.HiddenLayers.Remove(layer);
|
|
}
|
|
else
|
|
{
|
|
humanoid.HiddenLayers.Add(layer);
|
|
}
|
|
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the visibility for multiple layers at once on a humanoid's sprite.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="layers">An enumerable of all sprite layers that are going to have their visibility set</param>
|
|
/// <param name="visible">The visibility state of the layers given</param>
|
|
/// <param name="permanent">If this is a permanent change, or temporary. Permanent layers are stored in their own hash set.</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void SetLayersVisibility(EntityUid uid, IEnumerable<HumanoidVisualLayers> layers, bool visible, bool permanent = false,
|
|
HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var layer in layers)
|
|
{
|
|
if (visible)
|
|
{
|
|
if (permanent && humanoid.PermanentlyHidden.Contains(layer))
|
|
{
|
|
humanoid.PermanentlyHidden.Remove(layer);
|
|
}
|
|
|
|
humanoid.HiddenLayers.Remove(layer);
|
|
}
|
|
else
|
|
{
|
|
if (permanent)
|
|
{
|
|
humanoid.PermanentlyHidden.Add(layer);
|
|
}
|
|
|
|
humanoid.HiddenLayers.Add(layer);
|
|
}
|
|
}
|
|
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a marking to this humanoid.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="marking">Marking ID to use</param>
|
|
/// <param name="color">Color to apply to all marking layers of this marking</param>
|
|
/// <param name="sync">Whether to immediately sync this marking or not</param>
|
|
/// <param name="forced">If this marking was forced (ignores marking points)</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void AddMarking(EntityUid uid, string marking, Color? color = null, bool sync = true, bool forced = false, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid)
|
|
|| !_markingManager.Markings.TryGetValue(marking, out var prototype))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var markingObject = prototype.AsMarking();
|
|
markingObject.Forced = forced;
|
|
if (color != null)
|
|
{
|
|
for (var i = 0; i < prototype.Sprites.Count; i++)
|
|
{
|
|
markingObject.SetColor(i, color.Value);
|
|
}
|
|
}
|
|
|
|
humanoid.CurrentMarkings.AddBack(prototype.MarkingCategory, markingObject);
|
|
|
|
if (sync)
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="marking">Marking ID to use</param>
|
|
/// <param name="colors">Colors to apply against this marking's set of sprites.</param>
|
|
/// <param name="sync">Whether to immediately sync this marking or not</param>
|
|
/// <param name="forced">If this marking was forced (ignores marking points)</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void AddMarking(EntityUid uid, string marking, IReadOnlyList<Color> colors, bool sync = true, bool forced = false, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid)
|
|
|| !_markingManager.Markings.TryGetValue(marking, out var prototype))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var markingObject = new Marking(marking, colors);
|
|
markingObject.Forced = forced;
|
|
humanoid.CurrentMarkings.AddBack(prototype.MarkingCategory, markingObject);
|
|
|
|
if (sync)
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a marking from a humanoid by ID.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="marking">The marking to try and remove.</param>
|
|
/// <param name="sync">Whether to immediately sync this to the humanoid</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void RemoveMarking(EntityUid uid, string marking, bool sync = true, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (!Resolve(uid, ref humanoid)
|
|
|| !_markingManager.Markings.TryGetValue(marking, out var prototype))
|
|
{
|
|
return;
|
|
}
|
|
|
|
humanoid.CurrentMarkings.Remove(prototype.MarkingCategory, marking);
|
|
|
|
if (sync)
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes a marking from a humanoid by category and index.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="category">Category of the marking</param>
|
|
/// <param name="index">Index of the marking</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void RemoveMarking(EntityUid uid, MarkingCategories category, int index, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (index < 0
|
|
|| !Resolve(uid, ref humanoid)
|
|
|| !humanoid.CurrentMarkings.TryGetCategory(category, out var markings)
|
|
|| index >= markings.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
humanoid.CurrentMarkings.Remove(category, index);
|
|
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the marking ID of the humanoid in a category at an index in the category's list.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="category">Category of the marking</param>
|
|
/// <param name="index">Index of the marking</param>
|
|
/// <param name="markingId">The marking ID to use</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void SetMarkingId(EntityUid uid, MarkingCategories category, int index, string markingId, HumanoidComponent? humanoid = null)
|
|
{
|
|
if (index < 0
|
|
|| !_markingManager.MarkingsByCategory(category).TryGetValue(markingId, out var markingPrototype)
|
|
|| !Resolve(uid, ref humanoid)
|
|
|| !humanoid.CurrentMarkings.TryGetCategory(category, out var markings)
|
|
|| index >= markings.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var marking = markingPrototype.AsMarking();
|
|
for (var i = 0; i < marking.MarkingColors.Count && i < markings[index].MarkingColors.Count; i++)
|
|
{
|
|
marking.SetColor(i, markings[index].MarkingColors[i]);
|
|
}
|
|
|
|
humanoid.CurrentMarkings.Replace(category, index, marking);
|
|
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the marking colors of the humanoid in a category at an index in the category's list.
|
|
/// </summary>
|
|
/// <param name="uid">Humanoid mob's UID</param>
|
|
/// <param name="category">Category of the marking</param>
|
|
/// <param name="index">Index of the marking</param>
|
|
/// <param name="colors">The marking colors to use</param>
|
|
/// <param name="humanoid">Humanoid component of the entity</param>
|
|
public void SetMarkingColor(EntityUid uid, MarkingCategories category, int index, List<Color> colors,
|
|
HumanoidComponent? humanoid = null)
|
|
{
|
|
if (index < 0
|
|
|| !Resolve(uid, ref humanoid)
|
|
|| !humanoid.CurrentMarkings.TryGetCategory(category, out var markings)
|
|
|| index >= markings.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (var i = 0; i < markings[index].MarkingColors.Count && i < colors.Count; i++)
|
|
{
|
|
markings[index].SetColor(i, colors[i]);
|
|
}
|
|
|
|
Synchronize(uid, humanoid);
|
|
}
|
|
|
|
private void EnsureDefaultMarkings(EntityUid uid, HumanoidComponent? humanoid)
|
|
{
|
|
if (!Resolve(uid, ref humanoid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
humanoid.CurrentMarkings.EnsureDefault(humanoid.SkinColor, _markingManager);
|
|
}
|
|
}
|