package handler import ( "ecs/proto" "ecs/proto/pb" "ecs/servers/game/data" "ecs/servers/game/logic" "github.com/oylshe1314/framework/net" ) func (this *PlayerHandler) checkLevelConsume(sceneTable *data.Scene, player *logic.Player, times uint32) proto.TipError { var consume = map[uint32]uint32{} for i := range sceneTable.ConsumeItems { consume[uint32(sceneTable.ConsumeItems[i])] += uint32(sceneTable.ConsumeNums[i]) * times } for i := range sceneTable.SuConsumeItems { consume[uint32(sceneTable.SuConsumeItems[i])] += uint32(sceneTable.SuConsumeNums[i]) * times } for itemId, itemNum := range consume { if ok, tip := player.CheckItem(itemId, itemNum); !ok { return tip } } return nil } func (this *PlayerHandler) reduceLevelConsume(sceneTable *data.Scene, player *logic.Player, times uint32) { this.reduceLevelEnterConsume(sceneTable, player, times) this.reduceLevelSuccessConsume(sceneTable, player, times) } func (this *PlayerHandler) reduceLevelEnterConsume(sceneTable *data.Scene, player *logic.Player, times uint32) { for i := range sceneTable.ConsumeItems { player.ReduceItem(uint32(sceneTable.ConsumeItems[i]), uint32(sceneTable.ConsumeNums[i])*times, logic.LogTypeItemConsumeByCopy) } } func (this *PlayerHandler) reduceLevelSuccessConsume(sceneTable *data.Scene, player *logic.Player, times uint32) { for i := range sceneTable.SuConsumeItems { player.ReduceItem(uint32(sceneTable.SuConsumeItems[i]), uint32(sceneTable.SuConsumeNums[i])*times, logic.LogTypeItemConsumeByCopy) } } func (this *PlayerHandler) enterCopyMain(player *logic.Player, levelId uint32) { var copyMainTable = this.tables.CopyMain.Get(int(levelId)) if copyMainTable == nil { this.logger.Error("Parameter or data error, Table 'CopyMain' was not found, levelId: ", levelId) _ = player.TipNotice(proto.TipDataTablesError) return } for i, unlockType := range copyMainTable.UnlockType { switch unlockType { case 1: if player.RoleHero.Level < uint32(copyMainTable.UnlockArgs[i]) { _ = player.TipNotice(proto.TipCopyCanNotEnter) return } case 2: if player.GetCopyPassedNum(uint32(copyMainTable.UnlockArgs[i])) == 0 { _ = player.TipNotice(proto.TipCopyCanNotEnter) return } case 3: if player.GetCounterTotal(pb.CounterType_TaskCompleted, uint64(copyMainTable.UnlockArgs[i])) == 0 { _ = player.TipNotice(proto.TipCopyCanNotEnter) return } } } var sceneTable = this.tables.Scene.Get(copyMainTable.SceneId) if sceneTable == nil { this.logger.Error("Data error, Table 'Scene' was not found, sceneId: ", copyMainTable.SceneId) _ = player.TipNotice(proto.TipDataTablesError) return } var err = this.checkLevelConsume(sceneTable, player, 1) if err != nil { _ = player.TipNotice(err) return } this.reduceLevelEnterConsume(sceneTable, player, 1) player.EnterBattle(sceneTable) } //func (this *PlayerHandler) enterCopyMaterial(player *logic.Player, indexId uint32) { // var copyMaterialTable = this.tables.CopyMaterial.Get(int(indexId)) // if copyMaterialTable == nil { // this.logger.Error("Parameter or data error, Table 'CopyChapter' was not found, indexId: ", indexId) // _ = player.TipNotice(proto.TipCopyNotFound) // return // } // // var counter = player.GetCounterDaily(proto.CounterTypeCopyMaterial, uint32(copyMaterialTable.MaterialType)) // if counter >= uint32(copyMaterialTable.Time) { // this.logger.Errorf("Daily times over, CounterType: %d, Id: %d, counter: %d, times: %d", proto.CounterTypeCopyMaterial, copyMaterialTable.MaterialType, counter, copyMaterialTable.Time) // _ = player.TipNotice(proto.TipTodayTimesOver) // return // } // // var sceneTable = this.tables.Scene.Get(copyMaterialTable.SceneId) // if sceneTable == nil { // this.logger.Error("Data error, Table 'Scene' was not found, sceneId: ", copyMaterialTable.SceneId) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var err = this.checkLevelConsume(sceneTable, player, 1) // if err != nil { // _ = player.TipNotice(err) // return // } // // this.reduceLevelEnterConsume(sceneTable, player, 1) // // player.enterScene(uint32(sceneTable.Id), true) //} // //func (this *PlayerHandler) enterCopySpeed(player *logic.Player, indexId uint32) { // var copySpeedTable = this.tables.CopySpeed.Get(int(indexId)) // if copySpeedTable == nil { // this.logger.Error("Parameter or data error, Table 'CopyChapter' was not found, indexId: ", indexId) // _ = player.TipNotice(proto.TipCopyNotFound) // return // } // // var counter = player.GetCounterDaily(proto.CounterTypeCopySpeed, uint32(copySpeedTable.CopyType)) // if counter >= uint32(copySpeedTable.LimitTimes) { // this.logger.Errorf("Daily times over, CounterType: %d, Id: %d, counter: %d, times: %d", proto.CounterTypeCopySpeed, copySpeedTable.CopyType, counter, copySpeedTable.LimitTimes) // _ = player.TipNotice(proto.TipTodayTimesOver) // return // } // // var season = this.arenaManager.CopySpeedSeason() // if season == nil { // this.logger.Error("Copy not in time, season == nil") // _ = player.TipNotice(proto.TipCopyNotInTime) // return // } // // var sceneTable = this.tables.Scene.Get(copySpeedTable.SceneId) // if sceneTable == nil { // this.logger.Error("Data error, Table 'Scene' was not found, sceneId: ", copySpeedTable.SceneId) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var err = this.checkLevelConsume(sceneTable, player, 1) // if err != nil { // _ = player.TipNotice(err) // return // } // // this.reduceLevelEnterConsume(sceneTable, player, 1) // // player.AddCopySpeed(season, copySpeedTable) // // player.enterScene(uint32(sceneTable.Id), true) //} // //func (this *PlayerHandler) enterCopyArena(player *logic.Player, indexId uint32) { // var copyArenaTable = this.tables.CopyArena.Get(1) // if copyArenaTable == nil { // this.logger.Error("Parameter or data error, Table 'CopyChapter' was not found, indexId: ", indexId) // _ = player.TipNotice(proto.TipCopyNotFound) // return // } // // var season = this.arenaManager.CopyArenaSeason() // if season == nil { // this.logger.Error("Copy not in time, season == nil") // _ = player.TipNotice(proto.TipCopyNotInTime) // return // } // // var sceneTable = this.tables.Scene.Get(copyArenaTable.ArenaSceneId) // if sceneTable == nil { // this.logger.Error("Data error, Table 'Scene' was not found, sceneId: ", copyArenaTable.ArenaSceneId) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // if player.GetCounterDaily(proto.CounterTypeCopyArena, uint32(copyArenaTable.Id)) >= uint32(copyArenaTable.MaxChallengeNum) { // var err = this.checkLevelConsume(sceneTable, player, 1) // if err != nil { // _ = player.TipNotice(err) // return // } // // this.reduceLevelEnterConsume(sceneTable, player, 1) // } // // player.enterScene(uint32(sceneTable.Id), true) //} func (this *PlayerHandler) LevelEnter(player *logic.Player, msg *net.Message) { var req = new(pb.LevelEnterReq) var err = msg.Read(req) if err != nil { this.logger.Error("Read message failed, ", err) _ = player.TipNotice(proto.TipMessageError) return } if req.LevelId == 0 { this.logger.Error("Parameter error, req.LevelId == 0") _ = player.TipNotice(proto.TipParameterError) return } switch pb.CopyType(req.CopyType) { case pb.CopyType_CopyMain: this.enterCopyMain(player, req.LevelId) //case pb.CopyTypeMaterial: // this.enterCopyMaterial(player, req.IndexId) //case pb.CopyTypeReserve: // //TODO 暂时保留 // this.logger.Error("Parameter error, req.CopyType: ", req.CopyType) // _ = player.TipNotice(proto.TipParameterError) //case pb.CopyTypeSpeed: // this.enterCopySpeed(player, req.IndexId) //case pb.CopyTypeArena: //进入竞技场在选择对手的消息 // // return this.enterCopyArena(player, req.IndexId) // this.logger.Error("Parameter error, req.CopyType: ", req.CopyType) // _ = player.TipNotice(proto.TipParameterError) default: this.logger.Error("Parameter error, req.CopyType: ", req.CopyType) _ = player.TipNotice(proto.TipParameterError) } } //func (this *PlayerHandler) CopySpeedGetReward(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgCopySpeedGetRewardReq) // 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 copySpeedRewardTable = this.tables.CopySpeedReward.Get(int(req.Id)) // if copySpeedRewardTable == nil { // this.logger.Error("Data error, Table 'CopySpeedReward' was not found, id: ", req.Id) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var copySpeed = player.CopySpeed[uint32(copySpeedRewardTable.CopyId)] // if copySpeed == nil { // this.logger.Error("Reward unable, copySpeed == nil") // _ = player.TipNotice(proto.TipRewardUnable) // return // } // // if proto.RewardStatus(copySpeed.RewardStatus[req.Id]) == proto.RewardStatusUnable { // this.logger.Error("Reward unable, req.Id: ", req.Id) // _ = player.TipNotice(proto.TipRewardUnable) // return // } // // if proto.RewardStatus(copySpeed.RewardStatus[req.Id]) == proto.RewardStatusHasGot { // this.logger.Error("Reward has got, req.Id: ", req.Id) // _ = player.TipNotice(proto.TipRewardHasGot) // return // } // // var rewardList []*proto.ItemPair // for i := range copySpeedRewardTable.ItemList { // _ = player.AddItem(uint32(copySpeedRewardTable.ItemList[i]), uint32(copySpeedRewardTable.NumList[i]), logic.LogTypeItemObtainByCopySpeedReward) // rewardList = append(rewardList, &proto.ItemPair{ItemId: uint32(copySpeedRewardTable.ItemList[i]), ItemNum: uint32(copySpeedRewardTable.NumList[i])}) // } // // copySpeed.RewardStatus[req.Id] = uint32(proto.RewardStatusHasGot) // player.SaveField(fmt.Sprintf("arena_copy.%d.reward_status.%d", copySpeed.Id, req.Id), uint32(proto.RewardStatusHasGot)) // // _ = player.Send(proto.ModIdLevel, proto.MsgIdCopySpeedGetReward, &proto.MsgCopySpeedGetRewardAck{MsgRewardListAck: &proto.MsgRewardListAck{RewardList: rewardList}}) // // _ = player.Send(proto.ModIdLevel, proto.MsgIdCopySpeedRewardStatusChange, &proto.MsgCopySpeedRewardStatusChangeAck{StatusList: copySpeed.BuildCopySpeedRewardStatusList()}) //} // //func (this *PlayerHandler) CopySpeedRankList(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgCopySpeedRankListReq) // 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 copySpeedTable = this.tables.CopySpeed.Get(int(req.Id)) // if copySpeedTable == nil { // this.logger.Error("Parameter or data error, Table 'CopySpeed' was not found, req.Id: ", req.Id) // _ = player.TipNotice(proto.TipCopyNotFound) // return // } // // _ = player.Send(proto.ModIdLevel, proto.MsgIdCopySpeedRankList, player.BuildMsgCopySpeedRankListAck(uint32(copySpeedTable.Id))) //} // //func (this *PlayerHandler) ArenaPlayerDetail(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgArenaPlayerDetailReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.CopyId == 0 || req.PlayerId == 0 { // this.logger.Error("Parameter error, req.CopyId == 0 || req.PlayerId == 0") // _ = player.TipNotice(proto.TipParameterError) // return // } // // var season logic.ArenaSeason // switch proto.CopyType(req.CopyType) { // case proto.CopyTypeMainline: // season = this.arenaManager.CopyMainRanking() // case proto.CopyTypeSpeed: // season = this.arenaManager.CopySpeedSeason() // case proto.CopyTypeArena: // season = this.arenaManager.CopyArenaSeason() // default: // this.logger.Error("Parameter error, req.CopyType: ", req.CopyType) // _ = player.TipNotice(proto.TipParameterError) // return // } // // if season == nil { // this.logger.Error("Copy not in time, season == nil") // _ = player.TipNotice(proto.TipCopyNotInTime) // return // } // // var rankingPlayer = season.GetPlayer(req.PlayerId) // if rankingPlayer == nil { // this.logger.Error("Arena player not found: req.PlayerId: ", req.PlayerId) // _ = player.TipNotice(proto.TipArenaPlayerNotFound) // return // } // // var ack *proto.MsgArenaPlayerDetailAck // if req.PlayerId == player.PlayerId { // var playerSelf = &proto.ArenaPlayer{ // PlayerId: player.PlayerId, // IsRobot: false, // Name: player.Role.Name, // Avatar: player.Role.Avatar, // Capacity: player.RigAttrsCapacity(), // RigEquips: make([]uint32, proto.EquipNum), // RigPendants: make([]uint32, proto.PendantNum), // RigAttrs: player.Rig.Attrs[:], // } // // var copoment *logic.PlayerRigComponent // copoment = player.RigComponent[player.Rig.Head] // if copoment != nil { // playerSelf.RigHead = copoment.Id // playerSelf.RigHeadStar = copoment.StarId // } // // copoment = player.RigComponent[player.Rig.Body] // if copoment != nil { // playerSelf.RigBody = copoment.Id // playerSelf.RigBodyStar = copoment.StarId // } // // copoment = player.RigComponent[player.Rig.Tail] // if copoment != nil { // playerSelf.RigTail = copoment.Id // playerSelf.RigTailStar = copoment.StarId // } // // for i := range player.Rig.Equips { // var equip = player.RigEquip[player.Rig.Equips[i]] // if equip != nil { // playerSelf.RigEquips[i] = equip.Id // } // } // // for i := range player.Rig.Pendants { // var pendant = player.RigPendant[player.Rig.Pendants[i]] // if pendant != nil { // playerSelf.RigPendants[i] = pendant.Id // } // } // // ack = &proto.MsgArenaPlayerDetailAck{ // ArenaPlayer: playerSelf, // } // } else { // ack = &proto.MsgArenaPlayerDetailAck{ // ArenaPlayer: &proto.ArenaPlayer{ // PlayerId: rankingPlayer.PlayerId, // IsRobot: rankingPlayer.PlayerId < 1000000000, // Name: rankingPlayer.Name, // Avatar: rankingPlayer.Avatar, // Capacity: rankingPlayer.Capacity, // RigHead: rankingPlayer.RigHead, // RigHeadStar: rankingPlayer.RigHeadStar, // RigBody: rankingPlayer.RigBody, // RigBodyStar: rankingPlayer.RigBodyStar, // RigTail: rankingPlayer.RigTail, // RigTailStar: rankingPlayer.RigTailStar, // RigEquips: rankingPlayer.RigEquips[:], // RigPendants: rankingPlayer.RigPendants[:], // RigAttrs: rankingPlayer.RigAttrs[:], // }, // } // } // // var score = rankingPlayer.Scores[req.CopyId] // if score != nil { // ack.Duration = score.Duration // ack.MaxScore = score.MaxScore // ack.MaxDepth = score.MaxDepth // ack.RankIndex = score.RankIndex // } // // _ = player.Send(proto.ModIdLevel, proto.MsgIdArenaPlayerDetail, ack) //} // //func (this *PlayerHandler) MaterialCopySweep(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgMaterialCopySweepReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.IndexId == 0 || req.Times == 0 { // this.logger.Error("Parameter error, req.IndexId == 0 || req.Times == 0") // _ = player.TipNotice(proto.TipParameterError) // return // } // // switch proto.CopyType(req.CopyType) { // case proto.CopyTypeMainline: // this.logger.Error("Copy cannot sweep, req.CopyType: ", req.CopyType) // _ = player.TipNotice(proto.TipCopyCannotSweep) // return // case proto.CopyTypeMaterial: // var allowSweep = player.CheckMonthlyCardPrivilege(proto.MonthlyCardPrivilegeTypeMaterialCopyAllowSweep) > 0 // if !allowSweep { // _ = player.TipNotice(proto.TipCopyCannotSweep) // return // } // // var copyMaterialTable = this.tables.CopyMaterial.Get(int(req.IndexId)) // if copyMaterialTable == nil { // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var counter = player.GetCounterDaily(proto.CounterTypeCopyMaterial, uint32(copyMaterialTable.MaterialType)) // if counter >= uint32(copyMaterialTable.Time) { // this.logger.Errorf("Daily times over, CounterType: %d, Id: %d, counter: %d, times: %d", proto.CounterTypeCopyMaterial, copyMaterialTable.MaterialType, counter, copyMaterialTable.Time) // _ = player.TipNotice(proto.TipTodayTimesOver) // return // } // // err = this.sweepCopy(player, uint32(copyMaterialTable.SceneId), req.Times) // if err != nil { // _ = player.TipNotice(err) // return // } // case proto.CopyTypeReserve: // this.logger.Error("Copy cannot sweep, req.CopyType: ", req.CopyType) // _ = player.TipNotice(proto.TipCopyCannotSweep) // return // case proto.CopyTypeSpeed: // this.logger.Error("Copy cannot sweep, req.CopyType: ", req.CopyType) // _ = player.TipNotice(proto.TipCopyCannotSweep) // return // case proto.CopyTypeArena: // this.logger.Error("Copy cannot sweep, req.CopyType: ", req.CopyType) // _ = player.TipNotice(proto.TipCopyCannotSweep) // return // default: // this.logger.Error("Parameter error, req.CopyType: ", req.CopyType) // _ = player.TipNotice(proto.TipParameterError) // return // } //} // //func (this *PlayerHandler) sweepCopy(player *logic.Player, sceneId, times uint32) error { // var sceneTable = this.tables.Scene.Get(int(sceneId)) // if sceneTable == nil { // this.logger.Error("Data error, Table 'Scene' was not found, sceneId: ", sceneId) // return proto.TipDataTablesError // } // // var err = this.checkLevelConsume(sceneTable, player, times) // if err != nil { // this.logger.Error("Check level consume failed, ", err) // return err // } // // _, err = player.PassedCopy(sceneTable, 0, 0, 0) // if err != nil { // this.logger.Error("Passed copy failed, ", err) // return err // } // // this.reduceLevelConsume(sceneTable, player, times) // // var rewardMap = map[uint32]uint32{} // var sceneMapTables = this.tables.SceneMapExtend.Get(sceneTable.Id) // for _, sceneMapTable := range sceneMapTables { // if sceneMapTable.Seat1Monster <= 0 { // continue // } // // var monsterTable = this.tables.Monster.Get(sceneMapTable.Seat1Monster) // if monsterTable == nil { // continue // } // // for _, dropId := range monsterTable.DeathDropItems { // var dropResult = this.tables.DropExtend.Drop(dropId, int(times)) // for _, itemPair := range dropResult { // rewardMap[itemPair[0]] += itemPair[1] // } // } // // player.CheckTask(proto.TaskSection1KillSpecificMonster, monsterTable.Id, int(1*times)) // player.CheckTask(proto.TaskSection1KillClassifyMonsters, monsterTable.Type, int(1*times)) // } // // var dropResult = this.tables.DropExtend.Drop(sceneTable.RewardId, int(times)) // 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 // } // } // // var rewardList []*proto.ItemPair // for itemId, itemNum := range rewardMap { // 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)) // itemNum *= uint32(outputMultiple) // } // // _ = player.AddItem(itemId, itemNum, logic.LogTypeItemObtainByCopy) // rewardList = append(rewardList, &proto.ItemPair{ItemId: itemId, ItemNum: itemNum}) // } // // _ = player.Send(proto.ModIdLevel, proto.MsgIdMaterialCopySweep, &proto.MsgMaterialCopySweepAck{ // MsgRewardListAck: &proto.MsgRewardListAck{RewardList: rewardList}, // }) // return nil //} // //func (this *PlayerHandler) PlanetMine(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgPlanetMineReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.PlanetId == 0 { // this.logger.Error("Parameter error, req.PlanetId == 0") // _ = player.TipNotice(proto.TipParameterError) // return // } // // var planetTable = this.tables.Planet.Get(int(req.PlanetId)) // if planetTable == nil { // this.logger.Error("Parameter or data error, Table 'Planet' was not found, req.PlanetId: ", req.PlanetId) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var chapterTables = this.tables.CopyChapterExtend.List(planetTable.Id) // for _, chapterTable := range chapterTables { // if player.GetCopyPassedNum(uint32(chapterTable.SceneId)) == 0 { // this.logger.Error("Planet incomplete, sceneId: ", chapterTable.SceneId) // _ = player.TipNotice(proto.TipPlanetIncomplete) // return // } // } // // err = player.CheckItem(uint32(planetTable.SweepCostId), uint32(planetTable.SweepCostNum)) // if err != nil { // this.logger.Errorf("Check item consume failed, itemId: %d, itemNum: %d, error: %v", planetTable.SweepCostId, planetTable.SweepCostNum, err) // _ = player.TipNotice(err) // return // } // // player.ReduceItem(uint32(planetTable.SweepCostId), uint32(planetTable.SweepCostNum), logic.LogTypeItemConsumeByPlanetMime) // // var rewardList []*proto.ItemPair // var dropResult = this.tables.DropExtend.Drop(planetTable.DropId, 1) // for _, itemPair := range dropResult { // _ = player.AddItem(itemPair[0], itemPair[1], logic.LogTypeItemObtainByPlanetMime) // rewardList = append(rewardList, &proto.ItemPair{ItemId: itemPair[0], ItemNum: itemPair[1]}) // } // // _ = player.Send(proto.ModIdLevel, proto.MsgIdPlanetMine, &proto.MsgPlanetMineAck{MsgRewardListAck: &proto.MsgRewardListAck{RewardList: rewardList}, PlanetId: req.PlanetId}) // // player.CheckTask(proto.TaskSection1PlanetMineTimes, 0, 1) //} // //func (this *PlayerHandler) PlanetCivilizationChoose(player *logic.Player, msg *net.Message) { // if !player.CheckRequestTime(logic.RequestTimeTypeChooseCivilization) { // this.logger.Error("Repeated choose civilization request") // _ = player.TipNotice(proto.TipRepeatedRequest) // return // } // // var req = new(proto.MsgPlanetCivilizationChooseReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.PlanetId == 0 { // this.logger.Error("Parameter error, req.PlanetId == 0") // _ = player.TipNotice(proto.TipParameterError) // return // } // // var planetTable = this.tables.Planet.Get(int(req.PlanetId)) // if planetTable == nil { // this.logger.Error("Parameter or data error, Table 'Planet' was not found, req.PlanetId: ", req.PlanetId) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var chapterTables = this.tables.CopyChapterExtend.List(planetTable.Id) // for _, chapterTable := range chapterTables { // if player.GetCopyPassedNum(uint32(chapterTable.SceneId)) == 0 { // this.logger.Error("Planet incomplete, sceneId: ", chapterTable.SceneId) // _ = player.TipNotice(proto.TipPlanetIncomplete) // return // } // } // // for i := range planetTable.CivilizationCostId { // err = player.CheckItem(uint32(planetTable.CivilizationCostId[i]), uint32(planetTable.CivilizationCostNum[i])) // if err != nil { // this.logger.Errorf("Check item consume failed, itemId: %d, itemNum: %d, error: %v", planetTable.CivilizationCostId[i], planetTable.CivilizationCostNum[i], err) // _ = player.TipNotice(err) // return // } // } // // var builtIds = map[uint32]bool{} // var planet = player.Planet[req.PlanetId] // if planet != nil { // for _, civilization := range planet.Civilizations { // builtIds[civilization.CivilizationId] = true // } // } // // var weights []uint32 // var civilizationIds []uint32 // for i := range planetTable.CivilizationWeights { // if builtIds[uint32(planetTable.CivilizationWeights[i][0])] { // continue // } // // civilizationIds = append(civilizationIds, uint32(planetTable.CivilizationWeights[i][0])) // weights = append(weights, uint32(planetTable.CivilizationWeights[i][1])) // } // // for i := range planetTable.CivilizationCostId { // player.ReduceItem(uint32(planetTable.CivilizationCostId[i]), uint32(planetTable.CivilizationCostNum[i]), logic.LogTypeItemConsumeByCivilizationBuild) // } // // var chosenId = util.RandomWeights(civilizationIds, func(i int) uint32 { // return weights[i] // }) // // player.Temp.ChosenPlanetId = req.PlanetId // player.Temp.ChosenCivilizationId = chosenId // // _ = player.Send(proto.ModIdLevel, proto.MsgIdPlanetCivilizationChoose, &proto.MsgPlanetCivilizationChooseAck{PlanetId: req.PlanetId, CivilizationId: chosenId}) //} // //func (this *PlayerHandler) PlanetCivilizationBuild(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgPlanetCivilizationBuildReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.PlanetId != player.Temp.ChosenPlanetId || req.CivilizationId != player.Temp.ChosenCivilizationId { // this.logger.Error("Parameter error, req.PlanetId: %d, chosenPlanetId: %d, req.CivilizationId: %d, chosenCivilizationId: %d", req.PlanetId, player.Temp.ChosenPlanetId, req.CivilizationId, player.Temp.ChosenCivilizationId) // _ = player.TipNotice(proto.TipParameterError) // return // } // // var planetTable = this.tables.Planet.Get(int(req.PlanetId)) // if planetTable == nil { // this.logger.Error("Parameter or data error, Table 'Planet' was not found, req.PlanetId: ", req.PlanetId) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var planetCivilizationTable = this.tables.PlanetCivilizationExtend.Get(int(req.CivilizationId), 1) // if planetCivilizationTable == nil { // this.logger.Error("Parameter or data error, Table 'PlanetCivilization' was not found, req.CivilizationId: ", req.CivilizationId) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var index = -1 // var planet = player.Planet[req.PlanetId] // if planet == nil { // index = 0 // planet = &logic.PlayerPlanet{Id: uint32(planetTable.Id), Civilizations: []*logic.PlayerPlanetCivilization{nil}} // } else { // if len(planet.Civilizations) < proto.CivilizationNum { // index = len(planet.Civilizations) // planet.Civilizations = append(planet.Civilizations, nil) // } else { // index, _ = planet.FindCivilization(req.ReplacedId) // if index < 0 { // this.logger.Error("Parameter error, 'ReplacedId' was not found, req.ReplacedId: ", req.ReplacedId) // _ = player.TipNotice(proto.TipParameterError) // return // } // } // } // // player.Temp.ChosenCivilizationId = 0 // // planet.Civilizations[index] = &logic.PlayerPlanetCivilization{CivilizationId: uint32(planetCivilizationTable.CivilizationId), Id: uint32(planetCivilizationTable.Id)} // // player.Planet[planet.Id] = planet // player.SaveModel(planet) // // player.UpdateRigAttrs() // // _ = player.Send(proto.ModIdLevel, proto.MsgIdPlanetChange, &proto.MsgPlanetChangeAck{Planet: planet.BuildMsgPlanet()}) // // player.ResetRequestTime(logic.RequestTimeTypeChooseCivilization) // // player.CheckTask(proto.TaskSection1BuildCivilizations, 0, 1) //} // //func (this *PlayerHandler) PlanetCivilizationUpgrade(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgPlanetCivilizationUpgradeReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.PlanetId == 0 || req.CivilizationId == 0 { // this.logger.Error("Parameter error, req.PlanetId == 0 || req.CivilizationId == 0") // _ = player.TipNotice(proto.TipParameterError) // return // } // // var planet = player.Planet[req.PlanetId] // if planet == nil { // this.logger.Error("Parameter or data error, Table 'Planet' was not found, req.PlanetId: ", req.PlanetId) // _ = player.TipNotice(proto.TipPlanetNotExists) // return // } // // var _, civilization = planet.FindCivilization(req.CivilizationId) // if civilization == nil { // this.logger.Error("Parameter or data error, Civilization not built, req.CivilizationId: ", req.CivilizationId) // _ = player.TipNotice(proto.TipCivilizationNotBuilt) // return // } // // var planetCivilizationTables = this.tables.PlanetCivilizationExtend.List(int(req.CivilizationId)) // if len(planetCivilizationTables) == 0 { // this.logger.Error("Parameter or data error, 'PlanetCivilizations' length 0, req.CivilizationId: ", req.CivilizationId) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var curIndex = -1 // for i, planetCivilizationTable := range planetCivilizationTables { // if uint32(planetCivilizationTable.Id) == civilization.Id { // curIndex = i // break // } // } // // if curIndex == -1 { // this.logger.Error("Data error, Civilization level was not found, civilization.Id: ", civilization.Id) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // if curIndex+1 >= len(planetCivilizationTables) { // this.logger.Error("Civilization level already max, civilization.Id: ", civilization.Id) // _ = player.TipNotice(proto.TipLevelAlreadyMax) // return // } // // for i := range planetCivilizationTables[curIndex].CostItemId { // err = player.CheckItem(uint32(planetCivilizationTables[curIndex].CostItemId[i]), uint32(planetCivilizationTables[curIndex].CostItemNum[i])) // if err != nil { // this.logger.Errorf("Check item consume failed, itemId: %d, itemNum: %d, error: %v", planetCivilizationTables[curIndex].CostItemId[i], planetCivilizationTables[curIndex].CostItemNum[i], err) // _ = player.TipNotice(err) // return // } // } // // for i := range planetCivilizationTables[curIndex].CostItemId { // player.ReduceItem(uint32(planetCivilizationTables[curIndex].CostItemId[i]), uint32(planetCivilizationTables[curIndex].CostItemNum[i]), logic.LogTypeItemConsumeByCivilizationUpgrade) // } // // civilization.Id = uint32(planetCivilizationTables[curIndex+1].Id) // player.SaveModel(planet) // // player.UpdateRigAttrs() // // _ = player.Send(proto.ModIdLevel, proto.MsgIdPlanetChange, &proto.MsgPlanetChangeAck{Planet: planet.BuildMsgPlanet()}) //} // //func (this *PlayerHandler) PlanetCivilizationDestroy(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgPlanetCivilizationDestroyReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.PlanetId == 0 || req.CivilizationId == 0 { // this.logger.Error("Parameter error, req.PlanetId == 0 || req.CivilizationId == 0") // _ = player.TipNotice(proto.TipParameterError) // return // } // // var planet = player.Planet[req.PlanetId] // if planet == nil { // this.logger.Error("Parameter error, Player 'Planet' was not found, req.PlanetId: ", req.PlanetId) // _ = player.TipNotice(proto.TipPlanetNotExists) // return // } // // var index, _ = planet.FindCivilization(req.CivilizationId) // if index == -1 { // this.logger.Error("Parameter or data error, Civilization not built, req.CivilizationId: ", req.CivilizationId) // _ = player.TipNotice(proto.TipCivilizationNotBuilt) // return // } // // planet.Civilizations = append(planet.Civilizations[:index], planet.Civilizations[index+1:]...) // player.SaveModel(planet) // // player.UpdateRigAttrs() // // _ = player.Send(proto.ModIdLevel, proto.MsgIdPlanetChange, &proto.MsgPlanetChangeAck{Planet: planet.BuildMsgPlanet()}) //} // //func (this *PlayerHandler) PlanetRawStoneMine(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgPlanetRawStoneMineReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.Id == 0 || req.Times == 0 { // this.logger.Error("Parameter error, req.Id == 0 || req.Times == 0") // _ = player.TipNotice(proto.TipParameterError) // return // } // // var rawStoneTable = this.tables.PlanetRawStone.Get(int(req.Id)) // if rawStoneTable == nil { // this.logger.Error("Parameter or data error, Table 'PlanetRawStone' was not found, req.Id: ", req.Id) // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var now = util.Unix() // var rawStone = player.RawStone[req.Id] // if rawStone == nil { // rawStone = &logic.PlayerRawStone{Id: uint32(rawStoneTable.Id)} // player.RawStone[rawStone.Id] = rawStone // } // // if rawStoneTable.FreeInterval > 0 && (rawStone.FreeTime == 0 || now >= rawStone.FreeTime) { //免费时只能抽一次 // if req.Times != 1 { // _ = player.TipNotice(proto.TipParameterError) // return // } // // rawStone.FreeTime = now + int64(rawStoneTable.FreeInterval) // } else { // if req.Times < uint32(rawStoneTable.MinTimes) || req.Times > uint32(rawStoneTable.MaxTimes) { // _ = player.TipNotice(proto.TipParameterError) // return // } // // err = player.CheckItem(uint32(rawStoneTable.CostItemId), uint32(rawStoneTable.CostItemNum)*req.Times) // if err != nil { // _ = player.TipNotice(err) // return // } // // player.ReduceItem(uint32(rawStoneTable.CostItemId), uint32(rawStoneTable.CostItemNum)*req.Times, logic.LogTypeItemConsumeByRawStoneMime) // } // // var dropResult [][2]uint32 // if req.Times == uint32(rawStoneTable.MaxTimes) { // if player.GetCounterTotal(proto.CounterTypeRawStoneTenfold, rawStone.Id) > 0 { //第一次走首次十连,之后走普通十连,一次掉落出十个东西 // dropResult = this.tables.DropExtend.Drop(rawStoneTable.TenfoldDropId, 1) // } else { // dropResult = this.tables.DropExtend.Drop(rawStoneTable.FirstTenfoldDropId, 1) // } // player.AddCounter(proto.CounterTypeRawStoneTenfold, rawStone.Id, 1) //计一次十连抽,而不是十次 // } else { // dropResult = this.tables.DropExtend.Drop(rawStoneTable.GeneralDropId, int(req.Times)) //多次单抽掉落多次,每次一个东西 // } // // rawStone.MineCount += req.Times // player.SaveModel(rawStone) // // var rewardList []*proto.ItemPair // for _, itemPair := range dropResult { // _ = player.AddItem(itemPair[0], itemPair[1], logic.LogTypeItemObtainByRawStoneMime) // rewardList = append(rewardList, &proto.ItemPair{ItemId: itemPair[0], ItemNum: itemPair[1]}) // } // // _ = player.Send(proto.ModIdLevel, proto.MsgIdPlanetRawStoneMine, &proto.MsgPlanetRawStoneMineAck{MsgRewardListAck: &proto.MsgRewardListAck{RewardList: rewardList}}) // // _ = player.Send(proto.ModIdLevel, proto.MsgIdPlanetRawStoneStatus, &proto.MsgPlanetRawStoneStatusListAck{ // List: []*proto.PlanetRawStoneStatus{rawStone.BuildMsgPlanetRawStoneStatus()}, // }) //} // //func (this *PlayerHandler) PlanetRawStoneAccrueReward(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgPlanetRawStoneAccrueRewardReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.Id == 0 { // _ = player.TipNotice(proto.TipParameterError) // return // } // // var planetRawStoneTable = this.tables.PlanetRawStone.Get(int(req.Id)) // if planetRawStoneTable == nil { // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var rawStone = player.RawStone[req.Id] // if rawStone == nil || rawStone.MineCount < uint32(planetRawStoneTable.RewardTimes) { // _ = player.TipNotice(proto.TipRewardUnable) // return // } // // var multiple = rawStone.MineCount / uint32(planetRawStoneTable.RewardTimes) // // rawStone.MineCount = rawStone.MineCount % uint32(planetRawStoneTable.RewardTimes) // player.SaveModel(rawStone) // // _ = player.AddItem(uint32(planetRawStoneTable.RewardItemId), uint32(planetRawStoneTable.RewardItemNum)*multiple, logic.LogTypeItemObtainByRawStoneAccrue) // // _ = player.Send(proto.ModIdLevel, proto.MsgIdPlanetRawStoneAccrueReward, &proto.MsgPlanetRawStoneAccrueRewardAck{MsgRewardListAck: &proto.MsgRewardListAck{ // RewardList: []*proto.ItemPair{ // {ItemId: uint32(planetRawStoneTable.RewardItemId), ItemNum: uint32(planetRawStoneTable.RewardItemNum) * multiple}, // }, // }}) // // _ = player.Send(proto.ModIdLevel, proto.MsgIdPlanetRawStoneStatus, &proto.MsgPlanetRawStoneStatusListAck{ // List: []*proto.PlanetRawStoneStatus{rawStone.BuildMsgPlanetRawStoneStatus()}, // }) //} // //func (this *PlayerHandler) CopyArenaMatches(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgCopyArenaMatchesReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // var copyArenaTable = this.tables.CopyArena.Get(1) // if copyArenaTable == nil { // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // var season = this.arenaManager.CopyArenaSeason() // if season == nil { // _ = player.TipNotice(proto.TipCopyNotInTime) // return // } // // if player.Arena == nil { // player.EnterArena(season, copyArenaTable) // if player.Arena == nil { // _ = player.TipNotice(proto.TipArenaNotEntered) // return // } // } else if req.Refresh { // var counter = player.GetCounterDaily(proto.CounterTypeCopyArenaRefresh, uint32(copyArenaTable.Id)) // if counter >= uint32(copyArenaTable.MaxReloadNum) { // this.logger.Error("Daily arena refresh times over, count: ", counter) // _ = player.TipNotice(proto.TipTodayTimesOver) // return // } // // player.Arena.Matches = season.Matches(player, uint32(copyArenaTable.Id), 4, player.Arena.Matches) // player.SaveField("arena.matches", player.Arena.Matches) // // player.AddCounter(proto.CounterTypeCopyArenaRefresh, uint32(copyArenaTable.Id), 1) // } // // var matches []*proto.ArenaPlayer // for _, playerId := range player.Arena.Matches { // var arenaPlayer = season.GetPlayer(playerId) // if arenaPlayer != nil { // var match = &proto.ArenaPlayer{ // PlayerId: arenaPlayer.PlayerId, // IsRobot: arenaPlayer.PlayerId < 1000000000, // Name: arenaPlayer.Name, // Avatar: arenaPlayer.Avatar, // Capacity: arenaPlayer.Capacity, // RigHead: arenaPlayer.RigHead, // RigHeadStar: arenaPlayer.RigHeadStar, // RigBody: arenaPlayer.RigBody, // RigBodyStar: arenaPlayer.RigBodyStar, // RigTail: arenaPlayer.RigTail, // RigTailStar: arenaPlayer.RigTailStar, // RigEquips: arenaPlayer.RigEquips[:], // RigPendants: arenaPlayer.RigPendants[:], // RigAttrs: arenaPlayer.RigAttrs[:], // } // // var score = arenaPlayer.Scores[uint32(copyArenaTable.Id)] // if score != nil { // match.MaxScore = score.MaxScore // match.RankIndex = score.RankIndex // } // // matches = append(matches, match) // } // } // // _ = player.Send(proto.ModIdLevel, proto.MsgIdCopyArenaMatches, &proto.MsgCopyArenaMatchesAck{Matches: matches}) //} // //func (this *PlayerHandler) CopyArenaSelectMatch(player *logic.Player, msg *net.Message) { // var req = new(proto.MsgCopyArenaSelectMatchReq) // var err = msg.Read(req) // if err != nil { // this.logger.Error("Read message failed, ", err) // _ = player.TipNotice(proto.TipMessageError) // return // } // // if req.PlayerId == 0 { // _ = player.TipNotice(proto.TipParameterError) // return // } // // if player.Arena == nil { // _ = player.TipNotice(proto.TipArenaNotEntered) // return // } // // if !player.Arena.Matched(req.PlayerId) { // _ = player.TipNotice(proto.TipArenaNotMatched) // return // } // // var season = this.arenaManager.CopyArenaSeason() // if season == nil { // _ = player.TipNotice(proto.TipCopyNotInTime) // return // } // // var arenaPlayer = season.GetPlayer(req.PlayerId) // if arenaPlayer == nil { // _ = player.TipNotice(proto.TipArenaMatchNotFound) // return // } // // player.Temp.ArenaEnemy = arenaPlayer // // _ = player.Send(proto.ModIdLevel, proto.MsgIdCopyArenaSelectMatch, nil) // // this.enterCopyArena(player, 1) //} // //func (this *PlayerHandler) CopyArenaRankList(player *logic.Player, msg *net.Message) { // var copyArenaTable = this.tables.CopyArena.Get(1) // if copyArenaTable == nil { // _ = player.TipNotice(proto.TipDataTablesError) // return // } // // _ = player.Send(proto.ModIdLevel, proto.MsgIdCopyArenaRankList, player.BuildMsgCopyArenaRankListAck(uint32(copyArenaTable.Id))) // return //} // //func (this *PlayerHandler) CopyArenaBattleRecordList(player *logic.Player, msg *net.Message) { // var list []*proto.CopyArenaBattleRecord // if player.Arena != nil { // for _, record := range player.Arena.Records { // list = append(list, record.BuildMsgCopyArenaBattleRecord()) // } // } // _ = player.Send(proto.ModIdLevel, proto.MsgIdCopyArenaBattleRecordList, &proto.MsgCopyArenaBattleRecordListAck{List: list}) // return //} // //func (this *PlayerHandler) CopyMainlineRankList(player *logic.Player, msg *net.Message) { // _ = player.Send(proto.ModIdLevel, proto.MsgIdCopyMainlineRankList, player.BuildMsgCopyMainlineRankListAck()) // return //}