You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

269 lines
10 KiB

using System;
using System.Collections.Generic;
//using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using ProtoCSStruct;
namespace Game
{
public class TaskEXHandler : BasePacketHandler
{
public override int GetServiceType()
{
return GameServiceType.TaskEXHandler;
}
//销毁的时候置空
public override void Dispose()
{
}
public TaskEXHandler()
{
}
public override void HandlerClientPacket(PlayerSession playerSession, StructPacket packet)
{
PlayerOnGame player = playerSession.Player;
if (player == null)
{
TraceLog.Error("TaskEXHandler.HandlerClientPacket player is null sessionid {0}",
playerSession.SessionID);
return;
}
switch (packet.MsgID)
{
case (int)CSGameMsgID.TaskexAcceptTaskReq:
OnTaskexAcceptTaskReq(player, packet);
break;
case (int)CSGameMsgID.TaskexHandoverTaskReq:
OnTaskexHandoverTaskReq(player, packet);
break;
case (int)CSGameMsgID.BatchTaskexHandoverTaskReq:
OnBatchTaskexHandoverTaskReq(player, packet);
break;
case (int)CSGameMsgID.TaskexUpexinfoReq:
OnTaskexUpEXInfoReq(player, packet);
break;
case (int)CSGameMsgID.TaskexBatchUpexinfoReq:
OnTaskexBatchUpEXInfoReq(player, packet);
break;
default:
break;
}
}
public override void HandlerServerPacket(uint serverID, StructPacket packet)
{
switch (packet.MsgID)
{
case (int)SSGameMsgID.OperationUpdateTaskReq:
{
OnGmDoneTaskReq(packet);
}
break;
default:
break;
}
}
public void OnGmDoneTaskReq(StructPacket packet)
{
SSOperationUpdateTaskRes res = new SSOperationUpdateTaskRes();
SSOperationUpdateTaskReq req = packet.GetMessage<SSOperationUpdateTaskReq>();
res.Id = req.Id;
res.TaskId = req.TaskId;
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (player == null)
{
req.Model = 1;
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.OperationUpdateTaskReq, ref req, packet.ObjectID);
return;
}
var taskId = req.TaskId;
ref var taskList = ref player.RoleData.TaskEXData.TaskList;
int index = -1;
for (int i = 0; i < taskList.Count; i++)
{
if (taskList[i].TaskId == taskId && taskList[i].Status == (int)TaskEXCfg.TaskStatusProcessing)
{
index = i;
break;
}
}
if (index == -1)
{
res.Ret = -1;
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.OperationUpdateTaskRes, ref res, packet.ObjectID);
return;
}
ref var task = ref taskList[index];
task.Status = (int)TaskEXCfg.TaskStatusComplete;
var desc = QuestEXDescMgr.Instance.GetConfig(taskId);
ref var condition = ref task.Condition;
for (int i = 0; i < desc.fulfill.Length; i++)
{
var cd = desc.fulfill[i].Condition;
for (int j = 0; j < Math.Min(cd.Length, condition.Count); j++)
{
condition[j].CurrVal = (int)cd[j];
condition[j].Done = true;
}
}
player.MakeDirty();
CSTaskEXChangeNotify chgNotify = new CSTaskEXChangeNotify();
chgNotify.ChgTaskList.Add(task);
player.SendToClient((int)CSGameMsgID.TaskexChangeNotify, ref chgNotify);
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.OperationUpdateTaskRes, ref res, packet.ObjectID);
}
private void OnTaskexAcceptTaskReq(PlayerOnGame player, StructPacket packet)
{
ref CSTaskEXAcceptTaskReq req = ref packet.GetMessage<CSTaskEXAcceptTaskReq>();
CSTaskEXAcceptTaskRes res = new CSTaskEXAcceptTaskRes
{
TaskId = req.TaskId,
Ret = TaskEXSvc.ProcessAcceptTask(player, req.TaskId, true, out int index)
};
if (res.Ret == CSErrCode.None)
{
res.Taskdata.CopyFrom(ref TaskEXSvc.GetTaskByIndex(player, index));
}
// 如果任务不存在于配置中就不理客户端了
if (res.Ret != CSErrCode.TaskNotExist)
{
player.SendToClient((int)CSGameMsgID.TaskexAcceptTaskRes, ref res);
}
if (res.Ret == CSErrCode.None)
{
TaskEXSvc.RefreshTaskStatus(player, res.TaskId);
}
TraceLog.Trace("TaskEXHandler OnTaskexAcceptTaskReq. uid {0} accept task {1} ret {2}", player.UserID, req.TaskId, res.Ret);
}
private static void OnTaskexHandoverTaskReq(PlayerOnGame player, StructPacket packet)
{
ref CSTaskEXHandoverTaskReq req = ref packet.GetMessage<CSTaskEXHandoverTaskReq>();
var descTask = QuestEXDescMgr.Instance.GetConfig(req.TaskId);
if (descTask == null)
{
TraceLog.Error("TaskEXHandler OnTaskexHandoverTaskReq get descTask is null id:{0}.", req.TaskId);
return;
}
CSTaskEXHandoverTaskRes res = new CSTaskEXHandoverTaskRes
{
TaskId = req.TaskId,
};
res.Ret = TaskEXSvc.ProcessHandoverTask(player, req.TaskId, true, out int index);
//TaskEXSvc.ProcessHandoverTask 内部没有对错误的交付进行回包
if (res.Ret != CSErrCode.None)
{
player.SendToClient((int)CSGameMsgID.TaskexHandoverTaskRes, ref res);
}
//处理些特殊任务问题,不去侵入任务逻辑
if (res.Ret == CSErrCode.None)
{
}
if (res.TaskId == 11)
{
GameTALogUtils.LogToClient(player, "battle_1time");
}
TraceLog.Trace("TaskEXHandler.OnTaskexHandoverTaskReq uid {0} handover task {1} ret {2}", player.UserID, req.TaskId, res.Ret);
}
private static void OnBatchTaskexHandoverTaskReq(PlayerOnGame player, StructPacket packet)
{
ref var req = ref packet.GetMessage<CSBatchTaskEXHandoverTaskReq>();
var res = new CSBatchTaskEXHandoverTaskRes
{
Ret = TaskEXSvc.ProcessBatchHandoverTask(player, ref req, true, out _)
};
player.SendToClient((int)CSGameMsgID.BatchTaskexHandoverTaskRes, ref res);
}
private static void OnTaskexUpEXInfoReq(PlayerOnGame player, StructPacket packet)
{
ref CSTaskEXUpEXInfoReq req = ref packet.GetMessage<CSTaskEXUpEXInfoReq>();
CSTaskEXUpEXInfoRes res = new CSTaskEXUpEXInfoRes
{
TaskId = req.TaskId,
Ret = CSErrCode.Fail
};
if (TaskEXSvc.IsVaildTaskID(player, req.TaskId) == true)
{
int taskIdx = TaskEXSvc.GetTaskIndex(player, req.TaskId);
if (taskIdx != -1)
{
ref DBTaskEXOne taskOne = ref TaskEXSvc.GetTaskByIndex(player, taskIdx);
{
TraceLog.Error("TaskEXHandler OnTaskexUpEXInfoReq. uid {0} taskid {1} task.ExIdx {2} CheckIsVaildEXposInfo == false",
player.UserID, req.TaskId, req.ExIdx);
}
}
else
{
TraceLog.Error("TaskEXHandler OnTaskexUpEXInfoReq. uid {0} taskid {1} TaskEXSvc.GetTaskIndex == -1", player.UserID, req.TaskId);
}
}
else
{
TraceLog.Error("TaskEXHandler OnTaskexUpEXInfoReq. uid {0} taskid {1} IsVaildTaskID == false", player.UserID, req.TaskId);
}
player.SendToClient((int)CSGameMsgID.TaskexUpexinfoRes, ref res);
TraceLog.Trace("TaskEXHandler OnTaskexUpEXInfoReq. uid {0} taskid {1} task.ExIdx {2} ret {3}", player.UserID, req.TaskId, req.ExIdx, res.Ret);
}
private static void OnTaskexBatchUpEXInfoReq(PlayerOnGame player, StructPacket packet)
{
ref CSTaskEXBatchUpEXInfoReq req = ref packet.GetMessage<CSTaskEXBatchUpEXInfoReq>();
CSTaskEXBatchUpEXInfoRes res = new CSTaskEXBatchUpEXInfoRes
{
TaskId = req.TaskId,
Ret = CSErrCode.Fail
};
if (TaskEXSvc.IsVaildTaskID(player, req.TaskId) == true)
{
int taskIdx = TaskEXSvc.GetTaskIndex(player, req.TaskId);
if (taskIdx != -1)
{
ref DBTaskEXOne taskOne = ref TaskEXSvc.GetTaskByIndex(player, taskIdx);
}
else
{
TraceLog.Error("TaskEXHandler.OnTaskexBatchUpEXInfoReq uid {0} taskid {1} TaskEXSvc.GetTaskIndex == -1", player.UserID, req.TaskId);
}
}
else
{
TraceLog.Error("TaskEXHandler.OnTaskexBatchUpEXInfoReq uid {0} taskid {1} IsVaildTaskID == false", player.UserID, req.TaskId);
}
player.SendToClient((int)CSGameMsgID.TaskexBatchUpexinfoRes, ref res);
TraceLog.Trace("TaskEXHandler.OnTaskexBatchUpEXInfoReq uid {0} taskid {1} ret {2}", player.UserID, req.TaskId, res.Ret);
}
}
}