From e58a58f9a3fe3d4b382e60586c6c95a56764b18d Mon Sep 17 00:00:00 2001
From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com>
Date: Sun, 6 Oct 2019 22:46:54 +0000
Subject: [PATCH] Fixed relation related issues, like siege flag not appearing
on players, or nexttarget not working. Contributed by Sahar.
---
.../org/l2jmobius/gameserver/ai/PlayerAI.java | 11 +++
.../gameserver/model/RelationCache.java | 42 +++++++++
.../gameserver/model/actor/Creature.java | 5 +-
.../model/actor/instance/PlayerInstance.java | 91 ++++++++++++-------
.../l2jmobius/gameserver/util/Broadcast.java | 11 ++-
5 files changed, 120 insertions(+), 40 deletions(-)
create mode 100644 L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/RelationCache.java
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/ai/PlayerAI.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/ai/PlayerAI.java
index f97093d702..da87b04fdb 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/ai/PlayerAI.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/ai/PlayerAI.java
@@ -105,6 +105,17 @@ public class PlayerAI extends PlayableAI
super.onEvtReadyToAct();
}
+ @Override
+ protected void onEvtForgetObject(WorldObject object)
+ {
+ if (object.isPlayer())
+ {
+ getActor().getKnownRelations().remove(object.getObjectId());
+ }
+
+ super.onEvtForgetObject(object);
+ }
+
/**
* Launch actions corresponding to the Event Cancel.
* Actions :
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/RelationCache.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/RelationCache.java
new file mode 100644
index 0000000000..a3cd8efbbc
--- /dev/null
+++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/RelationCache.java
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.model;
+
+/**
+ * @author Sahar
+ */
+public final class RelationCache
+{
+ private final int _relation;
+ private final boolean _isAutoAttackable;
+
+ public RelationCache(final int relation, final boolean isAutoAttackable)
+ {
+ _relation = relation;
+ _isAutoAttackable = isAutoAttackable;
+ }
+
+ public int getRelation()
+ {
+ return _relation;
+ }
+
+ public boolean isAutoAttackable()
+ {
+ return _isAutoAttackable;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java
index be4b29ae80..a90fe1e103 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -64,6 +64,7 @@ import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Location;
import org.l2jmobius.gameserver.model.Party;
import org.l2jmobius.gameserver.model.PlayerCondOverride;
+import org.l2jmobius.gameserver.model.RelationCache;
import org.l2jmobius.gameserver.model.Spawn;
import org.l2jmobius.gameserver.model.TeleportWhereType;
import org.l2jmobius.gameserver.model.TimeStamp;
@@ -277,7 +278,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
protected Future> _skillCast;
protected Future> _skillCast2;
- private final Map _knownRelations = new ConcurrentHashMap<>();
+ private final Map _knownRelations = new ConcurrentHashMap<>();
/** A list containing the dropped items of this fake player. */
private final List _fakePlayerDrops = new CopyOnWriteArrayList<>();
@@ -6736,7 +6737,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return 0;
}
- public Map getKnownRelations()
+ public Map getKnownRelations()
{
return _knownRelations;
}
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 37631a1225..1a06131a4c 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -132,6 +132,7 @@ import org.l2jmobius.gameserver.model.PlayerCondOverride;
import org.l2jmobius.gameserver.model.PremiumItem;
import org.l2jmobius.gameserver.model.Radar;
import org.l2jmobius.gameserver.model.RecipeList;
+import org.l2jmobius.gameserver.model.RelationCache;
import org.l2jmobius.gameserver.model.Request;
import org.l2jmobius.gameserver.model.ShortCuts;
import org.l2jmobius.gameserver.model.Shortcut;
@@ -4141,15 +4142,16 @@ public class PlayerInstance extends Playable
if (mov instanceof CharInfo)
{
final int relation = getRelation(player);
- Integer oldrelation = getKnownRelations().get(player.getObjectId());
- if ((oldrelation != null) && (oldrelation != relation))
+ final boolean isAutoAttackable = isAutoAttackable(player);
+ final RelationCache cache = getKnownRelations().get(player.getObjectId());
+ if ((cache == null) || (cache.getRelation() != relation) || (cache.isAutoAttackable() != isAutoAttackable))
{
- player.sendPacket(new RelationChanged(this, relation, isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(this, relation, isAutoAttackable));
if (hasSummon())
{
- player.sendPacket(new RelationChanged(_summon, relation, isAutoAttackable(player)));
- // getKnownRelations().put(player.getObjectId(), relation);
+ player.sendPacket(new RelationChanged(_summon, relation, isAutoAttackable));
}
+ getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
}
}
});
@@ -4174,15 +4176,16 @@ public class PlayerInstance extends Playable
if (mov instanceof CharInfo)
{
final int relation = getRelation(player);
- final Integer oldrelation = getKnownRelations().get(player.getObjectId());
- if ((oldrelation != null) && (oldrelation != relation))
+ final boolean isAutoAttackable = isAutoAttackable(player);
+ final RelationCache cache = getKnownRelations().get(player.getObjectId());
+ if ((cache == null) || (cache.getRelation() != relation) || (cache.isAutoAttackable() != isAutoAttackable))
{
- player.sendPacket(new RelationChanged(this, relation, isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(this, relation, isAutoAttackable));
if (hasSummon())
{
- player.sendPacket(new RelationChanged(_summon, relation, isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(_summon, relation, isAutoAttackable));
}
- getKnownRelations().put(player.getObjectId(), relation);
+ getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
}
}
});
@@ -13198,26 +13201,33 @@ public class PlayerInstance extends Playable
player.sendPacket(new CharInfo(this, isInvisible() && player.canOverrideCond(PlayerCondOverride.SEE_ALL_PLAYERS)));
player.sendPacket(new ExBrExtraUserInfo(this));
+
final int relation1 = getRelation(player);
final int relation2 = player.getRelation(this);
- Integer oldrelation = getKnownRelations().get(player.getObjectId());
- if ((oldrelation != null) && (oldrelation != relation1))
+ final boolean isAutoAttackable1 = isAutoAttackable(player);
+ final boolean isAutoAttackable2 = player.isAutoAttackable(this);
+ RelationCache cache = getKnownRelations().get(player.getObjectId());
+ if ((cache == null) || (cache.getRelation() != relation1) || (cache.isAutoAttackable() != isAutoAttackable1))
{
- player.sendPacket(new RelationChanged(this, relation1, isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(this, relation1, isAutoAttackable1));
if (hasSummon())
{
- player.sendPacket(new RelationChanged(_summon, relation1, isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(_summon, relation1, isAutoAttackable1));
}
+ getKnownRelations().put(player.getObjectId(), new RelationCache(relation1, isAutoAttackable1));
}
- oldrelation = player.getKnownRelations().get(getObjectId());
- if ((oldrelation != null) && (oldrelation != relation2))
+
+ cache = player.getKnownRelations().get(getObjectId());
+ if ((cache == null) || (cache.getRelation() != relation2) || (cache.isAutoAttackable() != isAutoAttackable2))
{
- sendPacket(new RelationChanged(player, relation2, player.isAutoAttackable(this)));
+ sendPacket(new RelationChanged(player, relation2, isAutoAttackable2));
if (player.hasSummon())
{
- sendPacket(new RelationChanged(player.getSummon(), relation2, player.isAutoAttackable(this)));
+ sendPacket(new RelationChanged(player.getSummon(), relation2, isAutoAttackable2));
}
+ player.getKnownRelations().put(getObjectId(), new RelationCache(relation2, isAutoAttackable2));
}
+
player.sendPacket(new GetOnVehicle(getObjectId(), getBoat().getObjectId(), _inVehiclePosition));
}
else if (isInAirShip())
@@ -13225,51 +13235,64 @@ public class PlayerInstance extends Playable
setXYZ(getAirShip().getLocation());
player.sendPacket(new CharInfo(this, isInvisible() && player.canOverrideCond(PlayerCondOverride.SEE_ALL_PLAYERS)));
player.sendPacket(new ExBrExtraUserInfo(this));
+
final int relation1 = getRelation(player);
final int relation2 = player.getRelation(this);
- Integer oldrelation = getKnownRelations().get(player.getObjectId());
- if ((oldrelation != null) && (oldrelation != relation1))
+ final boolean isAutoAttackable1 = isAutoAttackable(player);
+ final boolean isAutoAttackable2 = player.isAutoAttackable(this);
+ RelationCache cache = getKnownRelations().get(player.getObjectId());
+ if ((cache == null) || (cache.getRelation() != relation1) || (cache.isAutoAttackable() != isAutoAttackable1))
{
- player.sendPacket(new RelationChanged(this, relation1, isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(this, relation1, isAutoAttackable1));
if (hasSummon())
{
- player.sendPacket(new RelationChanged(_summon, relation1, isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(_summon, relation1, isAutoAttackable1));
}
+ getKnownRelations().put(player.getObjectId(), new RelationCache(relation1, isAutoAttackable1));
}
- oldrelation = player.getKnownRelations().get(getObjectId());
- if ((oldrelation != null) && (oldrelation != relation2))
+
+ cache = player.getKnownRelations().get(getObjectId());
+ if ((cache == null) || (cache.getRelation() != relation2) || (cache.isAutoAttackable() != isAutoAttackable2))
{
- sendPacket(new RelationChanged(player, relation2, player.isAutoAttackable(this)));
+ sendPacket(new RelationChanged(player, relation2, isAutoAttackable2));
if (player.hasSummon())
{
- sendPacket(new RelationChanged(player.getSummon(), relation2, player.isAutoAttackable(this)));
+ sendPacket(new RelationChanged(player.getSummon(), relation2, isAutoAttackable2));
}
+ player.getKnownRelations().put(getObjectId(), new RelationCache(relation2, isAutoAttackable2));
}
+
player.sendPacket(new ExGetOnAirShip(this, getAirShip()));
}
else
{
player.sendPacket(new CharInfo(this, isInvisible() && player.canOverrideCond(PlayerCondOverride.SEE_ALL_PLAYERS)));
player.sendPacket(new ExBrExtraUserInfo(this));
+
final int relation1 = getRelation(player);
final int relation2 = player.getRelation(this);
- Integer oldrelation = getKnownRelations().get(player.getObjectId());
- if ((oldrelation != null) && (oldrelation != relation1))
+ final boolean isAutoAttackable1 = isAutoAttackable(player);
+ final boolean isAutoAttackable2 = player.isAutoAttackable(this);
+ RelationCache cache = getKnownRelations().get(player.getObjectId());
+ if ((cache == null) || (cache.getRelation() != relation1) || (cache.isAutoAttackable() != isAutoAttackable1))
{
- player.sendPacket(new RelationChanged(this, relation1, isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(this, relation1, isAutoAttackable1));
if (hasSummon())
{
- player.sendPacket(new RelationChanged(_summon, relation1, isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(_summon, relation1, isAutoAttackable1));
}
+ getKnownRelations().put(player.getObjectId(), new RelationCache(relation1, isAutoAttackable1));
}
- oldrelation = player.getKnownRelations().get(getObjectId());
- if ((oldrelation != null) && (oldrelation != relation2))
+
+ cache = player.getKnownRelations().get(getObjectId());
+ if ((cache == null) || (cache.getRelation() != relation2) || (cache.isAutoAttackable() != isAutoAttackable2))
{
- sendPacket(new RelationChanged(player, relation2, player.isAutoAttackable(this)));
+ sendPacket(new RelationChanged(player, relation2, isAutoAttackable2));
if (player.hasSummon())
{
- sendPacket(new RelationChanged(player.getSummon(), relation2, player.isAutoAttackable(this)));
+ sendPacket(new RelationChanged(player.getSummon(), relation2, isAutoAttackable2));
}
+ player.getKnownRelations().put(getObjectId(), new RelationCache(relation2, isAutoAttackable2));
}
}
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/util/Broadcast.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/util/Broadcast.java
index 0c64cd2f38..b7c46fc440 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/util/Broadcast.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/gameserver/util/Broadcast.java
@@ -20,6 +20,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.enums.ChatType;
+import org.l2jmobius.gameserver.model.RelationCache;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
@@ -75,14 +76,16 @@ public class Broadcast
if ((mov instanceof CharInfo) && creature.isPlayer())
{
final int relation = ((PlayerInstance) creature).getRelation(player);
- final Integer oldrelation = creature.getKnownRelations().get(player.getObjectId());
- if ((oldrelation != null) && (oldrelation != relation))
+ final boolean isAutoAttackable = creature.isAutoAttackable(player);
+ final RelationCache cache = creature.getKnownRelations().get(player.getObjectId());
+ if ((cache == null) || (cache.getRelation() != relation) || (cache.isAutoAttackable() != isAutoAttackable))
{
- player.sendPacket(new RelationChanged((PlayerInstance) creature, relation, creature.isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged((PlayerInstance) creature, relation, isAutoAttackable));
if (creature.hasSummon())
{
- player.sendPacket(new RelationChanged(creature.getSummon(), relation, creature.isAutoAttackable(player)));
+ player.sendPacket(new RelationChanged(creature.getSummon(), relation, isAutoAttackable));
}
+ creature.getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
}
}
}