Accent trait limit (#28046)

This commit is contained in:
Ed
2024-06-03 21:47:06 +03:00
committed by GitHub
parent ee8224bce2
commit a4d1601758
14 changed files with 365 additions and 171 deletions

View File

@@ -346,13 +346,43 @@ namespace Content.Shared.Preferences
};
}
public HumanoidCharacterProfile WithTraitPreference(string traitId, bool pref)
public HumanoidCharacterProfile WithTraitPreference(string traitId, string? categoryId, bool pref)
{
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
var traitProto = prototypeManager.Index<TraitPrototype>(traitId);
TraitCategoryPrototype? categoryProto = null;
if (categoryId != null && categoryId != "default")
categoryProto = prototypeManager.Index<TraitCategoryPrototype>(categoryId);
var list = new HashSet<string>(_traitPreferences);
if (pref)
{
list.Add(traitId);
if (categoryProto == null || categoryProto.MaxTraitPoints < 0)
{
return new(this)
{
_traitPreferences = list,
};
}
var count = 0;
foreach (var trait in list)
{
var traitProtoTemp = prototypeManager.Index<TraitPrototype>(trait);
count += traitProtoTemp.Cost;
}
if (count > categoryProto.MaxTraitPoints && traitProto.Cost != 0)
{
return new(this)
{
_traitPreferences = _traitPreferences,
};
}
}
else
{