骑士
 
- UID
- 130957
- 帖子
- 127
- 威望
- 0
- 久币
- 0
- 贡献
- 0
- 阅读权限
- 30
- 在线时间
- 5 小时
- 注册时间
- 2018-3-30
|
1.創建任務類(處理任務)
L1PcQuestGroup.java
|
文章轉載至天堂技術論壇http://bbs.t1fb.net/forum.php?mod=viewthread&tid=204- package com.lineage.server.model;
- import java.util.concurrent.ConcurrentHashMap;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import com.lineage.server.datatables.readwrite.read.DTRCharQuest;
- import com.lineage.server.model.Instance.L1PcInstance;
- import com.lineage.server.staticobj.STOTime;
- public class L1PcQuestGroup {
- private static final Log _log = LogFactory.getLog(L1PcQuestGroup.class);
- public static final int QUEST_NOT = 0; // 任務尚未開始
- public static final int QUEST_END = 255; // 任務已經結束
- private final DTRCharQuest _cqr = DTRCharQuest.get();
- private L1PcInstance _owner = null;
- private ConcurrentHashMap<Integer, L1PcQuest> _questGroup = null;
- /**
- * 任務紀錄模組
- *
- * @param owner
- */
- public L1PcQuestGroup(final L1PcInstance owner) {
- this._owner = owner;
- }
- /**
- * 傳回執行任務者
- *
- * @return
- */
- public L1PcInstance get_owner() {
- return this._owner;
- }
- /**
- * 傳回任務梯度
- *
- * @param quest_id
- * 任務編號
- * @return 梯度
- */
- public int get_step(final int quest_id) {
- try {
- this._questGroup = this._cqr.getQuests(this._owner.getId()); // 即時讀取任務組(必須)
- if (this._questGroup == null) {
- return 0;
- }
- final L1PcQuest quest = this._questGroup.get(new Integer(quest_id)); // 讀取指定Id的任務信息
- if (quest == null) {
- return 0;
- }
- final int step = quest.getStep();
- return step;
- } catch (final Exception e) {
- _log.error(e.getLocalizedMessage(), e);
- }
- return 0;
- }
- /**
- * 傳回任務完成數量
- *
- * @param quest_id
- * 任務編號
- * @return 數量
- */
- public int get_count(final int quest_id) {
- try {
- this._questGroup = this._cqr.getQuests(this._owner.getId()); // 即時讀取任務組(必須)
- if (this._questGroup == null) {
- return 0;
- }
- final L1PcQuest quest = this._questGroup.get(new Integer(quest_id)); // 讀取指定Id的任務信息
- if (quest == null) {
- return 0;
- }
- final int count = quest.getCount();
- return count;
- } catch (final Exception e) {
- _log.error(e.getLocalizedMessage(), e);
- }
- return 0;
- }
- /**
- * 傳回任務執行起始時間
- *
- * @param quest_id
- * 任務編號
- * @return 起始時間
- */
- public int get_startTime(final int quest_id) {
- try {
- this._questGroup = this._cqr.getQuests(this._owner.getId()); // 即時讀取任務組(必須)
- if (this._questGroup == null) {
- return 0;
- }
- final L1PcQuest quest = this._questGroup.get(new Integer(quest_id)); // 讀取指定Id的任務信息
- if (quest == null) {
- return 0;
- }
- final int startTime = quest.getStartTime();
- return startTime;
- } catch (final Exception e) {
- _log.error(e.getLocalizedMessage(), e);
- }
- return 0;
- }
- /**
- * 傳回任務所需道具
- *
- * @param quest_id
- * 任務編號
- * @return 所需道具
- */
- public int get_targetItem(final int quest_id) {
- try {
- this._questGroup = this._cqr.getQuests(this._owner.getId()); // 即時讀取任務組(必須)
- if (this._questGroup == null) {
- return 0;
- }
- final L1PcQuest quest = this._questGroup.get(new Integer(quest_id)); // 讀取指定Id的任務信息
- if (quest == null) {
- return 0;
- }
- final int targetItem = quest.getTargetItem();
- return targetItem;
- } catch (final Exception e) {
- _log.error(e.getLocalizedMessage(), e);
- }
- return 0;
- }
- /**
- * 傳回任務所需道具數量
- *
- * @param quest_id
- * 任務編號
- * @return 道具數量
- */
- public int get_itemCount(final int quest_id) {
- try {
- this._questGroup = this._cqr.getQuests(this._owner.getId()); // 即時讀取任務組(必須)
- if (this._questGroup == null) {
- return 0;
- }
- final L1PcQuest quest = this._questGroup.get(new Integer(quest_id)); // 讀取指定Id的任務信息
- if (quest == null) {
- return 0;
- }
- final int itemCount = quest.getItemCount();
- return itemCount;
- } catch (final Exception e) {
- _log.error(e.getLocalizedMessage(), e);
- }
- return 0;
- }
- /**
- * 傳回任務目標地圖
- *
- * @param quest_id
- * 任務編號
- * @return 目標地圖
- */
- public int get_targetMap(final int quest_id) {
- try {
- this._questGroup = this._cqr.getQuests(this._owner.getId()); // 即時讀取任務組(必須)
- if (this._questGroup == null) {
- return 0;
- }
- final L1PcQuest quest = this._questGroup.get(new Integer(quest_id)); // 讀取指定Id的任務信息
- if (quest == null) {
- return 0;
- }
- final int targetMap = quest.getTargetMap();
- return targetMap;
- } catch (final Exception e) {
- _log.error(e.getLocalizedMessage(), e);
- }
- return 0;
- }
- /**
- * 傳回任務目標怪物
- *
- * @param quest_id
- * 任務編號
- * @return 目標怪物
- */
- public int get_targetMob(final int quest_id) {
- try {
- this._questGroup = this._cqr.getQuests(this._owner.getId()); // 即時讀取任務組(必須)
- if (this._questGroup == null) {
- return 0;
- }
- final L1PcQuest quest = this._questGroup.get(new Integer(quest_id)); // 讀取指定Id的任務信息
- if (quest == null) {
- return 0;
- }
- final int targetMob = quest.getTargetMob();
- return targetMob;
- } catch (final Exception e) {
- _log.error(e.getLocalizedMessage(), e);
- }
- return 0;
- }
- /**
- * 該任務是否開始 (get_step 大於0 小於255 傳回任務已經開始)
- *
- * @param quest_id
- * 任務編號
- * @return true:已經開始 false:尚未開始
- */
- public boolean isStart(final int quest_id) {
- try {
- final int step = this.get_step(quest_id);
- // 大於0 小於255
- if (step > QUEST_NOT && step < QUEST_END) {
- return true;
- }
- } catch (final Exception e) {
- _log.error(e.getLocalizedMessage(), e);
- }
- return false;
- }
- /**
- * 該任務是否結束
- *
- * @param quest_id
- * 任務編號
- * @return true:已經結束 false:尚未結束
- */
- public boolean isEnd(final int quest_id) {
- try {
- if (this.get_step(quest_id) == QUEST_END) {
- return true;
- }
- } catch (final Exception e) {
- _log.error(e.getLocalizedMessage(), e);
- }
- return false;
- }
- /**
- * 增加任務梯度(只用做單純的step切換時使用,只變更step信息其他不變)
- *
- * @param questId
- * 任務編號
- * @param addStep
- * 增加的梯度值
- */
- public void add_step(final int questId, final int addStep) {
- final int quest_id = questId;
- final int step = this.get_step(quest_id) + addStep;
- final int addNum = 0;
- final int startTime = this.get_startTime(questId);
- final int targetItem = this.get_targetItem(quest_id);
- final int itemCount = this.get_itemCount(quest_id);
- final int targetMap = this.get_targetMap(quest_id);
- final int targetMob = this.get_targetMob(quest_id);
- this.set_quest(quest_id, step, addNum, startTime, targetItem, itemCount, targetMap, targetMob);
- }
- /**
- * 增加任務數量(只用做單純的計數時使用,只變更count信息其他不變)
- *
- * @param questId
- * 任務編號
- * @param addCount
- * 增加的梯度值
- */
- public void add_count(final int questId, final int addCount) {
- final int quest_id = questId;
- final int step = this.get_step(quest_id);
- final int addNum = addCount;
- final int startTime = this.get_startTime(questId);
- final int targetItem = this.get_targetItem(quest_id);
- final int itemCount = this.get_itemCount(quest_id);
- final int targetMap = this.get_targetMap(quest_id);
- final int targetMob = this.get_targetMob(quest_id);
- this.set_quest(quest_id, step, addNum, startTime, targetItem, itemCount, targetMap, targetMob);
- }
- /**
- * 設置任務梯度(只用做單純的step重置時使用,只變更step信息其他不變)
- *
- * @param questId
- * 任務編號
- * @param step
- * 目标梯度值
- */
- public void set_step(final int questId, final int step) {
- final int quest_id = questId;
- final int newStep = step;
- final int addNum = 0;
- final int startTime = this.get_startTime(questId);
- final int targetItem = this.get_targetItem(quest_id);
- final int itemCount = this.get_itemCount(quest_id);
- final int targetMap = this.get_targetMap(quest_id);
- final int targetMob = this.get_targetMob(quest_id);
- this.set_quest(quest_id, newStep, addNum, startTime, targetItem, itemCount, targetMap, targetMob);
- }
- /**
- * 設置任務完成數量(只用做單純的count重置時使用,只變更count信息其他不變)
- *
- * @param questId
- * 任務編號
- * @param count
- * 任務完成數量
- */
- public void set_count(final int questId, final int count) {
- final int quest_id = questId;
- final int step = this.get_step(quest_id);
- final int addNum = count - get_count(quest_id);
- final int startTime = this.get_startTime(questId);
- final int targetItem = this.get_targetItem(quest_id);
- final int itemCount = this.get_itemCount(quest_id);
- final int targetMap = this.get_targetMap(quest_id);
- final int targetMob = this.get_targetMob(quest_id);
- this.set_quest(quest_id, step, addNum, startTime, targetItem, itemCount, targetMap, targetMob);
- }
复制代码 |
|