359 lines
12 KiB
Go
359 lines
12 KiB
Go
package handler
|
|
|
|
import (
|
|
"ecs/servers/game/logic"
|
|
"github.com/oylshe1314/framework/net"
|
|
)
|
|
|
|
func (this *PlayerHandler) BattleEnd(player *logic.Player, msg *net.Message) {
|
|
player.EndBattle()
|
|
}
|
|
|
|
//func (this *PlayerHandler) battleVerify() error {
|
|
// //TODO implement it
|
|
// return nil
|
|
//}
|
|
//
|
|
//func (this *PlayerHandler) BattleResult(player *logic.Player, msg *net.Message) {
|
|
// var req = new(proto.MsgBattleResultReq)
|
|
// var err = msg.Read(req)
|
|
// if err != nil {
|
|
// this.logger.Error("Read message failed, ", err)
|
|
// _ = player.TipNotice(proto.ErrMessageError)
|
|
// return
|
|
// }
|
|
//
|
|
// if req.SceneId != player.Temp.SceneId {
|
|
// this.logger.Errorf("Parameter error, req.SceneId: %d, player.Temp.SceneId: %d", req.SceneId, player.Temp.SceneId)
|
|
// _ = player.TipNotice(proto.ErrParameterError)
|
|
// return
|
|
// }
|
|
//
|
|
// if !player.Temp.Fighting {
|
|
// this.logger.Errorf("Not in fighting, req.SceneId: ", req.SceneId)
|
|
// _ = player.TipNotice(proto.ErrNotInFighting)
|
|
// return
|
|
// }
|
|
//
|
|
// var sceneTable = this.tables.Scene.Get(int(req.SceneId))
|
|
// if sceneTable == nil {
|
|
// this.logger.Error("Parameter or data tables error, Table 'Scene' was not found, req.SceneId: ", req.SceneId)
|
|
// _ = player.TipNotice(proto.ErrSceneNotFound)
|
|
// return
|
|
// }
|
|
//
|
|
// if proto.CopyType(sceneTable.CopyType) == proto.CopyTypeArena { //判断场景如果是竞技场
|
|
// this.logger.Error("Parameter error, sceneTable.CopyType == proto.CopyTypeArena")
|
|
// _ = player.TipNotice(proto.ErrParameterError)
|
|
// return
|
|
// }
|
|
//
|
|
// if req.Result > 0 {
|
|
// err = this.battleVerify()
|
|
// if err != nil {
|
|
// this.logger.Error("Battle verify failed, ", err)
|
|
// _ = player.Send(proto.ModIdBattle, proto.MsgIdBattleResult, &proto.MsgBattleResultAck{
|
|
// SceneId: req.SceneId,
|
|
// Result: 0,
|
|
// })
|
|
// return
|
|
// }
|
|
// }
|
|
//
|
|
// var maxScore int32
|
|
// for _, kill := range req.KillList {
|
|
// if kill.Id == 0 || kill.Num == 0 {
|
|
// this.logger.Warn("Parameter error, kill.Id == 0 || kill.Num == 0")
|
|
// continue
|
|
// }
|
|
//
|
|
// var monsterTable = this.tables.Monster.Get(int(kill.Id))
|
|
// if monsterTable == nil {
|
|
// this.logger.Warn("Parameter or data error, Table 'Monster' was not found, id: ", kill.Id)
|
|
// continue
|
|
// }
|
|
//
|
|
// maxScore += int32(monsterTable.KillScore) * int32(kill.Num)
|
|
//
|
|
// player.CheckTask(proto.TaskSection1KillSpecificMonster, monsterTable.Id, int(kill.Num))
|
|
// player.CheckTask(proto.TaskSection1KillClassifyMonsters, monsterTable.Type, int(kill.Num))
|
|
// }
|
|
//
|
|
// var rewardMap = map[uint32]uint32{}
|
|
// for _, itemPair := range req.ItemList {
|
|
// rewardMap[itemPair.ItemId] += itemPair.ItemNum
|
|
// }
|
|
//
|
|
// var copyRank uint32
|
|
// if req.Result > 0 {
|
|
// copyRank, err = player.PassedCopy(sceneTable, req.Duration, req.MaxDepth, maxScore)
|
|
// if err != nil {
|
|
// _ = player.TipNotice(err)
|
|
// return
|
|
// }
|
|
//
|
|
// this.reduceLevelSuccessConsume(sceneTable, player, 1)
|
|
//
|
|
// var dropResult [][2]uint32
|
|
// if player.GetCopyPassedNum(uint32(sceneTable.Id)) == 0 {
|
|
// dropResult = this.tables.DropExtend.Drop(sceneTable.FirstRewardId, 1)
|
|
// for _, itemPair := range dropResult {
|
|
// rewardMap[itemPair[0]] += itemPair[1]
|
|
// }
|
|
// }
|
|
//
|
|
// dropResult = this.tables.DropExtend.Drop(sceneTable.RewardId, 1)
|
|
// for _, itemPair := range dropResult {
|
|
// rewardMap[itemPair[0]] += itemPair[1]
|
|
// }
|
|
// }
|
|
//
|
|
// var outputMultiple = int64(1)
|
|
// if proto.CopyType(sceneTable.CopyType) == proto.CopyTypeMaterial {
|
|
// outputMultiple = player.CheckMonthlyCardPrivilege(proto.MonthlyCardPrivilegeTypeCoinCopyOutputMultiple)
|
|
// if outputMultiple < 1 {
|
|
// outputMultiple = 1
|
|
// }
|
|
// }
|
|
//
|
|
// player.AddItems(rewardMap, logic.LogTypeItemObtainByCopy)
|
|
//
|
|
// var rewardList []*proto.ItemPair
|
|
// var extraRewards []*proto.BattleExtraReward
|
|
// for itemId, itemNum := range rewardMap {
|
|
// if itemId == 0 || itemNum == 0 {
|
|
// continue
|
|
// }
|
|
//
|
|
// var extraItemNum = uint32(0)
|
|
// var itemTable = this.tables.Item.Get(int(itemId))
|
|
// if proto.ItemType(itemTable.ItemType) == proto.ItemTypeMoney && proto.MoneyType(itemTable.Subtype) == proto.MoneyTypeCoin {
|
|
// itemNum += uint32(float64(itemNum) * (player.RigAttr(proto.AttrTypeExtraCoinRate) * proto.AttrRateIn))
|
|
// if outputMultiple > 1 {
|
|
// extraItemNum = itemNum * uint32(outputMultiple-1)
|
|
// extraRewards = append(extraRewards, &proto.BattleExtraReward{
|
|
// Type: 1,
|
|
// MsgRewardListAck: &proto.MsgRewardListAck{RewardList: []*proto.ItemPair{{ItemId: itemId, ItemNum: extraItemNum}}},
|
|
// })
|
|
// }
|
|
// }
|
|
//
|
|
// rewardList = append(rewardList, &proto.ItemPair{ItemId: itemId, ItemNum: itemNum})
|
|
// }
|
|
//
|
|
// _ = player.Send(proto.ModIdBattle, proto.MsgIdBattleResult, &proto.MsgBattleResultAck{
|
|
// MsgRewardListAck: &proto.MsgRewardListAck{RewardList: rewardList},
|
|
// SceneId: req.SceneId,
|
|
// Result: req.Result,
|
|
// CopyRank: copyRank,
|
|
// ExtraRewards: extraRewards,
|
|
// })
|
|
//
|
|
// player.EndBattle()
|
|
//}
|
|
//
|
|
//func (this *PlayerHandler) IdleBattleGetReward(player *logic.Player, _ *net.Message) {
|
|
// if player.IdleBattle == nil {
|
|
// this.logger.Error("Not in idle battle")
|
|
// _ = player.TipNotice(proto.ErrNotInIdleBattle)
|
|
// return
|
|
// }
|
|
//
|
|
// var idleProfitTable = this.tables.IdleProfit.Get(int(player.IdleBattle.SceneId))
|
|
// if idleProfitTable == nil {
|
|
// this.logger.Error("Data error, Table 'IdleProfit' was not found, sceneId: ", player.IdleBattle.SceneId)
|
|
// _ = player.TipNotice(proto.ErrDataTablesError)
|
|
// return
|
|
// }
|
|
//
|
|
// if len(player.IdleBattle.Rewards) == 0 {
|
|
// this.logger.Error("No idle battle rewards")
|
|
// _ = player.TipNotice(proto.ErrIdleBattleNoRewards)
|
|
// return
|
|
// }
|
|
//
|
|
// player.AddItems(player.IdleBattle.Rewards, logic.LogTypeItemObtainByIdleBattle)
|
|
//
|
|
// var rewardList []*proto.ItemPair
|
|
// for itemId, itemNum := range player.IdleBattle.Rewards {
|
|
// rewardList = append(rewardList, &proto.ItemPair{ItemId: itemId, ItemNum: itemNum})
|
|
// }
|
|
//
|
|
// _ = player.Send(proto.ModIdBattle, proto.MsgIdIdleBattleGetReward, &proto.MsgIdleBattleRewardListAck{MsgRewardListAck: &proto.MsgRewardListAck{RewardList: rewardList}})
|
|
//
|
|
// var now = util.Unix()
|
|
// if now-player.IdleBattle.GetTime >= int64(idleProfitTable.IdleLimit) {
|
|
// player.IdleBattle.PutTime = now
|
|
// player.SaveField("idle_battle.put_time", player.IdleBattle.PutTime)
|
|
// }
|
|
//
|
|
// player.IdleBattle.GetTime = now
|
|
// player.SaveField("idle_battle.get_time", player.IdleBattle.GetTime)
|
|
// player.IdleBattle.Rewards = map[uint32]uint32{}
|
|
// player.SaveField("idle_battle.rewards", player.IdleBattle.Rewards)
|
|
//
|
|
// _ = player.Send(proto.ModIdBattle, proto.MsgIdIdleBattleStatus, player.BuildMsgIdleBattleStatusAck())
|
|
//
|
|
// player.CheckTask(proto.TaskSection1GetIdleBattleRewards, 0, 1)
|
|
//}
|
|
//
|
|
//func (this *PlayerHandler) IdleQuickBattle(player *logic.Player, _ *net.Message) {
|
|
// if player.IdleBattle == nil {
|
|
// this.logger.Error("Not in idle battle")
|
|
// _ = player.TipNotice(proto.ErrNotInIdleBattle)
|
|
// return
|
|
// }
|
|
//
|
|
// var idleProfitTable = this.tables.IdleProfit.Get(int(player.IdleBattle.SceneId))
|
|
// if idleProfitTable == nil {
|
|
// this.logger.Error("Data error, Table 'IdleProfit' was not found, sceneId: ", player.IdleBattle.SceneId)
|
|
// _ = player.TipNotice(proto.ErrDataTablesError)
|
|
// return
|
|
// }
|
|
//
|
|
// var counter = player.GetCounterDaily(proto.CounterTypeIdleQuickBattle, 1)
|
|
// if counter >= uint32(idleProfitTable.DailyTimes) {
|
|
// this.logger.Error("Daily idle quick battle times over, counter: ", counter)
|
|
// _ = player.TipNotice(proto.ErrTodayTimesOver)
|
|
// return
|
|
// }
|
|
//
|
|
// var err = player.CheckMoney(proto.MoneyType(idleProfitTable.MoneyType), uint32(idleProfitTable.MoneyNum))
|
|
// if err != nil {
|
|
// this.logger.Errorf("%s, moneyType: %d, moneyNum: %d", err.Error(), idleProfitTable.MoneyType, idleProfitTable.MoneyNum)
|
|
// _ = player.TipNotice(err)
|
|
// return
|
|
// }
|
|
// player.ReduceMoney(proto.MoneyType(idleProfitTable.MoneyType), uint32(idleProfitTable.MoneyNum), logic.LogTypeItemConsumeByIdleQuickBattle)
|
|
//
|
|
// player.AddCounter(proto.CounterTypeIdleQuickBattle, 1, 1)
|
|
//
|
|
// var times = uint32(idleProfitTable.QuickRewardDuration) / uint32(idleProfitTable.Interval)
|
|
//
|
|
// var rewardMap = map[uint32]uint32{}
|
|
// for i, itemId := range idleProfitTable.ItemId {
|
|
// rewardMap[uint32(itemId)] = uint32(idleProfitTable.ItemNum[i]) * times
|
|
// }
|
|
//
|
|
// var dropResult = this.tables.DropExtend.Drop(idleProfitTable.DropId, int(times))
|
|
// for _, itemPair := range dropResult {
|
|
// rewardMap[itemPair[0]] += itemPair[1]
|
|
// }
|
|
//
|
|
// player.AddItems(rewardMap, logic.LogTypeItemObtainByIdleQuickBattle)
|
|
//
|
|
// var rewardList []*proto.ItemPair
|
|
// for itemId, itemNum := range rewardMap {
|
|
// rewardList = append(rewardList, &proto.ItemPair{ItemId: itemId, ItemNum: itemNum})
|
|
// }
|
|
//
|
|
// _ = player.Send(proto.ModIdBattle, proto.MsgIdIdleBattleGetReward, &proto.MsgIdleBattleRewardListAck{MsgRewardListAck: &proto.MsgRewardListAck{RewardList: rewardList}})
|
|
//
|
|
// player.CheckTask(proto.TaskSection1GetIdleBattleRewards, 0, 1)
|
|
//}
|
|
//
|
|
//func (this *PlayerHandler) ArenaBattleResult(player *logic.Player, msg *net.Message) {
|
|
// var req = new(proto.MsgBattleResultReq)
|
|
// var err = msg.Read(req)
|
|
// if err != nil {
|
|
// this.logger.Error("Read message failed, ", err)
|
|
// _ = player.TipNotice(proto.ErrMessageError)
|
|
// return
|
|
// }
|
|
//
|
|
// if req.SceneId != player.Temp.SceneId {
|
|
// this.logger.Errorf("Parameter error, req.SceneId: %d, player.Temp.SceneId: %d", req.SceneId, player.Temp.SceneId)
|
|
// _ = player.TipNotice(proto.ErrParameterError)
|
|
// return
|
|
// }
|
|
//
|
|
// if !player.Temp.Fighting {
|
|
// this.logger.Errorf("Not in fighting, req.SceneId: ", req.SceneId)
|
|
// _ = player.TipNotice(proto.ErrNotInFighting)
|
|
// return
|
|
// }
|
|
//
|
|
// var sceneTable = this.tables.Scene.Get(int(req.SceneId))
|
|
// if sceneTable == nil {
|
|
// this.logger.Error("Parameter or data tables error, Table 'Scene' was not found, req.SceneId: ", req.SceneId)
|
|
// _ = player.TipNotice(proto.ErrSceneNotFound)
|
|
// return
|
|
// }
|
|
//
|
|
// var copyArenaTable = this.tables.CopyArena.Get(1)
|
|
// if copyArenaTable == nil {
|
|
// this.logger.Error("Parameter or data error, Table 'CopyArena' was not found, id: 1")
|
|
// _ = player.TipNotice(proto.ErrDataTablesError)
|
|
// return
|
|
// }
|
|
//
|
|
// if sceneTable.Id != copyArenaTable.ArenaSceneId {
|
|
// this.logger.Errorf("Parameter or data error, The id of scene not arena scene id, sceneTable.Id: %d, copyArenaTable.ArenaSceneId: %d", sceneTable.Id, copyArenaTable.ArenaSceneId)
|
|
// _ = player.TipNotice(proto.ErrDataTablesError)
|
|
// return
|
|
// }
|
|
//
|
|
// player.AddCounter(proto.CounterTypeCopyArena, uint32(copyArenaTable.Id), 1)
|
|
//
|
|
// var enemyPlayer = player.Temp.ArenaEnemy
|
|
//
|
|
// myScore, enemyScore := player.PassedCopyArena(copyArenaTable, req.Result > 0, enemyPlayer)
|
|
//
|
|
// var rewardList []*proto.ItemPair
|
|
// var rewardTables = this.tables.CopyArenaRewardExtend.Get(copyArenaTable.Id, 2)
|
|
// for _, rewardTable := range rewardTables {
|
|
// for i := range rewardTable.ItemList {
|
|
// _ = player.AddItem(uint32(rewardTable.ItemList[i]), uint32(rewardTable.NumList[i]), logic.LogTypeItemObtainByArenaChallenge)
|
|
// rewardList = append(rewardList, &proto.ItemPair{ItemId: uint32(rewardTable.ItemList[i]), ItemNum: uint32(rewardTable.NumList[i])})
|
|
// }
|
|
// }
|
|
//
|
|
// _ = player.Send(proto.ModIdBattle, proto.MsgIdArenaBattleResult, &proto.MsgArenaBattleResultAck{
|
|
// MsgRewardListAck: &proto.MsgRewardListAck{
|
|
// RewardList: rewardList,
|
|
// },
|
|
// Result: req.Result,
|
|
// Self: &proto.ArenaPlayer{
|
|
// PlayerId: player.PlayerId,
|
|
// Name: player.Role.Name,
|
|
// Avatar: player.Role.Avatar,
|
|
// MaxScore: myScore,
|
|
// },
|
|
// Enemy: &proto.ArenaPlayer{
|
|
// PlayerId: enemyPlayer.PlayerId,
|
|
// Name: enemyPlayer.Name,
|
|
// Avatar: enemyPlayer.Avatar,
|
|
// MaxScore: enemyScore,
|
|
// },
|
|
// })
|
|
//
|
|
// player.EndBattle()
|
|
//
|
|
// player.CheckTask(proto.TaskSection1ArenaChallengeTimes, 0, 1)
|
|
//}
|
|
//
|
|
//func (this *PlayerHandler) BattleRadarUse(player *logic.Player, msg *net.Message) {
|
|
// var radarTable = this.tables.Radar.Get(1)
|
|
// if radarTable == nil {
|
|
// this.logger.Error("Parameter or data error, Table 'Radar' was not found, id: 1")
|
|
// _ = player.TipNotice(proto.ErrDataTablesError)
|
|
// return
|
|
// }
|
|
//
|
|
// var duration = int64(radarTable.AdRadarTime)
|
|
// if !player.CheckAdFunction(proto.AdFunctionTypeRadar, 0, 0, 1) {
|
|
// var counter = player.GetCounterDaily(proto.CounterTypeRadar, uint32(radarTable.Id))
|
|
// if counter >= uint32(radarTable.DailyTimes) {
|
|
// this.logger.Error("Daily radar use times over, count: ", counter)
|
|
// _ = player.TipNotice(proto.ErrTodayTimesOver)
|
|
// return
|
|
// }
|
|
// duration = int64(radarTable.FreeRadarTime)
|
|
// }
|
|
//
|
|
// player.ChangeProperty(util.NewPair(proto.RolePropertyTypeRadarEndTime, uint64(util.Unix()+duration)))
|
|
//
|
|
// _ = player.Send(proto.ModIdBattle, proto.MsgIdBattleRadarUse, &proto.MsgBattleRadarUseAck{Duration: duration})
|
|
//
|
|
//}
|