L2Summon.java 24 KB

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