1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-10 09:22:49 +00:00

ThreadService implementation

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-27 12:35:05 -03:00
parent 73f51e53c0
commit faec07b8d5
23 changed files with 532 additions and 85 deletions

View File

@@ -16,9 +16,11 @@
*/
package com.l2jserver.game.ai;
import com.google.inject.Inject;
import com.l2jserver.game.ai.desires.Desire;
import com.l2jserver.game.ai.desires.DesireQueue;
import com.l2jserver.model.world.Actor;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -26,14 +28,35 @@ import com.l2jserver.model.world.Actor;
* the {@link Actor} type for this {@link AI}
*/
public abstract class AI<T extends Actor> {
/**
* The desire queue for this AI
*/
protected DesireQueue desireQueue = new DesireQueue();
protected final T creature;
/**
* The actor controlled by this AI
*/
protected final T actor;
protected AI(T creature) {
this.creature = creature;
@Inject
protected WorldEventDispatcher eventDispatcher;
protected AI(T actor) {
this.actor = actor;
}
protected void handleDesire(Desire desire) {
desire.handleDesire(this);
/**
* Executes an AI tick
*/
protected void tick() {
Desire desire = desireQueue.poll();
handleDesire(desire);
}
/**
* Handles the given desire
*
* @param desire
* the desire
*/
protected abstract void handleDesire(Desire desire);
}

View File

@@ -16,7 +16,6 @@
*/
package com.l2jserver.game.ai.desires;
import com.l2jserver.game.ai.AI;
import com.l2jserver.model.world.Actor;
/**
@@ -43,11 +42,6 @@ public final class AttackDesire extends AbstractDesire {
this.target = target;
}
@Override
public void handleDesire(AI<?> ai) {
// TODO: Implement
}
@Override
public boolean equals(Object o) {
if (this == o)

View File

@@ -16,14 +16,8 @@
*/
package com.l2jserver.game.ai.desires;
import com.l2jserver.game.ai.AI;
/**
* This interface represents basic desire functions.<br>
* Each desire should implement {@link #handleDesire(com.l2jserver.game.ai.AI)}
* method with default behavior.<br>
* AI can override {@link com.l2jserver.game.ai.AI#handleDesire(Desire)} to
* implement custom behavior of desire.<br>
* This interface represents basic desire functions.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see com.l2jserver.game.ai.AI
@@ -31,15 +25,6 @@ import com.l2jserver.game.ai.AI;
* @see com.l2jserver.game.ai.desires.AbstractDesire
*/
public interface Desire extends Comparable<Desire> {
/**
* Invokes default desire action. AI can override invocation of this method
* to handle desire in it's own way
*
* @param ai
* actor that is doing this desire
*/
void handleDesire(AI<?> ai);
/**
* Returns hashcode for this object, must be overrided by child
*

View File

@@ -16,7 +16,6 @@
*/
package com.l2jserver.game.ai.desires;
import com.l2jserver.game.ai.AI;
import com.l2jserver.model.world.Actor;
import com.l2jserver.util.geometry.Point3D;
@@ -44,14 +43,6 @@ public final class MoveDesire extends AbstractDesire {
this.point = point;
}
@Override
public void handleDesire(AI<?> ai) {
// TODO: Implement
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o)
@@ -64,9 +55,6 @@ public final class MoveDesire extends AbstractDesire {
return point.equals(that.point);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return point.hashCode();

View File

@@ -25,6 +25,7 @@ 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.character.CannotSetTargetServiceException;
import com.l2jserver.service.game.npc.ActionServiceException;
import com.l2jserver.service.game.npc.NPCService;
import com.l2jserver.util.geometry.Coordinate;
@@ -97,6 +98,8 @@ public class CharacterActionPacket extends AbstractClientPacket {
npcService.action(npc, conn.getCharacter(), action);
} catch (ActionServiceException e) {
conn.sendActionFailed();
} catch (CannotSetTargetServiceException e) {
conn.sendActionFailed();
}
}
}

View File

@@ -27,6 +27,7 @@ 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.character.CannotSetTargetServiceException;
import com.l2jserver.service.game.npc.ActionServiceException;
import com.l2jserver.service.game.npc.NPCService;
import com.l2jserver.util.BufferUtils;
@@ -86,6 +87,8 @@ public class CharacterRequestBypass extends AbstractClientPacket {
createArgumentArray(tokenizer));
} catch (ActionServiceException e) {
conn.sendActionFailed();
} catch (CannotSetTargetServiceException e) {
conn.sendActionFailed();
}
}
}