RequestActionUse.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.clientpackets;
  16. import java.util.Map;
  17. import java.util.logging.Logger;
  18. import net.sf.l2j.Config;
  19. import net.sf.l2j.gameserver.ai.CtrlIntention;
  20. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  21. import net.sf.l2j.gameserver.model.L2CharPosition;
  22. import net.sf.l2j.gameserver.model.L2Character;
  23. import net.sf.l2j.gameserver.model.L2ManufactureList;
  24. import net.sf.l2j.gameserver.model.L2Object;
  25. import net.sf.l2j.gameserver.model.L2Skill;
  26. import net.sf.l2j.gameserver.model.L2Summon;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  28. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  29. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2SiegeSummonInstance;
  31. import net.sf.l2j.gameserver.model.actor.instance.L2StaticObjectInstance;
  32. import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  33. import net.sf.l2j.gameserver.network.SystemMessageId;
  34. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  35. import net.sf.l2j.gameserver.serverpackets.ChairSit;
  36. import net.sf.l2j.gameserver.serverpackets.RecipeShopManageList;
  37. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  38. /**
  39. * This class ...
  40. *
  41. * @version $Revision: 1.11.2.7.2.9 $ $Date: 2005/04/06 16:13:48 $
  42. */
  43. public final class RequestActionUse extends L2GameClientPacket
  44. {
  45. private static final String _C__45_REQUESTACTIONUSE = "[C] 45 RequestActionUse";
  46. private static Logger _log = Logger.getLogger(RequestActionUse.class.getName());
  47. private int _actionId;
  48. private boolean _ctrlPressed;
  49. private boolean _shiftPressed;
  50. @Override
  51. protected void readImpl()
  52. {
  53. _actionId = readD();
  54. _ctrlPressed = (readD() == 1);
  55. _shiftPressed = (readC() == 1);
  56. }
  57. @Override
  58. protected void runImpl()
  59. {
  60. L2PcInstance activeChar = getClient().getActiveChar();
  61. if (activeChar == null)
  62. return;
  63. if (Config.DEBUG)
  64. _log.finest(activeChar.getName()+" request Action use: id "+_actionId + " 2:" + _ctrlPressed + " 3:"+_shiftPressed);
  65. // dont do anything if player is dead
  66. if (activeChar.isAlikeDead())
  67. {
  68. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  69. return;
  70. }
  71. // don't do anything if player is confused
  72. if (activeChar.isOutOfControl())
  73. {
  74. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  75. return;
  76. }
  77. // don't do anything if player is transformed
  78. if (activeChar.isTransformed())
  79. {
  80. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  81. return;
  82. }
  83. L2Summon pet = activeChar.getPet();
  84. L2Object target = activeChar.getTarget();
  85. if (Config.DEBUG)
  86. _log.info("Requested Action ID: " + String.valueOf(_actionId));
  87. switch (_actionId)
  88. {
  89. case 0:
  90. if (activeChar.getMountType() != 0)
  91. break;
  92. if (target != null
  93. && !activeChar.isSitting()
  94. && target instanceof L2StaticObjectInstance
  95. && ((L2StaticObjectInstance)target).getType() == 1
  96. && CastleManager.getInstance().getCastle(target) != null
  97. && activeChar.isInsideRadius(target, L2StaticObjectInstance.INTERACTION_DISTANCE, false, false)
  98. )
  99. {
  100. ChairSit cs = new ChairSit(activeChar,((L2StaticObjectInstance)target).getStaticObjectId());
  101. activeChar.sendPacket(cs);
  102. activeChar.sitDown();
  103. activeChar.broadcastPacket(cs);
  104. break;
  105. }
  106. if (activeChar.isSitting())
  107. activeChar.standUp();
  108. else
  109. activeChar.sitDown();
  110. if (Config.DEBUG)
  111. _log.fine("new wait type: "+(activeChar.isSitting() ? "SITTING" : "STANDING"));
  112. break;
  113. case 1:
  114. if (activeChar.isRunning())
  115. activeChar.setWalking();
  116. else
  117. activeChar.setRunning();
  118. if (Config.DEBUG)
  119. _log.fine("new move type: "+(activeChar.isRunning() ? "RUNNING" : "WALKIN"));
  120. break;
  121. case 10:
  122. // Private Store Sell
  123. activeChar.tryOpenPrivateSellStore(false);
  124. break;
  125. case 28:
  126. activeChar.tryOpenPrivateBuyStore();
  127. break;
  128. case 15:
  129. case 21: // pet follow/stop
  130. if (pet != null && !pet.isMovementDisabled() && !activeChar.isBetrayed())
  131. pet.setFollowStatus(!pet.getFollowStatus());
  132. break;
  133. case 16:
  134. case 22: // pet attack
  135. if (target != null && pet != null && pet != target && !pet.isAttackingDisabled() && !pet.isBetrayed())
  136. {
  137. if (pet instanceof L2PetInstance && (pet.getLevel() - activeChar.getLevel() > 20))
  138. {
  139. activeChar.sendPacket(new SystemMessage(SystemMessageId.PET_TOO_HIGH_TO_CONTROL));
  140. return;
  141. }
  142. if (activeChar.isInOlympiadMode() && !activeChar.isOlympiadStart()){
  143. // if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
  144. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  145. return;
  146. }
  147. if (!activeChar.getAccessLevel().allowPeaceAttack() &&
  148. activeChar.isInsidePeaceZone(pet, target))
  149. {
  150. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  151. return;
  152. }
  153. if (target.isAutoAttackable(activeChar) || _ctrlPressed)
  154. {
  155. if (target instanceof L2DoorInstance)
  156. {
  157. if(((L2DoorInstance)target).isAttackable(activeChar) && pet.getNpcId() != L2SiegeSummonInstance.SWOOP_CANNON_ID)
  158. pet.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  159. }
  160. // siege golem AI doesn't support attacking other than doors at the moment
  161. else if (pet.getNpcId() != L2SiegeSummonInstance.SIEGE_GOLEM_ID)
  162. pet.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  163. }
  164. }
  165. break;
  166. case 17:
  167. case 23: // pet - cancel action
  168. if (pet != null && !pet.isMovementDisabled() && !activeChar.isBetrayed())
  169. pet.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
  170. break;
  171. case 19: // pet unsummon
  172. if (pet != null)
  173. {
  174. //returns pet to control item
  175. if (pet.isDead())
  176. {
  177. activeChar.sendPacket(new SystemMessage(SystemMessageId.DEAD_PET_CANNOT_BE_RETURNED));
  178. }
  179. else if (pet.isAttackingNow() || pet.isRooted() || pet.isBetrayed())
  180. {
  181. activeChar.sendPacket(new SystemMessage(SystemMessageId.PET_CANNOT_SENT_BACK_DURING_BATTLE));
  182. }
  183. else
  184. {
  185. // if it is a pet and not a summon
  186. if (pet instanceof L2PetInstance)
  187. {
  188. L2PetInstance petInst = (L2PetInstance)pet;
  189. // if the pet is more than 40% fed
  190. if (petInst.getCurrentFed() > (petInst.getMaxFed() * 0.40))
  191. pet.unSummon(activeChar);
  192. else
  193. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_CANNOT_RESTORE_HUNGRY_PETS));
  194. }
  195. }
  196. }
  197. break;
  198. case 38: // pet mount
  199. // mount
  200. if (pet != null && pet.isMountable() && !activeChar.isMounted() && !activeChar.isBetrayed())
  201. {
  202. if (activeChar.isDead())
  203. {
  204. //A strider cannot be ridden when dead
  205. SystemMessage msg = new SystemMessage(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_DEAD);
  206. activeChar.sendPacket(msg);
  207. msg = null;
  208. }
  209. if (activeChar.isTransformed())
  210. {
  211. // You cannot mount a steed while transformed.
  212. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  213. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_TRANSFORMED);
  214. activeChar.sendPacket(msg);
  215. return;
  216. }
  217. else if (pet.isDead())
  218. {
  219. //A dead strider cannot be ridden.
  220. SystemMessage msg = new SystemMessage(SystemMessageId.DEAD_STRIDER_CANT_BE_RIDDEN);
  221. activeChar.sendPacket(msg);
  222. msg = null;
  223. }
  224. else if (pet.isInCombat() || pet.isRooted())
  225. {
  226. //A strider in battle cannot be ridden
  227. SystemMessage msg = new SystemMessage(SystemMessageId.STRIDER_IN_BATLLE_CANT_BE_RIDDEN);
  228. activeChar.sendPacket(msg);
  229. msg = null;
  230. }
  231. else if (activeChar.isInCombat() || activeChar.getPvpFlag() != 0)
  232. {
  233. //A strider cannot be ridden while in battle
  234. SystemMessage msg = new SystemMessage(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_IN_BATTLE);
  235. activeChar.sendPacket(msg);
  236. msg = null;
  237. }
  238. else if (activeChar.isSitting() || activeChar.isMoving() || activeChar.isInsideZone(L2Character.ZONE_WATER))
  239. {
  240. //A strider can be ridden only when standing
  241. SystemMessage msg = new SystemMessage(SystemMessageId.STRIDER_CAN_BE_RIDDEN_ONLY_WHILE_STANDING);
  242. activeChar.sendPacket(msg);
  243. msg = null;
  244. }
  245. else if (activeChar.isFishing())
  246. {
  247. //You can't mount, dismount, break and drop items while fishing
  248. SystemMessage msg = new SystemMessage(SystemMessageId.CANNOT_DO_WHILE_FISHING_2);
  249. activeChar.sendPacket(msg);
  250. msg = null;
  251. }
  252. else if (activeChar.isCursedWeaponEquipped())
  253. {
  254. //You can't mount, dismount, break and drop items while weilding a cursed weapon
  255. SystemMessage msg = new SystemMessage(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_IN_BATTLE);
  256. activeChar.sendPacket(msg);
  257. }
  258. else if (!pet.isDead() && !activeChar.isMounted())
  259. {
  260. activeChar.mount(pet);
  261. }
  262. }
  263. else if (activeChar.isRentedPet())
  264. {
  265. activeChar.stopRentPet();
  266. }
  267. else if (activeChar.isMounted())
  268. {
  269. activeChar.dismount();
  270. }
  271. break;
  272. case 32: // Wild Hog Cannon - Mode Change
  273. useSkill(4230);
  274. break;
  275. case 36: // Soulless - Toxic Smoke
  276. useSkill(4259);
  277. break;
  278. case 37:
  279. if (activeChar.isAlikeDead())
  280. {
  281. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  282. return;
  283. }
  284. if(activeChar.getPrivateStoreType() != 0){
  285. activeChar.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
  286. activeChar.broadcastUserInfo();
  287. }
  288. if (activeChar.isSitting())
  289. activeChar.standUp();
  290. if (activeChar.getCreateList() == null)
  291. {
  292. activeChar.setCreateList(new L2ManufactureList());
  293. }
  294. activeChar.sendPacket(new RecipeShopManageList(activeChar, true));
  295. break;
  296. case 39: // Soulless - Parasite Burst
  297. useSkill(4138);
  298. break;
  299. case 41: // Wild Hog Cannon - Attack
  300. useSkill(4230);
  301. break;
  302. case 42: // Kai the Cat - Self Damage Shield
  303. useSkill(4378, activeChar);
  304. break;
  305. case 43: // Unicorn Merrow - Hydro Screw
  306. useSkill(4137);
  307. break;
  308. case 44: // Big Boom - Boom Attack
  309. useSkill(4139);
  310. break;
  311. case 45: // Unicorn Boxer - Master Recharge
  312. useSkill(4025, activeChar);
  313. break;
  314. case 46: // Mew the Cat - Mega Storm Strike
  315. useSkill(4261);
  316. break;
  317. case 47: // Silhouette - Steal Blood
  318. useSkill(4260);
  319. break;
  320. case 48: // Mechanic Golem - Mech. Cannon
  321. useSkill(4068);
  322. break;
  323. case 51:
  324. // Player shouldn't be able to set stores if he/she is alike dead (dead or fake death)
  325. if (activeChar.isAlikeDead())
  326. {
  327. getClient().sendPacket(ActionFailed.STATIC_PACKET);
  328. return;
  329. }
  330. if(activeChar.getPrivateStoreType() != 0){
  331. activeChar.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
  332. activeChar.broadcastUserInfo();
  333. }
  334. if (activeChar.isSitting())
  335. activeChar.standUp();
  336. if (activeChar.getCreateList() == null)
  337. activeChar.setCreateList(new L2ManufactureList());
  338. activeChar.sendPacket(new RecipeShopManageList(activeChar, false));
  339. break;
  340. case 52: // unsummon
  341. if (pet != null && pet instanceof L2SummonInstance)
  342. pet.unSummon(activeChar);
  343. break;
  344. case 53: // move to target
  345. if (target != null && pet != null && pet != target && !pet.isMovementDisabled())
  346. {
  347. pet.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO,
  348. new L2CharPosition(target.getX(),target.getY(), target.getZ(), 0 ));
  349. }
  350. break;
  351. case 54: // move to target hatch/strider
  352. if (target != null && pet != null && pet != target && !pet.isMovementDisabled())
  353. {
  354. pet.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO,
  355. new L2CharPosition(target.getX(),target.getY(), target.getZ(), 0 ));
  356. }
  357. break;
  358. case 61:
  359. // Private Store Package Sell
  360. activeChar.tryOpenPrivateSellStore(true);
  361. break;
  362. case 96: // Quit Party Command Channel
  363. _log.info("98 Accessed");
  364. break;
  365. case 97: // Request Party Command Channel Info
  366. //if (!PartyCommandManager.getInstance().isPlayerInChannel(activeChar))
  367. //return;
  368. _log.info("97 Accessed");
  369. //PartyCommandManager.getInstance().getActiveChannelInfo(activeChar);
  370. break;
  371. case 1000: // Siege Golem - Siege Hammer
  372. if (target instanceof L2DoorInstance) useSkill(4079);
  373. break;
  374. case 1001:
  375. break;
  376. case 1003: // Wind Hatchling/Strider - Wild Stun
  377. useSkill(4710); //TODO use correct skill lvl based on pet lvl
  378. break;
  379. case 1004: // Wind Hatchling/Strider - Wild Defense
  380. useSkill(4711, activeChar); //TODO use correct skill lvl based on pet lvl
  381. break;
  382. case 1005: // Star Hatchling/Strider - Bright Burst
  383. useSkill(4712); //TODO use correct skill lvl based on pet lvl
  384. break;
  385. case 1006: // Star Hatchling/Strider - Bright Heal
  386. useSkill(4713, activeChar); //TODO use correct skill lvl based on pet lvl
  387. break;
  388. case 1007: // Cat Queen - Blessing of Queen
  389. useSkill(4699, activeChar);
  390. break;
  391. case 1008: // Cat Queen - Gift of Queen
  392. useSkill(4700, activeChar);
  393. break;
  394. case 1009: // Cat Queen - Cure of Queen
  395. useSkill(4701);
  396. break;
  397. case 1010: // Unicorn Seraphim - Blessing of Seraphim
  398. useSkill(4702, activeChar);
  399. break;
  400. case 1011: // Unicorn Seraphim - Gift of Seraphim
  401. useSkill(4703, activeChar);
  402. break;
  403. case 1012: // Unicorn Seraphim - Cure of Seraphim
  404. useSkill(4704);
  405. break;
  406. case 1013: // Nightshade - Curse of Shade
  407. useSkill(4705);
  408. break;
  409. case 1014: // Nightshade - Mass Curse of Shade
  410. useSkill(4706, activeChar);
  411. break;
  412. case 1015: // Nightshade - Shade Sacrifice
  413. useSkill(4707);
  414. break;
  415. case 1016: // Cursed Man - Cursed Blow
  416. useSkill(4709);
  417. break;
  418. case 1017: // Cursed Man - Cursed Strike/Stun
  419. useSkill(4708);
  420. break;
  421. case 1031: // Feline King - Slash
  422. useSkill(5135);
  423. break;
  424. case 1032: // Feline King - Spinning Slash
  425. useSkill(5136);
  426. break;
  427. case 1033: // Feline King - Grip of the Cat
  428. useSkill(5137);
  429. break;
  430. case 1034: // Magnus the Unicorn - Whiplash
  431. useSkill(5138);
  432. break;
  433. case 1035: // Magnus the Unicorn - Tridal Wave
  434. useSkill(5139);
  435. break;
  436. case 1036: // Spectral Lord - Corpse Kaboom
  437. useSkill(5142);
  438. break;
  439. case 1037: // Spectral Lord - Dicing Death
  440. useSkill(5141);
  441. break;
  442. case 1038: // Spectral Lord - Force Curse
  443. useSkill(5140);
  444. break;
  445. case 1039: // Swoop Cannon - Cannon Fodder
  446. if (!(target instanceof L2DoorInstance))
  447. useSkill(5110);
  448. break;
  449. case 1040: // Swoop Cannon - Big Bang
  450. if (!(target instanceof L2DoorInstance))
  451. useSkill(5111);
  452. break;
  453. case 1041: // Great Wolf - Bite Attack
  454. useSkill(5442);
  455. break;
  456. case 1042: // Great Wolf - Maul
  457. useSkill(5444);
  458. break;
  459. case 1043: // Great Wolf - Cry of the Wolf
  460. useSkill(5443);
  461. break;
  462. case 1044: // Great Wolf - Awakening
  463. useSkill(5445);
  464. break;
  465. case 1045: // Great Wolf - Howl
  466. useSkill(5584);
  467. break;
  468. default:
  469. _log.warning(activeChar.getName()+": unhandled action type "+_actionId);
  470. }
  471. }
  472. /*
  473. * Cast a skill for active pet/servitor.
  474. * Target is specified as a parameter but can be
  475. * overwrited or ignored depending on skill type.
  476. */
  477. private void useSkill(int skillId, L2Object target)
  478. {
  479. L2PcInstance activeChar = getClient().getActiveChar();
  480. if (activeChar == null) return;
  481. L2Summon activeSummon = activeChar.getPet();
  482. if (activeChar.getPrivateStoreType() != 0)
  483. {
  484. activeChar.sendMessage("Cannot use skills while trading");
  485. return;
  486. }
  487. if (activeSummon != null && !activeSummon.isBetrayed())
  488. {
  489. if (activeSummon instanceof L2PetInstance && (activeSummon.getLevel() - activeChar.getLevel() > 20))
  490. {
  491. activeChar.sendPacket(new SystemMessage(SystemMessageId.PET_TOO_HIGH_TO_CONTROL));
  492. return;
  493. }
  494. Map<Integer, L2Skill> _skills = activeSummon.getTemplate().getSkills();
  495. if (_skills == null) return;
  496. if (_skills.size() == 0)
  497. {
  498. activeChar.sendPacket(new SystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE));
  499. return;
  500. }
  501. L2Skill skill = _skills.get(skillId);
  502. if (skill == null)
  503. {
  504. if (Config.DEBUG)
  505. _log.warning("Skill " + skillId + " missing from npcskills.sql for a summon id " + activeSummon.getNpcId());
  506. return;
  507. }
  508. activeSummon.setTarget(target);
  509. activeSummon.useMagic(skill, _ctrlPressed, _shiftPressed);
  510. }
  511. }
  512. /*
  513. * Cast a skill for active pet/servitor.
  514. * Target is retrieved from owner' target,
  515. * then validated by overloaded method useSkill(int, L2Character).
  516. */
  517. private void useSkill(int skillId)
  518. {
  519. L2PcInstance activeChar = getClient().getActiveChar();
  520. if (activeChar == null) return;
  521. useSkill(skillId, activeChar.getTarget());
  522. }
  523. @Override
  524. public String getType()
  525. {
  526. return _C__45_REQUESTACTIONUSE;
  527. }
  528. }