L2Playable.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 com.l2jserver.gameserver.ai.CtrlEvent;
  17. import com.l2jserver.gameserver.model.CharEffectList;
  18. import com.l2jserver.gameserver.model.L2Effect;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.actor.knownlist.PlayableKnownList;
  22. import com.l2jserver.gameserver.model.actor.stat.PlayableStat;
  23. import com.l2jserver.gameserver.model.actor.status.PlayableStatus;
  24. import com.l2jserver.gameserver.model.quest.QuestState;
  25. import com.l2jserver.gameserver.templates.chars.L2CharTemplate;
  26. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  27. /**
  28. * This class represents all Playable characters in the world.<BR><BR>
  29. *
  30. * L2PlayableInstance :<BR><BR>
  31. * <li>L2PcInstance</li>
  32. * <li>L2Summon</li><BR><BR>
  33. *
  34. */
  35. public abstract class L2Playable extends L2Character
  36. {
  37. private L2Character _lockedTarget = null;
  38. /**
  39. * Constructor of L2PlayableInstance (use L2Character constructor).<BR><BR>
  40. *
  41. * <B><U> Actions</U> :</B><BR><BR>
  42. * <li>Call the L2Character constructor to create an empty _skills slot and link copy basic Calculator set to this L2PlayableInstance </li><BR><BR>
  43. *
  44. * @param objectId Identifier of the object to initialized
  45. * @param template The L2CharTemplate to apply to the L2PlayableInstance
  46. *
  47. */
  48. public L2Playable(int objectId, L2CharTemplate template)
  49. {
  50. super(objectId, template);
  51. setInstanceType(InstanceType.L2Playable);
  52. setIsInvul(false);
  53. }
  54. @Override
  55. public PlayableKnownList getKnownList()
  56. {
  57. return (PlayableKnownList)super.getKnownList();
  58. }
  59. @Override
  60. public void initKnownList()
  61. {
  62. setKnownList(new PlayableKnownList(this));
  63. }
  64. @Override
  65. public PlayableStat getStat()
  66. {
  67. return (PlayableStat)super.getStat();
  68. }
  69. @Override
  70. public void initCharStat()
  71. {
  72. setStat(new PlayableStat(this));
  73. }
  74. @Override
  75. public PlayableStatus getStatus()
  76. {
  77. return (PlayableStatus)super.getStatus();
  78. }
  79. @Override
  80. public void initCharStatus()
  81. {
  82. setStatus(new PlayableStatus(this));
  83. }
  84. @Override
  85. public boolean doDie(L2Character killer)
  86. {
  87. // killing is only possible one time
  88. synchronized (this)
  89. {
  90. if (isDead())
  91. return false;
  92. // now reset currentHp to zero
  93. setCurrentHp(0);
  94. setIsDead(true);
  95. }
  96. // Set target to null and cancel Attack or Cast
  97. setTarget(null);
  98. // Stop movement
  99. stopMove(null);
  100. // Stop HP/MP/CP Regeneration task
  101. getStatus().stopHpMpRegeneration();
  102. // Stop all active skills effects in progress on the L2Character,
  103. // if the Character isn't affected by Soul of The Phoenix or Salvation
  104. if (isPhoenixBlessed())
  105. {
  106. if (getCharmOfLuck()) //remove Lucky Charm if player has SoulOfThePhoenix/Salvation buff
  107. stopCharmOfLuck(null);
  108. if (isNoblesseBlessed())
  109. stopNoblesseBlessing(null);
  110. }
  111. // Same thing if the Character isn't a Noblesse Blessed L2PlayableInstance
  112. else if (isNoblesseBlessed())
  113. {
  114. stopNoblesseBlessing(null);
  115. if (getCharmOfLuck()) //remove Lucky Charm if player have Nobless blessing buff
  116. stopCharmOfLuck(null);
  117. }
  118. else
  119. stopAllEffectsExceptThoseThatLastThroughDeath();
  120. // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  121. broadcastStatusUpdate();
  122. if (getWorldRegion() != null)
  123. getWorldRegion().onDeath(this);
  124. // Notify Quest of L2Playable's death
  125. L2PcInstance actingPlayer = getActingPlayer();
  126. if (!actingPlayer.isNotifyQuestOfDeathEmpty())
  127. {
  128. for (QuestState qs : actingPlayer.getNotifyQuestOfDeath())
  129. {
  130. qs.getQuest().notifyDeath((killer == null ? this : killer), this, qs);
  131. }
  132. }
  133. if (killer != null)
  134. {
  135. L2PcInstance player = killer.getActingPlayer();
  136. if (player != null)
  137. player.onKillUpdatePvPKarma(this);
  138. }
  139. // Notify L2Character AI
  140. getAI().notifyEvent(CtrlEvent.EVT_DEAD);
  141. return true;
  142. }
  143. public boolean checkIfPvP(L2Character target)
  144. {
  145. if (target == null) return false; // Target is null
  146. if (target == this) return false; // Target is self
  147. if (!(target instanceof L2Playable)) return false; // Target is not a L2PlayableInstance
  148. L2PcInstance player = null;
  149. if (this instanceof L2PcInstance)
  150. player = (L2PcInstance)this;
  151. else if (this instanceof L2Summon)
  152. player = ((L2Summon)this).getOwner();
  153. if (player == null) return false; // Active player is null
  154. if (player.getKarma() != 0) return false; // Active player has karma
  155. L2PcInstance targetPlayer = null;
  156. if (target instanceof L2PcInstance)
  157. targetPlayer = (L2PcInstance)target;
  158. else if (target instanceof L2Summon)
  159. targetPlayer = ((L2Summon)target).getOwner();
  160. if (targetPlayer == null) return false; // Target player is null
  161. if (targetPlayer == this) return false; // Target player is self
  162. if (targetPlayer.getKarma() != 0) return false; // Target player has karma
  163. if (targetPlayer.getPvpFlag() == 0) return false;
  164. return true;
  165. /* Even at war, there should be PvP flag
  166. if(
  167. player.getClan() == null ||
  168. targetPlayer.getClan() == null ||
  169. (
  170. !targetPlayer.getClan().isAtWarWith(player.getClanId()) &&
  171. targetPlayer.getWantsPeace() == 0 &&
  172. player.getWantsPeace() == 0
  173. )
  174. )
  175. {
  176. return true;
  177. }
  178. return false;
  179. */
  180. }
  181. /**
  182. * Return True.<BR><BR>
  183. */
  184. @Override
  185. public boolean isAttackable()
  186. {
  187. return true;
  188. }
  189. // Support for Noblesse Blessing skill, where buffs are retained
  190. // after resurrect
  191. public final boolean isNoblesseBlessed()
  192. {
  193. return _effects.isAffected(CharEffectList.EFFECT_FLAG_NOBLESS_BLESSING);
  194. }
  195. public final void stopNoblesseBlessing(L2Effect effect)
  196. {
  197. if (effect == null)
  198. stopEffects(L2EffectType.NOBLESSE_BLESSING);
  199. else
  200. removeEffect(effect);
  201. updateAbnormalEffect();
  202. }
  203. // Support for Soul of the Phoenix and Salvation skills
  204. public final boolean isPhoenixBlessed()
  205. {
  206. return _effects.isAffected(CharEffectList.EFFECT_FLAG_PHOENIX_BLESSING);
  207. }
  208. public final void stopPhoenixBlessing(L2Effect effect)
  209. {
  210. if (effect == null)
  211. stopEffects(L2EffectType.PHOENIX_BLESSING);
  212. else
  213. removeEffect(effect);
  214. updateAbnormalEffect();
  215. }
  216. /**
  217. * Return True if the Silent Moving mode is active.<BR><BR>
  218. */
  219. public boolean isSilentMoving()
  220. {
  221. return _effects.isAffected(CharEffectList.EFFECT_FLAG_SILENT_MOVE);
  222. }
  223. // for Newbie Protection Blessing skill, keeps you safe from an attack by a chaotic character >= 10 levels apart from you
  224. public final boolean getProtectionBlessing()
  225. {
  226. return _effects.isAffected(CharEffectList.EFFECT_FLAG_PROTECTION_BLESSING);
  227. }
  228. /**
  229. * @param blessing
  230. */
  231. public void stopProtectionBlessing(L2Effect effect)
  232. {
  233. if (effect == null)
  234. stopEffects(L2EffectType.PROTECTION_BLESSING);
  235. else
  236. removeEffect(effect);
  237. updateAbnormalEffect();
  238. }
  239. //Charm of Luck - During a Raid/Boss war, decreased chance for death penalty
  240. public final boolean getCharmOfLuck()
  241. {
  242. return _effects.isAffected(CharEffectList.EFFECT_FLAG_CHARM_OF_LUCK);
  243. }
  244. public final void stopCharmOfLuck(L2Effect effect)
  245. {
  246. if (effect == null)
  247. stopEffects(L2EffectType.CHARM_OF_LUCK);
  248. else
  249. removeEffect(effect);
  250. updateAbnormalEffect();
  251. }
  252. @Override
  253. public void updateEffectIcons(boolean partyOnly)
  254. {
  255. _effects.updateEffectIcons(partyOnly);
  256. }
  257. public boolean isLockedTarget()
  258. {
  259. return _lockedTarget != null;
  260. }
  261. public L2Character getLockedTarget()
  262. {
  263. return _lockedTarget;
  264. }
  265. public void setLockedTarget(L2Character cha)
  266. {
  267. _lockedTarget = cha;
  268. }
  269. public abstract int getKarma();
  270. public abstract byte getPvpFlag();
  271. public abstract boolean useMagic(L2Skill skill, boolean forceUse, boolean dontMove);
  272. }