Files
LuaCsForBarotraumaEP/BarotraumaShared/Source/Characters/Jobs/JobPrefab.cs
juanjp600 7168a534ed Further separation of client-specific code
Still not done here, just gonna push a commit now so I can pull this from elsewhere.
2017-06-16 16:02:07 -03:00

123 lines
3.5 KiB
C#

using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Linq;
using System.Linq;
namespace Barotrauma
{
partial class JobPrefab
{
public static List<JobPrefab> List;
public readonly XElement Items;
public readonly List<string> ItemNames;
public List<SkillPrefab> Skills;
public string Name
{
get;
private set;
}
public string Description
{
get;
private set;
}
//if set to true, a client that has chosen this as their preferred job will get it no matter what
public bool AllowAlways
{
get;
private set;
}
//how many crew members can have the job (only one captain etc)
public int MaxNumber
{
get;
private set;
}
//how many crew members are REQUIRED to have the job
//(i.e. if one captain is required, one captain is chosen even if all the players have set captain to lowest preference)
public int MinNumber
{
get;
private set;
}
public float Commonness
{
get;
private set;
}
public JobPrefab(XElement element)
{
Name = ToolBox.GetAttributeString(element, "name", "name not found");
Description = ToolBox.GetAttributeString(element, "description", "");
MinNumber = ToolBox.GetAttributeInt(element, "minnumber", 0);
MaxNumber = ToolBox.GetAttributeInt(element, "maxnumber", 10);
Commonness = ToolBox.GetAttributeInt(element, "commonness", 10);
AllowAlways = ToolBox.GetAttributeBool(element, "allowalways", false);
ItemNames = new List<string>();
Skills = new List<SkillPrefab>();
foreach (XElement subElement in element.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "items":
Items = subElement;
foreach (XElement itemElement in subElement.Elements())
{
string itemName = ToolBox.GetAttributeString(itemElement, "name", "");
if (!string.IsNullOrWhiteSpace(itemName)) ItemNames.Add(itemName);
}
break;
case "skills":
foreach (XElement skillElement in subElement.Elements())
{
Skills.Add(new SkillPrefab(skillElement));
}
break;
}
}
Skills.Sort((x,y) => y.LevelRange.X.CompareTo(x.LevelRange.X));
}
public static JobPrefab Random()
{
return List[Rand.Int(List.Count)];
}
public static void LoadAll(List<string> filePaths)
{
List = new List<JobPrefab>();
foreach (string filePath in filePaths)
{
XDocument doc = ToolBox.TryLoadXml(filePath);
if (doc == null || doc.Root == null) return;
foreach (XElement element in doc.Root.Elements())
{
JobPrefab job = new JobPrefab(element);
List.Add(job);
}
}
}
}
}