StatusUpdate.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.network.serverpackets;
  16. import java.util.ArrayList;
  17. import com.l2jserver.gameserver.model.L2Object;
  18. import com.l2jserver.gameserver.model.L2World;
  19. import com.l2jserver.gameserver.model.actor.L2Attackable;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. /**
  22. *
  23. * 01 // Packet Identifier <BR>
  24. * c6 37 50 40 // ObjectId <BR><BR>
  25. *
  26. * 01 00 // Number of Attribute Trame of the Packet <BR><BR>
  27. *
  28. * c6 37 50 40 // Attribute Identifier : 01-Level, 02-Experience, 03-STR, 04-DEX, 05-CON, 06-INT, 07-WIT, 08-MEN, 09-Current HP, 0a, Max HP...<BR>
  29. * cd 09 00 00 // Attribute Value <BR>
  30. *
  31. * format d d(dd)
  32. *
  33. * @version $Revision: 1.3.2.1.2.5 $ $Date: 2005/03/27 15:29:39 $
  34. */
  35. public final class StatusUpdate extends L2GameServerPacket
  36. {
  37. private static final String _S__1A_STATUSUPDATE = "[S] 18 StatusUpdate";
  38. private static final int HP_MOD = 10000000;
  39. public static final int LEVEL = 0x01;
  40. public static final int EXP = 0x02;
  41. public static final int STR = 0x03;
  42. public static final int DEX = 0x04;
  43. public static final int CON = 0x05;
  44. public static final int INT = 0x06;
  45. public static final int WIT = 0x07;
  46. public static final int MEN = 0x08;
  47. public static final int CUR_HP = 0x09;
  48. public static final int MAX_HP = 0x0a;
  49. public static final int CUR_MP = 0x0b;
  50. public static final int MAX_MP = 0x0c;
  51. public static final int SP = 0x0d;
  52. public static final int CUR_LOAD = 0x0e;
  53. public static final int MAX_LOAD = 0x0f;
  54. public static final int P_ATK = 0x11;
  55. public static final int ATK_SPD = 0x12;
  56. public static final int P_DEF = 0x13;
  57. public static final int EVASION = 0x14;
  58. public static final int ACCURACY = 0x15;
  59. public static final int CRITICAL = 0x16;
  60. public static final int M_ATK = 0x17;
  61. public static final int CAST_SPD = 0x18;
  62. public static final int M_DEF = 0x19;
  63. public static final int PVP_FLAG = 0x1a;
  64. public static final int KARMA = 0x1b;
  65. public static final int CUR_CP = 0x21;
  66. public static final int MAX_CP = 0x22;
  67. private int _objectId;
  68. private int _maxHp = -1;
  69. private ArrayList<Attribute> _attributes;
  70. class Attribute
  71. {
  72. /** id values
  73. * 09 - current health
  74. * 0a - max health
  75. * 0b - current mana
  76. * 0c - max mana
  77. *
  78. */
  79. public int id;
  80. public int value;
  81. Attribute(int pId, int pValue)
  82. {
  83. id = pId;
  84. value = pValue;
  85. }
  86. }
  87. /**
  88. * If you have access to object itself use {@link StatusUpdate#StatusUpdate(L2Object)}.
  89. * @param objectId
  90. */
  91. public StatusUpdate(int objectId)
  92. {
  93. _attributes = new ArrayList<Attribute>();
  94. _objectId = objectId;
  95. L2Object obj = L2World.getInstance().findObject(objectId);
  96. if (obj != null && obj instanceof L2Attackable)
  97. {
  98. _maxHp = ((L2Character) obj).getMaxVisibleHp();
  99. }
  100. }
  101. /**
  102. * Create {@link StatusUpdate} packet for given {@link L2Object}.
  103. * @param object
  104. */
  105. public StatusUpdate(L2Object object)
  106. {
  107. _attributes = new ArrayList<Attribute>();
  108. _objectId = object.getObjectId();
  109. if (object instanceof L2Attackable)
  110. _maxHp = ((L2Character) object).getMaxVisibleHp();
  111. }
  112. public void addAttribute(int id, int level)
  113. {
  114. if (_maxHp != -1)
  115. {
  116. if (id == MAX_HP)
  117. level = HP_MOD;
  118. else if (id == CUR_HP)
  119. {
  120. level = (int) ((level / (float)_maxHp) * HP_MOD);
  121. }
  122. }
  123. _attributes.add(new Attribute(id, level));
  124. }
  125. @Override
  126. protected final void writeImpl()
  127. {
  128. writeC(0x18);
  129. writeD(_objectId);
  130. writeD(_attributes.size());
  131. for (Attribute temp: _attributes)
  132. {
  133. writeD(temp.id);
  134. writeD(temp.value);
  135. }
  136. }
  137. /* (non-Javadoc)
  138. * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
  139. */
  140. @Override
  141. public String getType()
  142. {
  143. return _S__1A_STATUSUPDATE;
  144. }
  145. }