73 lines
2.3 KiB
Go
73 lines
2.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"ecs/proto"
|
|
"ecs/proto/pb"
|
|
"ecs/servers/game/logic"
|
|
"github.com/oylshe1314/framework/net"
|
|
)
|
|
|
|
func (this *PlayerHandler) TaskCommit(player *logic.Player, msg *net.Message) {
|
|
var req = new(pb.TaskCommitReq)
|
|
var err = msg.Read(req)
|
|
if err != nil {
|
|
this.Logger().Error("Read message failed, ", err)
|
|
_ = player.TipNotice(proto.TipMessageError)
|
|
return
|
|
}
|
|
|
|
if req.Id == 0 {
|
|
this.Logger().Error("Parameter error, req.Id == 0")
|
|
_ = player.TipNotice(proto.TipParameterError)
|
|
return
|
|
}
|
|
|
|
var task = player.Task[req.Id]
|
|
if task == nil {
|
|
this.Logger().Error("Parameter error, Player 'Task' not found, id: ", req.Id)
|
|
_ = player.TipNotice(proto.TipTaskNotFound)
|
|
return
|
|
}
|
|
|
|
var taskTable = this.tables.Task.Find1(int(req.Id))
|
|
if taskTable == nil {
|
|
this.Logger().Error("Parameter or data error, Table 'Task' not found, id: ", req.Id)
|
|
_ = player.TipNotice(proto.TipDataTablesError)
|
|
return
|
|
}
|
|
|
|
if pb.AbleStatus(task.Status) < pb.AbleStatus_Able {
|
|
this.Logger().Errorf("The task was not completed, id: %d, status: %d", task.Id, task.Status)
|
|
_ = player.TipNotice(proto.TipTaskNotCompleted)
|
|
return
|
|
}
|
|
|
|
if pb.AbleStatus(task.Status) > pb.AbleStatus_Already {
|
|
this.Logger().Errorf("The task has been completed, id: %d, status: %d", task.Id, task.Status)
|
|
_ = player.TipNotice(proto.TipTaskHasCommitted)
|
|
return
|
|
}
|
|
|
|
var rewardList []*pb.Item
|
|
for i := range taskTable.ItemIds {
|
|
_ = player.AddItem(uint32(taskTable.ItemIds[i]), uint32(taskTable.ItemNums[i]), logic.LogTypeItemObtainByTask)
|
|
rewardList = append(rewardList, &pb.Item{ItemId: uint32(taskTable.ItemIds[i]), ItemNum: uint32(taskTable.ItemNums[i])})
|
|
}
|
|
|
|
task.Status = uint32(pb.AbleStatus_Already)
|
|
|
|
player.AddCounter(pb.CounterType_TaskCompleted, uint64(task.Id), 1)
|
|
|
|
delete(player.Task, task.Id)
|
|
player.WipeModel(task)
|
|
|
|
_ = player.Send(pb.ModId_ModuleTask, pb.MsgId_ModTaskCommit, &pb.TaskCommitAck{Id: task.Id, ItemList: rewardList})
|
|
_ = player.Send(pb.ModId_ModuleTask, pb.MsgId_ModTaskChange, &pb.TaskChangeListAck{
|
|
ChangeList: []*pb.TaskChange{{ChangeType: pb.ChangeType_Delete, Task: task.BuildMsgTask()}},
|
|
})
|
|
|
|
player.AddTask(taskTable.RearIds...)
|
|
|
|
// this.eventManager.PlayerTaskLog(player, logic.LogTypeTaskRemove, uint32(taskTable.Id), taskTable.Section1, taskTable.Section2, task.Process)
|
|
}
|