Proper updating for ZoneManager.

This commit is contained in:
MobiusDev 2018-04-09 15:44:59 +00:00
parent b1fc2fa47d
commit 5fd99e5454
15 changed files with 63 additions and 340 deletions

View File

@ -395,10 +395,10 @@ public class HallOfSufferingAttack extends AbstractNpcAI
// Notify L2Character AI
boss.getAI().notifyEvent(CtrlEvent.EVT_DEAD);
if (boss.getWorldRegion() != null)
{
boss.getWorldRegion().onDeath(boss);
}
// if (boss.getWorldRegion() != null)
// {
// boss.getWorldRegion().onDeath(boss);
// }
}
@Override

View File

@ -395,10 +395,10 @@ public class HallOfSufferingDefence extends AbstractNpcAI
// Notify L2Character AI
boss.getAI().notifyEvent(CtrlEvent.EVT_DEAD);
if (boss.getWorldRegion() != null)
{
boss.getWorldRegion().onDeath(boss);
}
// if (boss.getWorldRegion() != null)
// {
// boss.getWorldRegion().onDeath(boss);
// }
}
@Override

View File

@ -150,6 +150,16 @@ public final class GameServer
private static GameServer INSTANCE;
public static final Calendar dateTimeServerStarted = Calendar.getInstance();
public long getUsedMemoryMB()
{
return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1048576;
}
public DeadLockDetector getDeadLockDetectorThread()
{
return _deadDetectThread;
}
public GameServer() throws Exception
{
final long serverLoadStart = System.currentTimeMillis();
@ -452,16 +462,6 @@ public final class GameServer
INSTANCE = new GameServer();
}
public long getUsedMemoryMB()
{
return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1048576;
}
public DeadLockDetector getDeadLockDetectorThread()
{
return _deadDetectThread;
}
public static void printSection(String s)
{
s = "=[ " + s + " ]";

View File

@ -33,6 +33,7 @@ import org.xml.sax.SAXException;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.InstanceListManager;
import com.l2jmobius.gameserver.instancemanager.CastleManager;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.actor.instance.L2MerchantInstance;
import com.l2jmobius.gameserver.model.entity.Castle;
@ -58,7 +59,7 @@ public class MerchantPriceConfigTable implements InstanceListManager
{
for (MerchantPriceConfig mpc : _mpcs.values())
{
if ((npc.getWorldRegion() != null) && npc.getWorldRegion().containsZone(mpc.getZoneId()))
if (ZoneManager.getInstance().getRegion(npc).getZones().containsKey(mpc.getZoneId()))
{
return mpc;
}

View File

@ -459,22 +459,6 @@ public final class ZoneManager implements IGameXmlReader
}
}
/**
* Returns all zones registered with the ZoneManager. To minimize iteration processing retrieve zones from L2WorldRegion for a specific location instead.
* @return zones
* @see #getAllZones(Class)
*/
// @Deprecated
// public Collection<L2ZoneType> getAllZones()
// {
// final List<L2ZoneType> zones = new ArrayList<>();
// for (Map<Integer, ? extends L2ZoneType> map : _classZones.values())
// {
// zones.addAll(map.values());
// }
// return zones;
// }
/**
* Return all zones by class type.
* @param <T> the generic type

View File

@ -16,9 +16,7 @@
*/
package com.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
@ -29,12 +27,8 @@ import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.gameserver.datatables.SpawnTable;
import com.l2jmobius.gameserver.model.actor.L2Attackable;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Npc;
import com.l2jmobius.gameserver.model.actor.L2Vehicle;
import com.l2jmobius.gameserver.model.skills.Skill;
import com.l2jmobius.gameserver.model.zone.L2ZoneType;
import com.l2jmobius.gameserver.model.zone.type.L2PeaceZone;
public final class L2WorldRegion
{
@ -47,7 +41,6 @@ public final class L2WorldRegion
private final int _regionZ;
private boolean _active = false;
private ScheduledFuture<?> _neighborsTask = null;
private final List<L2ZoneType> _zones;
public L2WorldRegion(int regionX, int regionY, int regionZ)
{
@ -57,104 +50,6 @@ public final class L2WorldRegion
// default a newly initialized region to inactive, unless always on is specified
_active = Config.GRIDS_ALWAYS_ON;
_zones = new ArrayList<>();
}
public List<L2ZoneType> getZones()
{
return _zones;
}
public void addZone(L2ZoneType zone)
{
_zones.add(zone);
}
public void removeZone(L2ZoneType zone)
{
_zones.remove(zone);
}
public void revalidateZones(L2Character character)
{
// do NOT update the world region while the character is still in the process of teleporting
// Once the teleport is COMPLETED, revalidation occurs safely, at that time.
if (character.isTeleporting())
{
return;
}
for (L2ZoneType z : getZones())
{
if (z != null)
{
z.revalidateInZone(character);
}
}
}
public void removeFromZones(L2Character character)
{
for (L2ZoneType z : getZones())
{
if (z != null)
{
z.removeCharacter(character);
}
}
}
public boolean containsZone(int zoneId)
{
for (L2ZoneType z : getZones())
{
if (z.getId() == zoneId)
{
return true;
}
}
return false;
}
public boolean checkEffectRangeInsidePeaceZone(Skill skill, int x, int y, int z)
{
final int range = skill.getEffectRange();
final int up = y + range;
final int down = y - range;
final int left = x + range;
final int right = x - range;
for (L2ZoneType e : getZones())
{
if ((e instanceof L2PeaceZone) && (e.isInsideZone(x, up, z) || e.isInsideZone(x, down, z) || e.isInsideZone(left, y, z) || e.isInsideZone(right, y, z) || e.isInsideZone(x, y, z)))
{
return false;
}
}
return true;
}
public void onDeath(L2Character character)
{
for (L2ZoneType z : getZones())
{
if (z != null)
{
z.onDieInside(character);
}
}
}
public void onRevive(L2Character character)
{
for (L2ZoneType z : getZones())
{
if (z != null)
{
z.onReviveInside(character);
}
}
}
/** Task of AI notification */

View File

@ -55,6 +55,7 @@ import com.l2jmobius.gameserver.idfactory.IdFactory;
import com.l2jmobius.gameserver.instancemanager.InstanceManager;
import com.l2jmobius.gameserver.instancemanager.MapRegionManager;
import com.l2jmobius.gameserver.instancemanager.TerritoryWarManager;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.CharEffectList;
import com.l2jmobius.gameserver.model.L2AccessLevel;
import com.l2jmobius.gameserver.model.L2Clan;
@ -123,6 +124,7 @@ import com.l2jmobius.gameserver.model.stats.Formulas;
import com.l2jmobius.gameserver.model.stats.Stats;
import com.l2jmobius.gameserver.model.stats.functions.AbstractFunction;
import com.l2jmobius.gameserver.model.zone.ZoneId;
import com.l2jmobius.gameserver.model.zone.ZoneRegion;
import com.l2jmobius.gameserver.network.Disconnection;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.AbstractNpcInfo;
@ -481,13 +483,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
*/
public void onDecay()
{
final L2WorldRegion reg = getWorldRegion();
if (reg != null)
{
reg.removeFromZones(this);
}
decayMe(); // Sets world region to null
decayMe();
ZoneManager.getInstance().getRegion(this).removeFromZones(this);
}
@Override
@ -1989,21 +1986,17 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
// prevent casting signets to peace zone
if (skill.isChanneling() && (skill.getChannelingSkillId() > 0))
{
final L2WorldRegion region = getWorldRegion();
if (region == null)
{
return false;
}
final ZoneRegion zoneRegion = ZoneManager.getInstance().getRegion(this);
boolean canCast = true;
if ((skill.getTargetType() == L2TargetType.GROUND) && isPlayer())
{
final Location wp = getActingPlayer().getCurrentSkillWorldPosition();
if (!region.checkEffectRangeInsidePeaceZone(skill, wp.getX(), wp.getY(), wp.getZ()))
Location wp = getActingPlayer().getCurrentSkillWorldPosition();
if (!zoneRegion.checkEffectRangeInsidePeaceZone(skill, wp.getX(), wp.getY(), wp.getZ()))
{
canCast = false;
}
}
else if (!region.checkEffectRangeInsidePeaceZone(skill, getX(), getY(), getZ()))
else if (!zoneRegion.checkEffectRangeInsidePeaceZone(skill, getX(), getY(), getZ()))
{
canCast = false;
}
@ -2413,10 +2406,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
getAI().notifyEvent(CtrlEvent.EVT_DEAD);
}
if (getWorldRegion() != null)
{
getWorldRegion().onDeath(this);
}
ZoneManager.getInstance().getRegion(this).onDeath(this);
getAttackByList().clear();
@ -2424,16 +2414,6 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
// karma reduction tempfix
// if (isMonster() && (killer != null) && killer.isPlayer() && (killer.getActingPlayer().getKarma() > 0))
// {
// if (killer.getLevel() >= (getLevel() - 5))
// {
// killer.getActingPlayer().setKarma(killer.getActingPlayer().getKarma() < 50 ? 0 : (int) (killer.getActingPlayer().getKarma() - (killer.getActingPlayer().getKarma() / 8)));
// }
// }
return true;
}
@ -2487,10 +2467,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
// Start broadcast status
broadcastPacket(new Revive(this));
if (getWorldRegion() != null)
{
getWorldRegion().onRevive(this);
}
ZoneManager.getInstance().getRegion(this).onRevive(this);
}
else
{
@ -2519,8 +2497,6 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
{
if (_ai == null)
{
// Return the new AI within the synchronized block
// to avoid being nulled by other threads
return _ai = initAI();
}
}
@ -4023,7 +3999,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
getWorldRegion().revalidateZones(this);
ZoneManager.getInstance().getRegion(this).revalidateZones(this);
}
/**

View File

@ -17,6 +17,7 @@
package com.l2jmobius.gameserver.model.actor;
import com.l2jmobius.gameserver.enums.InstanceType;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.actor.templates.L2CharTemplate;
@ -130,10 +131,7 @@ public abstract class L2Decoy extends L2Character
{
return;
}
if (getWorldRegion() != null)
{
getWorldRegion().removeFromZones(this);
}
ZoneManager.getInstance().getRegion(this).removeFromZones(this);
owner.setDecoy(null);
decayMe();
}

View File

@ -50,10 +50,10 @@ import com.l2jmobius.gameserver.instancemanager.CastleManager;
import com.l2jmobius.gameserver.instancemanager.FortManager;
import com.l2jmobius.gameserver.instancemanager.TownManager;
import com.l2jmobius.gameserver.instancemanager.WalkingManager;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2Spawn;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.L2WorldRegion;
import com.l2jmobius.gameserver.model.Location;
import com.l2jmobius.gameserver.model.actor.instance.L2ClanHallManagerInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2DoormenInstance;
@ -1345,14 +1345,10 @@ public class L2Npc extends L2Character
getSkillChannelized().abortChannelization();
}
final L2WorldRegion oldRegion = getWorldRegion();
if (oldRegion != null)
{
oldRegion.removeFromZones(this);
}
ZoneManager.getInstance().getRegion(this).removeFromZones(this);
// Remove L2Object object from _allObjects of L2World
L2World.getInstance().removeObject(this);
// L2World.getInstance().removeObject(this);
return super.deleteMe();
}

View File

@ -19,6 +19,7 @@ package com.l2jmobius.gameserver.model.actor;
import com.l2jmobius.gameserver.ai.CtrlEvent;
import com.l2jmobius.gameserver.enums.InstanceType;
import com.l2jmobius.gameserver.instancemanager.InstanceManager;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.actor.stat.PlayableStat;
@ -155,10 +156,7 @@ public abstract class L2Playable extends L2Character
// Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform
broadcastStatusUpdate();
if (getWorldRegion() != null)
{
getWorldRegion().onDeath(this);
}
ZoneManager.getInstance().getRegion(this).onDeath(this);
// Notify Quest of L2Playable's death
final L2PcInstance actingPlayer = getActingPlayer();

View File

@ -31,11 +31,11 @@ import com.l2jmobius.gameserver.geoengine.GeoEngine;
import com.l2jmobius.gameserver.handler.IItemHandler;
import com.l2jmobius.gameserver.handler.ItemHandler;
import com.l2jmobius.gameserver.instancemanager.TerritoryWarManager;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.AggroInfo;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2Party;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.L2WorldRegion;
import com.l2jmobius.gameserver.model.actor.instance.L2NpcInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.actor.stat.SummonStat;
@ -53,6 +53,7 @@ import com.l2jmobius.gameserver.model.olympiad.OlympiadGameManager;
import com.l2jmobius.gameserver.model.skills.Skill;
import com.l2jmobius.gameserver.model.skills.targets.L2TargetType;
import com.l2jmobius.gameserver.model.zone.ZoneId;
import com.l2jmobius.gameserver.model.zone.ZoneRegion;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.AbstractNpcInfo.SummonInfo;
import com.l2jmobius.gameserver.network.serverpackets.ActionFailed;
@ -417,12 +418,9 @@ public abstract class L2Summon extends L2Playable
}
stopAllEffects();
final L2WorldRegion oldRegion = getWorldRegion();
final ZoneRegion oldRegion = ZoneManager.getInstance().getRegion(this);
decayMe();
if (oldRegion != null)
{
oldRegion.removeFromZones(this);
}
oldRegion.removeFromZones(this);
setTarget(null);
if (owner != null)

View File

@ -25,8 +25,8 @@ import com.l2jmobius.gameserver.GameTimeController;
import com.l2jmobius.gameserver.ai.CtrlIntention;
import com.l2jmobius.gameserver.enums.InstanceType;
import com.l2jmobius.gameserver.instancemanager.MapRegionManager;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.L2WorldRegion;
import com.l2jmobius.gameserver.model.Location;
import com.l2jmobius.gameserver.model.TeleportWhereType;
import com.l2jmobius.gameserver.model.VehiclePathPoint;
@ -36,6 +36,7 @@ import com.l2jmobius.gameserver.model.actor.templates.L2CharTemplate;
import com.l2jmobius.gameserver.model.interfaces.ILocational;
import com.l2jmobius.gameserver.model.items.L2Weapon;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.model.zone.ZoneRegion;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
import com.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
@ -391,7 +392,7 @@ public abstract class L2Vehicle extends L2Character
_log.log(Level.SEVERE, "Failed oustPlayers().", e);
}
final L2WorldRegion oldZoneRegion = getWorldRegion();
final ZoneRegion oldZoneRegion = ZoneManager.getInstance().getRegion(this);
try
{
@ -402,13 +403,10 @@ public abstract class L2Vehicle extends L2Character
_log.log(Level.SEVERE, "Failed decayMe().", e);
}
if (oldZoneRegion != null)
{
oldZoneRegion.removeFromZones(this);
}
oldZoneRegion.removeFromZones(this);
// Remove L2Object object from _allObjects of L2World
L2World.getInstance().removeObject(this);
// L2World.getInstance().removeObject(this);
return super.deleteMe();
}

View File

@ -131,7 +131,6 @@ import com.l2jmobius.gameserver.model.L2RecipeList;
import com.l2jmobius.gameserver.model.L2Request;
import com.l2jmobius.gameserver.model.L2SkillLearn;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.L2WorldRegion;
import com.l2jmobius.gameserver.model.Location;
import com.l2jmobius.gameserver.model.Macro;
import com.l2jmobius.gameserver.model.MacroList;
@ -1699,16 +1698,24 @@ public final class L2PcInstance extends L2Playable
}
// This function is called too often from movement code
if (!force)
if (force)
{
_zoneValidateCounter = 4;
}
else
{
_zoneValidateCounter--;
if (_zoneValidateCounter >= 0)
if (_zoneValidateCounter < 0)
{
_zoneValidateCounter = 4;
}
else
{
return;
}
}
_zoneValidateCounter = 4;
getWorldRegion().revalidateZones(this);
ZoneManager.getInstance().getRegion(this).revalidateZones(this);
if (Config.ALLOW_WATER)
{
@ -11224,11 +11231,7 @@ public final class L2PcInstance extends L2Playable
getEffectList().stopAllToggles();
// Remove from world regions zones
final L2WorldRegion oldRegion = getWorldRegion();
if (oldRegion != null)
{
oldRegion.removeFromZones(this);
}
ZoneManager.getInstance().getRegion(this).removeFromZones(this);
// Remove the L2PcInstance from the world
try

View File

@ -23,6 +23,7 @@ import java.util.concurrent.ScheduledFuture;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.gameserver.enums.InstanceType;
import com.l2jmobius.gameserver.enums.TrapAction;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.L2Attackable;
import com.l2jmobius.gameserver.model.actor.L2Character;
@ -416,11 +417,7 @@ public final class L2TrapInstance extends L2Npc
if (isSpawned() && !isDead())
{
if (getWorldRegion() != null)
{
getWorldRegion().removeFromZones(this);
}
ZoneManager.getInstance().getRegion(this).removeFromZones(this);
deleteMe();
}
}

View File

@ -1,121 +0,0 @@
/*
* 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 com.l2jmobius.gameserver.model.zone.type;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
import com.l2jmobius.gameserver.model.L2WorldRegion;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.skills.Skill;
import com.l2jmobius.gameserver.model.zone.AbstractZoneSettings;
import com.l2jmobius.gameserver.model.zone.L2ZoneType;
import com.l2jmobius.gameserver.model.zone.TaskZoneSettings;
/**
* A dynamic zone? Maybe use this for interlude skills like protection field :>
* @author durgus
*/
public class L2DynamicZone extends L2ZoneType
{
private final L2WorldRegion _region;
private final L2Character _owner;
private final Skill _skill;
public L2DynamicZone(L2WorldRegion region, L2Character owner, Skill skill)
{
super(-1);
_region = region;
_owner = owner;
_skill = skill;
final AbstractZoneSettings settings = ZoneManager.getSettings(getName()) == null ? new TaskZoneSettings() : ZoneManager.getSettings(getName());
setSettings(settings);
getSettings().setTask(ThreadPool.schedule(() -> remove(), skill.getAbnormalTime() * 1000));
}
@Override
public TaskZoneSettings getSettings()
{
return (TaskZoneSettings) super.getSettings();
}
@Override
protected void onEnter(L2Character character)
{
if (character.isPlayer())
{
character.sendMessage("You have entered a temporary zone!");
}
if (_owner != null)
{
_skill.applyEffects(_owner, character);
}
}
@Override
protected void onExit(L2Character character)
{
if (character.isPlayer())
{
character.sendMessage("You have left a temporary zone!"); // TODO: Custom message?
}
if (character == _owner)
{
remove();
return;
}
character.stopSkillEffects(true, _skill.getId());
}
protected void remove()
{
if ((getSettings().getTask() == null) || (_skill == null))
{
return;
}
getSettings().getTask().cancel(false);
_region.removeZone(this);
for (L2Character member : getCharactersInside())
{
member.stopSkillEffects(true, _skill.getId());
}
_owner.stopSkillEffects(true, _skill.getId());
}
@Override
public void onDieInside(L2Character character)
{
if (character == _owner)
{
remove();
}
else
{
character.stopSkillEffects(true, _skill.getId());
}
}
@Override
public void onReviveInside(L2Character character)
{
_skill.applyEffects(_owner, character);
}
}