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")
|
f5.RspErr(c, 500, "server internal error7")
|
||||||
return
|
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)
|
rspObj.GetOrCreateAward().AddItem(constant.VIRTUAL_ITEM_SCORE, score)
|
||||||
|
|
||||||
totalaward := rspObj.GetOrCreateAward()
|
totalaward := rspObj.GetOrCreateAward()
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"f5"
|
"f5"
|
||||||
"main/constant"
|
"main/constant"
|
||||||
"q5"
|
"q5"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@ -27,8 +28,10 @@ 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"`
|
||||||
CreateTime int32 `gorm:"column:createtime;<-:create"`
|
AwardGrids string `gorm:"column:award_grids"`
|
||||||
ModifyTime int32 `gorm:"column:modifytime"`
|
AwardGridsList []int32
|
||||||
|
CreateTime int32 `gorm:"column:createtime;<-:create"`
|
||||||
|
ModifyTime int32 `gorm:"column:modifytime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *User) TableName() string {
|
func (this *User) TableName() string {
|
||||||
@ -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
|
||||||
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package mt
|
package mt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"q5"
|
|
||||||
"f5"
|
"f5"
|
||||||
"main/mtb"
|
"main/mtb"
|
||||||
|
"q5"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MapGridRewardItem struct {
|
type MapGridRewardItem struct {
|
||||||
ItemId int32
|
ItemId int32
|
||||||
ItemNum int32
|
ItemNum int32
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +19,8 @@ type MapGrid struct {
|
|||||||
|
|
||||||
type MapGridTable struct {
|
type MapGridTable struct {
|
||||||
f5.IdMetaTable[MapGrid]
|
f5.IdMetaTable[MapGrid]
|
||||||
maxGridId int32
|
awardGrids []*MapGrid
|
||||||
|
maxGridId int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MapGrid) Init1() {
|
func (this *MapGrid) Init1() {
|
||||||
@ -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])
|
||||||
@ -41,10 +42,13 @@ func (this *MapGrid) GetRewardItems() *[]*MapGridRewardItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *MapGridTable) PostInit1() {
|
func (this *MapGridTable) PostInit1() {
|
||||||
this.Traverse(func (gridMeta *MapGrid) bool {
|
this.Traverse(func(gridMeta *MapGrid) bool {
|
||||||
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
|
||||||
|
}
|
||||||
|
@ -5,15 +5,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
AccountId string `json:"account_id"`
|
AccountId string `json:"account_id"`
|
||||||
NickName string `json:"nickname"`
|
NickName string `json:"nickname"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
Score int64 `json:"score"`
|
Score int64 `json:"score"`
|
||||||
HourlyEarnings string `json:"hourly_earnings"`
|
HourlyEarnings string `json:"hourly_earnings"`
|
||||||
Dice int32 `json:"dice"`
|
Dice int32 `json:"dice"`
|
||||||
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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user