Fixed next target not working sometimes.

Contributed by Sahar.
This commit is contained in:
MobiusDevelopment
2021-03-07 14:11:32 +00:00
parent 81926a9acb
commit dfa85564ad
95 changed files with 1710 additions and 722 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.cache;
/**
* @author Sahar
*/
public final class RelationCache
{
private final int _relation;
private final boolean _isAutoAttackable;
public RelationCache(int relation, boolean isAutoAttackable)
{
_relation = relation;
_isAutoAttackable = isAutoAttackable;
}
public int getRelation()
{
return _relation;
}
public boolean isAutoAttackable()
{
return _isAutoAttackable;
}
}

View File

@@ -49,6 +49,7 @@ import org.l2jmobius.gameserver.ai.AttackableAI;
import org.l2jmobius.gameserver.ai.CreatureAI;
import org.l2jmobius.gameserver.ai.CtrlEvent;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.cache.RelationCache;
import org.l2jmobius.gameserver.data.xml.CategoryData;
import org.l2jmobius.gameserver.data.xml.SkillData;
import org.l2jmobius.gameserver.data.xml.TransformData;
@@ -268,7 +269,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final AtomicInteger _abnormalShieldBlocks = new AtomicInteger();
private final Map<Integer, Integer> _knownRelations = new ConcurrentHashMap<>();
private final Map<Integer, RelationCache> _knownRelations = new ConcurrentHashMap<>();
private CreatureContainer _seenCreatures;
@@ -5281,7 +5282,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
super.setXYZ(newX, newY, newZ);
}
public Map<Integer, Integer> getKnownRelations()
public Map<Integer, RelationCache> getKnownRelations()
{
return _knownRelations;
}

View File

@@ -57,6 +57,7 @@ import org.l2jmobius.gameserver.ai.CreatureAI.IntentionCommand;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.ai.PlayerAI;
import org.l2jmobius.gameserver.ai.SummonAI;
import org.l2jmobius.gameserver.cache.RelationCache;
import org.l2jmobius.gameserver.cache.WarehouseCacheManager;
import org.l2jmobius.gameserver.communitybbs.BB.Forum;
import org.l2jmobius.gameserver.communitybbs.Manager.ForumsBBSManager;
@@ -1769,25 +1770,26 @@ public class PlayerInstance extends Playable
}
final int relation = getRelation(player);
final Integer oldrelation = getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation != relation))
final boolean isAutoAttackable = isAutoAttackable(player);
final RelationCache oldrelation = getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation.getRelation() != relation) || (oldrelation.isAutoAttackable() != isAutoAttackable))
{
final RelationChanged rc = new RelationChanged();
rc.addRelation(this, relation, isAutoAttackable(player));
rc.addRelation(this, relation, isAutoAttackable);
if (hasSummon())
{
final Summon pet = _pet;
if (pet != null)
{
rc.addRelation(pet, relation, isAutoAttackable(player));
rc.addRelation(pet, relation, isAutoAttackable);
}
if (hasServitors())
{
getServitors().values().forEach(s -> rc.addRelation(s, relation, isAutoAttackable(player)));
getServitors().values().forEach(s -> rc.addRelation(s, relation, isAutoAttackable));
}
}
player.sendPacket(rc);
getKnownRelations().put(player.getObjectId(), relation);
getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
}
});
}
@@ -4072,25 +4074,26 @@ public class PlayerInstance extends Playable
// Update relation.
final int relation = getRelation(player);
final Integer oldrelation = getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation != relation))
final boolean isAutoAttackable = isAutoAttackable(player);
final RelationCache oldrelation = getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation.getRelation() != relation) || (oldrelation.isAutoAttackable() != isAutoAttackable))
{
final RelationChanged rc = new RelationChanged();
rc.addRelation(this, relation, !isInsideZone(ZoneId.PEACE));
rc.addRelation(this, relation, isAutoAttackable);
if (hasSummon())
{
final Summon pet = getPet();
if (pet != null)
{
rc.addRelation(pet, relation, !isInsideZone(ZoneId.PEACE));
rc.addRelation(pet, relation, isAutoAttackable);
}
if (hasServitors())
{
getServitors().values().forEach(s -> rc.addRelation(s, relation, !isInsideZone(ZoneId.PEACE)));
getServitors().values().forEach(s -> rc.addRelation(s, relation, isAutoAttackable));
}
}
player.sendPacket(rc);
getKnownRelations().put(player.getObjectId(), relation);
getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
}
}
});
@@ -6311,24 +6314,25 @@ public class PlayerInstance extends Playable
}
final int relation = getRelation(player);
final Integer oldrelation = getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation != relation))
final boolean isAutoAttackable = isAutoAttackable(player);
final RelationCache oldrelation = getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation.getRelation() != relation) || (oldrelation.isAutoAttackable() != isAutoAttackable))
{
final RelationChanged rc = new RelationChanged();
rc.addRelation(this, relation, !isInsideZone(ZoneId.PEACE));
rc.addRelation(this, relation, isAutoAttackable);
if (hasSummon())
{
if (_pet != null)
{
rc.addRelation(_pet, relation, !isInsideZone(ZoneId.PEACE));
rc.addRelation(_pet, relation, isAutoAttackable);
}
if (hasServitors())
{
getServitors().values().forEach(s -> rc.addRelation(s, relation, !isInsideZone(ZoneId.PEACE)));
getServitors().values().forEach(s -> rc.addRelation(s, relation, isAutoAttackable));
}
}
player.sendPacket(rc);
getKnownRelations().put(player.getObjectId(), relation);
getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
}
});
}

View File

@@ -35,6 +35,7 @@ import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.gameserver.cache.RelationCache;
import org.l2jmobius.gameserver.data.sql.ClanTable;
import org.l2jmobius.gameserver.data.xml.SiegeScheduleData;
import org.l2jmobius.gameserver.enums.SiegeClanType;
@@ -594,25 +595,26 @@ public class Siege implements Siegable
}
final int relation = member.getRelation(player);
final Integer oldrelation = member.getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation != relation))
final boolean isAutoAttackable = member.isAutoAttackable(player);
final RelationCache oldrelation = member.getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation.getRelation() != relation) || (oldrelation.isAutoAttackable() != isAutoAttackable))
{
final RelationChanged rc = new RelationChanged();
rc.addRelation(member, relation, member.isAutoAttackable(player));
rc.addRelation(member, relation, isAutoAttackable);
if (member.hasSummon())
{
final Summon pet = member.getPet();
if (pet != null)
{
rc.addRelation(pet, relation, member.isAutoAttackable(player));
rc.addRelation(pet, relation, isAutoAttackable);
}
if (member.hasServitors())
{
member.getServitors().values().forEach(s -> rc.addRelation(s, relation, member.isAutoAttackable(player)));
member.getServitors().values().forEach(s -> rc.addRelation(s, relation, isAutoAttackable));
}
}
player.sendPacket(rc);
member.getKnownRelations().put(player.getObjectId(), relation);
member.getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
}
});
}
@@ -653,25 +655,26 @@ public class Siege implements Siegable
}
final int relation = member.getRelation(player);
final Integer oldrelation = member.getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation != relation))
final boolean isAutoAttackable = member.isAutoAttackable(player);
final RelationCache oldrelation = member.getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation.getRelation() != relation) || (oldrelation.isAutoAttackable() != isAutoAttackable))
{
final RelationChanged rc = new RelationChanged();
rc.addRelation(member, relation, member.isAutoAttackable(player));
rc.addRelation(member, relation, isAutoAttackable);
if (member.hasSummon())
{
final Summon pet = member.getPet();
if (pet != null)
{
rc.addRelation(pet, relation, member.isAutoAttackable(player));
rc.addRelation(pet, relation, isAutoAttackable);
}
if (member.hasServitors())
{
member.getServitors().values().forEach(s -> rc.addRelation(s, relation, member.isAutoAttackable(player)));
member.getServitors().values().forEach(s -> rc.addRelation(s, relation, isAutoAttackable));
}
}
player.sendPacket(rc);
member.getKnownRelations().put(player.getObjectId(), relation);
member.getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
}
});
}

View File

@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.util;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.gameserver.cache.RelationCache;
import org.l2jmobius.gameserver.enums.ChatType;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.World;
@@ -82,25 +83,26 @@ 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 oldrelation = creature.getKnownRelations().get(player.getObjectId());
if ((oldrelation == null) || (oldrelation.getRelation() != relation) || (oldrelation.isAutoAttackable() != isAutoAttackable))
{
final RelationChanged rc = new RelationChanged();
rc.addRelation((PlayerInstance) creature, relation, creature.isAutoAttackable(player));
rc.addRelation((PlayerInstance) creature, relation, isAutoAttackable);
if (creature.hasSummon())
{
final Summon pet = creature.getPet();
if (pet != null)
{
rc.addRelation(pet, relation, creature.isAutoAttackable(player));
rc.addRelation(pet, relation, isAutoAttackable);
}
if (creature.hasServitors())
{
creature.getServitors().values().forEach(s -> rc.addRelation(s, relation, creature.isAutoAttackable(player)));
creature.getServitors().values().forEach(s -> rc.addRelation(s, relation, isAutoAttackable));
}
}
player.sendPacket(rc);
creature.getKnownRelations().put(player.getObjectId(), relation);
creature.getKnownRelations().put(player.getObjectId(), new RelationCache(relation, isAutoAttackable));
}
}
}