ecs/servers/game/logic/player_check_correct.go
2025-06-20 15:33:09 +08:00

380 lines
10 KiB
Go

package logic
import (
"ecs/proto/pb"
"github.com/oylshe1314/framework/util"
"sort"
)
func (this *Player) checkCorrect(firstLogin bool, cur *GameTime) {
if firstLogin {
this.checkCorrectFirstLogin(cur)
}
this.checkCorrectModules(cur)
this.checkCorrectMemoryData(cur)
//this.checkWechatUserInfo(cur)
this.checkCorrectPower(cur)
//this.checkCorrectBattlePass(cur)
//this.checkEnterArena(cur)
//this.checkStorePoolChange(cur)
}
func (this *Player) checkCorrectModules(cur *GameTime) {
if this.Artifact == nil {
this.Artifact = make(map[uint64]*PlayerArtifact)
this.SaveField("achievement", this.Artifact)
}
//if this.Achievement == nil {
// this.Achievement = make(map[uint64]*PlayerAchievement)
// this.SaveField("achievement", this.Achievement)
//}
//if this.BattlePass == nil {
// this.BattlePass = make(map[uint32]*PlayerBattlePass)
// this.SaveField("battle_pass", this.BattlePass)
//}
//if this.Cdkey == nil {
// this.Cdkey = make(map[string]*PlayerCdkey)
// this.SaveField("cdkey", this.Cdkey)
//}
//if this.CopyPassed == nil {
// this.CopyPassed = make(map[uint32]*PlayerCopyPassed)
// this.SaveField("copy_passed", this.CopyPassed)
//}
//if this.CopySpeed == nil {
// this.CopySpeed = make(map[uint32]*PlayerCopySpeed)
// this.SaveField("copy_speed", this.CopySpeed)
//}
if this.CopyStatus == nil {
this.CopyStatus = make(map[uint64]*PlayerCopyStatus)
this.SaveField("copy_status", this.CopyStatus)
}
if this.Counter == nil {
this.Counter = make(map[uint32]map[uint64]*PlayerCounter)
this.SaveField("counter", this.Counter)
}
if this.Hero == nil {
this.Hero = make(map[uint64]*PlayerHero)
this.SaveField("hero", this.Hero)
}
if this.Hero == nil {
this.HeroBook = make(map[uint32]*PlayerHeroBook)
this.SaveField("hero", this.Hero)
}
if this.Item == nil {
this.Item = make(map[uint32]*PlayerItem)
this.SaveField("item", this.Item)
}
if this.Equip == nil {
this.Equip = make(map[uint64]*PlayerEquip)
this.SaveField("item", this.Equip)
}
//if this.GiftPack == nil {
// this.GiftPack = make(map[uint32]*PlayerGiftPack)
// this.SaveField("gift_pack", this.GiftPack)
//}
if this.Lineup == nil {
this.Lineup = make(map[uint64]*PlayerLineup)
this.SaveField("money", this.Lineup)
}
if this.Mail == nil {
this.Mail = make(map[uint64]*PlayerMail)
this.SaveField("mail", this.Mail)
}
if this.Money == nil {
this.Money = make(map[uint32]*PlayerMoney)
this.SaveField("money", this.Money)
}
//if this.MonthlyCard == nil {
// this.MonthlyCard = make(map[uint32]*PlayerMonthlyCard)
// this.SaveField("monthly_card", this.MonthlyCard)
//}
//if this.Planet == nil {
// this.Planet = make(map[uint32]*PlayerPlanet)
// this.SaveField("planet", this.Planet)
//}
//if this.RawStone == nil {
// this.RawStone = make(map[uint32]*PlayerRawStone)
// this.SaveField("raw_stone", this.RawStone)
//}
//if this.RigCharacter == nil {
// this.RigCharacter = make(map[uint32]*PlayerRigCharacter)
// this.SaveField("rig_character", this.RigCharacter)
//}
//if this.RigComponent == nil {
// this.RigComponent = make(map[uint32]*PlayerRigComponent)
// this.SaveField("rig_component", this.RigComponent)
//}
//if this.RigCore == nil {
// this.RigCore = make(map[uint32]*PlayerRigCore)
// this.SaveField("rig_core", this.RigCore)
//}
//if this.RigEquip == nil {
// this.RigEquip = make(map[uint32]*PlayerRigEquip)
// this.SaveField("rig_equip", this.RigEquip)
//}
//if this.RigPendant == nil {
// this.RigPendant = make(map[uint32]*PlayerRigPendant)
// this.SaveField("rig_pendant", this.RigPendant)
//}
//if this.RigRemains == nil {
// this.RigRemains = make(map[uint32]*PlayerRigRemains)
// this.SaveField("rig_remains", this.RigRemains)
//}
//if this.RigSmelter == nil {
// this.RigSmelter = make(map[uint32]*PlayerRigSmelter)
// this.SaveField("rig_smelter", this.RigSmelter)
//}
//if this.RigTrammels == nil {
// this.RigTrammels = make(map[uint32]*PlayerRigTrammels)
// this.SaveField("rig_trammels", this.RigTrammels)
//}
//if this.RigWarship == nil {
// this.RigWarship = make(map[uint32]*PlayerRigWarship)
// this.SaveField("rig_warship", this.RigWarship)
//}
//if this.RoleTalent == nil {
// this.RoleTalent = make(map[uint32]*PlayerRoleTalent)
// this.SaveField("role_talent", this.RoleTalent)
//}
//if this.StorePool == nil {
// this.StorePool = make(map[uint32]*PlayerStorePool)
// this.SaveField("store_pool", this.StorePool)
//}
//if this.Task == nil {
// this.Task = make(map[uint32]*PlayerTask)
// this.SaveField("task", this.Task)
//}
//if this.TaskActive == nil {
// this.TaskActive = make(map[uint32]*PlayerTaskActive)
// this.SaveField("task_active", this.TaskActive)
//}
if this.Treasure == nil {
this.Treasure = make(map[uint64]*PlayerTreasure)
this.SaveField("achievement", this.Treasure)
}
}
func (this *Player) initRole(cur *GameTime) {
var roleHeroId = this.manager.tables.ServerConfig.GetInitRole(int(this.RoleGender))
if roleHeroId == 0 {
this.manager.logger.Error("get main hero id failed, roleHeroId: 0, roleGender: ", this.RoleGender)
return
}
this.AddHero(uint32(roleHeroId))
}
func (this *Player) initHeroes(cur *GameTime) {
var initHeroIds = this.manager.tables.ServerConfig.GetInitHeroes()
for _, initHeroId := range initHeroIds {
this.AddHero(uint32(initHeroId))
}
}
func (this *Player) initItems(cur *GameTime) {
var itemIds, itemNums = this.manager.tables.ServerConfig.GetInitItems()
for i := range itemIds {
this.AddItem(uint32(itemIds[i]), uint32(itemNums[i]), 0)
}
}
func (this *Player) initLineup(cur *GameTime) {
var roleHeroId = this.manager.tables.ServerConfig.GetInitRole(int(this.RoleGender))
var lineup = &PlayerLineup{
Uid: util.RandomUid(),
Name: "阵容1",
Active: true,
}
var heroes = make([]*PlayerHero, 0, len(this.Hero))
for _, hero := range this.Hero {
heroes = append(heroes, hero)
}
sort.Slice(heroes, func(i, j int) bool {
if heroes[i].Id == uint32(roleHeroId) {
return true
}
if heroes[j].Id == uint32(roleHeroId) {
return true
}
return heroes[i].Uid < heroes[j].Uid
})
for i, hero := range heroes {
if i > 5 {
break
}
var lineupHero = &PlayerLineupHero{
HeroUid: hero.Uid,
Position: uint32(i + 1),
}
lineup.Heroes[i] = lineupHero
hero.InLineup = 2
this.SaveModel(hero)
}
this.Lineup[lineup.Uid] = lineup
this.SaveModel(lineup)
}
func (this *Player) initMails(cur *GameTime) {
var mails = this.manager.tables.ServerConfig.GetInitMails()
for i := range mails {
var titleId, contentId, itemIds, itemNums = this.manager.tables.ServerConfig.GetInitMail(i)
var items = make([][2]uint32, len(itemIds))
for ii := range itemIds {
items[ii][0] = uint32(itemIds[ii])
items[ii][1] = uint32(itemNums[ii])
}
this.AddMail(util.RandomUid(),
pb.MailType_MailNormal,
util.IntegerToString(titleId),
util.IntegerToString(contentId),
util.Unix(),
0,
nil,
items,
)
}
}
// func (this *Player) initTasks(cur *GameTime) {
// var cfgTable = this.manager.tables.ServerCfg.Get("init_tasks")
// if cfgTable == nil {
// return
// }
//
// var taskIds []uint32
// err := util.SplitToIntegers2(cfgTable.Value1, ",", &taskIds)
// if err != nil {
// return
// }
//
// for _, taskId := range taskIds {
// var taskTable = this.manager.tables.Task.Get(int(taskId))
// if taskTable != nil {
// this.addTask(taskTable)
// }
// }
// }
func (this *Player) initPower(cur *GameTime) {
var money = &PlayerMoney{Type: uint32(pb.MoneyType_Power), Value: RolePowerMax}
this.Money[money.Type] = money
this.SaveModel(money)
}
func (this *Player) checkCorrectFirstLogin(cur *GameTime) {
this.initRole(cur)
this.initHeroes(cur)
this.initItems(cur)
this.initLineup(cur)
this.initMails(cur)
//this.initTasks(cur)
this.initPower(cur)
}
func (this *Player) checkCorrectMemoryData(cur *GameTime) {
this.initTemp()
var lineup = util.MapFindValue(this.Lineup, func(lineup *PlayerLineup) bool {
return lineup.Active
})
heroLoop:
for _, hero := range this.Hero {
if hero.InLineup == 2 && lineup != nil {
for _, lineupHero := range lineup.Heroes {
if hero.Uid == lineupHero.HeroUid {
this.updateHeroAttrs(hero, lineup, lineupHero)
this.UpdateBattleHeroCapacity(lineupHero)
continue heroLoop
}
}
}
this.updateHeroAttrs(hero, nil, nil)
}
}
func (this *Player) checkCorrectPower(cur *GameTime) {
var money = this.GetMoney(pb.MoneyType_Power)
if money.Value >= uint32(RolePowerMax) || this.PowerNextTime > cur.Timestamp {
return
}
for {
money.Value += uint32(RolePowerRegain)
this.PowerNextTime += int64(RolePowerCycle)
if money.Value >= uint32(RolePowerMax) {
this.PowerNextTime = 0
break
}
if this.PowerNextTime > cur.Timestamp {
break
}
}
this.SaveModel(money)
this.SaveField("power_next_time", this.PowerNextTime)
}
//func (this *Player) checkCorrectBattlePass(cur *GameTime) {
// var seasonTable = this.manager.tables.BattlePassSeasonExtend.Get(cur.Timestamp)
// if seasonTable == nil {
// this.Role.BattlePassSeason = 0
// return
// }
//
// if this.Role.BattlePassSeason != uint32(seasonTable.Id) || this.BattlePass[this.Role.BattlePassSeason] == nil {
// this.Role.BattlePassSeason = uint32(seasonTable.Id)
// this.SaveField("role.battle_pass_season", this.Role.BattlePassSeason)
//
// var battlePass = &PlayerBattlePass{
// Season: this.Role.BattlePassSeason,
// Advanced: false,
// }
// this.BattlePass[this.Role.BattlePassSeason] = battlePass
// this.SaveModel(battlePass)
//
// var levels = seasonTable.MaxLevel
// var rewardTables = this.manager.tables.BattlePassRewardExtend.List(int(battlePass.Season))
// if levels > len(rewardTables) {
// levels = len(rewardTables)
// }
//
// this.BattlePassReward = make([]*PlayerBattlePassRewrad, levels)
// for i, rewardTable := range rewardTables {
// this.BattlePassReward[i] = &PlayerBattlePassRewrad{Id: uint32(rewardTable.Id), Ordinary: uint32(proto.RewardStatusUnable), Advanced: uint32(proto.RewardStatusUnable)}
// }
// this.SaveField("battle_pass_reward", this.BattlePassReward)
//
// this.checkTaskReset(proto.TaskTypeBattlePass)
// }
//}
//
//func (this *Player) checkEnterArena(cur *GameTime) {
// var copyArenaTable = this.manager.tables.CopyArena.Get(1)
// if copyArenaTable == nil {
// return
// }
//
// var season = this.manager.arenaManager.CopyArenaSeason()
// if season == nil {
// return
// }
//
// this.EnterArena(season, copyArenaTable)
//}
//
//func (this *Player) checkStorePoolChange(cur *GameTime) {
// this.copyStorePoolUnlock(this.Role.CopyMainSceneId, cur.Timestamp)
//}