package mapLeague import ( "f1-game/internal/code" "f1-game/internal/data" "f1-game/internal/enum" "f1-game/internal/event" nameLocal "f1-game/internal/name/local" nameRoute "f1-game/internal/name/route" "f1-game/internal/pb" "f1-game/internal/sessions" "f1-game/nodes/map/internal/db" dbLeague "f1-game/nodes/map/internal/db/data/league" leagueAttr "f1-game/nodes/map/league/attr" leagueBase "f1-game/nodes/map/league/base" leagueStorage "f1-game/nodes/map/league/storage" cstring "github.com/cherry-game/cherry/extend/string" clog "github.com/cherry-game/cherry/logger" cproto "github.com/cherry-game/cherry/net/proto" ) func (p *actorLeague) initTech() { p.Local().Register(nameLocal.MapLeague_TechList, p.techList) p.Local().Register(nameLocal.MapLeague_TechUpgrade, p.techUpgrade) } // 科技列表 func (p *actorLeague) techList(session *cproto.Session, _ *pb.None) { p.Response(session, p.leagueTable.Techs.ToProto()) } // 科技升级 func (p *actorLeague) techUpgrade(session *cproto.Session, req *pb.I32) { techID := req.GetValue() if techID < 1 { p.ResponseCode(session, code.IllegalArgument) return } // 检查当前操作者是否有权限 leagueMemberTable, found := db.GetMapLeagueMemberTable(p.leagueID) if !found { p.ResponseCode(session, code.LeagueMembersEmpty) return } opPlayerID := sessions.GetPlayerID(session) // 权限检查 需要同盟建设权限 ok := leagueMemberTable.CheckPermission(opPlayerID, enum.League_Permission_Construction) if !ok { p.ResponseCode(session, code.LeaguePermissionDenied) return } // 检查科技是否解锁 if !p.leagueTable.Techs.CheckUnlock(techID) { p.ResponseCode(session, code.MapLeague_TechNotUnlock) return } tech, found := p.leagueTable.Techs.Techs.Get(techID) if !found { tech = dbLeague.NewTech(techID) } // 检查前置条件 if !p.leagueTable.Techs.CheckPreTech(techID, tech.Level) { p.ResponseCode(session, code.MapLeague_TechUpPreConditionNotMet) return } // 检查科技等级上限 if !data.LeagueTechLevel.ContainTechIDLevel(techID, tech.Level+1) { p.ResponseCode(session, code.MapLeague_TechUpLevelLimit) return } techRow, ok := data.LeagueTechLevel.GetByTechIDLevel(techID, tech.Level) if !ok { p.ResponseCode(session, code.MapLeague_TechUpLevelLimit) return } // 扣除联盟资源 p.subAssets(techRow.UpgradeCost) tech.Level++ p.leagueTable.Techs.Techs.Put(techID, tech) // 更新属性 leagueAttr.Service().UpdateAttrs(p.leagueTable) p.leagueTable.Save2Queue() // 检查更新仓库容量 leagueStorage.Service().CheckAndInitCapacity(p.leagueTable) p.Response(session, tech.ToProto()) // 记录日志 leagueLogTable, _ := db.GetMapLeagueLogTable(p.leagueID) // TODO 只消耗一种资源,如果策划改了就需要增加日志ID,不能修改原有的ID costAsset := techRow.UpgradeCost[0] leagueLogTable.AddLeagueLog(enum.Log_LeagueTechUpgradeCost, leagueBase.Service().GetPlayerName(opPlayerID), cstring.ToString(costAsset.ID), cstring.ToString(costAsset.Num), cstring.ToString(tech.TechID)) p.PostEvent(event.NewLeagueTechUpgrade(p.leagueID, tech.TechID, tech.Level)) // 通知前端更新属性 p.Push(session, nameRoute.PushLeague_AttrChange, p.leagueTable.LeagueInfo.Attrs.ToProto()) clog.Debugf("techUp success: %+v", tech) }