SystemMessage.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 net.sf.l2j.gameserver.serverpackets;
  16. import java.util.Vector;
  17. import net.sf.l2j.gameserver.network.SystemMessageId;
  18. /**
  19. * This class ...
  20. *
  21. * @version $Revision: 1.18.2.5.2.8 $ $Date: 2005/04/05 19:41:08 $
  22. */
  23. public final class SystemMessage extends L2GameServerPacket
  24. {
  25. // d d (d S/d d/d dd)
  26. // |--------------> 0 - String 1-number 2-textref npcname (1000000-1002655) 3-textref itemname 4-textref skills 5-??
  27. private static final int TYPE_ZONE_NAME = 7;
  28. private static final int TYPE_SKILL_NAME = 4;
  29. private static final int TYPE_ITEM_NAME = 3;
  30. private static final int TYPE_NPC_NAME = 2;
  31. private static final int TYPE_NUMBER = 1;
  32. private static final int TYPE_TEXT = 0;
  33. private static final String _S__7A_SYSTEMMESSAGE = "[S] 62 SystemMessage";
  34. private int _messageId;
  35. private Vector<Integer> _types = new Vector<Integer>();
  36. private Vector<Object> _values = new Vector<Object>();
  37. private int _skillLvL = 1;
  38. public SystemMessage(SystemMessageId messageId)
  39. {
  40. _messageId = messageId.getId();
  41. }
  42. @Deprecated
  43. public SystemMessage(int messageId)
  44. {
  45. _messageId = messageId;
  46. }
  47. public static SystemMessage sendString(String msg)
  48. {
  49. SystemMessage sm = new SystemMessage(SystemMessageId.S1);
  50. sm.addString(msg);
  51. return sm;
  52. }
  53. public SystemMessage addString(String text)
  54. {
  55. _types.add(new Integer(TYPE_TEXT));
  56. _values.add(text);
  57. return this;
  58. }
  59. public SystemMessage addNumber(int number)
  60. {
  61. _types.add(new Integer(TYPE_NUMBER));
  62. _values.add(new Integer(number));
  63. return this;
  64. }
  65. public SystemMessage addNpcName(int id)
  66. {
  67. _types.add(new Integer(TYPE_NPC_NAME));
  68. _values.add(new Integer(1000000 + id));
  69. return this;
  70. }
  71. public SystemMessage addItemName(int id)
  72. {
  73. _types.add(new Integer(TYPE_ITEM_NAME));
  74. _values.add(new Integer(id));
  75. return this;
  76. }
  77. public SystemMessage addZoneName(int x, int y, int z)
  78. {
  79. _types.add(new Integer(TYPE_ZONE_NAME));
  80. int[] coord = {x, y, z};
  81. _values.add(coord);
  82. return this;
  83. }
  84. public SystemMessage addSkillName(int id){return addSkillName(id, 1);}
  85. public SystemMessage addSkillName(int id, int lvl)
  86. {
  87. _types.add(new Integer(TYPE_SKILL_NAME));
  88. _values.add(new Integer(id));
  89. _skillLvL = lvl;
  90. return this;
  91. }
  92. @Override
  93. protected final void writeImpl()
  94. {
  95. writeC(0x62);
  96. writeD(_messageId);
  97. writeD(_types.size());
  98. for (int i = 0; i < _types.size(); i++)
  99. {
  100. int t = _types.get(i).intValue();
  101. writeD(t);
  102. switch (t)
  103. {
  104. case TYPE_TEXT:
  105. {
  106. writeS( (String)_values.get(i));
  107. break;
  108. }
  109. case TYPE_NUMBER:
  110. case TYPE_NPC_NAME:
  111. case TYPE_ITEM_NAME:
  112. {
  113. int t1 = ((Integer)_values.get(i)).intValue();
  114. writeD(t1);
  115. break;
  116. }
  117. case TYPE_SKILL_NAME:
  118. {
  119. int t1 = ((Integer)_values.get(i)).intValue();
  120. writeD(t1); // Skill Id
  121. writeD(_skillLvL); // Skill lvl
  122. break;
  123. }
  124. case TYPE_ZONE_NAME:
  125. {
  126. int t1 = ((int[])_values.get(i))[0];
  127. int t2 = ((int[])_values.get(i))[1];
  128. int t3 = ((int[])_values.get(i))[2];
  129. writeD(t1);
  130. writeD(t2);
  131. writeD(t3);
  132. break;
  133. }
  134. }
  135. }
  136. }
  137. /* (non-Javadoc)
  138. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
  139. */
  140. @Override
  141. public String getType()
  142. {
  143. return _S__7A_SYSTEMMESSAGE;
  144. }
  145. public int getMessageID()
  146. {
  147. return _messageId;
  148. }
  149. }