/* * MIT License * * Copyright (c) 2018 Clark Yang * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ using System; using System.Collections.Generic; using System.Collections.ObjectModel; namespace Loxodon.Framework.Examples.Domains { public class Equipment { private float health = 0; private float attackDamage = 0; private float abilityPower = 0; private float armor = 0; private float magicResist = 0; private List crystals; public Equipment() : this(new List()) { } public Equipment(List crystals) { this.crystals = crystals; foreach (var crystal in this.crystals) { if (crystal != null) Apply(crystal); } } /// /// 装备ID /// public int Id { get; set; } /// /// 玩家ID /// public string PlayerId { get; set; } /// /// 级别 /// public int Level { get; set; } /// /// 镶嵌的宝石 /// public ReadOnlyCollection Crystals { get { return crystals.AsReadOnly(); } } /// /// 是否被穿戴 /// public bool Used { get; set; } /// /// 装备信息 /// public EquipmentInfo Definition { get; set; } public float Health { get { return Definition.Health + this.health; } } /// /// 攻击力伤害 /// public float AttackDamage { get { return Definition.AttackDamage + this.attackDamage; } } /// /// 法术强度 /// public float AbilityPower { get { return Definition.AbilityPower + this.abilityPower; } } /// /// 护甲值 /// public float Armor { get { return Definition.Armor + this.armor; } } /// /// 魔法抗性 /// public float MagicResist { get { return Definition.MagicResist + this.magicResist; } } /// /// 镶嵌宝石 /// /// /// /// public bool InlayCrystal(int index, CrystalInfo crystal) { if (index < 0) throw new IndexOutOfRangeException(); while (index >= crystals.Count) crystals.Add(null); crystals[index] = crystal; Apply(crystal); return true; } /// /// 卸载宝石 /// /// /// public CrystalInfo UnloadCrystal(int index) { if (index < 0 || index > crystals.Count) throw new IndexOutOfRangeException(); CrystalInfo crystal = crystals[index]; crystals[index] = null; this.Remove(crystal); return crystal; } private void Apply(CrystalInfo crystal) { if (crystal == null) return; switch (crystal.Key) { case "health": this.health += crystal.Value; break; case "attackDamage": this.attackDamage += crystal.Value; break; case "abilityPower": this.abilityPower += crystal.Value; break; case "armor": this.armor += crystal.Value; break; case "magicResist": this.magicResist += crystal.Value; break; } } private void Remove(CrystalInfo crystal) { if (crystal == null) return; switch (crystal.Key) { case "health": this.health -= crystal.Value; break; case "attackDamage": this.attackDamage -= crystal.Value; break; case "abilityPower": this.abilityPower -= crystal.Value; break; case "armor": this.armor -= crystal.Value; break; case "magicResist": this.magicResist -= crystal.Value; break; } } } }