L2Playable.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. setInstanceType(InstanceType.L2Playable);
  55. setIsInvul(false);
  56. }
  57. @Override
  58. public PlayableKnownList getKnownList()
  59. {
  60. return (PlayableKnownList)super.getKnownList();
  61. }
  62. @Override
  63. public void initKnownList()
  64. {
  65. setKnownList(new PlayableKnownList(this));
  66. }
  67. @Override
  68. public PlayableStat getStat()
  69. {
  70. return (PlayableStat)super.getStat();
  71. }
  72. @Override
  73. public void initCharStat()
  74. {
  75. setStat(new PlayableStat(this));
  76. }
  77. @Override
  78. public PlayableStatus getStatus()
  79. {
  80. return (PlayableStatus)super.getStatus();
  81. }
  82. @Override
  83. public void initCharStatus()
  84. {
  85. setStatus(new PlayableStatus(this));
  86. }
  87. @Override
  88. public boolean doDie(L2Character killer)
  89. {
  90. // killing is only possible one time
  91. synchronized (this)
  92. {
  93. if (isDead())
  94. return false;
  95. // now reset currentHp to zero
  96. setCurrentHp(0);
  97. setIsDead(true);
  98. }
  99. // Set target to null and cancel Attack or Cast
  100. setTarget(null);
  101. // Stop movement
  102. stopMove(null);
  103. // Stop HP/MP/CP Regeneration task
  104. getStatus().stopHpMpRegeneration();
  105. // Stop all active skills effects in progress on the L2Character,
  106. // if the Character isn't affected by Soul of The Phoenix or Salvation
  107. if (isPhoenixBlessed())
  108. {
  109. if (getCharmOfLuck()) //remove Lucky Charm if player has SoulOfThePhoenix/Salvation buff
  110. stopCharmOfLuck(null);
  111. if (isNoblesseBlessed())
  112. stopNoblesseBlessing(null);
  113. }
  114. // Same thing if the Character isn't a Noblesse Blessed L2PlayableInstance
  115. else if (isNoblesseBlessed())
  116. {
  117. stopNoblesseBlessing(null);
  118. if (getCharmOfLuck()) //remove Lucky Charm if player have Nobless blessing buff
  119. stopCharmOfLuck(null);
  120. }
  121. else
  122. stopAllEffectsExceptThoseThatLastThroughDeath();
  123. // Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
  124. broadcastStatusUpdate();
  125. if (getWorldRegion() != null)
  126. getWorldRegion().onDeath(this);
  127. // Notify Quest of L2Playable's death
  128. L2PcInstance actingPlayer = getActingPlayer();
  129. for (QuestState qs : actingPlayer.getNotifyQuestOfDeath())
  130. {
  131. qs.getQuest().notifyDeath((killer == null ? this : killer), this, qs);
  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() { return _isNoblesseBlessed; }
  192. public final void setIsNoblesseBlessed(boolean value) { _isNoblesseBlessed = value; }
  193. public final void startNoblesseBlessing()
  194. {
  195. setIsNoblesseBlessed(true);
  196. updateAbnormalEffect();
  197. }
  198. public final void stopNoblesseBlessing(L2Effect effect)
  199. {
  200. if (effect == null)
  201. stopEffects(L2EffectType.NOBLESSE_BLESSING);
  202. else
  203. removeEffect(effect);
  204. setIsNoblesseBlessed(false);
  205. updateAbnormalEffect();
  206. }
  207. // Support for Soul of the Phoenix and Salvation skills
  208. public final boolean isPhoenixBlessed() { return _isPhoenixBlessed; }
  209. public final void setIsPhoenixBlessed(boolean value) { _isPhoenixBlessed = value; }
  210. public final void startPhoenixBlessing()
  211. {
  212. setIsPhoenixBlessed(true);
  213. updateAbnormalEffect();
  214. }
  215. public final void stopPhoenixBlessing(L2Effect effect)
  216. {
  217. if (effect == null)
  218. stopEffects(L2EffectType.PHOENIX_BLESSING);
  219. else
  220. removeEffect(effect);
  221. setIsPhoenixBlessed(false);
  222. updateAbnormalEffect();
  223. }
  224. /**
  225. * Set the Silent Moving mode Flag.<BR><BR>
  226. */
  227. public void setSilentMoving(boolean flag)
  228. {
  229. _isSilentMoving = flag;
  230. }
  231. /**
  232. * Return True if the Silent Moving mode is active.<BR><BR>
  233. */
  234. public boolean isSilentMoving()
  235. {
  236. return _isSilentMoving;
  237. }
  238. // for Newbie Protection Blessing skill, keeps you safe from an attack by a chaotic character >= 10 levels apart from you
  239. public final boolean getProtectionBlessing() { return _ProtectionBlessing; }
  240. public final void setProtectionBlessing(boolean value) { _ProtectionBlessing = value; }
  241. public void startProtectionBlessing()
  242. {
  243. setProtectionBlessing(true);
  244. updateAbnormalEffect();
  245. }
  246. /**
  247. * @param blessing
  248. */
  249. public void stopProtectionBlessing(L2Effect effect)
  250. {
  251. if (effect == null)
  252. stopEffects(L2EffectType.PROTECTION_BLESSING);
  253. else
  254. removeEffect(effect);
  255. setProtectionBlessing(false);
  256. updateAbnormalEffect();
  257. }
  258. //Charm of Luck - During a Raid/Boss war, decreased chance for death penalty
  259. public final boolean getCharmOfLuck() { return _getCharmOfLuck; }
  260. public final void setCharmOfLuck(boolean value) { _getCharmOfLuck = value; }
  261. public final void startCharmOfLuck()
  262. {
  263. setCharmOfLuck(true);
  264. updateAbnormalEffect();
  265. }
  266. public final void stopCharmOfLuck(L2Effect effect)
  267. {
  268. if (effect == null)
  269. stopEffects(L2EffectType.CHARM_OF_LUCK);
  270. else
  271. removeEffect(effect);
  272. setCharmOfLuck(false);
  273. updateAbnormalEffect();
  274. }
  275. @Override
  276. public void updateEffectIcons(boolean partyOnly)
  277. {
  278. _effects.updateEffectIcons(partyOnly);
  279. }
  280. public boolean isLockedTarget()
  281. {
  282. return _lockedTarget != null;
  283. }
  284. public L2Character getLockedTarget()
  285. {
  286. return _lockedTarget;
  287. }
  288. public void setLockedTarget(L2Character cha)
  289. {
  290. _lockedTarget = cha;
  291. }
  292. }