게임 중의 퀘스트 시스템의 간단한 구조!
4293 단어 java 게임 서버 개발 노트
쓸데없는 말은 많지 않으니 코드를 올리지 마라!
임무의 다섯 가지 상태
/**
*
* @author kevin chen
* @Description: TODO
* @date 2015 10 21 8:20:39
*/
public class TaskState {
/**0 */
public static final int cannotAccept = 0;
/**1 */
public static final int canAccept = 1;
/**2 */
public static final int doTasking = 2;
/**3 */
public static final int completeTask = 3;
/**4 */
public static final int finishTask = 4;
}
작업 객체의 엔티티
/**
*
* @author kevin chen
* @Description: TODO
* @date 2015 10 21 8:51:16
*/
public class Task {
/** id*/
private int taskId;
/** */
private int taskState;
/** */
private int progress;
/** */
private transient Tasktemplate tasktemplate;
/** */
private transient ITarget target;
public Task(int taskId, int taskState) {
this.taskId = taskId;
this.taskState = taskState;
this.tasktemplate = DataManager.getSingleData(GameConfigTable.tasktemplate, this.taskId);
this.target = TargetType.getITargetById(this.tasktemplate.getTargetType());
}
public Tasktemplate getTasktemplate() {
return tasktemplate;
}
public int getTaskId() {
return taskId;
}
public void setTaskId(int taskId) {
this.taskId = taskId;
}
public int getTaskState() {
return taskState;
}
public void setTaskState(int taskState) {
this.taskState = taskState;
}
public int getProgress() {
return progress;
}
public void setProgress(int progress) {
this.progress = progress;
}
public int getTaskType(){
return this.tasktemplate.getTaskType();
}
public ITarget getTarget() {
return target;
}
/** */
public int getNextTaskId(){
return this.tasktemplate.getPostTaskId();
}
}
임무의 실체가 어떻게 구성되는지 중점적으로 봐라!
public interface ITarget {
/** */
boolean checkTaskComplete(Hero hero,Task task);
}
작업 구성 테이블에서 작업 목적을 나타내는 매개 변수는 열거된 하표와 일치해야 한다
public enum TargetType {
/**0 none*/
Null(null),
/**1 */
HitMonster(new HitMonsterTarget()),
/**2 */
Collect(new CollectTarget()),
/**3 */
Gather(new GatherTarget()),
/**4 */
PassKa(new PassKaTarget()),
/**5 */
DialogTarget(new DialogTarget()),
/**6 */
GiveItem(new GiveItemTarget()),
/**7 */
Escort(new EscortTarget()),
/**8 */
UseItem(new UseItemTarget()),
/**9 */
Special(new SpecialTarget()),
;
private ITarget target;
private TargetType (ITarget target){
this.target = target;
}
public ITarget getTarget() {
return target;
}
/** */
public static ITarget getITargetById(int targetId){
TargetType[] values = TargetType.values();
TargetType targetType = values[targetId];
return targetType.getTarget();
}
}
public class Hero {
/**
* ( , , )
*/
private List doingTasks = new ArrayList();
/**
*
*/
private List finishTasks = new ArrayList();
public List getDoingTasks() {
return doingTasks;
}
}
任务的业务逻辑处理 采用的静态方法
/**
*
* @author kevin chen
* @Description: TODO
* @date 2015 10 22 11:45:48
*/
public class TaskManager {
/**
*
* @param hero
* @param tasktemplate
* @return true: false:
*/
public static boolean isEnoughTaskLevel(Hero hero,Tasktemplate tasktemplate){
return true;
}
/**
*
* @param hero
* @param task
*/
public static void updateTaskMsg(Hero hero,Task task){
}
/**
* !
* !
* @param hero
*/
public static void checkTask(Hero hero){
List doingTasks = hero.getDoingTasks();
for (Iterator iterator = doingTasks.iterator(); iterator.hasNext();) {
Task task = iterator.next();
ITarget target = task.getTarget();
boolean complete = target.checkTaskComplete(hero, task);
if(complete){
updateTaskMsg(hero, task);
}
}
}
}
샤오강 공유, 많은 지도 부탁드립니다!