NpcSay.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 java.util.ArrayList;
  17. import java.util.List;
  18. /**
  19. *
  20. * @author Kerberos
  21. */
  22. public final class NpcSay extends L2GameServerPacket
  23. {
  24. // cddddS
  25. private static final String _S__30_NPCSAY = "[S] 30 NpcSay";
  26. private int _objectId;
  27. private int _textType;
  28. private int _npcId;
  29. private String _text;
  30. private int _npcString;
  31. private List<String> _parameters;
  32. /**
  33. * @param _characters
  34. */
  35. public NpcSay(int objectId, int messageType, int npcId, String text)
  36. {
  37. _objectId = objectId;
  38. _textType = messageType;
  39. _npcId = 1000000+npcId;
  40. _text = text;
  41. }
  42. public NpcSay(int objectId, int messageType, int npcId, int npcString)
  43. {
  44. _objectId = objectId;
  45. _textType = messageType;
  46. _npcId = 1000000+npcId;
  47. _npcString = npcString;
  48. }
  49. /**
  50. * String parameter for argument S1,S2,.. in npcstring-e.dat
  51. * @param text
  52. */
  53. public void addStringParameter(String text)
  54. {
  55. if (_parameters == null)
  56. _parameters = new ArrayList<String>();
  57. _parameters.add(text);
  58. }
  59. @Override
  60. protected final void writeImpl()
  61. {
  62. writeC(0x30);
  63. writeD(_objectId);
  64. writeD(_textType);
  65. writeD(_npcId);
  66. writeD(_npcString);
  67. if (_npcString == 0)
  68. writeS(_text);
  69. else
  70. {
  71. if (_parameters != null)
  72. {
  73. for (String s : _parameters)
  74. writeS(s);
  75. }
  76. }
  77. }
  78. /* (non-Javadoc)
  79. * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
  80. */
  81. @Override
  82. public String getType()
  83. {
  84. return _S__30_NPCSAY;
  85. }
  86. }