mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-08 08:23:11 +00:00
DAO abstractions and updated 'npc' sql file
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -20,16 +20,15 @@ import org.jboss.netty.buffer.ChannelBuffer;
|
||||
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.AbstractServerPacket;
|
||||
import com.l2jserver.game.net.packet.server.CharacterCreateFailPacket.Reason;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
|
||||
/**
|
||||
* This packet notifies the client that the chosen character has been
|
||||
* successfully selected.
|
||||
* This packet notifies the client that the character is moving to an certain
|
||||
* point. If the {@link Actor} moving is the same as the client connected, the
|
||||
* client will send position validations at specific time intervals.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @see Reason
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a> O
|
||||
*/
|
||||
public class ActorMovementPacket extends AbstractServerPacket {
|
||||
/**
|
||||
@@ -42,26 +41,26 @@ public class ActorMovementPacket extends AbstractServerPacket {
|
||||
*/
|
||||
private final Actor actor;
|
||||
/**
|
||||
* The source target
|
||||
* The destination coordinate
|
||||
*/
|
||||
private Coordinate source;
|
||||
private Coordinate target;
|
||||
|
||||
public ActorMovementPacket(Actor actor, Coordinate source) {
|
||||
public ActorMovementPacket(Actor actor, Coordinate target) {
|
||||
super(OPCODE);
|
||||
this.actor = actor;
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
|
||||
buffer.writeInt(actor.getID().getID());
|
||||
|
||||
// source
|
||||
buffer.writeInt(source.getX());
|
||||
buffer.writeInt(source.getY());
|
||||
buffer.writeInt(source.getZ());
|
||||
|
||||
|
||||
// target
|
||||
buffer.writeInt(target.getX());
|
||||
buffer.writeInt(target.getY());
|
||||
buffer.writeInt(target.getZ());
|
||||
|
||||
// source
|
||||
buffer.writeInt(actor.getPoint().getX());
|
||||
buffer.writeInt(actor.getPoint().getY());
|
||||
buffer.writeInt(actor.getPoint().getZ());
|
||||
|
||||
@@ -74,9 +74,11 @@ public class NPCInformationPacket extends AbstractServerPacket {
|
||||
buffer.writeDouble(template.getAttackSpeedMultiplier());
|
||||
buffer.writeDouble(template.getCollisionRadius());
|
||||
buffer.writeDouble(template.getCollisionHeight());
|
||||
buffer.writeInt(template.getRightHand().getID()); // right hand weapon
|
||||
buffer.writeInt((template.getRightHand() != null ? template
|
||||
.getRightHand().getID() : 0x00));
|
||||
buffer.writeInt(0x00); // chest
|
||||
buffer.writeInt(template.getLeftHand().getID()); // left hand weapon
|
||||
buffer.writeInt((template.getLeftHand() != null ? template
|
||||
.getLeftHand().getID() : 0x00));
|
||||
buffer.writeByte(1); // name above char 1=true ... ??
|
||||
buffer.writeByte(0x00); // is running
|
||||
buffer.writeByte(0x00); // is in combat
|
||||
|
||||
@@ -30,10 +30,9 @@ public abstract class AbstractModel<T extends ID<?>> implements Model<T> {
|
||||
*/
|
||||
protected T id;
|
||||
/**
|
||||
* The database state. True inidicates that the object is on database, false
|
||||
* indicates it must be inserted.
|
||||
* The database object state
|
||||
*/
|
||||
protected boolean inDatabase;
|
||||
protected ObjectState state = ObjectState.NOT_STORED;
|
||||
|
||||
@Override
|
||||
public T getID() {
|
||||
@@ -46,6 +45,16 @@ public abstract class AbstractModel<T extends ID<?>> implements Model<T> {
|
||||
this.id = ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectState getObjectState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setObjectState(ObjectState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
@@ -70,14 +79,4 @@ public abstract class AbstractModel<T extends ID<?>> implements Model<T> {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInDatabase() {
|
||||
return inDatabase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIsInDatabase(boolean state) {
|
||||
inDatabase = state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,13 +35,17 @@ public interface Model<T extends ID<?>> {
|
||||
void setID(T ID);
|
||||
|
||||
/**
|
||||
* @return true if object is already inserted in the database
|
||||
* @return the database object state
|
||||
*/
|
||||
boolean isInDatabase();
|
||||
ObjectState getObjectState();
|
||||
|
||||
/**
|
||||
* @param state
|
||||
* the database state
|
||||
* the database object state to set
|
||||
*/
|
||||
void setIsInDatabase(boolean state);
|
||||
void setObjectState(ObjectState state);
|
||||
|
||||
public enum ObjectState {
|
||||
STORED, NOT_STORED, ORPHAN;
|
||||
}
|
||||
}
|
||||
|
||||
49
src/main/java/com/l2jserver/model/game/CharacterFriend.java
Normal file
49
src/main/java/com/l2jserver/model/game/CharacterFriend.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.game;
|
||||
|
||||
import com.l2jserver.model.AbstractModel;
|
||||
import com.l2jserver.model.id.FriendID;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
|
||||
/**
|
||||
* Represents a pair of two {@link CharacterID} whose characters are friends.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterFriend extends AbstractModel<FriendID> {
|
||||
public CharacterFriend(FriendID id) {
|
||||
this.setID(id);
|
||||
}
|
||||
|
||||
public CharacterID getCharacterID() {
|
||||
return id.getID1();
|
||||
}
|
||||
|
||||
public L2Character getCharacter() {
|
||||
return id.getID1().getObject();
|
||||
}
|
||||
|
||||
public CharacterID getFriendID() {
|
||||
return id.getID2();
|
||||
}
|
||||
|
||||
public L2Character getFriend() {
|
||||
return id.getID2().getObject();
|
||||
}
|
||||
}
|
||||
44
src/main/java/com/l2jserver/model/id/FriendID.java
Normal file
44
src/main/java/com/l2jserver/model/id/FriendID.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.id;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.l2jserver.model.game.CharacterFriend;
|
||||
import com.l2jserver.model.id.compound.AbstractCompoundID;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
|
||||
/**
|
||||
* Each {@link CharacterFriend} is identified by an {@link ID}.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class FriendID extends AbstractCompoundID<CharacterID, CharacterID> {
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param id1
|
||||
* the first id
|
||||
* @param id2
|
||||
* the second id
|
||||
*/
|
||||
@Inject
|
||||
public FriendID(@Assisted("id1") CharacterID id1,
|
||||
@Assisted("id2") CharacterID id2) {
|
||||
super(id1, id2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.id.compound;
|
||||
|
||||
import com.l2jserver.model.id.ID;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class AbstractCompoundID<T1, T2> extends ID<AbstractCompoundID<T1, T2>> {
|
||||
/**
|
||||
* The first ID
|
||||
*/
|
||||
private final T1 id1;
|
||||
/**
|
||||
* The second ID
|
||||
*/
|
||||
private final T2 id2;
|
||||
|
||||
/**
|
||||
* @param id1
|
||||
* @param id2
|
||||
*/
|
||||
protected AbstractCompoundID(T1 id1, T2 id2) {
|
||||
super(null);
|
||||
this.id1 = id1;
|
||||
this.id2 = id2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the first id
|
||||
*/
|
||||
public T1 getID1() {
|
||||
return id1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the second id
|
||||
*/
|
||||
public T2 getID2() {
|
||||
return id2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractCompoundID<T1, T2> getID() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,6 @@ public final class CharacterID extends ActorID<L2Character> {
|
||||
|
||||
@Override
|
||||
public L2Character getObject() {
|
||||
return characterDao.load(this);
|
||||
return characterDao.select(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@ public final class ClanID extends ObjectID<Clan> {
|
||||
|
||||
@Override
|
||||
public Clan getObject() {
|
||||
return clanDao.load(this);
|
||||
return clanDao.select(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@ public final class ItemID extends ObjectID<Item> {
|
||||
|
||||
@Override
|
||||
public Item getObject() {
|
||||
return itemDao.load(this);
|
||||
return itemDao.select(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,6 @@ public final class PetID extends ActorID<Pet> {
|
||||
|
||||
@Override
|
||||
public Pet getObject() {
|
||||
return petDao.load(this);
|
||||
return petDao.select(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.model.id.provider;
|
||||
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.l2jserver.model.id.ID;
|
||||
import com.l2jserver.model.id.compound.AbstractCompoundID;
|
||||
|
||||
/**
|
||||
* The ID factory is used to create instances of IDs. It will automatically make
|
||||
* sure the ID is free before allocating it.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface CompoundIDProvider<I1 extends ID<?>, I2 extends ID<?>, T extends AbstractCompoundID<I1, I2>> {
|
||||
/**
|
||||
* Creates the ID object for an <b>EXISTING</b> ID.
|
||||
*
|
||||
* @param id1
|
||||
* the first id
|
||||
* @param id2
|
||||
* the second id
|
||||
* @return the created compound {@link ID}
|
||||
*/
|
||||
T createID(@Assisted("id1") I1 id1, @Assisted("id2") I2 id2);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.id.provider;
|
||||
|
||||
import com.l2jserver.model.id.FriendID;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
|
||||
/**
|
||||
* Creates a new {@link FriendID}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface FriendIDProvider extends
|
||||
CompoundIDProvider<CharacterID, CharacterID, FriendID> {
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import com.l2jserver.model.id.ID;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface IDProvider<I, T extends ID<?>> {
|
||||
public interface IDProvider<I, T extends ID<I>> {
|
||||
/**
|
||||
* Creates the ID object for an <b>EXISTING</b> ID.
|
||||
*
|
||||
|
||||
@@ -68,6 +68,7 @@ public class IDProviderModule extends AbstractModule {
|
||||
// MISC OBJECTS
|
||||
install(new FactoryModuleBuilder().build(AccountIDProvider.class));
|
||||
install(new FactoryModuleBuilder().build(FortIDProvider.class));
|
||||
install(new FactoryModuleBuilder().build(FriendIDProvider.class));
|
||||
|
||||
// TEMPLATE IDS
|
||||
install(new FactoryModuleBuilder().build(ItemTemplateIDProvider.class));
|
||||
|
||||
@@ -45,13 +45,14 @@ public abstract class ActorTemplate<T extends Actor> extends
|
||||
*/
|
||||
protected double attackSpeedMultiplier = 1.0;
|
||||
|
||||
/**
|
||||
* The Actor maximum HP
|
||||
*/
|
||||
protected double maxHP;
|
||||
protected double HP;
|
||||
|
||||
/**
|
||||
* The Actor maximum MP
|
||||
*/
|
||||
protected double maxMP;
|
||||
protected double MP;
|
||||
|
||||
protected int level;
|
||||
|
||||
/**
|
||||
* The base attributes instance
|
||||
@@ -206,7 +207,7 @@ public abstract class ActorTemplate<T extends Actor> extends
|
||||
public double getRunSpeed() {
|
||||
return attributes.getRunSpeed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.l2jserver.model.template.ActorBaseAttributes#getWalkSpeed()
|
||||
|
||||
@@ -88,32 +88,71 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> implements
|
||||
*/
|
||||
protected double collisionHeight = 0;
|
||||
|
||||
// id idTemplate name serverSideName title serverSideTitle class
|
||||
// collision_radius collision_height level sex type attackrange hp mp hpreg
|
||||
// mpreg str con dex int wit men exp sp patk pdef matk mdef atkspd critical
|
||||
// aggro matkspd rhand lhand enchant walkspd runspd targetable show_name
|
||||
// dropHerbGroup basestats
|
||||
|
||||
/**
|
||||
* The NPC Sex
|
||||
*/
|
||||
protected ActorSex sex;
|
||||
/**
|
||||
* The NPC level
|
||||
*/
|
||||
protected int level;
|
||||
|
||||
/**
|
||||
* The NPC attack range
|
||||
*/
|
||||
protected int attackRange;
|
||||
|
||||
/**
|
||||
* The HP regeneration
|
||||
*/
|
||||
protected double hpRegeneration;
|
||||
/**
|
||||
* The MP regeneration
|
||||
*/
|
||||
protected double mpRegeneration;
|
||||
|
||||
/**
|
||||
* The NPC experience
|
||||
*/
|
||||
protected long experience;
|
||||
/**
|
||||
* The NPC sp
|
||||
*/
|
||||
protected long sp;
|
||||
|
||||
/**
|
||||
* The NPC agressive state
|
||||
*/
|
||||
protected boolean aggressive;
|
||||
|
||||
/**
|
||||
* Weapon or shield in NPC right hand
|
||||
*/
|
||||
protected ItemTemplateID rightHand;
|
||||
/**
|
||||
* Weapon or shield in NPC left hand
|
||||
*/
|
||||
protected ItemTemplateID leftHand;
|
||||
/**
|
||||
* Enchant level in NPC weapon
|
||||
*/
|
||||
protected int enchantLevel;
|
||||
|
||||
/**
|
||||
* True if NPC can be targetted
|
||||
*/
|
||||
protected boolean targetable;
|
||||
/**
|
||||
* True will display the NPC name
|
||||
*/
|
||||
protected boolean showName;
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
protected int dropHerbGroup;
|
||||
/**
|
||||
* Use base attributes
|
||||
*/
|
||||
protected boolean baseAttributes;
|
||||
|
||||
protected NPCTemplate(NPCTemplateID id) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.l2jserver.model.id.template.ActorTemplateID;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.actor.ActorEffects;
|
||||
import com.l2jserver.model.world.actor.ActorSkillContainer;
|
||||
import com.l2jserver.util.dimensional.Point;
|
||||
|
||||
/**
|
||||
* Abstract {@link Actor} class.
|
||||
@@ -108,9 +107,9 @@ public abstract class Actor extends PositionableObject {
|
||||
*/
|
||||
protected int hp;
|
||||
/**
|
||||
* The actor coordinate point
|
||||
* The actor MP
|
||||
*/
|
||||
protected Point point;
|
||||
protected int mp;
|
||||
/**
|
||||
* The currently effects active on the actor
|
||||
*/
|
||||
@@ -132,6 +131,21 @@ public abstract class Actor extends PositionableObject {
|
||||
this.hp = hp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mp
|
||||
*/
|
||||
public int getMP() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mp
|
||||
* the mp to set
|
||||
*/
|
||||
public void setMP(int mp) {
|
||||
this.mp = mp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the race
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,11 @@ import com.l2jserver.service.game.ai.AIScript;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class NPC extends Actor {
|
||||
public int oldId;
|
||||
public int tpl;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
|
||||
@@ -124,7 +124,9 @@ public class CharacterCalculatedAttributes implements ActorAttributes {
|
||||
|
||||
@Override
|
||||
public double getWalkSpeed() {
|
||||
return baseAttributes.getWalkSpeed();
|
||||
//FIXME this is a temporary work arround
|
||||
return getRunSpeed();
|
||||
//return baseAttributes.getWalkSpeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import com.l2jserver.model.game.CharacterFriend;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.iterator.WorldObjectIterator;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
@@ -30,7 +30,7 @@ import com.l2jserver.util.factory.CollectionFactory;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterFriendList implements Iterable<L2Character> {
|
||||
public class CharacterFriendList implements Iterable<CharacterFriend> {
|
||||
/**
|
||||
* The character
|
||||
*/
|
||||
@@ -39,8 +39,7 @@ public class CharacterFriendList implements Iterable<L2Character> {
|
||||
/**
|
||||
* The list of friends of this character
|
||||
*/
|
||||
private final Set<CharacterID> friends = CollectionFactory
|
||||
.newSet();
|
||||
private final Set<CharacterFriend> friends = CollectionFactory.newSet();
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
@@ -64,13 +63,15 @@ public class CharacterFriendList implements Iterable<L2Character> {
|
||||
*
|
||||
* @return an iterator with friend ids
|
||||
*/
|
||||
public Iterator<CharacterID> idIterator() {
|
||||
public Iterator<CharacterFriend> idIterator() {
|
||||
return friends.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<L2Character> iterator() {
|
||||
return new WorldObjectIterator<L2Character>(friends.iterator());
|
||||
public Iterator<CharacterFriend> iterator() {
|
||||
// return new WorldObjectIterator<L2Character>(friends.iterator());
|
||||
// FIXME
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +82,7 @@ public class CharacterFriendList implements Iterable<L2Character> {
|
||||
* @param list
|
||||
* the id list
|
||||
*/
|
||||
public void load(Collection<CharacterID> list) {
|
||||
public void load(Collection<CharacterFriend> list) {
|
||||
friends.addAll(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.l2jserver.service.game.npc.NPCServiceImpl;
|
||||
import com.l2jserver.service.game.pathing.MapperPathingService;
|
||||
import com.l2jserver.service.game.pathing.PathingService;
|
||||
import com.l2jserver.service.game.scripting.ScriptingService;
|
||||
import com.l2jserver.service.game.scripting.ScriptingServiceImpl;
|
||||
import com.l2jserver.service.game.scripting.PreCompiledScriptingService;
|
||||
import com.l2jserver.service.game.spawn.SpawnService;
|
||||
import com.l2jserver.service.game.spawn.SpawnServiceImpl;
|
||||
import com.l2jserver.service.game.template.ScriptTemplateService;
|
||||
@@ -78,7 +78,7 @@ public class ServiceModule extends AbstractModule {
|
||||
.in(Scopes.SINGLETON);
|
||||
bind(NetworkService.class).to(NettyNetworkService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
bind(ScriptingService.class).to(ScriptingServiceImpl.class).in(
|
||||
bind(ScriptingService.class).to(PreCompiledScriptingService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
bind(TemplateService.class).to(ScriptTemplateService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package com.l2jserver.service.database;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.Model;
|
||||
import com.l2jserver.model.id.ID;
|
||||
|
||||
/**
|
||||
* Abstract DAO implementations. Store an instance of {@link DatabaseService}.
|
||||
@@ -26,7 +28,8 @@ import com.google.inject.Inject;
|
||||
* @param <T>
|
||||
* the dao object type
|
||||
*/
|
||||
public abstract class AbstractDAO<T> implements DataAccessObject<T> {
|
||||
public abstract class AbstractDAO<T extends Model<?>, I extends ID<?>>
|
||||
implements DataAccessObject<T, I> {
|
||||
/**
|
||||
* The database service instance
|
||||
*/
|
||||
@@ -37,6 +40,19 @@ public abstract class AbstractDAO<T> implements DataAccessObject<T> {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(T object) {
|
||||
switch (object.getObjectState()) {
|
||||
case NOT_STORED:
|
||||
return insert(object);
|
||||
case STORED:
|
||||
return update(object);
|
||||
case ORPHAN:
|
||||
return delete(object);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the database service
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
*/
|
||||
package com.l2jserver.service.database;
|
||||
|
||||
import com.l2jserver.model.Model;
|
||||
import com.l2jserver.model.id.ID;
|
||||
import com.l2jserver.service.cache.IgnoreCaching;
|
||||
|
||||
/**
|
||||
* The DAO interface
|
||||
* <p>
|
||||
@@ -28,6 +32,53 @@ package com.l2jserver.service.database;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface DataAccessObject<T> {
|
||||
public interface DataAccessObject<O extends Model<?>, I extends ID<?>> {
|
||||
/**
|
||||
* Load the instance represented by <tt>id</tt> from the database
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
*/
|
||||
O select(I id);
|
||||
|
||||
/**
|
||||
* Save the instance to the database. If a new database entry was created
|
||||
* returns true.
|
||||
*
|
||||
* @param object
|
||||
* the object
|
||||
* @return true if the row was inserted or updated
|
||||
*/
|
||||
@IgnoreCaching
|
||||
boolean save(O object);
|
||||
|
||||
/**
|
||||
* Inserts the instance in the database.
|
||||
*
|
||||
* @param object
|
||||
* the object
|
||||
* @return true if the row was inserted
|
||||
*/
|
||||
@IgnoreCaching
|
||||
boolean insert(O object);
|
||||
|
||||
/**
|
||||
* Updates the instance in the database.
|
||||
*
|
||||
* @param object
|
||||
* the object
|
||||
* @return true if the row was updated
|
||||
*/
|
||||
@IgnoreCaching
|
||||
boolean update(O object);
|
||||
|
||||
/**
|
||||
* Deletes the instance in the database.
|
||||
*
|
||||
* @param object
|
||||
* the object
|
||||
* @return true if the row was deleted
|
||||
*/
|
||||
@IgnoreCaching
|
||||
boolean delete(O object);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
|
||||
for (final NPC npc : npcs) {
|
||||
spawnService.spawn(npc, null);
|
||||
}
|
||||
return null;
|
||||
return npcs;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,18 +42,19 @@ import com.l2jserver.service.game.scripting.scriptmanager.ScriptList;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* Default {@link ScriptingService} implementation
|
||||
* This alternative {@link ScriptingService} uses an cache to speed up the
|
||||
* server startup at the cost of not being capable of recompiling templates.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends(LoggingService.class)
|
||||
public class ScriptingServiceImpl extends AbstractService implements
|
||||
public class PreCompiledScriptingService extends AbstractService implements
|
||||
ScriptingService {
|
||||
/**
|
||||
* Logger for script context
|
||||
*/
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(ScriptingServiceImpl.class);
|
||||
.getLogger(PreCompiledScriptingService.class);
|
||||
|
||||
private final Injector injector;
|
||||
|
||||
@@ -63,7 +64,7 @@ public class ScriptingServiceImpl extends AbstractService implements
|
||||
private final Set<ScriptContext> contexts = CollectionFactory.newSet();
|
||||
|
||||
@Inject
|
||||
public ScriptingServiceImpl(Injector injector) {
|
||||
public PreCompiledScriptingService(Injector injector) {
|
||||
this.injector = injector;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user