66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
logicplayer "blazing/logic/service/player"
|
|
"blazing/logic/service/user"
|
|
configservice "blazing/modules/config/service"
|
|
playerservice "blazing/modules/player/service"
|
|
"time"
|
|
)
|
|
|
|
// CDK 处理控制器请求。
|
|
func (h Controller) CDK(data *C2S_GET_GIFT_COMPLETE, player *logicplayer.Player) (result *user.S2C_GET_GIFT_COMPLETE, err errorcode.ErrorCode) {
|
|
result = &user.S2C_GET_GIFT_COMPLETE{}
|
|
|
|
cdkService := configservice.NewCdkService()
|
|
now := time.Now()
|
|
|
|
r := cdkService.Get(data.PassText)
|
|
if r == nil {
|
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeNotExists
|
|
}
|
|
if r.BindUserId != 0 && r.BindUserId != data.Head.UserID {
|
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeFrozen
|
|
}
|
|
if r.ValidEndTime.Compare(now) == -1 {
|
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeExpired
|
|
}
|
|
if !player.Service.Cdk.CanGet(uint32(r.ID)) {
|
|
return
|
|
}
|
|
if !cdkService.Set(data.PassText) {
|
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeGiftsGone
|
|
}
|
|
|
|
reward, grantErr := playerservice.NewCdkService(data.Head.UserID).GrantConfigReward(uint32(r.ID))
|
|
if grantErr != nil {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
|
|
result.Flag = 1
|
|
appendGift := func(giftID, count int64) {
|
|
if giftID == 0 || count <= 0 {
|
|
return
|
|
}
|
|
result.GiftList = append(result.GiftList, user.GiftInfo{GiftID: giftID, Count: count})
|
|
}
|
|
|
|
appendGift(1, reward.Coins)
|
|
appendGift(3, reward.ExpPool)
|
|
appendGift(5, reward.Gold)
|
|
appendGift(9, reward.EVPool)
|
|
for _, item := range reward.Items {
|
|
appendGift(item.ItemId, item.ItemCnt)
|
|
}
|
|
for _, pet := range reward.Pets {
|
|
result.PetGift = append(result.PetGift, user.PetGiftInfo{PetID: pet.PetID, CacthTime: pet.CatchTime})
|
|
}
|
|
if len(reward.TitleIDs) > 0 {
|
|
result.Tile = reward.TitleIDs[0]
|
|
}
|
|
|
|
player.Service.Cdk.Log(uint32(r.ID))
|
|
return
|
|
}
|