AdminCHSiege.java 8.9 KB

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