RelationChanged.java 3.9 KB

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