L2Transformation.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. /**
  22. * @author KenM
  23. */
  24. public abstract class L2Transformation implements Cloneable, Runnable
  25. {
  26. private final int _id;
  27. private final int _graphicalId;
  28. private double _collisionRadius;
  29. private double _collisionHeight;
  30. private final boolean _isStance;
  31. public static final int TRANSFORM_ZARICHE = 301;
  32. public static final int TRANSFORM_AKAMANAH = 302;
  33. protected static final int[] EMPTY_ARRAY = {};
  34. private L2PcInstance _player;
  35. /**
  36. * @param id Internal id that server will use to associate this transformation
  37. * @param graphicalId Client visible transformation id
  38. * @param collisionRadius Collision Radius of the player while transformed
  39. * @param collisionHeight Collision Height of the player while transformed
  40. */
  41. public L2Transformation(int id, int graphicalId, double collisionRadius, double collisionHeight)
  42. {
  43. _id = id;
  44. _graphicalId = graphicalId;
  45. _collisionRadius = collisionRadius;
  46. _collisionHeight = collisionHeight;
  47. _isStance = false;
  48. }
  49. /**
  50. * @param id Internal id(will be used also as client graphical id) that server will use to associate this transformation
  51. * @param collisionRadius Collision Radius of the player while transformed
  52. * @param collisionHeight Collision Height of the player while transformed
  53. */
  54. public L2Transformation(int id, double collisionRadius, double collisionHeight)
  55. {
  56. this(id, id, collisionRadius, collisionHeight);
  57. }
  58. /**
  59. * @param id Internal id(will be used also as client graphical id) that server will use to associate this transformation Used for stances
  60. */
  61. public L2Transformation(int id)
  62. {
  63. _id = id;
  64. _graphicalId = id;
  65. _isStance = true;
  66. }
  67. /**
  68. * @return Returns the id.
  69. */
  70. public int getId()
  71. {
  72. return _id;
  73. }
  74. /**
  75. * @return Returns the graphicalId.
  76. */
  77. public int getGraphicalId()
  78. {
  79. return _graphicalId;
  80. }
  81. /**
  82. * Return true if this is a stance (vanguard/inquisitor)
  83. * @return
  84. */
  85. public boolean isStance()
  86. {
  87. return _isStance;
  88. }
  89. /**
  90. * @return Returns the collisionRadius.
  91. */
  92. public double getCollisionRadius()
  93. {
  94. if (isStance())
  95. {
  96. return _player.getCollisionRadius();
  97. }
  98. return _collisionRadius;
  99. }
  100. /**
  101. * @return Returns the collisionHeight.
  102. */
  103. public double getCollisionHeight()
  104. {
  105. if (isStance())
  106. {
  107. return _player.getCollisionHeight();
  108. }
  109. return _collisionHeight;
  110. }
  111. // Scriptable Events
  112. public abstract void onTransform();
  113. public abstract void onUntransform();
  114. /**
  115. * @param player The player to set.
  116. */
  117. private void setPlayer(L2PcInstance player)
  118. {
  119. _player = player;
  120. }
  121. /**
  122. * @return Returns the player.
  123. */
  124. public L2PcInstance getPlayer()
  125. {
  126. return _player;
  127. }
  128. public void start()
  129. {
  130. resume();
  131. }
  132. public void resume()
  133. {
  134. getPlayer().transform(this);
  135. }
  136. @Override
  137. public void run()
  138. {
  139. stop();
  140. }
  141. public void stop()
  142. {
  143. getPlayer().untransform();
  144. }
  145. public L2Transformation createTransformationForPlayer(L2PcInstance player)
  146. {
  147. try
  148. {
  149. L2Transformation transformation = (L2Transformation) clone();
  150. transformation.setPlayer(player);
  151. return transformation;
  152. }
  153. catch (CloneNotSupportedException e)
  154. {
  155. // should never happen
  156. return null;
  157. }
  158. }
  159. // Override if necessary
  160. public void onLevelUp()
  161. {
  162. }
  163. /**
  164. * @return true if transformation can do melee attack
  165. */
  166. public boolean canDoMeleeAttack()
  167. {
  168. return true;
  169. }
  170. /**
  171. * @return true if transformation can start follow target when trying to cast an skill out of range
  172. */
  173. public boolean canStartFollowToCast()
  174. {
  175. return true;
  176. }
  177. @Override
  178. public String toString()
  179. {
  180. return getClass().getSimpleName() + " [_id=" + _id + ", _graphicalId=" + _graphicalId + ", _collisionRadius=" + _collisionRadius + ", _collisionHeight=" + _collisionHeight + ", _isStance=" + _isStance + "]";
  181. }
  182. }