L2Transformation.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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;
  16. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  17. /**
  18. * @author KenM
  19. */
  20. public abstract class L2Transformation implements Cloneable, Runnable
  21. {
  22. private final int _id;
  23. private final int _graphicalId;
  24. private double _collisionRadius;
  25. private double _collisionHeight;
  26. private final boolean _isStance;
  27. public static final int TRANSFORM_ZARICHE = 301;
  28. public static final int TRANSFORM_AKAMANAH = 302;
  29. protected static final int[] EMPTY_ARRAY = {};
  30. private L2PcInstance _player;
  31. /**
  32. * @param id Internal id that server will use to associate this transformation
  33. * @param graphicalId Client visible transformation id
  34. * @param collisionRadius Collision Radius of the player while transformed
  35. * @param collisionHeight Collision Height of the player while transformed
  36. */
  37. public L2Transformation(int id, int graphicalId, double collisionRadius, double collisionHeight)
  38. {
  39. _id = id;
  40. _graphicalId = graphicalId;
  41. _collisionRadius = collisionRadius;
  42. _collisionHeight = collisionHeight;
  43. _isStance = false;
  44. }
  45. /**
  46. * @param id Internal id(will be used also as client graphical id) that server will use to associate this transformation
  47. * @param collisionRadius Collision Radius of the player while transformed
  48. * @param collisionHeight Collision Height of the player while transformed
  49. */
  50. public L2Transformation(int id, double collisionRadius, double collisionHeight)
  51. {
  52. this(id, id, collisionRadius, collisionHeight);
  53. }
  54. /**
  55. * @param id Internal id(will be used also as client graphical id) that server will use to associate this transformation Used for stances
  56. */
  57. public L2Transformation(int id)
  58. {
  59. _id = id;
  60. _graphicalId = id;
  61. _isStance = true;
  62. }
  63. /**
  64. * @return Returns the id.
  65. */
  66. public int getId()
  67. {
  68. return _id;
  69. }
  70. /**
  71. * @return Returns the graphicalId.
  72. */
  73. public int getGraphicalId()
  74. {
  75. return _graphicalId;
  76. }
  77. /**
  78. * Return true if this is a stance (vanguard/inquisitor)
  79. * @return
  80. */
  81. public boolean isStance()
  82. {
  83. return _isStance;
  84. }
  85. /**
  86. * @return Returns the collisionRadius.
  87. */
  88. public double getCollisionRadius()
  89. {
  90. if (isStance())
  91. {
  92. return _player.getCollisionRadius();
  93. }
  94. return _collisionRadius;
  95. }
  96. /**
  97. * @return Returns the collisionHeight.
  98. */
  99. public double getCollisionHeight()
  100. {
  101. if (isStance())
  102. {
  103. return _player.getCollisionHeight();
  104. }
  105. return _collisionHeight;
  106. }
  107. // Scriptable Events
  108. public abstract void onTransform();
  109. public abstract void onUntransform();
  110. /**
  111. * @param player The player to set.
  112. */
  113. private void setPlayer(L2PcInstance player)
  114. {
  115. _player = player;
  116. }
  117. /**
  118. * @return Returns the player.
  119. */
  120. public L2PcInstance getPlayer()
  121. {
  122. return _player;
  123. }
  124. public void start()
  125. {
  126. resume();
  127. }
  128. public void resume()
  129. {
  130. getPlayer().transform(this);
  131. }
  132. @Override
  133. public void run()
  134. {
  135. stop();
  136. }
  137. public void stop()
  138. {
  139. getPlayer().untransform();
  140. }
  141. public L2Transformation createTransformationForPlayer(L2PcInstance player)
  142. {
  143. try
  144. {
  145. L2Transformation transformation = (L2Transformation) clone();
  146. transformation.setPlayer(player);
  147. return transformation;
  148. }
  149. catch (CloneNotSupportedException e)
  150. {
  151. // should never happen
  152. return null;
  153. }
  154. }
  155. // Override if necessary
  156. public void onLevelUp()
  157. {
  158. }
  159. /**
  160. * @return true if transformation can do melee attack
  161. */
  162. public boolean canDoMeleeAttack()
  163. {
  164. return true;
  165. }
  166. /**
  167. * @return true if transformation can start follow target when trying to cast an skill out of range
  168. */
  169. public boolean canStartFollowToCast()
  170. {
  171. return true;
  172. }
  173. @Override
  174. public String toString()
  175. {
  176. return getClass().getSimpleName() + " [_id=" + _id + ", _graphicalId=" + _graphicalId + ", _collisionRadius=" + _collisionRadius + ", _collisionHeight=" + _collisionHeight + ", _isStance=" + _isStance + "]";
  177. }
  178. }