adjust fresh award grids

This commit is contained in:
yangduo 2024-12-06 19:06:21 +08:00
parent 3898d38933
commit ea98c2e536
4 changed files with 84 additions and 18 deletions

View File

@ -113,9 +113,30 @@ func (this *ActivityApi) RollDice(c *gin.Context) {
f5.RspErr(c, 500, "server internal error7") f5.RspErr(c, 500, "server internal error7")
return return
} }
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 { for _, item := range *items {
rspObj.GetOrCreateAward().AddItem(item.ItemId, item.ItemNum) 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) rspObj.GetOrCreateAward().AddItem(constant.VIRTUAL_ITEM_SCORE, score)
totalaward := rspObj.GetOrCreateAward() totalaward := rspObj.GetOrCreateAward()

View File

@ -5,6 +5,7 @@ import (
"f5" "f5"
"main/constant" "main/constant"
"q5" "q5"
"strings"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -27,6 +28,8 @@ type User struct {
SpecDice int32 `gorm:"column:spec_dice"` SpecDice int32 `gorm:"column:spec_dice"`
LastPresentDiceTime int32 `gorm:"column:last_present_dice_time"` LastPresentDiceTime int32 `gorm:"column:last_present_dice_time"`
CurrGrid int32 `gorm:"column:curr_grid"` CurrGrid int32 `gorm:"column:curr_grid"`
AwardGrids string `gorm:"column:award_grids"`
AwardGridsList []int32
CreateTime int32 `gorm:"column:createtime;<-:create"` CreateTime int32 `gorm:"column:createtime;<-:create"`
ModifyTime int32 `gorm:"column:modifytime"` ModifyTime int32 `gorm:"column:modifytime"`
} }
@ -64,6 +67,11 @@ func (this *User) Find(accountId string, nowTime int64) (error, bool) {
return err, false 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 return nil, result.RowsAffected > 0
} }
@ -158,3 +166,25 @@ func (this *User) AddScore(score int32) error {
func (this *User) UpdateName() error { func (this *User) UpdateName() error {
return this.UpdateFields([]string{"nickname"}) 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
}

View File

@ -1,9 +1,9 @@
package mt package mt
import ( import (
"q5"
"f5" "f5"
"main/mtb" "main/mtb"
"q5"
"strings" "strings"
) )
@ -19,6 +19,7 @@ type MapGrid struct {
type MapGridTable struct { type MapGridTable struct {
f5.IdMetaTable[MapGrid] f5.IdMetaTable[MapGrid]
awardGrids []*MapGrid
maxGridId int32 maxGridId int32
} }
@ -27,7 +28,7 @@ func (this *MapGrid) Init1() {
return return
} }
tmpStrs := strings.Split(this.MapGrid.GetReward(), "|") tmpStrs := strings.Split(this.MapGrid.GetReward(), "|")
for _, tmpStr := range(tmpStrs) { for _, tmpStr := range tmpStrs {
tmpStrs2 := strings.Split(tmpStr, ":") tmpStrs2 := strings.Split(tmpStr, ":")
p := new(MapGridRewardItem) p := new(MapGridRewardItem)
p.ItemId = q5.ToInt32(tmpStrs2[0]) p.ItemId = q5.ToInt32(tmpStrs2[0])
@ -45,6 +46,9 @@ func (this *MapGridTable) PostInit1() {
if gridMeta.GetId() > this.maxGridId { if gridMeta.GetId() > this.maxGridId {
this.maxGridId = gridMeta.GetId() this.maxGridId = gridMeta.GetId()
} }
if len(gridMeta.rewardItems) > 0 {
this.awardGrids = append(this.awardGrids, gridMeta)
}
return true return true
}) })
} }
@ -52,3 +56,12 @@ func (this *MapGridTable) PostInit1() {
func (this *MapGridTable) GetMaxGridId() int32 { func (this *MapGridTable) GetMaxGridId() int32 {
return this.maxGridId return this.maxGridId
} }
func (this *MapGridTable) GetAwardGridIdList() []int32 {
idlist := []int32{}
for _, item := range this.awardGrids {
idlist = append(idlist, item.GetId())
}
return idlist
}

View File

@ -14,6 +14,7 @@ type User struct {
SpecDice int32 `json:"spec_dice"` SpecDice int32 `json:"spec_dice"`
CurrGrid int32 `json:"curr_grid"` CurrGrid int32 `json:"curr_grid"`
LastPresentDiceTime int32 `json:"last_present_dice_time"` LastPresentDiceTime int32 `json:"last_present_dice_time"`
AwardGrids []int32 `json:"award_grids"`
} }
func (this *User) FromModel(m *model.User) { func (this *User) FromModel(m *model.User) {
@ -26,4 +27,5 @@ func (this *User) FromModel(m *model.User) {
this.SpecDice = m.SpecDice this.SpecDice = m.SpecDice
this.CurrGrid = m.CurrGrid this.CurrGrid = m.CurrGrid
this.LastPresentDiceTime = m.LastPresentDiceTime this.LastPresentDiceTime = m.LastPresentDiceTime
this.AwardGrids = m.AwardGridsList
} }