ConfirmDlg.java 5.7 KB

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