mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-08 08:23:11 +00:00
41
src/main/java/com/l2jserver/Test.java
Normal file
41
src/main/java/com/l2jserver/Test.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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 Test {
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
final HtmlTemplate template = new HtmlTemplate("Notice") {
|
||||
@Override
|
||||
public void build(MarkupTag body) {
|
||||
body.text("This NPC is not yet implemented!").br();
|
||||
body.text("This NPC is not yet implemented!", "000000").br();
|
||||
body.text("This NPC is not yet implemented!", "ffffff").p();
|
||||
body.addLink("Click me!", "test");
|
||||
}
|
||||
};
|
||||
System.out.println(template.toHtmlString());
|
||||
}
|
||||
}
|
||||
@@ -278,7 +278,7 @@ public class CharacterInformationPacket extends AbstractServerPacket {
|
||||
buffer.writeShort(500); // inventory limit
|
||||
|
||||
buffer.writeInt(character.getCharacterClass().id);
|
||||
buffer.writeInt(0x01); // special effects? circles around player...
|
||||
buffer.writeInt(0x00); // special effects? circles around player...
|
||||
buffer.writeInt(200); // max cp
|
||||
buffer.writeInt(200); // cur cp
|
||||
buffer.writeByte(0x00); // is mount or is airshilhelp = 0; otherwise
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.l2jserver.game.net.packet.server.CharacterTargetSelectedPacket;
|
||||
import com.l2jserver.game.net.packet.server.GameGuardQueryPacket;
|
||||
import com.l2jserver.game.net.packet.server.NPCInformationPacket;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.L2Character.CharacterMoveType;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
@@ -119,9 +120,10 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
if (conn == null)
|
||||
return;
|
||||
if (!worldService.add(character))
|
||||
// TODO this should throw an exception
|
||||
// character is already in the world!
|
||||
return;
|
||||
|
||||
|
||||
itemDao.loadInventory(character);
|
||||
|
||||
// chat listener
|
||||
@@ -146,6 +148,8 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
// this listener will be filtered so that only interesting events are
|
||||
// dispatched, once a event arrives will be possible to check check if
|
||||
// the given event will be broadcasted or not
|
||||
// TODO this should not be here, it should be i world service or a newly
|
||||
// created broadcast service.
|
||||
final WorldListener broadcastListener = new FilteredWorldListener<Positionable>(
|
||||
new KnownListFilter(character)) {
|
||||
@Override
|
||||
@@ -206,7 +210,8 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
run(character);
|
||||
|
||||
// broadcast knownlist -- trashy implementation
|
||||
// TODO should be moved to world service
|
||||
// TODO should be moved to world service or a newly created broadcast
|
||||
// service, whichever fits the purpose
|
||||
for (final WorldObject o : worldService.iterable(new KnownListFilter(
|
||||
character))) {
|
||||
if (o instanceof NPC) {
|
||||
@@ -226,21 +231,22 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
public void move(L2Character character, Coordinate coordinate) {
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
// for now, let's just write the packet
|
||||
// aiService.walk(character, coordinate);
|
||||
// we don't set the character coordinate here, this will be done by
|
||||
// validation packets, sent by client
|
||||
|
||||
final Coordinate source = character.getPosition();
|
||||
// we don't set the character coordinate yet, this will be done by
|
||||
// validate coordinate
|
||||
// for now, let's just write the packet, we don't have much validation
|
||||
// to be done yet. With character validation packet, another packet of
|
||||
// these will be broadcasted.
|
||||
conn.write(new ActorMovementPacket(character, coordinate));
|
||||
// we don't dispatch events here, they will be dispatched by
|
||||
// receivedValidation at fixed time intervals.
|
||||
// with the same packet referred up here.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveWorld(L2Character character) {
|
||||
if (!worldService.remove(character))
|
||||
return;
|
||||
spawnService.unspawn(character);
|
||||
eventDispatcher.dispatch(new CharacterLeaveWorldEvent(character));
|
||||
}
|
||||
|
||||
@@ -250,21 +256,33 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
|
||||
if (target == null && character.getTargetID() != null) {
|
||||
// if is trying to select null (remove target) and the character has
|
||||
// an target, trigger an deselect
|
||||
final Actor oldTarget = character.getTarget();
|
||||
character.setTargetID(null);
|
||||
eventDispatcher.dispatch(new CharacterTargetDeselectedEvent(
|
||||
character, oldTarget));
|
||||
// TODO we need to send an packet here to inform of deselection
|
||||
} else if (target != null && !target.getID().equals(character.getID())) {
|
||||
// if new target is not null and the current character target is
|
||||
// null or different, trigger the selection.
|
||||
if (character.getTargetID() != null) {
|
||||
// first deselect old target
|
||||
eventDispatcher.dispatch(new CharacterTargetDeselectedEvent(
|
||||
character, character.getTarget()));
|
||||
}
|
||||
character.setTargetID(null);
|
||||
// now select the new target
|
||||
character.setTargetID(target.getID());
|
||||
eventDispatcher.dispatch(new CharacterTargetSelectedEvent(
|
||||
character, target));
|
||||
conn.write(new CharacterTargetSelectedPacket(target));
|
||||
} else {
|
||||
// this indicates an inconsistency, send an action failed and reset
|
||||
// target, i.e. deselect with no target
|
||||
// TODO instead of sending action failed, we should throw an
|
||||
// exception here
|
||||
conn.sendActionFailed();
|
||||
character.setTargetID(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,11 +293,15 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
// check if this Actor can be attacked
|
||||
if (target instanceof NPC) {
|
||||
final NPC npc = (NPC) target;
|
||||
if (!npc.getTemplate().isAttackable()) {
|
||||
final NPCTemplate template = npc.getTemplate();
|
||||
if (!template.isAttackable()) {
|
||||
conn.write(ActionFailedPacket.SHARED_INSTANCE);
|
||||
return;
|
||||
}
|
||||
// first try to target this, if it is not already
|
||||
target(character, target);
|
||||
|
||||
// TODO issue attack
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,19 +320,27 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
public void walk(L2Character character) {
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
// test if character is running
|
||||
if (character.getMoveType() == CharacterMoveType.RUN) {
|
||||
// if running set mode to walk and broadcast packet
|
||||
character.setMoveType(CharacterMoveType.WALK);
|
||||
conn.broadcast(new CharacterMovementTypePacket(character));
|
||||
// TODO dispatch move change type event
|
||||
}
|
||||
// TODO we need to throw an exception if character is not running
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(L2Character character) {
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
// test if character is walking
|
||||
if (character.getMoveType() == CharacterMoveType.WALK) {
|
||||
// if running walking mode to run and broadcast packet
|
||||
character.setMoveType(CharacterMoveType.RUN);
|
||||
conn.broadcast(new CharacterMovementTypePacket(character));
|
||||
// TODO dispatch move change type event
|
||||
}
|
||||
// TODO we need to throw an exception if character is not walking
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
point = spawnable.getPoint();
|
||||
if (point == null) {
|
||||
// not point send and no point stored, aborting
|
||||
// TODO this should throw an exception
|
||||
log.warn("Trying to spawn {} to a null point", spawnable);
|
||||
return;
|
||||
}
|
||||
@@ -87,6 +88,7 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
spawnable.setPoint(point);
|
||||
// register object in the world
|
||||
if (!worldService.add(spawnable))
|
||||
// TODO this should throw an exception
|
||||
// object was already in world
|
||||
return;
|
||||
|
||||
@@ -99,11 +101,11 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
event = null;
|
||||
}
|
||||
|
||||
// TODO throw an exception if event is null
|
||||
if (event != null)
|
||||
// dispatch spawn event
|
||||
eventDispatcher.dispatch(event);
|
||||
|
||||
// TODO broadcast this object to players nearby
|
||||
// remember: broadcasting is done through events!
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,13 +115,14 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
final Lineage2Connection conn = networkService
|
||||
.discover((CharacterID) player.getID());
|
||||
if (conn == null)
|
||||
// TODO throw an exception here
|
||||
return;
|
||||
conn.write(new CharacterTeleportPacket(conn.getCharacter()));
|
||||
}
|
||||
// dispatch teleport event
|
||||
eventDispatcher.dispatch(new PlayerTeleportEvent(player, coordinate
|
||||
.toPoint()));
|
||||
// TODO broadcast this player new position
|
||||
// remember: broadcasting is done through events!
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.service.game.CharacterService;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
||||
@@ -31,7 +30,7 @@ import com.l2jserver.service.threading.ThreadService;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
|
||||
/**
|
||||
* Default implementation for {@link CharacterService}.
|
||||
* Default implementation for {@link AIService}.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
|
||||
@@ -111,6 +111,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
if (filter.accept(object))
|
||||
return (T) object;
|
||||
}
|
||||
// TODO throw exception if object is not found
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user