adjust fresh award grids
This commit is contained in:
parent
3898d38933
commit
ea98c2e536
@ -113,9 +113,30 @@ func (this *ActivityApi) RollDice(c *gin.Context) {
|
||||
f5.RspErr(c, 500, "server internal error7")
|
||||
return
|
||||
}
|
||||
for _, item := range *items {
|
||||
rspObj.GetOrCreateAward().AddItem(item.ItemId, item.ItemNum)
|
||||
|
||||
awardgridids := mt.Table.MapGrid.GetAwardGridIdList()
|
||||
if len(*items) > 0 {
|
||||
gridawarded := false
|
||||
for _, id := range user.AwardGridsList {
|
||||
if id == user.CurrGrid {
|
||||
gridawarded = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !gridawarded {
|
||||
for _, item := range *items {
|
||||
rspObj.GetOrCreateAward().AddItem(item.ItemId, item.ItemNum)
|
||||
}
|
||||
|
||||
if len(awardgridids) > len(user.AwardGridsList) + 1 {
|
||||
user.AddAwardGrid(user.CurrGrid)
|
||||
} else {
|
||||
user.ClearAwardGrid()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rspObj.GetOrCreateAward().AddItem(constant.VIRTUAL_ITEM_SCORE, score)
|
||||
|
||||
totalaward := rspObj.GetOrCreateAward()
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"f5"
|
||||
"main/constant"
|
||||
"q5"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@ -27,8 +28,10 @@ type User struct {
|
||||
SpecDice int32 `gorm:"column:spec_dice"`
|
||||
LastPresentDiceTime int32 `gorm:"column:last_present_dice_time"`
|
||||
CurrGrid int32 `gorm:"column:curr_grid"`
|
||||
CreateTime int32 `gorm:"column:createtime;<-:create"`
|
||||
ModifyTime int32 `gorm:"column:modifytime"`
|
||||
AwardGrids string `gorm:"column:award_grids"`
|
||||
AwardGridsList []int32
|
||||
CreateTime int32 `gorm:"column:createtime;<-:create"`
|
||||
ModifyTime int32 `gorm:"column:modifytime"`
|
||||
}
|
||||
|
||||
func (this *User) TableName() string {
|
||||
@ -64,6 +67,11 @@ func (this *User) Find(accountId string, nowTime int64) (error, bool) {
|
||||
return err, false
|
||||
}
|
||||
}
|
||||
gridstr := strings.Split(this.AwardGrids, ",")
|
||||
this.AwardGridsList = []int32{}
|
||||
for _, item := range gridstr {
|
||||
this.AwardGridsList = append(this.AwardGridsList, q5.SafeToInt32(item))
|
||||
}
|
||||
}
|
||||
return nil, result.RowsAffected > 0
|
||||
}
|
||||
@ -158,3 +166,25 @@ func (this *User) AddScore(score int32) error {
|
||||
func (this *User) UpdateName() error {
|
||||
return this.UpdateFields([]string{"nickname"})
|
||||
}
|
||||
|
||||
func (this *User) AddAwardGrid(gridid int32) error {
|
||||
this.AwardGridsList = append(this.AwardGridsList, gridid)
|
||||
if len(this.AwardGridsList) > 1 {
|
||||
this.AwardGrids += ","
|
||||
}
|
||||
|
||||
this.AwardGrids += q5.SafeToString(gridid)
|
||||
if err := this.UpdateFields([]string{"award_grids"}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *User) ClearAwardGrid() error {
|
||||
this.AwardGridsList = []int32{}
|
||||
this.AwardGrids = ""
|
||||
if err := this.UpdateFields([]string{"award_grids"}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package mt
|
||||
|
||||
import (
|
||||
"q5"
|
||||
"f5"
|
||||
"main/mtb"
|
||||
"q5"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type MapGridRewardItem struct {
|
||||
ItemId int32
|
||||
ItemId int32
|
||||
ItemNum int32
|
||||
}
|
||||
|
||||
@ -19,7 +19,8 @@ type MapGrid struct {
|
||||
|
||||
type MapGridTable struct {
|
||||
f5.IdMetaTable[MapGrid]
|
||||
maxGridId int32
|
||||
awardGrids []*MapGrid
|
||||
maxGridId int32
|
||||
}
|
||||
|
||||
func (this *MapGrid) Init1() {
|
||||
@ -27,7 +28,7 @@ func (this *MapGrid) Init1() {
|
||||
return
|
||||
}
|
||||
tmpStrs := strings.Split(this.MapGrid.GetReward(), "|")
|
||||
for _, tmpStr := range(tmpStrs) {
|
||||
for _, tmpStr := range tmpStrs {
|
||||
tmpStrs2 := strings.Split(tmpStr, ":")
|
||||
p := new(MapGridRewardItem)
|
||||
p.ItemId = q5.ToInt32(tmpStrs2[0])
|
||||
@ -41,10 +42,13 @@ func (this *MapGrid) GetRewardItems() *[]*MapGridRewardItem {
|
||||
}
|
||||
|
||||
func (this *MapGridTable) PostInit1() {
|
||||
this.Traverse(func (gridMeta *MapGrid) bool {
|
||||
this.Traverse(func(gridMeta *MapGrid) bool {
|
||||
if gridMeta.GetId() > this.maxGridId {
|
||||
this.maxGridId = gridMeta.GetId()
|
||||
}
|
||||
if len(gridMeta.rewardItems) > 0 {
|
||||
this.awardGrids = append(this.awardGrids, gridMeta)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
@ -52,3 +56,12 @@ func (this *MapGridTable) PostInit1() {
|
||||
func (this *MapGridTable) GetMaxGridId() int32 {
|
||||
return this.maxGridId
|
||||
}
|
||||
|
||||
func (this *MapGridTable) GetAwardGridIdList() []int32 {
|
||||
idlist := []int32{}
|
||||
for _, item := range this.awardGrids {
|
||||
idlist = append(idlist, item.GetId())
|
||||
}
|
||||
|
||||
return idlist
|
||||
}
|
||||
|
@ -5,15 +5,16 @@ import (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
AccountId string `json:"account_id"`
|
||||
NickName string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
Score int64 `json:"score"`
|
||||
HourlyEarnings string `json:"hourly_earnings"`
|
||||
Dice int32 `json:"dice"`
|
||||
SpecDice int32 `json:"spec_dice"`
|
||||
CurrGrid int32 `json:"curr_grid"`
|
||||
LastPresentDiceTime int32 `json:"last_present_dice_time"`
|
||||
AccountId string `json:"account_id"`
|
||||
NickName string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
Score int64 `json:"score"`
|
||||
HourlyEarnings string `json:"hourly_earnings"`
|
||||
Dice int32 `json:"dice"`
|
||||
SpecDice int32 `json:"spec_dice"`
|
||||
CurrGrid int32 `json:"curr_grid"`
|
||||
LastPresentDiceTime int32 `json:"last_present_dice_time"`
|
||||
AwardGrids []int32 `json:"award_grids"`
|
||||
}
|
||||
|
||||
func (this *User) FromModel(m *model.User) {
|
||||
@ -26,4 +27,5 @@ func (this *User) FromModel(m *model.User) {
|
||||
this.SpecDice = m.SpecDice
|
||||
this.CurrGrid = m.CurrGrid
|
||||
this.LastPresentDiceTime = m.LastPresentDiceTime
|
||||
this.AwardGrids = m.AwardGridsList
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user