1
0
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:
2011-05-23 12:51:52 -03:00
parent 66d5fee187
commit 1909bb06cc
41 changed files with 42265 additions and 41874 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View 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();
}
}

View 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);
}
}

View File

@@ -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;
}
}

View File

@@ -41,6 +41,6 @@ public final class CharacterID extends ActorID<L2Character> {
@Override
public L2Character getObject() {
return characterDao.load(this);
return characterDao.select(this);
}
}

View File

@@ -41,6 +41,6 @@ public final class ClanID extends ObjectID<Clan> {
@Override
public Clan getObject() {
return clanDao.load(this);
return clanDao.select(this);
}
}

View File

@@ -41,6 +41,6 @@ public final class ItemID extends ObjectID<Item> {
@Override
public Item getObject() {
return itemDao.load(this);
return itemDao.select(this);
}
}

View File

@@ -40,6 +40,6 @@ public final class PetID extends ActorID<Pet> {
@Override
public Pet getObject() {
return petDao.load(this);
return petDao.select(this);
}
}

View 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.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);
}

View File

@@ -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> {
}

View File

@@ -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.
*

View File

@@ -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));

View File

@@ -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()

View File

@@ -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) {

View File

@@ -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
*/

View File

@@ -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
*

View File

@@ -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

View File

@@ -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);
}
}