(965c31410a) Unstable v0.10.4.0

This commit is contained in:
Juan Pablo Arce
2020-07-21 08:57:50 -03:00
parent 4f8bd39789
commit 33d3a41104
546 changed files with 45952 additions and 25762 deletions
@@ -33,6 +33,8 @@ namespace Barotrauma
public int Variant;
public Skill PrimarySkill { get; }
public Job(JobPrefab jobPrefab, int variant = 0)
{
prefab = jobPrefab;
@@ -41,14 +43,16 @@ namespace Barotrauma
skills = new Dictionary<string, Skill>();
foreach (SkillPrefab skillPrefab in prefab.Skills)
{
skills.Add(skillPrefab.Identifier, new Skill(skillPrefab));
var skill = new Skill(skillPrefab);
skills.Add(skillPrefab.Identifier, skill);
if (skillPrefab.IsPrimarySkill) { PrimarySkill = skill; }
}
}
public Job(XElement element)
{
string identifier = element.GetAttributeString("identifier", "").ToLowerInvariant();
JobPrefab p = null;
JobPrefab p;
if (!JobPrefab.Prefabs.ContainsKey(identifier))
{
DebugConsole.ThrowError($"Could not find the job {identifier}. Giving the character a random job.");
@@ -65,9 +69,9 @@ namespace Barotrauma
if (!subElement.Name.ToString().Equals("skill", System.StringComparison.OrdinalIgnoreCase)) { continue; }
string skillIdentifier = subElement.GetAttributeString("identifier", "");
if (string.IsNullOrEmpty(skillIdentifier)) { continue; }
skills.Add(
skillIdentifier,
new Skill(skillIdentifier, subElement.GetAttributeFloat("level", 0)));
var skill = new Skill(skillIdentifier, subElement.GetAttributeFloat("level", 0));
skills.Add(skillIdentifier, skill);
if (skillIdentifier == prefab.PrimarySkill?.Identifier) { PrimarySkill = skill; }
}
}
@@ -146,6 +146,13 @@ namespace Barotrauma
private set;
}
[Serialize(1.0f, false)]
public float PriceMultiplier
{
get;
private set;
}
// TODO: not used
[Serialize(10.0f, false)]
public float Commonness
@@ -164,6 +171,9 @@ namespace Barotrauma
public Sprite Icon;
public Sprite IconSmall;
public SkillPrefab PrimarySkill => Skills?.FirstOrDefault(s => s.IsPrimarySkill);
public string FilePath { get; private set; }
public XElement Element { get; private set; }
@@ -1,24 +1,12 @@
using Microsoft.Xna.Framework;
using System;
namespace Barotrauma
{
class Skill
{
private SkillPrefab prefab;
private float level;
static string[] levelNames = new string[] {
"Untrained", "Incompetent", "Novice",
"Adequate", "Competent", "Proficient",
"Professional", "Master", "Legendary" };
string identifier;
public string Identifier
{
get { return identifier; }
}
public string Identifier { get; }
public float Level
{
@@ -26,29 +14,58 @@ namespace Barotrauma
set { level = MathHelper.Clamp(value, 0.0f, 100.0f); }
}
private Sprite icon;
public Sprite Icon
{
get
{
if (icon == null)
{
icon = GetIcon();
}
return icon;
}
}
internal SkillPrefab Prefab { get; private set; }
public Skill(SkillPrefab prefab)
{
this.prefab = prefab;
this.identifier = prefab.Identifier;
this.level = Rand.Range(prefab.LevelRange.X, prefab.LevelRange.Y, Rand.RandSync.Server);
this.Prefab = prefab;
Identifier = prefab.Identifier;
level = Rand.Range(prefab.LevelRange.X, prefab.LevelRange.Y, Rand.RandSync.Server);
icon = GetIcon();
}
public Skill(string identifier, float level)
{
this.identifier = identifier;
Identifier = identifier;
this.level = level;
icon = GetIcon();
}
/// <summary>
/// returns the "name" of some skill level (0-10 -> untrained, etc)
/// </summary>
public static string GetLevelName(float level)
private Sprite GetIcon()
{
level = MathHelper.Clamp(level, 0.0f, 100.0f);
int scaledLevel = (int)Math.Floor((level / 100.0f) * levelNames.Length);
return levelNames[Math.Min(scaledLevel, levelNames.Length - 1)];
string jobId = null;
switch (Identifier.ToLowerInvariant())
{
case "electrical":
jobId = "engineer";
break;
case "helm":
jobId = "captain";
break;
case "mechanical":
jobId = "mechanic";
break;
case "medical":
jobId = "medicaldoctor";
break;
case "weapons":
jobId = "securityofficer";
break;
}
return jobId != null && JobPrefab.Prefabs.ContainsKey(jobId) ? JobPrefab.Prefabs[jobId].IconSmall : null;
}
}
}
@@ -9,10 +9,17 @@ namespace Barotrauma
public Vector2 LevelRange { get; private set; }
/// <summary>
/// How much this skill affects characters' hiring cost
/// </summary>
public readonly float PriceMultiplier;
public bool IsPrimarySkill { get; }
public SkillPrefab(XElement element)
{
Identifier = element.GetAttributeString("identifier", "");
PriceMultiplier = element.GetAttributeFloat("pricemultiplier", 25.0f);
var levelString = element.GetAttributeString("level", "");
if (levelString.Contains(","))
{
@@ -23,6 +30,8 @@ namespace Barotrauma
float skillLevel = float.Parse(levelString, System.Globalization.CultureInfo.InvariantCulture);
LevelRange = new Vector2(skillLevel, skillLevel);
}
IsPrimarySkill = element.GetAttributeBool("primary", false);
}
}
}