L2Playable.java 10 KB

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