/// <summary> /// Creates a player unit from a unit template. /// </summary> /// <param name="unitType"></param> /// <param name="attributes"></param> /// <param name="gridWidth"></param> /// <param name="gridHeight"></param> public CorePlayerUnit(PlayerUnitType unitType, UnitAttributes attributes, CorePlayer player, int gridWidth, int gridHeight) : base(EntityType.PlayerUnit, gridWidth, gridHeight) { UnitType = unitType; Player = player; _attributes = new UnitAttributes(attributes); }
private static void Register(PlayerUnitType unitType, UnitTemplate templates) { if (Templates.ContainsKey(unitType)) { throw new ArgumentException("Another template already exists with the unit type: " + unitType); } Templates[unitType] = templates; }
/// <summary> /// Finds and returns player unit of specific type. /// </summary> /// <param name="unitType">Type of player unit to be found</param> /// <returns>Player unit of given type</returns> public PlayerUnit FindPlayerUnit(PlayerUnitType unitType) { PlayerUnit unit = PlayerUnitStats.FirstOrDefault(t => t.UnitType == unitType); if (unit == null) { throw new PlayerUnitNotFoundException(unitType); } return unit; }
/// <summary> /// Creates player unit with specific values of properties. /// </summary> /// <param name="name">Name of player unit</param> /// <param name="unitType">Type of player unit</param> /// <param name="maxHealth">Max health of player unit</param> /// <param name="damage">Damage of player unit</param> /// <param name="armor">Armor of player unit</param> /// <param name="attactSpeed">Attack speed of player unit</param> /// <param name="moveSpeed">Move speed of player unit</param> /// <param name="spawnCooldown">Spawn cooldown time of player unit</param> public PlayerUnit(string name, PlayerUnitType unitType, float maxHealth, float damage, float armor, float attactSpeed, float moveSpeed, float spawnCooldown) { Name = name; UnitType = unitType; MaxHealth = maxHealth; Damage = damage; Armor = armor; AttackSpeed = attactSpeed; MoveSpeed = moveSpeed; SpawnCooldown = spawnCooldown; }
/// <summary> /// Instantiates a new copy of a unit of given type. /// </summary> /// <param name="owner">The player who owns this unit.</param> /// <param name="unitType">The type of unit to create.</param> /// <returns>A newly generated instance of a given unit type.</returns> public static CorePlayerUnit CreateNew(CorePlayer owner, PlayerUnitType unitType) { UnitTemplate templates = UnitTemplates.Get(unitType); if (templates == null) { throw new ArgumentException("Cannot find unit template for type: " + unitType); } int unitWidth = templates.UnitWidth; int unitHeight = templates.UnitHeight; UnitAttributes attributes = templates.Attributes; return(new CorePlayerUnit(unitType, attributes, owner, unitWidth, unitHeight)); }
/// <summary> /// Returns reference on player unit prefab of specific type. /// </summary> /// <param name="unitType">Type of player unit prefab to be found</param> /// <returns></returns> public GameObject GetPlayerUnitPrefab(PlayerUnitType unitType) { switch (unitType) { case PlayerUnitType.Warrior: return _warrior; case PlayerUnitType.Spearman: return _spearman; case PlayerUnitType.Axeman: return _axeman; case PlayerUnitType.Knight: return _knight; case PlayerUnitType.Crossbowman: return _crossbowman; case PlayerUnitType.Bowman: return _bowman; default: throw new PlayerUnitPrefabNotFoundException(unitType); } }
/// <summary> /// Updates damage value of player unit of specific type. /// </summary> /// <param name="unitType">Type of player unit to be updated</param> /// <param name="newDamage">New damage of player unit</param> public void UpdatePlayerUnitDamage(PlayerUnitType unitType, float newDamage) { PlayerUnit unit = FindPlayerUnit(unitType); unit.Damage = newDamage; }
/// <summary> /// Creates exception instance. /// </summary> /// <param name="unitType">Type of already existing player unit</param> public PlayerUnitAlreadyExistsException(PlayerUnitType unitType) { _unitType = unitType; }
/// <summary> /// Creates expcetion instance. /// </summary> /// <param name="unitType">Type of not found player unit</param> public PlayerUnitNotFoundException(PlayerUnitType unitType) { _unitType = unitType; }
public static PlayerUnitTextureBank Get(PlayerUnitType unitType) { return(Textures[unitType] == null ? throw new ArgumentException("No texture bank exist for unit type: " + unitType) : Textures[unitType]); }
/// <summary> /// Updates spawn cooldown time of player unit of specific type. /// </summary> /// <param name="unitType">Type of player unit to be updated</param> /// <param name="newSpawnCooldown">New spawn cooldown time of player unit</param> public void UpdatePlayerUnitSpawnCooldown(PlayerUnitType unitType, float newSpawnCooldown) { PlayerUnit unit = FindPlayerUnit(unitType); unit.SpawnCooldown = newSpawnCooldown; }
/// <summary> /// Updates name of player unit of specific type. /// </summary> /// <param name="unitType">Type of player unit to be updated</param> /// <param name="newName">New name of player unit</param> public void UpdatePlayerUnitName(PlayerUnitType unitType, string newName) { PlayerUnit unit = FindPlayerUnit(unitType); unit.Name = newName; }
/// <summary> /// Updates move speed of player unit of specific type. /// </summary> /// <param name="unitType">Type of player unit to be updated</param> /// <param name="newMoveSpeed">New move speed of player unit</param> public void UpdatePlayerUnitMoveSpeed(PlayerUnitType unitType, float newMoveSpeed) { PlayerUnit unit = FindPlayerUnit(unitType); unit.MoveSpeed = newMoveSpeed; }
/// <summary> /// Updates max health of player unit of specific type. /// </summary> /// <param name="unitType">Type of player unit to be updated</param> /// <param name="newMaxHealth">New max health of player unit</param> public void UpdatePlayerUnitMaxHealth(PlayerUnitType unitType, float newMaxHealth) { PlayerUnit unit = FindPlayerUnit(unitType); unit.MaxHealth = newMaxHealth; }
/// <summary> /// Updates attack speed of player unit od specific type. /// </summary> /// <param name="unitType">Type of player unit to be updated</param> /// <param name="newAttackSpeed">New attack speed of player unit</param> public void UpdatePlayerUnitAttactSpeed(PlayerUnitType unitType, float newAttackSpeed) { PlayerUnit unit = FindPlayerUnit(unitType); unit.AttackSpeed = newAttackSpeed; }
/// <summary> /// Updates armor value of player unit od specific type. /// </summary> /// <param name="unitType">Type of player unit to be updated</param> /// <param name="newArmor">New armor of player unit</param> public void UpdatePlayerUnitArmor(PlayerUnitType unitType, float newArmor) { PlayerUnit unit = FindPlayerUnit(unitType); unit.Armor = newArmor; }
/// <summary> /// Sets reference on player unit prefab of specific type. /// </summary> /// <param name="unitType">Player unit type of prefab to be set</param> /// <param name="prefab">Reference on prefab</param> public void SetPlayerUnitPrefab(PlayerUnitType unitType, GameObject prefab) { if (prefab == null) { throw new ArgumentNullException("prefab"); } switch (unitType) { case PlayerUnitType.Warrior: _warrior = prefab; break; case PlayerUnitType.Spearman: _spearman = prefab; break; case PlayerUnitType.Axeman: _axeman = prefab; break; case PlayerUnitType.Knight: _knight = prefab; break; case PlayerUnitType.Crossbowman: _crossbowman = prefab; break; case PlayerUnitType.Bowman: _bowman = prefab; break; default: throw new ArgumentOutOfRangeException("unitType", unitType, "Unknown player unit type " + unitType + "."); } }
public static UnitTemplate Get(PlayerUnitType unitType) { return(Templates[unitType]); }
private static void Register(PlayerUnitType unitType, PlayerUnitTextureBank textureBank) { Textures.Add(unitType, textureBank); }