Spell.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace D21._1
  5. {
  6. public class SpellSequence : IEnumerable<Spell>
  7. {
  8. public Spell Spell;
  9. public SpellSequence NextEntry;
  10. public int Count() => (NextEntry?.Count() ?? 0) + 1;
  11. public override int GetHashCode() => HashCode.Combine(Spell, NextEntry);
  12. public bool Contains(Spell i)
  13. {
  14. var cur = this;
  15. while (cur != null)
  16. {
  17. if (i.Equals(cur.Spell)) return true;
  18. cur = cur.NextEntry;
  19. }
  20. return false;
  21. }
  22. public int Position(Spell i)
  23. {
  24. var cur = this;
  25. int pos = 0;
  26. while (cur != null)
  27. {
  28. if (i.Equals(cur.Spell)) return pos;
  29. cur = cur.NextEntry;
  30. pos++;
  31. }
  32. return -1;
  33. }
  34. public IEnumerator<Spell> GetEnumerator()
  35. {
  36. var cur = this;
  37. while (cur != null)
  38. {
  39. yield return cur.Spell;
  40. cur = cur.NextEntry;
  41. }
  42. }
  43. IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
  44. }
  45. public abstract class Spell
  46. {
  47. public int Cost { get; protected set; }
  48. public string Name { get; protected set; }
  49. public int? EffectDuration { get; protected set; }
  50. public override bool Equals(object obj) => obj is Spell item && Name.Equals(item.Name, StringComparison.OrdinalIgnoreCase);
  51. public override int GetHashCode() => HashCode.Combine(Name);
  52. public virtual void ActiveEffect(Heroe h, MonsterBoss b) { }
  53. public virtual void ApplyEffect(Heroe h, MonsterBoss b) { }
  54. public virtual void WornOutEffect(Heroe h, MonsterBoss b) { }
  55. }
  56. public class MagicMissile : Spell
  57. {
  58. public MagicMissile()
  59. {
  60. Name = "Magic Missile";
  61. Cost = 53;
  62. }
  63. public override void ActiveEffect(Heroe h, MonsterBoss b) => b.HitPoints -= 4;
  64. }
  65. public class Drain : Spell
  66. {
  67. public Drain()
  68. {
  69. Name = "Drain";
  70. Cost = 73;
  71. }
  72. public override void ActiveEffect(Heroe h, MonsterBoss b)
  73. {
  74. b.HitPoints -= 2;
  75. h.HitPoints += 2;
  76. }
  77. }
  78. public class Shield : Spell
  79. {
  80. public Shield()
  81. {
  82. Name = "Shield";
  83. EffectDuration = 6;
  84. Cost = 113;
  85. }
  86. public override void ActiveEffect(Heroe h, MonsterBoss b) => h.Armor += 7;
  87. public override void WornOutEffect(Heroe h, MonsterBoss b) => h.Armor -= 7;
  88. }
  89. public class Poison : Spell
  90. {
  91. public Poison()
  92. {
  93. Name = "Poison";
  94. EffectDuration = 6;
  95. Cost = 173;
  96. }
  97. public override void ApplyEffect(Heroe h, MonsterBoss b) => b.HitPoints -= 3;
  98. }
  99. public class Recharge : Spell
  100. {
  101. public Recharge()
  102. {
  103. Name = "Recharge";
  104. EffectDuration = 5;
  105. Cost = 229;
  106. }
  107. public override void ApplyEffect(Heroe h, MonsterBoss b) => h.Mana += 101;
  108. }
  109. }