ConquestObject.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. using System.Drawing;
  2. using Server.MirEnvir;
  3. using Server.MirDatabase;
  4. namespace Server.MirObjects
  5. {
  6. public class ConquestObject
  7. {
  8. protected static Envir Envir
  9. {
  10. get { return Envir.Main; }
  11. }
  12. public ConquestGuildInfo GuildInfo;
  13. public ConquestInfo Info
  14. {
  15. get { return GuildInfo.Info; }
  16. set { GuildInfo.Info = value; }
  17. }
  18. public List<ConquestGuildArcherInfo> ArcherList
  19. {
  20. get { return GuildInfo.ArcherList; }
  21. set { GuildInfo.ArcherList = value; }
  22. }
  23. public List<ConquestGuildGateInfo> GateList
  24. {
  25. get { return GuildInfo.GateList; }
  26. set { GuildInfo.GateList = value; }
  27. }
  28. public List<ConquestGuildWallInfo> WallList
  29. {
  30. get { return GuildInfo.WallList; }
  31. set { GuildInfo.WallList = value; }
  32. }
  33. public List<ConquestGuildSiegeInfo> SiegeList
  34. {
  35. get { return GuildInfo.SiegeList; }
  36. set { GuildInfo.SiegeList = value; }
  37. }
  38. public List<ConquestGuildFlagInfo> FlagList
  39. {
  40. get { return GuildInfo.FlagList; }
  41. set { GuildInfo.FlagList = value; }
  42. }
  43. public Dictionary<ConquestGuildFlagInfo, Dictionary<GuildObject, int>> ControlPoints
  44. {
  45. get { return GuildInfo.ControlPoints; }
  46. set { GuildInfo.ControlPoints = value; }
  47. }
  48. public GuildObject Guild;
  49. public Map ConquestMap;
  50. public Map PalaceMap;
  51. private bool AtWar = false;
  52. public DateTime WarStartTime;
  53. public DateTime WarEndTime;
  54. public ConquestGame GameType;
  55. public ConquestType StartType;
  56. public long ScheduleTimer;
  57. public long ScoreTimer;
  58. public const int MAX_KING_POINTS = 18; //3 minutes
  59. public const int MAX_CONTROL_POINTS = 6; //1 minute
  60. public Dictionary<GuildObject, int> KingPoints = new Dictionary<GuildObject, int>();
  61. public List<SpellObject> WarEffects = new List<SpellObject>();
  62. public List<NPCObject> ConquestNPCs = new List<NPCObject>();
  63. public ConquestObject(ConquestGuildInfo guildInfo)
  64. {
  65. GuildInfo = guildInfo;
  66. }
  67. public void Bind()
  68. {
  69. //Bind Info to Saved Archer objects or create new objects
  70. for (var j = 0; j < Info.ConquestGuards.Count; j++)
  71. {
  72. var tempArcher = GuildInfo.ArcherList.FirstOrDefault(x => x.Index == Info.ConquestGuards[j].Index);
  73. if (tempArcher != null)
  74. {
  75. tempArcher.Info = Info.ConquestGuards[j];
  76. tempArcher.Conquest = this;
  77. }
  78. else
  79. {
  80. GuildInfo.ArcherList.Add(new ConquestGuildArcherInfo { Info = Info.ConquestGuards[j], Alive = true, Index = Info.ConquestGuards[j].Index, Conquest = this });
  81. }
  82. }
  83. //Remove archers that have been removed from DB
  84. for (var j = 0; j < GuildInfo.ArcherList.Count; j++)
  85. {
  86. if (GuildInfo.ArcherList[j].Info == null)
  87. {
  88. GuildInfo.ArcherList.Remove(GuildInfo.ArcherList[j]);
  89. }
  90. }
  91. //Bind Info to Saved Gate objects or create new objects
  92. for (var j = 0; j < Info.ConquestGates.Count; j++)
  93. {
  94. var tempGate = GuildInfo.GateList.FirstOrDefault(x => x.Index == Info.ConquestGates[j].Index);
  95. if (tempGate != null)
  96. {
  97. tempGate.Info = Info.ConquestGates[j];
  98. tempGate.Conquest = this;
  99. }
  100. else
  101. {
  102. GuildInfo.GateList.Add(new ConquestGuildGateInfo { Info = Info.ConquestGates[j], Health = int.MaxValue, Index = Info.ConquestGates[j].Index, Conquest = this });
  103. }
  104. }
  105. //Bind Info to Saved Flag objects or create new objects
  106. for (var j = 0; j < Info.ConquestFlags.Count; j++)
  107. {
  108. GuildInfo.FlagList.Add(new ConquestGuildFlagInfo { Info = Info.ConquestFlags[j], Index = Info.ConquestFlags[j].Index, Conquest = this });
  109. }
  110. //Remove Gates that have been removed from DB
  111. for (var j = 0; j < GuildInfo.GateList.Count; j++)
  112. {
  113. if (GuildInfo.GateList[j].Info == null)
  114. {
  115. GuildInfo.GateList.Remove(GuildInfo.GateList[j]);
  116. }
  117. }
  118. //Bind Info to Saved Wall objects or create new objects
  119. for (var j = 0; j < Info.ConquestWalls.Count; j++)
  120. {
  121. var tempWall = GuildInfo.WallList.FirstOrDefault(x => x.Index == Info.ConquestWalls[j].Index);
  122. if (tempWall != null)
  123. {
  124. tempWall.Info = Info.ConquestWalls[j];
  125. tempWall.Conquest = this;
  126. }
  127. else
  128. {
  129. GuildInfo.WallList.Add(new ConquestGuildWallInfo { Info = Info.ConquestWalls[j], Index = Info.ConquestWalls[j].Index, Health = int.MaxValue, Conquest = this });
  130. }
  131. }
  132. //Remove Walls that have been removed from DB
  133. for (var j = 0; j < GuildInfo.WallList.Count; j++)
  134. {
  135. if (GuildInfo.WallList[j].Info == null)
  136. {
  137. GuildInfo.WallList.Remove(GuildInfo.WallList[j]);
  138. }
  139. }
  140. //Bind Info to Saved Siege objects or create new objects
  141. for (var j = 0; j < Info.ConquestSieges.Count; j++)
  142. {
  143. var tempSiege = GuildInfo.SiegeList.FirstOrDefault(x => x.Index == Info.ConquestSieges[j].Index);
  144. if (tempSiege != null)
  145. {
  146. tempSiege.Info = Info.ConquestSieges[j];
  147. tempSiege.Conquest = this;
  148. }
  149. else
  150. {
  151. GuildInfo.SiegeList.Add(new ConquestGuildSiegeInfo { Info = Info.ConquestSieges[j], Index = Info.ConquestSieges[j].Index, Health = int.MaxValue, Conquest = this });
  152. }
  153. }
  154. //Remove Siege that have been removed from DB
  155. for (var j = 0; j < GuildInfo.SiegeList.Count; j++)
  156. {
  157. if (GuildInfo.SiegeList[j].Info == null)
  158. {
  159. GuildInfo.SiegeList.Remove(GuildInfo.SiegeList[j]);
  160. }
  161. }
  162. //Bind Info to Saved Flag objects or create new objects
  163. for (var j = 0; j < Info.ControlPoints.Count; j++)
  164. {
  165. ConquestGuildFlagInfo cp;
  166. GuildInfo.ControlPoints.Add(cp = new ConquestGuildFlagInfo { Info = Info.ControlPoints[j], Index = Info.ControlPoints[j].Index, Conquest = this }, new Dictionary<GuildObject, int>());
  167. }
  168. LoadArchers();
  169. LoadGates();
  170. LoadWalls();
  171. LoadSieges();
  172. LoadFlags();
  173. LoadNPCs();
  174. LoadControlPoints();
  175. }
  176. public bool WarIsOn
  177. {
  178. get
  179. {
  180. return AtWar;
  181. }
  182. set
  183. {
  184. AtWar = value;
  185. AtWarChanged();
  186. }
  187. }
  188. public void LoadArchers()
  189. {
  190. for (int i = 0; i < ArcherList.Count; i++)
  191. {
  192. ArcherList[i].Spawn();
  193. }
  194. }
  195. public void LoadGates()
  196. {
  197. for (int i = 0; i < GateList.Count; i++)
  198. {
  199. GateList[i].Spawn(false);
  200. }
  201. }
  202. public void LoadWalls()
  203. {
  204. for (int i = 0; i < WallList.Count; i++)
  205. {
  206. WallList[i].Spawn(false);
  207. }
  208. }
  209. public void LoadSieges()
  210. {
  211. for (int i = 0; i < SiegeList.Count; i++)
  212. {
  213. SiegeList[i].Spawn();
  214. }
  215. }
  216. public void LoadFlags()
  217. {
  218. for (int i = 0; i < FlagList.Count; i++)
  219. {
  220. FlagList[i].Spawn();
  221. }
  222. }
  223. public void LoadNPCs()
  224. {
  225. for (int i = 0; i < ConquestMap.NPCs.Count; i++)
  226. {
  227. if (ConquestMap.NPCs[i].Info.Conquest == Info.Index)
  228. {
  229. ConquestMap.NPCs[i].Conq = this;
  230. ConquestNPCs.Add(ConquestMap.NPCs[i]);
  231. }
  232. }
  233. PalaceMap = Envir.GetMap(Info.PalaceIndex);
  234. if (PalaceMap != null)
  235. {
  236. for (int i = 0; i < PalaceMap.NPCs.Count; i++)
  237. {
  238. if (PalaceMap.NPCs[i].Info.Conquest == Info.Index)
  239. {
  240. PalaceMap.NPCs[i].Conq = this;
  241. ConquestNPCs.Add(ConquestMap.NPCs[i]);
  242. }
  243. }
  244. }
  245. Map temp;
  246. for (int i = 0; i < Info.ExtraMaps.Count; i++)
  247. {
  248. temp = Envir.GetMap(Info.ExtraMaps[i]);
  249. if (temp == null) continue;
  250. for (int j = 0; j < temp.NPCs.Count; j++)
  251. {
  252. if (temp.NPCs[j].Info.Conquest == Info.Index)
  253. {
  254. temp.NPCs[j].Conq = this;
  255. ConquestNPCs.Add(temp.NPCs[j]);
  256. }
  257. }
  258. }
  259. }
  260. public void LoadControlPoints()
  261. {
  262. foreach (var cp in ControlPoints.Keys)
  263. {
  264. cp.Spawn();
  265. }
  266. }
  267. private void AtWarChanged()
  268. {
  269. if (WarIsOn)
  270. {
  271. if (StartType == ConquestType.Forced)
  272. {
  273. WarStartTime = Envir.Now;
  274. WarEndTime = WarStartTime.AddMinutes(Info.WarLength);
  275. GameType = Info.Game;
  276. }
  277. NPCVisibility(true);
  278. switch (GameType)
  279. {
  280. case ConquestGame.CapturePalace:
  281. break;
  282. case ConquestGame.KingOfHill:
  283. CreateZone(true);
  284. break;
  285. case ConquestGame.Random:
  286. break;
  287. case ConquestGame.Classic:
  288. break;
  289. }
  290. }
  291. else
  292. {
  293. NPCVisibility(false);
  294. for (int i = 0; i < ArcherList.Count; i++)
  295. {
  296. if (ArcherList[i].ArcherMonster != null)
  297. ArcherList[i].ArcherMonster.Target = null;
  298. }
  299. switch (StartType)
  300. {
  301. case ConquestType.Request:
  302. GuildInfo.AttackerID = -1;
  303. break;
  304. }
  305. switch (GameType)
  306. {
  307. case ConquestGame.CapturePalace:
  308. break;
  309. case ConquestGame.KingOfHill:
  310. CreateZone(false);
  311. break;
  312. case ConquestGame.Random:
  313. break;
  314. case ConquestGame.Classic:
  315. break;
  316. }
  317. }
  318. }
  319. private void NPCVisibility(bool show = true)
  320. {
  321. //Check if Players in Conquest Zone;
  322. for (int j = 0; j < ConquestMap.Players.Count; j++)
  323. {
  324. ConquestMap.Players[j].CheckConquest();
  325. }
  326. PalaceMap = Envir.GetMap(Info.PalaceIndex);
  327. if (PalaceMap != null)
  328. {
  329. if (show)
  330. {
  331. PalaceMap.tempConquest = this;
  332. }
  333. else
  334. {
  335. PalaceMap.tempConquest = null;
  336. }
  337. for (int j = 0; j < PalaceMap.Players.Count; j++)
  338. {
  339. PalaceMap.Players[j].CheckConquest();
  340. }
  341. }
  342. Map temp;
  343. for (int i = 0; i < Info.ExtraMaps.Count; i++)
  344. {
  345. temp = Envir.GetMap(Info.ExtraMaps[i]);
  346. if (temp == null) continue;
  347. if (show)
  348. {
  349. temp.tempConquest = this;
  350. }
  351. else
  352. {
  353. temp.tempConquest = null;
  354. }
  355. for (int k = 0; k < temp.Players.Count; k++)
  356. {
  357. temp.Players[k].CheckConquest();
  358. }
  359. }
  360. //Set NPCs to invisible
  361. Map npcMap;
  362. NPCObject npcTemp;
  363. for (int i = 0; i < ConquestNPCs.Count; i++)
  364. {
  365. npcMap = ConquestNPCs[i].CurrentMap;
  366. npcTemp = ConquestNPCs[i];
  367. for (int j = 0; j < npcMap.Players.Count; j++)
  368. {
  369. if (Functions.InRange(npcTemp.CurrentLocation, npcMap.Players[j].CurrentLocation, Globals.DataRange))
  370. npcTemp.CheckVisible(npcMap.Players[j]);
  371. }
  372. }
  373. }
  374. public bool CheckDay()
  375. {
  376. switch (Envir.Now.DayOfWeek.ToString())
  377. {
  378. case "Monday":
  379. return Info.Monday;
  380. case "Tuesday":
  381. return Info.Tuesday;
  382. case "Wednesday":
  383. return Info.Wednesday;
  384. case "Thursday":
  385. return Info.Thursday;
  386. case "Friday":
  387. return Info.Friday;
  388. case "Saturday":
  389. return Info.Saturday;
  390. case "Sunday":
  391. return Info.Sunday;
  392. }
  393. return true;
  394. }
  395. public void AutoSchedule()
  396. {
  397. int start = ((Info.StartHour * 60));
  398. int finish = ((Info.StartHour * 60) + Info.WarLength);
  399. int now = ((Envir.Now.Hour * 60) + Envir.Now.Minute);
  400. if (WarIsOn && StartType == ConquestType.Forced && WarEndTime <= Envir.Now)
  401. {
  402. EndWar(Info.Game);
  403. }
  404. if (StartType != ConquestType.Forced)
  405. {
  406. if (WarIsOn && (now > start && finish <= now))
  407. {
  408. EndWar(Info.Game);
  409. }
  410. else if (start <= now && finish > now && CheckDay())
  411. {
  412. if (!WarIsOn)
  413. {
  414. if (Info.Type == ConquestType.Request)
  415. {
  416. if (GuildInfo.AttackerID != -1)
  417. {
  418. GameType = Info.Game;
  419. StartType = Info.Type;
  420. StartWar(Info.Game);
  421. }
  422. }
  423. else
  424. {
  425. GameType = Info.Game;
  426. StartType = Info.Type;
  427. StartWar(Info.Game);
  428. }
  429. }
  430. }
  431. }
  432. ScheduleTimer = Envir.Time + Settings.Minute;
  433. }
  434. public void Process()
  435. {
  436. if (ScheduleTimer < Envir.Time) AutoSchedule();
  437. if (WarIsOn && (GameType == ConquestGame.KingOfHill || GameType == ConquestGame.Classic || GameType == ConquestGame.ControlPoints)) ScorePoints();
  438. }
  439. public void Reset()
  440. {
  441. GuildInfo.Owner = -1;
  442. GuildInfo.AttackerID = -1;
  443. GuildInfo.GoldStorage = 0;
  444. GuildInfo.NPCRate = 0;
  445. if (Guild != null)
  446. {
  447. Guild.Conquest = null;
  448. UpdatePlayers(Guild);
  449. Guild = null;
  450. }
  451. for (int i = 0; i < ArcherList.Count; i++)
  452. {
  453. ArcherList[i].Spawn();
  454. }
  455. for (int i = 0; i < GateList.Count; i++)
  456. {
  457. GateList[i].Repair();
  458. }
  459. for (int i = 0; i < WallList.Count; i++)
  460. {
  461. WallList[i].Repair();
  462. }
  463. for (int i = 0; i < SiegeList.Count; i++)
  464. {
  465. //SiegeList[i].Repair();
  466. }
  467. GuildInfo.NeedSave = true;
  468. }
  469. public void TakeConquest(PlayerObject player = null, GuildObject winningGuild = null)
  470. {
  471. if (winningGuild == null && (player == null || player.MyGuild == null || player.MyGuild.Conquest != null || player.Dead)) return;
  472. if (winningGuild != null && winningGuild.Conquest != null) return;
  473. if (player != null && player.MyGuild != null && player.MyGuild.Conquest != null) return;
  474. GuildObject tmpPrevious = null;
  475. switch (GameType)
  476. {
  477. case ConquestGame.CapturePalace:
  478. if (StartType == ConquestType.Request)
  479. if (player.MyGuild.Guildindex != GuildInfo.AttackerID) break;
  480. if (Guild != null)
  481. {
  482. tmpPrevious = Guild;
  483. Guild.Conquest = null;
  484. GuildInfo.AttackerID = tmpPrevious.Guildindex;
  485. }
  486. GuildInfo.Owner = player.MyGuild.Guildindex;
  487. Guild = player.MyGuild;
  488. player.MyGuild.Conquest = this;
  489. EndWar(GameType);
  490. break;
  491. case ConquestGame.KingOfHill:
  492. case ConquestGame.Classic:
  493. if (StartType == ConquestType.Request)
  494. if (winningGuild.Guildindex != GuildInfo.AttackerID) break;
  495. if (Guild != null)
  496. {
  497. tmpPrevious = Guild;
  498. Guild.Conquest = null;
  499. GuildInfo.AttackerID = tmpPrevious.Guildindex;
  500. }
  501. GuildInfo.Owner = winningGuild.Guildindex;
  502. Guild = winningGuild;
  503. Guild.Conquest = this;
  504. break;
  505. case ConquestGame.ControlPoints:
  506. if (Guild != null)
  507. {
  508. tmpPrevious = Guild;
  509. }
  510. GuildInfo.Owner = winningGuild.Guildindex;
  511. Guild = winningGuild;
  512. Guild.Conquest = this;
  513. List<ConquestGuildFlagInfo> keys = new List<ConquestGuildFlagInfo>(ControlPoints.Keys);
  514. foreach (ConquestGuildFlagInfo key in keys)
  515. {
  516. key.ChangeOwner(Guild);
  517. ControlPoints[key] = new Dictionary<GuildObject, int>();
  518. }
  519. break;
  520. }
  521. for (int i = 0; i < FlagList.Count; i++)
  522. {
  523. FlagList[i].Guild = Guild;
  524. FlagList[i].UpdateImage();
  525. FlagList[i].UpdateColour();
  526. }
  527. if (Guild != null &&
  528. (tmpPrevious == null || Guild != tmpPrevious))
  529. {
  530. UpdatePlayers(Guild);
  531. if (tmpPrevious != null)
  532. {
  533. tmpPrevious.Conquest = null;
  534. UpdatePlayers(tmpPrevious);
  535. }
  536. GuildInfo.NeedSave = true;
  537. }
  538. }
  539. public void UpdatePlayers(GuildObject tempGuild)
  540. {
  541. PlayerObject player = null;
  542. Packet p;
  543. for (int i = 0; i < tempGuild.Ranks.Count; i++)
  544. for (int j = 0; j < tempGuild.Ranks[i].Members.Count; j++)
  545. {
  546. player = (PlayerObject)tempGuild.Ranks[i].Members[j].Player;
  547. if (player != null)
  548. {
  549. tempGuild.SendGuildStatus(player);
  550. p = new ServerPackets.ObjectGuildNameChanged { ObjectID = player.ObjectID, GuildName = player.MyGuild.GetName()};
  551. BroadcastGuildName(player, p);
  552. }
  553. }
  554. }
  555. public void BroadcastGuildName(PlayerObject player, Packet p)
  556. {
  557. if (player.CurrentMap == null) return;
  558. for (int i = player.CurrentMap.Players.Count - 1; i >= 0; i--)
  559. {
  560. PlayerObject tempPlayer = player.CurrentMap.Players[i];
  561. if (tempPlayer == player) continue;
  562. if (Functions.InRange(player.CurrentLocation, tempPlayer.CurrentLocation, Globals.DataRange))
  563. {
  564. if (p != null)
  565. tempPlayer.Enqueue(p);
  566. }
  567. }
  568. }
  569. private void CreateZone(bool create = true)
  570. {
  571. if (create)
  572. {
  573. WarEffects.Clear();
  574. for (int y = Info.KingLocation.Y - Info.KingSize; y <= Info.KingLocation.Y + Info.KingSize; y++)
  575. {
  576. if (y < 0) continue;
  577. if (y >= ConquestMap.Height) break;
  578. for (int x = Info.KingLocation.X - Info.KingSize; x <= Info.KingLocation.X + Info.KingSize; x += Math.Abs(y - Info.KingLocation.Y) == Info.KingSize ? 1 : Info.KingSize * 2)
  579. {
  580. if (x < 0) continue;
  581. if (x >= ConquestMap.Width) break;
  582. if (!ConquestMap.Cells[x, y].Valid) continue;
  583. SpellObject spell = new SpellObject
  584. {
  585. ExpireTime = long.MaxValue,
  586. Spell = Spell.TrapHexagon,
  587. TickSpeed = int.MaxValue,
  588. CurrentLocation = new Point(x, y),
  589. CurrentMap = ConquestMap,
  590. Decoration = true
  591. };
  592. ConquestMap.Cells[x, y].Add(spell);
  593. WarEffects.Add(spell);
  594. spell.Spawned();
  595. }
  596. }
  597. }
  598. else
  599. {
  600. for (int i = 0; i < WarEffects.Count; i++)
  601. {
  602. //if (WarEffects[i].CurrentLocation != null)
  603. //{
  604. WarEffects[i].Despawn();
  605. ConquestMap.RemoveObject(WarEffects[i]);
  606. //}
  607. }
  608. WarEffects.Clear();
  609. }
  610. }
  611. public void ScorePoints()
  612. {
  613. bool pointsChanged = false;
  614. switch (GameType)
  615. {
  616. case ConquestGame.ControlPoints:
  617. {
  618. int points;
  619. foreach (KeyValuePair<ConquestGuildFlagInfo, Dictionary<GuildObject, int>> item in ControlPoints)
  620. {
  621. pointsChanged = false;
  622. ConquestGuildFlagInfo controlFlag = null;
  623. Dictionary<GuildObject, int> controlFlagPoints = null;
  624. for (int i = 0; i < ConquestMap.Players.Count; i++)
  625. {
  626. if (!ConquestMap.Players[i].WarZone || ConquestMap.Players[i].MyGuild == null || ConquestMap.Players[i].Dead) continue;
  627. controlFlag = item.Key;
  628. controlFlagPoints = item.Value;
  629. if (!Functions.InRange(controlFlag.Info.Location, ConquestMap.Players[i].CurrentLocation, 3)) continue;
  630. controlFlagPoints.TryGetValue(ConquestMap.Players[i].MyGuild, out points);
  631. if (points == 0)
  632. {
  633. controlFlagPoints[ConquestMap.Players[i].MyGuild] = 1;
  634. ConquestMap.Players[i].MyGuild.SendOutputMessage(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.GainingControlOf), ((double)controlFlagPoints[ConquestMap.Players[i].MyGuild] / MAX_CONTROL_POINTS), controlFlag.Info.Name));
  635. }
  636. else if (points < MAX_CONTROL_POINTS)
  637. {
  638. controlFlagPoints[ConquestMap.Players[i].MyGuild] += 1;
  639. ConquestMap.Players[i].MyGuild.SendOutputMessage(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.GainingControlOf), ((double)controlFlagPoints[ConquestMap.Players[i].MyGuild] / MAX_CONTROL_POINTS), controlFlag.Info.Name));
  640. }
  641. List<GuildObject> guilds = controlFlagPoints.Keys.ToList();
  642. foreach (var guild in guilds)
  643. {
  644. if (ConquestMap.Players[i].MyGuild == guild) continue;
  645. controlFlagPoints.TryGetValue(ConquestMap.Players[i].MyGuild, out points);
  646. if (controlFlagPoints[guild] > 0)
  647. {
  648. controlFlagPoints[guild] -= 1;
  649. }
  650. }
  651. pointsChanged = true;
  652. }
  653. if (pointsChanged)
  654. {
  655. GuildObject tempWinning = Guild;
  656. int tempInt;
  657. //Check Scores
  658. for (int i = 0; i < Envir.Guilds.Count; i++)
  659. {
  660. controlFlagPoints.TryGetValue(Envir.Guilds[i], out points);
  661. if (tempWinning != null)
  662. controlFlagPoints.TryGetValue(tempWinning, out tempInt);
  663. else tempInt = 0;
  664. if (points > tempInt)
  665. {
  666. tempWinning = Envir.Guilds[i];
  667. }
  668. }
  669. if (tempWinning != controlFlag.Guild)
  670. {
  671. controlFlag.ChangeOwner(tempWinning);
  672. for (int j = 0; j < ConquestMap.Players.Count; j++)
  673. {
  674. ConquestMap.Players[j].ReceiveChat(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.PlayerCapturedFlagAtLocation), tempWinning.Name, controlFlag.Info.Name, Info.Name), ChatType.System);
  675. }
  676. }
  677. }
  678. }
  679. }
  680. break;
  681. case ConquestGame.KingOfHill:
  682. {
  683. int points;
  684. for (int i = 0; i < ConquestMap.Players.Count; i++)
  685. {
  686. if (ConquestMap.Players[i].WarZone && ConquestMap.Players[i].MyGuild != null && !ConquestMap.Players[i].Dead && Functions.InRange(Info.KingLocation, ConquestMap.Players[i].CurrentLocation, Info.KingSize))
  687. {
  688. if (StartType == ConquestType.Request && ConquestMap.Players[i].MyGuild.Guildindex != GuildInfo.AttackerID) continue;
  689. if (ConquestMap.Players[i].MyGuild.Conquest != null && ConquestMap.Players[i].MyGuild.Conquest != this) continue;
  690. KingPoints.TryGetValue(ConquestMap.Players[i].MyGuild, out points);
  691. if (points == 0)
  692. {
  693. KingPoints[ConquestMap.Players[i].MyGuild] = 1;
  694. ConquestMap.Players[i].MyGuild.SendOutputMessage(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.GainingControlOfGuild), ((double)KingPoints[ConquestMap.Players[i].MyGuild] / MAX_KING_POINTS), Info.Name));
  695. }
  696. else if (points < MAX_KING_POINTS)
  697. {
  698. KingPoints[ConquestMap.Players[i].MyGuild] += 1;
  699. ConquestMap.Players[i].MyGuild.SendOutputMessage(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.GainingControlOfGuild), ((double)KingPoints[ConquestMap.Players[i].MyGuild] / MAX_KING_POINTS), Info.Name));
  700. }
  701. List<GuildObject> guilds = KingPoints.Keys.ToList();
  702. foreach (var guild in guilds)
  703. {
  704. if (ConquestMap.Players[i].MyGuild == guild) continue;
  705. KingPoints.TryGetValue(ConquestMap.Players[i].MyGuild, out points);
  706. if (KingPoints[guild] > 0)
  707. {
  708. KingPoints[guild] -= 1;
  709. guild.SendOutputMessage(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.LosingControlOf), ((double)KingPoints[guild] / MAX_KING_POINTS), Info.Name));
  710. }
  711. }
  712. pointsChanged = true;
  713. }
  714. }
  715. if (pointsChanged)
  716. {
  717. GuildObject tempWinning = Guild;
  718. int tempInt;
  719. //Check Scores
  720. for (int i = 0; i < Envir.Guilds.Count; i++)
  721. {
  722. KingPoints.TryGetValue(Envir.Guilds[i], out points);
  723. if (tempWinning != null)
  724. KingPoints.TryGetValue(tempWinning, out tempInt);
  725. else tempInt = 0;
  726. if (points > tempInt)
  727. {
  728. tempWinning = Envir.Guilds[i];
  729. }
  730. }
  731. if (tempWinning != Guild)
  732. {
  733. TakeConquest(null, tempWinning);
  734. for (int j = 0; j < ConquestMap.Players.Count; j++)
  735. {
  736. ConquestMap.Players[j].ReceiveChat(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.PlayerHasCapturedHill), tempWinning.Name), ChatType.System);
  737. }
  738. }
  739. }
  740. }
  741. break;
  742. case ConquestGame.Classic:
  743. int guildCounter = 0;
  744. GuildObject takingGuild = null;
  745. for (int i = 0; i < PalaceMap.Players.Count; i++)
  746. {
  747. if (PalaceMap.Players[i].Dead) continue;
  748. if (PalaceMap.Players[i].MyGuild != null)
  749. {
  750. if (takingGuild == null || takingGuild != PalaceMap.Players[i].MyGuild)
  751. guildCounter++;
  752. takingGuild = PalaceMap.Players[i].MyGuild;
  753. }
  754. else
  755. {
  756. guildCounter++;
  757. }
  758. }
  759. if (guildCounter == 1 && takingGuild != Guild)
  760. {
  761. if (StartType == ConquestType.Request && takingGuild.Guildindex != GuildInfo.AttackerID) return;
  762. TakeConquest(null, takingGuild);
  763. }
  764. break;
  765. default:
  766. return;
  767. }
  768. }
  769. public void StartWar(ConquestGame type)
  770. {
  771. WarIsOn = true;
  772. foreach (var pl in Envir.Players)
  773. pl.BroadcastInfo();
  774. }
  775. public void EndWar(ConquestGame type)
  776. {
  777. WarIsOn = false;
  778. switch(type)
  779. {
  780. case ConquestGame.ControlPoints:
  781. Dictionary<GuildObject, int> controlledPoints = new Dictionary<GuildObject, int>();
  782. int count = 0;
  783. foreach (KeyValuePair<ConquestGuildFlagInfo, Dictionary<GuildObject, int>> item in ControlPoints)
  784. {
  785. controlledPoints.TryGetValue(item.Key.Guild, out count);
  786. if(count == 0)
  787. controlledPoints[item.Key.Guild] = 1;
  788. else
  789. controlledPoints[item.Key.Guild] += 1;
  790. }
  791. GuildObject tempWinning = Guild;
  792. int tempInt;
  793. List<GuildObject> guilds = controlledPoints.Keys.ToList();
  794. //Check Scores
  795. for (int i = 0; i < guilds.Count; i++)
  796. {
  797. controlledPoints.TryGetValue(guilds[i], out count);
  798. if (tempWinning != null)
  799. {
  800. controlledPoints.TryGetValue(tempWinning, out tempInt);
  801. }
  802. else
  803. {
  804. tempInt = 0;
  805. }
  806. if (count > tempInt)
  807. {
  808. tempWinning = guilds[i];
  809. }
  810. }
  811. TakeConquest(null, tempWinning);
  812. break;
  813. }
  814. foreach (var pl in Envir.Players)
  815. pl.BroadcastInfo();
  816. }
  817. }
  818. }