using System;
using System.Collections.Generic;
using System.Text;
namespace Substrate
{
///
/// Provides named id values for known enchantment types.
///
/// See for additional information.
public class EnchantmentType
{
public const int PROTECTION = 0;
public const int FIRE_PROTECTION = 1;
public const int FEATHER_FALLING = 2;
public const int BLAST_PROTECTION = 3;
public const int PROJECTILE_PROTECTION = 4;
public const int RESPIRATION = 5;
public const int AQUA_AFFINITY = 6;
public const int SHARPNESS = 16;
public const int SMITE = 17;
public const int BANE_OF_ARTHROPODS = 18;
public const int KNOCKBACK = 19;
public const int FIRE_ASPECT = 20;
public const int LOOTING = 21;
public const int EFFICIENCY = 32;
public const int SILK_TOUCH = 33;
public const int UNBREAKING = 34;
public const int FORTUNE = 35;
}
///
/// Provides information on a specific type of enchantment.
///
/// By default, all known MC enchantment types are already defined and registered, assuming Substrate
/// is up to date with the current MC version.
/// New enchantment types may be created and used at runtime, and will automatically populate various static lookup tables
/// in the class.
public class EnchantmentInfo
{
private static Random _rand = new Random();
private class CacheTableDict : ICacheTable
{
private Dictionary _cache;
public T this[int index]
{
get
{
T val;
if (_cache.TryGetValue(index, out val)) {
return val;
}
return default(T);
}
}
public CacheTableDict (Dictionary cache)
{
_cache = cache;
}
}
private static readonly Dictionary _enchTable;
private int _id = 0;
private string _name = "";
private int _maxLevel = 0;
private static readonly CacheTableDict _enchTableCache;
///
/// Gets the lookup table for id-to-info values.
///
public static ICacheTable EnchantmentTable
{
get { return _enchTableCache; }
}
///
/// Gets the id of the enchantment type.
///
public int ID
{
get { return _id; }
}
///
/// Gets the name of the enchantment type.
///
public string Name
{
get { return _name; }
}
///
/// Gets the maximum level allowed for this enchantment type.
///
public int MaxLevel
{
get { return _maxLevel; }
}
///
/// Constructs a new record for the given enchantment id.
///
/// The id of an item type.
public EnchantmentInfo (int id)
{
_id = id;
_enchTable[_id] = this;
}
///
/// Constructs a new record for the given enchantment id and name.
///
/// The id of an item type.
/// The name of an item type.
public EnchantmentInfo (int id, string name)
{
_id = id;
_name = name;
_enchTable[_id] = this;
}
///
/// Sets the maximum level for this enchantment type.
///
/// The maximum allowed level.
/// The object instance used to invoke this method.
public EnchantmentInfo SetMaxLevel (int level)
{
_maxLevel = level;
return this;
}
///
/// Chooses a registered enchantment type at random and returns it.
///
///
public static EnchantmentInfo GetRandomEnchantment ()
{
List list = new List(_enchTable.Values);
return list[_rand.Next(list.Count)];
}
public static EnchantmentInfo Protection;
public static EnchantmentInfo FireProtection;
public static EnchantmentInfo FeatherFalling;
public static EnchantmentInfo BlastProtection;
public static EnchantmentInfo ProjectileProtection;
public static EnchantmentInfo Respiration;
public static EnchantmentInfo AquaAffinity;
public static EnchantmentInfo Sharpness;
public static EnchantmentInfo Smite;
public static EnchantmentInfo BaneOfArthropods;
public static EnchantmentInfo Knockback;
public static EnchantmentInfo FireAspect;
public static EnchantmentInfo Looting;
public static EnchantmentInfo Efficiency;
public static EnchantmentInfo SilkTouch;
public static EnchantmentInfo Unbreaking;
public static EnchantmentInfo Fortune;
static EnchantmentInfo ()
{
_enchTable = new Dictionary();
_enchTableCache = new CacheTableDict(_enchTable);
Protection = new EnchantmentInfo(EnchantmentType.PROTECTION, "Protection").SetMaxLevel(4);
FireProtection = new EnchantmentInfo(EnchantmentType.FIRE_PROTECTION, "Fire Protection").SetMaxLevel(4);
FeatherFalling = new EnchantmentInfo(EnchantmentType.FEATHER_FALLING, "Feather Falling").SetMaxLevel(4);
BlastProtection = new EnchantmentInfo(EnchantmentType.BLAST_PROTECTION, "Blast Protection").SetMaxLevel(4);
ProjectileProtection = new EnchantmentInfo(EnchantmentType.PROJECTILE_PROTECTION, "Projectile Protection").SetMaxLevel(4);
Respiration = new EnchantmentInfo(EnchantmentType.RESPIRATION, "Respiration").SetMaxLevel(3);
AquaAffinity = new EnchantmentInfo(EnchantmentType.AQUA_AFFINITY, "Aqua Affinity").SetMaxLevel(1);
Sharpness = new EnchantmentInfo(EnchantmentType.SHARPNESS, "Sharpness").SetMaxLevel(5);
Smite = new EnchantmentInfo(EnchantmentType.SMITE, "Smite").SetMaxLevel(5);
BaneOfArthropods = new EnchantmentInfo(EnchantmentType.BANE_OF_ARTHROPODS, "Bane of Arthropods").SetMaxLevel(5);
Knockback = new EnchantmentInfo(EnchantmentType.KNOCKBACK, "Knockback").SetMaxLevel(2);
FireAspect = new EnchantmentInfo(EnchantmentType.FIRE_ASPECT, "Fire Aspect").SetMaxLevel(2);
Looting = new EnchantmentInfo(EnchantmentType.LOOTING, "Looting").SetMaxLevel(3);
Efficiency = new EnchantmentInfo(EnchantmentType.EFFICIENCY, "Efficiency").SetMaxLevel(5);
SilkTouch = new EnchantmentInfo(EnchantmentType.SILK_TOUCH, "Silk Touch").SetMaxLevel(1);
Unbreaking = new EnchantmentInfo(EnchantmentType.UNBREAKING, "Unbreaking").SetMaxLevel(4);
Fortune = new EnchantmentInfo(EnchantmentType.FORTUNE, "Fortune").SetMaxLevel(3);
}
}
}