ExShowScreenMessage.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.serverpackets;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import com.l2jserver.gameserver.network.NpcStringId;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. /**
  25. * ExShowScreenMessage server packet implementation.
  26. * @author Kerberos
  27. */
  28. public class ExShowScreenMessage extends L2GameServerPacket
  29. {
  30. private final int _type;
  31. private final int _sysMessageId;
  32. private final int _unk1;
  33. private final int _unk2;
  34. private final int _unk3;
  35. private final boolean _fade;
  36. private final int _size;
  37. private final int _position;
  38. private final boolean _effect;
  39. private final String _text;
  40. private final int _time;
  41. private final int _npcString;
  42. private List<String> _parameters = null;
  43. // Positions
  44. public static final byte TOP_LEFT = 0x01;
  45. public static final byte TOP_CENTER = 0x02;
  46. public static final byte TOP_RIGHT = 0x03;
  47. public static final byte MIDDLE_LEFT = 0x04;
  48. public static final byte MIDDLE_CENTER = 0x05;
  49. public static final byte MIDDLE_RIGHT = 0x06;
  50. public static final byte BOTTOM_CENTER = 0x07;
  51. public static final byte BOTTOM_RIGHT = 0x08;
  52. /**
  53. * Display a String on the screen for a given time.
  54. * @param text the text to display
  55. * @param time the display time
  56. */
  57. public ExShowScreenMessage(String text, int time)
  58. {
  59. _type = 2;
  60. _sysMessageId = -1;
  61. _unk1 = 0;
  62. _unk2 = 0;
  63. _unk3 = 0;
  64. _fade = false;
  65. _position = TOP_CENTER;
  66. _text = text;
  67. _time = time;
  68. _size = 0;
  69. _effect = false;
  70. _npcString = -1;
  71. }
  72. /**
  73. * Display a NPC String on the screen for a given position and time.
  74. * @param npcString the NPC String Id
  75. * @param position the position on the screen
  76. * @param time the display time
  77. * @param params the String parameters
  78. */
  79. public ExShowScreenMessage(NpcStringId npcString, int position, int time, String... params)
  80. {
  81. _type = 2;
  82. _sysMessageId = -1;
  83. _unk1 = 0x00;
  84. _unk2 = 0x00;
  85. _unk3 = 0x00;
  86. _fade = false;
  87. _position = position;
  88. _text = null;
  89. _time = time;
  90. _size = 0x00;
  91. _effect = false;
  92. _npcString = npcString.getId();
  93. if (params != null)
  94. {
  95. addStringParameter(params);
  96. }
  97. }
  98. /**
  99. * Display a System Message on the screen for a given position and time.
  100. * @param systemMsg the System Message Id
  101. * @param position the position on the screen
  102. * @param time the display time
  103. * @param params the String parameters
  104. */
  105. public ExShowScreenMessage(SystemMessageId systemMsg, int position, int time, String... params)
  106. {
  107. _type = 2;
  108. _sysMessageId = systemMsg.getId();
  109. _unk1 = 0x00;
  110. _unk2 = 0x00;
  111. _unk3 = 0x00;
  112. _fade = false;
  113. _position = position;
  114. _text = null;
  115. _time = time;
  116. _size = 0x00;
  117. _effect = false;
  118. _npcString = -1;
  119. if (params != null)
  120. {
  121. addStringParameter(params);
  122. }
  123. }
  124. /**
  125. * Display a Text, System Message or a NPC String on the screen for the given parameters.
  126. * @param type 0 - System Message, 1 - Text, 2 - NPC String
  127. * @param messageId the System Message Id
  128. * @param position the position on the screen
  129. * @param unk1
  130. * @param size the font size 0 - normal, 1 - small
  131. * @param unk2
  132. * @param unk3
  133. * @param showEffect upper effect (0 - disabled, 1 enabled) - _position must be 2 (center) otherwise no effect
  134. * @param time the display time
  135. * @param fade the fade effect (0 - disabled, 1 enabled)
  136. * @param text the text to display
  137. * @param npcString
  138. * @param params the String parameters
  139. */
  140. public ExShowScreenMessage(int type, int messageId, int position, int unk1, int size, int unk2, int unk3, boolean showEffect, int time, boolean fade, String text, NpcStringId npcString, String params)
  141. {
  142. _type = type;
  143. _sysMessageId = messageId;
  144. _unk1 = unk1;
  145. _unk2 = unk2;
  146. _unk3 = unk3;
  147. _fade = fade;
  148. _position = position;
  149. _text = text;
  150. _time = time;
  151. _size = size;
  152. _effect = showEffect;
  153. _npcString = npcString.getId();
  154. }
  155. /**
  156. * String parameter for argument S1,S2,.. in npcstring-e.dat
  157. * @param params the parameter
  158. */
  159. public void addStringParameter(String... params)
  160. {
  161. if (_parameters == null)
  162. {
  163. _parameters = new ArrayList<>();
  164. }
  165. for (String param : params)
  166. {
  167. _parameters.add(param);
  168. }
  169. }
  170. @Override
  171. protected void writeImpl()
  172. {
  173. writeC(0xFE);
  174. writeH(0x39);
  175. writeD(_type);
  176. writeD(_sysMessageId);
  177. writeD(_position);
  178. writeD(_unk1);
  179. writeD(_size);
  180. writeD(_unk2);
  181. writeD(_unk3);
  182. writeD(_effect ? 0x01 : 0x00);
  183. writeD(_time);
  184. writeD(_fade ? 0x01 : 0x00);
  185. writeD(_npcString);
  186. if (_npcString == -1)
  187. {
  188. writeS(_text);
  189. }
  190. else
  191. {
  192. if (_parameters != null)
  193. {
  194. for (String s : _parameters)
  195. {
  196. writeS(s);
  197. }
  198. }
  199. }
  200. }
  201. }