public override int calculateChance(CreatureContainer user, CreatureContainer target) { int chance; bool skip = true; if (target.Creature.getEquip("Off-Hand") != null) { if (target.Creature.getEquip("Off-Hand").GetType() == typeof(ItemShield)) { defenderAttr = target.Stats.Strength * (100 + ((ItemShield)target.Creature.getEquip("Off-Hand")).getBlock()) / 100; resultMessage = "Block"; skip = false; } } if (skip) { defenderAttr = target.Stats.Dexterity; resultMessage = "Dodge"; } chance = user.Stats.Dexterity * 100 / 2 / defenderAttr; if (chance > 99) { chance = 99; } else if (chance < 1) { chance = 1; } return(chance); }
// Use this for initialization void Start() { human_Creatures = CreatureContainer.LoadHumanCreatures(humanCreaturesPath); undead_Creatures = CreatureContainer.LoadHumanCreatures(undeadCreaturesPath); foreach (Creature c in human_Creatures.creatures) { Debug.Log(c.name + " > " + c.healthPerUnit); } Debug.Log("------------------------------------"); foreach (Creature c in undead_Creatures.creatures) { Debug.Log(c.name + " > " + c.healthPerUnit); } }
public static CreatureContainer LoadHumanCreatures(string path) { TextAsset _xml = Resources.Load <TextAsset>(path); if (_xml == null) { Debug.Log("LOL"); } XmlSerializer serializer = new XmlSerializer(typeof(CreatureContainer)); StringReader reader = new StringReader(_xml.text); CreatureContainer creatures = serializer.Deserialize(reader) as CreatureContainer; reader.Close(); return(creatures); }
//Here you code the chance to hit public abstract int calculateChance(CreatureContainer user, CreatureContainer target);
//Here you code what the ability does public abstract Result runAbility(CreatureContainer user, CreatureContainer target);
public override Result runAbility(CreatureContainer user, CreatureContainer target) { int chance = calculateChance(user, target); int hit = (ConstantLib.RANDOM.Next(100) + 1); if (!(chance < hit)) { int damage; bool equipNull = false; if (user.Creature.getEquip("Main-Hand") == null) { damage = 1; equipNull = true; } else { damage = ((ItemWeapon)user.Creature.getEquip("Main-Hand")).getDamage(); } if (hit == 1) { if (equipNull) { hit = 2; } else { hit = ((ItemWeapon)user.Creature.getEquip("Main-Hand")).getCritMod(); } } else { hit = 1; } damage = (int)(damage * damageMod + user.Stats.DamageModMelee) * hit; foreach (var item in this.damageTypes) { if (target.Creature.getResistance().ContainsKey(item.Key)) { damage -= damage * item.Value * target.Creature.getResistance()[item.Key] / 10000; } } //Needs to figure out how to implement damage type on weapon into damage resistance /*if (user.getEquip("RightArm") != null) * { * foreach (var item in ((ItemWeapon)user.getEquip("RightArm")).getDamageType()) * { * if (target.getResistance().ContainsKey(item)) * { * damage = damage * (100-target.getResistance()[item]) / 100; * } * } * }*/ if (damage < 1) { resultMessage = "Immune"; } else { resultMessage = "Hit " + damage; target.Stats.HP -= damage; } } return(new Result(user, resultMessage, target)); }
public Result(CreatureContainer user, string result, CreatureContainer target) { this.result = result; this.user = user; this.target = target; }