L2Transformation.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. private L2PcInstance _player;
  31. /**
  32. *
  33. * @param id Internal id that server will use to associate this transformation
  34. * @param graphicalId Client visible transformation id
  35. * @param collisionRadius Collision Radius of the player while transformed
  36. * @param collisionHeight Collision Height of the player while transformed
  37. */
  38. public L2Transformation(int id, int graphicalId, double collisionRadius, double collisionHeight)
  39. {
  40. _id = id;
  41. _graphicalId = graphicalId;
  42. _collisionRadius = collisionRadius;
  43. _collisionHeight = collisionHeight;
  44. _isStance = false;
  45. }
  46. /**
  47. *
  48. * @param id Internal id(will be used also as client graphical id) that server will use to associate this transformation
  49. * @param collisionRadius Collision Radius of the player while transformed
  50. * @param collisionHeight Collision Height of the player while transformed
  51. */
  52. public L2Transformation(int id, double collisionRadius, double collisionHeight)
  53. {
  54. this(id, id, collisionRadius, collisionHeight);
  55. }
  56. /**
  57. *
  58. * @param id Internal id(will be used also as client graphical id) that server will use to associate this transformation
  59. * 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. return _player.getBaseTemplate().collisionRadius;
  96. return _collisionRadius;
  97. }
  98. /**
  99. * @return Returns the collisionHeight.
  100. */
  101. public double getCollisionHeight()
  102. {
  103. if (isStance())
  104. return _player.getBaseTemplate().collisionHeight;
  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. this.resume();
  127. }
  128. public void resume()
  129. {
  130. this.getPlayer().transform(this);
  131. }
  132. public void run()
  133. {
  134. this.stop();
  135. }
  136. public void stop()
  137. {
  138. this.getPlayer().untransform();
  139. }
  140. public L2Transformation createTransformationForPlayer(L2PcInstance player)
  141. {
  142. try
  143. {
  144. L2Transformation transformation = (L2Transformation) this.clone();
  145. transformation.setPlayer(player);
  146. return transformation;
  147. }
  148. catch (CloneNotSupportedException e)
  149. {
  150. // should never happen
  151. return null;
  152. }
  153. }
  154. // Override if necessary
  155. public void onLevelUp()
  156. {
  157. }
  158. /**
  159. * Returns true if transformation can do melee attack
  160. */
  161. public boolean canDoMeleeAttack()
  162. {
  163. return true;
  164. }
  165. /**
  166. * Returns true if transformation can start follow target when trying to cast an skill out of range
  167. */
  168. public boolean canStartFollowToCast()
  169. {
  170. return true;
  171. }
  172. }