ConfirmDlg.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 com.l2jserver.gameserver.model.L2Effect;
  17. import com.l2jserver.gameserver.model.L2ItemInstance;
  18. import com.l2jserver.gameserver.model.L2Skill;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.L2Summon;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  24. import com.l2jserver.gameserver.templates.item.L2Item;
  25. import javolution.util.FastList;
  26. /**
  27. * @author kombat
  28. * Format: cd d[d s/d/dd/ddd]
  29. */
  30. public class ConfirmDlg extends L2GameServerPacket
  31. {
  32. private static final String _S__ED_CONFIRMDLG = "[S] f3 ConfirmDlg";
  33. private int _messageId;
  34. private int _skillLvL = 1;
  35. private static final int TYPE_ZONE_NAME = 7;
  36. private static final int TYPE_SKILL_NAME = 4;
  37. private static final int TYPE_ITEM_NAME = 3;
  38. private static final int TYPE_NPC_NAME = 2;
  39. private static final int TYPE_NUMBER = 1;
  40. private static final int TYPE_TEXT = 0;
  41. private final FastList<CnfDlgData> _info = new FastList<CnfDlgData>();
  42. private int _time = 0;
  43. private int _requesterId = 0;
  44. protected class CnfDlgData
  45. {
  46. protected final int type;
  47. protected final Object value;
  48. protected CnfDlgData(int t, Object val)
  49. {
  50. type = t;
  51. value = val;
  52. }
  53. }
  54. public ConfirmDlg(int messageId)
  55. {
  56. _messageId = messageId;
  57. }
  58. public ConfirmDlg addString(String text)
  59. {
  60. _info.add(new CnfDlgData(TYPE_TEXT, text));
  61. return this;
  62. }
  63. public ConfirmDlg addNumber(int number)
  64. {
  65. _info.add(new CnfDlgData(TYPE_NUMBER, number));
  66. return this;
  67. }
  68. public ConfirmDlg addCharName(L2Character cha)
  69. {
  70. if (cha instanceof L2Npc)
  71. return addNpcName((L2Npc)cha);
  72. if (cha instanceof L2PcInstance)
  73. return addPcName((L2PcInstance)cha);
  74. if (cha instanceof L2Summon)
  75. return addNpcName((L2Summon)cha);
  76. return addString(cha.getName());
  77. }
  78. public ConfirmDlg addPcName(L2PcInstance pc)
  79. {
  80. return addString(pc.getAppearance().getVisibleName());
  81. }
  82. public ConfirmDlg addNpcName(L2Npc npc)
  83. {
  84. return addNpcName(npc.getTemplate());
  85. }
  86. public ConfirmDlg addNpcName(L2Summon npc)
  87. {
  88. return addNpcName(npc.getNpcId());
  89. }
  90. public ConfirmDlg addNpcName(L2NpcTemplate tpl)
  91. {
  92. if (tpl.isCustom())
  93. return addString(tpl.name);
  94. return addNpcName(tpl.npcId);
  95. }
  96. public ConfirmDlg addNpcName(int id)
  97. {
  98. _info.add(new CnfDlgData(TYPE_NPC_NAME, id));
  99. return this;
  100. }
  101. public ConfirmDlg addItemName(L2ItemInstance item)
  102. {
  103. return addItemName(item.getItem().getItemId());
  104. }
  105. public ConfirmDlg addItemName(L2Item item)
  106. {
  107. // TODO: template id for items
  108. return addItemName(item.getItemId());
  109. }
  110. public ConfirmDlg addItemName(int id)
  111. {
  112. _info.add(new CnfDlgData(TYPE_ITEM_NAME, id));
  113. return this;
  114. }
  115. public ConfirmDlg addZoneName(int x, int y, int z)
  116. {
  117. Integer[] coord = {x, y, z};
  118. _info.add(new CnfDlgData(TYPE_ZONE_NAME, coord));
  119. return this;
  120. }
  121. public ConfirmDlg addSkillName(L2Effect effect)
  122. {
  123. return addSkillName(effect.getSkill());
  124. }
  125. public ConfirmDlg addSkillName(L2Skill skill)
  126. {
  127. if (skill.getId() != skill.getDisplayId()) //custom skill - need nameId or smth like this.
  128. return addString(skill.getName());
  129. return addSkillName(skill.getId(), skill.getLevel());
  130. }
  131. public ConfirmDlg addSkillName(int id)
  132. {
  133. return addSkillName(id, 1);
  134. }
  135. public ConfirmDlg addSkillName(int id, int lvl)
  136. {
  137. _info.add(new CnfDlgData(TYPE_SKILL_NAME, id));
  138. _skillLvL = lvl;
  139. return this;
  140. }
  141. public ConfirmDlg addTime(int time)
  142. {
  143. _time = time;
  144. return this;
  145. }
  146. public ConfirmDlg addRequesterId(int id)
  147. {
  148. _requesterId = id;
  149. return this;
  150. }
  151. @Override
  152. protected final void writeImpl()
  153. {
  154. writeC(0xf3);
  155. writeD(_messageId);
  156. if (_info.isEmpty())
  157. {
  158. writeD(0x00);
  159. writeD(_time);
  160. writeD(_requesterId);
  161. }
  162. else
  163. {
  164. writeD(_info.size());
  165. for (CnfDlgData data : _info)
  166. {
  167. writeD(data.type);
  168. switch (data.type)
  169. {
  170. case TYPE_TEXT:
  171. writeS((String)data.value);
  172. break;
  173. case TYPE_NUMBER:
  174. case TYPE_NPC_NAME:
  175. case TYPE_ITEM_NAME:
  176. writeD((Integer)data.value);
  177. break;
  178. case TYPE_SKILL_NAME:
  179. writeD((Integer)data.value); // Skill Id
  180. writeD(_skillLvL); // Skill lvl
  181. break;
  182. case TYPE_ZONE_NAME:
  183. Integer[] array = (Integer[])data.value;
  184. writeD(array[0]);
  185. writeD(array[1]);
  186. writeD(array[2]);
  187. break;
  188. }
  189. }
  190. if (_time != 0)
  191. writeD(_time);
  192. if (_requesterId != 0)
  193. writeD(_requesterId);
  194. }
  195. }
  196. /* (non-Javadoc)
  197. * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
  198. */
  199. @Override
  200. public String getType()
  201. {
  202. return _S__ED_CONFIRMDLG;
  203. }
  204. }