1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-09 08:52:51 +00:00

Change-Id: If18611eb0a6296da808aead8f1da54be094db2a9

This commit is contained in:
rogiel
2011-04-29 20:17:45 -03:00
parent 43403d9a1e
commit 0662150229
48 changed files with 612 additions and 513 deletions

View File

@@ -4,6 +4,7 @@ import com.l2jserver.model.id.ObjectID;
/**
* This is an abstract object representing all the world objects in Lineage II.
*
* @author Rogiel
*/
public abstract class AbstractObject implements WorldObject {
@@ -16,4 +17,29 @@ public abstract class AbstractObject implements WorldObject {
public void setId(ObjectID id) {
this.id = id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AbstractObject other = (AbstractObject) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}

View File

@@ -54,4 +54,9 @@ public class Item extends AbstractObject implements Playable, Spawnable,
// TODO Auto-generated method stub
return null;
}
@Override
public void setPosition(Coordinate coord) {
}
}

View File

@@ -2,7 +2,7 @@ package com.l2jserver.model.world;
import com.l2jserver.model.id.CharacterID;
public class Character extends Player {
public class L2Character extends Player {
@Override
public CharacterID getId() {
return (CharacterID) super.getId();

View File

@@ -1,10 +1,30 @@
package com.l2jserver.model.world;
import com.l2jserver.model.world.capability.Child;
import com.l2jserver.model.world.capability.Summonable;
import com.l2jserver.util.Coordinate;
public class Pet extends Player implements Child<Character> {
public class Pet extends Player implements Child<L2Character>, Summonable {
@Override
public Character getParent() {
public L2Character getParent() {
return null;
}
@Override
public void teleport(Coordinate coordinate) {
// TODO Auto-generated method stub
}
@Override
public void summon(Coordinate coordinate) {
// TODO Auto-generated method stub
}
@Override
public boolean isSummoned() {
// TODO Auto-generated method stub
return false;
}
}

View File

@@ -1,94 +1,42 @@
package com.l2jserver.model.world;
import java.util.List;
import com.l2jserver.model.template.SkillTemplate;
import com.l2jserver.model.world.capability.Attackable;
import com.l2jserver.model.world.capability.Attacker;
import com.l2jserver.model.world.capability.Castable;
import com.l2jserver.model.world.capability.Caster;
import com.l2jserver.model.world.capability.Levelable;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Parent;
import com.l2jserver.model.world.capability.Playable;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.player.PlayerEvent;
import com.l2jserver.model.world.player.PlayerListener;
import com.l2jserver.model.world.capability.Teleportable;
import com.l2jserver.model.world.player.PlayerTeleportEvent;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.factory.CollectionFactory;
/**
* {@link Player} is any object that can be controlled by the player. The most
* common implementation is {@link Character}.
* common implementation is {@link L2Character}.
*
* @author Rogiel
*/
public abstract class Player extends AbstractObject implements Playable,
Spawnable, Attacker, Attackable,
Listenable<PlayerListener, PlayerEvent>, Caster, Parent, Levelable {
private final List<PlayerListener> listeners = CollectionFactory
.newList(PlayerListener.class);
public abstract class Player extends AbstractActor implements Playable, Actor,
Teleportable, Parent {
protected Lineage2Connection connection;
@Override
public void spawn(Coordinate coordinate) {
public void teleport(Coordinate coordinate) {
final PlayerTeleportEvent event = new PlayerTeleportEvent(this, coordinate);
this.setPosition(coordinate);
event.dispatch();
}
@Override
public void attack(Attackable target,
com.l2jserver.model.template.capability.Attackable weapon) {
/**
* @return the connection
*/
public Lineage2Connection getConnection() {
return connection;
}
@Override
public void receiveAttack(Attacker attacker,
com.l2jserver.model.template.capability.Attackable weapon) {
}
@Override
public void addListener(PlayerListener listener) {
listeners.add(listener);
}
@Override
public void removeListener(PlayerListener listener) {
listeners.remove(listener);
}
@Override
public void dispatch(PlayerEvent e) {
for (final PlayerListener listener : listeners) {
listener.dispatch(e);
}
}
@Override
public Coordinate getPosition() {
// TODO Auto-generated method stub
return null;
}
@Override
public void cast(SkillTemplate skill, Castable cast) {
// TODO Auto-generated method stub
}
@Override
public boolean isSpawned() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getLevel() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setLevel(int level) {
// TODO Auto-generated method stub
/**
* @param connection
* the connection to set
*/
public void setConnection(Lineage2Connection connection) {
this.connection = connection;
}
}

View File

@@ -1,52 +0,0 @@
package com.l2jserver.model.world;
import java.util.Iterator;
import java.util.Set;
import com.l2jserver.model.world.event.WorldEventDispatcher;
import com.l2jserver.model.world.filter.WorldObjectFilter;
import com.l2jserver.model.world.iterator.FilterIterator;
import com.l2jserver.util.factory.CollectionFactory;
public class World implements Iterable<WorldObject> {
private final Set<WorldObject> objects = CollectionFactory
.newSet(WorldObject.class);
private final WorldEventDispatcher dispatcher = new WorldEventDispatcher(
this);
public void add(WorldObject object) {
objects.add(object);
}
public void remove(WorldObject object) {
objects.remove(object);
}
public boolean contains(WorldObject object) {
return objects.contains(object);
}
public WorldEventDispatcher getDispatcher() {
return dispatcher;
}
@Override
public Iterator<WorldObject> iterator() {
return objects.iterator();
}
public <T extends WorldObject> Iterator<T> iterator(
final WorldObjectFilter<T> filter) {
return new FilterIterator<T>(filter, objects.iterator());
}
public <T extends WorldObject> Iterable<T> iterable(
final WorldObjectFilter<T> filter) {
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return new FilterIterator<T>(filter, objects.iterator());
}
};
}
}

View File

@@ -8,5 +8,5 @@ import com.l2jserver.model.world.AbstractObject;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Conversable extends ObjectCapability {
void talk(Talker talker);
}

View File

@@ -1,12 +1,19 @@
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.Coordinate;
/**
* Defines an {@link AbstractObject} that can be dropped on the ground.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Dropable extends ObjectCapability {
void drop();
public interface Dropable extends Positionable {
/**
* When an item is dropped its position will be set as <tt>position</tt>
*
* @param position
* the position
*/
void drop(Coordinate position);
}

View File

@@ -10,4 +10,5 @@ import com.l2jserver.util.Coordinate;
*/
public interface Positionable extends ObjectCapability {
Coordinate getPosition();
void setPosition(Coordinate coord);
}

View File

@@ -1,7 +1,9 @@
package com.l2jserver.model.world.event;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.util.Coordinate;
public interface SpawnEvent extends WorldEvent {
Spawnable getObject();
Coordinate getCoordinate();
}

View File

@@ -1,16 +0,0 @@
package com.l2jserver.model.world.event;
import com.l2jserver.model.world.World;
public class WorldEventDispatcher {
private final World world;
public WorldEventDispatcher(World world) {
this.world = world;
}
public void dispatch(WorldEvent event) {
//TODO implement threaded model
event.dispatch();
}
}

View File

@@ -3,6 +3,7 @@ package com.l2jserver.model.world.item;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.player.PlayerEvent;
public class ItemDropEvent implements ItemEvent, PlayerEvent {
@@ -35,4 +36,9 @@ public class ItemDropEvent implements ItemEvent, PlayerEvent {
if (player != null)
player.dispatch(this);
}
@Override
public Actor getActor() {
return player;
}
}

View File

@@ -1,8 +1,8 @@
package com.l2jserver.model.world.player;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.event.WorldEvent;
import com.l2jserver.model.world.actor.ActorEvent;
public interface PlayerEvent extends WorldEvent {
public interface PlayerEvent extends ActorEvent {
Player getPlayer();
}

View File

@@ -1,6 +1,22 @@
package com.l2jserver.model.world.player;
import com.l2jserver.model.world.event.WorldListener;
import com.l2jserver.model.world.actor.ActorEvent;
import com.l2jserver.model.world.actor.ActorListener;
public interface PlayerListener extends WorldListener<PlayerEvent> {
public abstract class PlayerListener implements ActorListener {
@Override
public void dispatch(ActorEvent e) {
if (!(e instanceof PlayerEvent))
return;
dispatch((PlayerEvent) e);
}
/**
* Once the event call is dispatched, the listener <b>WILL NOT</b> be
* removed. You must manually remove it from the <tt>event</tt> object.
*
* @param e
* the event
*/
protected abstract void dispatch(PlayerEvent e);
}

View File

@@ -1,14 +1,24 @@
package com.l2jserver.model.world.player;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.util.Coordinate;
public class PlayerSpawnEvent implements PlayerEvent, SpawnEvent {
private final Player player;
private final Coordinate coordinate;
public PlayerSpawnEvent(Player player) {
public PlayerSpawnEvent(Player player, Coordinate coordinate) {
this.player = player;
this.coordinate = coordinate;
}
@Override
public void dispatch() {
if (player != null)
player.dispatch(this);
}
@Override
@@ -22,8 +32,12 @@ public class PlayerSpawnEvent implements PlayerEvent, SpawnEvent {
}
@Override
public void dispatch() {
if(player != null)
player.dispatch(this);
public Coordinate getCoordinate() {
return coordinate;
}
@Override
public Actor getActor() {
return player;
}
}