Server job assigning logic, submarine movement syncing, submarine collision improvements, spawnpoints in levels
This commit is contained in:
@@ -24,7 +24,7 @@ namespace Subsurface
|
||||
// return gender.ToString();
|
||||
//}
|
||||
|
||||
public CharacterInfo(string file, string name = "", Gender gender = Gender.None, Job job = null)
|
||||
public CharacterInfo(string file, string name = "", Gender gender = Gender.None, JobPrefab jobPrefab = null)
|
||||
{
|
||||
this.File = file;
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Subsurface
|
||||
HeadSpriteId = Rand.Range((int)headSpriteRange.X, (int)headSpriteRange.Y + 1);
|
||||
}
|
||||
|
||||
this.Job = (job == null) ? Job.Random() : job;
|
||||
this.Job = (jobPrefab == null) ? Job.Random() : new Job(jobPrefab);
|
||||
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
@@ -72,14 +72,14 @@ namespace Subsurface
|
||||
|
||||
if (doc.Root.Element("name") != null)
|
||||
{
|
||||
string firstNamePath = (ToolBox.GetAttributeString(doc.Root.Element("name"), "firstname", ""));
|
||||
string firstNamePath = ToolBox.GetAttributeString(doc.Root.Element("name"), "firstname", "");
|
||||
if (firstNamePath != "")
|
||||
{
|
||||
firstNamePath = firstNamePath.Replace("[GENDER]", (this.Gender == Gender.Female) ? "f" : "");
|
||||
this.Name = ToolBox.GetRandomLine(firstNamePath);
|
||||
}
|
||||
|
||||
string lastNamePath = (ToolBox.GetAttributeString(doc.Root.Element("name"), "lastname", ""));
|
||||
string lastNamePath = ToolBox.GetAttributeString(doc.Root.Element("name"), "lastname", "");
|
||||
if (lastNamePath != "")
|
||||
{
|
||||
lastNamePath = lastNamePath.Replace("[GENDER]", (this.Gender == Gender.Female) ? "f" : "");
|
||||
@@ -101,21 +101,31 @@ namespace Subsurface
|
||||
Salary = ToolBox.GetAttributeInt(element, "salary", 1000);
|
||||
|
||||
HeadSpriteId = ToolBox.GetAttributeInt(element, "headspriteid", 1);
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLower() != "job") continue;
|
||||
|
||||
Job = new Job(subElement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual XElement Save(XElement parentElement)
|
||||
{
|
||||
XElement componentElement = new XElement("character");
|
||||
XElement charElement = new XElement("character");
|
||||
|
||||
componentElement.Add(
|
||||
charElement.Add(
|
||||
new XAttribute("name", Name),
|
||||
new XAttribute("file", File),
|
||||
new XAttribute("gender", Gender == Gender.Male ? "male" : "female"),
|
||||
new XAttribute("salary", Salary),
|
||||
new XAttribute("headspriteid", HeadSpriteId));
|
||||
|
||||
parentElement.Add(componentElement);
|
||||
return componentElement;
|
||||
Job.Save(charElement);
|
||||
|
||||
parentElement.Add(charElement);
|
||||
return charElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +98,7 @@ namespace Subsurface
|
||||
{
|
||||
floorY = rayStart.Y + (rayEnd.Y - rayStart.Y) * closestFraction;
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.WriteLine(floorY+" - "+inWater);
|
||||
|
||||
|
||||
|
||||
IgnorePlatforms = (TargetMovement.Y < 0.0f);
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Subsurface.Characters
|
||||
{
|
||||
class Job
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
@@ -23,17 +24,29 @@ namespace Subsurface
|
||||
get { return prefab.Description; }
|
||||
}
|
||||
|
||||
|
||||
public Job(JobPrefab jobPrefab)
|
||||
{
|
||||
prefab = jobPrefab;
|
||||
|
||||
skills = new Dictionary<string, float>();
|
||||
foreach (KeyValuePair<string, Vector2> skill in prefab.skills)
|
||||
foreach (KeyValuePair<string, Vector2> skill in prefab.Skills)
|
||||
{
|
||||
skills.Add(skill.Key, Rand.Range(skill.Value.X, skill.Value.Y, false));
|
||||
}
|
||||
}
|
||||
|
||||
public Job(XElement element)
|
||||
{
|
||||
string name = ToolBox.GetAttributeString(element, "name", "").ToLower();
|
||||
prefab = JobPrefab.List.Find(jp => jp.Name.ToLower() == name);
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
skills.Add(subElement.Name.ToString(), ToolBox.GetAttributeFloat(subElement, "level", 0.0f));
|
||||
}
|
||||
}
|
||||
|
||||
public static Job Random()
|
||||
{
|
||||
JobPrefab prefab = JobPrefab.List[Rand.Int(JobPrefab.List.Count-1, false)];
|
||||
@@ -48,5 +61,20 @@ namespace Subsurface
|
||||
|
||||
return skillLevel;
|
||||
}
|
||||
|
||||
public virtual XElement Save(XElement parentElement)
|
||||
{
|
||||
XElement jobElement = new XElement("job");
|
||||
|
||||
jobElement.Add(new XAttribute("name", Name));
|
||||
|
||||
foreach (KeyValuePair<string, float> skill in skills)
|
||||
{
|
||||
jobElement.Add(new XElement(skill.Key, new XAttribute("level", skill.Value)));
|
||||
}
|
||||
|
||||
parentElement.Add(jobElement);
|
||||
return jobElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,25 @@ namespace Subsurface
|
||||
|
||||
string name;
|
||||
string description;
|
||||
|
||||
//how many crew members can have the job (only one captain etc)
|
||||
private int maxNumber;
|
||||
|
||||
//how many crew members are REQUIRED to have a job
|
||||
//(i.e. if one captain is required, one captain is chosen even if all the players have set captain to lowest preference)
|
||||
private int minNumber;
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
//names of the items the character spawns with
|
||||
public List<string> itemNames;
|
||||
public List<string> ItemNames;
|
||||
|
||||
public Dictionary<string, Vector2> skills;
|
||||
public Dictionary<string, Vector2> Skills;
|
||||
|
||||
public string Name
|
||||
{
|
||||
@@ -27,19 +41,15 @@ namespace Subsurface
|
||||
get { return description; }
|
||||
}
|
||||
|
||||
//public float GetSkill(string skillName)
|
||||
//{
|
||||
// float skillLevel = 0.0f;
|
||||
// if (skills.TryGetValue(skillName.ToLower(), out skillLevel))
|
||||
// {
|
||||
// return skillLevel;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// DebugConsole.ThrowError("Skill ''"+skillName+" not found!");
|
||||
// return skillLevel;
|
||||
// }
|
||||
//}
|
||||
public int MaxNumber
|
||||
{
|
||||
get { return maxNumber; }
|
||||
}
|
||||
|
||||
public int MinNumber
|
||||
{
|
||||
get { return minNumber; }
|
||||
}
|
||||
|
||||
public JobPrefab(XElement element)
|
||||
{
|
||||
@@ -47,9 +57,14 @@ namespace Subsurface
|
||||
|
||||
description = ToolBox.GetAttributeString(element, "description", "");
|
||||
|
||||
itemNames = new List<string>();
|
||||
minNumber = ToolBox.GetAttributeInt(element, "minnumber", 0);
|
||||
maxNumber = ToolBox.GetAttributeInt(element, "maxnumber", 10);
|
||||
|
||||
skills = new Dictionary<string, Vector2>();
|
||||
AllowAlways = ToolBox.GetAttributeBool(element, "allowalways", false);
|
||||
|
||||
ItemNames = new List<string>();
|
||||
|
||||
Skills = new Dictionary<string, Vector2>();
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
@@ -57,7 +72,7 @@ namespace Subsurface
|
||||
{
|
||||
case "item":
|
||||
string itemName = ToolBox.GetAttributeString(subElement, "name", "");
|
||||
if (!string.IsNullOrEmpty(itemName)) itemNames.Add(itemName);
|
||||
if (!string.IsNullOrEmpty(itemName)) ItemNames.Add(itemName);
|
||||
break;
|
||||
case "skills":
|
||||
LoadSkills(subElement);
|
||||
@@ -70,18 +85,18 @@ namespace Subsurface
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
string skillName = subElement.Name.ToString().ToLower();
|
||||
if (skills.ContainsKey(skillName)) continue;
|
||||
string skillName = subElement.Name.ToString();
|
||||
if (Skills.ContainsKey(skillName)) continue;
|
||||
|
||||
var levelAttribute = subElement.Attribute("level").ToString();
|
||||
if (levelAttribute.Contains("'"))
|
||||
{
|
||||
skills.Add(skillName, ToolBox.ParseToVector2(levelAttribute, false));
|
||||
Skills.Add(skillName, ToolBox.ParseToVector2(levelAttribute, false));
|
||||
}
|
||||
else
|
||||
{
|
||||
float skillLevel = float.Parse(levelAttribute, CultureInfo.InvariantCulture);
|
||||
skills.Add(skillName, new Vector2(skillLevel, skillLevel));
|
||||
Skills.Add(skillName, new Vector2(skillLevel, skillLevel));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user