Saving (wip), statuseffect refactoring, multiple character faces
This commit is contained in:
@@ -14,7 +14,7 @@ using Subsurface.Particles;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
class Character : Entity, IDamageable
|
||||
class Character : Entity, IDamageable, IPropertyObject
|
||||
{
|
||||
public static List<Character> characterList = new List<Character>();
|
||||
|
||||
@@ -40,12 +40,14 @@ namespace Subsurface
|
||||
public byte largeUpdateTimer;
|
||||
|
||||
public readonly Dictionary<string, ObjectProperty> properties;
|
||||
public Dictionary<string, ObjectProperty> ObjectProperties
|
||||
{
|
||||
get { return properties; }
|
||||
}
|
||||
|
||||
protected Key selectKeyHit;
|
||||
protected Key actionKeyHit;
|
||||
protected Key actionKeyDown;
|
||||
protected Key secondaryKeyHit;
|
||||
protected Key secondaryKeyDown;
|
||||
protected Key actionKeyHit, actionKeyDown;
|
||||
protected Key secondaryKeyHit, secondaryKeyDown;
|
||||
|
||||
private Item selectedConstruction;
|
||||
private Item[] selectedItems;
|
||||
@@ -83,6 +85,14 @@ namespace Subsurface
|
||||
//which AIstate each sound is for
|
||||
private AIController.AiState[] soundStates;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return speciesName;
|
||||
}
|
||||
}
|
||||
|
||||
public Inventory Inventory
|
||||
{
|
||||
get { return inventory; }
|
||||
@@ -344,10 +354,10 @@ namespace Subsurface
|
||||
|
||||
animController.FindHull();
|
||||
|
||||
if (info.ID >= 0)
|
||||
{
|
||||
ID = info.ID;
|
||||
}
|
||||
//if (info.ID >= 0)
|
||||
//{
|
||||
// ID = info.ID;
|
||||
//}
|
||||
|
||||
characterList.Add(this);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
@@ -6,27 +7,28 @@ namespace Subsurface
|
||||
|
||||
class CharacterInfo
|
||||
{
|
||||
//the name of the character (e.q. Urist McEngineer)
|
||||
public string name;
|
||||
|
||||
public readonly string file;
|
||||
|
||||
public int ID;
|
||||
public readonly int headSpriteId;
|
||||
|
||||
//public int ID;
|
||||
|
||||
public Gender gender;
|
||||
|
||||
public int salary;
|
||||
|
||||
public string GenderString()
|
||||
{
|
||||
return gender.ToString();
|
||||
}
|
||||
//public string GenderString()
|
||||
//{
|
||||
// return gender.ToString();
|
||||
//}
|
||||
|
||||
public CharacterInfo(string file, string name = "", Gender gender = Gender.None)
|
||||
{
|
||||
this.file = file;
|
||||
|
||||
ID = -1;
|
||||
//ID = -1;
|
||||
|
||||
XDocument doc = ToolBox.TryLoadXml(file);
|
||||
if (doc == null) return;
|
||||
@@ -35,7 +37,7 @@ namespace Subsurface
|
||||
|
||||
if (ToolBox.GetAttributeBool(doc.Root, "genders", false))
|
||||
{
|
||||
if (gender==Gender.None)
|
||||
if (gender == Gender.None)
|
||||
{
|
||||
float femaleRatio = ToolBox.GetAttributeFloat(doc.Root, "femaleratio", 0.5f);
|
||||
this.gender = (Game1.random.NextDouble() < femaleRatio) ? Gender.Female : Gender.Male;
|
||||
@@ -45,7 +47,21 @@ namespace Subsurface
|
||||
this.gender = gender;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vector2 headSpriteRange = ToolBox.GetAttributeVector2(doc.Root, "headid", Vector2.Zero);
|
||||
if (headSpriteRange == Vector2.Zero)
|
||||
{
|
||||
headSpriteRange = ToolBox.GetAttributeVector2(
|
||||
doc.Root,
|
||||
this.gender == Gender.Female ? "femaleheadid" : "maleheadid",
|
||||
Vector2.Zero);
|
||||
}
|
||||
|
||||
if (headSpriteRange != Vector2.Zero)
|
||||
{
|
||||
headSpriteId = Game1.localRandom.Next((int)headSpriteRange.X, (int)headSpriteRange.Y + 1);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
this.name = name;
|
||||
@@ -69,8 +85,30 @@ namespace Subsurface
|
||||
this.name += ToolBox.GetRandomLine(lastNamePath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CharacterInfo(XElement element)
|
||||
{
|
||||
name = element.Name.ToString();
|
||||
|
||||
string genderStr = ToolBox.GetAttributeString(element, "gender", "male").ToLower();
|
||||
gender = (genderStr == "male") ? Gender.Male : Gender.Female;
|
||||
|
||||
salary = ToolBox.GetAttributeInt(element, "salary", 1000);
|
||||
}
|
||||
|
||||
public virtual XElement Save(XElement parentElement)
|
||||
{
|
||||
XElement componentElement = new XElement("character");
|
||||
|
||||
componentElement.Add(
|
||||
new XAttribute("name", name),
|
||||
new XAttribute("gender", gender == Gender.Male ? "male" : "female"),
|
||||
new XAttribute("salary", salary),
|
||||
new XAttribute("headspriteid", headSpriteId));
|
||||
|
||||
parentElement.Add(componentElement);
|
||||
return componentElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Subsurface
|
||||
@@ -11,9 +12,9 @@ namespace Subsurface
|
||||
|
||||
float timer;
|
||||
|
||||
private Item item;
|
||||
Vector2 position;
|
||||
|
||||
private Character character;
|
||||
List<IPropertyObject> targets;
|
||||
|
||||
public float Timer
|
||||
{
|
||||
@@ -26,14 +27,14 @@ namespace Subsurface
|
||||
delay = ToolBox.GetAttributeFloat(element, "delay", 1.0f);
|
||||
}
|
||||
|
||||
public override void Apply(ActionType type, float deltaTime, Item item, Character character = null)
|
||||
public override void Apply(ActionType type, float deltaTime, Vector2 position, List<IPropertyObject> targets)
|
||||
{
|
||||
if (this.type != type) return;
|
||||
|
||||
this.item = item;
|
||||
this.character = character;
|
||||
|
||||
|
||||
timer = delay;
|
||||
this.position = position;
|
||||
|
||||
this.targets = targets;
|
||||
|
||||
list.Add(this);
|
||||
}
|
||||
@@ -44,7 +45,7 @@ namespace Subsurface
|
||||
|
||||
if (timer > 0.0f) return;
|
||||
|
||||
base.Apply(1.0f, character, item);
|
||||
base.Apply(1.0f, position, targets);
|
||||
list.Remove(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -227,7 +227,11 @@ namespace Subsurface
|
||||
string spritePath = subElement.Attribute("texture").Value;
|
||||
|
||||
if (character.info!=null)
|
||||
{
|
||||
spritePath = spritePath.Replace("[GENDER]", (character.info.gender == Gender.Female) ? "f" : "");
|
||||
spritePath = spritePath.Replace("[HEADID]", character.info.headSpriteId.ToString());
|
||||
}
|
||||
|
||||
|
||||
sprite = new Sprite(subElement, "", spritePath);
|
||||
break;
|
||||
|
||||
@@ -9,12 +9,12 @@ namespace Subsurface
|
||||
class StatusEffect
|
||||
{
|
||||
[Flags]
|
||||
public enum Target
|
||||
public enum TargetType
|
||||
{
|
||||
This = 1, Parent = 2, Character = 4, Contained = 8, Nearby = 16, UseTarget=32
|
||||
}
|
||||
|
||||
private Target targets;
|
||||
private TargetType targetTypes;
|
||||
private string[] targetNames;
|
||||
|
||||
public string[] propertyNames;
|
||||
@@ -30,9 +30,9 @@ namespace Subsurface
|
||||
|
||||
private Sound sound;
|
||||
|
||||
public Target Targets
|
||||
public TargetType Targets
|
||||
{
|
||||
get { return targets; }
|
||||
get { return targetTypes; }
|
||||
}
|
||||
|
||||
public string[] TargetNames
|
||||
@@ -92,7 +92,7 @@ namespace Subsurface
|
||||
string[] Flags = attribute.Value.Split(',');
|
||||
foreach (string s in Flags)
|
||||
{
|
||||
targets |= (Target)Enum.Parse(typeof(Target), s, true);
|
||||
targetTypes |= (TargetType)Enum.Parse(typeof(TargetType), s, true);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -143,18 +143,27 @@ namespace Subsurface
|
||||
}
|
||||
|
||||
|
||||
public virtual void Apply(ActionType type, float deltaTime, Item item, Character character = null)
|
||||
{
|
||||
if (this.type == type) Apply(deltaTime, character, item);
|
||||
}
|
||||
//public virtual void Apply(ActionType type, float deltaTime, Item item, Character character = null)
|
||||
//{
|
||||
// if (this.type == type) Apply(deltaTime, character, item);
|
||||
//}
|
||||
|
||||
public virtual void Apply(ActionType type, float deltaTime, Vector2 position, IPropertyObject target)
|
||||
{
|
||||
if (!targetNames.Contains(target.Name)) return;
|
||||
if (this.type == type) Apply(deltaTime, position, target);
|
||||
|
||||
List<IPropertyObject> targets = new List<IPropertyObject>();
|
||||
targets.Add(target);
|
||||
|
||||
if (this.type == type) Apply(deltaTime, position, targets);
|
||||
}
|
||||
|
||||
protected virtual void Apply(float deltaTime, Vector2 position, IPropertyObject target)
|
||||
public virtual void Apply(ActionType type, float deltaTime, Vector2 position, List<IPropertyObject> targets)
|
||||
{
|
||||
if (this.type == type) Apply(deltaTime, position, targets);
|
||||
}
|
||||
|
||||
protected virtual void Apply(float deltaTime, Vector2 position, List<IPropertyObject> targets)
|
||||
{
|
||||
if (explosion != null) explosion.Explode(position);
|
||||
|
||||
@@ -163,42 +172,45 @@ namespace Subsurface
|
||||
for (int i = 0; i < propertyNames.Count(); i++)
|
||||
{
|
||||
ObjectProperty property;
|
||||
if (target.ObjectProperties.TryGetValue(propertyNames[i], out property))
|
||||
foreach (IPropertyObject target in targets)
|
||||
{
|
||||
ApplyToProperty(property, propertyEffects[i], deltaTime);
|
||||
if (targetNames!=null && !targetNames.Contains(target.Name)) continue;
|
||||
if (!target.ObjectProperties.TryGetValue(propertyNames[i], out property)) continue;
|
||||
|
||||
ApplyToProperty(property, propertyEffects[i], deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Apply(float deltaTime, Character character, Item item)
|
||||
{
|
||||
if (explosion != null) explosion.Explode(item.SimPosition);
|
||||
//protected virtual void Apply(float deltaTime, Character character, Item item)
|
||||
//{
|
||||
// if (explosion != null) explosion.Explode(item.SimPosition);
|
||||
|
||||
if (sound != null) sound.Play(1.0f, 1000.0f, item.body.FarseerBody);
|
||||
// if (sound != null) sound.Play(1.0f, 1000.0f, item.body.FarseerBody);
|
||||
|
||||
for (int i = 0; i < propertyNames.Count(); i++)
|
||||
{
|
||||
ObjectProperty property;
|
||||
// for (int i = 0; i < propertyNames.Count(); i++)
|
||||
// {
|
||||
// ObjectProperty property;
|
||||
|
||||
if (character!=null && character.properties.TryGetValue(propertyNames[i], out property))
|
||||
{
|
||||
ApplyToProperty(property, propertyEffects[i], deltaTime);
|
||||
}
|
||||
// if (character!=null && character.properties.TryGetValue(propertyNames[i], out property))
|
||||
// {
|
||||
// ApplyToProperty(property, propertyEffects[i], deltaTime);
|
||||
// }
|
||||
|
||||
if (item == null) continue;
|
||||
// if (item == null) continue;
|
||||
|
||||
if (item.properties.TryGetValue(propertyNames[i], out property))
|
||||
{
|
||||
ApplyToProperty(property, propertyEffects[i], deltaTime);
|
||||
}
|
||||
// if (item.properties.TryGetValue(propertyNames[i], out property))
|
||||
// {
|
||||
// ApplyToProperty(property, propertyEffects[i], deltaTime);
|
||||
// }
|
||||
|
||||
foreach (ItemComponent ic in item.components)
|
||||
{
|
||||
if (!ic.properties.TryGetValue(propertyNames[i], out property)) continue;
|
||||
ApplyToProperty(property, propertyEffects[i], deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
// foreach (ItemComponent ic in item.components)
|
||||
// {
|
||||
// if (!ic.properties.TryGetValue(propertyNames[i], out property)) continue;
|
||||
// ApplyToProperty(property, propertyEffects[i], deltaTime);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
protected void ApplyToProperty(ObjectProperty property, object value, float deltaTime)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user