1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-08 08:23:11 +00:00

Open map implemented

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-22 13:21:08 -03:00
parent 87ce7bb987
commit 0661b41cfd
31 changed files with 649 additions and 111 deletions

View File

@@ -19,6 +19,9 @@ package com.l2jserver.model.template;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.capability.Depositable;
import com.l2jserver.model.template.capability.Dropable;
@@ -27,6 +30,8 @@ import com.l2jserver.model.template.capability.Sellable;
import com.l2jserver.model.template.capability.Tradable;
import com.l2jserver.model.template.capability.Usable;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.network.NetworkService;
/**
* Template for an {@link Item}
@@ -40,6 +45,9 @@ public abstract class ItemTemplate extends AbstractTemplate<Item> {
private static final Logger log = LoggerFactory
.getLogger(ItemTemplate.class);
@Inject
protected NetworkService networkService;
protected int weight = 0;
protected int price = 0;
protected String icon;
@@ -68,6 +76,16 @@ public abstract class ItemTemplate extends AbstractTemplate<Item> {
return new Item(this.getID());
}
public final void use(Item item, L2Character character) {
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
this.use(item, character, conn);
}
protected void use(Item item, L2Character character, Lineage2Connection conn) {
conn.sendActionFailed();
}
public void stack(Item... object) {
}

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.model.template;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.server.NPCHtmlMessagePacket;
@@ -32,7 +33,6 @@ import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.calculator.Calculator;
import com.l2jserver.util.exception.L2Exception;
import com.l2jserver.util.html.markup.HtmlTemplate;
import com.l2jserver.util.html.markup.MarkupTag;
/**
* Template for {@link NPC}
@@ -106,6 +106,10 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> {
*/
public void action(NPC npc, L2Character character, String... args)
throws L2Exception {
Preconditions.checkNotNull(npc, "npc");
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(args, "args");
final Lineage2Connection conn = networkService.discover(character
.getID());
if (conn == null)
@@ -119,17 +123,40 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> {
return;
}
// generate not implemented message
final HtmlTemplate template = new HtmlTemplate(name) {
@Override
public void build(MarkupTag body) {
body.text("The NPC ${name} is not yet implemented!", "ff0000")
.p().p();
body.addLink("Click me!", "test");
if (args.length == 0 || args[0].equals("Chat"))
talk(npc, character, conn, args);
}
/**
* Talks with this NPC
*
* @param npc
* the npc
* @param character
* the character
* @param conn
* the lineage 2 connection
* @param args
* the action arguments
* @throws L2Exception
*/
public void talk(NPC npc, L2Character character, Lineage2Connection conn,
String... args) throws L2Exception {
if (args.length == 0 || (args.length >= 1 && args[0].equals("Chat"))) {
String name = "";
if (args.length == 2)
name = args[1];
final HtmlTemplate template = getChat(name);
if (template != null) {
template.register("npcid", npc.getID().getID());
conn.write(new NPCHtmlMessagePacket(npc, template));
}
};
template.register("name", name);
conn.write(new NPCHtmlMessagePacket(npc, template));
}
conn.sendActionFailed();
}
protected HtmlTemplate getChat(String name) throws L2Exception {
return null;
}
/**

View File

@@ -1,28 +0,0 @@
/*
* 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.template.capability;
import com.l2jserver.model.world.capability.Damagable;
/**
* Indicates that an template has the ability to intercept outgoing damage.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface OutgoingDamageIntercept extends TemplateCapability {
void interceptOutgoingDamage(Damagable target);
}

View File

@@ -19,7 +19,6 @@ package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.template.capability.Defendable;
import com.l2jserver.model.template.capability.IncomingDamageIntercept;
import com.l2jserver.model.world.Item;
/**
@@ -27,8 +26,7 @@ import com.l2jserver.model.world.Item;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ArmorTemplate extends ItemTemplate implements Defendable,
IncomingDamageIntercept {
public abstract class ArmorTemplate extends ItemTemplate implements Defendable {
public ArmorTemplate(ItemTemplateID id) {
super(id);
}

View File

@@ -14,16 +14,19 @@
* 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.template.capability;
package com.l2jserver.model.template.item;
import com.l2jserver.model.world.capability.Damagable;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Indicates that an template has the ability to intercept incoming damage.
* Template for general items {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public interface IncomingDamageIntercept extends TemplateCapability {
void interceptIncomingDamage(Damagable target);
public abstract class EtcItemTemplate extends ItemTemplate {
public EtcItemTemplate(ItemTemplateID id, String icon, ItemMaterial material) {
super(id, icon, material);
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.template.item;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.id.template.SkillTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.L2Character;
/**
* Template for general items {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class SkillEtcItemTemplate extends ItemTemplate {
protected SkillTemplateID skill;
public SkillEtcItemTemplate(ItemTemplateID id, String icon,
ItemMaterial material, SkillTemplateID skill) {
super(id, icon, material);
}
@Override
protected void use(Item item, L2Character character, Lineage2Connection conn) {
super.use(item, character, conn);
}
/**
* @return the skill
*/
public SkillTemplateID getSkill() {
return skill;
}
}

View File

@@ -18,6 +18,9 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.util.exception.L2Exception;
import com.l2jserver.util.html.markup.HtmlTemplate;
import com.l2jserver.util.html.markup.MarkupTag;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -35,4 +38,14 @@ public class MonsterNPCTemplate extends NPCTemplate {
protected MonsterNPCTemplate(NPCTemplateID id) {
super(id);
}
@Override
protected HtmlTemplate getChat(String name) throws L2Exception {
return new HtmlTemplate() {
@Override
protected void build(MarkupTag body) {
body.text("Sorry, but you can't interact with me yet.");
}
};
}
}

View File

@@ -20,7 +20,6 @@ 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;
@@ -100,40 +99,44 @@ public class TeleporterNPCTemplate extends NPCTemplate {
@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() {
if (args.length >= 2 && args[0].equals("goto")) {
teleport(npc, character, conn, args[1]);
}
super.action(npc, character, args);
}
@Override
protected HtmlTemplate getChat(String name) throws L2Exception {
if (name.equals("") || name.equals("teleport")) {
return 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();
+ " Adena", "npc_${npcid}_goto " + 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();
return super.getChat(name);
}
protected void teleport(NPC npc, L2Character character,
Lineage2Connection conn, String name)
throws NotSpawnedServiceException {
final int location = Integer.parseInt(name);
final TeleportationMetadata metadata = locations.get(location);
if (metadata == null) {
conn.sendActionFailed();
return;
}
spawnService.teleport(character, metadata.point);
}
protected void addLocation(String name, Coordinate coordinate, int price) {

View File

@@ -125,12 +125,12 @@ public class L2Character extends Player {
*/
private ActorID<?> targetID;
/**
* State if the player is being teleported
* State of the character. Will be null if it is idle
*/
private CharacterState state;
public enum CharacterState {
TELEPORTING;
TELEPORTING, CASTING, ATTACKING, MOVING;
}
/**

View File

@@ -0,0 +1,70 @@
/*
* 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.character.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
/**
* Event triggered once a character starts running
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterRunningEvent implements CharacterEvent {
/**
* The character that is logging in
*/
private final L2Character character;
/**
* Creates a new instance
*
* @param character
* the character
*/
public CharacterRunningEvent(L2Character character) {
this.character = character;
}
@Override
public Player getPlayer() {
return character;
}
@Override
public Actor getActor() {
return character;
}
@Override
public WorldObject getObject() {
return character;
}
@Override
public L2Character getCharacter() {
return character;
}
@Override
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { character.getID() };
}
}

View File

@@ -0,0 +1,70 @@
/*
* 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.character.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
/**
* Event triggered once a character starts walking
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterWalkingEvent implements CharacterEvent {
/**
* The character that is logging in
*/
private final L2Character character;
/**
* Creates a new instance
*
* @param character
* the character
*/
public CharacterWalkingEvent(L2Character character) {
this.character = character;
}
@Override
public Player getPlayer() {
return character;
}
@Override
public Actor getActor() {
return character;
}
@Override
public WorldObject getObject() {
return character;
}
@Override
public L2Character getCharacter() {
return character;
}
@Override
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { character.getID() };
}
}