2
0

RelationChanged.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.List;
  17. import javolution.util.FastList;
  18. import com.l2jserver.gameserver.model.actor.L2Playable;
  19. /**
  20. *
  21. * @author Luca Baldi
  22. */
  23. public final class RelationChanged extends L2GameServerPacket
  24. {
  25. public static final int RELATION_PARTY1 = 0x00001; // party member
  26. public static final int RELATION_PARTY2 = 0x00002; // party member
  27. public static final int RELATION_PARTY3 = 0x00004; // party member
  28. public static final int RELATION_PARTY4 = 0x00008; // party member (for information, see L2PcInstance.getRelation())
  29. public static final int RELATION_PARTYLEADER = 0x00010; // true if is party leader
  30. public static final int RELATION_HAS_PARTY = 0x00020; // true if is in party
  31. public static final int RELATION_CLAN_MEMBER = 0x00040; // true if is in clan
  32. public static final int RELATION_LEADER = 0x00080; // true if is clan leader
  33. public static final int RELATION_CLAN_MATE = 0x00100; // true if is in same clan
  34. public static final int RELATION_INSIEGE = 0x00200; // true if in siege
  35. public static final int RELATION_ATTACKER = 0x00400; // true when attacker
  36. public static final int RELATION_ALLY = 0x00800; // blue siege icon, cannot have if red
  37. public static final int RELATION_ENEMY = 0x01000; // true when red icon, doesn't matter with blue
  38. public static final int RELATION_MUTUAL_WAR = 0x04000; // double fist
  39. public static final int RELATION_1SIDED_WAR = 0x08000; // single fist
  40. public static final int RELATION_ALLY_MEMBER = 0x10000; // clan is in alliance
  41. public static final int RELATION_TERRITORY_WAR= 0x80000; // show Territory War icon
  42. private static final String _S__CE_RELATIONCHANGED = "[S] CE RelationChanged";
  43. private static class Relation
  44. {
  45. int _objId, _relation, _autoAttackable, _karma, _pvpFlag;
  46. }
  47. private Relation _singled;
  48. private List<Relation> _multi;
  49. public RelationChanged(L2Playable activeChar, int relation, boolean autoattackable)
  50. {
  51. _singled = new Relation();
  52. _singled._objId = activeChar.getObjectId();
  53. _singled._relation = relation;
  54. _singled._autoAttackable = autoattackable ? 1 : 0;
  55. _singled._karma = activeChar.getKarma();
  56. _singled._pvpFlag = activeChar.getPvpFlag();
  57. _invisible = activeChar.getActingPlayer().getAppearance().getInvisible();
  58. }
  59. public RelationChanged()
  60. {
  61. _multi = FastList.newInstance();
  62. }
  63. public void addRelation(L2Playable activeChar, int relation, boolean autoattackable)
  64. {
  65. if (activeChar.getActingPlayer().getAppearance().getInvisible())
  66. throw new IllegalArgumentException("Cannot add insivisble character to multi relation packet");
  67. Relation r = new Relation();
  68. r._objId = activeChar.getObjectId();
  69. r._relation = relation;
  70. r._autoAttackable = autoattackable ? 1 : 0;
  71. r._karma = activeChar.getKarma();
  72. r._pvpFlag = activeChar.getPvpFlag();
  73. _multi.add(r);
  74. }
  75. /**
  76. * @see com.l2jserver.util.network.BaseSendablePacket.ServerBasePacket#writeImpl()
  77. */
  78. @Override
  79. protected final void writeImpl()
  80. {
  81. writeC(0xce);
  82. if (_multi == null)
  83. {
  84. writeD(1);
  85. writeRelation(_singled);
  86. }
  87. else
  88. {
  89. writeD(_multi.size());
  90. for (Relation r : _multi)
  91. writeRelation(r);
  92. FastList.recycle((FastList<?>) _multi);
  93. }
  94. }
  95. private void writeRelation(Relation relation)
  96. {
  97. writeD(relation._objId);
  98. writeD(relation._relation);
  99. writeD(relation._autoAttackable);
  100. writeD(relation._karma);
  101. writeD(relation._pvpFlag);
  102. }
  103. /**
  104. * @see com.l2jserver.gameserver.BasePacket#getType()
  105. */
  106. @Override
  107. public String getType()
  108. {
  109. return _S__CE_RELATIONCHANGED;
  110. }
  111. }