L2Summon.java 22 KB

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