L2Summon.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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.model;
  16. import java.util.Collection;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.GeoData;
  19. import net.sf.l2j.gameserver.Olympiad;
  20. import net.sf.l2j.gameserver.ai.CtrlIntention;
  21. import net.sf.l2j.gameserver.ai.L2CharacterAI;
  22. import net.sf.l2j.gameserver.ai.L2SummonAI;
  23. import net.sf.l2j.gameserver.datatables.SkillTable;
  24. import net.sf.l2j.gameserver.model.L2Attackable.AggroInfo;
  25. import net.sf.l2j.gameserver.model.L2Skill.SkillTargetType;
  26. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  28. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  29. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  31. import net.sf.l2j.gameserver.model.actor.knownlist.SummonKnownList;
  32. import net.sf.l2j.gameserver.model.actor.stat.SummonStat;
  33. import net.sf.l2j.gameserver.model.actor.status.SummonStatus;
  34. import net.sf.l2j.gameserver.model.base.Experience;
  35. import net.sf.l2j.gameserver.network.SystemMessageId;
  36. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  37. import net.sf.l2j.gameserver.serverpackets.ExPartyPetWindowAdd;
  38. import net.sf.l2j.gameserver.serverpackets.ExPartyPetWindowDelete;
  39. import net.sf.l2j.gameserver.serverpackets.ExPartyPetWindowUpdate;
  40. import net.sf.l2j.gameserver.serverpackets.MyTargetSelected;
  41. import net.sf.l2j.gameserver.serverpackets.NpcInfo;
  42. import net.sf.l2j.gameserver.serverpackets.PartySpelled;
  43. import net.sf.l2j.gameserver.serverpackets.PetDelete;
  44. import net.sf.l2j.gameserver.serverpackets.PetInfo;
  45. import net.sf.l2j.gameserver.serverpackets.PetStatusShow;
  46. import net.sf.l2j.gameserver.serverpackets.PetStatusUpdate;
  47. import net.sf.l2j.gameserver.serverpackets.RelationChanged;
  48. import net.sf.l2j.gameserver.serverpackets.StatusUpdate;
  49. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  50. import net.sf.l2j.gameserver.taskmanager.DecayTaskManager;
  51. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  52. import net.sf.l2j.gameserver.templates.L2Weapon;
  53. public abstract class L2Summon extends L2PlayableInstance
  54. {
  55. //private static Logger _log = Logger.getLogger(L2Summon.class.getName());
  56. protected int _pkKills;
  57. private byte _pvpFlag;
  58. private L2PcInstance _owner;
  59. private int _karma = 0;
  60. private int _attackRange = 36; //Melee range
  61. private boolean _follow = true;
  62. private boolean _previousFollowStatus = true;
  63. private int _maxLoad;
  64. private int _chargedSoulShot;
  65. private int _chargedSpiritShot;
  66. // TODO: currently, all servitors use 1 shot. However, this value
  67. // should vary depending on the servitor template (id and level)!
  68. private int _soulShotsPerHit = 1;
  69. private int _spiritShotsPerHit = 1;
  70. protected boolean _showSummonAnimation;
  71. public class AIAccessor extends L2Character.AIAccessor
  72. {
  73. protected AIAccessor() {}
  74. public L2Summon getSummon() { return L2Summon.this; }
  75. public boolean isAutoFollow() {
  76. return L2Summon.this.getFollowStatus();
  77. }
  78. public void doPickupItem(L2Object object) {
  79. L2Summon.this.doPickupItem(object);
  80. }
  81. }
  82. public L2Summon(int objectId, L2NpcTemplate template, L2PcInstance owner)
  83. {
  84. super(objectId, template);
  85. getKnownList(); // init knownlist
  86. getStat(); // init stats
  87. getStatus(); // init status
  88. _showSummonAnimation = true;
  89. _owner = owner;
  90. _ai = new L2SummonAI(new L2Summon.AIAccessor());
  91. setXYZInvisible(owner.getX()+50, owner.getY()+100, owner.getZ()+100);
  92. }
  93. @Override
  94. public void onSpawn()
  95. {
  96. super.onSpawn();
  97. this.setFollowStatus(true);
  98. this.setShowSummonAnimation(false); // addVisibleObject created the info packets with summon animation
  99. // if someone comes into range now, the animation shouldnt show any more
  100. this.getOwner().sendPacket(new PetInfo(this));
  101. getOwner().sendPacket(new RelationChanged(this, getOwner().getRelation(getOwner()), false));
  102. for (L2PcInstance player : getOwner().getKnownList().getKnownPlayersInRadius(800))
  103. player.sendPacket(new RelationChanged(this, getOwner().getRelation(player), isAutoAttackable(player)));
  104. L2Party party = this.getOwner().getParty();
  105. if (party != null)
  106. {
  107. party.broadcastToPartyMembers(this.getOwner(), new ExPartyPetWindowAdd(this));
  108. }
  109. }
  110. @Override
  111. public final SummonKnownList getKnownList()
  112. {
  113. if(!(super.getKnownList() instanceof SummonKnownList))
  114. setKnownList(new SummonKnownList(this));
  115. return (SummonKnownList)super.getKnownList();
  116. }
  117. @Override
  118. public SummonStat getStat()
  119. {
  120. if(!(super.getStat() instanceof SummonStat))
  121. setStat(new SummonStat(this));
  122. return (SummonStat)super.getStat();
  123. }
  124. @Override
  125. public SummonStatus getStatus()
  126. {
  127. if(!(super.getStatus() instanceof SummonStatus))
  128. setStatus(new SummonStatus(this));
  129. return (SummonStatus)super.getStatus();
  130. }
  131. @Override
  132. public L2CharacterAI getAI()
  133. {
  134. if (_ai == null)
  135. {
  136. synchronized(this)
  137. {
  138. if (_ai == null)
  139. _ai = new L2SummonAI(new L2Summon.AIAccessor());
  140. }
  141. }
  142. return _ai;
  143. }
  144. @Override
  145. public L2NpcTemplate getTemplate()
  146. {
  147. return (L2NpcTemplate)super.getTemplate();
  148. }
  149. // this defines the action buttons, 1 for Summon, 2 for Pets
  150. public abstract int getSummonType();
  151. @Override
  152. public void updateAbnormalEffect()
  153. {
  154. for (L2PcInstance player : getKnownList().getKnownPlayers().values())
  155. player.sendPacket(new NpcInfo(this, player));
  156. }
  157. /**
  158. * @return Returns the mountable.
  159. */
  160. public boolean isMountable()
  161. {
  162. return false;
  163. }
  164. public boolean isMountableOverTime()
  165. {
  166. return false;
  167. }
  168. @Override
  169. public void onAction(L2PcInstance player)
  170. {
  171. if (player == _owner && player.getTarget() == this)
  172. {
  173. player.sendPacket(new PetStatusShow(this));
  174. player.sendPacket(ActionFailed.STATIC_PACKET);
  175. }
  176. else if (player.getTarget() != this)
  177. {
  178. if (Config.DEBUG) _log.fine("new target selected:"+getObjectId());
  179. player.setTarget(this);
  180. MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
  181. player.sendPacket(my);
  182. //sends HP/MP status of the summon to other characters
  183. StatusUpdate su = new StatusUpdate(getObjectId());
  184. su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
  185. su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
  186. player.sendPacket(su);
  187. }
  188. else if (player.getTarget() == this)
  189. {
  190. if (isAutoAttackable(player))
  191. {
  192. if (Config.GEODATA > 0)
  193. {
  194. if (GeoData.getInstance().canSeeTarget(player, this))
  195. {
  196. player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
  197. player.onActionRequest();
  198. }
  199. }
  200. else
  201. {
  202. player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
  203. player.onActionRequest();
  204. }
  205. }
  206. else
  207. {
  208. // This Action Failed packet avoids player getting stuck when clicking three or more times
  209. player.sendPacket(ActionFailed.STATIC_PACKET);
  210. if (Config.GEODATA > 0)
  211. {
  212. if (GeoData.getInstance().canSeeTarget(player, this))
  213. player.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, this);
  214. }
  215. else
  216. player.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, this);
  217. }
  218. }
  219. }
  220. public long getExpForThisLevel()
  221. {
  222. if(getLevel() >= Experience.LEVEL.length)
  223. {
  224. return 0;
  225. }
  226. return Experience.LEVEL[getLevel()];
  227. }
  228. public long getExpForNextLevel()
  229. {
  230. if(getLevel() >= Experience.LEVEL.length - 1)
  231. {
  232. return 0;
  233. }
  234. return Experience.LEVEL[getLevel()+1];
  235. }
  236. public final int getKarma()
  237. {
  238. return _karma;
  239. }
  240. public void setKarma(int karma)
  241. {
  242. _karma = karma;
  243. }
  244. public final L2PcInstance getOwner()
  245. {
  246. return _owner;
  247. }
  248. public final int getNpcId()
  249. {
  250. return getTemplate().npcId;
  251. }
  252. public void setPvpFlag(byte pvpFlag)
  253. {
  254. _pvpFlag = pvpFlag;
  255. }
  256. public byte getPvpFlag()
  257. {
  258. return _pvpFlag;
  259. }
  260. public void setPkKills(int pkKills)
  261. {
  262. _pkKills = pkKills;
  263. }
  264. public final int getPkKills()
  265. {
  266. return _pkKills;
  267. }
  268. public final int getMaxLoad()
  269. {
  270. return _maxLoad;
  271. }
  272. public final int getSoulShotsPerHit()
  273. {
  274. return _soulShotsPerHit;
  275. }
  276. public final int getSpiritShotsPerHit()
  277. {
  278. return _spiritShotsPerHit;
  279. }
  280. public void setMaxLoad(int maxLoad)
  281. {
  282. _maxLoad = maxLoad;
  283. }
  284. public void setChargedSoulShot(int shotType)
  285. {
  286. _chargedSoulShot = shotType;
  287. }
  288. public void setChargedSpiritShot(int shotType)
  289. {
  290. _chargedSpiritShot = shotType;
  291. }
  292. public void followOwner()
  293. {
  294. setFollowStatus(true);
  295. }
  296. @Override
  297. public boolean doDie(L2Character killer)
  298. {
  299. if (!super.doDie(killer))
  300. return false;
  301. L2PcInstance owner = getOwner();
  302. if (owner != null)
  303. {
  304. Collection<L2Character> KnownTarget = this.getKnownList().getKnownCharacters();
  305. for (L2Character TgMob : KnownTarget)
  306. {
  307. // get the mobs which have aggro on the this instance
  308. if (TgMob instanceof L2Attackable)
  309. {
  310. if (((L2Attackable) TgMob).isDead())
  311. continue;
  312. AggroInfo info = ((L2Attackable) TgMob).getAggroListRP().get(this);
  313. if (info != null)
  314. ((L2Attackable) TgMob).addDamageHate(owner, info._damage, info._hate);
  315. }
  316. }
  317. }
  318. DecayTaskManager.getInstance().addDecayTask(this);
  319. return true;
  320. }
  321. public boolean doDie(L2Character killer, boolean decayed)
  322. {
  323. if (!super.doDie(killer))
  324. return false;
  325. if (!decayed)
  326. {
  327. DecayTaskManager.getInstance().addDecayTask(this);
  328. }
  329. return true;
  330. }
  331. public void stopDecay()
  332. {
  333. DecayTaskManager.getInstance().cancelDecayTask(this);
  334. }
  335. @Override
  336. public void onDecay()
  337. {
  338. deleteMe(_owner);
  339. }
  340. @Override
  341. public void broadcastStatusUpdate()
  342. {
  343. super.broadcastStatusUpdate();
  344. if (isVisible())
  345. {
  346. getOwner().sendPacket(new PetStatusUpdate(this));
  347. L2Party party = this.getOwner().getParty();
  348. if (party != null)
  349. {
  350. party.broadcastToPartyMembers(this.getOwner(), new ExPartyPetWindowUpdate(this));
  351. }
  352. }
  353. }
  354. @Override
  355. public void updateEffectIcons(boolean partyOnly)
  356. {
  357. PartySpelled ps = new PartySpelled(this);
  358. // Go through all effects if any
  359. L2Effect[] effects = getAllEffects();
  360. if (effects != null && effects.length > 0)
  361. {
  362. for (int i = 0; i < effects.length; i++)
  363. {
  364. L2Effect effect = effects[i];
  365. if (effect == null)
  366. continue;
  367. if (effect.getInUse())
  368. {
  369. effect.addPartySpelledIcon(ps);
  370. }
  371. }
  372. }
  373. L2Party party = this.getOwner().getParty();
  374. if (party != null)
  375. {
  376. // tell everyone about the summon effect
  377. party.broadcastToPartyMembers(ps);
  378. }
  379. else
  380. {
  381. // tell only the owner
  382. this.getOwner().sendPacket(ps);
  383. }
  384. }
  385. public void deleteMe(L2PcInstance owner)
  386. {
  387. getAI().stopFollow();
  388. owner.sendPacket(new PetDelete(getObjectId(), 2));
  389. //FIXME: I think it should really drop items to ground and only owner can take for a while
  390. giveAllToOwner();
  391. decayMe();
  392. getKnownList().removeAllKnownObjects();
  393. owner.setPet(null);
  394. }
  395. public void onSummon()
  396. {
  397. }
  398. public synchronized void unSummon(L2PcInstance owner)
  399. {
  400. if (isVisible() && !isDead())
  401. {
  402. getAI().stopFollow();
  403. owner.sendPacket(new PetDelete(getObjectId(), 2));
  404. L2Party party;
  405. if ((party = owner.getParty()) != null)
  406. {
  407. party.broadcastToPartyMembers(owner, new ExPartyPetWindowDelete(this));
  408. }
  409. store();
  410. giveAllToOwner();
  411. L2WorldRegion oldRegion = getWorldRegion();
  412. decayMe();
  413. if (oldRegion != null) oldRegion.removeFromZones(this);
  414. getKnownList().removeAllKnownObjects();
  415. owner.setPet(null);
  416. setTarget(null);
  417. if (this instanceof L2PetInstance)
  418. ((L2PetInstance)this).setIsMountableOverTime(false);
  419. }
  420. }
  421. public int getAttackRange()
  422. {
  423. return _attackRange;
  424. }
  425. public void setAttackRange(int range)
  426. {
  427. if (range < 36)
  428. range = 36;
  429. _attackRange = range;
  430. }
  431. public void setFollowStatus(boolean state)
  432. {
  433. _follow = state;
  434. if (_follow)
  435. getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, getOwner());
  436. else
  437. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
  438. }
  439. public boolean getFollowStatus()
  440. {
  441. return _follow;
  442. }
  443. @Override
  444. public boolean isAutoAttackable(L2Character attacker)
  445. {
  446. return _owner.isAutoAttackable(attacker);
  447. }
  448. public int getChargedSoulShot()
  449. {
  450. return _chargedSoulShot;
  451. }
  452. public int getChargedSpiritShot()
  453. {
  454. return _chargedSpiritShot;
  455. }
  456. public int getControlItemId()
  457. {
  458. return 0;
  459. }
  460. public L2Weapon getActiveWeapon()
  461. {
  462. return null;
  463. }
  464. @Override
  465. public PetInventory getInventory()
  466. {
  467. return null;
  468. }
  469. protected void doPickupItem(L2Object object)
  470. {
  471. return;
  472. }
  473. public void giveAllToOwner()
  474. {
  475. return;
  476. }
  477. public void store()
  478. {
  479. return;
  480. }
  481. @Override
  482. public L2ItemInstance getActiveWeaponInstance()
  483. {
  484. return null;
  485. }
  486. @Override
  487. public L2Weapon getActiveWeaponItem()
  488. {
  489. return null;
  490. }
  491. @Override
  492. public L2ItemInstance getSecondaryWeaponInstance()
  493. {
  494. return null;
  495. }
  496. @Override
  497. public L2Weapon getSecondaryWeaponItem()
  498. {
  499. return null;
  500. }
  501. /**
  502. * Return the L2Party object of its L2PcInstance owner or null.<BR><BR>
  503. */
  504. @Override
  505. public L2Party getParty()
  506. {
  507. if (_owner == null)
  508. return null;
  509. else
  510. return _owner.getParty();
  511. }
  512. /**
  513. * Return True if the L2Character has a Party in progress.<BR><BR>
  514. */
  515. @Override
  516. public boolean isInParty()
  517. {
  518. if (_owner == null)
  519. return false;
  520. else
  521. return _owner.getParty() != null;
  522. }
  523. /**
  524. * Check if the active L2Skill can be casted.<BR><BR>
  525. *
  526. * <B><U> Actions</U> :</B><BR><BR>
  527. * <li>Check if the target is correct </li>
  528. * <li>Check if the target is in the skill cast range </li>
  529. * <li>Check if the summon owns enough HP and MP to cast the skill </li>
  530. * <li>Check if all skills are enabled and this skill is enabled </li><BR><BR>
  531. * <li>Check if the skill is active </li><BR><BR>
  532. * <li>Notify the AI with AI_INTENTION_CAST and target</li><BR><BR>
  533. *
  534. * @param skill The L2Skill to use
  535. * @param forceUse used to force ATTACK on players
  536. * @param dontMove used to prevent movement, if not in range
  537. *
  538. */
  539. public void useMagic(L2Skill skill, boolean forceUse, boolean dontMove)
  540. {
  541. if (skill == null || isDead())
  542. return;
  543. // Check if the skill is active
  544. if (skill.isPassive())
  545. {
  546. // just ignore the passive skill request. why does the client send it anyway ??
  547. return;
  548. }
  549. //************************************* Check Casting in Progress *******************************************
  550. // If a skill is currently being used
  551. if (isCastingNow())
  552. {
  553. return;
  554. }
  555. //************************************* Check Target *******************************************
  556. // Get the target for the skill
  557. L2Object target = null;
  558. switch (skill.getTargetType())
  559. {
  560. // OWNER_PET should be cast even if no target has been found
  561. case TARGET_OWNER_PET:
  562. target = getOwner();
  563. break;
  564. // PARTY, AURA, SELF should be cast even if no target has been found
  565. case TARGET_PARTY:
  566. case TARGET_AURA:
  567. case TARGET_FRONT_AURA:
  568. case TARGET_BEHIND_AURA:
  569. case TARGET_SELF:
  570. target = this;
  571. break;
  572. default:
  573. // Get the first target of the list
  574. target = skill.getFirstOfTargetList(this);
  575. break;
  576. }
  577. // Check the validity of the target
  578. if (target == null)
  579. {
  580. if (getOwner() != null)
  581. getOwner().sendPacket(new SystemMessage(SystemMessageId.TARGET_CANT_FOUND));
  582. return;
  583. }
  584. //************************************* Check skill availability *******************************************
  585. // Check if this skill is enabled (ex : reuse time)
  586. if (isSkillDisabled(skill.getId())
  587. && getOwner() != null
  588. && (!getOwner().getAccessLevel().allowPeaceAttack()))
  589. {
  590. SystemMessage sm = new SystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE);
  591. sm.addSkillName(skill);
  592. getOwner().sendPacket(sm);
  593. return;
  594. }
  595. // Check if all skills are disabled
  596. if (isAllSkillsDisabled()
  597. && getOwner() != null
  598. && (!getOwner().getAccessLevel().allowPeaceAttack()))
  599. {
  600. return;
  601. }
  602. //************************************* Check Consumables *******************************************
  603. // Check if the summon has enough MP
  604. if (getCurrentMp() < getStat().getMpConsume(skill) + getStat().getMpInitialConsume(skill))
  605. {
  606. // Send a System Message to the caster
  607. if (getOwner() != null)
  608. getOwner().sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
  609. return;
  610. }
  611. // Check if the summon has enough HP
  612. if (getCurrentHp() <= skill.getHpConsume())
  613. {
  614. // Send a System Message to the caster
  615. if (getOwner() != null)
  616. getOwner().sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_HP));
  617. return;
  618. }
  619. //************************************* Check Summon State *******************************************
  620. // Check if this is offensive magic skill
  621. if (skill.isOffensive())
  622. {
  623. if (isInsidePeaceZone(this, target)
  624. && getOwner() != null
  625. && (!getOwner().getAccessLevel().allowPeaceAttack()))
  626. {
  627. // If summon or target is in a peace zone, send a system message TARGET_IN_PEACEZONE
  628. sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  629. return;
  630. }
  631. if (getOwner() != null && getOwner().isInOlympiadMode() && !getOwner().isOlympiadStart()){
  632. // if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
  633. sendPacket(ActionFailed.STATIC_PACKET);
  634. return;
  635. }
  636. // Check if the target is attackable
  637. if (target instanceof L2DoorInstance)
  638. {
  639. if(!((L2DoorInstance)target).isAttackable(getOwner()))
  640. return;
  641. }
  642. else
  643. {
  644. if (!target.isAttackable()
  645. && getOwner() != null
  646. && (!getOwner().getAccessLevel().allowPeaceAttack()))
  647. {
  648. return;
  649. }
  650. // Check if a Forced ATTACK is in progress on non-attackable target
  651. if (!target.isAutoAttackable(this) && !forceUse &&
  652. skill.getTargetType() != SkillTargetType.TARGET_AURA &&
  653. skill.getTargetType() != SkillTargetType.TARGET_FRONT_AURA &&
  654. skill.getTargetType() != SkillTargetType.TARGET_BEHIND_AURA &&
  655. skill.getTargetType() != SkillTargetType.TARGET_CLAN &&
  656. skill.getTargetType() != SkillTargetType.TARGET_ALLY &&
  657. skill.getTargetType() != SkillTargetType.TARGET_PARTY &&
  658. skill.getTargetType() != SkillTargetType.TARGET_SELF)
  659. {
  660. return;
  661. }
  662. }
  663. }
  664. // Notify the AI with AI_INTENTION_CAST and target
  665. getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, skill, target);
  666. }
  667. @Override
  668. public void setIsImmobilized(boolean value)
  669. {
  670. super.setIsImmobilized(value);
  671. if (value)
  672. {
  673. _previousFollowStatus = getFollowStatus();
  674. // if immobilized temporarly disable follow mode
  675. if (_previousFollowStatus)
  676. setFollowStatus(false);
  677. }
  678. else
  679. {
  680. // if not more immobilized restore previous follow mode
  681. setFollowStatus(_previousFollowStatus);
  682. }
  683. }
  684. public void setOwner(L2PcInstance newOwner)
  685. {
  686. _owner = newOwner;
  687. }
  688. @Override
  689. public final void sendDamageMessage(L2Character target, int damage, boolean mcrit, boolean pcrit, boolean miss)
  690. {
  691. if (miss) return;
  692. // Prevents the double spam of system messages, if the target is the owning player.
  693. if (target.getObjectId() != getOwner().getObjectId())
  694. {
  695. if (pcrit || mcrit)
  696. if (this instanceof L2SummonInstance)
  697. getOwner().sendPacket(new SystemMessage(SystemMessageId.CRITICAL_HIT_BY_SUMMONED_MOB));
  698. else
  699. getOwner().sendPacket(new SystemMessage(SystemMessageId.CRITICAL_HIT_BY_PET));
  700. if (getOwner().isInOlympiadMode() &&
  701. target instanceof L2PcInstance &&
  702. ((L2PcInstance)target).isInOlympiadMode() &&
  703. ((L2PcInstance)target).getOlympiadGameId() == getOwner().getOlympiadGameId())
  704. {
  705. Olympiad.getInstance().notifyCompetitorDamage(getOwner().getObjectId(), damage, getOwner().getOlympiadGameId());
  706. }
  707. SystemMessage sm;
  708. if (this instanceof L2SummonInstance)
  709. sm = new SystemMessage(SystemMessageId.SUMMON_GAVE_DAMAGE_S1);
  710. else
  711. sm = new SystemMessage(SystemMessageId.PET_HIT_FOR_S1_DAMAGE);
  712. sm.addNumber(damage);
  713. getOwner().sendPacket(sm);
  714. }
  715. }
  716. public void reduceCurrentHp(int damage, L2Character attacker)
  717. {
  718. super.reduceCurrentHp(damage, attacker);
  719. SystemMessage sm;
  720. if (this instanceof L2SummonInstance)
  721. sm = new SystemMessage(SystemMessageId.SUMMON_RECEIVED_DAMAGE_S2_BY_S1);
  722. else
  723. sm = new SystemMessage(SystemMessageId.PET_RECEIVED_S2_DAMAGE_BY_S1);
  724. sm.addCharName(attacker);
  725. sm.addNumber(damage);
  726. getOwner().sendPacket(sm);
  727. }
  728. /**
  729. * @return Returns the showSummonAnimation.
  730. */
  731. public boolean isShowSummonAnimation()
  732. {
  733. return _showSummonAnimation;
  734. }
  735. /**
  736. * @param showSummonAnimation The showSummonAnimation to set.
  737. */
  738. public void setShowSummonAnimation(boolean showSummonAnimation)
  739. {
  740. _showSummonAnimation = showSummonAnimation;
  741. }
  742. /**
  743. * Servitors' skills automatically change their level based on the servitor's level.
  744. * Until level 70, the servitor gets 1 lv of skill per 10 levels. After that, it is 1
  745. * skill level per 5 servitor levels. If the resulting skill level doesn't exist use
  746. * the max that does exist!
  747. *
  748. * @see net.sf.l2j.gameserver.model.L2Character#doCast(net.sf.l2j.gameserver.model.L2Skill)
  749. */
  750. @Override
  751. public void doCast(L2Skill skill)
  752. {
  753. int petLevel = getLevel();
  754. int skillLevel = petLevel/10;
  755. if(petLevel >= 70)
  756. skillLevel += (petLevel-65)/10;
  757. // adjust the level for servitors less than lv 10
  758. if (skillLevel < 1)
  759. skillLevel = 1;
  760. L2Skill skillToCast = SkillTable.getInstance().getInfo(skill.getId(),skillLevel);
  761. if (skillToCast != null)
  762. super.doCast(skillToCast);
  763. else
  764. super.doCast(skill);
  765. }
  766. }