mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-10 09:22:49 +00:00
Character creation code moved to CharacterService
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.service.game.character;
|
||||
|
||||
/**
|
||||
* Exception thrown when the character is <b>not</b> in jail
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterInvalidAppearanceException extends
|
||||
CharacterServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.service.game.character;
|
||||
|
||||
/**
|
||||
* Exception thrown when the character is <b>not</b> in jail
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterInvalidNameException extends
|
||||
CharacterServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.service.game.character;
|
||||
|
||||
/**
|
||||
* Exception thrown when the character is <b>not</b> in jail
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterNameAlreadyExistsException extends
|
||||
CharacterServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -17,9 +17,14 @@
|
||||
package com.l2jserver.service.game.character;
|
||||
|
||||
import com.l2jserver.model.game.CharacterFriend;
|
||||
import com.l2jserver.model.template.actor.ActorSex;
|
||||
import com.l2jserver.model.template.character.CharacterClass;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.Item;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.CharacterAppearance.CharacterFace;
|
||||
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairColor;
|
||||
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairStyle;
|
||||
import com.l2jserver.service.Service;
|
||||
import com.l2jserver.service.game.npc.NotAttackableNPCServiceException;
|
||||
import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException;
|
||||
@@ -40,6 +45,36 @@ import com.l2jserver.util.geometry.Point3D;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface CharacterService extends Service {
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* The name of the new character
|
||||
* @param sex
|
||||
* The sex of the new character
|
||||
* @param characterClass
|
||||
* The class of the new character
|
||||
* @param hairStyle
|
||||
* The new character hair style
|
||||
* @param hairColor
|
||||
* The new character hair color
|
||||
* @param face
|
||||
* The new character face
|
||||
* @return the newly created {@link L2Character} object
|
||||
* @throws CharacterInvalidNameException
|
||||
* if the character name contains invalid characters, too long
|
||||
* or not long enough
|
||||
* @throws CharacterInvalidAppearanceException
|
||||
* if the appearance sent by the client is not valid
|
||||
* @throws CharacterNameAlreadyExistsException
|
||||
* the character name is already being used
|
||||
*/
|
||||
L2Character create(String name, ActorSex sex,
|
||||
CharacterClass characterClass, CharacterHairStyle hairStyle,
|
||||
CharacterHairColor hairColor, CharacterFace face)
|
||||
throws CharacterInvalidNameException,
|
||||
CharacterInvalidAppearanceException,
|
||||
CharacterNameAlreadyExistsException;
|
||||
|
||||
/**
|
||||
* Perform all operations required to this character join the world
|
||||
*
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.character;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.game.net.Lineage2Client;
|
||||
@@ -28,14 +31,24 @@ import com.l2jserver.game.net.packet.server.SM_ITEM_GROUND;
|
||||
import com.l2jserver.game.net.packet.server.SM_MOVE;
|
||||
import com.l2jserver.game.net.packet.server.SM_MOVE_TYPE;
|
||||
import com.l2jserver.game.net.packet.server.SM_TARGET;
|
||||
import com.l2jserver.model.dao.CharacterDAO;
|
||||
import com.l2jserver.model.dao.ItemDAO;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
|
||||
import com.l2jserver.model.id.template.CharacterTemplateID;
|
||||
import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
|
||||
import com.l2jserver.model.server.ChatMessage;
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.template.actor.ActorSex;
|
||||
import com.l2jserver.model.template.character.CharacterClass;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.Actor.ActorState;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.L2Character.CharacterMoveType;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.character.CharacterAppearance.CharacterFace;
|
||||
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairColor;
|
||||
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairStyle;
|
||||
import com.l2jserver.model.world.character.event.CharacterEnterWorldEvent;
|
||||
import com.l2jserver.model.world.character.event.CharacterEvent;
|
||||
import com.l2jserver.model.world.character.event.CharacterLeaveWorldEvent;
|
||||
@@ -76,6 +89,12 @@ import com.l2jserver.util.geometry.Point3D;
|
||||
BroadcastService.class })
|
||||
public class CharacterServiceImpl extends AbstractService implements
|
||||
CharacterService {
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(CharacterServiceImpl.class);
|
||||
|
||||
/**
|
||||
* The {@link BroadcastService}
|
||||
*/
|
||||
@@ -104,11 +123,19 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
* The {@link GameGuardService}
|
||||
*/
|
||||
private final GameGuardService ggService;
|
||||
|
||||
/**
|
||||
* The {@link CharacterDAO}
|
||||
*/
|
||||
private final CharacterDAO characterDao;
|
||||
/**
|
||||
* The {@link ItemDAO}
|
||||
*/
|
||||
private final ItemDAO itemDao;
|
||||
|
||||
private final CharacterIDProvider charIdProvider;
|
||||
private final CharacterTemplateIDProvider charTemplateIdProvider;
|
||||
|
||||
// /**
|
||||
// * The {@link AIService}
|
||||
// */
|
||||
@@ -118,7 +145,10 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
public CharacterServiceImpl(BroadcastService broadcastService,
|
||||
WorldEventDispatcher eventDispatcher, ChatService chatService,
|
||||
NetworkService networkService, SpawnService spawnService,
|
||||
NPCService npcService, GameGuardService ggService, ItemDAO itemDao) {
|
||||
NPCService npcService, GameGuardService ggService,
|
||||
CharacterDAO characterDao, ItemDAO itemDao,
|
||||
CharacterTemplateIDProvider charTemplateIdProvider,
|
||||
CharacterIDProvider charIdProvider) {
|
||||
this.broadcastService = broadcastService;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.chatService = chatService;
|
||||
@@ -126,7 +156,60 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
this.spawnService = spawnService;
|
||||
this.npcService = npcService;
|
||||
this.ggService = ggService;
|
||||
this.characterDao = characterDao;
|
||||
this.itemDao = itemDao;
|
||||
this.charTemplateIdProvider = charTemplateIdProvider;
|
||||
this.charIdProvider = charIdProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2Character create(String name, ActorSex sex,
|
||||
CharacterClass characterClass, CharacterHairStyle hairStyle,
|
||||
CharacterHairColor hairColor, CharacterFace face)
|
||||
throws CharacterInvalidNameException,
|
||||
CharacterInvalidAppearanceException,
|
||||
CharacterNameAlreadyExistsException {
|
||||
if ((name.length() < 1) || (name.length() > 16)) {
|
||||
throw new CharacterInvalidNameException();
|
||||
}
|
||||
// TODO check alphanumeric name
|
||||
if (sex == null || hairStyle == null || hairColor == null
|
||||
|| face == null)
|
||||
// if some of those attributes is null, something wrong happened.
|
||||
// Maybe we don't support the value sent!
|
||||
throw new CharacterInvalidAppearanceException();
|
||||
|
||||
// existence check
|
||||
final L2Character existenceCheck = characterDao.selectByName(name);
|
||||
if (existenceCheck != null)
|
||||
throw new CharacterNameAlreadyExistsException();
|
||||
|
||||
// create template id and lookup for the template instance
|
||||
final CharacterTemplateID templateId = charTemplateIdProvider
|
||||
.resolveID(characterClass.id);
|
||||
final CharacterTemplate template = templateId.getTemplate();
|
||||
log.debug("Creating character with template {}", template);
|
||||
|
||||
// everything is fine, allocate a new ID
|
||||
final CharacterID id = charIdProvider.createID();
|
||||
// create the instance from the template
|
||||
final L2Character character = template.create();
|
||||
|
||||
log.debug("Character object created, ID: {}, Object: {}", id, character);
|
||||
|
||||
// set parameters
|
||||
character.setID(id);
|
||||
character.setName(name);
|
||||
|
||||
character.setSex(sex);
|
||||
|
||||
character.getAppearance().setHairStyle(hairStyle);
|
||||
character.getAppearance().setHairColor(hairColor);
|
||||
character.getAppearance().setFace(face);
|
||||
|
||||
if (characterDao.save(character))
|
||||
return character;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user