L2Summon.java 22 KB

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