1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-05 23:22:47 +00:00

Teleporter implementation

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-22 02:04:35 -03:00
parent b3ff0795ec
commit 87ce7bb987
31 changed files with 900 additions and 31 deletions

View File

@@ -0,0 +1,53 @@
/*
* 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 script.template.actor.npc;
import com.google.inject.Inject;
import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
import com.l2jserver.model.template.npc.TeleporterNPCTemplate;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class RoxxyGatekeeperTemplate extends TeleporterNPCTemplate {
public static final int ID = 30006;
@Inject
protected RoxxyGatekeeperTemplate(NPCTemplateIDProvider provider) {
super(provider.createID(ID));
this.name = "Roxxy";
this.title = "Gatekeeper";
this.attackable = true;
this.maxHp = 200;
this.collisionRadius = 8.00;
this.collisionHeight = 25.00;
addLocation("The Village of Gludin", GLUDIN, 18000);
addLocation("Dark Elven Village", DARK_ELF_VILLAGE, 24000);
addLocation("Dwarven Village", DWARVEN_VILLAGE, 46000);
addLocation("Elven Village", ELVEN_VILLAGE, 2300);
addLocation("Orc Village", ORC_VILLAGE, 35000);
addLocation("Kamael Village", KAMAEL_VILLAGE, 20000);
addLocation("Elven Ruins", ELVEN_RUINS, 830);
addLocation("Singing Waterfall", SINGING_WATERFALL, 770);
addLocation("Talking Island, Northern Territor",
TALKING_ISLAND_NORTHERN_TERRITORY, 1000);
addLocation("Obelisk of Victory", OBELISK_OF_VICTORY, 470);
}
}

View File

@@ -0,0 +1,54 @@
/*
* 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 script.template.actor.npc;
import com.google.inject.Inject;
import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
import com.l2jserver.model.template.npc.TeleporterNPCTemplate;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class TamilGatekeeperTemplate extends TeleporterNPCTemplate {
public static final int ID = 30576;
@Inject
protected TamilGatekeeperTemplate(NPCTemplateIDProvider provider) {
super(provider.createID(ID));
this.name = "Tamil";
this.title = "Gatekeeper";
this.attackable = true;
this.maxHp = 200;
this.collisionRadius = 8.00;
this.collisionHeight = 32.00;
addLocation("The Town of Gludio", GLUDIO, 23000);
addLocation("Town of Schuttgart", SCHUTTGART, 13000);
addLocation("Dark Elven Village", DARK_ELF_VILLAGE, 13000);
addLocation("Dwarven Village", DWARVEN_VILLAGE, 17000);
addLocation("Talking Island Village", TALKING_ISLAND_VILLAGE, 35000);
addLocation("Elven Village", ELVEN_VILLAGE, 18000);
addLocation("Kamael Village", KAMAEL_VILLAGE, 17000);
addLocation("Immortal Plateau, Southern Region",
IMMORTAL_PLATEAU_SOUTHERN_REGION, 2000);
addLocation("The Immortal Plateau", IMMORTAL_PLATEAU, 960);
addLocation("Cave of Trials", CAVE_OF_TRIALS, 1500);
addLocation("Frozen Waterfall", FROZEN_WATERFALL, 1600);
}
}

View File

@@ -99,5 +99,19 @@ public class L2JGameServerMain {
npc.setPoint(Point.fromXYZ(-71301, 258259, -3134));
spawnService.spawn(npc, null);
// close spawn gatekepper
final NPCTemplateID gid = templateProvider.createID(30006);
final NPC gatekeeper = gid.getTemplate().create();
gatekeeper.setID(provider.createID());
gatekeeper.setPoint(Point.fromXYZ(-71301, 258559, -3134));
spawnService.spawn(gatekeeper, null);
// spawn tamil - orc village
final NPCTemplateID tamilId = templateProvider.createID(30576);
final NPC tamil = tamilId.getTemplate().create();
tamil.setID(provider.createID());
tamil.setPoint(Point.fromXYZ(-45264, -112512, -240));
spawnService.spawn(tamil, null);
}
}

View File

@@ -27,10 +27,14 @@ import com.google.inject.Inject;
import com.google.inject.Injector;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.ClientPacket;
import com.l2jserver.game.net.packet.client.AdminCommandPacket;
import com.l2jserver.game.net.packet.client.AuthLoginPacket;
import com.l2jserver.game.net.packet.client.CharacterActionPacket;
import com.l2jserver.game.net.packet.client.CharacterAppearingPacket;
import com.l2jserver.game.net.packet.client.CharacterChatMessagePacket;
import com.l2jserver.game.net.packet.client.CharacterCreatePacket;
import com.l2jserver.game.net.packet.client.CharacterRequestActionUse;
import com.l2jserver.game.net.packet.client.CharacterRequestBypass;
import com.l2jserver.game.net.packet.client.CharacterRequestInventoryPacket;
import com.l2jserver.game.net.packet.client.CharacterRequestMovePacket;
import com.l2jserver.game.net.packet.client.CharacterSelectPacket;
@@ -166,6 +170,14 @@ public class Lineage2PacketReader extends OneToOneDecoder {
return CharacterActionPacket.class;
case CharacterRequestInventoryPacket.OPCODE:
return CharacterRequestInventoryPacket.class;
case AdminCommandPacket.OPCODE:
return AdminCommandPacket.class;
case CharacterRequestBypass.OPCODE:
return CharacterRequestBypass.class;
case CharacterAppearingPacket.OPCODE:
return CharacterAppearingPacket.class;
case CharacterRequestActionUse.OPCODE:
return CharacterRequestActionUse.class;
default:
logger.warn("Unknown opcode: 0x{}", Integer.toHexString(opcode));
break;

View File

@@ -0,0 +1,84 @@
/*
* 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.game.net.packet.client;
import java.util.StringTokenizer;
import org.jboss.netty.buffer.ChannelBuffer;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.service.admin.AdministratorService;
import com.l2jserver.service.game.spawn.NotSpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.util.BufferUtils;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Executes an administrator action
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AdminCommandPacket extends AbstractClientPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x74;
/**
* The admin service
*/
private final AdministratorService adminService;
private final SpawnService spawnService;
/**
* The command
*/
private String command;
@Inject
public AdminCommandPacket(AdministratorService adminService,
SpawnService spawnService) {
this.adminService = adminService;
this.spawnService = spawnService;
}
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
command = BufferUtils.readString(buffer).trim();
}
@Override
public void process(final Lineage2Connection conn) {
final StringTokenizer tokenizer = new StringTokenizer(command, " ");
final String cmd = tokenizer.nextToken();
if (cmd.equals("tele")) {
Coordinate coord = Coordinate.fromXYZ(
Integer.parseInt(tokenizer.nextToken()),
Integer.parseInt(tokenizer.nextToken()),
Integer.parseInt(tokenizer.nextToken()));
try {
spawnService.teleport(conn.getCharacter(), coord);
} catch (NotSpawnedServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// TODO implement admin commands
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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.game.net.packet.client;
import org.jboss.netty.buffer.ChannelBuffer;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.service.game.character.CharacterService;
/**
* Completes the creation of an character. Creates the object, inserts into the
* database and notifies the client about the status of the operation.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterAppearingPacket extends AbstractClientPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x3a;
/**
* The {@link CharacterService}
*/
private final CharacterService charService;
@Inject
public CharacterAppearingPacket(CharacterService charService) {
this.charService = charService;
}
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
}
@Override
public void process(final Lineage2Connection conn) {
charService.appearing(conn.getCharacter());
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.game.net.packet.client;
import java.util.StringTokenizer;
import org.jboss.netty.buffer.ChannelBuffer;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.id.object.NPCID;
import com.l2jserver.model.id.object.provider.ObjectIDResolver;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.game.npc.ActionServiceException;
import com.l2jserver.service.game.npc.NPCService;
import com.l2jserver.util.BufferUtils;
/**
* Executes an bypass command
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterRequestBypass extends AbstractClientPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x23;
/**
* The {@link ObjectID} resolver
*/
private final ObjectIDResolver idResolver;
/**
* The {@link NPC} service
*/
private final NPCService npcService;
/**
* The bypass command
*/
private String command;
@Inject
public CharacterRequestBypass(ObjectIDResolver idResolver,
NPCService npcService) {
this.idResolver = idResolver;
this.npcService = npcService;
}
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
this.command = BufferUtils.readString(buffer);
}
@Override
public void process(final Lineage2Connection conn) {
// parse command
final StringTokenizer tokenizer = new StringTokenizer(command, "_ ");
final String type = tokenizer.nextToken();
if (type.equals("npc")) {
final int objectId = Integer.parseInt(tokenizer.nextToken());
final ObjectID<NPC> id = idResolver.resolve(objectId);
if (!(id instanceof NPCID)) {
conn.sendActionFailed();
return;
}
final NPC npc = id.getObject();
try {
npcService.action(npc, conn.getCharacter(),
createArgumentArray(tokenizer));
} catch (ActionServiceException e) {
conn.sendActionFailed();
}
}
}
private String[] createArgumentArray(StringTokenizer tokenizer) {
if (!tokenizer.hasMoreTokens())
return new String[0];
final String[] args = new String[tokenizer.countTokens()];
int i = 0;
while (tokenizer.hasMoreTokens()) {
args[i++] = tokenizer.nextToken();
}
return args;
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.game.net.packet.server;
import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.model.world.L2Character;
/**
* This is an message informing the client of extra informations from a player
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterInformationExtraPacket extends AbstractServerPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0xfe;
/**
* The character
*/
private L2Character character;
public CharacterInformationExtraPacket(L2Character character) {
super(OPCODE);
this.character = character;
}
@Override
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
buffer.writeShort(0xcf); // opcode2
buffer.writeInt(character.getID().getID()); // object ID of Player
buffer.writeInt(0x00); // event effect id
}
}

View File

@@ -239,7 +239,7 @@ public class CharacterInformationPacket extends AbstractServerPacket {
buffer.writeInt(character.getAppearance().getHairStyle().option);
buffer.writeInt(character.getAppearance().getHairColor().option);
buffer.writeInt(character.getAppearance().getFace().option);
buffer.writeInt(0x00); // is gm
buffer.writeInt(0x01); // is gm
String title = "Testing"; // title
BufferUtils.writeString(buffer, title);

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction;
import com.l2jserver.game.net.packet.server.NPCHtmlMessagePacket;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.id.template.NPCTemplateID;
@@ -100,12 +99,12 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> {
*
* @param character
* the interacting character
* @param action
* the action performed
* @param args
* the action arguments
* @throws L2Exception
* any {@link L2Exception}
*/
public void action(NPC npc, L2Character character, CharacterAction action)
public void action(NPC npc, L2Character character, String... args)
throws L2Exception {
final Lineage2Connection conn = networkService.discover(character
.getID());

View File

@@ -16,23 +16,139 @@
*/
package com.l2jserver.model.template.npc;
import java.util.List;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.server.NPCHtmlMessagePacket;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.game.spawn.NotSpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.exception.L2Exception;
import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.html.markup.HtmlTemplate;
import com.l2jserver.util.html.markup.MarkupTag;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class TeleporterNPCTemplate extends NPCTemplate {
// TOWNS
public static final Coordinate GLUDIN = Coordinate.fromXYZ(-80684, 149770,
-3040);
public static final Coordinate GLUDIO = Coordinate.fromXYZ(-12787, 122779,
-3112);
public static final Coordinate SCHUTTGART = Coordinate.fromXYZ(87126,
-143520, -1288);
// VILLAGES
public static final Coordinate DARK_ELF_VILLAGE = Coordinate.fromXYZ(9709,
15566, -4568);
public static final Coordinate DWARVEN_VILLAGE = Coordinate.fromXYZ(115120,
-178224, -880);
public static final Coordinate ELVEN_VILLAGE = Coordinate.fromXYZ(46951,
51550, -2976);
public static final Coordinate ORC_VILLAGE = Coordinate.fromXYZ(-45158,
-112583, -240);
public static final Coordinate KAMAEL_VILLAGE = Coordinate.fromXYZ(-117251,
46771, 360);
public static final Coordinate TALKING_ISLAND_VILLAGE = Coordinate.fromXYZ(
-84141, 244623, -3728);
public static final Coordinate TALKING_ISLAND_NORTHERN_TERRITORY = Coordinate
.fromXYZ(-106696, 214691, -3424);
// TERRITORIES
public static final Coordinate ELVEN_RUINS = Coordinate.fromXYZ(-112367,
234703, -3688);
public static final Coordinate SINGING_WATERFALL = Coordinate.fromXYZ(
-111728, 244330, -3448);
public static final Coordinate OBELISK_OF_VICTORY = Coordinate.fromXYZ(
-99586, 237637, -3568);
public static final Coordinate IMMORTAL_PLATEAU = Coordinate.fromXYZ(
-10983, -117484, -2464);
public static final Coordinate IMMORTAL_PLATEAU_SOUTHERN_REGION = Coordinate
.fromXYZ(-4190, -80040, -2696);
public static final Coordinate FROZEN_WATERFALL = Coordinate.fromXYZ(8652,
-139941, -1144);
public static final Coordinate CAVE_OF_TRIALS = Coordinate.fromXYZ(9340,
-112509, -2536);
@Inject
protected SpawnService spawnService;
/**
* The list of all possible teleportation locations
*/
protected final List<TeleportationMetadata> locations = CollectionFactory
.newList();
/**
* Creates a new instance of this template
*
* @param id
* the template id
* @param race
* the npc race
*/
protected TeleporterNPCTemplate(NPCTemplateID id) {
super(id);
}
@Override
public void action(NPC npc, L2Character character, String... args)
throws L2Exception {
talk(npc, character, args);
}
public void talk(NPC npc, L2Character character, String... args)
throws NotSpawnedServiceException {
final Lineage2Connection conn = networkService.discover(character
.getID());
if (args.length == 0) {
final HtmlTemplate template = new HtmlTemplate() {
@Override
protected void build(MarkupTag body) {
body.textcode(556).br().br();
// TODO this should not be hard coded!
int i = 0;
for (final TeleportationMetadata location : locations) {
body.addLink(
location.name + " - " + location.price
+ " Adena",
"npc_${npcid}_teleport " + i++).br();
}
}
};
template.register("npcid", String.valueOf(npc.getID().getID()));
conn.write(new NPCHtmlMessagePacket(npc, template));
} else if (args[0].equals("teleport")) {
final int location = Integer.parseInt(args[1]);
final TeleportationMetadata metadata = locations.get(location);
if (metadata == null) {
conn.sendActionFailed();
return;
}
spawnService.teleport(character, metadata.point);
}
conn.sendActionFailed();
}
protected void addLocation(String name, Coordinate coordinate, int price) {
this.locations.add(new TeleportationMetadata(name, coordinate, price));
}
protected static class TeleportationMetadata {
public final String name;
public final Coordinate point;
public final int price;
public TeleportationMetadata(String name, Coordinate point, int price) {
this.name = name;
this.point = point;
this.price = price;
}
}
}

View File

@@ -98,17 +98,12 @@ public class L2Character extends Player {
// ////////////////////////////////////
// / RUNTIME
// ////////////////////////////////////
/**
* The character walk mode.
* <p>
* This field is not persisted.
*/
private CharacterMoveType moveType = CharacterMoveType.WALK;
/**
* The character target, if any.
*/
private ActorID<?> targetID;
/**
* The character walking mode
@@ -125,6 +120,19 @@ public class L2Character extends Player {
}
}
/**
* The character target, if any.
*/
private ActorID<?> targetID;
/**
* State if the player is being teleported
*/
private CharacterState state;
public enum CharacterState {
TELEPORTING;
}
/**
* Creates a new instance
*
@@ -298,6 +306,28 @@ public class L2Character extends Player {
this.targetID = target;
}
/**
* @return the state
*/
public CharacterState getState() {
return state;
}
/**
* @param state
* the state to set
*/
public void setState(CharacterState state) {
this.state = state;
}
/**
* @return true if character is being teleported
*/
public boolean isTeleporting() {
return state == CharacterState.TELEPORTING;
}
/**
* @return the inventory
*/

View File

@@ -52,7 +52,7 @@ public class CharacterMoveEvent implements CharacterEvent {
}
/**
* @return the point
* @return the new point
*/
public Point getPoint() {
return point;

View File

@@ -20,11 +20,12 @@ import com.l2jserver.model.world.Player;
import com.l2jserver.util.dimensional.Point;
/**
* Event dispatched once an player is teleported to another location
* Event dispatched once an player has completed its teleportation to another
* location
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class PlayerTeleportEvent extends PlayerSpawnEvent {
public class PlayerTeleportedEvent extends PlayerSpawnEvent {
/**
* Creates a new instance
*
@@ -33,7 +34,7 @@ public class PlayerTeleportEvent extends PlayerSpawnEvent {
* @param point
* the teleport point
*/
public PlayerTeleportEvent(Player player, Point point) {
public PlayerTeleportedEvent(Player player, Point point) {
super(player, point);
}
}

View File

@@ -0,0 +1,76 @@
/*
* 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.model.world.player.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.util.dimensional.Point;
/**
* Event dispatched once an player has started his teleported to another
* location
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class PlayerTeleportingEvent implements PlayerEvent {
private final Player player;
private final Point point;
/**
* Creates a new instance
*
* @param player
* the teleported player
* @param point
* the teleport point
*/
public PlayerTeleportingEvent(Player player, Point point) {
this.player = player;
this.point = point;
}
@Override
public Actor getActor() {
return player;
}
@Override
public WorldObject getObject() {
return player;
}
@Override
public Player getPlayer() {
return player;
}
/**
* The point to which this player was teleported.
*
* @return the teleported point
*/
public Point getPoint() {
return point;
}
@Override
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { player.getID() };
}
}

View File

@@ -0,0 +1,48 @@
/*
* 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.admin;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.Service;
/**
* This service handles administrators in the server
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface AdministratorService extends Service {
/**
* Executes an command
*
* @param character
* the admin character
* @param command
* the command
* @param args
* the arguments
*/
void command(L2Character character, String command, String... args);
/**
* The base interface for Administrator commands
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface AdministratorCommand {
void administrator(L2Character character, String... args);
}
}

View File

@@ -16,13 +16,21 @@
*/
package com.l2jserver.service.admin;
import com.l2jserver.service.Service;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.AbstractService;
/**
* This service handles administrators in the server
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public interface AdminService extends Service {
public class AdministratorServiceImpl extends AbstractService implements
AdministratorService {
@Override
public void command(L2Character character, String command, String... args) {
if(command.equals("log")) {
if(args.length == 2) {
}
}
}
}

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.service.admin;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.Service;
/**
@@ -24,5 +25,9 @@ import com.l2jserver.service.Service;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface GMService extends Service {
void command(L2Character character, String command, String... args);
public interface GMCommand {
void gm(L2Character character, String... args);
}
}

View File

@@ -37,6 +37,7 @@ public class Log4JLoggingService extends AbstractService implements
private Logger rootLogger;
private Logger l2jLogger;
private Logger scriptLogger;
private Logger nettyLogger;
@Override
protected void doStart() throws ServiceStartException {
@@ -47,6 +48,7 @@ public class Log4JLoggingService extends AbstractService implements
rootLogger = Logger.getRootLogger();
l2jLogger = Logger.getLogger("com.l2jserver");
scriptLogger = Logger.getLogger("script");
nettyLogger = Logger.getLogger("org.jboss.netty");
rootLogger.removeAllAppenders();
rootLogger.setLevel(Level.WARN);
@@ -54,6 +56,7 @@ public class Log4JLoggingService extends AbstractService implements
l2jLogger.setLevel(Level.DEBUG);
scriptLogger.setLevel(Level.DEBUG);
nettyLogger.setLevel(Level.DEBUG);
}
@Override

View File

@@ -81,6 +81,16 @@ public interface CharacterService extends Service {
void attack(L2Character character, Actor target)
throws CannotSetTargetServiceException;
/**
* Informs that an given <tt>character</tt> is appearing in the world.
* <p>
* This is normally called after an teleport.
*
* @param character
* the character
*/
void appearing(L2Character character);
/**
* Jails the given <tt>character</tt> for <tt>time</tt> seconds.
*

View File

@@ -24,6 +24,7 @@ import com.l2jserver.game.net.SystemMessage;
import com.l2jserver.game.net.packet.server.ActionFailedPacket;
import com.l2jserver.game.net.packet.server.ActorChatMessagePacket;
import com.l2jserver.game.net.packet.server.ActorMovementPacket;
import com.l2jserver.game.net.packet.server.CharacterInformationExtraPacket;
import com.l2jserver.game.net.packet.server.CharacterInformationPacket;
import com.l2jserver.game.net.packet.server.CharacterInventoryPacket;
import com.l2jserver.game.net.packet.server.CharacterMovementTypePacket;
@@ -46,6 +47,7 @@ import com.l2jserver.model.world.character.event.CharacterMoveEvent;
import com.l2jserver.model.world.character.event.CharacterTargetDeselectedEvent;
import com.l2jserver.model.world.character.event.CharacterTargetSelectedEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportedEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.game.chat.ChatMessageDestination;
@@ -165,8 +167,21 @@ public class CharacterServiceImpl extends AbstractService implements
// TODO char broadcast
} else if (e instanceof CharacterMoveEvent) {
final CharacterMoveEvent evt = (CharacterMoveEvent) e;
if (object.equals(character))
return true;
conn.write(new ActorMovementPacket((L2Character) object,
evt.getPoint().getCoordinate()));
} else if (e instanceof PlayerTeleportedEvent) {
// TODO this should not be here!
System.out.println(((PlayerTeleportedEvent) e).getPoint()
.getCoordinate());
System.out.println(character.getPosition());
for (final WorldObject o : worldService
.iterable(new KnownListFilter(character))) {
if (o instanceof NPC) {
conn.write(new NPCInformationPacket((NPC) o));
}
}
}
// keep listener alive
return true;
@@ -202,6 +217,7 @@ public class CharacterServiceImpl extends AbstractService implements
// send this user information
conn.write(new CharacterInformationPacket(character));
conn.write(new CharacterInformationExtraPacket(character));
// TODO game guard enforcing
conn.write(new GameGuardQueryPacket());
conn.write(new CharacterInventoryPacket(character.getInventory()));
@@ -220,7 +236,6 @@ public class CharacterServiceImpl extends AbstractService implements
character))) {
if (o instanceof NPC) {
conn.write(new NPCInformationPacket((NPC) o));
// conn.write(new ServerObjectPacket((NPC) o));
}
}
@@ -300,6 +315,20 @@ public class CharacterServiceImpl extends AbstractService implements
}
}
@Override
public void appearing(L2Character character) {
Preconditions.checkNotNull(character, "character");
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
character.setState(null);
conn.write(new CharacterInformationPacket(character));
conn.write(new CharacterInformationExtraPacket(character));
eventDispatcher.dispatch(new PlayerTeleportedEvent(character, character
.getPoint()));
}
@Override
public void jail(L2Character character, long time, String reason)
throws CharacterInJailServiceException {
@@ -346,6 +375,10 @@ public class CharacterServiceImpl extends AbstractService implements
public void receivedValidation(L2Character character, Point point) {
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(point, "point");
if (character.isTeleporting())
// ignore while teleporting, for some reason the client sends a
// validation just before teleport packet
return;
character.setPoint(point);
eventDispatcher.dispatch(new CharacterMoveEvent(character, point));
}

View File

@@ -111,7 +111,6 @@ public class SimpleChatService extends AbstractService implements ChatService {
ChatBanActiveChatServiceException {
Preconditions.checkNotNull(sender, "sender");
Preconditions.checkNotNull(message, "message");
Preconditions.checkNotNull(extra, "extra");
final ChatChannel channel;
switch (chat) {

View File

@@ -42,6 +42,20 @@ public interface NPCService extends Service {
void action(NPC npc, L2Character character, CharacterAction action)
throws ActionServiceException;
/**
* Executes an action for an NPC. Each {@link NPCTemplate} have it's own
* actions.
*
* @param npc
* the npc
* @param character
* the character
* @param args
* the action arguments
*/
void action(NPC npc, L2Character character, String... args)
throws ActionServiceException;
/**
* Attacks an given NPC, if possible.
*

View File

@@ -39,7 +39,23 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
final NPCTemplate template = npc.getTemplate();
try {
template.action(npc, character, action);
template.action(npc, character, new String[0]);
} catch (L2Exception e) {
throw new ActionServiceException(e);
}
}
@Override
public void action(NPC npc, L2Character character, String... args)
throws ActionServiceException {
Preconditions.checkNotNull(npc, "npc");
Preconditions.checkNotNull(character, "character");
if (args == null)
args = new String[0];
final NPCTemplate template = npc.getTemplate();
try {
template.action(npc, character, args);
} catch (L2Exception e) {
throw new ActionServiceException(e);
}

View File

@@ -70,7 +70,7 @@ public class MapperPathingService extends AbstractService implements
private final WorldEventDispatcher eventDispatcher;
/**
* The database channel, will reamain open until service is stopped.
* The database channel, will remain open until service is stopped.
*/
private FileChannel channel;
@@ -102,6 +102,7 @@ public class MapperPathingService extends AbstractService implements
.fromCoordinate(point.getCoordinate());
try {
channel.write(struct.getByteBuffer());
channel.force(true);
} catch (IOException e1) {
log.warn("Error writing pathing file!", e1);
}

View File

@@ -19,7 +19,7 @@ package com.l2jserver.service.game.spawn;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportingEvent;
import com.l2jserver.service.Service;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
@@ -54,7 +54,7 @@ public interface SpawnService extends Service {
/**
* Teleports the object to the given <tt>point</tt>.
* <p>
* An {@link PlayerTeleportEvent} will be dispatched and the new position
* An {@link PlayerTeleportingEvent} will be dispatched and the new position
* will be broadcast to all clients.
*
* @param player

View File

@@ -25,12 +25,13 @@ import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.server.CharacterTeleportPacket;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterState;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportingEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.game.world.WorldService;
@@ -113,6 +114,7 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
public void teleport(Player player, Coordinate coordinate) {
Preconditions.checkNotNull(player, "player");
Preconditions.checkNotNull(coordinate, "coordinate");
System.out.println("teleport: "+coordinate);
player.setPosition(coordinate);
if (player instanceof L2Character) {
final Lineage2Connection conn = networkService
@@ -121,9 +123,10 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
// TODO throw an exception here
return;
conn.write(new CharacterTeleportPacket(conn.getCharacter()));
((L2Character) player).setState(CharacterState.TELEPORTING);
}
// dispatch teleport event
eventDispatcher.dispatch(new PlayerTeleportEvent(player, coordinate
eventDispatcher.dispatch(new PlayerTeleportingEvent(player, coordinate
.toPoint()));
// remember: broadcasting is done through events!
}

View File

@@ -200,7 +200,10 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
set = CollectionFactory.newSet();
listeners.put(id, set);
}
return set;
final Set<WorldListener> union = CollectionFactory.newSet();
union.addAll(set);
union.addAll(globalListeners);
return union;
}
public void stop() {

View File

@@ -0,0 +1,65 @@
/*
* 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.world.filter;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.util.factory.CollectionFactory;
/**
* And filter that accepts all values that are not in <tt>objects</tt>
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
* @param <O>
* the object type
*/
public class ExcludeFilter<O extends WorldObject> implements
WorldObjectFilter<O> {
/**
* The objects to be exluded
*/
private Set<WorldObject> objects = CollectionFactory.newSet();
/**
* Creates a new instance
*
* @param objects
* the excluded objects
*/
public ExcludeFilter(WorldObject... objects) {
Collections.addAll(this.objects, objects);
}
/**
* Creates a new instance
*
* @param objects
* the excluded objects
*/
public ExcludeFilter(Collection<WorldObject> objects) {
this.objects.addAll(objects);
}
@Override
public boolean accept(O object) {
return objects.contains(object);
}
}

View File

@@ -27,7 +27,7 @@ import com.l2jserver.service.game.world.filter.AndFilter;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class KnownListFilter extends AndFilter<Positionable> {
public static final int KNOWNLIST_RANGE = 200;
public static final int KNOWNLIST_RANGE = 2000;
@SuppressWarnings("unchecked")
public KnownListFilter(Positionable object) {

View File

@@ -91,6 +91,17 @@ public class MarkupTag {
return this;
}
/**
* Adds an internal text from an code
*
* @param text
* the text
* @return this {@link MarkupTag}
*/
public MarkupTag textcode(int code) {
return text("&$" + Integer.toString(code) + ";");
}
/**
* Adds a plain text to the tag, use the color formatting.
*