using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace mmoRLserver { public enum AttackResult { Hit, Miss, Dead, NotAvailable } public class Creature { public int x = 10; public int y = 5; public static Random random = new Random(); //Combat stats public int HP = 25; public int maxHP = 25; public int strength = 10; public int experience = 0; public int armor = 0; public float hitChance = 1f; public bool dead = false; public AttackResult Damage(int amount) { this.HP -= amount; if (this.HP > maxHP) this.HP = maxHP; if (this.HP < 0) this.HP = 0; if (this.HP == 0) { this.dead = true; return AttackResult.Dead; } else return AttackResult.Hit; } public AttackResult BeAttacked(Creature assailant) { if (random.NextDouble() < hitChance) { int damage = assailant.strength; if (damage > 0) { float reduction = ((float)this.armor / 2f); int intReduction = (int)Math.Floor(reduction); float reductionDiff = reduction - intReduction; if (random.NextDouble() < reductionDiff) intReduction++; damage -= intReduction; if (damage < 1) damage = 1; } return this.Damage(damage); } else return AttackResult.Miss; } public void RecoverTo(int targetHP) { this.HP = targetHP; if (this.HP > this.maxHP) this.HP = this.maxHP; } public void Recover(int amount) { RecoverTo(this.HP + amount); } } }