上传犬兔大战

This commit is contained in:
liwei1dao 2023-10-27 15:46:56 +08:00
parent d8a88755a5
commit 29b4928fd1
3 changed files with 48 additions and 99 deletions

View File

@ -3,6 +3,7 @@ package caninerabbit
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
) )
func (this *apiComp) AwardCheck(session comm.IUserSession, req *pb.CanineRabbitAwardReq) (errdata *pb.ErrorData) { func (this *apiComp) AwardCheck(session comm.IUserSession, req *pb.CanineRabbitAwardReq) (errdata *pb.ErrorData) {
@ -11,6 +12,7 @@ func (this *apiComp) AwardCheck(session comm.IUserSession, req *pb.CanineRabbitA
func (this *apiComp) Award(session comm.IUserSession, req *pb.CanineRabbitAwardReq) (errdata *pb.ErrorData) { func (this *apiComp) Award(session comm.IUserSession, req *pb.CanineRabbitAwardReq) (errdata *pb.ErrorData) {
var ( var (
conf *cfg.GameCatchrabbitrewardData
info *pb.DBCanineRabbit info *pb.DBCanineRabbit
atno []*pb.UserAtno atno []*pb.UserAtno
ok bool ok bool
@ -19,6 +21,13 @@ func (this *apiComp) Award(session comm.IUserSession, req *pb.CanineRabbitAwardR
if errdata = this.AwardCheck(session, req); errdata != nil { if errdata = this.AwardCheck(session, req); errdata != nil {
return return
} }
if conf, err = this.module.configure.getGameGColorRewardData(req.Id); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Message: err.Error(),
}
return
}
if info, err = this.module.model.getModel(session.GetUserId()); err != nil { if info, err = this.module.model.getModel(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
@ -27,14 +36,34 @@ func (this *apiComp) Award(session comm.IUserSession, req *pb.CanineRabbitAwardR
} }
return return
} }
if _, ok = info.Award[req.Id]; ok { if _, ok = info.Award[req.Id]; ok {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError, Code: pb.ErrorCode_ReqParameterError,
Message: "Allaward Claimed!", Message: "Allaward Claimed!",
} }
} }
if conf.Type == 1 {
session.SendMsg(string(this.module.GetType()), "info", &pb.CanineRabbitAwardResp{Id: req.Id, Award: atno}) if info.Rabbitintegral < conf.Condition {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ActivityCantReward,
Message: "Rabbitintegral no enough",
}
return
}
} else {
if info.Houndintegral < conf.Condition {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ActivityCantReward,
Message: "Houndintegral no enough",
}
return
}
}
if errdata, atno = this.module.DispenseAtno(session, conf.Reward, true); errdata != nil {
return
}
session.SendMsg(string(this.module.GetType()), "award", &pb.CanineRabbitAwardResp{Id: req.Id, Award: atno})
return return
} }

View File

@ -1,130 +1,41 @@
package caninerabbit package caninerabbit
import ( import (
"fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"sync"
) )
const ( const (
game_gcolorgetfraction = "game_gcolorgetfraction.json" game_catchrabbitreward = "game_catchrabbitreward.json"
game_gcolorreward = "game_gcolorreward.json"
game_gcolorttmedecay = "game_gcolorttmedecay.json"
) )
type configureComp struct { type configureComp struct {
modules.MCompConfigure modules.MCompConfigure
module *CanineRabbit module *CanineRabbit
lock sync.RWMutex
repeatMap map[int32][]*cfg.GameGColorGetfractionData
norepeatMap map[int32][]*cfg.GameGColorGetfractionData
} }
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompConfigure.Init(service, module, comp, options) err = this.MCompConfigure.Init(service, module, comp, options)
this.module = module.(*CanineRabbit) this.module = module.(*CanineRabbit)
this.repeatMap = make(map[int32][]*cfg.GameGColorGetfractionData)
err = this.LoadMultiConfigure(map[string]interface{}{ err = this.LoadMultiConfigure(map[string]interface{}{
game_gcolorreward: cfg.NewGameGColorReward, game_catchrabbitreward: cfg.NewGameCatchrabbitreward,
game_gcolorttmedecay: cfg.NewGameGColortTmedecay,
}) })
configure.RegisterConfigure(game_gcolorgetfraction, cfg.NewGameGColorGetfraction, this.updateconfigure)
return
}
// 更新任务配置表
func (this *configureComp) updateconfigure() {
var (
v interface{}
conf *cfg.GameGColorGetfraction
ok bool
err error
)
if v, err = this.GetConfigure(game_gcolorgetfraction); err != nil {
return
}
if conf, ok = v.(*cfg.GameGColorGetfraction); !ok {
this.module.Error("日常任务配置异常!")
return
}
repeatMap := map[int32][]*cfg.GameGColorGetfractionData{}
norepeatMap := map[int32][]*cfg.GameGColorGetfractionData{}
for _, v := range conf.GetDataList() {
if v.Repeat == 1 {
if _, ok = repeatMap[v.Difficulty]; !ok {
repeatMap[v.Difficulty] = make([]*cfg.GameGColorGetfractionData, 0)
}
repeatMap[v.Difficulty] = append(repeatMap[v.Difficulty], v)
} else {
if _, ok = norepeatMap[v.Difficulty]; !ok {
norepeatMap[v.Difficulty] = make([]*cfg.GameGColorGetfractionData, 0)
}
norepeatMap[v.Difficulty] = append(norepeatMap[v.Difficulty], v)
}
}
this.lock.Lock()
this.repeatMap = repeatMap
this.norepeatMap = norepeatMap
this.lock.Unlock()
}
func (this *configureComp) getGameGColorGetfractionData(dif int32, repeat bool, index int) (conf *cfg.GameGColorGetfractionData, err error) {
var (
confs map[int32][]*cfg.GameGColorGetfractionData
ok bool
)
if repeat {
confs = this.repeatMap
} else {
confs = this.norepeatMap
}
if _, ok = confs[dif]; ok {
if len(confs[dif]) > index {
conf = confs[dif][index]
return
}
}
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_gcolorgetfraction, fmt.Sprintf("dif:%d repeat:%v index:%d", dif, repeat, index))
return
}
// 获取伤害对应的评分组
func (this *configureComp) getGameGColortTmedecayData(time int32) (conf *cfg.GameGColortTmedecayData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_gcolorttmedecay); err != nil {
return
} else {
for _, v := range v.(*cfg.GameGColortTmedecay).GetDataList() {
if (time >= v.Min || v.Min == -1) && (time <= v.Max || v.Max == -1) {
conf = v
return
}
}
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_gcolorttmedecay, time)
this.module.Errorf("err:%v", err)
}
return return
} }
// 获取奖励列表 // 获取奖励列表
func (this *configureComp) getGameGColorRewardData(id int32) (conf *cfg.GameGColorRewardData, err error) { func (this *configureComp) getGameGColorRewardData(id int32) (conf *cfg.GameCatchrabbitrewardData, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
) )
if v, err = this.GetConfigure(game_gcolorreward); err != nil { if v, err = this.GetConfigure(game_catchrabbitreward); err != nil {
return return
} }
if conf, ok = v.(*cfg.GameGColorReward).GetDataMap()[id]; !ok { if conf, ok = v.(*cfg.GameCatchrabbitreward).GetDataMap()[id]; !ok {
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_gcolorreward, id) err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_catchrabbitreward, id)
this.module.Errorln(err) this.module.Errorln(err)
return return
} }

View File

@ -79,7 +79,11 @@ func (this *Room) PlayerWin(uid string, handle *pb.CanineRabbitWinReq) (err erro
if handle.Iswin { if handle.Iswin {
if this.currside == 1 { if this.currside == 1 {
this.data.Red.Score = 1 this.data.Red.Score = 1
if this.data.Rules.RedType == 0 {
this.data.Red.Rabbitintegral += 1
} else {
this.data.Red.Houndintegral += 1
}
this.module.model.Change(this.data.Red.Info.Uid, map[string]interface{}{ this.module.model.Change(this.data.Red.Info.Uid, map[string]interface{}{
"rabbitintegral": this.data.Red.Rabbitintegral, "rabbitintegral": this.data.Red.Rabbitintegral,
"houndintegral": this.data.Red.Houndintegral, "houndintegral": this.data.Red.Houndintegral,
@ -87,6 +91,11 @@ func (this *Room) PlayerWin(uid string, handle *pb.CanineRabbitWinReq) (err erro
} else { } else {
this.data.Blue.Score = 1 this.data.Blue.Score = 1
if this.data.Rules.RedType == 0 {
this.data.Blue.Rabbitintegral += 1
} else {
this.data.Blue.Houndintegral += 1
}
this.module.model.Change(this.data.Blue.Info.Uid, map[string]interface{}{ this.module.model.Change(this.data.Blue.Info.Uid, map[string]interface{}{
"rabbitintegral": this.data.Red.Rabbitintegral, "rabbitintegral": this.data.Red.Rabbitintegral,
"houndintegral": this.data.Red.Houndintegral, "houndintegral": this.data.Red.Houndintegral,