| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- package mapPlayer
- import (
- "f1-game/internal/code"
- "f1-game/internal/data"
- "f1-game/internal/enum"
- "f1-game/internal/event"
- nameEvent "f1-game/internal/name/event"
- nameLocal "f1-game/internal/name/local"
- "f1-game/internal/pb"
- ao "f1-game/nodes/game/player/asset/origin"
- "f1-game/nodes/map/internal/db"
- mapFacade "f1-game/nodes/map/internal/facade"
- show "f1-game/nodes/map/player/show"
- ctime "github.com/cherry-game/cherry/extend/time"
- cfacade "github.com/cherry-game/cherry/facade"
- cproto "github.com/cherry-game/cherry/net/proto"
- )
- func (p *actorPlayer) initShow() {
- p.Local().Register(nameLocal.MapPlayer_ActiveShow, p.activeShow)
- p.Local().Register(nameLocal.MapPlayer_ShowView, p.showView)
- p.Local().Register(nameLocal.MapPlayer_MainCityChange, p.mainCityChange)
- // 城建升级触发(主要是主堡升级)
- p.EventRegister(nameEvent.Lord_FacilityUp, p.onFacilityUpRefreshShow)
- }
- // 主城外观激活
- func (p *actorPlayer) activeShow(session *cproto.Session, req *pb.I32) {
- var (
- playerTable = db.GetMapPlayerTable(p.playerID)
- showID = req.Value
- )
- showRow, found := data.MapMainCityShow.GetByMainCityShowID(showID)
- if !found {
- p.ResponseCode(session, code.ShowConfigNotExist)
- return
- }
- // 激活类型错误
- if showRow.ActiveType != enum.ShowActiveType_Item {
- p.ResponseCode(session, code.ShowActiveTypeError)
- return
- }
- // 已激活过 跳过
- _, found = playerTable.Shows.GetShow(showID)
- if found && showRow.ExpireTime <= 0 {
- p.ResponseCode(session, code.ShowAlreadyActive)
- return
- }
- // 扣除消耗道具
- _, errCode := mapFacade.Storage.AssetSubOne(p.playerID, showRow.ActiveCondition.Key, int64(showRow.ActiveCondition.Value), ao.ConscriptOutsideReturn, true)
- if code.IsFail(errCode) {
- p.ResponseCode(session, errCode)
- return
- }
- show := playerTable.Shows.ActiveShow(showID, showRow.ExpireTime, true)
- playerTable.Save2Queue()
- resp := show.ToShowProto(showID)
- p.Response(session, resp)
- }
- // 查看外显 消除红点
- func (p *actorPlayer) showView(session *cproto.Session, req *pb.I32) {
- var (
- playerTable = db.GetMapPlayerTable(p.playerID)
- showID = req.Value
- )
- show, found := playerTable.Shows.GetShow(showID)
- if !found {
- p.ResponseCode(session, code.ShowNotUnlock)
- return
- }
- if !show.IsViewed {
- show.IsViewed = true
- playerTable.Save2Queue()
- }
- p.ResponseCode(session, code.OK)
- }
- // 主城外观变更
- func (p *actorPlayer) mainCityChange(session *cproto.Session, req *pb.I32) {
- var (
- playerTable = db.GetMapPlayerTable(p.playerID)
- showID = req.Value
- )
- show, found := playerTable.Shows.GetShow(showID)
- if !found {
- p.ResponseCode(session, code.ShowNotUnlock)
- return
- }
- // 外显已过期
- if show.ExpireTime > 0 && show.ExpireTime <= ctime.Now().ToSecond() {
- p.ResponseCode(session, code.ShowExpire)
- return
- }
- // 发送变更事件
- p.PostEvent(event.NewMainCityShowChange(p.playerID, showID))
- // 更新主城外观ID
- playerTable.Shows.MainCityShowID = showID
- playerTable.Save2Queue()
- resp := &pb.I32{Value: showID}
- p.Response(session, resp)
- }
- func (p *actorPlayer) onFacilityUpRefreshShow(c cfacade.IEventData) {
- evt, ok := c.(*event.FacilityUp)
- if !ok {
- p.Warn("[onFacilityUpRefreshShow] fail, event: %+v", c)
- return
- }
- var (
- playerTable = db.GetMapPlayerTable(p.playerID)
- facilityID = evt.FacilityID()
- level = evt.Level()
- changeShowIDs = []int32{}
- )
- for _, showRow := range data.MapMainCityShow.List() {
- // 不是建筑激活 或 所需建筑ID不匹配
- if showRow.ActiveType != enum.ShowActiveType_Facility || showRow.ActiveCondition.Key != facilityID {
- continue
- }
- // 已经激活过 跳过
- _, found := playerTable.Shows.GetShow(showRow.MainCityShowID)
- if found {
- continue
- }
- // 当前等级不足
- if level < showRow.ActiveCondition.Value {
- continue
- }
- playerTable.Shows.ActiveShow(showRow.MainCityShowID, showRow.ExpireTime, false)
- changeShowIDs = append(changeShowIDs, showRow.MainCityShowID)
- }
- // 变更推送
- show.Service().ChangePush(playerTable, nil, changeShowIDs...)
- }
|