CreatureSay.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.NpcStringId;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. public final class CreatureSay extends L2GameServerPacket
  26. {
  27. private final int _objectId;
  28. private final int _textType;
  29. private String _charName = null;
  30. private int _charId = 0;
  31. private String _text = null;
  32. private int _npcString = -1;
  33. private List<String> _parameters;
  34. /**
  35. * @param objectId
  36. * @param messageType
  37. * @param charName
  38. * @param text
  39. */
  40. public CreatureSay(int objectId, int messageType, String charName, String text)
  41. {
  42. _objectId = objectId;
  43. _textType = messageType;
  44. _charName = charName;
  45. _text = text;
  46. }
  47. public CreatureSay(int objectId, int messageType, int charId, NpcStringId npcString)
  48. {
  49. _objectId = objectId;
  50. _textType = messageType;
  51. _charId = charId;
  52. _npcString = npcString.getId();
  53. }
  54. public CreatureSay(int objectId, int messageType, String charName, NpcStringId npcString)
  55. {
  56. _objectId = objectId;
  57. _textType = messageType;
  58. _charName = charName;
  59. _npcString = npcString.getId();
  60. }
  61. public CreatureSay(int objectId, int messageType, int charId, SystemMessageId sysString)
  62. {
  63. _objectId = objectId;
  64. _textType = messageType;
  65. _charId = charId;
  66. _npcString = sysString.getId();
  67. }
  68. /**
  69. * String parameter for argument S1,S2,.. in npcstring-e.dat
  70. * @param text
  71. */
  72. public void addStringParameter(String text)
  73. {
  74. if (_parameters == null)
  75. {
  76. _parameters = new ArrayList<>();
  77. }
  78. _parameters.add(text);
  79. }
  80. @Override
  81. protected final void writeImpl()
  82. {
  83. writeC(0x4a);
  84. writeD(_objectId);
  85. writeD(_textType);
  86. if (_charName != null)
  87. {
  88. writeS(_charName);
  89. }
  90. else
  91. {
  92. writeD(_charId);
  93. }
  94. writeD(_npcString); // High Five NPCString ID
  95. if (_text != null)
  96. {
  97. writeS(_text);
  98. }
  99. else if (_parameters != null)
  100. {
  101. for (String s : _parameters)
  102. {
  103. writeS(s);
  104. }
  105. }
  106. }
  107. @Override
  108. public final void runImpl()
  109. {
  110. L2PcInstance _pci = getClient().getActiveChar();
  111. if (_pci != null)
  112. {
  113. _pci.broadcastSnoop(_textType, _charName, _text);
  114. }
  115. }
  116. }