公会BOSS战斗

This commit is contained in:
wh_zcy 2023-01-11 17:01:09 +08:00
parent 70ab245740
commit 12b9240d7a
8 changed files with 772 additions and 470 deletions

View File

@ -45,8 +45,9 @@ func (s *SociatyBossView) CreateView(t *model.TestCase) fyne.CanvasObject {
defer loadSociaty() defer loadSociaty()
buzhenBtn := widget.NewButton("布阵", s.buzhen) buzhenBtn := widget.NewButton("布阵", s.buzhen)
challengeBtn := widget.NewButton("挑战", s.challenge) challengestartBtn := widget.NewButton("开始挑战", s.challengestart)
btns := container.NewHBox(buzhenBtn, challengeBtn) challengefinishBtn := widget.NewButton("挑战结束", s.challengefinish)
btns := container.NewHBox(buzhenBtn, challengestartBtn, challengefinishBtn)
c := container.NewBorder(btns, nil, nil, nil) c := container.NewBorder(btns, nil, nil, nil)
s.listenTeams() s.listenTeams()
@ -82,9 +83,36 @@ func (s *SociatyBossView) listenTeams() {
s.teamFlag = true s.teamFlag = true
} }
// 挑战 // 挑战开始
func (s *SociatyBossView) challenge() { func (s *SociatyBossView) challengestart() {
if err := service.GetPttService().SendToClient(
string(comm.ModuleSociaty),
sociaty.SociatySubTypeChallengestart,
&pb.SociatyBChallengeStartReq{
SociatyId: s.sociatyId,
},
); err != nil {
logrus.Error(err)
return
}
}
// 挑战结束
func (s *SociatyBossView) challengefinish() {
if err := service.GetPttService().SendToClient(
string(comm.ModuleSociaty),
sociaty.SociatySubTypeChallengefinish,
&pb.SociatyBChallengeFinishReq{
Ptype: pb.PlayType_sociaty,
Report: &pb.BattleReport{
Costtime: 180,
Harm: 180300,
},
},
); err != nil {
logrus.Error(err)
return
}
} }
//布阵 //布阵
@ -148,6 +176,8 @@ func (s *SociatyBossView) buzhen() {
s.teams = make(map[int32]*pb.ChallengeTeams) s.teams = make(map[int32]*pb.ChallengeTeams)
} }
s.teams[1] = &pb.ChallengeTeams{Infos: teams} s.teams[1] = &pb.ChallengeTeams{Infos: teams}
team1.Refresh()
team1Box.Refresh()
} }
// 添加二队英雄 // 添加二队英雄

View File

@ -35,6 +35,8 @@ const (
SociatySubTypeAgreePush = "agree" SociatySubTypeAgreePush = "agree"
SociatySubTypeRecord = "record" SociatySubTypeRecord = "record"
SociatySubTypeFormation = "formation" SociatySubTypeFormation = "formation"
SociatySubTypeChallengestart = "challengestart"
SociatySubTypeChallengefinish = "challengefinish"
) )
type apiComp struct { type apiComp struct {

View File

@ -1,16 +0,0 @@
package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.SociatyBChallengeReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.SociatyBChallengeReq) (code pb.ErrorCode, data proto.Message) {
return
}

View File

@ -0,0 +1,37 @@
package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
// 结束挑战
func (this *apiComp) ChallengefinishCheck(session comm.IUserSession, req *pb.SociatyBChallengeFinishReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) Challengefinish(session comm.IUserSession, req *pb.SociatyBChallengeFinishReq) (code pb.ErrorCode, data proto.Message) {
if code = this.ChallengefinishCheck(session, req); code != pb.ErrorCode_Success {
return
}
uid := session.GetUserId()
sociaty := this.module.modelSociaty.getUserSociaty(uid)
if sociaty != nil && sociaty.Id == "" {
code = pb.ErrorCode_SociatyNoFound
this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid})
return
}
this.module.modelSociatyBoss.challengefinish(sociaty, uid, req.Report)
rsp := &pb.SociatyBChallengeFinishResp{
Integral: this.module.modelSociatyBoss.transIntegral(req.Report.Harm),
}
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeChallengefinish, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -0,0 +1,40 @@
package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
// 开始挑战
func (this *apiComp) ChallengestartCheck(session comm.IUserSession, req *pb.SociatyBChallengeStartReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) Challengestart(session comm.IUserSession, req *pb.SociatyBChallengeStartReq) (code pb.ErrorCode, data proto.Message) {
if code = this.ChallengestartCheck(session, req); code != pb.ErrorCode_Success {
return
}
uid := session.GetUserId()
sociaty := this.module.modelSociaty.getUserSociaty(uid)
if sociaty != nil && sociaty.Id == "" {
code = pb.ErrorCode_SociatyNoFound
this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid})
return
}
this.module.modelSociatyBoss.challengestart(session)
rsp := &pb.SociatyBChallengeStartResp{
SociatyId: sociaty.Id,
Uid: uid,
}
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeChallengestart, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -1,10 +1,16 @@
package sociaty package sociaty
import ( import (
"context"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/lego/sys/redis/pipe"
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/bson/primitive"
) )
type ModelSociatyBoss struct { type ModelSociatyBoss struct {
@ -38,8 +44,8 @@ func (s *ModelSociatyBoss) setFormation(sociaty *pb.DBSociaty, uid string, teams
return s.moduleSociaty.modelSociaty.updateSociaty(sociaty.Id, update) return s.moduleSociaty.modelSociaty.updateSociaty(sociaty.Id, update)
} }
//挑战 //挑战开始
func (s *ModelSociatyBoss) challenge(session comm.IUserSession) error { func (s *ModelSociatyBoss) challengestart(session comm.IUserSession) error {
iBattle, err := s.moduleSociaty.service.GetModule(comm.ModuleBattle) iBattle, err := s.moduleSociaty.service.GetModule(comm.ModuleBattle)
if err != nil { if err != nil {
@ -55,3 +61,57 @@ func (s *ModelSociatyBoss) challenge(session comm.IUserSession) error {
} }
return nil return nil
} }
// 挑战结束
func (s *ModelSociatyBoss) challengefinish(sociaty *pb.DBSociaty, uid string, report *pb.BattleReport) error {
//扣除挑战券
sm := s.moduleSociaty.modelSociaty.getMemberInfo(sociaty, uid)
if sm.ChallengeTicket <= 0 {
}
//保存挑战记录
if err := s.addChallengeRecord(uid, &pb.DBSociatyBossRecord{
Uid: uid,
SociatyId: sociaty.Id,
Integral: s.transIntegral(report.Harm),
Duration: report.Costtime,
}); err != nil {
return err
}
return nil
}
// 挑战记录 作为阵容推荐的依据;
func (s *ModelSociatyBoss) addChallengeRecord(uid string, record *pb.DBSociatyBossRecord) error {
id := primitive.NewObjectID().Hex()
if err := s.AddList(uid, id, record); err != nil {
return err
}
return nil
}
// 计入排行
func (s *ModelSociatyBoss) addRank(uid string, integral int32) error {
var (
pipe *pipe.RedisPipe = s.Redis.RedisPipe(context.TODO())
m *redis.Z
)
m = &redis.Z{Score: float64(integral), Member: uid}
if cmd := pipe.ZAdd(s.TableName, m); cmd != nil {
_, err := cmd.Result()
if err != nil {
return err
}
}
if _, err := pipe.Exec(); err != nil {
return err
}
return nil
}
// 伤害转换积分
func (s *ModelSociatyBoss) transIntegral(harm int32) int64 {
return int64(harm)
}

View File

@ -897,11 +897,10 @@ type DBSociatyBossRecord struct {
SociatyId string `protobuf:"bytes,1,opt,name=sociatyId,proto3" json:"sociatyId" bson:"sociatyId"` //公会ID SociatyId string `protobuf:"bytes,1,opt,name=sociatyId,proto3" json:"sociatyId" bson:"sociatyId"` //公会ID
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //玩家ID Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //玩家ID
Integral int32 `protobuf:"varint,3,opt,name=integral,proto3" json:"integral" bson:"integral"` //公会BOSS挑战积分 Integral int64 `protobuf:"varint,3,opt,name=integral,proto3" json:"integral" bson:"integral"` //公会BOSS挑战积分
Evaluate int32 `protobuf:"varint,4,opt,name=evaluate,proto3" json:"evaluate" bson:"evaluate"` //评价 Teams map[int32]*ChallengeTeams `protobuf:"bytes,4,rep,name=teams,proto3" json:"teams" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3" bson:"teams"` //挑战队伍
Teams map[int32]*ChallengeTeams `protobuf:"bytes,5,rep,name=teams,proto3" json:"teams" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3" bson:"teams"` //挑战队伍 Duration int32 `protobuf:"varint,5,opt,name=duration,proto3" json:"duration" bson:"duration"` //战斗耗时
Duration int32 `protobuf:"varint,6,opt,name=duration,proto3" json:"duration" bson:"duration"` //战斗耗时 Rtime int64 `protobuf:"varint,6,opt,name=rtime,proto3" json:"rtime" bson:"rtime"` //记录时间
Rtime int64 `protobuf:"varint,7,opt,name=rtime,proto3" json:"rtime" bson:"rtime"` //记录时间
} }
func (x *DBSociatyBossRecord) Reset() { func (x *DBSociatyBossRecord) Reset() {
@ -950,20 +949,13 @@ func (x *DBSociatyBossRecord) GetUid() string {
return "" return ""
} }
func (x *DBSociatyBossRecord) GetIntegral() int32 { func (x *DBSociatyBossRecord) GetIntegral() int64 {
if x != nil { if x != nil {
return x.Integral return x.Integral
} }
return 0 return 0
} }
func (x *DBSociatyBossRecord) GetEvaluate() int32 {
if x != nil {
return x.Evaluate
}
return 0
}
func (x *DBSociatyBossRecord) GetTeams() map[int32]*ChallengeTeams { func (x *DBSociatyBossRecord) GetTeams() map[int32]*ChallengeTeams {
if x != nil { if x != nil {
return x.Teams return x.Teams
@ -1089,32 +1081,30 @@ var file_sociaty_sociaty_db_proto_rawDesc = []byte{
0x6c, 0x65, 0x6e, 0x67, 0x65, 0x54, 0x65, 0x61, 0x6d, 0x73, 0x12, 0x28, 0x0a, 0x05, 0x69, 0x6e, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x54, 0x65, 0x61, 0x6d, 0x73, 0x12, 0x28, 0x0a, 0x05, 0x69, 0x6e,
0x66, 0x6f, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x43, 0x68, 0x61, 0x6c, 0x66, 0x6f, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x43, 0x68, 0x61, 0x6c,
0x6c, 0x65, 0x6e, 0x67, 0x65, 0x54, 0x65, 0x61, 0x6d, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x69, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x54, 0x65, 0x61, 0x6d, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x69,
0x6e, 0x66, 0x6f, 0x73, 0x22, 0xb1, 0x02, 0x0a, 0x13, 0x44, 0x42, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x6e, 0x66, 0x6f, 0x73, 0x22, 0x95, 0x02, 0x0a, 0x13, 0x44, 0x42, 0x53, 0x6f, 0x63, 0x69, 0x61,
0x74, 0x79, 0x42, 0x6f, 0x73, 0x73, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x79, 0x42, 0x6f, 0x73, 0x73, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x1c, 0x0a, 0x09,
0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x09, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x09, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69,
0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08,
0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08,
0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x76, 0x61, 0x6c, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x12, 0x35, 0x0a, 0x05, 0x74, 0x65, 0x61, 0x6d,
0x75, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x65, 0x76, 0x61, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x44, 0x42, 0x53, 0x6f, 0x63, 0x69,
0x75, 0x61, 0x74, 0x65, 0x12, 0x35, 0x0a, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x18, 0x05, 0x20, 0x61, 0x74, 0x79, 0x42, 0x6f, 0x73, 0x73, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x54, 0x65,
0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x44, 0x42, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x42, 0x61, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x12,
0x6f, 0x73, 0x73, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x54, 0x65, 0x61, 0x6d, 0x73, 0x45, 0x1a, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28,
0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x74, 0x65, 0x61, 0x6d, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x05, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x72,
0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x64, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x72, 0x74, 0x69, 0x6d,
0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x65, 0x1a, 0x49, 0x0a, 0x0a, 0x54, 0x65, 0x61, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12,
0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x72, 0x74, 0x69, 0x6d, 0x65, 0x1a, 0x49, 0x0a, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65,
0x0a, 0x54, 0x65, 0x61, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x79, 0x12, 0x25, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b,
0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x25, 0x0a, 0x32, 0x0f, 0x2e, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x54, 0x65, 0x61, 0x6d,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x43, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x2a, 0x50, 0x0a, 0x0a,
0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x54, 0x65, 0x61, 0x6d, 0x73, 0x52, 0x05, 0x76, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x4a, 0x6f, 0x62, 0x12, 0x09, 0x0a, 0x05, 0x4e, 0x4f,
0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x2a, 0x50, 0x0a, 0x0a, 0x53, 0x6f, 0x63, 0x69, 0x4a, 0x4f, 0x42, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4d, 0x45, 0x4d, 0x42, 0x45, 0x52, 0x10,
0x61, 0x74, 0x79, 0x4a, 0x6f, 0x62, 0x12, 0x09, 0x0a, 0x05, 0x4e, 0x4f, 0x4a, 0x4f, 0x42, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x41, 0x44, 0x4d, 0x49, 0x4e, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d,
0x00, 0x12, 0x0a, 0x0a, 0x06, 0x4d, 0x45, 0x4d, 0x42, 0x45, 0x52, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x56, 0x49, 0x43, 0x45, 0x50, 0x52, 0x45, 0x53, 0x49, 0x44, 0x45, 0x4e, 0x54, 0x10, 0x03, 0x12,
0x05, 0x41, 0x44, 0x4d, 0x49, 0x4e, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x56, 0x49, 0x43, 0x45, 0x0d, 0x0a, 0x09, 0x50, 0x52, 0x45, 0x53, 0x49, 0x44, 0x45, 0x4e, 0x54, 0x10, 0x04, 0x42, 0x06,
0x50, 0x52, 0x45, 0x53, 0x49, 0x44, 0x45, 0x4e, 0x54, 0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x52, 0x45, 0x53, 0x49, 0x44, 0x45, 0x4e, 0x54, 0x10, 0x04, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (

File diff suppressed because it is too large Load Diff