SpellObject.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. using Client.MirGraphics;
  2. using Client.MirScenes;
  3. using Client.MirSounds;
  4. using S = ServerPackets;
  5. namespace Client.MirObjects
  6. {
  7. class SpellObject : MapObject
  8. {
  9. public override ObjectType Race
  10. {
  11. get { return ObjectType.Spell; }
  12. }
  13. public override bool Blocking
  14. {
  15. get { return false; }
  16. }
  17. public Spell Spell;
  18. public Point AnimationOffset = new(0, 0);
  19. public int FrameCount, FrameInterval, FrameIndex;
  20. public bool Repeat, Ended;
  21. public SpellObject(uint objectID) : base(objectID)
  22. {
  23. }
  24. public void Load(S.ObjectSpell info)
  25. {
  26. CurrentLocation = info.Location;
  27. MapLocation = info.Location;
  28. GameScene.Scene.MapControl.AddObject(this);
  29. Spell = info.Spell;
  30. Direction = info.Direction;
  31. Repeat = true;
  32. Ended = false;
  33. switch (Spell)
  34. {
  35. case Spell.TrapHexagon:
  36. BodyLibrary = Libraries.Magic;
  37. DrawFrame = 1390;
  38. FrameInterval = 100;
  39. FrameCount = 10;
  40. Blend = true;
  41. break;
  42. case Spell.FireWall:
  43. BodyLibrary = Libraries.Magic;
  44. DrawFrame = 1630;
  45. FrameInterval = 120;
  46. FrameCount = 6;
  47. Light = 3;
  48. Blend = true;
  49. break;
  50. case Spell.PoisonCloud:
  51. BodyLibrary = Libraries.Magic2;
  52. DrawFrame = 1650;
  53. FrameInterval = 120;
  54. FrameCount = 20;
  55. Light = 3;
  56. Blend = true;
  57. break;
  58. case Spell.DigOutZombie:
  59. BodyLibrary = (ushort)Monster.DigOutZombie < Libraries.Monsters.Count() ? Libraries.Monsters[(ushort)Monster.DigOutZombie] : Libraries.Magic;
  60. DrawFrame = 304 + (byte) Direction;
  61. FrameCount = 0;
  62. Blend = false;
  63. break;
  64. case Spell.Blizzard:
  65. AnimationOffset = new Point(0, -20);
  66. BodyLibrary = Libraries.Magic2;
  67. DrawFrame = 1550;
  68. FrameInterval = 100;
  69. FrameCount = 30;
  70. Light = 3;
  71. Blend = true;
  72. Repeat = false;
  73. break;
  74. case Spell.MeteorStrike:
  75. AnimationOffset = new Point(0, -20);
  76. MapControl.Effects.Add(new Effect(Libraries.Magic2, 1600, 10, 800, CurrentLocation) { Repeat = true, RepeatUntil = CMain.Time + 3000 });
  77. BodyLibrary = Libraries.Magic2;
  78. DrawFrame = 1610;
  79. FrameInterval = 100;
  80. FrameCount = 30;
  81. Light = 3;
  82. Blend = true;
  83. Repeat = false;
  84. break;
  85. case Spell.Rubble:
  86. if (Direction == 0)
  87. BodyLibrary = null;
  88. else
  89. {
  90. BodyLibrary = Libraries.Effect;
  91. DrawFrame = 64 + Math.Min(4, (int)(Direction - 1));
  92. FrameCount = 1;
  93. FrameInterval = 10000;
  94. }
  95. break;
  96. case Spell.Reincarnation:
  97. BodyLibrary = Libraries.Magic2;
  98. DrawFrame = 1680;
  99. FrameInterval = 100;
  100. FrameCount = 10;
  101. Light = 1;
  102. Blend = true;
  103. Repeat = true;
  104. break;
  105. case Spell.ExplosiveTrap:
  106. BodyLibrary = Libraries.Magic3;
  107. if (info.Param)
  108. {
  109. DrawFrame = 1570;
  110. FrameInterval = 100;
  111. FrameCount = 9;
  112. Repeat = false;
  113. SoundManager.PlaySound(20000 + 124 * 10 + 5);//Boom for all players in range
  114. }
  115. else
  116. {
  117. DrawFrame = 1560;
  118. FrameInterval = 100;
  119. FrameCount = 10;
  120. Repeat = true;
  121. }
  122. //Light = 1;
  123. Blend = true;
  124. break;
  125. case Spell.Trap:
  126. BodyLibrary = Libraries.Magic2;
  127. DrawFrame = 2360;
  128. FrameInterval = 100;
  129. FrameCount = 8;
  130. Blend = true;
  131. break;
  132. case Spell.MapLightning:
  133. MapControl.Effects.Add(new Effect(Libraries.Dragon, 400 + (CMain.Random.Next(3) * 10), 5, 600, CurrentLocation));
  134. SoundManager.PlaySound(8301);
  135. break;
  136. case Spell.MapLava:
  137. MapControl.Effects.Add(new Effect(Libraries.Dragon, 440, 20, 1600, CurrentLocation) { Blend = false });
  138. MapControl.Effects.Add(new Effect(Libraries.Dragon, 470, 10, 800, CurrentLocation));
  139. SoundManager.PlaySound(8302);
  140. break;
  141. case Spell.MapQuake1:
  142. MapControl.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.HellLord], 27, 12, 1200, CurrentLocation) { Blend = false });
  143. SoundManager.PlaySound(8304);
  144. break;
  145. case Spell.MapQuake2:
  146. MapControl.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.HellLord], 39, 13, 1300, CurrentLocation) { Blend = false });
  147. SoundManager.PlaySound(8304);
  148. break;
  149. case Spell.DigOutArmadillo:
  150. BodyLibrary = Libraries.Monsters[(ushort)Monster.Armadillo];
  151. DrawFrame = 472 + (byte)Direction;
  152. FrameCount = 0;
  153. Blend = false;
  154. break;
  155. case Spell.GeneralMeowMeowThunder:
  156. MapControl.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.GeneralMeowMeow], 522, 7, 700, CurrentLocation) { Blend = true });
  157. SoundManager.PlaySound(8321);
  158. break;
  159. case Spell.StoneGolemQuake:
  160. BodyLibrary = Libraries.Monsters[(ushort)Monster.StoneGolem];
  161. DrawFrame = 368 + (int)Direction * 8;
  162. FrameInterval = 100;
  163. FrameCount = 8;
  164. Light = 0;
  165. Blend = false;
  166. Repeat = false;
  167. SoundManager.PlaySound(8304);
  168. break;
  169. case Spell.EarthGolemPile:
  170. BodyLibrary = Libraries.Monsters[(ushort)Monster.EarthGolem];
  171. DrawFrame = 441;
  172. FrameInterval = 100;
  173. FrameCount = 8;
  174. Light = 0;
  175. Blend = false;
  176. Repeat = false;
  177. SoundManager.PlaySound(8331);
  178. break;
  179. case Spell.TreeQueenMassRoots:
  180. BodyLibrary = Libraries.Monsters[(ushort)Monster.TreeQueen];
  181. DrawFrame = 82;
  182. FrameInterval = 100;
  183. FrameCount = 15;
  184. Blend = false;
  185. Repeat = false;
  186. SoundManager.PlaySound(8341);
  187. MapControl.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.TreeQueen], 97, 14, 1400, CurrentLocation) { Blend = true });
  188. break;
  189. case Spell.TreeQueenGroundRoots:
  190. BodyLibrary = Libraries.Monsters[(ushort)Monster.TreeQueen];
  191. DrawFrame = 48;
  192. FrameInterval = 100;
  193. FrameCount = 9;
  194. Blend = false;
  195. Repeat = false;
  196. SoundManager.PlaySound(8342);
  197. MapControl.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.TreeQueen], 57, 9, 900, CurrentLocation) { Blend = true });
  198. break;
  199. case Spell.TreeQueenRoot:
  200. BodyLibrary = Libraries.Monsters[(ushort)Monster.TreeQueen];
  201. DrawFrame = 111;
  202. FrameInterval = 100;
  203. FrameCount = 15;
  204. Blend = false;
  205. Repeat = false;
  206. SoundManager.PlaySound(8343);
  207. break;
  208. case Spell.TucsonGeneralRock:
  209. MapControl.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.TucsonGeneral], 552, 20, 2000, CurrentLocation) { Repeat = false, Blend = false });
  210. BodyLibrary = Libraries.Monsters[(ushort)Monster.TucsonGeneral];
  211. DrawFrame = 572;
  212. FrameInterval = 100;
  213. FrameCount = 20;
  214. Light = 1;
  215. Blend = true;
  216. Repeat = false;
  217. break;
  218. case Spell.Portal:
  219. BodyLibrary = Libraries.Magic2;
  220. DrawFrame = 2360;
  221. FrameInterval = 100;
  222. FrameCount = 8;
  223. Blend = true;
  224. break;
  225. case Spell.HealingCircle:
  226. BodyLibrary = Libraries.Magic3;
  227. DrawFrame = 630;
  228. FrameInterval = 80;
  229. FrameCount = 11;
  230. Light = 3;
  231. Blend = true;
  232. break;
  233. case Spell.FlyingStatueIceTornado:
  234. BodyLibrary = Libraries.Monsters[(ushort)Monster.FlyingStatue];
  235. DrawFrame = 314;
  236. FrameInterval = 100;
  237. FrameCount = 20;
  238. Blend = true;
  239. Repeat = false;
  240. SoundManager.PlaySound(8303);
  241. break;
  242. case Spell.DarkOmaKingNuke:
  243. BodyLibrary = Libraries.Monsters[(ushort)Monster.DarkOmaKing];
  244. DrawFrame = 1630 + (int)Direction * 9;
  245. FrameInterval = 100;
  246. FrameCount = 9;
  247. Blend = true;
  248. Repeat = false;
  249. SoundManager.PlaySound(((ushort)Monster.DarkOmaKing * 10) + 9);
  250. break;
  251. case Spell.HornedSorcererDustTornado:
  252. BodyLibrary = Libraries.Monsters[(ushort)Monster.HornedSorceror];
  253. DrawFrame = 634;
  254. FrameInterval = 100;
  255. FrameCount = 10;
  256. Blend = true;
  257. Repeat = true;
  258. SoundManager.PlaySound(8306);
  259. break;
  260. case Spell.HornedCommanderRockFall:
  261. BodyLibrary = Libraries.Monsters[(ushort)Monster.HornedCommander];
  262. DrawFrame = 1066;
  263. FrameInterval = 100;
  264. FrameCount = 12;
  265. Blend = true;
  266. Repeat = true;
  267. SoundManager.PlaySound(8456);
  268. break;
  269. case Spell.HornedCommanderRockSpike:
  270. BodyLibrary = Libraries.Monsters[(ushort)Monster.HornedCommander];
  271. DrawFrame = 1190;
  272. FrameInterval = 100;
  273. FrameCount = 9;
  274. Blend = false;
  275. Repeat = true;
  276. SoundManager.PlaySound(8457);
  277. MapControl.Effects.Add(new Effect(Libraries.Monsters[(ushort)Monster.HornedCommander], 1199, 9, 900, CurrentLocation) { Blend = true });
  278. break;
  279. }
  280. NextMotion = CMain.Time + FrameInterval;
  281. NextMotion -= NextMotion % 100;
  282. }
  283. public override void Process()
  284. {
  285. if (CMain.Time >= NextMotion)
  286. {
  287. if (++FrameIndex >= FrameCount && Repeat)
  288. {
  289. FrameIndex = 0;
  290. Ended = true;
  291. }
  292. NextMotion = CMain.Time + FrameInterval;
  293. switch (Spell)
  294. {
  295. case Spell.TucsonGeneralRock:
  296. if (FrameIndex == 10) SoundManager.PlaySound(8305);
  297. break;
  298. case Spell.HornedSorcererDustTornado:
  299. if (FrameIndex == 0 && CMain.Random.Next(3) == 0) SoundManager.PlaySound(8306);
  300. break;
  301. case Spell.HornedCommanderRockSpike:
  302. if (Ended)
  303. {
  304. DrawFrame = 1198;
  305. FrameCount = 1;
  306. FrameIndex = 0;
  307. }
  308. break;
  309. }
  310. }
  311. DrawLocation = new Point((CurrentLocation.X - User.Movement.X + MapControl.OffSetX) * MapControl.CellWidth, (CurrentLocation.Y - User.Movement.Y + MapControl.OffSetY) * MapControl.CellHeight);
  312. DrawLocation.Offset(GlobalDisplayLocationOffset);
  313. DrawLocation.Offset(User.OffSetMove);
  314. }
  315. public override void Draw()
  316. {
  317. if (FrameIndex >= FrameCount && !Repeat) return;
  318. if (BodyLibrary == null) return;
  319. if (Blend)
  320. {
  321. BodyLibrary.DrawBlend(
  322. DrawFrame + FrameIndex,
  323. AnimationOffset == default ? DrawLocation : GetDrawWithOffset(),
  324. DrawColour, true,
  325. 0.8F);
  326. }
  327. else
  328. {
  329. BodyLibrary.Draw(DrawFrame + FrameIndex,
  330. AnimationOffset == default ? DrawLocation : GetDrawWithOffset(),
  331. DrawColour,
  332. true);
  333. }
  334. }
  335. public override bool MouseOver(Point p)
  336. {
  337. return false;
  338. }
  339. public override void DrawBehindEffects(bool effectsEnabled)
  340. {
  341. }
  342. public override void DrawEffects(bool effectsEnabled)
  343. {
  344. }
  345. private Point GetDrawWithOffset()
  346. {
  347. Point newDrawLocation = new (
  348. (CurrentLocation.X + AnimationOffset.X - User.Movement.X + MapControl.OffSetX) * MapControl.CellWidth,
  349. (CurrentLocation.Y + AnimationOffset.Y - User.Movement.Y + MapControl.OffSetY) * MapControl.CellHeight);
  350. newDrawLocation.Offset(GlobalDisplayLocationOffset);
  351. newDrawLocation.Offset(User.OffSetMove);
  352. return newDrawLocation;
  353. }
  354. }
  355. }