L2Summon.java 24 KB

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