mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-07 16:03:10 +00:00
DAO abstractions and updated 'npc' sql file
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
83128
dist/sql/npc.sql
vendored
83128
dist/sql/npc.sql
vendored
File diff suppressed because it is too large
Load Diff
@@ -33,15 +33,8 @@ import com.l2jserver.service.database.DataAccessObject;
|
||||
*
|
||||
* @author Rogiel
|
||||
*/
|
||||
public interface CharacterDAO extends DataAccessObject<L2Character>, Cacheable {
|
||||
/**
|
||||
* Load the instance represented by <tt>id</tt> from the database
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
*/
|
||||
L2Character load(CharacterID id);
|
||||
|
||||
public interface CharacterDAO extends
|
||||
DataAccessObject<L2Character, CharacterID>, Cacheable {
|
||||
/**
|
||||
* Load the members of the given <tt>clan</tt>
|
||||
*
|
||||
@@ -76,16 +69,4 @@ public interface CharacterDAO extends DataAccessObject<L2Character>, Cacheable {
|
||||
*/
|
||||
@IgnoreCaching
|
||||
List<CharacterID> listIDs();
|
||||
|
||||
/**
|
||||
* Save the instance to the database. If a new database entry was created
|
||||
* returns true.
|
||||
*
|
||||
* @param option
|
||||
* the id
|
||||
* @return true if created a new entry in database (i.e. insert), false if
|
||||
* not created (i.e. update)
|
||||
*/
|
||||
@IgnoreCaching
|
||||
boolean save(L2Character character);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
*/
|
||||
package com.l2jserver.db.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.game.CharacterFriend;
|
||||
import com.l2jserver.model.id.FriendID;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.CharacterFriendList;
|
||||
import com.l2jserver.service.cache.Cacheable;
|
||||
@@ -31,17 +30,8 @@ import com.l2jserver.service.database.DataAccessObject;
|
||||
*
|
||||
* @author Rogiel
|
||||
*/
|
||||
public interface CharacterFriendDAO extends DataAccessObject<CharacterID>,
|
||||
Cacheable {
|
||||
/**
|
||||
* Load the friend list for character represented by <tt>id</tt> from the
|
||||
* database
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
*/
|
||||
List<CharacterID> load(CharacterID id);
|
||||
|
||||
public interface CharacterFriendDAO extends
|
||||
DataAccessObject<CharacterFriend, FriendID>, Cacheable {
|
||||
/**
|
||||
* Load the friend list for character represented by <tt>character</tt> from
|
||||
* the database
|
||||
@@ -71,15 +61,4 @@ public interface CharacterFriendDAO extends DataAccessObject<CharacterID>,
|
||||
* @return true if at least 1 item was removed
|
||||
*/
|
||||
boolean delete(CharacterFriendList friends);
|
||||
|
||||
/**
|
||||
* Delete an <tt>friend</tt> from an <tt>character</tt>
|
||||
*
|
||||
* @param character
|
||||
* the character id
|
||||
* @param friend
|
||||
* the friend id
|
||||
* @return true if the item was removed
|
||||
*/
|
||||
boolean delete(CharacterID character, CharacterID friend);
|
||||
}
|
||||
|
||||
@@ -30,15 +30,7 @@ import com.l2jserver.service.database.DataAccessObject;
|
||||
*
|
||||
* @author Rogiel
|
||||
*/
|
||||
public interface ClanDAO extends DataAccessObject<Clan>, Cacheable {
|
||||
/**
|
||||
* Load the instance represented by <tt>id</tt> from the database
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
*/
|
||||
Clan load(ClanID id);
|
||||
|
||||
public interface ClanDAO extends DataAccessObject<Clan, ClanID>, Cacheable {
|
||||
/**
|
||||
* Loads an List of all {@link ID}s in the database
|
||||
*
|
||||
@@ -46,16 +38,4 @@ public interface ClanDAO extends DataAccessObject<Clan>, Cacheable {
|
||||
*/
|
||||
@IgnoreCaching
|
||||
List<ClanID> listIDs();
|
||||
|
||||
/**
|
||||
* Save the instance to the database. If a new database entry was created
|
||||
* returns true.
|
||||
*
|
||||
* @param option
|
||||
* the id
|
||||
* @return true if created a new entry in database (i.e. insert), false if
|
||||
* not created (i.e. update)
|
||||
*/
|
||||
@IgnoreCaching
|
||||
boolean save(Clan character);
|
||||
}
|
||||
|
||||
@@ -32,15 +32,7 @@ import com.l2jserver.service.database.DataAccessObject;
|
||||
*
|
||||
* @author Rogiel
|
||||
*/
|
||||
public interface ItemDAO extends DataAccessObject<Item>, Cacheable {
|
||||
/**
|
||||
* Load the instance represented by <tt>id</tt> from the database
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
*/
|
||||
Item load(ItemID id);
|
||||
|
||||
public interface ItemDAO extends DataAccessObject<Item, ItemID>, Cacheable {
|
||||
/**
|
||||
* Load the inventory for an {@link L2Character character}.
|
||||
*
|
||||
@@ -57,16 +49,4 @@ public interface ItemDAO extends DataAccessObject<Item>, Cacheable {
|
||||
*/
|
||||
@IgnoreCaching
|
||||
List<ItemID> listIDs();
|
||||
|
||||
/**
|
||||
* Save the instance to the database. If a new database entry was created
|
||||
* returns true.
|
||||
*
|
||||
* @param option
|
||||
* the id
|
||||
* @return true if created a new entry in database (i.e. insert), false if
|
||||
* not created (i.e. update)
|
||||
*/
|
||||
@IgnoreCaching
|
||||
boolean save(Item character);
|
||||
}
|
||||
|
||||
@@ -31,16 +31,7 @@ import com.l2jserver.service.database.DataAccessObject;
|
||||
*
|
||||
* @author Rogiel
|
||||
*/
|
||||
public interface NPCDAO extends DataAccessObject<NPC>, Cacheable {
|
||||
/**
|
||||
* Load the instance represented by <tt>id</tt> from the database
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
* @return the instance loaded
|
||||
*/
|
||||
NPC load(NPCID id);
|
||||
|
||||
public interface NPCDAO extends DataAccessObject<NPC, NPCID>, Cacheable {
|
||||
/**
|
||||
* Load all {@link NPC} instances
|
||||
*
|
||||
@@ -64,35 +55,4 @@ public interface NPCDAO extends DataAccessObject<NPC>, Cacheable {
|
||||
*/
|
||||
@IgnoreCaching
|
||||
List<NPCID> listIDs();
|
||||
|
||||
/**
|
||||
* Save the instance to the database. If a new database entry was created
|
||||
* returns true.
|
||||
*
|
||||
* @param npc
|
||||
* the npc
|
||||
* @return true if created a new entry in database (i.e. insert), false if
|
||||
* not created (i.e. update)
|
||||
*/
|
||||
@IgnoreCaching
|
||||
boolean save(NPC npc);
|
||||
|
||||
/**
|
||||
* Save the instance to the database. If a new database entry was created
|
||||
* returns true.
|
||||
*
|
||||
* @param npc
|
||||
* the npc
|
||||
*/
|
||||
@IgnoreCaching
|
||||
void insert(NPC npc);
|
||||
|
||||
/**
|
||||
* Updates the instance to the database.
|
||||
*
|
||||
* @param npc
|
||||
* the npc
|
||||
*/
|
||||
@IgnoreCaching
|
||||
void update(NPC npc);
|
||||
}
|
||||
|
||||
@@ -30,15 +30,7 @@ import com.l2jserver.service.database.DataAccessObject;
|
||||
*
|
||||
* @author Rogiel
|
||||
*/
|
||||
public interface PetDAO extends DataAccessObject<Pet>, Cacheable {
|
||||
/**
|
||||
* Load the instance represented by <tt>id</tt> from the database
|
||||
*
|
||||
* @param id
|
||||
* the id
|
||||
*/
|
||||
Pet load(PetID id);
|
||||
|
||||
public interface PetDAO extends DataAccessObject<Pet, PetID>, Cacheable {
|
||||
/**
|
||||
* Loads an List of all {@link ID}s in the database
|
||||
*
|
||||
@@ -46,16 +38,4 @@ public interface PetDAO extends DataAccessObject<Pet>, Cacheable {
|
||||
*/
|
||||
@IgnoreCaching
|
||||
List<PetID> listIDs();
|
||||
|
||||
/**
|
||||
* Save the instance to the database. If a new database entry was created
|
||||
* returns true.
|
||||
*
|
||||
* @param option
|
||||
* the id
|
||||
* @return true if created a new entry in database (i.e. insert), false if
|
||||
* not created (i.e. update)
|
||||
*/
|
||||
@IgnoreCaching
|
||||
boolean save(Pet character);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package com.l2jserver.db.dao.mysql5;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.Model;
|
||||
import com.l2jserver.model.id.ID;
|
||||
import com.l2jserver.service.database.AbstractDAO;
|
||||
import com.l2jserver.service.database.DatabaseService;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService;
|
||||
@@ -29,7 +31,8 @@ import com.l2jserver.service.database.MySQLDatabaseService;
|
||||
* @param <T>
|
||||
* the object for the DAO
|
||||
*/
|
||||
public class AbstractMySQL5DAO<T> extends AbstractDAO<T> {
|
||||
public abstract class AbstractMySQL5DAO<T extends Model<?>, I extends ID<?>> extends
|
||||
AbstractDAO<T, I> {
|
||||
/**
|
||||
* The MySQL Database Service
|
||||
*/
|
||||
|
||||
@@ -55,8 +55,8 @@ import com.l2jserver.util.dimensional.Point;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
||||
implements CharacterDAO {
|
||||
public class MySQL5CharacterDAO extends
|
||||
AbstractMySQL5DAO<L2Character, CharacterID> implements CharacterDAO {
|
||||
/**
|
||||
* The {@link CharacterID} factory
|
||||
*/
|
||||
@@ -180,7 +180,7 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
||||
};
|
||||
|
||||
@Override
|
||||
public L2Character load(final CharacterID id) {
|
||||
public L2Character select(final CharacterID id) {
|
||||
return database.query(new SelectSingleQuery<L2Character>() {
|
||||
@Override
|
||||
protected String query() {
|
||||
@@ -280,7 +280,7 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(L2Character character) {
|
||||
public boolean insert(L2Character character) {
|
||||
return database.query(new InsertUpdateQuery<L2Character>(character) {
|
||||
@Override
|
||||
protected String query() {
|
||||
@@ -330,4 +330,76 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(L2Character character) {
|
||||
return database.query(new InsertUpdateQuery<L2Character>(character) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "UPDATE `" + TABLE + "` SET " + ACCOUNT_ID + "` = ?,`"
|
||||
+ CLAN_ID + "` = ?,`" + NAME + "` = ?,`" + RACE
|
||||
+ "` = ?,`" + CLASS + "` = ?,`" + SEX + "` = ?,`"
|
||||
+ LEVEL + "` = ?,`" + POINT_X + "` = ?,`" + POINT_Y
|
||||
+ "` = ?,`" + POINT_Z + "` = ?,`" + POINT_ANGLE
|
||||
+ "` = ?,`" + APPEARANCE_HAIR_STYLE + "` = ?,`"
|
||||
+ APPEARANCE_HAIR_COLOR + "` = ?,`" + APPEARANCE_FACE
|
||||
+ "` = ? WHERE `" + CHAR_ID + "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st,
|
||||
L2Character character) throws SQLException {
|
||||
final CharacterAppearance appearance = character
|
||||
.getAppearance();
|
||||
int i = 1;
|
||||
|
||||
// SET
|
||||
st.setString(i++, character.getAccountID().getID());
|
||||
if (character.getClanID() != null)
|
||||
st.setInt(i++, character.getClanID().getID());
|
||||
else
|
||||
st.setNull(i++, Types.INTEGER);
|
||||
|
||||
st.setString(i++, character.getName());
|
||||
|
||||
st.setString(i++, character.getRace().name());
|
||||
st.setString(i++, character.getCharacterClass().name());
|
||||
st.setString(i++, character.getSex().name());
|
||||
|
||||
st.setInt(i++, character.getLevel());
|
||||
// TODO save experience
|
||||
// TODO save sp
|
||||
|
||||
st.setInt(i++, character.getPoint().getX());
|
||||
st.setInt(i++, character.getPoint().getY());
|
||||
st.setInt(i++, character.getPoint().getZ());
|
||||
st.setDouble(i++, character.getPoint().getAngle());
|
||||
|
||||
// appearance
|
||||
st.setString(i++, appearance.getHairStyle().name());
|
||||
st.setString(i++, appearance.getHairColor().name());
|
||||
st.setString(i++, appearance.getFace().name());
|
||||
|
||||
// WHERE
|
||||
st.setInt(i++, character.getID().getID());
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(L2Character character) {
|
||||
return database.query(new InsertUpdateQuery<L2Character>(character) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "DELETE FROM `" + TABLE + "` WHERE `" + CHAR_ID
|
||||
+ "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st,
|
||||
L2Character character) throws SQLException {
|
||||
st.setInt(1, character.getID().getID());
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,26 +23,35 @@ import java.util.List;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.db.dao.CharacterFriendDAO;
|
||||
import com.l2jserver.model.game.CharacterFriend;
|
||||
import com.l2jserver.model.id.FriendID;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
|
||||
import com.l2jserver.model.id.provider.FriendIDProvider;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.CharacterFriendList;
|
||||
import com.l2jserver.service.database.DatabaseService;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService.InsertUpdateQuery;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService.Mapper;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService.SelectListQuery;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService.SelectSingleQuery;
|
||||
|
||||
/**
|
||||
* {@link CharacterFriendDAO} implementation for MySQL5
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MySQL5CharacterFriendDAO extends AbstractMySQL5DAO<CharacterID>
|
||||
implements CharacterFriendDAO {
|
||||
public class MySQL5CharacterFriendDAO extends
|
||||
AbstractMySQL5DAO<CharacterFriend, FriendID> implements
|
||||
CharacterFriendDAO {
|
||||
/**
|
||||
* The {@link CharacterID} factory
|
||||
* The {@link FriendID} provider
|
||||
*/
|
||||
private final CharacterIDProvider idFactory;
|
||||
private final FriendIDProvider idProvider;
|
||||
/**
|
||||
* The {@link CharacterID} provider
|
||||
*/
|
||||
private final CharacterIDProvider charIdProvider;
|
||||
|
||||
/**
|
||||
* Character table name
|
||||
@@ -55,100 +64,132 @@ public class MySQL5CharacterFriendDAO extends AbstractMySQL5DAO<CharacterID>
|
||||
|
||||
@Inject
|
||||
public MySQL5CharacterFriendDAO(DatabaseService database,
|
||||
final CharacterIDProvider idFactory) {
|
||||
final FriendIDProvider idProvider,
|
||||
CharacterIDProvider charIdProvider) {
|
||||
super(database);
|
||||
this.idFactory = idFactory;
|
||||
this.idProvider = idProvider;
|
||||
this.charIdProvider = charIdProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link Mapper} for {@link CharacterID}
|
||||
*/
|
||||
private final Mapper<CharacterID> mapper = new Mapper<CharacterID>() {
|
||||
private final Mapper<CharacterFriend> mapper = new Mapper<CharacterFriend>() {
|
||||
@Override
|
||||
public CharacterID map(ResultSet rs) throws SQLException {
|
||||
return idFactory.createID(rs.getInt(CHAR_ID_FRIEND));
|
||||
public CharacterFriend map(ResultSet rs) throws SQLException {
|
||||
final CharacterID characterId = charIdProvider.createID(rs
|
||||
.getInt(CHAR_ID));
|
||||
final CharacterID friendId = charIdProvider.createID(rs
|
||||
.getInt(CHAR_ID_FRIEND));
|
||||
return new CharacterFriend(idProvider.createID(characterId,
|
||||
friendId));
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public List<CharacterID> load(final CharacterID id) {
|
||||
return database.query(new SelectListQuery<CharacterID>() {
|
||||
public CharacterFriend select(final FriendID id) {
|
||||
return database.query(new SelectSingleQuery<CharacterFriend>() {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "SELECT * FROM `" + TABLE + "` WHERE `" + CHAR_ID
|
||||
+ "` = ?";
|
||||
+ "` = ? AND `" + CHAR_ID_FRIEND + "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st) throws SQLException {
|
||||
st.setInt(1, id.getID());
|
||||
st.setInt(1, id.getID1().getID());
|
||||
st.setInt(2, id.getID2().getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mapper<CharacterID> mapper() {
|
||||
protected Mapper<CharacterFriend> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(L2Character character) {
|
||||
final List<CharacterID> list = load(character.getID());
|
||||
public void load(final L2Character character) {
|
||||
final List<CharacterFriend> list = database
|
||||
.query(new SelectListQuery<CharacterFriend>() {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "SELECT * FROM `" + TABLE + "` WHERE `"
|
||||
+ CHAR_ID + "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st)
|
||||
throws SQLException {
|
||||
st.setInt(1, character.getID().getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Mapper<CharacterFriend> mapper() {
|
||||
return mapper;
|
||||
}
|
||||
});
|
||||
character.getFriendList().load(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(final CharacterFriendList friends) {
|
||||
return database.query(new InsertUpdateQuery<CharacterID>(friends
|
||||
.idIterator()) {
|
||||
public boolean insert(CharacterFriend friend) {
|
||||
return database.query(new InsertUpdateQuery<CharacterFriend>(friend) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "REPLACE INTO `" + TABLE + "` (`" + CHAR_ID + "`,`"
|
||||
return "INSERT INTO `" + TABLE + "` (`" + CHAR_ID + "`,`"
|
||||
+ CHAR_ID_FRIEND + "`) VALUES(?,?)";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st, CharacterID id)
|
||||
throws SQLException {
|
||||
st.setInt(1, friends.getCharacter().getID().getID());
|
||||
st.setInt(2, id.getID());
|
||||
protected void parametize(PreparedStatement st,
|
||||
CharacterFriend friend) throws SQLException {
|
||||
st.setInt(1, friend.getCharacterID().getID());
|
||||
st.setInt(2, friend.getFriendID().getID());
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(final CharacterFriendList friends) {
|
||||
return database.query(new InsertUpdateQuery<CharacterFriendList>(
|
||||
friends) {
|
||||
public boolean update(CharacterFriend friend) {
|
||||
// is not possible update friends, because it is only a ID and IDs are
|
||||
// immutable
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(CharacterFriend friend) {
|
||||
return database.query(new InsertUpdateQuery<CharacterFriend>(friend) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "DELETE FROM `" + TABLE + "` WHERE `" + CHAR_ID
|
||||
+ "` = ?";
|
||||
+ "` = ?,`" + CHAR_ID_FRIEND + "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st,
|
||||
CharacterFriendList friends) throws SQLException {
|
||||
st.setInt(1, friends.getCharacter().getID().getID());
|
||||
CharacterFriend friend) throws SQLException {
|
||||
st.setInt(1, friend.getCharacterID().getID());
|
||||
st.setInt(2, friend.getFriendID().getID());
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(final CharacterID character, final CharacterID friend) {
|
||||
return database.query(new InsertUpdateQuery<Object>((Object) null) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "DELETE FROM `" + TABLE + "` WHERE `" + CHAR_ID
|
||||
+ "` = ?, `" + CHAR_ID_FRIEND + "` = ?";
|
||||
}
|
||||
public boolean save(final CharacterFriendList friends) {
|
||||
for (final CharacterFriend friend : friends) {
|
||||
if (!save(friend))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st, Object friends)
|
||||
throws SQLException {
|
||||
st.setInt(1, character.getID());
|
||||
st.setInt(2, friend.getID());
|
||||
}
|
||||
}) == 1;
|
||||
@Override
|
||||
public boolean delete(final CharacterFriendList friends) {
|
||||
for (final CharacterFriend friend : friends) {
|
||||
if (!delete(friend))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ import com.l2jserver.service.database.MySQLDatabaseService.SelectSingleQuery;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MySQL5ClanDAO extends AbstractMySQL5DAO<Clan> implements ClanDAO {
|
||||
public class MySQL5ClanDAO extends AbstractMySQL5DAO<Clan, ClanID> implements
|
||||
ClanDAO {
|
||||
/**
|
||||
* The {@link ClanID} factory
|
||||
*/
|
||||
@@ -60,8 +61,8 @@ public class MySQL5ClanDAO extends AbstractMySQL5DAO<Clan> implements ClanDAO {
|
||||
public static final String CHAR_ID_LEADER = "character_id_leader";
|
||||
|
||||
@Inject
|
||||
public MySQL5ClanDAO(DatabaseService database, ClanIDProvider clanIdFactory,
|
||||
final CharacterIDProvider idFactory) {
|
||||
public MySQL5ClanDAO(DatabaseService database,
|
||||
ClanIDProvider clanIdFactory, final CharacterIDProvider idFactory) {
|
||||
super(database);
|
||||
this.idFactory = clanIdFactory;
|
||||
this.charIdFactory = idFactory;
|
||||
@@ -95,7 +96,7 @@ public class MySQL5ClanDAO extends AbstractMySQL5DAO<Clan> implements ClanDAO {
|
||||
};
|
||||
|
||||
@Override
|
||||
public Clan load(final ClanID id) {
|
||||
public Clan select(final ClanID id) {
|
||||
return database.query(new SelectSingleQuery<Clan>() {
|
||||
@Override
|
||||
protected String query() {
|
||||
@@ -131,7 +132,7 @@ public class MySQL5ClanDAO extends AbstractMySQL5DAO<Clan> implements ClanDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(Clan clan) {
|
||||
public boolean insert(Clan clan) {
|
||||
return database.query(new InsertUpdateQuery<Clan>(clan) {
|
||||
@Override
|
||||
protected String query() {
|
||||
@@ -147,4 +148,27 @@ public class MySQL5ClanDAO extends AbstractMySQL5DAO<Clan> implements ClanDAO {
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(Clan clan) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Clan clan) {
|
||||
return database.query(new InsertUpdateQuery<Clan>(clan) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "DELETE FROM `" + TABLE + "` WHERE `" + CLAN_ID
|
||||
+ "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st, Clan clan)
|
||||
throws SQLException {
|
||||
st.setInt(1, clan.getID().getID());
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.l2jserver.model.world.character.CharacterInventory.InventoryLocation;
|
||||
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
|
||||
import com.l2jserver.service.database.DatabaseService;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService.CachedMapper;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService.InsertUpdateQuery;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService.Mapper;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService.SelectListQuery;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService.SelectSingleQuery;
|
||||
@@ -47,7 +48,8 @@ import com.l2jserver.util.dimensional.Coordinate;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MySQL5ItemDAO extends AbstractMySQL5DAO<Item> implements ItemDAO {
|
||||
public class MySQL5ItemDAO extends AbstractMySQL5DAO<Item, ItemID> implements
|
||||
ItemDAO {
|
||||
/**
|
||||
* The {@link ItemID} factory
|
||||
*/
|
||||
@@ -136,7 +138,7 @@ public class MySQL5ItemDAO extends AbstractMySQL5DAO<Item> implements ItemDAO {
|
||||
};
|
||||
|
||||
@Override
|
||||
public Item load(final ItemID id) {
|
||||
public Item select(final ItemID id) {
|
||||
return database.query(new SelectSingleQuery<Item>() {
|
||||
@Override
|
||||
protected String query() {
|
||||
@@ -196,8 +198,30 @@ public class MySQL5ItemDAO extends AbstractMySQL5DAO<Item> implements ItemDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(Item item) {
|
||||
public boolean insert(Item item) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Saving items is not yet implemented!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(Item item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Item item) {
|
||||
return database.query(new InsertUpdateQuery<Item>(item) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "DELETE FROM `" + TABLE + "` WHERE `" + ITEM_ID
|
||||
+ "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st, Item item)
|
||||
throws SQLException {
|
||||
st.setInt(1, item.getID().getID());
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.db.dao.CharacterDAO;
|
||||
import com.l2jserver.db.dao.NPCDAO;
|
||||
@@ -44,7 +47,10 @@ import com.l2jserver.util.dimensional.Point;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MySQL5NPCDAO extends AbstractMySQL5DAO<NPC> implements NPCDAO {
|
||||
public class MySQL5NPCDAO extends AbstractMySQL5DAO<NPC, NPCID> implements
|
||||
NPCDAO {
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
* The {@link NPCID} provider
|
||||
*/
|
||||
@@ -95,8 +101,8 @@ public class MySQL5NPCDAO extends AbstractMySQL5DAO<NPC> implements NPCDAO {
|
||||
if (template == null) {
|
||||
// set default npc instance, for now!
|
||||
// RoxxyGatekeeperTemplate - 30006
|
||||
templateId = templateIdProvider.createID(30006);
|
||||
template = templateId.getTemplate();
|
||||
log.warn("No template found for {}", templateId);
|
||||
return null;
|
||||
}
|
||||
|
||||
final NPC npc = template.create();
|
||||
@@ -122,7 +128,7 @@ public class MySQL5NPCDAO extends AbstractMySQL5DAO<NPC> implements NPCDAO {
|
||||
};
|
||||
|
||||
@Override
|
||||
public NPC load(final NPCID id) {
|
||||
public NPC select(final NPCID id) {
|
||||
return database.query(new SelectSingleQuery<NPC>() {
|
||||
@Override
|
||||
protected String query() {
|
||||
@@ -194,19 +200,8 @@ public class MySQL5NPCDAO extends AbstractMySQL5DAO<NPC> implements NPCDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(NPC npc) {
|
||||
if (npc.isInDatabase()) {
|
||||
update(npc);
|
||||
return false;
|
||||
} else {
|
||||
insert(npc);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(NPC npc) {
|
||||
database.query(new InsertUpdateQuery<NPC>(npc) {
|
||||
public boolean insert(NPC npc) {
|
||||
return database.query(new InsertUpdateQuery<NPC>(npc) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "INSERT INTO `" + TABLE + "` (`" + NPC_ID + "`,`"
|
||||
@@ -228,18 +223,18 @@ public class MySQL5NPCDAO extends AbstractMySQL5DAO<NPC> implements NPCDAO {
|
||||
st.setInt(i++, npc.getPoint().getZ());
|
||||
st.setDouble(i++, npc.getPoint().getAngle());
|
||||
}
|
||||
});
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(NPC npc) {
|
||||
database.query(new InsertUpdateQuery<NPC>(npc) {
|
||||
public boolean update(NPC npc) {
|
||||
return database.query(new InsertUpdateQuery<NPC>(npc) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "UPDATE `" + TABLE + "` SET `" + NPC_ID + "` = ?,`"
|
||||
+ NPC_TEMPLATE_ID + " = ?`,`" + POINT_X + " = ?`,`"
|
||||
+ POINT_Y + "` = ?,`" + POINT_Z + "` = ?,`"
|
||||
+ POINT_ANGLE + "` = ? WHERE " + NPC_ID + "` = ?";
|
||||
return "UPDATE `" + TABLE + "` SET " + NPC_TEMPLATE_ID
|
||||
+ "` = ?,`" + POINT_X + "` = ?,`" + POINT_Y + "` = ?,`"
|
||||
+ POINT_Z + "` = ?,`" + POINT_ANGLE + "` = ? WHERE `"
|
||||
+ NPC_ID + "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -248,7 +243,6 @@ public class MySQL5NPCDAO extends AbstractMySQL5DAO<NPC> implements NPCDAO {
|
||||
int i = 1;
|
||||
|
||||
// SET
|
||||
st.setInt(i++, npc.getID().getID());
|
||||
st.setInt(i++, npc.getTemplateID().getID());
|
||||
|
||||
st.setInt(i++, npc.getPoint().getX());
|
||||
@@ -259,6 +253,22 @@ public class MySQL5NPCDAO extends AbstractMySQL5DAO<NPC> implements NPCDAO {
|
||||
// WHERE
|
||||
st.setInt(i++, npc.getID().getID());
|
||||
}
|
||||
});
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(NPC npc) {
|
||||
return database.query(new InsertUpdateQuery<NPC>(npc) {
|
||||
@Override
|
||||
protected String query() {
|
||||
return "DELETE FROM `" + TABLE + "` WHERE `" + NPC_ID + "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parametize(PreparedStatement st, NPC npc)
|
||||
throws SQLException {
|
||||
st.setInt(1, npc.getID().getID());
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -41,9 +41,9 @@ public class MySQL5CharacterDAOTest {
|
||||
injector.getInstance(ServiceManager.class).start(DatabaseService.class);
|
||||
|
||||
final CharacterDAO dao = injector.getInstance(CharacterDAO.class);
|
||||
final L2Character char1 = dao.load(injector.getInstance(
|
||||
final L2Character char1 = dao.select(injector.getInstance(
|
||||
CharacterIDProvider.class).createID(268437456));
|
||||
final L2Character char2 = dao.load(injector.getInstance(
|
||||
final L2Character char2 = dao.select(injector.getInstance(
|
||||
CharacterIDProvider.class).createID(268437456));
|
||||
|
||||
Assert.assertSame(char1, char2);
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ScriptingServiceImplTest {
|
||||
.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ScriptingService.class).to(ScriptingServiceImpl.class)
|
||||
bind(ScriptingService.class).to(PreCompiledScriptingService.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user