Commit 85969f50 authored by hujiebin's avatar hujiebin

feat:势力经验值

parent 34116196
package groupPower_e
type GroupPowerGrade int
const (
GroupPowerGrade0 GroupPowerGrade = 0
GroupPowerGrade1 GroupPowerGrade = 1
GroupPowerGrade2 GroupPowerGrade = 2
GroupPowerGrade3 GroupPowerGrade = 3
GroupPowerGrade4 GroupPowerGrade = 4
GroupPowerGradeMax = GroupPowerGrade4
)
var (
GroupPowerGradeExp = map[GroupPowerGrade]int64{
GroupPowerGrade1: 2500000,
GroupPowerGrade2: 15000000,
GroupPowerGrade3: 45000000, // todo
GroupPowerGrade4: 60000000,
}
)
package groupPower_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"hilo-group/_const/enum/groupPower_e"
"time"
)
type GroupPowerExp struct {
Date string
GroupPowerId mysql.ID
Exp int64
CreatedTime time.Time `gorm:"->"`
UpdatedTime time.Time `gorm:"->"`
}
type GroupPowerGrade struct {
GroupPowerId mysql.ID
Exp int64
Grade groupPower_e.GroupPowerGrade
ExpiredAt time.Time
CreatedTime time.Time `gorm:"->"`
UpdatedTime time.Time `gorm:"->"`
}
// 增加家族经验
// 达到经验值之后升级
// 单进程同步执行,不考虑并发
func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp int64) error {
var err error
defer func() {
if err != nil {
txModel.Log.Errorf("IncrGroupPowerExp fail,id:%v,exp:%v,err:%v", groupPowerId, exp, err)
}
}()
// 增加家族经验-天
date := time.Now().Format("2006-01-02")
gpe := &GroupPowerExp{
Date: date,
GroupPowerId: groupPowerId,
Exp: exp,
}
if err = txModel.DB().Model(GroupPowerExp{}).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "date"}, {Name: "group_power_id"}},
DoUpdates: clause.Assignments(map[string]interface{}{
"exp": gorm.Expr("exp + ?", gpe.Exp)})}).Create(gpe).Error; err != nil {
return err
}
// 增加家族经验-总
gpg := &GroupPowerGrade{
GroupPowerId: groupPowerId,
Exp: exp,
Grade: 0,
ExpiredAt: time.Time{},
}
if err = txModel.DB().Model(GroupPowerGrade{}).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "group_power_id"}},
DoUpdates: clause.Assignments(map[string]interface{}{
"exp": gorm.Expr("exp + ?", gpg.Exp)})}).Create(gpg).Error; err != nil {
return err
}
// 达到经验值之后升级
latestGrade := new(GroupPowerGrade)
if err = txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(latestGrade).Error; err != nil {
return err
}
for grade := groupPower_e.GroupPowerGradeMax; grade >= groupPower_e.GroupPowerGrade0; grade-- {
if latestGrade.Exp > groupPower_e.GroupPowerGradeExp[grade] {
if latestGrade.Grade != grade {
if err = txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", latestGrade.GroupPowerId).UpdateColumn("grade", grade).Error; err != nil {
return err
}
}
break
}
}
return nil
}
...@@ -397,14 +397,23 @@ func FlushHiloInfo(extId string, isVip bool, isPrettyCode bool, medals []uint32, ...@@ -397,14 +397,23 @@ func FlushHiloInfo(extId string, isVip bool, isPrettyCode bool, medals []uint32,
} }
func SendGift() { func SendGift() {
// 送礼事件-火箭 // 送礼事件-势力经验
gift_ev.AddSendGiftEventAsync(func(model *domain.Model, event interface{}) error { gift_ev.AddSendGiftEventSync(func(model *domain.Model, event interface{}) error {
sendGiftEvent, ok := event.(*gift_ev.SendGiftEvent) sendGiftEvent, ok := event.(*gift_ev.SendGiftEvent)
if !ok { if !ok {
model.Log.Errorf("AddSendGiftEventAsync event type err") model.Log.Errorf("AddSendGiftEventAsync event type err")
return nil return nil
} }
model.Log.Infof("AddSendGiftEventAsync %+v", sendGiftEvent) model.Log.Infof("AddSendGiftEventAsync %+v", sendGiftEvent)
exist, groupPowerId, err := groupPower_m.CheckGroupPowerUser(model, sendGiftEvent.SendUserId)
if err != nil {
model.Log.Infof("CheckGroupPowerUser fail %+v", err)
return err
}
if exist {
exp := int64(sendGiftEvent.GiftN) * int64(len(sendGiftEvent.ReceiveUserIds)) * int64(sendGiftEvent.ResGift.DiamondNum)
return groupPower_m.IncrGroupPowerExp(model, groupPowerId, exp)
}
return nil return nil
}) })
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment