AdminCHSiege.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**
  2. *
  3. */
  4. package handlers.admincommandhandlers;
  5. import java.util.Calendar;
  6. import com.l2jserver.Config;
  7. import com.l2jserver.gameserver.datatables.ClanTable;
  8. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  9. import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
  10. import com.l2jserver.gameserver.model.L2Clan;
  11. import com.l2jserver.gameserver.model.L2Object;
  12. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  13. import com.l2jserver.gameserver.model.entity.clanhall.ClanHallSiegeEngine;
  14. import com.l2jserver.gameserver.model.entity.clanhall.SiegableHall;
  15. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  16. import com.l2jserver.gameserver.network.serverpackets.SiegeInfo;
  17. /**
  18. * @author BiggBoss
  19. */
  20. public final class AdminCHSiege implements IAdminCommandHandler
  21. {
  22. private static final String[] COMMANDS =
  23. {
  24. "admin_chsiege_siegablehall",
  25. "admin_chsiege_startSiege",
  26. "admin_chsiege_endsSiege",
  27. "admin_chsiege_setSiegeDate",
  28. "admin_chsiege_addAttacker",
  29. "admin_chsiege_removeAttacker",
  30. "admin_chsiege_clearAttackers",
  31. "admin_chsiege_listAttackers",
  32. "admin_chsiege_forwardSiege"
  33. };
  34. @Override
  35. public String[] getAdminCommandList()
  36. {
  37. return COMMANDS;
  38. }
  39. @Override
  40. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  41. {
  42. final String[] split = command.split(" ");
  43. SiegableHall hall = null;
  44. if(Config.ALT_DEV_NO_QUESTS)
  45. activeChar.sendMessage("AltDevNoQuests = true; Clan Hall Sieges are disabled!");
  46. else if(split.length < 2)
  47. activeChar.sendMessage("You have to specify the hall id at least");
  48. else if((hall = getHall(split[1], activeChar)) == null)
  49. activeChar.sendMessage("Couldnt find he desired siegable hall ("+split[1]+")");
  50. else if(hall.getSiege() == null)
  51. activeChar.sendMessage("The given hall dont have any attached siege!");
  52. else if(split[0].equals(COMMANDS[1]))
  53. {
  54. if(hall.isInSiege())
  55. activeChar.sendMessage("The requested clan hall is alredy in siege!");
  56. else
  57. {
  58. L2Clan owner = ClanTable.getInstance().getClan(hall.getOwnerId());
  59. if(owner != null)
  60. {
  61. hall.free();
  62. owner.setHasHideout(0);
  63. hall.addAttacker(owner);
  64. }
  65. hall.getSiege().startSiege();
  66. }
  67. }
  68. else if(split[0].equals(COMMANDS[2]))
  69. {
  70. if(!hall.isInSiege())
  71. activeChar.sendMessage("The requested clan hall isnt in siege!");
  72. else
  73. hall.getSiege().endSiege();
  74. }
  75. else if(split[0].equals(COMMANDS[3]))
  76. {
  77. if(!hall.isRegistering())
  78. activeChar.sendMessage("Cannot change siege date while hall is in siege");
  79. else if(split.length < 3)
  80. activeChar.sendMessage("The date format is incorrect. Try again.");
  81. else
  82. {
  83. String[] rawDate = split[2].split(";");
  84. if(rawDate.length < 2)
  85. activeChar.sendMessage("You have to specify this format DD-MM-YYYY;HH:MM");
  86. else
  87. {
  88. String[] day = rawDate[0].split("-");
  89. String[] hour = rawDate[1].split(":");
  90. if(day.length < 3 || hour.length < 2)
  91. activeChar.sendMessage("Incomplete day, hour or both!");
  92. else
  93. {
  94. int d = parseInt(day[0]);
  95. int month = parseInt(day[1]) - 1;
  96. int year = parseInt(day[2]);
  97. int h = parseInt(hour[0]);
  98. int min = parseInt(hour[1]);
  99. if((month == 2 && d > 28) || d > 31 || d <= 0
  100. || month <= 0 || month > 12
  101. || year < Calendar.getInstance().get(Calendar.YEAR))
  102. activeChar.sendMessage("Wrong day/month/year gave!");
  103. else if(h <= 0 || h > 24
  104. || min < 0 || min >= 60)
  105. activeChar.sendMessage("Wrong hour/minutes gave!");
  106. else
  107. {
  108. Calendar c = Calendar.getInstance();
  109. c.set(Calendar.YEAR, year);
  110. c.set(Calendar.MONTH, month);
  111. c.set(Calendar.DAY_OF_MONTH, d);
  112. c.set(Calendar.HOUR_OF_DAY, h);
  113. c.set(Calendar.MINUTE, min);
  114. c.set(Calendar.SECOND, 0);
  115. if(c.getTimeInMillis() > System.currentTimeMillis())
  116. {
  117. activeChar.sendMessage(hall.getName()+" siege: "+c.getTime().toString());
  118. hall.setNextSiegeDate(c.getTimeInMillis());
  119. hall.getSiege().updateSiege();
  120. hall.updateDb();
  121. }
  122. else
  123. activeChar.sendMessage("The given time is in the past!");
  124. }
  125. }
  126. }
  127. }
  128. }
  129. else if(split[0].equals(COMMANDS[4]))
  130. {
  131. if(hall.isInSiege())
  132. {
  133. activeChar.sendMessage("The clan hall is in siege, cannot add attackers now.");
  134. return false;
  135. }
  136. L2Clan attacker = null;
  137. if(split.length < 3)
  138. {
  139. L2Object rawTarget = activeChar.getTarget();
  140. L2PcInstance target = null;
  141. if(rawTarget == null)
  142. activeChar.sendMessage("You must target a clan member of the attacker!");
  143. else if(!(rawTarget instanceof L2PcInstance))
  144. activeChar.sendMessage("You must target a player with clan!");
  145. else if((target = (L2PcInstance)rawTarget).getClan() == null)
  146. activeChar.sendMessage("Your target does not have any clan!");
  147. else if(hall.getSiege().checkIsAttacker(target.getClan()))
  148. activeChar.sendMessage("Your target's clan is alredy participating!");
  149. else
  150. attacker = target.getClan();
  151. }
  152. else
  153. {
  154. L2Clan rawClan = ClanTable.getInstance().getClanByName(split[2]);
  155. if(rawClan == null)
  156. activeChar.sendMessage("The given clan does not exist!");
  157. else if(hall.getSiege().checkIsAttacker(rawClan))
  158. activeChar.sendMessage("The given clan is alredy participating!");
  159. else
  160. attacker = rawClan;
  161. }
  162. if(attacker != null)
  163. hall.addAttacker(attacker);
  164. }
  165. else if(split[0].equals(COMMANDS[5]))
  166. {
  167. if(hall.isInSiege())
  168. {
  169. activeChar.sendMessage("The clan hall is in siege, cannot remove attackers now.");
  170. return false;
  171. }
  172. if(split.length < 3)
  173. {
  174. L2Object rawTarget = activeChar.getTarget();
  175. L2PcInstance target = null;
  176. if(rawTarget == null)
  177. activeChar.sendMessage("You must target a clan member of the attacker!");
  178. else if(!(rawTarget instanceof L2PcInstance))
  179. activeChar.sendMessage("You must target a player with clan!");
  180. else if((target = (L2PcInstance)rawTarget).getClan() == null)
  181. activeChar.sendMessage("Your target does not have any clan!");
  182. else if(!hall.getSiege().checkIsAttacker(target.getClan()))
  183. activeChar.sendMessage("Your target's clan is not participating!");
  184. else
  185. hall.removeAttacker(target.getClan());
  186. }
  187. else
  188. {
  189. L2Clan rawClan = ClanTable.getInstance().getClanByName(split[2]);
  190. if(rawClan == null)
  191. activeChar.sendMessage("The given clan does not exist!");
  192. else if(!hall.getSiege().checkIsAttacker(rawClan))
  193. activeChar.sendMessage("The given clan is not participating!");
  194. else
  195. hall.removeAttacker(rawClan);
  196. }
  197. }
  198. else if(split[0].equals(COMMANDS[6]))
  199. {
  200. if(hall.isInSiege())
  201. activeChar.sendMessage("The requested hall is in siege right now, cannot clear attacker list!");
  202. else
  203. {
  204. ClanHallSiegeEngine siegable = hall.getSiege();
  205. siegable.getAttackers().clear();
  206. }
  207. }
  208. else if(split[0].equals(COMMANDS[7]))
  209. activeChar.sendPacket(new SiegeInfo(hall));
  210. else if(split[0].equals(COMMANDS[8]))
  211. {
  212. ClanHallSiegeEngine siegable = hall.getSiege();
  213. siegable.cancelSiegeTask();
  214. switch(hall.getSiegeStatus())
  215. {
  216. case REGISTERING:
  217. siegable.prepareOwner();
  218. break;
  219. case WAITING_BATTLE:
  220. siegable.startSiege();
  221. break;
  222. case RUNNING:
  223. siegable.endSiege();
  224. break;
  225. }
  226. }
  227. sendSiegableHallPage(activeChar, split[1], hall);
  228. return false;
  229. }
  230. private SiegableHall getHall(String id, L2PcInstance gm)
  231. {
  232. int ch = parseInt(id);
  233. if(ch == 0)
  234. {
  235. gm.sendMessage("Wrong clan hall id, unparseable id!");
  236. return null;
  237. }
  238. SiegableHall hall = CHSiegeManager.getInstance().getSiegableHall(ch);
  239. if(hall == null)
  240. gm.sendMessage("Couldnt find the clan hall.");
  241. return hall;
  242. }
  243. private int parseInt(String st)
  244. {
  245. int val = 0;
  246. try
  247. {
  248. val = Integer.parseInt(st);
  249. }
  250. catch(NumberFormatException e)
  251. {
  252. e.printStackTrace();
  253. }
  254. return val;
  255. }
  256. private void sendSiegableHallPage(L2PcInstance activeChar, String hallId, SiegableHall hall)
  257. {
  258. NpcHtmlMessage msg = new NpcHtmlMessage(5);
  259. msg.setFile(null, "data/html/admin/siegablehall.htm");
  260. msg.replace("%clanhallId%", hallId);
  261. msg.replace("%clanhallName%", hall.getName());
  262. if(hall.getOwnerId() > 0)
  263. {
  264. L2Clan owner = ClanTable.getInstance().getClan(hall.getOwnerId());
  265. if(owner != null)
  266. msg.replace("%clanhallOwner%", owner.getName());
  267. else
  268. msg.replace("%clanhallOwner%", "No Owner");
  269. }
  270. else
  271. msg.replace("%clanhallOwner%", "No Owner");
  272. activeChar.sendPacket(msg);
  273. }
  274. }