ConfirmDlg.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. /**
  18. * @author kombat
  19. * Format: cd d[d s/d/dd/ddd]
  20. */
  21. public class ConfirmDlg extends L2GameServerPacket
  22. {
  23. private static final String _S__ED_CONFIRMDLG = "[S] f3 ConfirmDlg";
  24. private int _messageId;
  25. private int _skillLvL = 1;
  26. private static final int TYPE_ZONE_NAME = 7;
  27. private static final int TYPE_SKILL_NAME = 4;
  28. private static final int TYPE_ITEM_NAME = 3;
  29. private static final int TYPE_NPC_NAME = 2;
  30. private static final int TYPE_NUMBER = 1;
  31. private static final int TYPE_TEXT = 0;
  32. private Vector<Integer> _types = new Vector<Integer>();
  33. private Vector<Object> _values = new Vector<Object>();
  34. public ConfirmDlg(int messageId)
  35. {
  36. _messageId = messageId;
  37. }
  38. public ConfirmDlg addString(String text)
  39. {
  40. _types.add(new Integer(TYPE_TEXT));
  41. _values.add(text);
  42. return this;
  43. }
  44. public ConfirmDlg addNumber(int number)
  45. {
  46. _types.add(new Integer(TYPE_NUMBER));
  47. _values.add(new Integer(number));
  48. return this;
  49. }
  50. public ConfirmDlg addNpcName(int id)
  51. {
  52. _types.add(new Integer(TYPE_NPC_NAME));
  53. _values.add(new Integer(1000000 + id));
  54. return this;
  55. }
  56. public ConfirmDlg addItemName(int id)
  57. {
  58. _types.add(new Integer(TYPE_ITEM_NAME));
  59. _values.add(new Integer(id));
  60. return this;
  61. }
  62. public ConfirmDlg addZoneName(int x, int y, int z)
  63. {
  64. _types.add(new Integer(TYPE_ZONE_NAME));
  65. int[] coord = {x, y, z};
  66. _values.add(coord);
  67. return this;
  68. }
  69. public ConfirmDlg addSkillName(int id)
  70. {
  71. return addSkillName(id, 1);
  72. }
  73. public ConfirmDlg addSkillName(int id, int lvl)
  74. {
  75. _types.add(new Integer(TYPE_SKILL_NAME));
  76. _values.add(new Integer(id));
  77. _skillLvL = lvl;
  78. return this;
  79. }
  80. @Override
  81. protected final void writeImpl()
  82. {
  83. writeC(0xf3);
  84. writeD(_messageId);
  85. writeD(_types.size());
  86. for (int i = 0; i < _types.size(); i++)
  87. {
  88. int t = _types.get(i).intValue();
  89. writeD(t);
  90. switch (t)
  91. {
  92. case TYPE_TEXT:
  93. {
  94. writeS( (String)_values.get(i));
  95. break;
  96. }
  97. case TYPE_NUMBER:
  98. case TYPE_NPC_NAME:
  99. case TYPE_ITEM_NAME:
  100. {
  101. int t1 = ((Integer)_values.get(i)).intValue();
  102. writeD(t1);
  103. break;
  104. }
  105. case TYPE_SKILL_NAME:
  106. {
  107. int t1 = ((Integer)_values.get(i)).intValue();
  108. writeD(t1); // Skill Id
  109. writeD(_skillLvL); // Skill lvl
  110. break;
  111. }
  112. case TYPE_ZONE_NAME:
  113. {
  114. int t1 = ((int[])_values.get(i))[0];
  115. int t2 = ((int[])_values.get(i))[1];
  116. int t3 = ((int[])_values.get(i))[2];
  117. writeD(t1);
  118. writeD(t2);
  119. writeD(t3);
  120. break;
  121. }
  122. }
  123. }
  124. }
  125. /* (non-Javadoc)
  126. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
  127. */
  128. @Override
  129. public String getType()
  130. {
  131. return _S__ED_CONFIRMDLG;
  132. }
  133. }