Random default characters (#2216)

This commit is contained in:
Víctor Aguilera Puerto
2020-10-11 13:15:09 +02:00
committed by GitHub
parent ba4c596195
commit 32876c78fe
3 changed files with 52 additions and 43 deletions

View File

@@ -15,22 +15,11 @@ namespace Content.Client.UserInterface
private void RandomizeEverything()
{
RandomizeSex();
RandomizeAge();
RandomizeName();
RandomizeAppearance();
}
private void RandomizeSex()
{
SetSex(_random.Prob(0.5f) ? Sex.Male : Sex.Female);
Profile = HumanoidCharacterProfile.Random();
UpdateSexControls();
}
private void RandomizeAge()
{
SetAge(_random.Next(HumanoidCharacterProfile.MinimumAge, HumanoidCharacterProfile.MaximumAge));
UpdateAgeEdit();
UpdateNameEdit();
UpdateHairPickers();
}
private void RandomizeName()
@@ -42,33 +31,5 @@ namespace Content.Client.UserInterface
SetName($"{firstName} {lastName}");
UpdateNameEdit();
}
private void RandomizeAppearance()
{
var newHairStyle = _random.Pick(HairStyles.HairStylesMap.Keys.ToList());
var newFacialHairStyle = Profile.Sex == Sex.Female
? HairStyles.DefaultFacialHairStyle
: _random.Pick(HairStyles.FacialHairStylesMap.Keys.ToList());
var newHairColor = _random.Pick(HairStyles.RealisticHairColors);
newHairColor = newHairColor
.WithRed(RandomizeColor(newHairColor.R))
.WithGreen(RandomizeColor(newHairColor.G))
.WithBlue(RandomizeColor(newHairColor.B));
Profile = Profile.WithCharacterAppearance(
Profile.Appearance
.WithHairStyleName(newHairStyle)
.WithFacialHairStyleName(newFacialHairStyle)
.WithHairColor(newHairColor)
.WithFacialHairColor(newHairColor));
UpdateHairPickers();
float RandomizeColor(float channel)
{
return MathHelper.Clamp01(channel + _random.Next(-25, 25) / 100f);
}
}
}
}

View File

@@ -1,6 +1,10 @@
using System;
using System.Linq;
using Content.Shared.Preferences.Appearance;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
namespace Content.Shared.Preferences
@@ -73,6 +77,31 @@ namespace Content.Shared.Preferences
);
}
public static HumanoidCharacterAppearance Random(Sex sex)
{
var random = IoCManager.Resolve<IRobustRandom>();
var newHairStyle = random.Pick(HairStyles.HairStylesMap.Keys.ToList());
var newFacialHairStyle = sex == Sex.Female
? HairStyles.DefaultFacialHairStyle
: random.Pick(HairStyles.FacialHairStylesMap.Keys.ToList());
var newHairColor = random.Pick(HairStyles.RealisticHairColors);
newHairColor = newHairColor
.WithRed(RandomizeColor(newHairColor.R))
.WithGreen(RandomizeColor(newHairColor.G))
.WithBlue(RandomizeColor(newHairColor.B));
// TODO: Add random eye and skin color
return new HumanoidCharacterAppearance(newHairStyle, newHairColor, newFacialHairStyle, newHairColor, Color.Black, Color.FromHex("#C0967F"));
float RandomizeColor(float channel)
{
return MathHelper.Clamp01(channel + random.Next(-25, 25) / 100f);
}
}
public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearance appearance)
{
string hairStyleName;

View File

@@ -2,7 +2,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Content.Shared.Roles;
using Content.Shared.Text;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
namespace Content.Shared.Preferences
@@ -49,7 +53,22 @@ namespace Content.Shared.Preferences
public static HumanoidCharacterProfile Default()
{
return new HumanoidCharacterProfile("John Doe", 18, Sex.Male, HumanoidCharacterAppearance.Default(),
return Random();
}
public static HumanoidCharacterProfile Random()
{
var random = IoCManager.Resolve<IRobustRandom>();
var sex = random.Prob(0.5f) ? Sex.Male : Sex.Female;
var firstName = random.Pick(sex == Sex.Male
? Names.MaleFirstNames
: Names.FemaleFirstNames);
var lastName = random.Pick(Names.LastNames);
var name = $"{firstName} {lastName}";
var age = random.Next(MinimumAge, MaximumAge);
return new HumanoidCharacterProfile(name, age, sex, HumanoidCharacterAppearance.Random(sex),
new Dictionary<string, JobPriority>
{
{SharedGameTicker.OverflowJob, JobPriority.High}