L2Summon.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  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. // Stop AI tasks
  334. if (hasAI())
  335. getAI().stopAITask();
  336. stopAllEffects();
  337. L2WorldRegion oldRegion = getWorldRegion();
  338. decayMe();
  339. if (oldRegion != null) oldRegion.removeFromZones(this);
  340. getKnownList().removeAllKnownObjects();
  341. setTarget(null);
  342. for (int itemId : owner.getAutoSoulShot())
  343. {
  344. String handler = ((L2EtcItem)ItemTable.getInstance().getTemplate(itemId)).getHandlerName();
  345. if (handler.contains("Beast"))
  346. owner.disableAutoShot(itemId);
  347. }
  348. }
  349. }
  350. public int getAttackRange()
  351. {
  352. return _attackRange;
  353. }
  354. public void setAttackRange(int range)
  355. {
  356. if (range < 36)
  357. range = 36;
  358. _attackRange = range;
  359. }
  360. public void setFollowStatus(boolean state)
  361. {
  362. _follow = state;
  363. if (_follow)
  364. getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, getOwner());
  365. else
  366. getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
  367. }
  368. public boolean getFollowStatus()
  369. {
  370. return _follow;
  371. }
  372. @Override
  373. public boolean isAutoAttackable(L2Character attacker)
  374. {
  375. return _owner.isAutoAttackable(attacker);
  376. }
  377. public int getChargedSoulShot()
  378. {
  379. return _chargedSoulShot;
  380. }
  381. public int getChargedSpiritShot()
  382. {
  383. return _chargedSpiritShot;
  384. }
  385. public int getControlObjectId()
  386. {
  387. return 0;
  388. }
  389. public L2Weapon getActiveWeapon()
  390. {
  391. return null;
  392. }
  393. @Override
  394. public PetInventory getInventory()
  395. {
  396. return null;
  397. }
  398. protected void doPickupItem(L2Object object)
  399. {
  400. }
  401. public void giveAllToOwner()
  402. {
  403. }
  404. public void store()
  405. {
  406. }
  407. @Override
  408. public L2ItemInstance getActiveWeaponInstance()
  409. {
  410. return null;
  411. }
  412. @Override
  413. public L2Weapon getActiveWeaponItem()
  414. {
  415. return null;
  416. }
  417. @Override
  418. public L2ItemInstance getSecondaryWeaponInstance()
  419. {
  420. return null;
  421. }
  422. @Override
  423. public L2Weapon getSecondaryWeaponItem()
  424. {
  425. return null;
  426. }
  427. /**
  428. * Return True if the L2Summon is invulnerable or if the summoner is in spawn protection.<BR><BR>
  429. */
  430. @Override
  431. public boolean isInvul()
  432. {
  433. return _isInvul || _isTeleporting || getOwner().isSpawnProtected();
  434. }
  435. /**
  436. * Return the L2Party object of its L2PcInstance owner or null.<BR><BR>
  437. */
  438. @Override
  439. public L2Party getParty()
  440. {
  441. if (_owner == null)
  442. return null;
  443. else
  444. return _owner.getParty();
  445. }
  446. /**
  447. * Return True if the L2Character has a Party in progress.<BR><BR>
  448. */
  449. @Override
  450. public boolean isInParty()
  451. {
  452. if (_owner == null)
  453. return false;
  454. else
  455. return _owner.getParty() != null;
  456. }
  457. /**
  458. * Check if the active L2Skill can be casted.<BR><BR>
  459. *
  460. * <B><U> Actions</U> :</B><BR><BR>
  461. * <li>Check if the target is correct </li>
  462. * <li>Check if the target is in the skill cast range </li>
  463. * <li>Check if the summon owns enough HP and MP to cast the skill </li>
  464. * <li>Check if all skills are enabled and this skill is enabled </li><BR><BR>
  465. * <li>Check if the skill is active </li><BR><BR>
  466. * <li>Notify the AI with AI_INTENTION_CAST and target</li><BR><BR>
  467. *
  468. * @param skill The L2Skill to use
  469. * @param forceUse used to force ATTACK on players
  470. * @param dontMove used to prevent movement, if not in range
  471. *
  472. */
  473. public void useMagic(L2Skill skill, boolean forceUse, boolean dontMove)
  474. {
  475. if (skill == null || isDead())
  476. return;
  477. // Check if the skill is active
  478. if (skill.isPassive())
  479. {
  480. // just ignore the passive skill request. why does the client send it anyway ??
  481. return;
  482. }
  483. //************************************* Check Casting in Progress *******************************************
  484. // If a skill is currently being used
  485. if (isCastingNow())
  486. {
  487. return;
  488. }
  489. // Set current pet skill
  490. getOwner().setCurrentPetSkill(skill, forceUse, dontMove);
  491. //************************************* Check Target *******************************************
  492. // Get the target for the skill
  493. L2Object target = null;
  494. switch (skill.getTargetType())
  495. {
  496. // OWNER_PET should be cast even if no target has been found
  497. case TARGET_OWNER_PET:
  498. target = getOwner();
  499. break;
  500. // PARTY, AURA, SELF should be cast even if no target has been found
  501. case TARGET_PARTY:
  502. case TARGET_AURA:
  503. case TARGET_FRONT_AURA:
  504. case TARGET_BEHIND_AURA:
  505. case TARGET_SELF:
  506. target = this;
  507. break;
  508. default:
  509. // Get the first target of the list
  510. target = skill.getFirstOfTargetList(this);
  511. break;
  512. }
  513. // Check the validity of the target
  514. if (target == null)
  515. {
  516. if (getOwner() != null)
  517. getOwner().sendPacket(new SystemMessage(SystemMessageId.TARGET_CANT_FOUND));
  518. return;
  519. }
  520. //************************************* Check skill availability *******************************************
  521. // Check if this skill is enabled (e.g. reuse time)
  522. if (isSkillDisabled(skill))
  523. {
  524. if (getOwner() != null)
  525. getOwner().sendPacket(new SystemMessage(SystemMessageId.PET_SKILL_CANNOT_BE_USED_RECHARCHING));
  526. return;
  527. }
  528. //************************************* Check Consumables *******************************************
  529. // Check if the summon has enough MP
  530. if (getCurrentMp() < getStat().getMpConsume(skill) + getStat().getMpInitialConsume(skill))
  531. {
  532. // Send a System Message to the caster
  533. if (getOwner() != null)
  534. getOwner().sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_MP));
  535. return;
  536. }
  537. // Check if the summon has enough HP
  538. if (getCurrentHp() <= skill.getHpConsume())
  539. {
  540. // Send a System Message to the caster
  541. if (getOwner() != null)
  542. getOwner().sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_HP));
  543. return;
  544. }
  545. //************************************* Check Summon State *******************************************
  546. // Check if this is offensive magic skill
  547. if (skill.isOffensive())
  548. {
  549. if (isInsidePeaceZone(this, target)
  550. && getOwner() != null
  551. && (!getOwner().getAccessLevel().allowPeaceAttack()))
  552. {
  553. // If summon or target is in a peace zone, send a system message TARGET_IN_PEACEZONE
  554. sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE));
  555. return;
  556. }
  557. if (getOwner() != null && getOwner().isInOlympiadMode() && !getOwner().isOlympiadStart()){
  558. // if L2PcInstance is in Olympia and the match isn't already start, send a Server->Client packet ActionFailed
  559. sendPacket(ActionFailed.STATIC_PACKET);
  560. return;
  561. }
  562. if (target.getActingPlayer() != null && this.getOwner().getSiegeState() > 0 && this.getOwner().isInsideZone(L2Character.ZONE_SIEGE)
  563. && target.getActingPlayer().getSiegeState() == this.getOwner().getSiegeState()
  564. && target.getActingPlayer() != this.getOwner() && target.getActingPlayer().getSiegeSide() == this.getOwner().getSiegeSide())
  565. {
  566. //
  567. if (TerritoryWarManager.getInstance().isTWInProgress())
  568. sendPacket(new SystemMessage(SystemMessageId.YOU_CANNOT_ATTACK_A_MEMBER_OF_THE_SAME_TERRITORY));
  569. else
  570. sendPacket(new SystemMessage(SystemMessageId.FORCED_ATTACK_IS_IMPOSSIBLE_AGAINST_SIEGE_SIDE_TEMPORARY_ALLIED_MEMBERS));
  571. sendPacket(ActionFailed.STATIC_PACKET);
  572. return;
  573. }
  574. // Check if the target is attackable
  575. if (target instanceof L2DoorInstance)
  576. {
  577. if(!((L2DoorInstance)target).isAttackable(getOwner()))
  578. return;
  579. }
  580. else
  581. {
  582. if (!target.isAttackable()
  583. && getOwner() != null
  584. && (!getOwner().getAccessLevel().allowPeaceAttack()))
  585. {
  586. return;
  587. }
  588. // Check if a Forced ATTACK is in progress on non-attackable target
  589. if (!target.isAutoAttackable(this) && !forceUse &&
  590. skill.getTargetType() != SkillTargetType.TARGET_AURA &&
  591. skill.getTargetType() != SkillTargetType.TARGET_FRONT_AURA &&
  592. skill.getTargetType() != SkillTargetType.TARGET_BEHIND_AURA &&
  593. skill.getTargetType() != SkillTargetType.TARGET_CLAN &&
  594. skill.getTargetType() != SkillTargetType.TARGET_ALLY &&
  595. skill.getTargetType() != SkillTargetType.TARGET_PARTY &&
  596. skill.getTargetType() != SkillTargetType.TARGET_SELF)
  597. {
  598. return;
  599. }
  600. }
  601. }
  602. // Notify the AI with AI_INTENTION_CAST and target
  603. getAI().setIntention(CtrlIntention.AI_INTENTION_CAST, skill, target);
  604. }
  605. @Override
  606. public void setIsImmobilized(boolean value)
  607. {
  608. super.setIsImmobilized(value);
  609. if (value)
  610. {
  611. _previousFollowStatus = getFollowStatus();
  612. // if immobilized temporarly disable follow mode
  613. if (_previousFollowStatus)
  614. setFollowStatus(false);
  615. }
  616. else
  617. {
  618. // if not more immobilized restore previous follow mode
  619. setFollowStatus(_previousFollowStatus);
  620. }
  621. }
  622. public void setOwner(L2PcInstance newOwner)
  623. {
  624. _owner = newOwner;
  625. }
  626. @Override
  627. public void sendDamageMessage(L2Character target, int damage, boolean mcrit, boolean pcrit, boolean miss)
  628. {
  629. if (miss || getOwner() == null)
  630. return;
  631. // Prevents the double spam of system messages, if the target is the owning player.
  632. if (target.getObjectId() != getOwner().getObjectId())
  633. {
  634. if (pcrit || mcrit)
  635. if (this instanceof L2SummonInstance)
  636. getOwner().sendPacket(new SystemMessage(SystemMessageId.CRITICAL_HIT_BY_SUMMONED_MOB));
  637. else
  638. getOwner().sendPacket(new SystemMessage(SystemMessageId.CRITICAL_HIT_BY_PET));
  639. if (getOwner().isInOlympiadMode() &&
  640. target instanceof L2PcInstance &&
  641. ((L2PcInstance)target).isInOlympiadMode() &&
  642. ((L2PcInstance)target).getOlympiadGameId() == getOwner().getOlympiadGameId())
  643. {
  644. Olympiad.getInstance().notifyCompetitorDamage(getOwner(), damage, getOwner().getOlympiadGameId());
  645. }
  646. final SystemMessage sm;
  647. if (target.isInvul() && !(target instanceof L2NpcInstance))
  648. sm = new SystemMessage(SystemMessageId.ATTACK_WAS_BLOCKED);
  649. else
  650. {
  651. sm = new SystemMessage(SystemMessageId.C1_GAVE_C2_DAMAGE_OF_S3);
  652. sm.addNpcName(this);
  653. sm.addCharName(target);
  654. sm.addNumber(damage);
  655. }
  656. getOwner().sendPacket(sm);
  657. }
  658. }
  659. @Override
  660. public void reduceCurrentHp(double damage, L2Character attacker, L2Skill skill)
  661. {
  662. super.reduceCurrentHp(damage, attacker, skill);
  663. if (getOwner() != null && attacker != null)
  664. {
  665. SystemMessage sm = new SystemMessage(SystemMessageId.C1_RECEIVED_DAMAGE_OF_S3_FROM_C2);
  666. sm.addNpcName(this);
  667. sm.addCharName(attacker);
  668. sm.addNumber((int)damage);
  669. getOwner().sendPacket(sm);
  670. }
  671. }
  672. @Override
  673. public void doCast(L2Skill skill)
  674. {
  675. final L2PcInstance actingPlayer = getActingPlayer();
  676. if (!actingPlayer.checkPvpSkill(getTarget(), skill, true)
  677. && !actingPlayer.getAccessLevel().allowPeaceAttack())
  678. {
  679. // Send a System Message to the L2PcInstance
  680. actingPlayer.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
  681. // Send a Server->Client packet ActionFailed to the L2PcInstance
  682. actingPlayer.sendPacket(ActionFailed.STATIC_PACKET);
  683. return;
  684. }
  685. super.doCast(skill);
  686. }
  687. @Override
  688. public boolean isInCombat()
  689. {
  690. return getOwner().isInCombat();
  691. }
  692. @Override
  693. public L2PcInstance getActingPlayer()
  694. {
  695. return getOwner();
  696. }
  697. @Override
  698. public final void broadcastPacket(L2GameServerPacket mov)
  699. {
  700. mov.setInvisible(getOwner().getAppearance().getInvisible());
  701. super.broadcastPacket(mov);
  702. }
  703. @Override
  704. public final void broadcastPacket(L2GameServerPacket mov, int radiusInKnownlist)
  705. {
  706. mov.setInvisible(getOwner().getAppearance().getInvisible());
  707. super.broadcastPacket(mov, radiusInKnownlist);
  708. }
  709. public void updateAndBroadcastStatus(int val)
  710. {
  711. if (getOwner() == null)
  712. return;
  713. getOwner().sendPacket(new PetInfo(this,val));
  714. getOwner().sendPacket(new PetStatusUpdate(this));
  715. if (isVisible())
  716. {
  717. broadcastNpcInfo(val);
  718. }
  719. L2Party party = this.getOwner().getParty();
  720. if (party != null)
  721. {
  722. party.broadcastToPartyMembers(this.getOwner(), new ExPartyPetWindowUpdate(this));
  723. }
  724. updateEffectIcons(true);
  725. }
  726. public void broadcastNpcInfo(int val)
  727. {
  728. Collection<L2PcInstance> plrs = getKnownList().getKnownPlayers().values();
  729. for (L2PcInstance player : plrs)
  730. {
  731. if (player == null || (player == getOwner() && !(this instanceof L2MerchantSummonInstance)))
  732. continue;
  733. player.sendPacket(new AbstractNpcInfo.SummonInfo(this,player, val));
  734. }
  735. }
  736. public boolean isHungry()
  737. {
  738. return false;
  739. }
  740. @Override
  741. public final boolean isAttackingNow()
  742. {
  743. return isInCombat();
  744. }
  745. public int getWeapon()
  746. {
  747. return 0;
  748. }
  749. public int getArmor()
  750. {
  751. return 0;
  752. }
  753. public int getPetSpeed()
  754. {
  755. return getTemplate().baseRunSpd;
  756. }
  757. @Override
  758. public void sendInfo(L2PcInstance activeChar)
  759. {
  760. // Check if the L2PcInstance is the owner of the Pet
  761. if (activeChar.equals(getOwner()) && !(this instanceof L2MerchantSummonInstance))
  762. {
  763. activeChar.sendPacket(new PetInfo(this, 0));
  764. // The PetInfo packet wipes the PartySpelled (list of active spells' icons). Re-add them
  765. updateEffectIcons(true);
  766. if (this instanceof L2PetInstance)
  767. {
  768. activeChar.sendPacket(new PetItemList((L2PetInstance) this));
  769. }
  770. }
  771. else
  772. activeChar.sendPacket(new AbstractNpcInfo.SummonInfo(this, activeChar, 0));
  773. }
  774. /* (non-Javadoc)
  775. * @see com.l2jserver.gameserver.model.actor.L2Character#onTeleported()
  776. */
  777. @Override
  778. public void onTeleported()
  779. {
  780. super.onTeleported();
  781. getOwner().sendPacket(new TeleportToLocation(this, getPosition().getX(), getPosition().getY(), getPosition().getZ(), getPosition().getHeading()));
  782. }
  783. @Override
  784. public String toString()
  785. {
  786. return super.toString()+" Owner: "+getOwner();
  787. }
  788. }