L2Summon.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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 com.l2jserver.gameserver.model.actor;
  16. import java.util.Collection;
  17. import com.l2jserver.gameserver.ai.CtrlIntention;
  18. import com.l2jserver.gameserver.ai.L2CharacterAI;
  19. import com.l2jserver.gameserver.ai.L2SummonAI;
  20. import com.l2jserver.gameserver.datatables.ItemTable;
  21. import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
  22. import com.l2jserver.gameserver.model.L2ItemInstance;
  23. import com.l2jserver.gameserver.model.L2Object;
  24. import com.l2jserver.gameserver.model.L2Party;
  25. import com.l2jserver.gameserver.model.L2Skill;
  26. import com.l2jserver.gameserver.model.L2WorldRegion;
  27. import com.l2jserver.gameserver.model.L2Skill.SkillTargetType;
  28. import com.l2jserver.gameserver.model.actor.L2Attackable.AggroInfo;
  29. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2MerchantSummonInstance;
  31. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  32. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  33. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  34. import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  35. import com.l2jserver.gameserver.model.actor.knownlist.SummonKnownList;
  36. import com.l2jserver.gameserver.model.actor.stat.SummonStat;
  37. import com.l2jserver.gameserver.model.actor.status.SummonStatus;
  38. import com.l2jserver.gameserver.model.base.Experience;
  39. import com.l2jserver.gameserver.model.itemcontainer.PetInventory;
  40. import com.l2jserver.gameserver.model.olympiad.Olympiad;
  41. import com.l2jserver.gameserver.network.SystemMessageId;
  42. import com.l2jserver.gameserver.network.serverpackets.AbstractNpcInfo;
  43. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  44. import com.l2jserver.gameserver.network.serverpackets.ExPartyPetWindowAdd;
  45. import com.l2jserver.gameserver.network.serverpackets.ExPartyPetWindowDelete;
  46. import com.l2jserver.gameserver.network.serverpackets.ExPartyPetWindowUpdate;
  47. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  48. import com.l2jserver.gameserver.network.serverpackets.PetDelete;
  49. import com.l2jserver.gameserver.network.serverpackets.PetInfo;
  50. import com.l2jserver.gameserver.network.serverpackets.PetItemList;
  51. import com.l2jserver.gameserver.network.serverpackets.PetStatusUpdate;
  52. import com.l2jserver.gameserver.network.serverpackets.RelationChanged;
  53. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  54. import com.l2jserver.gameserver.network.serverpackets.TeleportToLocation;
  55. import com.l2jserver.gameserver.taskmanager.DecayTaskManager;
  56. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  57. import com.l2jserver.gameserver.templates.item.L2EtcItem;
  58. import com.l2jserver.gameserver.templates.item.L2Weapon;
  59. public abstract class L2Summon extends L2Playable
  60. {
  61. private L2PcInstance _owner;
  62. private int _attackRange = 36; //Melee range
  63. private boolean _follow = true;
  64. private boolean _previousFollowStatus = true;
  65. private int _chargedSoulShot;
  66. private int _chargedSpiritShot;
  67. public class AIAccessor extends L2Character.AIAccessor
  68. {
  69. protected AIAccessor() {}
  70. public L2Summon getSummon() { return L2Summon.this; }
  71. public boolean isAutoFollow() {
  72. return L2Summon.this.getFollowStatus();
  73. }
  74. public void doPickupItem(L2Object object) {
  75. L2Summon.this.doPickupItem(object);
  76. }
  77. }
  78. public L2Summon(int objectId, L2NpcTemplate template, L2PcInstance owner)
  79. {
  80. super(objectId, template);
  81. setInstanceType(InstanceType.L2Summon);
  82. setInstanceId(owner.getInstanceId()); // set instance to same as owner
  83. _showSummonAnimation = true;
  84. _owner = owner;
  85. _ai = new L2SummonAI(new L2Summon.AIAccessor());
  86. setXYZInvisible(owner.getX()+20, owner.getY()+20, owner.getZ()+100);
  87. }
  88. @Override
  89. public void onSpawn()
  90. {
  91. super.onSpawn();
  92. if (!(this instanceof L2MerchantSummonInstance))
  93. {
  94. this.setFollowStatus(true);
  95. updateAndBroadcastStatus(0);
  96. getOwner().sendPacket(new RelationChanged(this, getOwner().getRelation(getOwner()), false));
  97. for (L2PcInstance player : getOwner().getKnownList().getKnownPlayersInRadius(800))
  98. player.sendPacket(new RelationChanged(this, getOwner().getRelation(player), isAutoAttackable(player)));
  99. L2Party party = this.getOwner().getParty();
  100. if (party != null)
  101. {
  102. party.broadcastToPartyMembers(this.getOwner(), new ExPartyPetWindowAdd(this));
  103. }
  104. }
  105. setShowSummonAnimation(false); // addVisibleObject created the info packets with summon animation
  106. // if someone comes into range now, the animation shouldnt show any more
  107. }
  108. @Override
  109. public final SummonKnownList getKnownList()
  110. {
  111. return (SummonKnownList)super.getKnownList();
  112. }
  113. @Override
  114. public void initKnownList()
  115. {
  116. setKnownList(new SummonKnownList(this));
  117. }
  118. @Override
  119. public SummonStat getStat()
  120. {
  121. return (SummonStat)super.getStat();
  122. }
  123. @Override
  124. public void initCharStat()
  125. {
  126. setStat(new SummonStat(this));
  127. }
  128. @Override
  129. public SummonStatus getStatus()
  130. {
  131. return (SummonStatus)super.getStatus();
  132. }
  133. @Override
  134. public void initCharStatus()
  135. {
  136. setStatus(new SummonStatus(this));
  137. }
  138. @Override
  139. public L2CharacterAI getAI()
  140. {
  141. L2CharacterAI ai = _ai; // copy handle
  142. if (ai == null)
  143. {
  144. synchronized(this)
  145. {
  146. if (_ai == null) _ai = new L2SummonAI(new L2Summon.AIAccessor());
  147. return _ai;
  148. }
  149. }
  150. return ai;
  151. }
  152. @Override
  153. public L2NpcTemplate getTemplate()
  154. {
  155. return (L2NpcTemplate)super.getTemplate();
  156. }
  157. // this defines the action buttons, 1 for Summon, 2 for Pets
  158. public abstract int getSummonType();
  159. @Override
  160. public final void stopAllEffects()
  161. {
  162. super.stopAllEffects();
  163. updateAndBroadcastStatus(1);
  164. }
  165. @Override
  166. public final void stopAllEffectsExceptThoseThatLastThroughDeath()
  167. {
  168. super.stopAllEffectsExceptThoseThatLastThroughDeath();
  169. updateAndBroadcastStatus(1);
  170. }
  171. @Override
  172. public void updateAbnormalEffect()
  173. {
  174. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  175. //synchronized (getKnownList().getKnownPlayers())
  176. {
  177. for (L2PcInstance player : plrs)
  178. player.sendPacket(new AbstractNpcInfo.SummonInfo(this, player,1));
  179. }
  180. }
  181. /**
  182. * @return Returns the mountable.
  183. */
  184. public boolean isMountable()
  185. {
  186. return false;
  187. }
  188. public long getExpForThisLevel()
  189. {
  190. if(getLevel() >= Experience.LEVEL.length)
  191. {
  192. return 0;
  193. }
  194. return Experience.LEVEL[getLevel()];
  195. }
  196. public long getExpForNextLevel()
  197. {
  198. if(getLevel() >= Experience.LEVEL.length - 1)
  199. {
  200. return 0;
  201. }
  202. return Experience.LEVEL[getLevel()+1];
  203. }
  204. public final int getKarma()
  205. {
  206. return getOwner()!= null ? getOwner().getKarma() : 0;
  207. }
  208. public final byte getPvpFlag()
  209. {
  210. return getOwner()!= null ? getOwner().getPvpFlag() : 0;
  211. }
  212. public final int getTeam()
  213. {
  214. return getOwner()!= null ? getOwner().getTeam() : 0;
  215. }
  216. public final L2PcInstance getOwner()
  217. {
  218. return _owner;
  219. }
  220. public final int getNpcId()
  221. {
  222. return getTemplate().npcId;
  223. }
  224. public int getMaxLoad()
  225. {
  226. return 0;
  227. }
  228. public short getSoulShotsPerHit()
  229. {
  230. if (getTemplate().getAIDataStatic().getSoulShot() > 0)
  231. return (short) getTemplate().getAIDataStatic().getSoulShot();
  232. else return 1;
  233. }
  234. public short getSpiritShotsPerHit()
  235. {
  236. if (getTemplate().getAIDataStatic().getSpiritShot() > 0)
  237. return (short) getTemplate().getAIDataStatic().getSpiritShot();
  238. else return 1;
  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. if (this instanceof L2MerchantSummonInstance)
  258. return true;
  259. L2PcInstance owner = getOwner();
  260. if (owner != null)
  261. {
  262. Collection<L2Character> KnownTarget = this.getKnownList().getKnownCharacters();
  263. for (L2Character TgMob : KnownTarget)
  264. {
  265. // get the mobs which have aggro on the this instance
  266. if (TgMob instanceof L2Attackable)
  267. {
  268. if (((L2Attackable) TgMob).isDead())
  269. continue;
  270. AggroInfo info = ((L2Attackable) TgMob).getAggroList().get(this);
  271. if (info != null)
  272. ((L2Attackable) TgMob).addDamageHate(owner, info.getDamage(), info.getHate());
  273. }
  274. }
  275. }
  276. if (isPhoenixBlessed() && (getOwner() != null))
  277. getOwner().reviveRequest(getOwner(), null, true);
  278. DecayTaskManager.getInstance().addDecayTask(this);
  279. return true;
  280. }
  281. public boolean doDie(L2Character killer, boolean decayed)
  282. {
  283. if (!super.doDie(killer))
  284. return false;
  285. if (!decayed)
  286. {
  287. DecayTaskManager.getInstance().addDecayTask(this);
  288. }
  289. return true;
  290. }
  291. public void stopDecay()
  292. {
  293. DecayTaskManager.getInstance().cancelDecayTask(this);
  294. }
  295. @Override
  296. public void onDecay()
  297. {
  298. deleteMe(_owner);
  299. }
  300. @Override
  301. public void broadcastStatusUpdate()
  302. {
  303. super.broadcastStatusUpdate();
  304. updateAndBroadcastStatus(1);
  305. }
  306. public void deleteMe(L2PcInstance owner)
  307. {
  308. owner.sendPacket(new PetDelete(getSummonType(), getObjectId()));
  309. //pet will be deleted along with all his items
  310. if (getInventory() != null)
  311. {
  312. getInventory().destroyAllItems("pet deleted", getOwner(), this);
  313. }
  314. decayMe();
  315. getKnownList().removeAllKnownObjects();
  316. owner.setPet(null);
  317. super.deleteMe();
  318. }
  319. public void unSummon(L2PcInstance owner)
  320. {
  321. if (isVisible() && !isDead())
  322. {
  323. getAI().stopFollow();
  324. owner.sendPacket(new PetDelete(getSummonType(),getObjectId()));
  325. L2Party party;
  326. if ((party = owner.getParty()) != null)
  327. {
  328. party.broadcastToPartyMembers(owner, new ExPartyPetWindowDelete(this));
  329. }
  330. store();
  331. giveAllToOwner();
  332. owner.setPet(null);
  333. stopAllEffects();
  334. L2WorldRegion oldRegion = getWorldRegion();
  335. decayMe();
  336. if (oldRegion != null) oldRegion.removeFromZones(this);
  337. getKnownList().removeAllKnownObjects();
  338. setTarget(null);
  339. for (int itemId : owner.getAutoSoulShot())
  340. {
  341. String handler = ((L2EtcItem)ItemTable.getInstance().getTemplate(itemId)).getHandlerName();
  342. if (handler.contains("Beast"))
  343. owner.disableAutoShot(itemId);
  344. }
  345. }
  346. }
  347. public int getAttackRange()
  348. {
  349. return _attackRange;
  350. }
  351. public void setAttackRange(int range)
  352. {
  353. if (range < 36)
  354. range = 36;
  355. _attackRange = range;
  356. }
  357. public void setFollowStatus(boolean state)
  358. {
  359. _follow = state;
  360. if (_follow)
  361. getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, getOwner());
  362. else
  363. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
  364. }
  365. public boolean getFollowStatus()
  366. {
  367. return _follow;
  368. }
  369. @Override
  370. public boolean isAutoAttackable(L2Character attacker)
  371. {
  372. return _owner.isAutoAttackable(attacker);
  373. }
  374. public int getChargedSoulShot()
  375. {
  376. return _chargedSoulShot;
  377. }
  378. public int getChargedSpiritShot()
  379. {
  380. return _chargedSpiritShot;
  381. }
  382. public int getControlObjectId()
  383. {
  384. return 0;
  385. }
  386. public L2Weapon getActiveWeapon()
  387. {
  388. return null;
  389. }
  390. @Override
  391. public PetInventory getInventory()
  392. {
  393. return null;
  394. }
  395. protected void doPickupItem(L2Object object)
  396. {
  397. }
  398. public void giveAllToOwner()
  399. {
  400. }
  401. public void store()
  402. {
  403. }
  404. @Override
  405. public L2ItemInstance getActiveWeaponInstance()
  406. {
  407. return null;
  408. }
  409. @Override
  410. public L2Weapon getActiveWeaponItem()
  411. {
  412. return null;
  413. }
  414. @Override
  415. public L2ItemInstance getSecondaryWeaponInstance()
  416. {
  417. return null;
  418. }
  419. @Override
  420. public L2Weapon getSecondaryWeaponItem()
  421. {
  422. return null;
  423. }
  424. /**
  425. * Return True if the L2Summon is invulnerable or if the summoner is in spawn protection.<BR><BR>
  426. */
  427. @Override
  428. public boolean isInvul()
  429. {
  430. return _isInvul || _isTeleporting || getOwner().isSpawnProtected();
  431. }
  432. /**
  433. * Return the L2Party object of its L2PcInstance owner or null.<BR><BR>
  434. */
  435. @Override
  436. public L2Party getParty()
  437. {
  438. if (_owner == null)
  439. return null;
  440. else
  441. return _owner.getParty();
  442. }
  443. /**
  444. * Return True if the L2Character has a Party in progress.<BR><BR>
  445. */
  446. @Override
  447. public boolean isInParty()
  448. {
  449. if (_owner == null)
  450. return false;
  451. else
  452. return _owner.getParty() != null;
  453. }
  454. /**
  455. * Check if the active L2Skill can be casted.<BR><BR>
  456. *
  457. * <B><U> Actions</U> :</B><BR><BR>
  458. * <li>Check if the target is correct </li>
  459. * <li>Check if the target is in the skill cast range </li>
  460. * <li>Check if the summon owns enough HP and MP to cast the skill </li>
  461. * <li>Check if all skills are enabled and this skill is enabled </li><BR><BR>
  462. * <li>Check if the skill is active </li><BR><BR>
  463. * <li>Notify the AI with AI_INTENTION_CAST and target</li><BR><BR>
  464. *
  465. * @param skill The L2Skill to use
  466. * @param forceUse used to force ATTACK on players
  467. * @param dontMove used to prevent movement, if not in range
  468. *
  469. */
  470. public void useMagic(L2Skill skill, boolean forceUse, boolean dontMove)
  471. {
  472. if (skill == null || isDead())
  473. return;
  474. // Check if the skill is active
  475. if (skill.isPassive())
  476. {
  477. // just ignore the passive skill request. why does the client send it anyway ??
  478. return;
  479. }
  480. //************************************* Check Casting in Progress *******************************************
  481. // If a skill is currently being used
  482. if (isCastingNow())
  483. {
  484. return;
  485. }
  486. // Set current pet skill
  487. getOwner().setCurrentPetSkill(skill, forceUse, dontMove);
  488. //************************************* Check Target *******************************************
  489. // Get the target for the skill
  490. L2Object target = null;
  491. switch (skill.getTargetType())
  492. {
  493. // OWNER_PET should be cast even if no target has been found
  494. case TARGET_OWNER_PET:
  495. target = getOwner();
  496. break;
  497. // PARTY, AURA, SELF should be cast even if no target has been found
  498. case TARGET_PARTY:
  499. case TARGET_AURA:
  500. case TARGET_FRONT_AURA:
  501. case TARGET_BEHIND_AURA:
  502. case TARGET_SELF:
  503. target = this;
  504. break;
  505. default:
  506. // Get the first target of the list
  507. target = skill.getFirstOfTargetList(this);
  508. break;
  509. }
  510. // Check the validity of the target
  511. if (target == null)
  512. {
  513. if (getOwner() != null)
  514. getOwner().sendPacket(new SystemMessage(SystemMessageId.TARGET_CANT_FOUND));
  515. return;
  516. }
  517. //************************************* Check skill availability *******************************************
  518. // Check if this skill is enabled (e.g. reuse time)
  519. if (isSkillDisabled(skill))
  520. {
  521. if (getOwner() != null)
  522. getOwner().sendPacket(new SystemMessage(SystemMessageId.PET_SKILL_CANNOT_BE_USED_RECHARCHING));
  523. return;
  524. }
  525. //************************************* Check Consumables *******************************************
  526. // Check if the summon has enough MP
  527. if (getCurrentMp() < getStat().getMpConsume(skill) + getStat().getMpInitialConsume(skill))
  528. {
  529. // Send a System Message to the caster
  530. if (getOwner() != null)
  531. getOwner().sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
  532. return;
  533. }
  534. // Check if the summon has enough HP
  535. if (getCurrentHp() <= skill.getHpConsume())
  536. {
  537. // Send a System Message to the caster
  538. if (getOwner() != null)
  539. getOwner().sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_HP));
  540. return;
  541. }
  542. //************************************* Check Summon State *******************************************
  543. // Check if this is offensive magic skill
  544. if (skill.isOffensive())
  545. {
  546. if (isInsidePeaceZone(this, target)
  547. && getOwner() != null
  548. && (!getOwner().getAccessLevel().allowPeaceAttack()))
  549. {
  550. // If summon or target is in a peace zone, send a system message TARGET_IN_PEACEZONE
  551. sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  552. return;
  553. }
  554. if (getOwner() != null && getOwner().isInOlympiadMode() && !getOwner().isOlympiadStart()){
  555. // if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
  556. sendPacket(ActionFailed.STATIC_PACKET);
  557. return;
  558. }
  559. if (target.getActingPlayer() != null && this.getOwner().getSiegeState() > 0 && this.getOwner().isInsideZone(L2Character.ZONE_SIEGE)
  560. && target.getActingPlayer().getSiegeState() == this.getOwner().getSiegeState()
  561. && target.getActingPlayer() != this.getOwner() && target.getActingPlayer().getSiegeSide() == this.getOwner().getSiegeSide())
  562. {
  563. //
  564. if (TerritoryWarManager.getInstance().isTWInProgress())
  565. sendPacket(new SystemMessage(SystemMessageId.YOU_CANNOT_ATTACK_A_MEMBER_OF_THE_SAME_TERRITORY));
  566. else
  567. sendPacket(new SystemMessage(SystemMessageId.FORCED_ATTACK_IS_IMPOSSIBLE_AGAINST_SIEGE_SIDE_TEMPORARY_ALLIED_MEMBERS));
  568. sendPacket(ActionFailed.STATIC_PACKET);
  569. return;
  570. }
  571. // Check if the target is attackable
  572. if (target instanceof L2DoorInstance)
  573. {
  574. if(!((L2DoorInstance)target).isAttackable(getOwner()))
  575. return;
  576. }
  577. else
  578. {
  579. if (!target.isAttackable()
  580. && getOwner() != null
  581. && (!getOwner().getAccessLevel().allowPeaceAttack()))
  582. {
  583. return;
  584. }
  585. // Check if a Forced ATTACK is in progress on non-attackable target
  586. if (!target.isAutoAttackable(this) && !forceUse &&
  587. skill.getTargetType() != SkillTargetType.TARGET_AURA &&
  588. skill.getTargetType() != SkillTargetType.TARGET_FRONT_AURA &&
  589. skill.getTargetType() != SkillTargetType.TARGET_BEHIND_AURA &&
  590. skill.getTargetType() != SkillTargetType.TARGET_CLAN &&
  591. skill.getTargetType() != SkillTargetType.TARGET_ALLY &&
  592. skill.getTargetType() != SkillTargetType.TARGET_PARTY &&
  593. skill.getTargetType() != SkillTargetType.TARGET_SELF)
  594. {
  595. return;
  596. }
  597. }
  598. }
  599. // Notify the AI with AI_INTENTION_CAST and target
  600. getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, skill, target);
  601. }
  602. @Override
  603. public void setIsImmobilized(boolean value)
  604. {
  605. super.setIsImmobilized(value);
  606. if (value)
  607. {
  608. _previousFollowStatus = getFollowStatus();
  609. // if immobilized temporarly disable follow mode
  610. if (_previousFollowStatus)
  611. setFollowStatus(false);
  612. }
  613. else
  614. {
  615. // if not more immobilized restore previous follow mode
  616. setFollowStatus(_previousFollowStatus);
  617. }
  618. }
  619. public void setOwner(L2PcInstance newOwner)
  620. {
  621. _owner = newOwner;
  622. }
  623. @Override
  624. public void sendDamageMessage(L2Character target, int damage, boolean mcrit, boolean pcrit, boolean miss)
  625. {
  626. if (miss || getOwner() == null)
  627. return;
  628. // Prevents the double spam of system messages, if the target is the owning player.
  629. if (target.getObjectId() != getOwner().getObjectId())
  630. {
  631. if (pcrit || mcrit)
  632. if (this instanceof L2SummonInstance)
  633. getOwner().sendPacket(new SystemMessage(SystemMessageId.CRITICAL_HIT_BY_SUMMONED_MOB));
  634. else
  635. getOwner().sendPacket(new SystemMessage(SystemMessageId.CRITICAL_HIT_BY_PET));
  636. if (getOwner().isInOlympiadMode() &&
  637. target instanceof L2PcInstance &&
  638. ((L2PcInstance)target).isInOlympiadMode() &&
  639. ((L2PcInstance)target).getOlympiadGameId() == getOwner().getOlympiadGameId())
  640. {
  641. Olympiad.getInstance().notifyCompetitorDamage(getOwner(), damage, getOwner().getOlympiadGameId());
  642. }
  643. final SystemMessage sm;
  644. if (target.isInvul() && !(target instanceof L2NpcInstance))
  645. sm = new SystemMessage(SystemMessageId.ATTACK_WAS_BLOCKED);
  646. else
  647. {
  648. sm = new SystemMessage(SystemMessageId.C1_GAVE_C2_DAMAGE_OF_S3);
  649. sm.addNpcName(this);
  650. sm.addCharName(target);
  651. sm.addNumber(damage);
  652. }
  653. getOwner().sendPacket(sm);
  654. }
  655. }
  656. @Override
  657. public void reduceCurrentHp(double damage, L2Character attacker, L2Skill skill)
  658. {
  659. super.reduceCurrentHp(damage, attacker, skill);
  660. if (getOwner() != null && attacker != null)
  661. {
  662. SystemMessage sm = new SystemMessage(SystemMessageId.C1_RECEIVED_DAMAGE_OF_S3_FROM_C2);
  663. sm.addNpcName(this);
  664. sm.addCharName(attacker);
  665. sm.addNumber((int)damage);
  666. getOwner().sendPacket(sm);
  667. }
  668. }
  669. @Override
  670. public void doCast(L2Skill skill)
  671. {
  672. final L2PcInstance actingPlayer = getActingPlayer();
  673. if (!actingPlayer.checkPvpSkill(getTarget(), skill, true)
  674. && !actingPlayer.getAccessLevel().allowPeaceAttack())
  675. {
  676. // Send a System Message to the L2PcInstance
  677. actingPlayer.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  678. // Send a Server->Client packet ActionFailed to the L2PcInstance
  679. actingPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  680. return;
  681. }
  682. super.doCast(skill);
  683. }
  684. @Override
  685. public boolean isInCombat()
  686. {
  687. return getOwner().isInCombat();
  688. }
  689. @Override
  690. public L2PcInstance getActingPlayer()
  691. {
  692. return getOwner();
  693. }
  694. @Override
  695. public final void broadcastPacket(L2GameServerPacket mov)
  696. {
  697. mov.setInvisible(getOwner().getAppearance().getInvisible());
  698. super.broadcastPacket(mov);
  699. }
  700. @Override
  701. public final void broadcastPacket(L2GameServerPacket mov, int radiusInKnownlist)
  702. {
  703. mov.setInvisible(getOwner().getAppearance().getInvisible());
  704. super.broadcastPacket(mov, radiusInKnownlist);
  705. }
  706. public void updateAndBroadcastStatus(int val)
  707. {
  708. if (getOwner() == null)
  709. return;
  710. getOwner().sendPacket(new PetInfo(this,val));
  711. getOwner().sendPacket(new PetStatusUpdate(this));
  712. if (isVisible())
  713. {
  714. broadcastNpcInfo(val);
  715. }
  716. L2Party party = this.getOwner().getParty();
  717. if (party != null)
  718. {
  719. party.broadcastToPartyMembers(this.getOwner(), new ExPartyPetWindowUpdate(this));
  720. }
  721. updateEffectIcons(true);
  722. }
  723. public void broadcastNpcInfo(int val)
  724. {
  725. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  726. for (L2PcInstance player : plrs)
  727. {
  728. if (player == null || (player == getOwner() && !(this instanceof L2MerchantSummonInstance)))
  729. continue;
  730. player.sendPacket(new AbstractNpcInfo.SummonInfo(this,player, val));
  731. }
  732. }
  733. public boolean isHungry()
  734. {
  735. return false;
  736. }
  737. @Override
  738. public final boolean isAttackingNow()
  739. {
  740. return isInCombat();
  741. }
  742. public int getWeapon()
  743. {
  744. return 0;
  745. }
  746. public int getArmor()
  747. {
  748. return 0;
  749. }
  750. public int getPetSpeed()
  751. {
  752. return getTemplate().baseRunSpd;
  753. }
  754. @Override
  755. public void sendInfo(L2PcInstance activeChar)
  756. {
  757. // Check if the L2PcInstance is the owner of the Pet
  758. if (activeChar.equals(getOwner()) && !(this instanceof L2MerchantSummonInstance))
  759. {
  760. activeChar.sendPacket(new PetInfo(this, 0));
  761. // The PetInfo packet wipes the PartySpelled (list of active spells' icons). Re-add them
  762. updateEffectIcons(true);
  763. if (this instanceof L2PetInstance)
  764. {
  765. activeChar.sendPacket(new PetItemList((L2PetInstance) this));
  766. }
  767. }
  768. else
  769. activeChar.sendPacket(new AbstractNpcInfo.SummonInfo(this, activeChar, 0));
  770. }
  771. /* (non-Javadoc)
  772. * @see com.l2jserver.gameserver.model.actor.L2Character#onTeleported()
  773. */
  774. @Override
  775. public void onTeleported()
  776. {
  777. super.onTeleported();
  778. getOwner().sendPacket(new TeleportToLocation(this, getPosition().getX(), getPosition().getY(), getPosition().getZ(), getPosition().getHeading()));
  779. }
  780. @Override
  781. public String toString()
  782. {
  783. return super.toString()+" Owner: "+getOwner();
  784. }
  785. }