1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-07 16:03:10 +00:00

Signed-off-by: Rogiel <rogiel@rogiel.com>

This commit is contained in:
2011-05-18 19:59:27 -03:00
parent 4c27add4ef
commit 9bb83652e4
242 changed files with 7180 additions and 4199 deletions

View File

@@ -18,6 +18,7 @@ package com.l2jserver.service.game;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.Service;
import com.l2jserver.util.dimensional.Coordinate;
/**
* This service manages {@link L2Character} instances
@@ -40,4 +41,30 @@ public interface CharacterService extends Service {
* the character
*/
void leaveWorld(L2Character character);
/**
* Moves the given <tt>character</tt> to <tt>coordinate</tt>
*
* @param character
* the character
* @param coordinate
* the coordinate
*/
void move(L2Character character, Coordinate coordinate);
/**
* Set the character to walking mode
*
* @param character
* the character
*/
void walk(L2Character character);
/**
* Set the character to run mode
*
* @param character
* the character
*/
void run(L2Character character);
}

View File

@@ -20,30 +20,36 @@ import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.client.CharacterChatMessagePacket.MessageDestination;
import com.l2jserver.game.net.packet.server.ActorChatMessagePacket;
import com.l2jserver.game.net.packet.server.ActorMovementPacket;
import com.l2jserver.game.net.packet.server.CharacterMovementTypePacket;
import com.l2jserver.game.net.packet.server.GameGuardQueryPacket;
import com.l2jserver.game.net.packet.server.InventoryPacket;
import com.l2jserver.game.net.packet.server.UserInformationPacket;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterMoveType;
import com.l2jserver.model.world.character.event.CharacterEnterWorldEvent;
import com.l2jserver.model.world.character.event.CharacterEvent;
import com.l2jserver.model.world.character.event.CharacterLeaveWorldEvent;
import com.l2jserver.model.world.character.event.CharacterListener;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.game.ai.AIService;
import com.l2jserver.service.game.chat.ChatService;
import com.l2jserver.service.game.chat.channel.ChatChannel;
import com.l2jserver.service.game.chat.channel.ChatChannelListener;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Default implementation for {@link CharacterService}.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Depends({ WorldService.class, ChatService.class, NetworkService.class })
@Depends({ WorldService.class, ChatService.class, NetworkService.class,
SpawnService.class, AIService.class })
public class CharacterServiceImpl extends AbstractService implements
CharacterService {
/**
@@ -67,15 +73,25 @@ public class CharacterServiceImpl extends AbstractService implements
*/
private final SpawnService spawnService;
// /**
// * The {@link AIService}
// */
// private final AIService aiService;
@Inject
public CharacterServiceImpl(WorldService worldService,
WorldEventDispatcher eventDispatcher, ChatService chatService,
NetworkService networkService, SpawnService spawnService) {
NetworkService networkService, SpawnService spawnService/*
* ,
* AIService
* aiService
*/) {
this.worldService = worldService;
this.eventDispatcher = eventDispatcher;
this.chatService = chatService;
this.networkService = networkService;
this.spawnService = spawnService;
// this.aiService = aiService;
}
@Override
@@ -123,6 +139,8 @@ public class CharacterServiceImpl extends AbstractService implements
conn.write(new GameGuardQueryPacket());
conn.write(new InventoryPacket(character.getInventory()));
run(character);
// dispatch enter world event
eventDispatcher.dispatch(new CharacterEnterWorldEvent(character));
@@ -130,10 +148,44 @@ public class CharacterServiceImpl extends AbstractService implements
spawnService.spawn(character);
}
@Override
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);
final Coordinate source = character.getPosition();
character.setPosition(coordinate);
conn.write(new ActorMovementPacket(character, source));
// we don't dispatch events here, they will be dispatched by
// CharacterValidatePositionPacket packets at fixed time intervals.
}
@Override
public void leaveWorld(L2Character character) {
if (!worldService.remove(character))
return;
eventDispatcher.dispatch(new CharacterLeaveWorldEvent(character));
}
@Override
public void walk(L2Character character) {
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
if (character.getMoveType() == CharacterMoveType.RUN) {
character.setMoveType(CharacterMoveType.WALK);
conn.broadcast(new CharacterMovementTypePacket(character));
}
}
@Override
public void run(L2Character character) {
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
if (character.getMoveType() == CharacterMoveType.WALK) {
character.setMoveType(CharacterMoveType.RUN);
conn.broadcast(new CharacterMovementTypePacket(character));
}
}
}

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 com.l2jserver.service.game.ai;
/**
* The AI Script interface. Scripts are not continuous executed. The service
* will call multiple times {@link #run(double)}. Each time will represent a
* tick and a bit of the job should be done in there.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface AIScript {
/**
* Start the AIScript. Will register required listeners and start tasks.
*/
void start();
/**
* Executes an AI operation.
* <p>
* <b>Please note</b> that <tt>time</tt> will almost never reach 1 second
* its usage is to determine how much time has been spent idle and to deal
* with it.
* <p>
* Instead of having a fixed "tick" time this method will be called at a
* random interval. This will make possible to use load balancers that can
* slow the "tick" once the server is in high load and reduce when the load
* is low.
*
* @param time
* the time elapsed since last call. In seconds
*/
void run(double time);
/**
* Stop the AIScript. Will unregister the listeners that were registered in
* {@link #start()} and during life time.
*/
void stop();
}

View File

@@ -0,0 +1,38 @@
/*
* 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.ai;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.Service;
import com.l2jserver.util.dimensional.Coordinate;
/**
* This service executes AI operations
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface AIService extends Service {
/**
* Walks the given <tt>actor</tt> to <tt>coordinate</tt>
*
* @param actor
* the actor
* @param coordinate
* the coordinate
*/
void walk(Actor actor, Coordinate coordinate);
}

View File

@@ -0,0 +1,82 @@
/*
* 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.ai;
import com.google.inject.Inject;
import com.l2jserver.model.world.capability.Actor;
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;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.service.threading.ThreadService;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Default implementation for {@link CharacterService}.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Depends({ WorldService.class, TemplateService.class, ThreadService.class,
NetworkService.class })
public class AIServiceImpl extends AbstractService implements AIService {
/**
* The {@link WorldService}
*/
private final WorldService worldService;
/**
* The {@link WorldService} event dispatcher
*/
private final WorldEventDispatcher eventDispatcher;
/**
* The {@link ThreadService}
*/
private final ThreadService threadService;
/**
* The {@link NetworkService}
*/
private final NetworkService networkService;
@Inject
public AIServiceImpl(WorldService worldService,
WorldEventDispatcher eventDispatcher, ThreadService threadService,
NetworkService networkService) {
this.worldService = worldService;
this.eventDispatcher = eventDispatcher;
this.threadService = threadService;
this.networkService = networkService;
}
@Override
protected void doStart() throws ServiceStartException {
}
@Override
public void walk(Actor actor, Coordinate coordinate) {
}
@Override
protected void doStop() throws ServiceStopException {
}
}

View File

@@ -0,0 +1,27 @@
/*
* 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.ai.script;
import com.l2jserver.model.world.capability.Attackable;
import com.l2jserver.service.game.ai.AIScript;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a
*/
public interface AttackAIScript extends AIScript {
void attack(Attackable target);
}

View File

@@ -0,0 +1,35 @@
/*
* 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.ai.script;
import com.l2jserver.model.world.capability.Positionable;
/**
* This AI is used to receive notifications once another object aproaches.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ProximityAIScript {
/**
* Invoked once another object moves in proximity or the object suddenly
* appears.
*
* @param object
* the object
*/
void approach(Positionable object);
}

View File

@@ -0,0 +1,30 @@
/*
* 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.ai.script;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.service.game.ai.AIScript;
import com.l2jserver.util.dimensional.Coordinate;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a
*/
public interface WalkingAIScript extends AIScript {
void walk(Coordinate coord);
void follow(Positionable positionable);
}

View File

@@ -0,0 +1,38 @@
/*
* 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.effect;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.Service;
/**
* The effect service will handle
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface EffectService extends Service {
/**
* Adds a new effect to an given <tt>character</tt>. The effect will last
* <tt>duration</tt> milliseconds.
*
* @param character
* the character
* @param duration
* the effect duration in milliseconds
*/
void addEffect(L2Character character, long duration);
}

View File

@@ -19,6 +19,7 @@ package com.l2jserver.service.game.world;
import java.util.Iterator;
import java.util.List;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.Service;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
@@ -55,6 +56,19 @@ public interface WorldService extends Service, Iterable<WorldObject> {
*/
boolean contains(WorldObject object);
/**
* Locates the object with the given <tt>id</tt>
*
* @param <T>
* the object type
* @param id
* the object id
* @return the found object
* @throws ClassCastException
* if object found is not an instance of <tt>T</tt>
*/
<T extends WorldObject> T find(ObjectID<T> id) throws ClassCastException;
/**
* Get the event dispatcher
*

View File

@@ -24,6 +24,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
@@ -35,6 +36,7 @@ import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.game.world.filter.FilterIterator;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
import com.l2jserver.service.game.world.filter.impl.IDFilter;
import com.l2jserver.service.game.world.filter.impl.InstanceFilter;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.util.factory.CollectionFactory;
@@ -90,6 +92,17 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
return objects.contains(object);
}
@Override
@SuppressWarnings("unchecked")
public <T extends WorldObject> T find(ObjectID<T> id) {
final IDFilter filter = new IDFilter(id);
for (final WorldObject object : objects) {
if (filter.accept(object))
return (T) object;
}
return null;
}
@Override
public WorldEventDispatcher getEventDispatcher() {
return dispatcher;

View File

@@ -36,6 +36,19 @@ public interface WorldEventDispatcher {
*/
void dispatch(WorldEvent event);
/**
* Adds a new global <tt>listener</tt>
*
* @param <E>
* the event type
* @param <L>
* the listener type
* @param listener
* the listener
*/
<E extends WorldEvent, L extends WorldListener> void addListener(
WorldListener listener);
/**
* Adds a new <tt>listener</tt> to <tt>object</tt>
*

View File

@@ -86,11 +86,19 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
}
}
@Override
public void addListener(WorldListener listener) {
log.debug("Adding new listener global {}", listener);
listeners.add(new ListenerIDPair(null, listener));
}
@Override
public <E extends WorldEvent, L extends WorldListener> void addListener(
Listenable<L, E> object, WorldListener listener) {
log.debug("Adding new listener {} to {}", listener, object.getID());
listeners.add(new ListenerIDPair(object.getID(), listener));
log.debug("Adding new listener {} to {}", listener,
(object != null ? object.getID() : null));
listeners.add(new ListenerIDPair((object != null ? object.getID()
: null), listener));
}
@Override
@@ -125,6 +133,8 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
}
public boolean testDispatch(ObjectID<?> id) {
if (this.ID == null) // global listeners
return true;
return id.equals(this.ID);
}

View File

@@ -17,7 +17,7 @@
package com.l2jserver.service.game.world.filter.impl;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
/**
@@ -25,7 +25,7 @@ import com.l2jserver.service.game.world.filter.WorldObjectFilter;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class IDFilter implements WorldObjectFilter<Positionable> {
public class IDFilter implements WorldObjectFilter<WorldObject> {
/**
* The object id
*/
@@ -42,7 +42,7 @@ public class IDFilter implements WorldObjectFilter<Positionable> {
}
@Override
public boolean accept(Positionable other) {
public boolean accept(WorldObject other) {
if (other == null)
return false;
return other.getID().equals(id);