L2Summon.java 25 KB

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