1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-09 17:02:53 +00:00

Template classes for all NPC instances

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-23 01:23:41 -03:00
parent ebc7947473
commit 66d5fee187
9119 changed files with 664622 additions and 410 deletions

View File

@@ -0,0 +1,28 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.spawn;
/**
* Exception thrown when trying to teleport an character but its state indicates
* that it is already teleporting.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterAlreadyTeleportingServiceException extends
SpawnServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,28 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.spawn;
/**
* Exception thrown when trying to finish the teleportion of an character but
* its state is not teleporting.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterNotTeleportingServiceException extends
SpawnServiceException {
private static final long serialVersionUID = 1L;
}

View File

@@ -16,9 +16,12 @@
*/
package com.l2jserver.service.game.spawn;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterState;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.PositionableObject;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportedEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportingEvent;
import com.l2jserver.service.Service;
import com.l2jserver.util.dimensional.Coordinate;
@@ -63,9 +66,29 @@ public interface SpawnService extends Service {
* the teleportation coordinate
* @throws NotSpawnedServiceException
* if the object to be teleported is not spawned
* @throws CharacterAlreadyTeleportingServiceException
* if this player is already being teleported. This will only be
* thrown for {@link L2Character} instances.
*/
void teleport(Player player, Coordinate coordinate)
throws NotSpawnedServiceException;
throws NotSpawnedServiceException,
CharacterAlreadyTeleportingServiceException;
/**
* Finishes teleporting the character. This is only used for
* {@link L2Character} instances.
* <p>
* An {@link PlayerTeleportedEvent} will be dispatched and the new position
* will be broadcast to all clients.
*
* @param character
* the character object
* @throws CharacterNotTeleportingServiceException
* if the character state is not
* {@link CharacterState#TELEPORTING}
*/
void finishTeleport(L2Character character)
throws CharacterNotTeleportingServiceException;
/**
* Schedules an {@link Spawnable} object to be respawn in a certain time.
@@ -85,5 +108,6 @@ public interface SpawnService extends Service {
* @throws NotSpawnedServiceException
* if the object is not spawned
*/
void unspawn(PositionableObject spawnable) throws NotSpawnedServiceException;
void unspawn(PositionableObject spawnable)
throws NotSpawnedServiceException;
}

View File

@@ -22,6 +22,8 @@ import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.server.CharacterInformationExtraPacket;
import com.l2jserver.game.net.packet.server.CharacterInformationPacket;
import com.l2jserver.game.net.packet.server.CharacterTeleportPacket;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.world.L2Character;
@@ -31,6 +33,7 @@ import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.PositionableObject;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportedEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportingEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
@@ -111,19 +114,25 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
}
@Override
public void teleport(Player player, Coordinate coordinate) {
public void teleport(Player player, Coordinate coordinate)
throws CharacterAlreadyTeleportingServiceException {
Preconditions.checkNotNull(player, "player");
Preconditions.checkNotNull(coordinate, "coordinate");
System.out.println("teleport: " + coordinate);
player.setPosition(coordinate);
if (player instanceof L2Character) {
if (((L2Character) player).isTeleporting())
throw new CharacterAlreadyTeleportingServiceException();
final Lineage2Connection conn = networkService
.discover((CharacterID) player.getID());
if (conn == null)
// TODO throw an exception here
return;
conn.write(new CharacterTeleportPacket(conn.getCharacter()));
conn.write(new CharacterTeleportPacket(conn.getCharacter(),
coordinate.toPoint()));
((L2Character) player).setState(CharacterState.TELEPORTING);
((L2Character) player).setTargetLocation(coordinate.toPoint());
} else {
player.setPosition(coordinate);
}
// dispatch teleport event
eventDispatcher.dispatch(new PlayerTeleportingEvent(player, coordinate
@@ -131,6 +140,28 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
// remember: broadcasting is done through events!
}
@Override
public void finishTeleport(L2Character character)
throws CharacterNotTeleportingServiceException {
Preconditions.checkNotNull(character, "character");
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
if (!character.isTeleporting())
throw new CharacterNotTeleportingServiceException();
character.setState(null);
character.setPoint(character.getTargetLocation());
eventDispatcher.dispatch(new PlayerTeleportedEvent(character, character
.getTargetLocation()));
character.setTargetLocation(null);
conn.write(new CharacterInformationPacket(character));
conn.write(new CharacterInformationExtraPacket(character));
}
@Override
public void scheduleRespawn(PositionableObject object) {
Preconditions.checkNotNull(object, "object");