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. *
  19. * @author KenM
  20. */
  21. public abstract class L2Transformation implements Cloneable, Runnable
  22. {
  23. private final int _id;
  24. private final int _graphicalId;
  25. private double _collisionRadius;
  26. private double _collisionHeight;
  27. private final boolean _isStance;
  28. public static final int TRANSFORM_ZARICHE = 301;
  29. public static final int TRANSFORM_AKAMANAH = 302;
  30. protected static final int[] EMPTY_ARRAY = {};
  31. private L2PcInstance _player;
  32. /**
  33. *
  34. * @param id Internal id that server will use to associate this transformation
  35. * @param graphicalId Client visible transformation id
  36. * @param collisionRadius Collision Radius of the player while transformed
  37. * @param collisionHeight Collision Height of the player while transformed
  38. */
  39. public L2Transformation(int id, int graphicalId, double collisionRadius, double collisionHeight)
  40. {
  41. _id = id;
  42. _graphicalId = graphicalId;
  43. _collisionRadius = collisionRadius;
  44. _collisionHeight = collisionHeight;
  45. _isStance = false;
  46. }
  47. /**
  48. *
  49. * @param id Internal id(will be used also as client graphical id) that server will use to associate this transformation
  50. * @param collisionRadius Collision Radius of the player while transformed
  51. * @param collisionHeight Collision Height of the player while transformed
  52. */
  53. public L2Transformation(int id, double collisionRadius, double collisionHeight)
  54. {
  55. this(id, id, collisionRadius, collisionHeight);
  56. }
  57. /**
  58. *
  59. * @param id Internal id(will be used also as client graphical id) that server will use to associate this transformation
  60. * Used for stances
  61. */
  62. public L2Transformation(int id)
  63. {
  64. _id = id;
  65. _graphicalId = id;
  66. _isStance = true;
  67. }
  68. /**
  69. * @return Returns the id.
  70. */
  71. public int getId()
  72. {
  73. return _id;
  74. }
  75. /**
  76. * @return Returns the graphicalId.
  77. */
  78. public int getGraphicalId()
  79. {
  80. return _graphicalId;
  81. }
  82. /**
  83. * Return true if this is a stance (vanguard/inquisitor)
  84. * @return
  85. */
  86. public boolean isStance()
  87. {
  88. return _isStance;
  89. }
  90. /**
  91. * @return Returns the collisionRadius.
  92. */
  93. public double getCollisionRadius()
  94. {
  95. if (isStance())
  96. return _player.getCollisionRadius();
  97. return _collisionRadius;
  98. }
  99. /**
  100. * @return Returns the collisionHeight.
  101. */
  102. public double getCollisionHeight()
  103. {
  104. if (isStance())
  105. return _player.getCollisionHeight();
  106. return _collisionHeight;
  107. }
  108. // Scriptable Events
  109. public abstract void onTransform();
  110. public abstract void onUntransform();
  111. /**
  112. * @param player The player to set.
  113. */
  114. private void setPlayer(L2PcInstance player)
  115. {
  116. _player = player;
  117. }
  118. /**
  119. * @return Returns the player.
  120. */
  121. public L2PcInstance getPlayer()
  122. {
  123. return _player;
  124. }
  125. public void start()
  126. {
  127. this.resume();
  128. }
  129. public void resume()
  130. {
  131. this.getPlayer().transform(this);
  132. }
  133. public void run()
  134. {
  135. this.stop();
  136. }
  137. public void stop()
  138. {
  139. this.getPlayer().untransform();
  140. }
  141. public L2Transformation createTransformationForPlayer(L2PcInstance player)
  142. {
  143. try
  144. {
  145. L2Transformation transformation = (L2Transformation) this.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. }