练功计算收益

This commit is contained in:
liwei1dao 2023-02-24 17:22:12 +08:00
parent f1e59e092f
commit 4209e202c1
4 changed files with 251 additions and 36 deletions

View File

@ -265,7 +265,7 @@ func (this *Equipment) RecycleEquipments(session comm.IUserSession, equs []strin
_s := &cfg.Gameatn{
A: s.A,
T: s.T,
N: int32(math.Floor(float64(s.N) * float64(discount) / float64(100))),
N: int32(math.Floor(float64(s.N) * float64(discount+1000) / float64(1000))),
}
sale[i][n] = _s
}

View File

@ -76,7 +76,7 @@ func (this *apiComp) Practice(session comm.IUserSession, req *pb.PracticePractic
return
}
room.Knapsack[req.Prop] = 1
if pconfigure, err = this.module.configure.getGamePandamasJx(req.Teacher); err != nil {
if pconfigure, err = this.module.configure.getGamePandamasJx(req.Prop); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
@ -84,7 +84,14 @@ func (this *apiComp) Practice(session comm.IUserSession, req *pb.PracticePractic
}
pillar.Hero = req.Hero
pillar.Start = configure.Now().Unix()
pillar.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix()
if extra >= 0 {
pillar.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration))).Unix()
pillar.Expend = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix()
} else {
pillar.End = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration + extra))).Unix()
pillar.Expend = configure.Now().Add(time.Minute * (time.Duration(pillarconfigure.PlacementDuration))).Unix()
}
this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{
"knapsack": room.Knapsack,
filed: pillar,

View File

@ -3,6 +3,11 @@ package practice
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"math"
"math/rand"
"time"
"google.golang.org/protobuf/proto"
)
@ -16,6 +21,181 @@ func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.PracticeRec
///练功请求 奖励
func (this *apiComp) Receive(session comm.IUserSession, req *pb.PracticeReceiveReq) (code pb.ErrorCode, data proto.Message) {
var (
err error
room *pb.DBPracticeRoom
pillar *pb.DBPracticePillar
pillarconfigure *cfg.GamePandamasMzData
tconfigure *cfg.GamePandamasJxData
pconfigure *cfg.GamePandamasJxData
filed string
exp int32
exp1 int32
ants1 []*cfg.Gameatn
ants2 []*cfg.Gameatn
)
if req.Friend != "" {
if room, err = this.module.modelPandata.queryUserMartialhall(req.Friend); err != nil {
code = pb.ErrorCode_DBError
return
}
pillar = room.Pillarf
filed = "pillarf"
} else {
if room, err = this.module.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil {
code = pb.ErrorCode_DBError
return
}
switch req.Index {
case 1:
pillar = room.Pillar1
filed = "pillar1"
break
case 2:
pillar = room.Pillar2
filed = "pillar2"
break
case 3:
pillar = room.Pillar3
filed = "pillar3"
break
}
}
if pillar == nil {
code = pb.ErrorCode_ReqParameterError
return
}
if pillarconfigure, err = this.module.configure.getGamePandamasMz(pillar.Lv); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if pillar.Teacher != "" {
if tconfigure, err = this.module.configure.getGamePandamasJx(pillar.Teacher); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
}
if pillar.Prop != "" {
if pconfigure, err = this.module.configure.getGamePandamasJx(pillar.Prop); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
}
//计算经验收益
if configure.Now().After(time.Unix(pillar.Expend, 0)) {
minutes := int32(time.Unix(pillar.Expend, 0).Sub(time.Unix(pillar.Start, 0)).Minutes())
exp = minutes * pillarconfigure.MinExp
} else {
minutes := int32(configure.Now().Sub(time.Unix(pillar.Start, 0)).Minutes())
exp = minutes * pillarconfigure.MinExp
}
exp1 += exp
//是否可以获得额外收益
if configure.Now().After(time.Unix(pillar.End, 0)) {
if tconfigure != nil {
if tconfigure.Exp > 0 { //经验加成
exp1 += int32(math.Floor(float64(exp) * (float64(tconfigure.Exp) / float64(100))))
}
if len(tconfigure.Ants) > 0 { //额外道具加成
ants1 = make([]*cfg.Gameatn, 0)
r := rand.New(rand.NewSource(time.Now().Unix()))
num := r.Int31n(tconfigure.Num[1]-tconfigure.Num[0]) + tconfigure.Num[0]
if r.Int31n(100) < tconfigure.Probability { //随机一个道具
total := 0
for _, v := range tconfigure.Wget {
total += int(v)
}
n := rand.Intn(total)
for i, v := range tconfigure.Wget {
if int32(n) <= v {
ants1 = append(ants1, &cfg.Gameatn{
A: tconfigure.Ants[i].A,
T: tconfigure.Ants[i].T,
N: num,
})
break
}
}
} else { //全部要
for _, v := range tconfigure.Ants {
ants1 = append(ants1, &cfg.Gameatn{
A: v.A,
T: v.T,
N: 0,
})
}
for i := int32(0); i < num; i++ {
index := i % int32(len(ants1))
ants1[index].N++
}
}
}
}
if pconfigure != nil {
if pconfigure.Exp > 0 { //经验加成
exp1 += int32(math.Floor(float64(exp) * (float64(pconfigure.Exp) / float64(100))))
}
if len(pconfigure.Ants) > 0 { //额外道具加成
ants2 = make([]*cfg.Gameatn, 0)
r := rand.New(rand.NewSource(time.Now().Unix()))
num := r.Int31n(pconfigure.Num[1]-pconfigure.Num[0]) + pconfigure.Num[0]
if r.Int31n(100) < pconfigure.Probability { //随机一个道具
total := 0
for _, v := range pconfigure.Wget {
total += int(v)
}
n := rand.Intn(total)
for i, v := range pconfigure.Wget {
if int32(n) <= v {
ants2 = append(ants2, &cfg.Gameatn{
A: pconfigure.Ants[i].A,
T: pconfigure.Ants[i].T,
N: num,
})
break
}
}
} else { //全部要
for _, v := range pconfigure.Ants {
ants2 = append(ants2, &cfg.Gameatn{
A: v.A,
T: v.T,
N: 0,
})
}
for i := int32(0); i < num; i++ {
index := i % int32(len(ants2))
ants2[index].N++
}
}
}
}
}
if _, code = this.module.ModuleHero.AddHeroExp(session, pillar.Hero, exp); code != pb.ErrorCode_Success {
return
}
if code = this.module.DispenseRes(session, append(ants1, ants2...), true); code != pb.ErrorCode_Success {
return
}
room.Knapsack[pillar.Teacher] = 0
room.Knapsack[pillar.Prop] = 0
pillar.Hero = ""
pillar.Teacher = ""
pillar.Prop = ""
pillar.Start = 0
pillar.End = 0
pillar.Expend = 0
this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{
"knapsack": room.Knapsack,
filed: pillar,
})
session.SendMsg(string(this.module.GetType()), "receive", &pb.PracticeReceiveResp{})
return
}

View File

@ -30,8 +30,11 @@ type DBPracticePillar struct {
Lv int32 `protobuf:"varint,2,opt,name=lv,proto3" json:"lv"` //柱子等级
Isunlock bool `protobuf:"varint,3,opt,name=isunlock,proto3" json:"isunlock"` //是否解锁
Hero string `protobuf:"bytes,4,opt,name=hero,proto3" json:"hero"` //当前练功英雄
Start int64 `protobuf:"varint,5,opt,name=start,proto3" json:"start"` //开始时间
End int64 `protobuf:"varint,6,opt,name=end,proto3" json:"end"` //结束时间
Teacher string `protobuf:"bytes,5,opt,name=teacher,proto3" json:"teacher"` //教习
Prop string `protobuf:"bytes,6,opt,name=prop,proto3" json:"prop"` //道具
Start int64 `protobuf:"varint,7,opt,name=start,proto3" json:"start"` //开始时间
End int64 `protobuf:"varint,8,opt,name=end,proto3" json:"end"` //结束时间
Expend int64 `protobuf:"varint,9,opt,name=expend,proto3" json:"expend"` //经验上限时间
}
func (x *DBPracticePillar) Reset() {
@ -94,6 +97,20 @@ func (x *DBPracticePillar) GetHero() string {
return ""
}
func (x *DBPracticePillar) GetTeacher() string {
if x != nil {
return x.Teacher
}
return ""
}
func (x *DBPracticePillar) GetProp() string {
if x != nil {
return x.Prop
}
return ""
}
func (x *DBPracticePillar) GetStart() int64 {
if x != nil {
return x.Start
@ -108,6 +125,13 @@ func (x *DBPracticePillar) GetEnd() int64 {
return 0
}
func (x *DBPracticePillar) GetExpend() int64 {
if x != nil {
return x.Expend
}
return 0
}
//熊猫武馆教习
type DBPracticeTeacher struct {
state protoimpl.MessageState
@ -272,45 +296,49 @@ var File_practice_practice_db_proto protoreflect.FileDescriptor
var file_practice_practice_db_proto_rawDesc = []byte{
0x0a, 0x1a, 0x70, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x2f, 0x70, 0x72, 0x61, 0x63, 0x74,
0x69, 0x63, 0x65, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x90, 0x01, 0x0a,
0x69, 0x63, 0x65, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd6, 0x01, 0x0a,
0x10, 0x44, 0x42, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x50, 0x69, 0x6c, 0x6c, 0x61,
0x72, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05,
0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76, 0x18, 0x02, 0x20,
0x01, 0x28, 0x05, 0x52, 0x02, 0x6c, 0x76, 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x73, 0x75, 0x6e, 0x6c,
0x6f, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x69, 0x73, 0x75, 0x6e, 0x6c,
0x6f, 0x63, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x04, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74,
0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x10, 0x0a,
0x03, 0x65, 0x6e, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x22,
0x4f, 0x0a, 0x11, 0x44, 0x42, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x54, 0x65, 0x61,
0x63, 0x68, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x03, 0x63, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x75, 0x64, 0x65, 0x6e,
0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x74, 0x75, 0x64, 0x65, 0x6e, 0x74,
0x22, 0xde, 0x02, 0x0a, 0x0e, 0x44, 0x42, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x52,
0x6f, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x39, 0x0a, 0x08, 0x6b, 0x6e, 0x61, 0x70, 0x73, 0x61, 0x63,
0x6b, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x44, 0x42, 0x50, 0x72, 0x61, 0x63,
0x74, 0x69, 0x63, 0x65, 0x52, 0x6f, 0x6f, 0x6d, 0x2e, 0x4b, 0x6e, 0x61, 0x70, 0x73, 0x61, 0x63,
0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6b, 0x6e, 0x61, 0x70, 0x73, 0x61, 0x63, 0x6b,
0x12, 0x2b, 0x0a, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x31, 0x18, 0x04, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x65, 0x61, 0x63, 0x68,
0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x74, 0x65, 0x61, 0x63, 0x68, 0x65,
0x72, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x72, 0x6f, 0x70, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x70, 0x72, 0x6f, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x07,
0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x65,
0x6e, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x12, 0x16, 0x0a,
0x06, 0x65, 0x78, 0x70, 0x65, 0x6e, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x65,
0x78, 0x70, 0x65, 0x6e, 0x64, 0x22, 0x4f, 0x0a, 0x11, 0x44, 0x42, 0x50, 0x72, 0x61, 0x63, 0x74,
0x69, 0x63, 0x65, 0x54, 0x65, 0x61, 0x63, 0x68, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69,
0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07,
0x73, 0x74, 0x75, 0x64, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73,
0x74, 0x75, 0x64, 0x65, 0x6e, 0x74, 0x22, 0xde, 0x02, 0x0a, 0x0e, 0x44, 0x42, 0x50, 0x72, 0x61,
0x63, 0x74, 0x69, 0x63, 0x65, 0x52, 0x6f, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x39, 0x0a, 0x08, 0x6b,
0x6e, 0x61, 0x70, 0x73, 0x61, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e,
0x44, 0x42, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x52, 0x6f, 0x6f, 0x6d, 0x2e, 0x4b,
0x6e, 0x61, 0x70, 0x73, 0x61, 0x63, 0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6b, 0x6e,
0x61, 0x70, 0x73, 0x61, 0x63, 0x6b, 0x12, 0x2b, 0x0a, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72,
0x31, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x44, 0x42, 0x50, 0x72, 0x61, 0x63,
0x74, 0x69, 0x63, 0x65, 0x50, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x52, 0x07, 0x70, 0x69, 0x6c, 0x6c,
0x61, 0x72, 0x31, 0x12, 0x2b, 0x0a, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x32, 0x18, 0x05,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x44, 0x42, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63,
0x65, 0x50, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x52, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x32,
0x12, 0x2b, 0x0a, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x33, 0x18, 0x06, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x11, 0x2e, 0x44, 0x42, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x50, 0x69,
0x6c, 0x6c, 0x61, 0x72, 0x52, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x31, 0x12, 0x2b, 0x0a,
0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x32, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11,
0x6c, 0x6c, 0x61, 0x72, 0x52, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x33, 0x12, 0x2b, 0x0a,
0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x66, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11,
0x2e, 0x44, 0x42, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x50, 0x69, 0x6c, 0x6c, 0x61,
0x72, 0x52, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x32, 0x12, 0x2b, 0x0a, 0x07, 0x70, 0x69,
0x6c, 0x6c, 0x61, 0x72, 0x33, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x44, 0x42,
0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x50, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x52, 0x07,
0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x33, 0x12, 0x2b, 0x0a, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61,
0x72, 0x66, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x44, 0x42, 0x50, 0x72, 0x61,
0x63, 0x74, 0x69, 0x63, 0x65, 0x50, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x52, 0x07, 0x70, 0x69, 0x6c,
0x6c, 0x61, 0x72, 0x66, 0x1a, 0x3b, 0x0a, 0x0d, 0x4b, 0x6e, 0x61, 0x70, 0x73, 0x61, 0x63, 0x6b,
0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38,
0x01, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
0x72, 0x52, 0x07, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x66, 0x1a, 0x3b, 0x0a, 0x0d, 0x4b, 0x6e,
0x61, 0x70, 0x73, 0x61, 0x63, 0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b,
0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (