Dropped TerritoryTable.
This commit is contained in:
parent
301255cb25
commit
68a7ef1c65
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,6 @@ import com.l2jmobius.Config;
|
|||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import com.l2jmobius.commons.util.Rnd;
|
import com.l2jmobius.commons.util.Rnd;
|
||||||
import com.l2jmobius.gameserver.GameTimeController;
|
import com.l2jmobius.gameserver.GameTimeController;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.TerritoryTable;
|
|
||||||
import com.l2jmobius.gameserver.data.xml.impl.SkillData;
|
import com.l2jmobius.gameserver.data.xml.impl.SkillData;
|
||||||
import com.l2jmobius.gameserver.enums.AISkillScope;
|
import com.l2jmobius.gameserver.enums.AISkillScope;
|
||||||
import com.l2jmobius.gameserver.enums.AIType;
|
import com.l2jmobius.gameserver.enums.AIType;
|
||||||
@ -722,37 +721,6 @@ public class L2AttackableAI extends L2CharacterAI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If NPC with random coord in territory - old method (for backward compatibility)
|
|
||||||
if ((npc.getSpawn().getX() == 0) && (npc.getSpawn().getY() == 0) && (npc.getSpawn().getSpawnTerritory() == null))
|
|
||||||
{
|
|
||||||
// Calculate a destination point in the spawn area
|
|
||||||
final Location location = TerritoryTable.getInstance().getRandomPoint(npc.getSpawn().getLocationId());
|
|
||||||
if (location != null)
|
|
||||||
{
|
|
||||||
x1 = location.getX();
|
|
||||||
y1 = location.getY();
|
|
||||||
z1 = location.getZ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the distance between the current position of the L2Character and the target (x,y)
|
|
||||||
final double distance2 = npc.calculateDistance(x1, y1, 0, false, true);
|
|
||||||
|
|
||||||
if (distance2 > ((range + range) * (range + range)))
|
|
||||||
{
|
|
||||||
npc.setisReturningToSpawnPoint(true);
|
|
||||||
final float delay = (float) Math.sqrt(distance2) / range;
|
|
||||||
x1 = npc.getX() + (int) ((x1 - npc.getX()) / delay);
|
|
||||||
y1 = npc.getY() + (int) ((y1 - npc.getY()) / delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If NPC with random fixed coord, don't move (unless needs to return to spawnpoint)
|
|
||||||
if (!npc.isReturningToSpawnPoint() && (TerritoryTable.getInstance().getProcMax(npc.getSpawn().getLocationId()) > 0))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
x1 = npc.getSpawn().getX(npc);
|
x1 = npc.getSpawn().getX(npc);
|
||||||
y1 = npc.getSpawn().getY(npc);
|
y1 = npc.getSpawn().getY(npc);
|
||||||
z1 = npc.getSpawn().getZ(npc);
|
z1 = npc.getSpawn().getZ(npc);
|
||||||
@ -770,7 +738,7 @@ public class L2AttackableAI extends L2CharacterAI
|
|||||||
y1 = (deltaY + y1) - range;
|
y1 = (deltaY + y1) - range;
|
||||||
z1 = npc.getZ();
|
z1 = npc.getZ();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
|
// Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
|
||||||
final Location moveLoc = GeoEngine.getInstance().canMoveToTargetLoc(npc.getX(), npc.getY(), npc.getZ(), x1, y1, z1, npc.getInstanceId());
|
final Location moveLoc = GeoEngine.getInstance().canMoveToTargetLoc(npc.getX(), npc.getY(), npc.getZ(), x1, y1, z1, npc.getInstanceId());
|
||||||
|
|
||||||
|
@ -1,111 +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.data.sql.impl;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import com.l2jmobius.commons.database.DatabaseFactory;
|
|
||||||
import com.l2jmobius.gameserver.model.L2Territory;
|
|
||||||
import com.l2jmobius.gameserver.model.Location;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Balancer, Mr
|
|
||||||
*/
|
|
||||||
public class TerritoryTable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(TerritoryTable.class.getName());
|
|
||||||
|
|
||||||
private static final Map<Integer, L2Territory> _territory = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new territory.
|
|
||||||
*/
|
|
||||||
protected TerritoryTable()
|
|
||||||
{
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the random point.
|
|
||||||
* @param terr the territory Id?
|
|
||||||
* @return the random point
|
|
||||||
*/
|
|
||||||
public Location getRandomPoint(int terr)
|
|
||||||
{
|
|
||||||
return _territory.get(terr).getRandomPoint();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the proc max.
|
|
||||||
* @param terr the territory Id?
|
|
||||||
* @return the proc max
|
|
||||||
*/
|
|
||||||
public int getProcMax(int terr)
|
|
||||||
{
|
|
||||||
return _territory.get(terr).getProcMax();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the data from database.
|
|
||||||
*/
|
|
||||||
public void load()
|
|
||||||
{
|
|
||||||
_territory.clear();
|
|
||||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
|
||||||
Statement stmt = con.createStatement();
|
|
||||||
ResultSet rset = stmt.executeQuery("SELECT * FROM locations WHERE loc_id>0"))
|
|
||||||
{
|
|
||||||
while (rset.next())
|
|
||||||
{
|
|
||||||
final int terrId = rset.getInt("loc_id");
|
|
||||||
L2Territory terr = _territory.get(terrId);
|
|
||||||
if (terr == null)
|
|
||||||
{
|
|
||||||
terr = new L2Territory(terrId);
|
|
||||||
_territory.put(terrId, terr);
|
|
||||||
}
|
|
||||||
terr.add(rset.getInt("loc_x"), rset.getInt("loc_y"), rset.getInt("loc_zmin"), rset.getInt("loc_zmax"), rset.getInt("proc"));
|
|
||||||
}
|
|
||||||
LOGGER.info("TerritoryTable: Loaded " + _territory.size() + " territories from database.");
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "TerritoryTable: Failed to load territories from database!", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the single instance of Territory.
|
|
||||||
* @return single instance of Territory
|
|
||||||
*/
|
|
||||||
public static TerritoryTable getInstance()
|
|
||||||
{
|
|
||||||
return SingletonHolder._instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SingletonHolder
|
|
||||||
{
|
|
||||||
protected static final TerritoryTable _instance = new TerritoryTable();
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import com.l2jmobius.commons.util.Rnd;
|
import com.l2jmobius.commons.util.Rnd;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.TerritoryTable;
|
|
||||||
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
||||||
import com.l2jmobius.gameserver.model.actor.instance.L2ControllableMobInstance;
|
import com.l2jmobius.gameserver.model.actor.instance.L2ControllableMobInstance;
|
||||||
import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate;
|
import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate;
|
||||||
@ -59,20 +58,12 @@ public class L2GroupSpawn extends L2Spawn
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Location location = TerritoryTable.getInstance().getRandomPoint(getLocationId());
|
return null;
|
||||||
if (location != null)
|
|
||||||
{
|
|
||||||
newlocx = location.getX();
|
|
||||||
newlocy = location.getY();
|
|
||||||
newlocz = location.getZ();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newlocx = getX();
|
newlocx = getX();
|
||||||
newlocy = getY();
|
newlocy = getY();
|
||||||
newlocz = getZ();
|
newlocz = getZ();
|
||||||
}
|
|
||||||
|
|
||||||
final L2Npc mob = new L2ControllableMobInstance(_template);
|
final L2Npc mob = new L2ControllableMobInstance(_template);
|
||||||
mob.setCurrentHpMp(mob.getMaxHp(), mob.getMaxMp());
|
mob.setCurrentHpMp(mob.getMaxHp(), mob.getMaxMp());
|
||||||
|
@ -29,7 +29,6 @@ import java.util.logging.Logger;
|
|||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
import com.l2jmobius.commons.concurrent.ThreadPool;
|
import com.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import com.l2jmobius.commons.util.Rnd;
|
import com.l2jmobius.commons.util.Rnd;
|
||||||
import com.l2jmobius.gameserver.data.sql.impl.TerritoryTable;
|
|
||||||
import com.l2jmobius.gameserver.data.xml.impl.NpcData;
|
import com.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||||
import com.l2jmobius.gameserver.datatables.NpcPersonalAIData;
|
import com.l2jmobius.gameserver.datatables.NpcPersonalAIData;
|
||||||
import com.l2jmobius.gameserver.geoengine.GeoEngine;
|
import com.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||||
@ -65,7 +64,7 @@ public class L2Spawn implements IPositionable, IIdentifiable, INamable
|
|||||||
private int _currentCount;
|
private int _currentCount;
|
||||||
/** The current number of SpawnTask in progress or stand by of this L2Spawn */
|
/** The current number of SpawnTask in progress or stand by of this L2Spawn */
|
||||||
protected int _scheduledCount;
|
protected int _scheduledCount;
|
||||||
/** The identifier of the location area where L2NpcInstance can be spwaned */
|
/** The identifier of the location area where L2NpcInstance can be spawned */
|
||||||
private int _locationId;
|
private int _locationId;
|
||||||
/** The Location of this NPC spawn. */
|
/** The Location of this NPC spawn. */
|
||||||
private Location _location = new Location(0, 0, 0, 0, 0);
|
private Location _location = new Location(0, 0, 0, 0, 0);
|
||||||
@ -181,7 +180,7 @@ public class L2Spawn implements IPositionable, IIdentifiable, INamable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the Identifier of the location area where L2NpcInstance can be spwaned.
|
* @return the Identifier of the location area where L2NpcInstance can be spawned.
|
||||||
*/
|
*/
|
||||||
public int getLocationId()
|
public int getLocationId()
|
||||||
{
|
{
|
||||||
@ -550,31 +549,17 @@ public class L2Spawn implements IPositionable, IIdentifiable, INamable
|
|||||||
|
|
||||||
// If Locx and Locy are not defined, the L2NpcInstance must be spawned in an area defined by location or spawn territory
|
// If Locx and Locy are not defined, the L2NpcInstance must be spawned in an area defined by location or spawn territory
|
||||||
// New method
|
// New method
|
||||||
if (isTerritoryBased())
|
if (_spawnTerritory != null)
|
||||||
{
|
{
|
||||||
final Location p = _spawnTerritory.getRandomPoint();
|
final Location p = _spawnTerritory.getRandomPoint();
|
||||||
newlocx = p.getX();
|
newlocx = p.getX();
|
||||||
newlocy = p.getY();
|
newlocy = p.getY();
|
||||||
newlocz = p.getZ();
|
newlocz = p.getZ();
|
||||||
}
|
}
|
||||||
// Old method (for backward compatibility)
|
|
||||||
else if ((getX() == 0) && (getY() == 0))
|
else if ((getX() == 0) && (getY() == 0))
|
||||||
{
|
{
|
||||||
if (getLocationId() == 0)
|
LOGGER.warning("NPC " + npc + " doesn't have spawn location!");
|
||||||
{
|
return null;
|
||||||
return npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the random position in the location area
|
|
||||||
final Location location = TerritoryTable.getInstance().getRandomPoint(getLocationId());
|
|
||||||
|
|
||||||
// Set the calculated position of the L2NpcInstance
|
|
||||||
if (location != null)
|
|
||||||
{
|
|
||||||
newlocx = location.getX();
|
|
||||||
newlocy = location.getY();
|
|
||||||
newlocz = location.getZ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user