HOME FORUMS MEMBERS RECENT POSTS LOG IN  
× Авторизация
Имя пользователя:
Пароль:
Нет аккаунта? Регистрация
Баннер 1   Баннер 2
НОВЫЕ ТОРГОВАЯ НОВОСТИ ЧАТ
loading...
Скрыть
Вернуться   ANTICHAT > ПРОГРАММИРОВАНИЕ > Общие вопросы программирования
   
 
 
Опции темы Поиск в этой теме Опции просмотра

  #11  
Старый 07.08.2015, 19:51
kick
Флудер
Регистрация: 20.01.2015
Сообщений: 7,201
С нами: 5952720

Репутация: 6527


По умолчанию

Смотрим чудо спавн:























-->





Вот это да, какая реализация и не сделаны banned территории, но всё согласно же официальному контенту. Но это осталось с оверов, а мозгов реализовать не хватило притом, что оверы парсили с офф скриптов, но как говорит гринд это придумали масоны. Про миньенов и точечный спавн молчу это нужно переписывать и да супер менеджер работающий с бд конечно же:

Цитата:
Сообщение от Спойлер  

package core.gameserver.instancemanager;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.ArrayList;

import java.util.List;

import java.util.Map;

import java.util.concurrent.ConcurrentHashMap;

import java.util.concurrent.ScheduledFuture;

import java.util.concurrent.TimeUnit;

import core.commons.dbutils.DbUtils;

import core.commons.threading.RunnableImpl;

import core.commons.util.Rnd;

import core.gameserver.Announcements;

import core.gameserver.Config;

import core.gameserver.ThreadPoolManager;

import core.gameserver.data.xml.holder.NpcHolder;

import core.gameserver.data.xml.holder.ResidenceHolder;

import core.gameserver.database.DatabaseFactory;

import core.gameserver.idfactory.IdFactory;

import core.gameserver.model.base.Race;

import core.gameserver.model.Creature;

import core.gameserver.model.Player;

import core.gameserver.model.SimpleSpawner;

import core.gameserver.model.Spawner;

import core.gameserver.model.entity.residence.Castle;

import core.gameserver.model.instances.NpcInstance;

import core.gameserver.templates.mapregion.RestartArea;

import core.gameserver.templates.mapregion.RestartPoint;

import core.gameserver.templates.npc.NpcTemplate;

import core.gameserver.utils.HtmlUtils;

import core.gameserver.utils.Location;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

public class AutoSpawnManager

{

private static final Logger _log = LoggerFactory.getLogger(AutoSpawnManager.class);

private static AutoSpawnManager _instance;

private static final int DEFAULT_INITIAL_SPAWN = 30000; // 30 seconds after registration

private static final int DEFAULT_RESPAWN = 3600000; //1 hour in millisecs

private static final int DEFAULT_DESPAWN = 3600000; //1 hour in millisecs

protected Map _registeredSpawns;

protected Map> _runningSpawns;

public AutoSpawnManager()

{

_registeredSpawns = new ConcurrentHashMap();

_runningSpawns = new ConcurrentHashMap>();

restoreSpawnData();

_log.info("AutoSpawnHandler: Loaded " + size() + " handlers in total.");

}

public static AutoSpawnManager getInstance()

{

if(_instance == null)

_instance = new AutoSpawnManager();

return _instance;

}

public final int size()

{

return _registeredSpawns.size();

}

private void restoreSpawnData()

{

int numLoaded = 0;

Connection con = null;

PreparedStatement statement = null;

PreparedStatement statement2 = null;

ResultSet rset = null, rset2 = null;

try

{

con = DatabaseFactory.getInstance().getConnection();

// Restore spawn group data, then the location data.

statement = con.prepareStatement("SELECT * FROM random_spawn ORDER BY groupId ASC");

statement2 = con.prepareStatement("SELECT * FROM random_spawn_loc WHERE groupId=?");

rset = statement.executeQuery();

while(rset.next())

{

// Register random spawn group, set various options on the created spawn instance.

AutoSpawnInstance spawnInst = registerSpawn(rset.getInt("npcId"), rset.getInt("initialDelay"), rset.getInt("respawnDelay"), rset.getInt("despawnDelay"));

spawnInst.setSpawnCount(rset.getInt("count"));

spawnInst.setBroadcast(rset.getBoolean("broadcastS pawn"));

spawnInst.setRandomSpawn(rset.getBoolean("randomSp awn"));

numLoaded++;

// Restore the spawn locations for this spawn group/instance.

statement2.setInt(1, rset.getInt("groupId"));

rset2 = statement2.executeQuery();

while(rset2.next())

// Add each location to the spawn group/instance.

spawnInst.addSpawnLocation(rset2.getInt("x"), rset2.getInt("y"), rset2.getInt("z"), rset2.getInt("heading"));

DbUtils.close(rset2);

}

}

catch(Exception e)

{

_log.warn("AutoSpawnHandler: Could not restore spawn data: " + e);

}

finally

{

DbUtils.closeQuietly(statement2, rset2);

DbUtils.closeQuietly(con, statement, rset);

}

}

/**

* Registers a spawn with the given parameters with the spawner, and marks it as

* active. Returns a AutoSpawnInstance containing info about the spawn.

*

* @param int npcId

* @param int[][] spawnPoints

* @param int initialDelay (If Warning: Spawn locations must be specified separately using addSpawnLocation().

*

* @param int npcId

* @param int initialDelay (If respawnTask = _runningSpawns.remove(spawnInst._objectId);

respawnTask.cancel(false);

}

catch(Exception e)

{

_log.warn("AutoSpawnHandler: Could not auto spawn for NPC ID " + spawnInst._npcId + " (Object ID = " + spawnInst._objectId + "): " + e);

return false;

}

return true;

}

/**

* Remove a registered spawn from the list, specified by the given spawn object ID.

*

* @param int objectId

* @Return boolean removedSuccessfully

*/

public void removeSpawn(int objectId)

{

removeSpawn(_registeredSpawns.get(objectId));

}

/**

* Sets the active state of the specified spawn.

*

* @param AutoSpawnInstance spawnInst

* @param boolean isActive

*/

public void setSpawnActive(AutoSpawnInstance spawnInst, boolean isActive)

{

int objectId = spawnInst._objectId;

if(isSpawnRegistered(objectId))

{

ScheduledFuture spawnTask = null;

if(isActive)

{

AutoSpawner rset = new AutoSpawner(objectId);

if(spawnInst._desDelay > 0)

spawnTask = ThreadPoolManager.getInstance().scheduleAtFixedRat e(rset, spawnInst._initDelay, spawnInst._resDelay);

else

spawnTask = ThreadPoolManager.getInstance().schedule(rset, spawnInst._initDelay);

//spawnTask = ThreadPoolManager.getInstance().scheduleGeneralAtF ixedRate(rset, spawnInst._initDelay, spawnInst._resDelay);

_runningSpawns.put(objectId, spawnTask);

}

else

{

spawnTask = _runningSpawns.remove(objectId);

if(spawnTask != null)

spawnTask.cancel(false);

}

spawnInst.setSpawnActive(isActive);

}

}

/**

* Returns the number of milliseconds until the next occurrance of

* the given spawn.

*

* @param AutoSpawnInstance spawnInst

* @param long milliRemaining

*/

public final long getTimeToNextSpawn(AutoSpawnInstance spawnInst)

{

int objectId = spawnInst._objectId;

if(!isSpawnRegistered(objectId))

return -1;

return _runningSpawns.get(objectId).getDelay(TimeUnit.MIL LISECONDS);

}

/**

* Attempts to return the AutoSpawnInstance associated with the given NPC or Object ID type.

*

* Note: If isObjectId == false, returns first instance for the specified NPC ID.

*

* @param int id

* @param boolean isObjectId

* @Return AutoSpawnInstance spawnInst

*/

public final AutoSpawnInstance getAutoSpawnInstance(int id, boolean isObjectId)

{

if(isObjectId)

{

if(isSpawnRegistered(id))

return _registeredSpawns.get(id);

}

else

for(AutoSpawnInstance spawnInst : _registeredSpawns.values())

if(spawnInst._npcId == id)

return spawnInst;

return null;

}

public Map getAllAutoSpawnInstance(int id)

{

Map spawnInstList = new ConcurrentHashMap();

for(AutoSpawnInstance spawnInst : _registeredSpawns.values())

if(spawnInst._npcId == id)

spawnInstList.put(spawnInst._objectId, spawnInst);

return spawnInstList;

}

/**

* Tests if the specified object ID is assigned to an auto spawn.

*

* @param int objectId

* @Return boolean isAssigned

*/

public final boolean isSpawnRegistered(int objectId)

{

return _registeredSpawns.containsKey(objectId);

}

/**

* Tests if the specified spawn instance is assigned to an auto spawn.

*

* @param AutoSpawnInstance spawnInst

* @Return boolean isAssigned

*/

public final boolean isSpawnRegistered(AutoSpawnInstance spawnInst)

{

return _registeredSpawns.containsValue(spawnInst);

}

/**

* AutoSpawner Class

*

* This handles the main spawn task for an auto spawn instance, and initializes

* a despawner if required.

*

* @author Tempy

*/

private class AutoSpawner extends RunnableImpl

{

private int _objectId;

AutoSpawner(int objectId)

{

_objectId = objectId;

}

@Override

public void runImpl() throws Exception

{

try

{

// Retrieve the required spawn instance for this spawn task.

AutoSpawnInstance spawnInst = _registeredSpawns.get(_objectId);

// If the spawn is not scheduled to be active, cancel the spawn task.

if(!spawnInst.isSpawnActive() || Config.DONTLOADSPAWN)

return;

Location[] locationList = spawnInst.getLocationList();

// If there are no set co-ordinates, cancel the spawn task.

if(locationList.length == 0)

{

_log.info("AutoSpawnHandler: No location co-ords specified for spawn instance (Object ID = " + _objectId + ").");

return;

}

int locationCount = locationList.length;

int locationIndex = Rnd.get(locationCount);

/*

* If random spawning is disabled, the spawn at the next set of

* co-ordinates after the last. If the index is greater than the number

* of possible spawns, reset the counter to zero.

*/

if(!spawnInst.isRandomSpawn())

{

locationIndex = spawnInst._lastLocIndex;

locationIndex++;

if(locationIndex == locationCount)

locationIndex = 0;

spawnInst._lastLocIndex = locationIndex;

}

// Set the X, Y and Z co-ordinates, where this spawn will take place.

final int x = locationList[locationIndex].x;

final int y = locationList[locationIndex].y;

final int z = locationList[locationIndex].z;

final int heading = locationList[locationIndex].h;

// Fetch the template for this NPC ID and create a new spawn.

NpcTemplate npcTemp = NpcHolder.getInstance().getTemplate(spawnInst.getN pcId());

SimpleSpawner newSpawn = new SimpleSpawner(npcTemp);

newSpawn.setLocx(x);

newSpawn.setLocy;

newSpawn.setLocz(z);

if(heading != -1)

newSpawn.setHeading(heading);

newSpawn.setAmount(spawnInst.getSpawnCount());

if(spawnInst._desDelay == 0)

newSpawn.setRespawnDelay(spawnInst._resDelay);

// Add the new spawn information to the spawn table, but do not store it.

NpcInstance npcInst = null;

for(int i = 0; i 0)

{

AutoDespawner rd = new AutoDespawner(_objectId);

ThreadPoolManager.getInstance().schedule(rd, spawnInst.getDespawnDelay() - 1000);

}

}

catch(Exception e)

{

_log.warn("AutoSpawnHandler: An error occurred while initializing spawn instance (Object ID = " + _objectId + "): " + e);

_log.error("", e);

}

}

}

/**

* AutoDespawner Class

*

* Simply used as a secondary class for despawning an auto spawn instance.

*

* @author Tempy

*/

private class AutoDespawner extends RunnableImpl

{

private int _objectId;

AutoDespawner(int objectId)

{

_objectId = objectId;

}

@Override

public void runImpl() throws Exception

{

try

{

AutoSpawnInstance spawnInst = _registeredSpawns.get(_objectId);

for(NpcInstance npcInst : spawnInst.getAttackableList())

{

npcInst.deleteMe();

spawnInst.removeAttackable(npcInst);

}

}

catch(Exception e)

{

_log.warn("AutoSpawnHandler: An error occurred while despawning spawn (Object ID = " + _objectId + "): " + e);

}

}

}

/**

* AutoSpawnInstance Class

*

* Stores information about a registered auto spawn.

*

* @author Tempy

*/

public class AutoSpawnInstance

{

protected int _objectId;

protected int _spawnIndex;

protected int _npcId;

protected int _initDelay;

protected int _resDelay;

protected int _desDelay;

protected int _spawnCount = 1;

protected int _lastLocIndex = -1;

private List _npcList = new ArrayList();

private List _locList = new ArrayList();

private boolean _spawnActive;

private boolean _randomSpawn = false;

private boolean _broadcastAnnouncement = false;

protected AutoSpawnInstance(int npcId, int initDelay, int respawnDelay, int despawnDelay)

{

_npcId = npcId;

_initDelay = initDelay;

_resDelay = respawnDelay;

_desDelay = despawnDelay;

}

void setSpawnActive(boolean activeValue)

{

_spawnActive = activeValue;

}

boolean addAttackable(NpcInstance npcInst)

{

return _npcList.add(npcInst);

}

boolean removeAttackable(NpcInstance npcInst)

{

return _npcList.remove(npcInst);

}

public int getObjectId()

{

return _objectId;

}

public int getInitialDelay()

{

return _initDelay;

}

public int getRespawnDelay()

{

return _resDelay;

}

public int getDespawnDelay()

{

return _desDelay;

}

public int getNpcId()

{

return _npcId;

}

public int getSpawnCount()

{

return _spawnCount;

}

public Location[] getLocationList()

{

return _locList.toArray(new Location[_locList.size()]);

}

public NpcInstance[] getAttackableList()

{

return _npcList.toArray(new NpcInstance[_npcList.size()]);

}

public Spawner[] getSpawns()

{

List npcSpawns = new ArrayList();

for(NpcInstance npcInst : _npcList)

npcSpawns.add(npcInst.getSpawn());

return npcSpawns.toArray(new Spawner[npcSpawns.size()]);

}

public void setSpawnCount(int spawnCount)

{

_spawnCount = spawnCount;

}

public void setRandomSpawn(boolean randValue)

{

_randomSpawn = randValue;

}

public void setBroadcast(boolean broadcastValue)

{

_broadcastAnnouncement = broadcastValue;

}

public boolean isSpawnActive()

{

return _spawnActive;

}

public boolean isRandomSpawn()

{

return _randomSpawn;

}

public boolean isBroadcasting()

{

return _broadcastAnnouncement;

}

public boolean addSpawnLocation(int x, int y, int z, int heading)

{

return _locList.add(new Location(x, y, z, heading));

}

public boolean addSpawnLocation(int[] spawnLoc)

{

if(spawnLoc.length != 3)

return false;

return addSpawnLocation(spawnLoc[0], spawnLoc[1], spawnLoc[2], -1);

}

public Location removeSpawnLocation(int locIndex)

{

try

{

return _locList.remove(locIndex);

}

catch(IndexOutOfBoundsException e)

{

return null;

}

}

}

}
Цитата:
Сообщение от Спойлер  

DROP TABLE IF EXISTS random_spawn;

CREATE TABLE random_spawn (

groupId INT NOT NULL default 0,

npcId INT NOT NULL default 0,

count INT NOT NULL default 0,

initialDelay BIGINT NOT NULL default -1,

respawnDelay BIGINT NOT NULL default -1,

despawnDelay BIGINT NOT NULL default -1,

broadcastSpawn enum('false','true') NOT NULL default 'false',

randomSpawn enum('false','true') NOT NULL default 'true',

PRIMARY KEY (groupId)

) ENGINE=MyISAM;

INSERT INTO `random_spawn` VALUES

(2,31111,1,-1,60,0,'false','false'),

(3,31112,1,-1,60,0,'false','false'),

(4,31113,1,-1,-1,-1,'true','true'),

(5,31126,1,-1,-1,-1,'true','true'),

(6,31094,1,-1,300000,300000,'false','true'),

(7,31094,1,-1,300000,300000,'false','true'),

(8,31094,1,-1,300000,300000,'false','true'),

(9,31094,1,-1,300000,300000,'false','true'),

(10,31094,1,-1,300000,300000,'false','true'),

(11,31094,1,-1,300000,300000,'false','true'),

(12,31094,1,-1,300000,300000,'false','true'),

(13,31094,1,-1,300000,300000,'false','true'),

(14,31093,1,-1,300000,300000,'false','true'),

(15,31093,1,-1,300000,300000,'false','true'),

(16,31093,1,-1,300000,300000,'false','true'),

(17,31093,1,-1,300000,300000,'false','true'),

(18,31093,1,-1,300000,300000,'false','true'),

(19,31093,1,-1,300000,300000,'false','true'),

(20,31093,1,-1,300000,300000,'false','true'),

(21,31093,1,-1,300000,300000,'false','true'),

(22,25283,1,-1,86400,0,'false','false'),

(23,25286,1,-1,86400,0,'false','false');

-- sevensigns emblem_of_dawn,emblem_of_dusk

insert into random_spawn values

(103, 31170, 1, -1, 60, 0, 'false', 'false'),

(104, 31171, 1, -1, 60, 0, 'false', 'false'),

(105, 31170, 1, -1, 60, 0, 'false', 'false'),

(106, 31171, 1, -1, 60, 0, 'false', 'false'),

(107, 31170, 1, -1, 60, 0, 'false', 'false'),

(108, 31171, 1, -1, 60, 0, 'false', 'false'),

(109, 31170, 1, -1, 60, 0, 'false', 'false'),

(110, 31171, 1, -1, 60, 0, 'false', 'false'),

(111, 31170, 1, -1, 60, 0, 'false', 'false'),

(112, 31171, 1, -1, 60, 0, 'false', 'false'),

(113, 31170, 1, -1, 60, 0, 'false', 'false'),

(114, 31171, 1, -1, 60, 0, 'false', 'false'),

(115, 31170, 1, -1, 60, 0, 'false', 'false'),

(116, 31171, 1, -1, 60, 0, 'false', 'false'),

(117, 31170, 1, -1, 60, 0, 'false', 'false'),

(118, 31171, 1, -1, 60, 0, 'false', 'false'),

(119, 31170, 1, -1, 60, 0, 'false', 'false'),

(120, 31171, 1, -1, 60, 0, 'false', 'false'),

(121, 31170, 1, -1, 60, 0, 'false', 'false'),

(122, 31171, 1, -1, 60, 0, 'false', 'false'),

(123, 31170, 1, -1, 60, 0, 'false', 'false'),

(124, 31171, 1, -1, 60, 0, 'false', 'false'),

(125, 31170, 1, -1, 60, 0, 'false', 'false'),

(126, 31171, 1, -1, 60, 0, 'false', 'false'),

(127, 31170, 1, -1, 60, 0, 'false', 'false'),

(128, 31171, 1, -1, 60, 0, 'false', 'false'),

(129, 31170, 1, -1, 60, 0, 'false', 'false'),

(130, 31171, 1, -1, 60, 0, 'false', 'false');
 
Ответить с цитированием
 





Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT ™ © 2001- Antichat Kft.