/// <summary> /// 移除执行目标 /// </summary> public void removeRunningTask(TaskData data) { _runningTaskDic.remove(data.instanceID); TaskTypeConfig tConfig; IntObjectMap <TaskData> dic; //双键 if ((tConfig = TaskTypeConfig.get(data.config.type)).needSecondKey) { if ((dic = _runningTaskTypeTwoDic.get((long)data.config.type << 32 | data.config.args[1])) != null) { dic.remove(data.instanceID); } if (tConfig.needSecondKey2) { if ((dic = _runningTaskTypeTwoDic2.get((long)data.config.type << 32 | data.config.args[2])) != null) { dic.remove(data.instanceID); } } } //单键 else { if ((dic = _runningTaskTypeOneDic.get(data.config.type)) != null) { dic.remove(data.instanceID); } } }
/// <summary> /// 任务更新 /// </summary> public void taskRefresh(int type, int secondKey, bool useSecond2) { TaskTypeConfig config = TaskTypeConfig.get(type); _tempArr[0] = secondKey; doTaskEvent(config, _tempArr, true, useSecond2); }
private void addRunningQuest(QuestData data) { TaskData[] tasks = data.tasks; TaskData tData; //串行 if (data.config.executeType == QuestExecuteType.Serial) { for (int i = 0; i < tasks.Length; i++) { //未完成,或刷新式的 if (!(tData = tasks[i]).isComplete()) { //只加一次 doAddRunningTask(tData); break; } } } //并行或任意 else { for (int i = 0; i < tasks.Length; i++) { //未完成,或刷新式的 if (!(tData = tasks[i]).isComplete() || TaskTypeConfig.get(tData.config.type).needUpdate) { doAddRunningTask(tData); } } } }
/// <summary> /// 客户端任务目标事件 /// </summary> public void clientTaskEvent(int type, params int[] args) { TaskTypeConfig typeConfig = TaskTypeConfig.get(type); if (typeConfig == null) { me.warnLog("clientTaskEvent时,找不到目标配置", type); return; } if (CommonSetting.isClientDriveLogic) { taskEvent(type, args); } else { if (!typeConfig.isClientDrive) { me.warnLog("clientTaskEvent时,不可客户端驱动", type); return; } me.send(ClientTaskEventRequest.create(type, args)); } }
/** 回收任务目标数据 */ public void releaseTaskData(int type, TaskData data) { if (TaskTypeConfig.get(type).needCustomTask) { _taskDataPool[type].back(data); } else { _taskDataPool[0].back(data); } }
/** 创建任务数据 */ public virtual TaskData createTaskData(int type) { if (TaskTypeConfig.get(type).needCustomTask) { return(_taskDataPool[type].getOne()); } else { return(_taskDataPool[0].getOne()); } }
/** 目标完成 */ private void taskComplete(TaskData data) { //先移除 if (!TaskTypeConfig.get(data.config.type).needUpdate) { removeRunningTask(data); } Action <TaskData> func; if ((func = _taskCompleteFuncDic.get(data.funcID)) == null) { Ctrl.throwError("找不到注册的task回调"); return; } func(data); }
/** 执行添加任务目标 */ private void doAddRunningTask(TaskData data) { _runningTaskDic.put(data.instanceID, data); TaskTypeConfig tConfig; //双键 if ((tConfig = TaskTypeConfig.get(data.config.type)).needSecondKey) { _runningTaskTypeTwoDic.computeIfAbsent((long)data.config.type << 32 | data.config.args[1], k => new IntObjectMap <TaskData>()).put(data.instanceID, data); if (tConfig.needSecondKey2) { _runningTaskTypeTwoDic2.computeIfAbsent((long)data.config.type << 32 | data.config.args[2], k => new IntObjectMap <TaskData>()).put(data.instanceID, data); } } //单键 else { _runningTaskTypeOneDic.computeIfAbsent(data.config.type, k => new IntObjectMap <TaskData>()).put(data.instanceID, data); } }
public virtual void init() { (attackDataPool = new ObjectPool <AttackData>(() => { return(new AttackData()); })).setEnable(CommonSetting.sceneLogicUsePool); (_fightDataLogicPool = new ObjectPool <UnitFightDataLogic>(() => { UnitFightDataLogic logic = GameC.factory.createUnitFightDataLogic(); logic.construct(); return(logic); })).setEnable(CommonSetting.sceneLogicUsePool); _unitPoolDic = new ObjectPool <Unit> [UnitType.size]; for (int i = 0; i < UnitType.size; ++i) { (_unitPoolDic[i] = createUnitPool(i)).setEnable(CommonSetting.sceneLogicUsePool); } (bulletPool = new ObjectPool <Bullet>(() => { Bullet bullet = GameC.factory.createBullet(); bullet.construct(); return(bullet); })).setEnable(CommonSetting.sceneLogicUsePool); (unitEffectPool = new ObjectPool <UnitEffect>(() => { UnitEffect effect = GameC.factory.createUnitEffect(); effect.construct(); return(effect); })).setEnable(CommonSetting.sceneLogicUsePool); (rolePool = new ObjectPool <Role>(() => { Role role = GameC.factory.createRole(); role.construct(); return(role); })).setEnable(CommonSetting.sceneLogicUsePool); buffDataPool.setEnable(CommonSetting.sceneLogicUsePool); buffIntervalActionDataPool.setEnable(CommonSetting.sceneLogicUsePool); //logic _itemDataPool = new ObjectPool <ItemData> [ItemType.size]; for (int i = 0; i < _itemDataPool.Length; ++i) { (_itemDataPool[i] = createItemDataPool(i)).setEnable(CommonSetting.logicUsePool); } TaskTypeConfig typeConfig; _taskDataPool = new ObjectPool <TaskData> [QuestType.size]; (_taskDataPool[0] = createTaskDataPool(0)).setEnable(CommonSetting.logicUsePool); for (int i = 0; i < _taskDataPool.Length; ++i) { if ((typeConfig = TaskTypeConfig.get(i)) != null && typeConfig.needCustomTask) { (_taskDataPool[i] = createTaskDataPool(i)).setEnable(CommonSetting.logicUsePool); } } petUseLogicPool.setEnable(CommonSetting.logicUsePool); }
/// <summary> /// 执行taskEvent /// </summary> protected void doTaskEvent(TaskTypeConfig typeConfig, int[] args, bool onlyRefresh, bool useSecond2) { IntObjectMap <TaskData> dic; if ((typeConfig = TaskTypeConfig.get(typeConfig.id)).needSecondKey) { if (useSecond2) { if ((dic = _runningTaskTypeTwoDic2.get((long)typeConfig.id << 32 | args[0])) == null || dic.isEmpty()) { return; } } else { if ((dic = _runningTaskTypeTwoDic.get((long)typeConfig.id << 32 | args[0])) == null || dic.isEmpty()) { return; } } } else { if ((dic = _runningTaskTypeOneDic.get(typeConfig.id)) == null || dic.isEmpty()) { return; } } //不是客户端执行 if (!typeConfig.isClientDrive && !CommonSetting.isClientDriveLogic) { return; } bool lastIsComplete; int lastNum; foreach (TaskData v in dic) { //未完成 if (!(lastIsComplete = v.isComplete()) || typeConfig.needUpdate) { lastNum = v.num; if (onlyRefresh) { refreshTaskData(v); } else { toTaskEvent(v, args); } //有变化 if (lastNum != v.num) { taskRefresh(v); } //新的完成 if (v.isComplete() && !lastIsComplete) { taskComplete(v); } } } }
/// <summary> /// 任务目标事件 /// </summary> public void taskEvent(int type, params int[] args) { TaskTypeConfig config = TaskTypeConfig.get(type); doTaskEvent(config, args, false, false); }