ConquestGuildInfo.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. using Server.MirEnvir;
  2. using Server.MirObjects;
  3. using Server.MirObjects.Monsters;
  4. namespace Server.MirDatabase
  5. {
  6. public class ConquestGuildInfo
  7. {
  8. public List<ConquestGuildArcherInfo> ArcherList = new List<ConquestGuildArcherInfo>();
  9. public List<ConquestGuildGateInfo> GateList = new List<ConquestGuildGateInfo>();
  10. public List<ConquestGuildWallInfo> WallList = new List<ConquestGuildWallInfo>();
  11. public List<ConquestGuildSiegeInfo> SiegeList = new List<ConquestGuildSiegeInfo>();
  12. public List<ConquestGuildFlagInfo> FlagList = new List<ConquestGuildFlagInfo>();
  13. public Dictionary<ConquestGuildFlagInfo, Dictionary<GuildObject, int>> ControlPoints = new Dictionary<ConquestGuildFlagInfo, Dictionary<GuildObject, int>>();
  14. public int Owner = 0;
  15. public uint GoldStorage;
  16. public int AttackerID;
  17. public byte NPCRate = 0;
  18. public ConquestInfo Info;
  19. public bool NeedSave = false;
  20. public ConquestGuildInfo() { }
  21. public ConquestGuildInfo(BinaryReader reader)
  22. {
  23. Owner = reader.ReadInt32();
  24. var archerCount = reader.ReadInt32();
  25. for (int i = 0; i < archerCount; i++)
  26. {
  27. ArcherList.Add(new ConquestGuildArcherInfo(reader));
  28. }
  29. var gateCount = reader.ReadInt32();
  30. for (int i = 0; i < gateCount; i++)
  31. {
  32. GateList.Add(new ConquestGuildGateInfo(reader));
  33. }
  34. var wallCount = reader.ReadInt32();
  35. for (int i = 0; i < wallCount; i++)
  36. {
  37. WallList.Add(new ConquestGuildWallInfo(reader));
  38. }
  39. var siegeCount = reader.ReadInt32();
  40. for (int i = 0; i < siegeCount; i++)
  41. {
  42. SiegeList.Add(new ConquestGuildSiegeInfo(reader));
  43. }
  44. GoldStorage = reader.ReadUInt32();
  45. NPCRate = reader.ReadByte();
  46. AttackerID = reader.ReadInt32();
  47. }
  48. public void Save(BinaryWriter writer)
  49. {
  50. writer.Write(Owner);
  51. writer.Write(ArcherList.Count);
  52. for (int i = 0; i < ArcherList.Count; i++)
  53. {
  54. ArcherList[i].Save(writer);
  55. }
  56. writer.Write(GateList.Count);
  57. for (int i = 0; i < GateList.Count; i++)
  58. {
  59. GateList[i].Save(writer);
  60. }
  61. writer.Write(WallList.Count);
  62. for (int i = 0; i < WallList.Count; i++)
  63. {
  64. WallList[i].Save(writer);
  65. }
  66. writer.Write(SiegeList.Count);
  67. for (int i = 0; i < SiegeList.Count; i++)
  68. {
  69. SiegeList[i].Save(writer);
  70. }
  71. writer.Write(GoldStorage);
  72. writer.Write(NPCRate);
  73. writer.Write(AttackerID);
  74. }
  75. }
  76. public class ConquestGuildSiegeInfo
  77. {
  78. protected static Envir Envir
  79. {
  80. get { return Envir.Main; }
  81. }
  82. public int Index;
  83. public int Health;
  84. public ConquestSiegeInfo Info;
  85. public ConquestObject Conquest;
  86. public Gate Gate;
  87. public ConquestGuildSiegeInfo() { }
  88. public ConquestGuildSiegeInfo(BinaryReader reader)
  89. {
  90. Index = reader.ReadInt32();
  91. if (Envir.LoadVersion <= 84)
  92. {
  93. Health = (int)reader.ReadUInt32();
  94. }
  95. else
  96. {
  97. Health = reader.ReadInt32();
  98. }
  99. }
  100. public void Save(BinaryWriter writer)
  101. {
  102. //if (Gate != null) Health = Gate.HP; - needs adding
  103. writer.Write(Index);
  104. writer.Write(Health);
  105. }
  106. public void Spawn()
  107. {
  108. if (Gate != null) Gate.Despawn();
  109. MonsterInfo monsterInfo = Envir.GetMonsterInfo(Info.MobIndex);
  110. if (monsterInfo == null) return;
  111. if (monsterInfo.AI != 72) return;
  112. if (monsterInfo.AI == 72)
  113. {
  114. Gate = (Gate)MonsterObject.GetMonster(monsterInfo);
  115. }
  116. else if (monsterInfo.AI == 73)
  117. {
  118. //Gate = (GateWest)MonsterObject.GetMonster(monsterInfo);
  119. }
  120. if (Gate == null) return;
  121. Gate.Conquest = Conquest;
  122. Gate.GateIndex = Index;
  123. Gate.Spawn(Conquest.ConquestMap, Info.Location);
  124. if (Health == 0)
  125. {
  126. Gate.Die();
  127. }
  128. else
  129. {
  130. Gate.SetHP(Health);
  131. }
  132. Gate.CheckDirection();
  133. }
  134. public int GetRepairCost()
  135. {
  136. int cost = 0;
  137. if (Gate == null) return 0;
  138. if (Gate.Stats[Stat.HP] == Gate.HP) return cost;
  139. if (Info.RepairCost != 0)
  140. {
  141. cost = Info.RepairCost / (Gate.Stats[Stat.HP] / (Gate.Stats[Stat.HP] - Gate.HP));
  142. }
  143. return cost;
  144. }
  145. public void Repair()
  146. {
  147. if (Gate == null)
  148. {
  149. Spawn();
  150. return;
  151. }
  152. if (Gate.Dead)
  153. {
  154. Spawn();
  155. }
  156. else
  157. {
  158. Gate.HP = Gate.Stats[Stat.HP];
  159. }
  160. Gate.CheckDirection();
  161. }
  162. }
  163. public class ConquestGuildFlagInfo
  164. {
  165. public int Index;
  166. public ConquestFlagInfo Info;
  167. public ConquestObject Conquest;
  168. public GuildObject Guild;
  169. public NPCObject Flag;
  170. public ConquestGuildFlagInfo() { }
  171. public void Spawn()
  172. {
  173. NPCInfo npcInfo = new NPCInfo
  174. {
  175. Name = Info.Name,
  176. FileName = Info.FileName,
  177. Location = Info.Location,
  178. Image = 1000
  179. };
  180. if (Conquest.Guild != null)
  181. {
  182. Guild = Conquest.Guild;
  183. npcInfo.Image = Guild.Info.FlagImage;
  184. npcInfo.Colour = Guild.Info.FlagColour;
  185. }
  186. Flag = new NPCObject(npcInfo)
  187. {
  188. CurrentMap = Conquest.ConquestMap
  189. };
  190. Flag.CurrentMap.AddObject(Flag);
  191. Flag.Spawned();
  192. }
  193. public void ChangeOwner(GuildObject guild)
  194. {
  195. Guild = guild;
  196. UpdateImage();
  197. UpdateColour();
  198. }
  199. public void UpdateImage()
  200. {
  201. if (Guild != null)
  202. {
  203. Flag.Info.Image = Guild.Info.FlagImage;
  204. Flag.Broadcast(Flag.GetUpdateInfo());
  205. }
  206. }
  207. public void UpdateColour()
  208. {
  209. if (Guild != null)
  210. {
  211. Flag.Info.Colour = Guild.Info.FlagColour;
  212. Flag.Broadcast(Flag.GetUpdateInfo());
  213. }
  214. }
  215. }
  216. public class ConquestGuildWallInfo
  217. {
  218. protected static Envir Envir
  219. {
  220. get { return Envir.Main; }
  221. }
  222. public int Index;
  223. public int Health;
  224. public ConquestWallInfo Info;
  225. public ConquestObject Conquest;
  226. public Wall Wall;
  227. public ConquestGuildWallInfo() { }
  228. public ConquestGuildWallInfo(BinaryReader reader)
  229. {
  230. Index = reader.ReadInt32();
  231. if (Envir.LoadVersion <= 84)
  232. {
  233. Health = (int)reader.ReadUInt32();
  234. }
  235. else
  236. {
  237. Health = reader.ReadInt32();
  238. }
  239. }
  240. public void Save(BinaryWriter writer)
  241. {
  242. if (Wall != null) Health = Wall.HP;
  243. writer.Write(Index);
  244. writer.Write(Wall.Health);
  245. }
  246. public void Spawn(bool repair)
  247. {
  248. if (Wall != null) Wall.Despawn();
  249. MonsterInfo monsterInfo = Envir.GetMonsterInfo(Info.MobIndex);
  250. if (monsterInfo == null) return;
  251. if (monsterInfo.AI != 82) return;
  252. Wall = (Wall)MonsterObject.GetMonster(monsterInfo);
  253. if (Wall == null) return;
  254. Wall.Conquest = Conquest;
  255. Wall.WallIndex = Index;
  256. Wall.Spawn(Conquest.ConquestMap, Info.Location);
  257. if (repair) Health = Wall.Stats[Stat.HP];
  258. if (Health == 0)
  259. Wall.Die();
  260. else
  261. Wall.SetHP(Health);
  262. Wall.CheckDirection();
  263. }
  264. public int GetRepairCost()
  265. {
  266. int cost = 0;
  267. if (Wall == null) return 0;
  268. if (Wall.Stats[Stat.HP] == Wall.HP) return cost;
  269. if (Info.RepairCost != 0)
  270. {
  271. cost = Info.RepairCost / (Wall.Stats[Stat.HP] / (Wall.Stats[Stat.HP] - Wall.HP));
  272. }
  273. return cost;
  274. }
  275. public void Repair()
  276. {
  277. if (Wall == null)
  278. {
  279. Spawn(true);
  280. return;
  281. }
  282. if (Wall.Dead)
  283. Spawn(true);
  284. else
  285. Wall.HP = Wall.Stats[Stat.HP];
  286. Wall.CheckDirection();
  287. }
  288. }
  289. public class ConquestGuildGateInfo
  290. {
  291. protected static Envir Envir
  292. {
  293. get { return Envir.Main; }
  294. }
  295. public int Index;
  296. public int Health;
  297. public ConquestGateInfo Info;
  298. public ConquestObject Conquest;
  299. public Gate Gate;
  300. public ConquestGuildGateInfo() { }
  301. public ConquestGuildGateInfo(BinaryReader reader)
  302. {
  303. Index = reader.ReadInt32();
  304. if (Envir.LoadVersion <= 84)
  305. {
  306. Health = (int)reader.ReadUInt32();
  307. }
  308. else
  309. {
  310. Health = reader.ReadInt32();
  311. }
  312. }
  313. public void Save(BinaryWriter writer)
  314. {
  315. if (Gate != null) Health = Gate.HP;
  316. writer.Write(Index);
  317. writer.Write(Health);
  318. }
  319. public void Spawn(bool repair)
  320. {
  321. if (Gate != null) Gate.Despawn();
  322. MonsterInfo monsterInfo = Envir.GetMonsterInfo(Info.MobIndex);
  323. if (monsterInfo == null) return;
  324. if (monsterInfo.AI != 81) return;
  325. Gate = (Gate)MonsterObject.GetMonster(monsterInfo);
  326. if (Gate == null) return;
  327. Gate.Conquest = Conquest;
  328. Gate.GateIndex = Index;
  329. Gate.Spawn(Conquest.ConquestMap, Info.Location);
  330. if (repair) Health = Gate.Stats[Stat.HP];
  331. if (Health == 0)
  332. Gate.Die();
  333. else
  334. Gate.SetHP(Health);
  335. Gate.CheckDirection();
  336. }
  337. public int GetRepairCost()
  338. {
  339. int cost = 0;
  340. if (Gate == null) return 0;
  341. if (Gate.Stats[Stat.HP] == Gate.HP) return cost;
  342. if (Info.RepairCost != 0)
  343. {
  344. cost = Info.RepairCost / (Gate.Stats[Stat.HP] / (Gate.Stats[Stat.HP] - Gate.HP));
  345. }
  346. return cost;
  347. }
  348. public void Repair()
  349. {
  350. if (Gate == null)
  351. {
  352. Spawn(true);
  353. return;
  354. }
  355. if (Gate.Dead)
  356. {
  357. Spawn(true);
  358. }
  359. else
  360. {
  361. Gate.HP = Gate.Stats[Stat.HP];
  362. }
  363. Gate.CheckDirection();
  364. }
  365. }
  366. public class ConquestGuildArcherInfo
  367. {
  368. protected static Envir Envir
  369. {
  370. get { return Envir.Main; }
  371. }
  372. public int Index;
  373. public bool Alive;
  374. public ConquestArcherInfo Info;
  375. public ConquestObject Conquest;
  376. public ConquestArcher ArcherMonster;
  377. public ConquestGuildArcherInfo() { }
  378. public ConquestGuildArcherInfo(BinaryReader reader)
  379. {
  380. Index = reader.ReadInt32();
  381. Alive = reader.ReadBoolean();
  382. }
  383. public void Save(BinaryWriter writer)
  384. {
  385. if (ArcherMonster == null || ArcherMonster.Dead)
  386. {
  387. Alive = false;
  388. }
  389. else
  390. {
  391. Alive = true;
  392. }
  393. writer.Write(Index);
  394. writer.Write(Alive);
  395. }
  396. public void Spawn(bool Revive = false)
  397. {
  398. if (Revive) Alive = true;
  399. MonsterInfo monsterInfo = Envir.GetMonsterInfo(Info.MobIndex);
  400. if (monsterInfo == null) return;
  401. if (monsterInfo.AI != 80) return;
  402. ArcherMonster = (ConquestArcher)MonsterObject.GetMonster(monsterInfo);
  403. if (ArcherMonster == null) return;
  404. ArcherMonster.Conquest = Conquest;
  405. ArcherMonster.ArcherIndex = Index;
  406. if (Alive)
  407. {
  408. ArcherMonster.Spawn(Conquest.ConquestMap, Info.Location);
  409. }
  410. else
  411. {
  412. ArcherMonster.Spawn(Conquest.ConquestMap, Info.Location);
  413. ArcherMonster.Die();
  414. ArcherMonster.DeadTime = Envir.Time;
  415. }
  416. }
  417. public uint GetRepairCost()
  418. {
  419. uint cost = 0;
  420. if (ArcherMonster == null || ArcherMonster.Dead)
  421. {
  422. cost = Info.RepairCost;
  423. }
  424. return cost;
  425. }
  426. }
  427. }