feat(game): 实现扭蛋系统批量物品添加功能并优化地图逻辑 - 新增ItemAddBatch方法用于批量添加物品,支持普通道具和特殊道具的分别处理 - 优化扭蛋游戏玩法中的物品添加逻辑,使用新的批量接口提升性能 - 在扭蛋机器人命令中实现完整的物品检查和批量添加流程 refactor(map): 重构地图控制器代码结构并添加注释 - 为EnterMap、LeaveMap、GetMapPlayerList等方法添加中文注释 - 统一地图相关的命名规范,如enter
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package robot
|
||||
|
||||
import (
|
||||
"blazing/common/data"
|
||||
"blazing/common/data/xmlres"
|
||||
base "blazing/modules/base/service"
|
||||
config "blazing/modules/config/service"
|
||||
dictservice "blazing/modules/dict/service"
|
||||
"blazing/modules/player/model"
|
||||
"blazing/modules/player/service"
|
||||
"strings"
|
||||
@@ -17,51 +19,129 @@ import (
|
||||
func init() {
|
||||
zero.OnCommand("扭蛋").
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
|
||||
msgs := strings.Fields(ctx.Event.Message.String())
|
||||
|
||||
if len(msgs) > 1 {
|
||||
|
||||
count := gconv.Int(msgs[1])
|
||||
if count > 10 {
|
||||
count = 10
|
||||
}
|
||||
user := base.NewBaseSysUserService().GetQQ(ctx.Event.Sender.ID)
|
||||
if user == nil {
|
||||
ctx.Send("未绑定,请个人中心复制token发给机器人")
|
||||
return
|
||||
}
|
||||
itemservice := service.NewItemService(uint32(user.ID))
|
||||
havs := itemservice.CheakItem(400501)
|
||||
if havs < int64(count) {
|
||||
ctx.Send("扭蛋币不足,当前扭蛋币数量:" + gconv.String(havs))
|
||||
return
|
||||
}
|
||||
var buf strings.Builder
|
||||
buf.WriteString("当前扭蛋币数量:" + gconv.String(havs) + "\n")
|
||||
if grand.Meet(int(count), 100) {
|
||||
r := config.NewPetRewardService().GetEgg()
|
||||
newPet := model.GenPetInfo(int(r.MonID), int(r.DV), int(r.Nature), int(r.Effect), int(r.Lv), nil, 0)
|
||||
if grand.Meet(1, 500) {
|
||||
newPet.RandomByWeightShiny()
|
||||
}
|
||||
service.NewPetService(uint32(user.ID)).PetAdd(newPet, 0)
|
||||
buf.WriteString("恭喜你获得" + xmlres.PetMAP[int(newPet.ID)].DefName + "\n")
|
||||
|
||||
}
|
||||
|
||||
items := config.NewItemService().GetEgg(int(count))
|
||||
|
||||
for _, item := range items {
|
||||
|
||||
itemservice.UPDATE(uint32(item.ItemId), int(item.ItemCnt))
|
||||
buf.WriteString("恭喜你获得" + xmlres.ItemsMAP[int(item.ItemId)].Name + ":" + gconv.String(item.ItemCnt) + "\n")
|
||||
}
|
||||
|
||||
itemservice.UPDATE(400501, int(-count))
|
||||
|
||||
ctx.SendChain(message.At(ctx.Event.Sender.ID), message.Reply(ctx.Event.MessageID), message.Text(buf.String()))
|
||||
if len(msgs) <= 1 {
|
||||
return
|
||||
}
|
||||
|
||||
count := gconv.Int(msgs[1])
|
||||
if count > 10 {
|
||||
count = 10
|
||||
}
|
||||
if count <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
user := base.NewBaseSysUserService().GetQQ(ctx.Event.Sender.ID)
|
||||
if user == nil {
|
||||
ctx.Send("未绑定,请先在个人中心绑定 token")
|
||||
return
|
||||
}
|
||||
|
||||
userID := uint32(user.ID)
|
||||
itemService := service.NewItemService(userID)
|
||||
infoService := service.NewInfoService(userID)
|
||||
playerInfo := infoService.GetLogin()
|
||||
if playerInfo == nil {
|
||||
ctx.Send("未创建角色,请先登录游戏")
|
||||
return
|
||||
}
|
||||
|
||||
havs := itemService.CheakItem(400501)
|
||||
if havs < int64(count) {
|
||||
ctx.Send("扭蛋币不足,当前扭蛋币数量:" + gconv.String(havs))
|
||||
return
|
||||
}
|
||||
|
||||
var buf strings.Builder
|
||||
buf.WriteString("当前扭蛋币数量:" + gconv.String(havs) + "\n")
|
||||
|
||||
if grand.Meet(count, 100) {
|
||||
r := config.NewPetRewardService().GetEgg()
|
||||
newPet := model.GenPetInfo(int(r.MonID), int(r.DV), int(r.Nature), int(r.Effect), int(r.Lv), nil, 0)
|
||||
if grand.Meet(1, 500) {
|
||||
newPet.RandomByWeightShiny()
|
||||
}
|
||||
service.NewPetService(userID).PetAdd(newPet, 0)
|
||||
buf.WriteString("恭喜你获得 " + xmlres.PetMAP[int(newPet.ID)].DefName + "\n")
|
||||
}
|
||||
|
||||
items := config.NewItemService().GetEgg(count)
|
||||
regularItems := make([]data.ItemInfo, 0, len(items))
|
||||
itemIDs := make([]uint32, 0, len(items))
|
||||
seenIDs := make(map[uint32]struct{}, len(items))
|
||||
infoDirty := false
|
||||
|
||||
for _, item := range items {
|
||||
switch item.ItemId {
|
||||
case 1:
|
||||
playerInfo.Coins += item.ItemCnt
|
||||
infoDirty = true
|
||||
buf.WriteString("恭喜你获得 " + xmlres.ItemsMAP[int(item.ItemId)].Name + ":" + gconv.String(item.ItemCnt) + "\n")
|
||||
case 3:
|
||||
playerInfo.ExpPool += item.ItemCnt
|
||||
infoDirty = true
|
||||
buf.WriteString("恭喜你获得 " + xmlres.ItemsMAP[int(item.ItemId)].Name + ":" + gconv.String(item.ItemCnt) + "\n")
|
||||
case 5:
|
||||
base.NewBaseSysUserService().UpdateGold(userID, item.ItemCnt*100)
|
||||
buf.WriteString("恭喜你获得 " + xmlres.ItemsMAP[int(item.ItemId)].Name + ":" + gconv.String(item.ItemCnt) + "\n")
|
||||
case 9:
|
||||
playerInfo.EVPool += item.ItemCnt
|
||||
infoDirty = true
|
||||
buf.WriteString("恭喜你获得 " + xmlres.ItemsMAP[int(item.ItemId)].Name + ":" + gconv.String(item.ItemCnt) + "\n")
|
||||
default:
|
||||
regularItems = append(regularItems, item)
|
||||
|
||||
itemID := uint32(item.ItemId)
|
||||
if _, ok := seenIDs[itemID]; ok {
|
||||
continue
|
||||
}
|
||||
seenIDs[itemID] = struct{}{}
|
||||
itemIDs = append(itemIDs, itemID)
|
||||
}
|
||||
}
|
||||
|
||||
if infoDirty {
|
||||
infoService.Save(*playerInfo)
|
||||
}
|
||||
|
||||
currentItems := itemService.CheakItemM(itemIDs...)
|
||||
currentMap := make(map[uint32]int64, len(currentItems))
|
||||
for _, item := range currentItems {
|
||||
currentMap[item.ItemId] = item.ItemCnt
|
||||
}
|
||||
maxMap := dictservice.NewDictInfoService().GetMaxMap(itemIDs...)
|
||||
|
||||
addableItems := make([]data.ItemInfo, 0, len(regularItems))
|
||||
pendingMap := make(map[uint32]int64, len(itemIDs))
|
||||
for _, item := range regularItems {
|
||||
itemID := uint32(item.ItemId)
|
||||
itemMax := maxMap[itemID]
|
||||
if itemMax == 0 {
|
||||
buf.WriteString("未发放奖励:物品不存在 " + gconv.String(item.ItemId) + "\n")
|
||||
continue
|
||||
}
|
||||
|
||||
if currentMap[itemID]+pendingMap[itemID]+item.ItemCnt > int64(itemMax) {
|
||||
buf.WriteString("未发放奖励:" + xmlres.ItemsMAP[int(item.ItemId)].Name + " 超出最大持有数量\n")
|
||||
continue
|
||||
}
|
||||
|
||||
pendingMap[itemID] += item.ItemCnt
|
||||
addableItems = append(addableItems, item)
|
||||
}
|
||||
|
||||
addedItems, err := itemService.AddItemsChecked(addableItems, currentMap)
|
||||
if err != nil {
|
||||
ctx.Send("扭蛋失败,请稍后再试")
|
||||
return
|
||||
}
|
||||
for _, item := range addedItems {
|
||||
buf.WriteString("恭喜你获得 " + xmlres.ItemsMAP[int(item.ItemId)].Name + ":" + gconv.String(item.ItemCnt) + "\n")
|
||||
}
|
||||
|
||||
itemService.UPDATE(400501, -count)
|
||||
|
||||
ctx.SendChain(message.At(ctx.Event.Sender.ID), message.Reply(ctx.Event.MessageID), message.Text(buf.String()))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user