2011-04-06 19:41:57 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2011-04-06 22:01:22 +00:00
|
|
|
|
namespace Substrate.Entities
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-30 04:41:29 +00:00
|
|
|
|
using Substrate.Nbt;
|
2011-12-04 23:55:03 +00:00
|
|
|
|
using Substrate.Core;
|
2011-04-06 19:41:57 +00:00
|
|
|
|
|
2011-09-21 04:38:34 +00:00
|
|
|
|
/// <summary>
|
2011-12-04 23:55:03 +00:00
|
|
|
|
/// Encompasses data in the "ActiveEffects" compound attribute of mob entity types, used to specify potion effects
|
2011-09-21 04:38:34 +00:00
|
|
|
|
/// </summary>
|
2011-12-04 23:55:03 +00:00
|
|
|
|
public class ActiveEffects : ICopyable<ActiveEffects>
|
2011-09-21 04:38:34 +00:00
|
|
|
|
{
|
|
|
|
|
private byte _id;
|
|
|
|
|
private byte _amplifier;
|
|
|
|
|
private int _duration;
|
|
|
|
|
|
2011-12-04 23:55:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the ID of the potion effect type.
|
|
|
|
|
/// </summary>
|
2011-09-21 04:38:34 +00:00
|
|
|
|
public int Id
|
|
|
|
|
{
|
|
|
|
|
get { return _id; }
|
|
|
|
|
set { _id = (byte)value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-04 23:55:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the amplification of the potion effect.
|
|
|
|
|
/// </summary>
|
2011-09-21 04:38:34 +00:00
|
|
|
|
public int Amplifier
|
|
|
|
|
{
|
|
|
|
|
get { return _amplifier; }
|
|
|
|
|
set { _amplifier = (byte)value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-04 23:55:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the remaining duration of the potion effect.
|
|
|
|
|
/// </summary>
|
2011-09-21 04:38:34 +00:00
|
|
|
|
public int Duration
|
|
|
|
|
{
|
|
|
|
|
get { return _duration; }
|
|
|
|
|
set { _duration = value; }
|
|
|
|
|
}
|
2011-12-04 23:55:03 +00:00
|
|
|
|
|
2011-12-16 04:03:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determine if the combination of properties in this ActiveEffects is valid.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsValid
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return !(_id == 0 || _amplifier == 0 || _duration == 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-04 23:55:03 +00:00
|
|
|
|
#region ICopyable<ActiveEffects> Members
|
|
|
|
|
|
|
|
|
|
public ActiveEffects Copy ()
|
|
|
|
|
{
|
|
|
|
|
ActiveEffects ae = new ActiveEffects();
|
|
|
|
|
ae._amplifier = _amplifier;
|
|
|
|
|
ae._duration = _duration;
|
|
|
|
|
ae._id = _id;
|
|
|
|
|
|
|
|
|
|
return ae;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2011-09-21 04:38:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-14 19:34:49 +00:00
|
|
|
|
public class EntityMob : TypedEntity
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-08-14 19:34:49 +00:00
|
|
|
|
public static readonly SchemaNodeCompound MobSchema = TypedEntity.Schema.MergeInto(new SchemaNodeCompound("")
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-11-05 18:17:57 +00:00
|
|
|
|
new SchemaNodeString("id", TypeId),
|
2011-06-20 03:51:40 +00:00
|
|
|
|
new SchemaNodeScaler("AttackTime", TagType.TAG_SHORT),
|
|
|
|
|
new SchemaNodeScaler("DeathTime", TagType.TAG_SHORT),
|
|
|
|
|
new SchemaNodeScaler("Health", TagType.TAG_SHORT),
|
|
|
|
|
new SchemaNodeScaler("HurtTime", TagType.TAG_SHORT),
|
2011-09-21 04:38:34 +00:00
|
|
|
|
new SchemaNodeCompound("ActiveEffects", SchemaOptions.OPTIONAL)
|
|
|
|
|
{
|
|
|
|
|
new SchemaNodeScaler("Id", TagType.TAG_BYTE),
|
|
|
|
|
new SchemaNodeScaler("Amplifier", TagType.TAG_BYTE),
|
|
|
|
|
new SchemaNodeScaler("Duration", TagType.TAG_INT),
|
|
|
|
|
},
|
2011-04-06 19:41:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
2011-11-05 18:17:57 +00:00
|
|
|
|
public static string TypeId
|
|
|
|
|
{
|
|
|
|
|
get { return "Mob"; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 19:41:57 +00:00
|
|
|
|
private short _attackTime;
|
|
|
|
|
private short _deathTime;
|
|
|
|
|
private short _health;
|
|
|
|
|
private short _hurtTime;
|
|
|
|
|
|
2011-09-21 04:38:34 +00:00
|
|
|
|
private ActiveEffects _activeEffects;
|
|
|
|
|
|
2011-04-06 19:41:57 +00:00
|
|
|
|
public int AttackTime
|
|
|
|
|
{
|
|
|
|
|
get { return _attackTime; }
|
|
|
|
|
set { _attackTime = (short)value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int DeathTime
|
|
|
|
|
{
|
|
|
|
|
get { return _deathTime; }
|
|
|
|
|
set { _deathTime = (short)value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Health
|
|
|
|
|
{
|
|
|
|
|
get { return _health; }
|
|
|
|
|
set { _health = (short)value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int HurtTime
|
|
|
|
|
{
|
|
|
|
|
get { return _hurtTime; }
|
|
|
|
|
set { _hurtTime = (short)value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-21 04:38:34 +00:00
|
|
|
|
public ActiveEffects ActiveEffects
|
|
|
|
|
{
|
|
|
|
|
get { return _activeEffects; }
|
|
|
|
|
set { _activeEffects = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-05 18:17:57 +00:00
|
|
|
|
protected EntityMob (string id)
|
|
|
|
|
: base(id)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-12-04 23:55:03 +00:00
|
|
|
|
_activeEffects = new ActiveEffects();
|
2011-04-06 19:41:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-05 18:17:57 +00:00
|
|
|
|
public EntityMob ()
|
|
|
|
|
: this(TypeId)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-14 19:34:49 +00:00
|
|
|
|
public EntityMob (TypedEntity e)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
: base(e)
|
|
|
|
|
{
|
|
|
|
|
EntityMob e2 = e as EntityMob;
|
|
|
|
|
if (e2 != null) {
|
|
|
|
|
_attackTime = e2._attackTime;
|
|
|
|
|
_deathTime = e2._deathTime;
|
|
|
|
|
_health = e2._health;
|
|
|
|
|
_hurtTime = e2._hurtTime;
|
2011-12-04 23:55:03 +00:00
|
|
|
|
_activeEffects = e2._activeEffects.Copy();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_activeEffects = new ActiveEffects();
|
2011-04-06 19:41:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region INBTObject<Entity> Members
|
|
|
|
|
|
2011-08-14 19:34:49 +00:00
|
|
|
|
public override TypedEntity LoadTree (TagNode tree)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
TagNodeCompound ctree = tree as TagNodeCompound;
|
2011-04-06 19:41:57 +00:00
|
|
|
|
if (ctree == null || base.LoadTree(tree) == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 02:50:42 +00:00
|
|
|
|
_attackTime = ctree["AttackTime"].ToTagShort();
|
|
|
|
|
_deathTime = ctree["DeathTime"].ToTagShort();
|
|
|
|
|
_health = ctree["Health"].ToTagShort();
|
|
|
|
|
_hurtTime = ctree["HurtTime"].ToTagShort();
|
2011-04-06 19:41:57 +00:00
|
|
|
|
|
2011-09-21 04:38:34 +00:00
|
|
|
|
if (ctree.ContainsKey("ActiveEffects")) {
|
|
|
|
|
TagNodeCompound ae = ctree["ActiveEffects"].ToTagCompound();
|
|
|
|
|
|
|
|
|
|
_activeEffects = new ActiveEffects();
|
|
|
|
|
_activeEffects.Id = ae["Id"].ToTagByte();
|
|
|
|
|
_activeEffects.Amplifier = ae["Amplifier"].ToTagByte();
|
|
|
|
|
_activeEffects.Duration = ae["Duration"].ToTagInt();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 19:41:57 +00:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override TagNode BuildTree ()
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
TagNodeCompound tree = base.BuildTree() as TagNodeCompound;
|
|
|
|
|
tree["AttackTime"] = new TagNodeShort(_attackTime);
|
|
|
|
|
tree["DeathTime"] = new TagNodeShort(_deathTime);
|
|
|
|
|
tree["Health"] = new TagNodeShort(_health);
|
|
|
|
|
tree["HurtTime"] = new TagNodeShort(_hurtTime);
|
2011-04-06 19:41:57 +00:00
|
|
|
|
|
2011-12-16 04:03:57 +00:00
|
|
|
|
if (_activeEffects != null && _activeEffects.IsValid) {
|
2011-09-21 04:38:34 +00:00
|
|
|
|
TagNodeCompound ae = new TagNodeCompound();
|
|
|
|
|
ae["Id"] = new TagNodeByte((byte)_activeEffects.Id);
|
|
|
|
|
ae["Amplifier"] = new TagNodeByte((byte)_activeEffects.Amplifier);
|
|
|
|
|
ae["Duration"] = new TagNodeInt(_activeEffects.Duration);
|
|
|
|
|
|
|
|
|
|
tree["ActiveEffects"] = ae;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-06 19:41:57 +00:00
|
|
|
|
return tree;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 03:51:40 +00:00
|
|
|
|
public override bool ValidateTree (TagNode tree)
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
2011-06-30 04:57:18 +00:00
|
|
|
|
return new NbtVerifier(tree, MobSchema).Verify();
|
2011-04-06 19:41:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region ICopyable<Entity> Members
|
|
|
|
|
|
2011-08-14 19:34:49 +00:00
|
|
|
|
public override TypedEntity Copy ()
|
2011-04-06 19:41:57 +00:00
|
|
|
|
{
|
|
|
|
|
return new EntityMob(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|