WIP level position syncing, job prefabs and assigning jobs to characters
This commit is contained in:
@@ -13,7 +13,7 @@ namespace Subsurface
|
||||
|
||||
public int HeadSpriteId;
|
||||
|
||||
//public int ID;
|
||||
public Job Job;
|
||||
|
||||
public Gender Gender;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Subsurface
|
||||
// return gender.ToString();
|
||||
//}
|
||||
|
||||
public CharacterInfo(string file, string name = "", Gender gender = Gender.None)
|
||||
public CharacterInfo(string file, string name = "", Gender gender = Gender.None, Job job = null)
|
||||
{
|
||||
this.File = file;
|
||||
|
||||
@@ -62,6 +62,8 @@ namespace Subsurface
|
||||
HeadSpriteId = Rand.Range((int)headSpriteRange.X, (int)headSpriteRange.Y + 1);
|
||||
}
|
||||
|
||||
this.Job = (job == null) ? Job.Random() : job;
|
||||
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
this.Name = name;
|
||||
|
||||
@@ -106,14 +106,16 @@ namespace Subsurface
|
||||
float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2;
|
||||
|
||||
Limb tail = GetLimb(LimbType.Tail);
|
||||
if (tail != null && waveAmplitude>0.0f)
|
||||
if (tail != null && waveAmplitude > 0.0f)
|
||||
{
|
||||
walkPos -= movement.Length();
|
||||
|
||||
float waveRotation = (float)Math.Sin(walkPos / waveLength)*waveAmplitude;
|
||||
float waveRotation = (float)Math.Sin(walkPos / waveLength) * waveAmplitude;
|
||||
|
||||
float angle = MathUtils.GetShortestAngle(tail.body.Rotation, movementAngle + waveRotation);
|
||||
|
||||
tail.body.ApplyTorque(angle * tail.Mass);
|
||||
|
||||
//limbs[tailIndex].body.ApplyTorque((Math.Sign(angle) + Math.Max(Math.Min(angle * 10.0f, 10.0f), -10.0f)) * limbs[tailIndex].body.Mass);
|
||||
//limbs[tailIndex].body.ApplyTorque(-limbs[tailIndex].body.AngularVelocity * 0.5f * limbs[tailIndex].body.Mass);
|
||||
}
|
||||
|
||||
@@ -1,56 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class Job
|
||||
{
|
||||
public static List<Job> jobList;
|
||||
|
||||
string name;
|
||||
string description;
|
||||
|
||||
//names of the items the character spawns with
|
||||
public List<string> itemNames;
|
||||
private JobPrefab prefab;
|
||||
|
||||
private Dictionary<string, float> skills;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
get { return prefab.Name; }
|
||||
}
|
||||
|
||||
public Job(XElement element)
|
||||
public string Description
|
||||
{
|
||||
name = element.Name.ToString();
|
||||
get { return prefab.Description; }
|
||||
}
|
||||
|
||||
description = ToolBox.GetAttributeString(element, "description", "");
|
||||
public Job(JobPrefab jobPrefab)
|
||||
{
|
||||
prefab = jobPrefab;
|
||||
|
||||
itemNames = new List<string>();
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
skills = new Dictionary<string, float>();
|
||||
foreach (KeyValuePair<string, Vector2> skill in prefab.skills)
|
||||
{
|
||||
switch (subElement.Name.ToString())
|
||||
{
|
||||
case "item":
|
||||
string itemName = ToolBox.GetAttributeString(subElement, "name", "");
|
||||
if (!string.IsNullOrEmpty(itemName)) itemNames.Add(itemName);
|
||||
break;
|
||||
}
|
||||
skills.Add(skill.Key, Rand.Range(skill.Value.X, skill.Value.Y, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void LoadAll(string filePath)
|
||||
public static Job Random()
|
||||
{
|
||||
jobList = new List<Job>();
|
||||
JobPrefab prefab = JobPrefab.List[Rand.Int(JobPrefab.List.Count-1, false)];
|
||||
|
||||
XDocument doc = ToolBox.TryLoadXml(filePath);
|
||||
if (doc == null) return;
|
||||
return new Job(prefab);
|
||||
}
|
||||
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
Job job = new Job(element);
|
||||
jobList.Add(job);
|
||||
}
|
||||
public float GetSkill(string skillName)
|
||||
{
|
||||
float skillLevel = 0.0f;
|
||||
skills.TryGetValue(skillName.ToLower(), out skillLevel);
|
||||
|
||||
return skillLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class JobPrefab
|
||||
{
|
||||
public static List<JobPrefab> List;
|
||||
|
||||
string name;
|
||||
string description;
|
||||
|
||||
//names of the items the character spawns with
|
||||
public List<string> itemNames;
|
||||
|
||||
public Dictionary<string, Vector2> skills;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
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 JobPrefab(XElement element)
|
||||
{
|
||||
name = element.Name.ToString();
|
||||
|
||||
description = ToolBox.GetAttributeString(element, "description", "");
|
||||
|
||||
itemNames = new List<string>();
|
||||
|
||||
skills = new Dictionary<string, Vector2>();
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString())
|
||||
{
|
||||
case "item":
|
||||
string itemName = ToolBox.GetAttributeString(subElement, "name", "");
|
||||
if (!string.IsNullOrEmpty(itemName)) itemNames.Add(itemName);
|
||||
break;
|
||||
case "skills":
|
||||
LoadSkills(subElement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadSkills(XElement element)
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
string skillName = subElement.Name.ToString().ToLower();
|
||||
if (skills.ContainsKey(skillName)) continue;
|
||||
|
||||
var levelAttribute = subElement.Attribute("level").ToString();
|
||||
if (levelAttribute.Contains("'"))
|
||||
{
|
||||
skills.Add(skillName, ToolBox.ParseToVector2(levelAttribute, false));
|
||||
}
|
||||
else
|
||||
{
|
||||
float skillLevel = float.Parse(levelAttribute, CultureInfo.InvariantCulture);
|
||||
skills.Add(skillName, new Vector2(skillLevel, skillLevel));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void LoadAll(string filePath)
|
||||
{
|
||||
List = new List<JobPrefab>();
|
||||
|
||||
XDocument doc = ToolBox.TryLoadXml(filePath);
|
||||
if (doc == null) return;
|
||||
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
JobPrefab job = new JobPrefab(element);
|
||||
List.Add(job);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user