Compare commits
26 Commits
62d93f65e7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de6c700bb3 | ||
|
|
3232efd05a | ||
|
|
0c79fee8af | ||
|
|
3d77e146e9 | ||
|
|
a43a25c610 | ||
|
|
3cfde577eb | ||
|
|
85f9c02ced | ||
|
|
9f7fd83626 | ||
|
|
ee8b0a2182 | ||
|
|
6e95e014fa | ||
|
|
61a135b3a7 | ||
|
|
5a81534e84 | ||
|
|
523d835ac0 | ||
|
|
5a7e20efec | ||
|
|
5f47bf0589 | ||
|
|
a58ef20fab | ||
|
|
3999f34f77 | ||
|
|
6f51a2e349 | ||
|
|
de755f8fd0 | ||
|
|
803aa71771 | ||
|
|
4a77066d08 | ||
|
|
c9b5f8569f | ||
|
|
ddbfe91d8b | ||
|
|
74ac6ce940 | ||
|
|
43b0bc2dec | ||
|
|
b953e7831a |
@@ -18,11 +18,11 @@ ENV GOMODCACHE=/workspace/.cache/gomod
|
||||
# ==========================================
|
||||
# 2. Codex 配置 (更换时修改这里,重新 build)
|
||||
# ==========================================
|
||||
ENV CODEX_BASE_URL="http://fast.jnm.lol/v1"
|
||||
ENV CODEX_BASE_URL="https://api.jucode.cn/v1"
|
||||
|
||||
ENV CODEX_MODEL="gpt-5.4"
|
||||
|
||||
ENV OPENAI_API_KEY="pk_live_d15iVqaSMxD_XLHh0nrFPJ_fzFZy8IfR4Cd62bERl8g"
|
||||
ENV OPENAI_API_KEY="sk-E0ZZIFNnD0RkhMC9pT2AGMutz9vNy2VLNrgyyobT5voa81pQ"
|
||||
|
||||
# ==========================================
|
||||
# 3. 安装系统依赖、Golang、Code-server
|
||||
|
||||
@@ -3,6 +3,7 @@ package cool
|
||||
import (
|
||||
_ "blazing/contrib/drivers/pgsql"
|
||||
"blazing/cool/cooldb"
|
||||
"sync"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -10,6 +11,11 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
autoMigrateMu sync.Mutex
|
||||
autoMigrateModels []IModel
|
||||
)
|
||||
|
||||
// 初始化数据库连接供gorm使用
|
||||
func InitDB(group string) (*gorm.DB, error) {
|
||||
// var ctx context.Context
|
||||
@@ -54,9 +60,33 @@ func getDBbyModel(model IModel) *gorm.DB {
|
||||
|
||||
// 根据entity结构体创建表
|
||||
func CreateTable(model IModel) error {
|
||||
if Config.AutoMigrate {
|
||||
autoMigrateMu.Lock()
|
||||
autoMigrateModels = append(autoMigrateModels, model)
|
||||
autoMigrateMu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunAutoMigrate 显式执行已注册模型的建表/迁移。
|
||||
func RunAutoMigrate() error {
|
||||
if !Config.AutoMigrate {
|
||||
return nil
|
||||
}
|
||||
autoMigrateMu.Lock()
|
||||
models := append([]IModel(nil), autoMigrateModels...)
|
||||
autoMigrateMu.Unlock()
|
||||
|
||||
seen := make(map[string]struct{}, len(models))
|
||||
for _, model := range models {
|
||||
key := model.GroupName() + ":" + model.TableName()
|
||||
if _, ok := seen[key]; ok {
|
||||
continue
|
||||
}
|
||||
seen[key] = struct{}{}
|
||||
|
||||
db := getDBbyModel(model)
|
||||
return db.AutoMigrate(model)
|
||||
if err := db.AutoMigrate(model); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -121,7 +121,23 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
|
||||
}
|
||||
}()
|
||||
|
||||
ws := c.Context().(*player.ClientData).Wsmsg
|
||||
client := c.Context().(*player.ClientData)
|
||||
if s.discorse && !client.IsCrossDomainChecked() {
|
||||
handled, ready, action := handle(c)
|
||||
if action != gnet.None {
|
||||
return action
|
||||
}
|
||||
if handled {
|
||||
client.MarkCrossDomainChecked()
|
||||
return gnet.None
|
||||
}
|
||||
if !ready {
|
||||
return gnet.None
|
||||
}
|
||||
client.MarkCrossDomainChecked()
|
||||
}
|
||||
|
||||
ws := client.Wsmsg
|
||||
if ws.Tcp {
|
||||
return s.handleTCP(c)
|
||||
}
|
||||
|
||||
@@ -82,7 +82,9 @@ func (h Controller) DASHIbeiR(req *C2s_MASTER_REWARDSR, c *player.Player) (resul
|
||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrAwardAlreadyClaimed)
|
||||
}
|
||||
|
||||
consumeMasterCupItems(c, requiredItems)
|
||||
if err := consumeMasterCupItems(c, requiredItems); err != nil {
|
||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrInsufficientItems)
|
||||
}
|
||||
progress.Set(uint(req.ElementType))
|
||||
taskData.Data = progress.Bytes()
|
||||
if taskErr = c.Service.Task.SetTask(taskData); taskErr != nil {
|
||||
@@ -130,10 +132,13 @@ func hasEnoughMasterCupItems(c *player.Player, requiredItems []ItemS) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func consumeMasterCupItems(c *player.Player, requiredItems []ItemS) {
|
||||
func consumeMasterCupItems(c *player.Player, requiredItems []ItemS) error {
|
||||
for _, item := range requiredItems {
|
||||
c.Service.Item.UPDATE(item.ItemId, -int(item.ItemCnt))
|
||||
if err := c.Service.Item.UPDATE(item.ItemId, -int(item.ItemCnt)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func appendMasterCupRewardItems(c *player.Player, result *S2C_MASTER_REWARDSR, itemList []data.ItemInfo) {
|
||||
|
||||
@@ -26,12 +26,11 @@ func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (res
|
||||
if data1.EggNum > 10 || data1.EggNum <= 0 {
|
||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
|
||||
}
|
||||
if r < 0 {
|
||||
if r <= 0 || data1.EggNum > r {
|
||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
||||
}
|
||||
if data1.EggNum > r {
|
||||
if err := c.Service.Item.UPDATE(400501, int(-data1.EggNum)); err != nil {
|
||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
||||
|
||||
}
|
||||
result = &S2C_EGG_GAME_PLAY{ListInfo: []data.ItemInfo{}}
|
||||
if grand.Meet(int(data1.EggNum), 100) {
|
||||
@@ -52,8 +51,6 @@ func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (res
|
||||
for _, item := range addedItems {
|
||||
result.ListInfo = append(result.ListInfo, data.ItemInfo{ItemId: item.ItemId, ItemCnt: item.ItemCnt})
|
||||
}
|
||||
|
||||
c.Service.Item.UPDATE(400501, int(-data1.EggNum))
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ func (h Controller) GET_XUANCAI(data *C2s_GET_XUANCAI, c *player.Player) (result
|
||||
|
||||
// 检查该位是否未被选中(避免重复)
|
||||
if (result.Status & mask) == 0 {
|
||||
result.Status |= mask
|
||||
itemID := uint32(400686 + randBitIdx + 1)
|
||||
selectedItems = append(selectedItems, itemID)
|
||||
itemMask[itemID] = mask
|
||||
|
||||
@@ -41,7 +41,6 @@ func (Controller) PlayerFightBoss(req *ChallengeBossInboundInfo, p *player.Playe
|
||||
if err != 0 {
|
||||
return nil, err
|
||||
}
|
||||
leadMonster := &monsterInfo.PetList[0]
|
||||
|
||||
p.Fightinfo.Status = fightinfo.BattleMode.FIGHT_WITH_NPC
|
||||
p.Fightinfo.Mode = resolveMapNodeFightMode(mapNode)
|
||||
@@ -53,7 +52,12 @@ func (Controller) PlayerFightBoss(req *ChallengeBossInboundInfo, p *player.Playe
|
||||
|
||||
var fightC *fight.FightC
|
||||
fightC, err = startMapBossFight(mapNode, p, ai, func(foi model.FightOverInfo) {
|
||||
handleMapBossFightRewards(p, fightC, foi, mapNode, bossConfigs[0], leadMonster)
|
||||
if mapNode.WinBonusID == 0 {
|
||||
return
|
||||
}
|
||||
if shouldGrantBossWinBonus(fightC, p.Info.UserID, bossConfigs[0], foi) {
|
||||
p.SptCompletedTask(mapNode.WinBonusID, 1)
|
||||
}
|
||||
})
|
||||
if err != 0 {
|
||||
return nil, err
|
||||
@@ -68,7 +72,7 @@ func startMapBossFight(
|
||||
ai *player.AI_player,
|
||||
fn func(model.FightOverInfo),
|
||||
) (*fight.FightC, errorcode.ErrorCode) {
|
||||
ourPets := p.GetPetInfo(100)
|
||||
ourPets := p.GetPetInfo(p.CurrentMapPetLevelLimit())
|
||||
oppPets := ai.GetPetInfo(0)
|
||||
if mapNode != nil && mapNode.IsGroupBoss != 0 {
|
||||
if len(ourPets) > 0 && len(oppPets) > 0 {
|
||||
@@ -94,8 +98,8 @@ func (Controller) OnPlayerFightNpcMonster(req *FightNpcMonsterInboundInfo, p *pl
|
||||
if err = p.CanFight(); err != 0 {
|
||||
return nil, err
|
||||
}
|
||||
if req.Number > 9 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
if int(req.Number) >= len(p.Data) {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotHere
|
||||
}
|
||||
|
||||
refPet := p.Data[req.Number]
|
||||
@@ -110,7 +114,7 @@ func (Controller) OnPlayerFightNpcMonster(req *FightNpcMonsterInboundInfo, p *pl
|
||||
p.Fightinfo.Status = fightinfo.BattleMode.FIGHT_WITH_NPC
|
||||
p.Fightinfo.Mode = fightinfo.BattleMode.MULTI_MODE
|
||||
|
||||
_, err = fight.NewFight(p, ai, p.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
||||
_, err = fight.NewFight(p, ai, p.GetPetInfo(p.CurrentMapPetLevelLimit()), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
||||
handleNpcFightRewards(p, foi, monster)
|
||||
})
|
||||
if err != 0 {
|
||||
@@ -230,98 +234,9 @@ func shouldGrantBossWinBonus(fightC *fight.FightC, playerID uint32, bossConfig c
|
||||
return true
|
||||
}
|
||||
|
||||
func handleMapBossFightRewards(
|
||||
p *player.Player,
|
||||
fightC *fight.FightC,
|
||||
foi model.FightOverInfo,
|
||||
mapNode *configmodel.MapNode,
|
||||
bossConfig configmodel.BossConfig,
|
||||
leadMonster *model.PetInfo,
|
||||
) {
|
||||
rewards := grantMonsterFightRewards(p, foi, leadMonster)
|
||||
if mapNode != nil && mapNode.WinBonusID != 0 && shouldGrantBossWinBonus(fightC, p.Info.UserID, bossConfig, foi) {
|
||||
appendBossTaskReward(p, mapNode.WinBonusID, 1, rewards)
|
||||
}
|
||||
if rewards != nil && rewards.HasReward() {
|
||||
p.SendPackCmd(8004, rewards)
|
||||
}
|
||||
}
|
||||
|
||||
func grantMonsterFightRewards(p *player.Player, foi model.FightOverInfo, monster *model.PetInfo) *fightinfo.S2C_GET_BOSS_MONSTER {
|
||||
rewards := &fightinfo.S2C_GET_BOSS_MONSTER{}
|
||||
if p == nil || monster == nil || foi.Reason != 0 || foi.WinnerId != p.Info.UserID || !p.CanGet() {
|
||||
return rewards
|
||||
}
|
||||
|
||||
petCfg, ok := xmlres.PetMAP[int(monster.ID)]
|
||||
if !ok {
|
||||
return rewards
|
||||
}
|
||||
|
||||
exp := uint32(petCfg.YieldingExp) * monster.Level / 7
|
||||
addlevel, poolevel := p.CanGetExp()
|
||||
addexp := gconv.Float32(addlevel * gconv.Float32(exp))
|
||||
poolexp := gconv.Float32(poolevel) * gconv.Float32(exp)
|
||||
|
||||
p.ItemAdd(3, int64(poolexp+addexp))
|
||||
rewards.AddItem(rewardItemExpPool, uint32(poolexp))
|
||||
p.AddPetExp(foi.Winpet, int64(addexp))
|
||||
|
||||
if p.CanGetItem() {
|
||||
itemID := p.GetSpace().GetDrop()
|
||||
if itemID != 0 {
|
||||
count := uint32(grand.N(1, 2))
|
||||
if p.ItemAdd(itemID, int64(count)) {
|
||||
rewards.AddItem(uint32(itemID), count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
petType := int64(petCfg.Type)
|
||||
if monster.IsShiny() && p.CanGetXUAN() && petType < 16 {
|
||||
xuanID := uint32(400686 + petType)
|
||||
count := uint32(grand.N(1, 2))
|
||||
if p.ItemAdd(int64(xuanID), int64(count)) {
|
||||
rewards.AddItem(xuanID, count)
|
||||
}
|
||||
}
|
||||
|
||||
if foi.Winpet != nil {
|
||||
foi.Winpet.AddEV(petCfg.YieldingEVValues)
|
||||
}
|
||||
return rewards
|
||||
}
|
||||
|
||||
func appendBossTaskReward(p *player.Player, taskID int, outState int, rewards *fightinfo.S2C_GET_BOSS_MONSTER) {
|
||||
if p == nil || rewards == nil || !p.IsLogin || taskID <= 0 {
|
||||
return
|
||||
}
|
||||
if p.Info.GetTask(taskID) == model.Completed {
|
||||
return
|
||||
}
|
||||
|
||||
granted, err := p.ApplyTaskCompletion(uint32(taskID), outState, nil)
|
||||
if err != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
p.Info.SetTask(taskID, model.Completed)
|
||||
rewards.BonusID = uint32(taskID)
|
||||
if granted == nil {
|
||||
return
|
||||
}
|
||||
if granted.Pet != nil {
|
||||
rewards.PetID = granted.Pet.ID
|
||||
rewards.CaptureTm = granted.Pet.CatchTime
|
||||
}
|
||||
for _, item := range granted.Items {
|
||||
rewards.AddItemInfo(item)
|
||||
}
|
||||
}
|
||||
|
||||
func buildNpcMonsterInfo(refPet player.OgrePetInfo, mapID uint32) (*model.PetInfo, *model.PlayerInfo, errorcode.ErrorCode) {
|
||||
if refPet.ID == 0 {
|
||||
return nil, nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
return nil, nil, errorcode.ErrorCodes.ErrPokemonNotHere
|
||||
}
|
||||
|
||||
monster := model.GenPetInfo(
|
||||
@@ -354,8 +269,46 @@ func buildNpcMonsterInfo(refPet player.OgrePetInfo, mapID uint32) (*model.PetInf
|
||||
}
|
||||
|
||||
func handleNpcFightRewards(p *player.Player, foi model.FightOverInfo, monster *model.PetInfo) {
|
||||
rewards := grantMonsterFightRewards(p, foi, monster)
|
||||
if foi.Reason != 0 || foi.WinnerId != p.Info.UserID || !p.CanGet() {
|
||||
return
|
||||
}
|
||||
|
||||
petCfg, ok := xmlres.PetMAP[int(monster.ID)]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
exp := uint32(petCfg.YieldingExp) * monster.Level / 7
|
||||
addlevel, poolevel := p.CanGetExp()
|
||||
addexp := gconv.Float32(addlevel * gconv.Float32(exp))
|
||||
poolexp := gconv.Float32(poolevel) * gconv.Float32(exp)
|
||||
rewards := &fightinfo.S2C_GET_BOSS_MONSTER{}
|
||||
|
||||
p.ItemAdd(3, int64(poolexp+addexp))
|
||||
rewards.AddItem(rewardItemExpPool, uint32(poolexp))
|
||||
p.AddPetExp(foi.Winpet, int64(addexp))
|
||||
|
||||
if p.CanGetItem() {
|
||||
itemID := p.GetSpace().GetDrop()
|
||||
if itemID != 0 {
|
||||
count := uint32(grand.N(1, 2))
|
||||
if p.ItemAdd(itemID, int64(count)) {
|
||||
rewards.AddItem(uint32(itemID), count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
petType := int64(petCfg.Type)
|
||||
if monster.IsShiny() && p.CanGetXUAN() && petType < 16 {
|
||||
xuanID := uint32(400686 + petType)
|
||||
count := uint32(grand.N(1, 2))
|
||||
if p.ItemAdd(int64(xuanID), int64(count)) {
|
||||
rewards.AddItem(xuanID, count)
|
||||
}
|
||||
}
|
||||
|
||||
if rewards.HasReward() {
|
||||
p.SendPackCmd(8004, rewards)
|
||||
}
|
||||
foi.Winpet.AddEV(petCfg.YieldingEVValues)
|
||||
}
|
||||
|
||||
@@ -18,10 +18,13 @@ func (h Controller) ItemSale(data *C2S_ITEM_SALE, c *player.Player) (result *fig
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
if err := c.Service.Item.UPDATE(data.ItemId, -gconv.Int(data.Amount)); err != nil {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
|
||||
itemConfig := xmlres.ItemsMAP[int(data.ItemId)]
|
||||
if itemConfig.SellPrice != 0 {
|
||||
c.Info.Coins += int64(int64(data.Amount) * int64(itemConfig.SellPrice))
|
||||
}
|
||||
c.Service.Item.UPDATE(data.ItemId, -gconv.Int(data.Amount))
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
const (
|
||||
// ItemDefaultLeftTime 道具默认剩余时间(毫秒)
|
||||
ItemDefaultLeftTime = 360000
|
||||
// UniversalNatureItemID 全能性格转化剂Ω
|
||||
UniversalNatureItemID uint32 = 300136
|
||||
)
|
||||
|
||||
// GetUserItemList 获取用户道具列表
|
||||
@@ -33,11 +35,16 @@ func (h Controller) GetUserItemList(data *ItemListInboundInfo, c *player.Player)
|
||||
// c: 当前玩家对象
|
||||
// 返回: 使用后的宠物信息和错误码
|
||||
func (h Controller) UsePetItemOutOfFight(data *C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *player.Player) (result *item.S2C_USE_PET_ITEM_OUT_OF_FIGHT, err errorcode.ErrorCode) {
|
||||
_, currentPet, found := c.FindPet(data.CatchTime)
|
||||
slot, found := c.FindPetBagSlot(data.CatchTime)
|
||||
if !found {
|
||||
return nil, errorcode.ErrorCodes.Err10401
|
||||
}
|
||||
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if currentPet == nil {
|
||||
return nil, errorcode.ErrorCodes.Err10401
|
||||
}
|
||||
|
||||
itemID := uint32(data.ItemID)
|
||||
if c.Service.Item.CheakItem(itemID) == 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
@@ -51,7 +58,10 @@ func (h Controller) UsePetItemOutOfFight(data *C2S_USE_PET_ITEM_OUT_OF_FIGHT, c
|
||||
return nil, errcode
|
||||
}
|
||||
refreshPetPaneKeepHP(currentPet, oldHP)
|
||||
c.Service.Item.UPDATE(itemID, -1)
|
||||
if err := c.Service.Item.UPDATE(itemID, -1); err != nil {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
c.Service.Info.Save(*c.Info)
|
||||
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
|
||||
copier.Copy(&result, currentPet)
|
||||
return result, 0
|
||||
@@ -83,7 +93,10 @@ func (h Controller) UsePetItemOutOfFight(data *C2S_USE_PET_ITEM_OUT_OF_FIGHT, c
|
||||
return nil, errcode
|
||||
}
|
||||
|
||||
c.Service.Item.UPDATE(itemID, -1)
|
||||
if err := c.Service.Item.UPDATE(itemID, -1); err != nil {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
c.Service.Info.Save(*c.Info)
|
||||
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
|
||||
copier.Copy(&result, currentPet)
|
||||
return result, 0
|
||||
@@ -126,7 +139,9 @@ func (h Controller) handlexuancaiItem(currentPet *model.PetInfo, c *player.Playe
|
||||
return errorcode.ErrorCodes.ErrItemUnusable
|
||||
}
|
||||
|
||||
c.Service.Item.UPDATE(itemid, -100)
|
||||
if err := c.Service.Item.UPDATE(itemid, -100); err != nil {
|
||||
return errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -182,11 +197,24 @@ func (h Controller) handleRegularPetItem(itemID uint32, currentPet *model.PetInf
|
||||
// c: 当前玩家对象
|
||||
// 返回: 无数据和错误码
|
||||
func (h Controller) ResetNature(data *C2S_PET_RESET_NATURE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
_, currentPet, found := c.FindPet(data.CatchTime)
|
||||
slot, found := c.FindPetBagSlot(data.CatchTime)
|
||||
if !found {
|
||||
return nil, errorcode.ErrorCodes.Err10401
|
||||
}
|
||||
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if currentPet == nil {
|
||||
return nil, errorcode.ErrorCodes.Err10401
|
||||
}
|
||||
|
||||
if data.ItemId != UniversalNatureItemID {
|
||||
return nil, errorcode.ErrorCodes.ErrItemUnusable
|
||||
}
|
||||
|
||||
if _, ok := xmlres.NatureRootMap[int(data.Nature)]; !ok {
|
||||
return nil, errorcode.ErrorCodes.ErrItemUnusable
|
||||
}
|
||||
|
||||
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
@@ -194,7 +222,10 @@ func (h Controller) ResetNature(data *C2S_PET_RESET_NATURE, c *player.Player) (r
|
||||
currentHP := currentPet.Hp
|
||||
currentPet.Nature = data.Nature
|
||||
refreshPetPaneKeepHP(currentPet, currentHP)
|
||||
c.Service.Item.UPDATE(data.ItemId, -1)
|
||||
if err := c.Service.Item.UPDATE(data.ItemId, -1); err != nil {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
c.Service.Info.Save(*c.Info)
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -222,29 +253,38 @@ func (h Controller) UseSpeedupItem(data *C2S_USE_SPEEDUP_ITEM, c *player.Player)
|
||||
if c.Info.TwoTimes != 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||
}
|
||||
c.Info.TwoTimes += 50 // 玩家对象新增 TwoTimesExp 字段存储双倍剩余次数
|
||||
case 300067:
|
||||
if c.Info.TwoTimes != 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||
}
|
||||
c.Info.TwoTimes += 25 // 玩家对象新增 TwoTimesExp 字段存储双倍剩余次数
|
||||
case 300051: // 假设1002是三倍经验加速器道具ID
|
||||
if c.Info.ThreeTimes != 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||
}
|
||||
c.Info.ThreeTimes += 50 // 玩家对象新增 ThreeTimesExp 字段存储三倍剩余次数
|
||||
case 300115:
|
||||
if c.Info.ThreeTimes != 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||
}
|
||||
c.Info.ThreeTimes += 30 // 玩家对象新增 ThreeTimesExp 字段存储三倍剩余次数
|
||||
|
||||
default:
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError // 未知道具ID
|
||||
}
|
||||
|
||||
// 3. 扣减道具(数量-1)
|
||||
c.Service.Item.UPDATE(data.ItemID, -1)
|
||||
if err := c.Service.Item.UPDATE(data.ItemID, -1); err != nil {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
|
||||
switch data.ItemID {
|
||||
case 300027: // 假设1001是双倍经验加速器道具ID
|
||||
c.Info.TwoTimes += 50 // 玩家对象新增 TwoTimesExp 字段存储双倍剩余次数
|
||||
case 300067:
|
||||
c.Info.TwoTimes += 25 // 玩家对象新增 TwoTimesExp 字段存储双倍剩余次数
|
||||
case 300051: // 假设1002是三倍经验加速器道具ID
|
||||
c.Info.ThreeTimes += 50 // 玩家对象新增 ThreeTimesExp 字段存储三倍剩余次数
|
||||
case 300115:
|
||||
c.Info.ThreeTimes += 30 // 玩家对象新增 ThreeTimesExp 字段存储三倍剩余次数
|
||||
}
|
||||
result.ThreeTimes = uint32(c.Info.ThreeTimes) // 返回三倍经验剩余次数
|
||||
result.TwoTimes = uint32(c.Info.TwoTimes) // 返回双倍经验剩余次数
|
||||
|
||||
@@ -275,10 +315,11 @@ func (h Controller) UseEnergyXishou(data *C2S_USE_ENERGY_XISHOU, c *player.Playe
|
||||
}
|
||||
// 2. 核心业务逻辑:更新能量吸收器剩余次数
|
||||
// (注:可根据道具ID配置不同的次数加成,此处默认+1)
|
||||
if err := c.Service.Item.UPDATE(data.ItemID, -1); err != nil {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
c.Info.EnergyTime += 40 // 玩家对象新增 EnergyTimes 字段存储能量吸收剩余次数
|
||||
|
||||
// 3. 扣减道具(数量-1)
|
||||
c.Service.Item.UPDATE(data.ItemID, -1)
|
||||
result = &item.S2C_USE_ENERGY_XISHOU{
|
||||
EnergyTimes: uint32(c.Info.EnergyTime),
|
||||
}
|
||||
@@ -309,6 +350,9 @@ func (h Controller) UseAutoFightItem(data *C2S_USE_AUTO_FIGHT_ITEM, c *player.Pl
|
||||
if c.Info.AutoFightTime != 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||
}
|
||||
if err := c.Service.Item.UPDATE(data.ItemID, -1); err != nil {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
result = &item.S2C_USE_AUTO_FIGHT_ITEM{}
|
||||
// 2. 核心业务逻辑:开启自动战斗 + 更新剩余次数
|
||||
c.Info.AutoFight = 3 // 按需求设置自动战斗flag为3(需测试)
|
||||
@@ -324,8 +368,6 @@ func (h Controller) UseAutoFightItem(data *C2S_USE_AUTO_FIGHT_ITEM, c *player.Pl
|
||||
c.Info.AutoFightTime += 50
|
||||
}
|
||||
result.AutoFightTimes = c.Info.AutoFightTime
|
||||
// 3. 扣减道具(数量-1)
|
||||
c.Service.Item.UPDATE(data.ItemID, -1)
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
60
logic/controller/item_use_test.go
Normal file
60
logic/controller/item_use_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/logic/service/player"
|
||||
playermodel "blazing/modules/player/model"
|
||||
blservice "blazing/modules/player/service"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUsePetItemOutOfFightAppliesToBackupPetInMemory(t *testing.T) {
|
||||
petID := firstPetIDForControllerTest(t)
|
||||
backupPet := playermodel.GenPetInfo(petID, 31, 0, 0, 50, nil, 0)
|
||||
if backupPet == nil {
|
||||
t.Fatal("failed to generate backup pet")
|
||||
}
|
||||
if backupPet.MaxHp <= 1 {
|
||||
t.Fatalf("expected generated pet to have max hp > 1, got %d", backupPet.MaxHp)
|
||||
}
|
||||
backupPet.Hp = 1
|
||||
|
||||
testPlayer := player.NewPlayer(nil)
|
||||
testPlayer.Info = &playermodel.PlayerInfo{
|
||||
UserID: 1,
|
||||
PetList: []playermodel.PetInfo{},
|
||||
BackupPetList: []playermodel.PetInfo{*backupPet},
|
||||
}
|
||||
testPlayer.Service = blservice.NewUserService(testPlayer.Info.UserID)
|
||||
|
||||
itemID, recoverHP := firstRecoverHPItemForControllerTest(t)
|
||||
if recoverHP <= 0 {
|
||||
t.Fatalf("expected positive recover hp for item %d, got %d", itemID, recoverHP)
|
||||
}
|
||||
|
||||
_, err := (Controller{}).UsePetItemOutOfFight(&C2S_USE_PET_ITEM_OUT_OF_FIGHT{
|
||||
CatchTime: backupPet.CatchTime,
|
||||
ItemID: int32(itemID),
|
||||
}, testPlayer)
|
||||
if err != 0 {
|
||||
t.Fatalf("expected backup pet item use to succeed in-memory, got err=%d", err)
|
||||
}
|
||||
|
||||
updatedPet := testPlayer.Info.BackupPetList[0]
|
||||
if updatedPet.Hp <= 1 {
|
||||
t.Fatalf("expected backup pet hp to increase in memory, got hp=%d", updatedPet.Hp)
|
||||
}
|
||||
}
|
||||
|
||||
func firstRecoverHPItemForControllerTest(t *testing.T) (uint32, int) {
|
||||
t.Helper()
|
||||
|
||||
for id, cfg := range xmlres.ItemsMAP {
|
||||
if cfg.HP > 0 {
|
||||
return uint32(id), cfg.HP
|
||||
}
|
||||
}
|
||||
|
||||
t.Fatal("xmlres.ItemsMAP has no HP recovery item")
|
||||
return 0, 0
|
||||
}
|
||||
@@ -19,20 +19,13 @@ func (h Controller) SavePetBagOrder(
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
// PetRetrieveFromWarehouse 领回仓库精灵
|
||||
// PetRetrieveFromWarehouse 从放生仓库领回精灵
|
||||
func (h Controller) PetRetrieveFromWarehouse(
|
||||
data *PET_RETRIEVE, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if _, ok := player.FindPetBagSlot(data.CatchTime); ok {
|
||||
return nil, 0
|
||||
if !player.Service.Pet.UpdateFree(data.CatchTime, 1, 0) {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||
}
|
||||
|
||||
petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
||||
if petInfo == nil {
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
player.AddPetToAvailableBag(petInfo.Data)
|
||||
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,9 @@ func (h Controller) PetELV(data *C2S_PET_EVOLVTION, c *player.Player) (result *f
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItemsMulti
|
||||
}
|
||||
if branch.EvolvItem != 0 {
|
||||
c.Service.Item.UPDATE(uint32(branch.EvolvItem), -branch.EvolvItemCount)
|
||||
if err := c.Service.Item.UPDATE(uint32(branch.EvolvItem), -branch.EvolvItemCount); err != nil {
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItemsMulti
|
||||
}
|
||||
}
|
||||
|
||||
currentPet.ID = uint32(branch.MonTo)
|
||||
|
||||
@@ -17,11 +17,16 @@ const (
|
||||
// c: 当前玩家对象
|
||||
// 返回: 分配结果和错误码
|
||||
func (h Controller) PetEVDiy(data *PetEV, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
_, currentPet, found := c.FindPet(data.CacthTime)
|
||||
slot, found := c.FindPetBagSlot(data.CacthTime)
|
||||
if !found {
|
||||
return nil, errorcode.ErrorCodes.Err10401
|
||||
}
|
||||
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if currentPet == nil {
|
||||
return nil, errorcode.ErrorCodes.Err10401
|
||||
}
|
||||
|
||||
var targetTotal uint32
|
||||
var currentTotal uint32
|
||||
for i, evValue := range data.EVs {
|
||||
|
||||
45
logic/controller/pet_ev_test.go
Normal file
45
logic/controller/pet_ev_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"blazing/logic/service/player"
|
||||
playermodel "blazing/modules/player/model"
|
||||
)
|
||||
|
||||
func TestPetEVDiy_AppliesToBackupPet(t *testing.T) {
|
||||
p := player.NewPlayer(nil)
|
||||
p.Info = &playermodel.PlayerInfo{
|
||||
EVPool: 20,
|
||||
PetList: []playermodel.PetInfo{
|
||||
{CatchTime: 1},
|
||||
},
|
||||
BackupPetList: []playermodel.PetInfo{
|
||||
{
|
||||
CatchTime: 2,
|
||||
Level: 100,
|
||||
Ev: [6]uint32{0, 4, 0, 0, 0, 0},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
data := &PetEV{
|
||||
CacthTime: 2,
|
||||
EVs: [6]uint32{0, 8, 4, 0, 0, 0},
|
||||
}
|
||||
|
||||
_, err := (Controller{}).PetEVDiy(data, p)
|
||||
if err != 0 {
|
||||
t.Fatalf("PetEVDiy returned error: %v", err)
|
||||
}
|
||||
|
||||
got := p.Info.BackupPetList[0].Ev
|
||||
want := [6]uint32{0, 8, 4, 0, 0, 0}
|
||||
if got != want {
|
||||
t.Fatalf("backup pet EV mismatch, got %v want %v", got, want)
|
||||
}
|
||||
|
||||
if gotPool, wantPool := p.Info.EVPool, int64(12); gotPool != wantPool {
|
||||
t.Fatalf("EVPool mismatch, got %d want %d", gotPool, wantPool)
|
||||
}
|
||||
}
|
||||
@@ -65,16 +65,33 @@ func (h Controller) PetFusion(data *C2S_PetFusion, c *player.Player) (result *pe
|
||||
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
||||
}
|
||||
|
||||
consumeItems(c, materialCounts)
|
||||
c.Info.Coins -= petFusionCost
|
||||
|
||||
if resultPetID == 0 {
|
||||
if useOptionalItem(c, data.GoldItem1[:], petFusionFailureItemID) {
|
||||
result.CostItemFlag = 1
|
||||
} else if auxPet.Level > 5 {
|
||||
auxPet.Downgrade(auxPet.Level - 5)
|
||||
failedAux := *auxPet
|
||||
if auxPet.Level > 5 {
|
||||
failedAux.Downgrade(auxPet.Level - 5)
|
||||
} else {
|
||||
auxPet.Downgrade(1)
|
||||
failedAux.Downgrade(1)
|
||||
}
|
||||
txResult, errCode := c.Service.PetFusionTx(
|
||||
*c.Info,
|
||||
data.Mcatchtime,
|
||||
data.Auxcatchtime,
|
||||
materialCounts,
|
||||
data.GoldItem1[:],
|
||||
petFusionKeepAuxItemID,
|
||||
petFusionFailureItemID,
|
||||
petFusionCost,
|
||||
nil,
|
||||
&failedAux,
|
||||
)
|
||||
if errCode != 0 {
|
||||
return result, errCode
|
||||
}
|
||||
c.Info.Coins -= petFusionCost
|
||||
if txResult.CostItemUsed {
|
||||
result.CostItemFlag = 1
|
||||
} else if txResult.UpdatedAux != nil {
|
||||
*auxPet = *txResult.UpdatedAux
|
||||
}
|
||||
return &pet.PetFusionInfo{}, 0
|
||||
}
|
||||
@@ -101,18 +118,37 @@ func (h Controller) PetFusion(data *C2S_PetFusion, c *player.Player) (result *pe
|
||||
newPet.RandomByWeightShiny()
|
||||
}
|
||||
|
||||
c.Service.Pet.PetAdd(newPet, 0)
|
||||
//println(c.Info.UserID, "进行融合", len(c.Info.PetList), masterPet.ID, auxPet.ID, newPet.ID)
|
||||
|
||||
c.PetDel(data.Mcatchtime)
|
||||
if useOptionalItem(c, data.GoldItem1[:], petFusionKeepAuxItemID) {
|
||||
result.CostItemFlag = 1
|
||||
} else {
|
||||
c.PetDel(data.Auxcatchtime)
|
||||
txResult, errCode := c.Service.PetFusionTx(
|
||||
*c.Info,
|
||||
data.Mcatchtime,
|
||||
data.Auxcatchtime,
|
||||
materialCounts,
|
||||
data.GoldItem1[:],
|
||||
petFusionKeepAuxItemID,
|
||||
petFusionFailureItemID,
|
||||
petFusionCost,
|
||||
newPet,
|
||||
nil,
|
||||
)
|
||||
if errCode != 0 {
|
||||
return result, errCode
|
||||
}
|
||||
|
||||
result.ObtainTime = newPet.CatchTime
|
||||
result.StarterCpTm = newPet.ID
|
||||
c.Info.Coins -= petFusionCost
|
||||
if txResult.CostItemUsed {
|
||||
result.CostItemFlag = 1
|
||||
} else {
|
||||
removePetFromPlayerInfo(c, data.Auxcatchtime)
|
||||
}
|
||||
removePetFromPlayerInfo(c, data.Mcatchtime)
|
||||
|
||||
if txResult.NewPet == nil {
|
||||
return result, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
c.Info.PetList = append(c.Info.PetList, *txResult.NewPet)
|
||||
|
||||
result.ObtainTime = txResult.NewPet.CatchTime
|
||||
result.StarterCpTm = txResult.NewPet.ID
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -149,21 +185,10 @@ func hasEnoughItems(c *player.Player, itemCounts map[uint32]int) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func consumeItems(c *player.Player, itemCounts map[uint32]int) {
|
||||
for itemID, count := range itemCounts {
|
||||
_ = c.Service.Item.UPDATE(itemID, -count)
|
||||
func removePetFromPlayerInfo(c *player.Player, catchTime uint32) {
|
||||
index, _, ok := c.FindPet(catchTime)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func useOptionalItem(c *player.Player, itemIDs []uint32, target uint32) bool {
|
||||
if c.Service.Item.CheakItem(target) <= 0 {
|
||||
return false
|
||||
}
|
||||
for _, itemID := range itemIDs {
|
||||
if itemID == target {
|
||||
_ = c.Service.Item.UPDATE(target, -1)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
c.Info.PetList = append(c.Info.PetList[:index], c.Info.PetList[index+1:]...)
|
||||
}
|
||||
|
||||
@@ -4,19 +4,22 @@ import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/logic/service/player"
|
||||
playersvc "blazing/logic/service/player"
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
|
||||
// GetPetInfo 获取精灵信息
|
||||
func (h Controller) GetPetInfo(
|
||||
data *GetPetInfoInboundInfo,
|
||||
player *player.Player) (result *model.PetInfo,
|
||||
player *playersvc.Player) (result *model.PetInfo,
|
||||
err errorcode.ErrorCode) {
|
||||
_, petInfo, found := player.FindPet(data.CatchTime)
|
||||
if found {
|
||||
result = petInfo
|
||||
return result, 0
|
||||
levelLimit := player.CurrentMapPetLevelLimit()
|
||||
if slot, found := player.FindPetBagSlot(data.CatchTime); found {
|
||||
if petInfo := slot.PetInfoPtr(); petInfo != nil {
|
||||
petCopy := playersvc.ApplyPetLevelLimit(*petInfo, levelLimit)
|
||||
result = &petCopy
|
||||
return result, 0
|
||||
}
|
||||
}
|
||||
|
||||
ret := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
||||
@@ -24,16 +27,18 @@ func (h Controller) GetPetInfo(
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
|
||||
result = &ret.Data
|
||||
petData := ret.Data
|
||||
petData = playersvc.ApplyPetLevelLimit(petData, levelLimit)
|
||||
result = &petData
|
||||
return result, 0
|
||||
}
|
||||
|
||||
// GetUserBagPetInfo 获取主背包和并列备用精灵列表
|
||||
func (h Controller) GetUserBagPetInfo(
|
||||
data *GetUserBagPetInfoInboundEmpty,
|
||||
player *player.Player) (result *pet.GetUserBagPetInfoOutboundInfo,
|
||||
player *playersvc.Player) (result *pet.GetUserBagPetInfoOutboundInfo,
|
||||
err errorcode.ErrorCode) {
|
||||
return player.GetUserBagPetInfo(), 0
|
||||
return player.GetUserBagPetInfo(player.CurrentMapPetLevelLimit()), 0
|
||||
}
|
||||
|
||||
// GetPetListInboundEmpty 定义请求或响应数据结构。
|
||||
@@ -44,7 +49,7 @@ type GetPetListInboundEmpty struct {
|
||||
// GetPetList 获取当前主背包列表
|
||||
func (h Controller) GetPetList(
|
||||
data *GetPetListInboundEmpty,
|
||||
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
||||
player *playersvc.Player) (result *pet.GetPetListOutboundInfo,
|
||||
err errorcode.ErrorCode) {
|
||||
return buildPetListOutboundInfo(player.Info.PetList), 0
|
||||
}
|
||||
@@ -57,7 +62,7 @@ type GetPetListFreeInboundEmpty struct {
|
||||
// GetPetReleaseList 获取仓库可放生列表
|
||||
func (h Controller) GetPetReleaseList(
|
||||
data *GetPetListFreeInboundEmpty,
|
||||
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
||||
player *playersvc.Player) (result *pet.GetPetListOutboundInfo,
|
||||
err errorcode.ErrorCode) {
|
||||
|
||||
return buildPetListOutboundInfo(player.WarehousePetList()), 0
|
||||
@@ -66,14 +71,13 @@ func (h Controller) GetPetReleaseList(
|
||||
// PlayerShowPet 精灵展示
|
||||
func (h Controller) PlayerShowPet(
|
||||
data *PetShowInboundInfo,
|
||||
player *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) {
|
||||
player *playersvc.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &pet.PetShowOutboundInfo{
|
||||
UserID: data.Head.UserID,
|
||||
CatchTime: data.CatchTime,
|
||||
Flag: data.Flag,
|
||||
}
|
||||
|
||||
_, currentPet, ok := player.FindPet(data.CatchTime)
|
||||
if data.Flag == 0 {
|
||||
player.SetPetDisplay(0, nil)
|
||||
player.GetSpace().RefreshUserInfo(player)
|
||||
@@ -81,10 +85,16 @@ func (h Controller) PlayerShowPet(
|
||||
return
|
||||
}
|
||||
|
||||
slot, ok := player.FindPetBagSlot(data.CatchTime)
|
||||
if !ok {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if currentPet == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
|
||||
player.SetPetDisplay(data.Flag, currentPet)
|
||||
player.GetSpace().RefreshUserInfo(player)
|
||||
result = buildPetShowOutboundInfo(data.Head.UserID, data.Flag, currentPet)
|
||||
|
||||
@@ -6,8 +6,39 @@ import (
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/pet"
|
||||
"blazing/logic/service/player"
|
||||
playermodel "blazing/modules/player/model"
|
||||
)
|
||||
|
||||
func petSetExpLimit(currentPet *playermodel.PetInfo) int64 {
|
||||
if currentPet == nil || currentPet.Level >= 100 {
|
||||
return 0
|
||||
}
|
||||
|
||||
simulatedPet := *currentPet
|
||||
allowedExp := simulatedPet.NextLvExp - simulatedPet.Exp
|
||||
if allowedExp < 0 {
|
||||
allowedExp = 0
|
||||
}
|
||||
|
||||
for simulatedPet.Level < 100 && simulatedPet.NextLvExp > 0 {
|
||||
simulatedPet.Level++
|
||||
simulatedPet.Update(true)
|
||||
if simulatedPet.Level >= 100 {
|
||||
break
|
||||
}
|
||||
allowedExp += simulatedPet.NextLvExp
|
||||
}
|
||||
|
||||
return allowedExp
|
||||
}
|
||||
|
||||
func minInt64(a, b int64) int64 {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// PetReleaseToWarehouse 将精灵从仓库包中放生
|
||||
func (h Controller) PetReleaseToWarehouse(
|
||||
data *PET_ROWEI, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
@@ -17,9 +48,8 @@ func (h Controller) PetReleaseToWarehouse(
|
||||
if inBag || inBackup || freeForbidden == 1 {
|
||||
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
||||
}
|
||||
|
||||
if !player.Service.Pet.UpdateFree(data.CatchTime, 1) {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
if !player.Service.Pet.UpdateFree(data.CatchTime, 0, 1) {
|
||||
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
||||
}
|
||||
|
||||
return nil, 0
|
||||
@@ -32,9 +62,11 @@ func (h Controller) PetOneCure(
|
||||
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
||||
}
|
||||
|
||||
_, currentPet, ok := player.FindPet(data.CatchTime)
|
||||
if ok {
|
||||
defer currentPet.Cure()
|
||||
if slot, ok := player.FindPetBagSlot(data.CatchTime); ok {
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if currentPet != nil {
|
||||
defer currentPet.Cure()
|
||||
}
|
||||
}
|
||||
|
||||
return &pet.PetOneCureOutboundInfo{
|
||||
@@ -63,11 +95,17 @@ func (h Controller) PetFirst(
|
||||
func (h Controller) SetPetExp(
|
||||
data *PetSetExpInboundInfo,
|
||||
player *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
||||
_, currentPet, found := player.FindPet(data.CatchTime)
|
||||
if !found || currentPet.Level >= 100 {
|
||||
slot, found := player.FindPetBagSlot(data.CatchTime)
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if !found || currentPet == nil || currentPet.Level >= 100 {
|
||||
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
player.AddPetExp(currentPet, data.Exp)
|
||||
allowedExp := petSetExpLimit(currentPet)
|
||||
if allowedExp <= 0 {
|
||||
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
player.AddPetExp(currentPet, minInt64(data.Exp, allowedExp))
|
||||
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, 0
|
||||
}
|
||||
|
||||
75
logic/controller/pet_manage_test.go
Normal file
75
logic/controller/pet_manage_test.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/player"
|
||||
playermodel "blazing/modules/player/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func firstPetIDForControllerTest(t *testing.T) int {
|
||||
t.Helper()
|
||||
|
||||
for id := range xmlres.PetMAP {
|
||||
return id
|
||||
}
|
||||
|
||||
t.Fatal("xmlres.PetMAP is empty")
|
||||
return 0
|
||||
}
|
||||
|
||||
func TestSetPetExpCapsLevelAt100(t *testing.T) {
|
||||
petID := firstPetIDForControllerTest(t)
|
||||
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 99, nil, 0)
|
||||
if petInfo == nil {
|
||||
t.Fatal("failed to generate test pet")
|
||||
}
|
||||
|
||||
expPool := petInfo.NextLvExp + 10_000
|
||||
testPlayer := player.NewPlayer(nil)
|
||||
testPlayer.Info = &playermodel.PlayerInfo{
|
||||
ExpPool: expPool,
|
||||
PetList: []playermodel.PetInfo{*petInfo},
|
||||
}
|
||||
|
||||
currentPet := &testPlayer.Info.PetList[0]
|
||||
result, err := (Controller{}).SetPetExp(&PetSetExpInboundInfo{
|
||||
CatchTime: currentPet.CatchTime,
|
||||
Exp: expPool,
|
||||
}, testPlayer)
|
||||
if err != 0 {
|
||||
t.Fatalf("expected SetPetExp to succeed, got err=%d", err)
|
||||
}
|
||||
if currentPet.Level != 100 {
|
||||
t.Fatalf("expected pet level to stop at 100, got %d", currentPet.Level)
|
||||
}
|
||||
if result.Exp != 10_000 {
|
||||
t.Fatalf("expected overflow exp to remain in pool, got %d", result.Exp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetPetExpRejectsPetAtLevel100(t *testing.T) {
|
||||
petID := firstPetIDForControllerTest(t)
|
||||
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||
if petInfo == nil {
|
||||
t.Fatal("failed to generate test pet")
|
||||
}
|
||||
|
||||
testPlayer := player.NewPlayer(nil)
|
||||
testPlayer.Info = &playermodel.PlayerInfo{
|
||||
ExpPool: 50_000,
|
||||
PetList: []playermodel.PetInfo{*petInfo},
|
||||
}
|
||||
|
||||
result, err := (Controller{}).SetPetExp(&PetSetExpInboundInfo{
|
||||
CatchTime: petInfo.CatchTime,
|
||||
Exp: 12_345,
|
||||
}, testPlayer)
|
||||
if err != errorcode.ErrorCodes.ErrSystemError {
|
||||
t.Fatalf("expected level-100 pet to be rejected, got err=%d", err)
|
||||
}
|
||||
if result.Exp != 50_000 {
|
||||
t.Fatalf("expected exp pool to remain unchanged, got %d", result.Exp)
|
||||
}
|
||||
}
|
||||
@@ -67,8 +67,9 @@ func (h Controller) GetPetLearnableSkills(
|
||||
data *GetPetLearnableSkillsInboundInfo,
|
||||
c *player.Player,
|
||||
) (result *GetPetLearnableSkillsOutboundInfo, err errorcode.ErrorCode) {
|
||||
_, currentPet, ok := c.FindPet(data.CatchTime)
|
||||
if !ok {
|
||||
slot, ok := c.FindPetBagSlot(data.CatchTime)
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if !ok || currentPet == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
|
||||
@@ -81,8 +82,9 @@ func (h Controller) GetPetLearnableSkills(
|
||||
func (h Controller) SetPetSkill(data *ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
|
||||
const setSkillCost = 50
|
||||
|
||||
_, currentPet, ok := c.FindPet(data.CatchTime)
|
||||
if !ok {
|
||||
slot, ok := c.FindPetBagSlot(data.CatchTime)
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if !ok || currentPet == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
||||
}
|
||||
|
||||
@@ -147,8 +149,9 @@ func (h Controller) SetPetSkill(data *ChangeSkillInfo, c *player.Player) (result
|
||||
func (h Controller) SortPetSkills(data *C2S_Skill_Sort, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
const skillSortCost = 50
|
||||
|
||||
_, currentPet, ok := c.FindPet(data.CapTm)
|
||||
if !ok {
|
||||
slot, ok := c.FindPetBagSlot(data.CapTm)
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if !ok || currentPet == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
|
||||
@@ -205,8 +208,9 @@ func (h Controller) CommitPetSkills(
|
||||
const setSkillCost = 50
|
||||
const skillSortCost = 50
|
||||
|
||||
_, currentPet, ok := c.FindPet(data.CatchTime)
|
||||
if !ok {
|
||||
slot, ok := c.FindPetBagSlot(data.CatchTime)
|
||||
currentPet := slot.PetInfoPtr()
|
||||
if !ok || currentPet == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ func (f *FightC) Over(c common.PlayerI, res model.EnumBattleOverReason) {
|
||||
// }
|
||||
|
||||
f.overl.Do(func() {
|
||||
f.Reason = res
|
||||
f.Reason = normalizeFightOverReason(res)
|
||||
if f.GetInputByPlayer(c, true) != nil {
|
||||
f.WinnerId = f.GetInputByPlayer(c, true).UserID
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (e *Effect1181) OnSkill() bool {
|
||||
type Effect1182 struct{ node.EffectNode }
|
||||
|
||||
func (e *Effect1182) Skill_Use() bool {
|
||||
if len(e.Args()) < 2 || e.Ctx().Our == nil || e.Ctx().Our.CurPet[0] == nil || e.Ctx().Opp == nil || e.Ctx().Opp.CurPet[0] == nil {
|
||||
if len(e.Args()) < 2 || e.Ctx().Our == nil || e.Ctx().Our.CurPet[0] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -153,9 +153,15 @@ func (e *Effect1182) Skill_Use() bool {
|
||||
if targetHP.Cmp(alpacadecimal.Zero) < 0 {
|
||||
targetHP = alpacadecimal.Zero
|
||||
}
|
||||
if e.Ctx().Opp.CurPet[0].GetHP().Cmp(targetHP) > 0 {
|
||||
e.Ctx().Opp.CurPet[0].Info.Hp = uint32(targetHP.IntPart())
|
||||
}
|
||||
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||
if target == nil || target.CurrentPet() == nil {
|
||||
return true
|
||||
}
|
||||
if target.CurrentPet().GetHP().Cmp(targetHP) > 0 {
|
||||
target.CurrentPet().Info.Hp = uint32(targetHP.IntPart())
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
sub := e.Ctx().Our.InitEffect(input.EffectType.Sub, 1182, int(e.Args()[1].IntPart()))
|
||||
if sub != nil {
|
||||
|
||||
@@ -10,20 +10,23 @@ type Effect169 struct {
|
||||
}
|
||||
|
||||
func (e *Effect169) OnSkill() bool {
|
||||
|
||||
chance := e.Args()[1].IntPart()
|
||||
success, _, _ := e.Input.Player.Roll(int(chance), 100)
|
||||
if success {
|
||||
// 添加异常状态
|
||||
statusEffect := e.CarrierInput().InitEffect(input.EffectType.Status, int(e.Args()[2].IntPart())) // 以麻痹为例
|
||||
if statusEffect != nil {
|
||||
e.TargetInput().AddEffect(e.CarrierInput(), statusEffect)
|
||||
}
|
||||
e.ForEachOpponentSlot(func(target *input.Input) bool {
|
||||
if target == nil {
|
||||
return true
|
||||
}
|
||||
statusEffect := e.CarrierInput().InitEffect(input.EffectType.Status, int(e.Args()[2].IntPart()))
|
||||
if statusEffect != nil {
|
||||
target.AddEffect(e.CarrierInput(), statusEffect)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func init() {
|
||||
input.InitEffect(input.EffectType.Skill, 169, &Effect169{})
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package effect
|
||||
|
||||
import (
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/fight/node"
|
||||
)
|
||||
|
||||
@@ -41,14 +42,16 @@ type Effect5 struct {
|
||||
// 技能触发时调用
|
||||
// -----------------------------------------------------------
|
||||
func (e *Effect5) Skill_Use() bool {
|
||||
|
||||
// 概率判定
|
||||
ok, _, _ := e.Input.Player.Roll(e.SideEffectArgs[1], 100)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
|
||||
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[2]))
|
||||
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||
target.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[2]))
|
||||
return true
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -22,15 +22,19 @@ type Effect76 struct {
|
||||
}
|
||||
|
||||
func (e *Effect76) OnSkill() bool {
|
||||
|
||||
// 概率判定
|
||||
ok, _, _ := e.Input.Player.Roll(int(e.Args()[0].IntPart()), 100)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: alpacadecimal.NewFromInt(int64(e.SideEffectArgs[2])),
|
||||
|
||||
damage := alpacadecimal.NewFromInt(int64(e.SideEffectArgs[2]))
|
||||
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: damage,
|
||||
})
|
||||
return true
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ var effectInfoByID = map[int]string{
|
||||
29: "额外附加{0}点固定伤害",
|
||||
31: "",
|
||||
32: "使用后{0}回合攻击击中对象要害概率增加1/16",
|
||||
33: "消除对手能力提升状态",
|
||||
33: "消除敌方阵营所有强化",
|
||||
34: "将所受的伤害{0}倍反馈给对手",
|
||||
35: "惩罚,对方能力等级越高,此技能威力越大",
|
||||
36: "命中时{0}%的概率秒杀对方",
|
||||
@@ -120,7 +120,7 @@ var effectInfoByID = map[int]string{
|
||||
164: "{0}回合内若受到攻击则有{1}%概率令对手{2}",
|
||||
165: "{0}回合内每回合防御和特防等级+{1}",
|
||||
166: "{0}回合内若对手使用属性攻击则{2}%对手{1}等级{3}",
|
||||
169: "{0}回合内每回合额外附加{1}%概率令对手{2}",
|
||||
169: "{0}回合内每回合额外附加{1}%概率令对方阵营全体{2}",
|
||||
170: "若先出手,则免疫当回合伤害并回复1/{0}的最大体力值",
|
||||
171: "{0}回合内自身使用属性技能时能较快出手",
|
||||
172: "若后出手,则给予对方损伤的1/{0}会回复自己的体力",
|
||||
|
||||
@@ -27,7 +27,7 @@ func (e *Effect3) Skill_Use() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Effect 33: 消除对手能力提升状态
|
||||
// Effect 33: 消除敌方阵营所有强化
|
||||
type Effect33 struct {
|
||||
node.EffectNode
|
||||
Reverse bool
|
||||
@@ -38,13 +38,17 @@ type Effect33 struct {
|
||||
// 执行时逻辑
|
||||
// ----------------------
|
||||
func (e *Effect33) Skill_Use() bool {
|
||||
|
||||
for i, v := range e.Ctx().Opp.Prop[:] {
|
||||
if v > 0 {
|
||||
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(i), 0)
|
||||
e.ForEachOpponentSlot(func(target *input.Input) bool {
|
||||
if target == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
for i, v := range target.Prop[:] {
|
||||
if v > 0 {
|
||||
target.SetProp(e.Ctx().Our, int8(i), 0)
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -54,8 +58,8 @@ func (e *Effect33) Skill_Use() bool {
|
||||
// ----------------------
|
||||
func init() {
|
||||
// {3, false, 0}, // 解除自身能力下降状态
|
||||
// {33, true, 0}, // 消除对手能力提升状态{3, false, 0}, // 解除自身能力下降状态
|
||||
// {33, true, 0}, // 消除对手能力提升状态
|
||||
// {33, true, 0}, // 消除敌方阵营所有强化{3, false, 0}, // 解除自身能力下降状态
|
||||
// {33, true, 0}, // 消除敌方阵营所有强化
|
||||
input.InitEffect(input.EffectType.Skill, 3, &Effect3{})
|
||||
input.InitEffect(input.EffectType.Skill, 33, &Effect33{})
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ func (e *StatusSleep) Skill_Use_ex() bool {
|
||||
|
||||
func (e *StatusSleep) TurnEnd() {
|
||||
e.hasTriedAct = false
|
||||
e.StatusCannotAct.TurnEnd()
|
||||
}
|
||||
|
||||
// 持续伤害状态基类(中毒、冻伤、烧伤等)
|
||||
@@ -95,13 +96,13 @@ type ContinuousDamage struct {
|
||||
isheal bool //是否回血
|
||||
}
|
||||
|
||||
// 技能命中前触发伤害(1/8最大生命值真实伤害)
|
||||
func (e *ContinuousDamage) ActionStart(attacker, defender *action.SelectSkillAction) bool {
|
||||
// 回合开始触发持续伤害,保证吃药/空过回合时也会正常结算。
|
||||
func (e *ContinuousDamage) TurnStart(attacker, defender *action.SelectSkillAction) {
|
||||
carrier := e.CarrierInput()
|
||||
source := e.SourceInput()
|
||||
opp := e.TargetInput()
|
||||
if carrier == nil {
|
||||
return true
|
||||
return
|
||||
}
|
||||
damage := e.calculateDamage()
|
||||
|
||||
@@ -110,7 +111,7 @@ func (e *ContinuousDamage) ActionStart(attacker, defender *action.SelectSkillAct
|
||||
Damage: damage,
|
||||
})
|
||||
if len(e.SideEffectArgs) == 0 {
|
||||
return true
|
||||
return
|
||||
}
|
||||
// 额外效果
|
||||
carrier.Damage(source, &info.DamageZone{
|
||||
@@ -118,12 +119,11 @@ func (e *ContinuousDamage) ActionStart(attacker, defender *action.SelectSkillAct
|
||||
Damage: damage,
|
||||
})
|
||||
if opp == nil || opp.CurPet[0].GetHP().IntPart() == 0 {
|
||||
return true
|
||||
return
|
||||
}
|
||||
|
||||
// 给对方回血(不受回血限制影响)
|
||||
opp.Heal(carrier, nil, damage)
|
||||
return true
|
||||
}
|
||||
|
||||
// 计算伤害:最大生命值的1/8
|
||||
|
||||
@@ -207,9 +207,15 @@ func registerSelfDamageOnSkillEffects() {
|
||||
})
|
||||
}
|
||||
|
||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: opponentDamage,
|
||||
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||
if target == nil || target.CurrentPet() == nil {
|
||||
return true
|
||||
}
|
||||
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: opponentDamage,
|
||||
})
|
||||
return true
|
||||
})
|
||||
return true
|
||||
},
|
||||
@@ -241,9 +247,15 @@ func registerSelfDamageSkillUseEffects() {
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: damage,
|
||||
})
|
||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: damage,
|
||||
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||
if target == nil || target.CurrentPet() == nil {
|
||||
return true
|
||||
}
|
||||
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: damage,
|
||||
})
|
||||
return true
|
||||
})
|
||||
return true
|
||||
},
|
||||
@@ -253,9 +265,23 @@ func registerSelfDamageSkillUseEffects() {
|
||||
Damage: alpacadecimal.NewFromInt(int64(e.Ctx().Our.CurPet[0].Info.MaxHp)),
|
||||
})
|
||||
damage := int64(grand.N(250, 300))
|
||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: alpacadecimal.Min(alpacadecimal.NewFromInt(damage), e.Ctx().Opp.CurPet[0].GetHP().Sub(alpacadecimal.NewFromInt(1))),
|
||||
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||
if target == nil {
|
||||
return true
|
||||
}
|
||||
targetPet := target.CurrentPet()
|
||||
if targetPet == nil {
|
||||
return true
|
||||
}
|
||||
remainHP := targetPet.GetHP().Sub(alpacadecimal.NewFromInt(1))
|
||||
if remainHP.Cmp(alpacadecimal.Zero) <= 0 {
|
||||
return true
|
||||
}
|
||||
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: alpacadecimal.Min(alpacadecimal.NewFromInt(damage), remainHP),
|
||||
})
|
||||
return true
|
||||
})
|
||||
return true
|
||||
},
|
||||
@@ -280,15 +306,25 @@ func registerSelfDamageSkillUseEffects() {
|
||||
randomDamage = grand.N(minDamage, maxDamage)
|
||||
}
|
||||
|
||||
remainHP := e.Ctx().Opp.CurPet[0].GetHP().Sub(alpacadecimal.NewFromInt(1))
|
||||
if remainHP.Cmp(alpacadecimal.Zero) <= 0 {
|
||||
return true
|
||||
}
|
||||
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||
if target == nil {
|
||||
return true
|
||||
}
|
||||
targetPet := target.CurrentPet()
|
||||
if targetPet == nil {
|
||||
return true
|
||||
}
|
||||
remainHP := targetPet.GetHP().Sub(alpacadecimal.NewFromInt(1))
|
||||
if remainHP.Cmp(alpacadecimal.Zero) <= 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
damage := alpacadecimal.Min(alpacadecimal.NewFromInt(int64(randomDamage)), remainHP)
|
||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: damage,
|
||||
damage := alpacadecimal.Min(alpacadecimal.NewFromInt(int64(randomDamage)), remainHP)
|
||||
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: damage,
|
||||
})
|
||||
return true
|
||||
})
|
||||
return true
|
||||
},
|
||||
@@ -297,11 +333,17 @@ func registerSelfDamageSkillUseEffects() {
|
||||
return true
|
||||
}
|
||||
|
||||
applyAllPropDown(e.Ctx().Our, e.Ctx().Opp, int8(e.Args()[0].IntPart()))
|
||||
sub := e.Ctx().Our.InitEffect(input.EffectType.Sub, 1380, int(e.Args()[1].IntPart()), int(e.Args()[2].IntPart()))
|
||||
if sub != nil {
|
||||
e.Ctx().Opp.AddEffect(e.Ctx().Our, sub)
|
||||
}
|
||||
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||
if target == nil || target.CurrentPet() == nil {
|
||||
return true
|
||||
}
|
||||
applyAllPropDown(e.Ctx().Our, target, int8(e.Args()[0].IntPart()))
|
||||
sub := e.Ctx().Our.InitEffect(input.EffectType.Sub, 1380, int(e.Args()[1].IntPart()), int(e.Args()[2].IntPart()))
|
||||
if sub != nil {
|
||||
target.AddEffect(e.Ctx().Our, sub)
|
||||
}
|
||||
return true
|
||||
})
|
||||
e.Ctx().Our.Damage(e.Ctx().Our, &info.DamageZone{
|
||||
Type: info.DamageType.Fixed,
|
||||
Damage: e.Ctx().Our.CurPet[0].GetHP(),
|
||||
|
||||
34
logic/service/fight/effect/skill_target_helper.go
Normal file
34
logic/service/fight/effect/skill_target_helper.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package effect
|
||||
|
||||
import (
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
)
|
||||
|
||||
// forEachEnemyTargetBySkill 在普通情况下对单个目标生效;
|
||||
// 当技能为 AtkType=3(仅自己)且当前目标仍在己方时,改为遍历敌方全部站位。
|
||||
func forEachEnemyTargetBySkill(carrier, target *input.Input, skill *info.SkillEntity, fn func(*input.Input) bool) {
|
||||
if fn == nil {
|
||||
return
|
||||
}
|
||||
if carrier == nil {
|
||||
if target != nil {
|
||||
fn(target)
|
||||
}
|
||||
return
|
||||
}
|
||||
if skill == nil || skill.XML.AtkType != 3 || !isSameSideTarget(carrier, target) {
|
||||
if target != nil {
|
||||
fn(target)
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, opponent := range carrier.OpponentSlots() {
|
||||
if opponent == nil {
|
||||
continue
|
||||
}
|
||||
if !fn(opponent) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,21 @@ import "blazing/modules/player/model"
|
||||
// 0=normal end 1=player lost/offline 2=overtime 3=draw 4=system error 5=npc escape.
|
||||
func buildFightOverPayload(over model.FightOverInfo) *model.FightOverInfo {
|
||||
payload := over
|
||||
payload.Reason = mapFightOverReasonFor2506(over.Reason)
|
||||
payload.Reason = model.EnumBattleOverReason(mapUnifiedFightOverReason(over.Reason))
|
||||
return &payload
|
||||
}
|
||||
|
||||
func mapFightOverReasonFor2506(reason model.EnumBattleOverReason) model.EnumBattleOverReason {
|
||||
switch reason {
|
||||
func normalizeFightOverReason(reason model.EnumBattleOverReason) model.EnumBattleOverReason {
|
||||
if reason == model.BattleOverReason.DefaultEnd {
|
||||
return 0
|
||||
}
|
||||
return reason
|
||||
}
|
||||
|
||||
func mapUnifiedFightOverReason(reason model.EnumBattleOverReason) uint32 {
|
||||
switch normalizeFightOverReason(reason) {
|
||||
case 0, model.BattleOverReason.Cacthok:
|
||||
return 0
|
||||
case model.BattleOverReason.PlayerOffline:
|
||||
return 1
|
||||
case model.BattleOverReason.PlayerOVerTime:
|
||||
@@ -20,12 +29,12 @@ func mapFightOverReasonFor2506(reason model.EnumBattleOverReason) model.EnumBatt
|
||||
case model.BattleOverReason.NOTwind:
|
||||
return 3
|
||||
case model.BattleOverReason.PlayerEscape:
|
||||
// Player-initiated escape is handled by 2410 on the flash side; 2506 should
|
||||
// still land in a non-error bucket instead of "system error".
|
||||
return 1
|
||||
case model.BattleOverReason.Cacthok, model.BattleOverReason.DefaultEnd:
|
||||
return 0
|
||||
return 5
|
||||
default:
|
||||
return 4
|
||||
}
|
||||
}
|
||||
|
||||
func mapFightOverReasonFor2506(reason model.EnumBattleOverReason) model.EnumBattleOverReason {
|
||||
return model.EnumBattleOverReason(mapUnifiedFightOverReason(reason))
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"blazing/logic/service/fight/action"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
_ "blazing/logic/service/fight/itemover"
|
||||
_ "blazing/logic/service/fight/rule"
|
||||
"blazing/modules/player/model"
|
||||
"reflect"
|
||||
|
||||
@@ -133,7 +135,20 @@ func (f *FightC) getSkillParticipants(skillAction *action.SelectSkillAction) (*i
|
||||
if skillAction == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return f.GetInputByAction(skillAction, false), f.GetInputByAction(skillAction, true)
|
||||
attacker := f.GetInputByAction(skillAction, false)
|
||||
defender := f.GetInputByAction(skillAction, true)
|
||||
if attacker != nil && defender == attacker && shouldResolveOpponentAsTarget(skillAction.SkillEntity) {
|
||||
if opponent, _ := attacker.OpponentSlotAtOrNextLiving(0); opponent != nil {
|
||||
defender = opponent
|
||||
} else if opponent := f.roundOpponentInput(attacker); opponent != nil {
|
||||
defender = opponent
|
||||
}
|
||||
}
|
||||
return attacker, defender
|
||||
}
|
||||
|
||||
func shouldResolveOpponentAsTarget(skill *info.SkillEntity) bool {
|
||||
return skill != nil && skill.XML.AtkType == 3
|
||||
}
|
||||
|
||||
// setEffectSkillContext 统一设置技能阶段 effect 上下文。
|
||||
@@ -232,6 +247,15 @@ func (f *FightC) roundOpponentInput(attacker *input.Input) *input.Input {
|
||||
return nil
|
||||
}
|
||||
|
||||
func shouldSkipSecondAction(first, second *input.Input) bool {
|
||||
if first == nil || second == nil {
|
||||
return false
|
||||
}
|
||||
firstPet := first.CurrentPet()
|
||||
secondPet := second.CurrentPet()
|
||||
return firstPet == nil || firstPet.Info.Hp <= 0 || secondPet == nil || secondPet.Info.Hp <= 0
|
||||
}
|
||||
|
||||
// enterturn 处理战斗回合逻辑
|
||||
// 回合有先手方和后手方,同时有攻击方和被攻击方
|
||||
func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) {
|
||||
@@ -333,6 +357,10 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
|
||||
if currentAction == nil {
|
||||
continue
|
||||
}
|
||||
if shouldSkipSecondAction(f.First, f.Second) {
|
||||
secondAttack = nil
|
||||
continue
|
||||
}
|
||||
attacker, defender = f.getSkillParticipants(secondAttack)
|
||||
originalSkill = f.copySkill(secondAttack)
|
||||
//取消后手历史效果
|
||||
@@ -522,9 +550,9 @@ func (f *FightC) TURNOVER(cur *input.Input) {
|
||||
if f.IsWin(f.GetInputByPlayer(cur.Player, true)) { //然后检查是否战斗结束
|
||||
|
||||
f.FightOverInfo.WinnerId = f.GetInputByPlayer(cur.Player, true).UserID
|
||||
f.FightOverInfo.Reason = model.BattleOverReason.DefaultEnd
|
||||
f.FightOverInfo.Reason = normalizeFightOverReason(model.BattleOverReason.DefaultEnd)
|
||||
f.WinnerId = f.FightOverInfo.WinnerId
|
||||
f.Reason = model.BattleOverReason.DefaultEnd
|
||||
f.Reason = f.FightOverInfo.Reason
|
||||
|
||||
f.closefight = true
|
||||
// break
|
||||
|
||||
@@ -8,6 +8,11 @@ import (
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
|
||||
// <!--
|
||||
// GBTL:
|
||||
// 1. AtkNum:本技能同时攻击数量, 默认:1(不能为0)
|
||||
// 2. AtkType:攻击类型: 0:所有人, 1:仅己方, 2:仅对方, 3:仅自己, 默认:2
|
||||
// -->
|
||||
const (
|
||||
groupCmdReadyToFight uint32 = 7555
|
||||
groupCmdReadyFightFinish uint32 = 7556
|
||||
@@ -426,38 +431,15 @@ func (f *FightC) buildLegacyGroupOverInfo(over *model.FightOverInfo) *legacyGrou
|
||||
}
|
||||
|
||||
func mapLegacyGroupFightOverReason(reason model.EnumBattleOverReason) uint32 {
|
||||
switch reason {
|
||||
case model.BattleOverReason.PlayerOffline:
|
||||
return 2
|
||||
case model.BattleOverReason.PlayerOVerTime:
|
||||
return 3
|
||||
case model.BattleOverReason.NOTwind:
|
||||
return 4
|
||||
case model.BattleOverReason.DefaultEnd:
|
||||
return 1
|
||||
case model.BattleOverReason.PlayerEscape:
|
||||
return 6
|
||||
default:
|
||||
return 5
|
||||
}
|
||||
return mapUnifiedFightOverReason(reason)
|
||||
}
|
||||
|
||||
func resolveLegacyGroupFightOverReason(over *model.FightOverInfo) uint32 {
|
||||
if over == nil {
|
||||
return 5
|
||||
}
|
||||
switch over.Reason {
|
||||
case model.BattleOverReason.PlayerOffline:
|
||||
return 2
|
||||
case model.BattleOverReason.PlayerOVerTime:
|
||||
return 3
|
||||
case model.BattleOverReason.PlayerEscape:
|
||||
return 6
|
||||
case model.BattleOverReason.NOTwind:
|
||||
return 4
|
||||
return mapUnifiedFightOverReason(0)
|
||||
}
|
||||
if over.WinnerId != 0 {
|
||||
return 1
|
||||
return mapUnifiedFightOverReason(0)
|
||||
}
|
||||
return mapLegacyGroupFightOverReason(over.Reason)
|
||||
}
|
||||
@@ -515,15 +497,23 @@ func (f *FightC) sendLegacyRoundBroadcast(firstAttack, secondAttack *action.Sele
|
||||
if f == nil || !f.LegacyGroupProtocol {
|
||||
return
|
||||
}
|
||||
if firstAttack != nil {
|
||||
if f.legacySkillExecuted(firstAttack) {
|
||||
f.sendLegacyGroupSkillHurt(firstAttack)
|
||||
}
|
||||
if secondAttack != nil {
|
||||
if f.legacySkillExecuted(secondAttack) {
|
||||
f.sendLegacyGroupSkillHurt(secondAttack)
|
||||
}
|
||||
f.sendLegacyGroupBoutDone()
|
||||
}
|
||||
|
||||
func (f *FightC) legacySkillExecuted(skillAction *action.SelectSkillAction) bool {
|
||||
if f == nil || skillAction == nil {
|
||||
return false
|
||||
}
|
||||
attacker := f.GetInputByAction(skillAction, false)
|
||||
return attacker != nil && attacker.AttackValue != nil && attacker.AttackValue.SkillID != 0
|
||||
}
|
||||
|
||||
func (f *FightC) sendLegacyGroupSkillHurt(skillAction *action.SelectSkillAction) {
|
||||
if f == nil || !f.LegacyGroupProtocol || skillAction == nil {
|
||||
return
|
||||
@@ -603,10 +593,10 @@ func (f *FightC) buildLegacyGroupSkillAttackInfo(skillAction *action.SelectSkill
|
||||
if attackValue == nil {
|
||||
attackValue = info.NewAttackValue(self.UserID)
|
||||
}
|
||||
if skillAction != nil && skillAction.SkillEntity != nil {
|
||||
result.MoveID = uint32(skillAction.SkillEntity.XML.ID)
|
||||
} else {
|
||||
if attackValue.SkillID != 0 {
|
||||
result.MoveID = attackValue.SkillID
|
||||
} else if skillAction != nil && skillAction.SkillEntity != nil {
|
||||
result.MoveID = uint32(skillAction.SkillEntity.XML.ID)
|
||||
}
|
||||
result.IsCrit = attackValue.IsCritical
|
||||
result.EffectName = attackValue.State
|
||||
|
||||
61
logic/service/fight/group_legacy_test.go
Normal file
61
logic/service/fight/group_legacy_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package fight
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"blazing/logic/service/fight/action"
|
||||
fightinfo "blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
|
||||
func TestSendLegacyRoundBroadcastSkipsUnexecutedAction(t *testing.T) {
|
||||
ourPlayer := &stubPlayer{info: model.PlayerInfo{UserID: 1001}}
|
||||
oppPlayer := &stubPlayer{info: model.PlayerInfo{UserID: 2002}}
|
||||
|
||||
our := input.NewInput(nil, ourPlayer)
|
||||
our.InitAttackValue()
|
||||
our.AttackValue.SkillID = 111
|
||||
our.SetCurPetAt(0, fightinfo.CreateBattlePetEntity(model.PetInfo{
|
||||
ID: 11,
|
||||
Hp: 80,
|
||||
MaxHp: 100,
|
||||
CatchTime: 101,
|
||||
}))
|
||||
|
||||
opp := input.NewInput(nil, oppPlayer)
|
||||
opp.InitAttackValue()
|
||||
opp.SetCurPetAt(0, fightinfo.CreateBattlePetEntity(model.PetInfo{
|
||||
ID: 22,
|
||||
Hp: 0,
|
||||
MaxHp: 100,
|
||||
CatchTime: 202,
|
||||
}))
|
||||
|
||||
fc := &FightC{
|
||||
Our: []*input.Input{our},
|
||||
Opp: []*input.Input{opp},
|
||||
LegacyGroupProtocol: true,
|
||||
}
|
||||
|
||||
firstAttack := &action.SelectSkillAction{
|
||||
BaseAction: action.BaseAction{PlayerID: ourPlayer.info.UserID, ActorIndex: 0, TargetIndex: 0},
|
||||
}
|
||||
secondAttack := &action.SelectSkillAction{
|
||||
BaseAction: action.BaseAction{PlayerID: oppPlayer.info.UserID, ActorIndex: 0, TargetIndex: 0},
|
||||
}
|
||||
|
||||
fc.sendLegacyRoundBroadcast(firstAttack, secondAttack)
|
||||
|
||||
for _, player := range []*stubPlayer{ourPlayer, oppPlayer} {
|
||||
if len(player.sentCmds) != 2 {
|
||||
t.Fatalf("expected one skill packet plus bout done, got %v", player.sentCmds)
|
||||
}
|
||||
if player.sentCmds[0] != groupCmdSkillHurt {
|
||||
t.Fatalf("expected first packet to be skill hurt, got %d", player.sentCmds[0])
|
||||
}
|
||||
if player.sentCmds[1] != groupCmdBoutDone {
|
||||
t.Fatalf("expected second packet to be bout done, got %d", player.sentCmds[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func (f *FightC) battleLoop() {
|
||||
if player := f.primaryOppPlayer(); player != nil {
|
||||
f.WinnerId = player.GetInfo().UserID
|
||||
}
|
||||
f.Reason = model.BattleOverReason.DefaultEnd
|
||||
f.Reason = normalizeFightOverReason(model.BattleOverReason.DefaultEnd)
|
||||
f.FightOverInfo.WinnerId = f.WinnerId
|
||||
f.FightOverInfo.Reason = f.Reason
|
||||
f.closefight = true
|
||||
@@ -86,7 +86,7 @@ func (f *FightC) battleLoop() {
|
||||
if player := f.primaryOurPlayer(); player != nil {
|
||||
f.WinnerId = player.GetInfo().UserID
|
||||
}
|
||||
f.Reason = model.BattleOverReason.DefaultEnd
|
||||
f.Reason = normalizeFightOverReason(model.BattleOverReason.DefaultEnd)
|
||||
f.FightOverInfo.WinnerId = f.WinnerId
|
||||
f.FightOverInfo.Reason = f.Reason
|
||||
f.closefight = true
|
||||
|
||||
@@ -12,7 +12,8 @@ import (
|
||||
)
|
||||
|
||||
type stubPlayer struct {
|
||||
info model.PlayerInfo
|
||||
info model.PlayerInfo
|
||||
sentCmds []uint32
|
||||
}
|
||||
|
||||
func (*stubPlayer) ApplyPetDisplayInfo(*spaceinfo.SimpleInfo) {}
|
||||
@@ -26,7 +27,7 @@ func (*stubPlayer) SetFightC(common.FightI) {}
|
||||
func (*stubPlayer) QuitFight() {}
|
||||
func (*stubPlayer) MessWin(bool) {}
|
||||
func (*stubPlayer) CanFight() errorcode.ErrorCode { return 0 }
|
||||
func (*stubPlayer) SendPackCmd(uint32, any) {}
|
||||
func (p *stubPlayer) SendPackCmd(cmd uint32, _ any) { p.sentCmds = append(p.sentCmds, cmd) }
|
||||
func (*stubPlayer) GetPetInfo(uint32) []model.PetInfo { return nil }
|
||||
|
||||
func TestFightActionEnvelopeEncodedTargetIndex(t *testing.T) {
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
package player
|
||||
|
||||
import "blazing/modules/player/model"
|
||||
|
||||
type AI_player struct {
|
||||
baseplayer
|
||||
|
||||
CanCapture int
|
||||
BossScript string
|
||||
}
|
||||
|
||||
func (p *AI_player) GetPetInfo(_ uint32) []model.PetInfo {
|
||||
ret := make([]model.PetInfo, 0, len(p.Info.PetList))
|
||||
ret = append(ret, p.Info.PetList...)
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -32,17 +32,19 @@ func (p *baseplayer) GetInfo() *model.PlayerInfo {
|
||||
return p.Info
|
||||
}
|
||||
|
||||
func ApplyPetLevelLimit(pet model.PetInfo, limitlevel uint32) model.PetInfo {
|
||||
originalHP := pet.Hp
|
||||
pet.CalculatePetPane(limitlevel)
|
||||
pet.Hp = utils.Min(originalHP, pet.MaxHp)
|
||||
return pet
|
||||
}
|
||||
|
||||
func (p *baseplayer) GetPetInfo(limitlevel uint32) []model.PetInfo {
|
||||
|
||||
var ret []model.PetInfo
|
||||
ret := make([]model.PetInfo, 0, len(p.Info.PetList))
|
||||
|
||||
for _, pet := range p.Info.PetList {
|
||||
if limitlevel > 0 {
|
||||
pet.Level = utils.Min(pet.Level, limitlevel)
|
||||
|
||||
}
|
||||
|
||||
ret = append(ret, pet)
|
||||
ret = append(ret, ApplyPetLevelLimit(pet, limitlevel))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -27,37 +27,32 @@ func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
||||
if petInfo == nil || addExp <= 0 {
|
||||
return
|
||||
}
|
||||
if petInfo.Level >= 100 {
|
||||
petInfo.Level = 100
|
||||
petInfo.Exp = 0
|
||||
panelLimit := p.CurrentMapPetLevelLimit()
|
||||
if petInfo.Level > 100 {
|
||||
currentHP := petInfo.Hp
|
||||
petInfo.Update(false)
|
||||
petInfo.CalculatePetPane(100)
|
||||
if petInfo.Hp > petInfo.MaxHp {
|
||||
petInfo.Hp = petInfo.MaxHp
|
||||
}
|
||||
return
|
||||
petInfo.CalculatePetPane(panelLimit)
|
||||
petInfo.Hp = utils.Min(currentHP, petInfo.MaxHp)
|
||||
}
|
||||
addExp = utils.Min(addExp, p.Info.ExpPool)
|
||||
if addExp <= 0 {
|
||||
return
|
||||
}
|
||||
originalLevel := petInfo.Level
|
||||
exp := int64(petInfo.Exp) + addExp
|
||||
allocatedExp := addExp
|
||||
p.Info.ExpPool -= addExp //减去已使用的经验
|
||||
gainedExp := exp //已获得的经验
|
||||
for petInfo.Level < 100 && exp >= int64(petInfo.NextLvExp) {
|
||||
|
||||
currentExp := petInfo.Exp + addExp
|
||||
for currentExp >= petInfo.NextLvExp && petInfo.NextLvExp > 0 {
|
||||
petInfo.Level++
|
||||
|
||||
exp -= int64(petInfo.LvExp)
|
||||
petInfo.Update(true)
|
||||
currentExp -= petInfo.LvExp
|
||||
}
|
||||
if petInfo.Level >= 100 {
|
||||
p.Info.ExpPool += exp // 超出100级上限的经验退回经验池
|
||||
gainedExp -= exp
|
||||
exp = 0
|
||||
}
|
||||
petInfo.Exp = (exp)
|
||||
petInfo.Exp = currentExp
|
||||
|
||||
// 重新计算面板
|
||||
if originalLevel != petInfo.Level {
|
||||
petInfo.CalculatePetPane(100)
|
||||
petInfo.CalculatePetPane(panelLimit)
|
||||
|
||||
petInfo.Cure()
|
||||
p.Info.PetMaxLevel = utils.Max(petInfo.Level, p.Info.PetMaxLevel)
|
||||
@@ -89,7 +84,7 @@ func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
||||
var petUpdateInfo info.UpdatePropInfo
|
||||
|
||||
copier.Copy(&petUpdateInfo, petInfo)
|
||||
petUpdateInfo.Exp = uint32(gainedExp)
|
||||
petUpdateInfo.Exp = uint32(allocatedExp)
|
||||
updateOutbound.Data = append(updateOutbound.Data, petUpdateInfo)
|
||||
p.SendPack(header.Pack(updateOutbound)) //准备包由各自发,因为协议不一样
|
||||
|
||||
|
||||
@@ -25,6 +25,13 @@ func (slot PetBagSlot) PetInfo() model.PetInfo {
|
||||
return slot.info
|
||||
}
|
||||
|
||||
func (slot PetBagSlot) PetInfoPtr() *model.PetInfo {
|
||||
if !slot.IsValid() {
|
||||
return nil
|
||||
}
|
||||
return &(*slot.list)[slot.index]
|
||||
}
|
||||
|
||||
func (slot PetBagSlot) IsMainBag() bool {
|
||||
return slot.main
|
||||
}
|
||||
@@ -99,12 +106,20 @@ func validatePetBagOrder(
|
||||
return true
|
||||
}
|
||||
|
||||
func buildLimitedPetList(petList []model.PetInfo, limitlevel uint32) []model.PetInfo {
|
||||
result := make([]model.PetInfo, 0, len(petList))
|
||||
for _, petInfo := range petList {
|
||||
result = append(result, ApplyPetLevelLimit(petInfo, limitlevel))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// GetUserBagPetInfo 返回主背包和并列备用精灵列表。
|
||||
func (p *Player) GetUserBagPetInfo() *pet.GetUserBagPetInfoOutboundInfo {
|
||||
func (p *Player) GetUserBagPetInfo(limitlevel uint32) *pet.GetUserBagPetInfoOutboundInfo {
|
||||
|
||||
result := &pet.GetUserBagPetInfoOutboundInfo{
|
||||
PetList: p.Info.PetList,
|
||||
BackupPetList: p.Info.BackupPetList,
|
||||
PetList: buildLimitedPetList(p.Info.PetList, limitlevel),
|
||||
BackupPetList: buildLimitedPetList(p.Info.BackupPetList, limitlevel),
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
@@ -17,12 +17,16 @@ func firstPetIDForTest(t *testing.T) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func TestAddPetExpStopsAtLevel100(t *testing.T) {
|
||||
func TestAddPetExpAllowsLevelBeyond100WhilePanelStaysCapped(t *testing.T) {
|
||||
petID := firstPetIDForTest(t)
|
||||
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 99, nil, 0)
|
||||
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||
expectedPanel := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||
if petInfo == nil {
|
||||
t.Fatalf("failed to generate test pet")
|
||||
}
|
||||
if expectedPanel == nil {
|
||||
t.Fatalf("failed to generate expected test pet")
|
||||
}
|
||||
|
||||
player := &Player{
|
||||
baseplayer: baseplayer{
|
||||
@@ -34,21 +38,29 @@ func TestAddPetExpStopsAtLevel100(t *testing.T) {
|
||||
|
||||
player.AddPetExp(petInfo, petInfo.NextLvExp+10_000)
|
||||
|
||||
if petInfo.Level != 100 {
|
||||
t.Fatalf("expected pet level to stop at 100, got %d", petInfo.Level)
|
||||
if petInfo.Level <= 100 {
|
||||
t.Fatalf("expected pet level to continue beyond 100, got %d", petInfo.Level)
|
||||
}
|
||||
if petInfo.Exp != 0 {
|
||||
t.Fatalf("expected pet exp to reset at level cap, got %d", petInfo.Exp)
|
||||
if petInfo.MaxHp != expectedPanel.MaxHp {
|
||||
t.Fatalf("expected max hp to stay capped at 100-level panel, got %d want %d", petInfo.MaxHp, expectedPanel.MaxHp)
|
||||
}
|
||||
if petInfo.Prop != expectedPanel.Prop {
|
||||
t.Fatalf("expected props to stay capped at 100-level panel, got %+v want %+v", petInfo.Prop, expectedPanel.Prop)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddPetExpDoesNotConsumePoolAboveLevel100(t *testing.T) {
|
||||
func TestAddPetExpRecalculatesPanelForLevelAbove100(t *testing.T) {
|
||||
petID := firstPetIDForTest(t)
|
||||
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||
expectedPanel := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||
if petInfo == nil {
|
||||
t.Fatalf("failed to generate test pet")
|
||||
}
|
||||
if expectedPanel == nil {
|
||||
t.Fatalf("failed to generate expected test pet")
|
||||
}
|
||||
petInfo.Level = 101
|
||||
petInfo.Exp = 7
|
||||
petInfo.MaxHp = 1
|
||||
petInfo.Hp = 999999
|
||||
|
||||
@@ -62,19 +74,84 @@ func TestAddPetExpDoesNotConsumePoolAboveLevel100(t *testing.T) {
|
||||
|
||||
player.AddPetExp(petInfo, 12_345)
|
||||
|
||||
if petInfo.Level != 100 {
|
||||
t.Fatalf("expected level to be normalized to 100, got %d", petInfo.Level)
|
||||
if petInfo.Level < 101 {
|
||||
t.Fatalf("expected level above 100 to be preserved, got %d", petInfo.Level)
|
||||
}
|
||||
if player.Info.ExpPool != 50_000 {
|
||||
t.Fatalf("expected exp pool to remain unchanged, got %d", player.Info.ExpPool)
|
||||
}
|
||||
if petInfo.Exp != 0 {
|
||||
t.Fatalf("expected exp to reset after normalization, got %d", petInfo.Exp)
|
||||
}
|
||||
if petInfo.MaxHp <= 1 {
|
||||
t.Fatalf("expected pet panel to be recalculated, got max hp %d", petInfo.MaxHp)
|
||||
if petInfo.MaxHp != expectedPanel.MaxHp {
|
||||
t.Fatalf("expected max hp to be recalculated using level 100 cap, got %d want %d", petInfo.MaxHp, expectedPanel.MaxHp)
|
||||
}
|
||||
if petInfo.Hp != petInfo.MaxHp {
|
||||
t.Fatalf("expected hp to be clamped to recalculated max hp, got hp=%d maxHp=%d", petInfo.Hp, petInfo.MaxHp)
|
||||
}
|
||||
if player.Info.ExpPool != 50_000-12_345 {
|
||||
t.Fatalf("expected exp pool to be consumed normally, got %d", player.Info.ExpPool)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddPetExpSmallRewardDoesNotJumpToMaxLevel(t *testing.T) {
|
||||
petID := firstPetIDForTest(t)
|
||||
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 20, nil, 0)
|
||||
if petInfo == nil {
|
||||
t.Fatalf("failed to generate test pet")
|
||||
}
|
||||
|
||||
player := &Player{
|
||||
baseplayer: baseplayer{
|
||||
Info: &playermodel.PlayerInfo{
|
||||
ExpPool: 1_000_000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
addExp := int64(100)
|
||||
originalLevel := petInfo.Level
|
||||
nextLevelNeed := petInfo.NextLvExp - petInfo.Exp
|
||||
if addExp >= nextLevelNeed {
|
||||
t.Fatalf("test setup invalid: addExp=%d should be smaller than next level need=%d", addExp, nextLevelNeed)
|
||||
}
|
||||
|
||||
player.AddPetExp(petInfo, addExp)
|
||||
|
||||
if petInfo.Level != originalLevel {
|
||||
t.Fatalf("expected level to stay at %d, got %d", originalLevel, petInfo.Level)
|
||||
}
|
||||
if petInfo.Exp != addExp {
|
||||
t.Fatalf("expected current exp to increase by %d, got %d", addExp, petInfo.Exp)
|
||||
}
|
||||
if player.Info.ExpPool != 1_000_000-addExp {
|
||||
t.Fatalf("expected exp pool to decrease by %d, got %d", addExp, player.Info.ExpPool)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddPetExpUsesDynamicPerLevelRequirement(t *testing.T) {
|
||||
petID := firstPetIDForTest(t)
|
||||
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 20, nil, 0)
|
||||
if petInfo == nil {
|
||||
t.Fatalf("failed to generate test pet")
|
||||
}
|
||||
|
||||
initialNeed := petInfo.NextLvExp
|
||||
if initialNeed <= 0 {
|
||||
t.Fatalf("expected positive exp requirement, got %d", initialNeed)
|
||||
}
|
||||
|
||||
player := &Player{
|
||||
baseplayer: baseplayer{
|
||||
Info: &playermodel.PlayerInfo{
|
||||
ExpPool: 1_000_000,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
player.AddPetExp(petInfo, initialNeed)
|
||||
|
||||
if petInfo.Level != 21 {
|
||||
t.Fatalf("expected pet level to become 21, got %d", petInfo.Level)
|
||||
}
|
||||
if petInfo.Exp != 0 {
|
||||
t.Fatalf("expected level-up to reset current level exp, got %d", petInfo.Exp)
|
||||
}
|
||||
if petInfo.NextLvExp == initialNeed {
|
||||
t.Fatalf("expected next level exp to change after leveling, still %d", petInfo.NextLvExp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,6 +228,21 @@ func (p *Player) GetSpace() *space.Space {
|
||||
return space.GetSpace(p.Info.MapID)
|
||||
}
|
||||
|
||||
func (p *Player) CurrentMapPetLevelLimit() uint32 {
|
||||
if p == nil {
|
||||
return 100
|
||||
}
|
||||
currentSpace := p.GetSpace()
|
||||
if currentSpace != nil && currentSpace.IsLevelBreakMap {
|
||||
return 0
|
||||
}
|
||||
return 100
|
||||
}
|
||||
|
||||
func (p *Player) IsCurrentMapLevelBreak() bool {
|
||||
return p != nil && p.CurrentMapPetLevelLimit() == 0
|
||||
}
|
||||
|
||||
// CanFight 检查玩家是否可以进行战斗
|
||||
// 0无战斗,1PVP,2,BOOS,3PVE
|
||||
func (p *Player) CanFight() errorcode.ErrorCode {
|
||||
@@ -419,7 +434,15 @@ func (p *Player) ItemAdd(ItemId, ItemCnt int64) (result bool) {
|
||||
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||
return false
|
||||
}
|
||||
p.Service.Item.UPDATE(uint32(ItemId), gconv.Int(ItemCnt))
|
||||
if err := p.Service.Item.UPDATE(uint32(ItemId), gconv.Int(ItemCnt)); err != nil {
|
||||
cool.Logger.Error(context.TODO(), "item add update failed", p.Info.UserID, ItemId, ItemCnt, err)
|
||||
|
||||
t1 := common.NewTomeeHeader(2601, p.Info.UserID)
|
||||
t1.Result = uint32(errorcode.ErrorCodes.ErrSystemError200007)
|
||||
|
||||
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,11 @@ type Space struct {
|
||||
WeatherType []uint32
|
||||
TimeBoss info.S2C_2022
|
||||
|
||||
IsTime bool
|
||||
DropItemIds []uint32
|
||||
PitS *csmap.CsMap[int, []model.MapPit]
|
||||
MapNodeS *csmap.CsMap[uint32, *model.MapNode]
|
||||
IsTime bool
|
||||
IsLevelBreakMap bool
|
||||
DropItemIds []uint32
|
||||
PitS *csmap.CsMap[int, []model.MapPit]
|
||||
MapNodeS *csmap.CsMap[uint32, *model.MapNode]
|
||||
}
|
||||
|
||||
func NewSpace() *Space {
|
||||
@@ -185,6 +186,9 @@ func (ret *Space) init() {
|
||||
if r.IsTimeSpace != 0 {
|
||||
ret.IsTime = true
|
||||
}
|
||||
if r.IsLevelBreakMap != 0 {
|
||||
ret.IsLevelBreakMap = true
|
||||
}
|
||||
ret.MapBossSInfo = info.MapModelBroadcastInfo{}
|
||||
ret.MapBossSInfo.INFO = make([]info.MapModelBroadcastEntry, 0)
|
||||
|
||||
|
||||
@@ -1,94 +1,97 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"blazing/common/rpc"
|
||||
"blazing/cool"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/yudeguang/ratelimit"
|
||||
|
||||
i18n "blazing/modules/base/middleware"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/xiaoqidun/qqwry"
|
||||
)
|
||||
|
||||
var (
|
||||
Main = gcmd.Command{
|
||||
Name: "main",
|
||||
Usage: "main",
|
||||
Brief: "start http server",
|
||||
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
|
||||
|
||||
r := parser.GetOpt("debug", false)
|
||||
if r.Bool() {
|
||||
g.DB().SetDebug(true)
|
||||
// service.NewServerService().SetServerScreen(0, "sss")
|
||||
cool.Config.ServerInfo.IsDebug = 1
|
||||
}
|
||||
if cool.IsRedisMode {
|
||||
go rpc.ListenFunc(ctx)
|
||||
}
|
||||
// // 从文件加载IP数据库
|
||||
if err := qqwry.LoadFile("public/qqwry.ipdb"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//go robot()
|
||||
//go reg()
|
||||
go startrobot()
|
||||
s := g.Server()
|
||||
s.Use(Limiter, ghttp.MiddlewareHandlerResponse)
|
||||
s.EnableAdmin()
|
||||
s.SetServerAgent(cool.Config.Name)
|
||||
s.BindHookHandler("/*", ghttp.HookBeforeServe, beforeServeHook)
|
||||
// runtime.SetMutexProfileFraction(1) // (非必需)开启对锁调用的跟踪
|
||||
// runtime.SetBlockProfileRate(1) // (非必需)开启对阻塞操作的跟踪
|
||||
// s.EnablePProf()
|
||||
// 如果存在 data/cool-admin-vue/dist 目录,则设置为主目录
|
||||
if gfile.IsDir("public") {
|
||||
s.SetServerRoot("public")
|
||||
}
|
||||
// i18n 信息
|
||||
s.BindHandler("/i18n", i18n.I18nInfo)
|
||||
// g.Server().BindMiddleware("/*", MiddlewareCORS)
|
||||
s.Run()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func beforeServeHook(r *ghttp.Request) {
|
||||
//glog.Debugf(r.GetCtx(), "beforeServeHook [is file:%v] URI:%s", r.IsFileRequest(), r.RequestURI)
|
||||
r.Response.CORSDefault()
|
||||
}
|
||||
|
||||
// var limiter = rate.NewLimiter(rate.Limit(150), 50)
|
||||
var limiter *ratelimit.Rule = ratelimit.NewRule()
|
||||
|
||||
// 简单规则案例
|
||||
func init() {
|
||||
|
||||
//步骤二:增加一条或者多条规则组成复合规则,此复合规则必须至少包含一条规则
|
||||
limiter.AddRule(time.Second*1, 20)
|
||||
//步骤三:调用函数判断某用户是否允许访问 allow:= r.AllowVisit(user)
|
||||
|
||||
}
|
||||
|
||||
// Limiter is a middleware that implements rate limiting for all HTTP requests.
|
||||
// It returns HTTP 429 (Too Many Requests) when the rate limit is exceeded.
|
||||
func Limiter(r *ghttp.Request) {
|
||||
// 3. 为任意键 "some-key" 获取一个速率限制器
|
||||
// - rate.Limit(2): 表示速率为 "每秒2个请求"
|
||||
// - 2: 表示桶的容量 (Burst),允许瞬时处理2个请求
|
||||
ip := r.GetClientIp()
|
||||
if !limiter.AllowVisitByIP4(ip) {
|
||||
r.Response.WriteStatusExit(429) // Return 429 Too Many Requests
|
||||
|
||||
r.ExitAll()
|
||||
}
|
||||
r.Middleware.Next()
|
||||
}
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"blazing/common/rpc"
|
||||
"blazing/cool"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/yudeguang/ratelimit"
|
||||
|
||||
i18n "blazing/modules/base/middleware"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/xiaoqidun/qqwry"
|
||||
)
|
||||
|
||||
var (
|
||||
Main = gcmd.Command{
|
||||
Name: "main",
|
||||
Usage: "main",
|
||||
Brief: "start http server",
|
||||
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
|
||||
|
||||
r := parser.GetOpt("debug", false)
|
||||
if r.Bool() {
|
||||
g.DB().SetDebug(true)
|
||||
// service.NewServerService().SetServerScreen(0, "sss")
|
||||
cool.Config.ServerInfo.IsDebug = 1
|
||||
}
|
||||
if err = cool.RunAutoMigrate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if cool.IsRedisMode {
|
||||
go rpc.ListenFunc(ctx)
|
||||
}
|
||||
// // 从文件加载IP数据库
|
||||
if err := qqwry.LoadFile("public/qqwry.ipdb"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//go robot()
|
||||
//go reg()
|
||||
go startrobot()
|
||||
s := g.Server()
|
||||
s.Use(Limiter, ghttp.MiddlewareHandlerResponse)
|
||||
s.EnableAdmin()
|
||||
s.SetServerAgent(cool.Config.Name)
|
||||
s.BindHookHandler("/*", ghttp.HookBeforeServe, beforeServeHook)
|
||||
// runtime.SetMutexProfileFraction(1) // (非必需)开启对锁调用的跟踪
|
||||
// runtime.SetBlockProfileRate(1) // (非必需)开启对阻塞操作的跟踪
|
||||
// s.EnablePProf()
|
||||
// 如果存在 data/cool-admin-vue/dist 目录,则设置为主目录
|
||||
if gfile.IsDir("public") {
|
||||
s.SetServerRoot("public")
|
||||
}
|
||||
// i18n 信息
|
||||
s.BindHandler("/i18n", i18n.I18nInfo)
|
||||
// g.Server().BindMiddleware("/*", MiddlewareCORS)
|
||||
s.Run()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func beforeServeHook(r *ghttp.Request) {
|
||||
//glog.Debugf(r.GetCtx(), "beforeServeHook [is file:%v] URI:%s", r.IsFileRequest(), r.RequestURI)
|
||||
r.Response.CORSDefault()
|
||||
}
|
||||
|
||||
// var limiter = rate.NewLimiter(rate.Limit(150), 50)
|
||||
var limiter *ratelimit.Rule = ratelimit.NewRule()
|
||||
|
||||
// 简单规则案例
|
||||
func init() {
|
||||
|
||||
//步骤二:增加一条或者多条规则组成复合规则,此复合规则必须至少包含一条规则
|
||||
limiter.AddRule(time.Second*1, 20)
|
||||
//步骤三:调用函数判断某用户是否允许访问 allow:= r.AllowVisit(user)
|
||||
|
||||
}
|
||||
|
||||
// Limiter is a middleware that implements rate limiting for all HTTP requests.
|
||||
// It returns HTTP 429 (Too Many Requests) when the rate limit is exceeded.
|
||||
func Limiter(r *ghttp.Request) {
|
||||
// 3. 为任意键 "some-key" 获取一个速率限制器
|
||||
// - rate.Limit(2): 表示速率为 "每秒2个请求"
|
||||
// - 2: 表示桶的容量 (Burst),允许瞬时处理2个请求
|
||||
ip := r.GetClientIp()
|
||||
if !limiter.AllowVisitByIP4(ip) {
|
||||
r.Response.WriteStatusExit(429) // Return 429 Too Many Requests
|
||||
|
||||
r.ExitAll()
|
||||
}
|
||||
r.Middleware.Next()
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,8 @@ type MapConfig struct {
|
||||
WeatherType []uint32 `gorm:"type:int[];comment:'天气类型( 0 晴天,1-雨天,2-雪天)'" json:"weather_type"`
|
||||
//是否超时空
|
||||
IsTimeSpace int `gorm:"type:int;default:0;comment:'是否超时空'" json:"is_time_space"`
|
||||
// 是否等级突破地图
|
||||
IsLevelBreakMap int `gorm:"type:int;default:0;comment:'是否等级突破地图'" json:"is_level_break_map"`
|
||||
|
||||
// 掉落物配置
|
||||
DropItemIds []uint32 `gorm:"type:int[];comment:'掉落物IDs" json:"drop_item_ids"`
|
||||
|
||||
@@ -20,6 +20,13 @@ func NewShinyService() *ShinyService {
|
||||
return &ShinyService{
|
||||
&cool.Service{
|
||||
Model: model.NewColorfulSkin(),
|
||||
ListQueryOp: &cool.QueryOp{
|
||||
Where: func(ctx context.Context) []g.Array {
|
||||
return []g.Array{
|
||||
{"is_enable", 1},
|
||||
}
|
||||
},
|
||||
},
|
||||
InsertParam: func(ctx context.Context) g.MapStrAny {
|
||||
admin := cool.GetAdmin(ctx)
|
||||
userId := admin.UserId
|
||||
|
||||
@@ -52,6 +52,10 @@ func init() {
|
||||
ctx.Send("扭蛋币不足,当前扭蛋币数量:" + gconv.String(havs))
|
||||
return
|
||||
}
|
||||
if err := itemService.UPDATE(400501, -count); err != nil {
|
||||
ctx.Send("扭蛋币不足,当前扭蛋币数量:" + gconv.String(havs))
|
||||
return
|
||||
}
|
||||
|
||||
var buf strings.Builder
|
||||
buf.WriteString("当前扭蛋币数量:" + gconv.String(havs) + "\n")
|
||||
@@ -140,8 +144,6 @@ func init() {
|
||||
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()))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ func (m *PlayerInfo) SetTask(i int, status TaskStatus) error {
|
||||
// GetTask 获取第 i 个任务的状态
|
||||
func (m *PlayerInfo) GetTask(i int) TaskStatus {
|
||||
i-- //下标减1
|
||||
if i < 0 || i >= 2000 {
|
||||
if i < 0 || i >= 4000 {
|
||||
return Reserved
|
||||
}
|
||||
|
||||
|
||||
@@ -532,18 +532,20 @@ func (petinfo *PetInfo) Update(isup bool) {
|
||||
if evolveCount >= maxEvolveTimes {
|
||||
break
|
||||
}
|
||||
// 进化完成后,统一更新经验(原逻辑保留)
|
||||
petinfo.LvExp = petinfo.NextLvExp
|
||||
// 获取当前宠物形态的配置
|
||||
basic, ok := xmlres.PetMAP[int(petinfo.ID)]
|
||||
// 配置不存在,直接退出循环
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
petinfo.NextLvExp = calculateExperience(petinfo.Level, basic.GetBasic())
|
||||
if !isup {
|
||||
petinfo.LvExp = calculatePreviousLevelExperience(petinfo.Level, basic.GetBasic())
|
||||
petinfo.NextLvExp = calculateExperience(petinfo.Level, basic.GetBasic())
|
||||
return
|
||||
}
|
||||
// 升级时保留上一等级需求,供经验结算使用。
|
||||
petinfo.LvExp = petinfo.NextLvExp
|
||||
petinfo.NextLvExp = calculateExperience(petinfo.Level, basic.GetBasic())
|
||||
// 检查是否满足进化条件
|
||||
canEvolve := basic.EvolvesTo != 0 && // 有明确的进化目标
|
||||
int(petinfo.Level) >= basic.EvolvingLv && // 等级达到进化要求
|
||||
@@ -561,6 +563,13 @@ func (petinfo *PetInfo) Update(isup bool) {
|
||||
|
||||
}
|
||||
|
||||
func calculatePreviousLevelExperience(level uint32, baseValue uint32) int64 {
|
||||
if level <= 1 {
|
||||
return 0
|
||||
}
|
||||
return calculateExperience(level-1, baseValue)
|
||||
}
|
||||
|
||||
// calculateExperience 计算指定等级和种族值所需的经验值
|
||||
// level: 当前等级
|
||||
// baseValue: 种族值
|
||||
|
||||
@@ -110,11 +110,19 @@ func buildJSONBArrayAnyCondition(column string, values []uint32) (string, []any)
|
||||
clauses := make([]string, 0, len(values)+1)
|
||||
params := make([]any, 0, len(values)+1)
|
||||
for _, value := range values {
|
||||
clauses = append(clauses, fmt.Sprintf(`CAST(? AS text) = ANY(ARRAY(SELECT jsonb_array_elements_text(%s)))`, column))
|
||||
clauses = append(clauses, fmt.Sprintf(
|
||||
`EXISTS (SELECT 1 FROM jsonb_array_elements_text(CASE WHEN jsonb_typeof(%s) = 'array' THEN %s ELSE '[]'::jsonb END) AS elem WHERE elem = CAST(? AS text))`,
|
||||
column,
|
||||
column,
|
||||
))
|
||||
params = append(params, value)
|
||||
}
|
||||
|
||||
clauses = append(clauses, fmt.Sprintf(`jsonb_array_length(%s) = ?`, column))
|
||||
clauses = append(clauses, fmt.Sprintf(
|
||||
`CASE WHEN jsonb_typeof(%s) = 'array' THEN jsonb_array_length(%s) ELSE -1 END = ?`,
|
||||
column,
|
||||
column,
|
||||
))
|
||||
params = append(params, len(values))
|
||||
|
||||
return strings.Join(clauses, " AND "), params
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
dictservice "blazing/modules/dict/service"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
@@ -58,12 +59,28 @@ func (s *ItemService) UPDATE(id uint32, count int) error {
|
||||
return err
|
||||
}
|
||||
if ok {
|
||||
_, err := s.dbm(s.Model).Where("item_id", id).Increment("item_cnt", count)
|
||||
updateModel := s.dbm(s.Model).Where("item_id", id)
|
||||
if count < 0 {
|
||||
updateModel = updateModel.Where("item_cnt + ? >= 0", count)
|
||||
}
|
||||
|
||||
result, err := updateModel.Increment("item_cnt", count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
affected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
return gerror.New("item update failed: no rows affected")
|
||||
}
|
||||
|
||||
} else {
|
||||
if count <= 0 {
|
||||
return gerror.New("item update failed: cannot insert non-positive item count")
|
||||
}
|
||||
m := s.dbm(s.Model)
|
||||
data := g.Map{
|
||||
"player_id": s.userid,
|
||||
|
||||
@@ -76,8 +76,12 @@ func (s *PetService) PetCount(flag int) int {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (s *PetService) UpdateFree(catchTime, free uint32) bool {
|
||||
res, err := s.dbm(s.Model).Where("catch_time", catchTime).Data("free", free).Update()
|
||||
func (s *PetService) UpdateFree(catchTime, fromFree, toFree uint32) bool {
|
||||
res, err := s.dbm(s.Model).
|
||||
Where("catch_time", catchTime).
|
||||
Where("free", fromFree).
|
||||
Data("free", toFree).
|
||||
Update()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
297
modules/player/service/pet_fusion_tx.go
Normal file
297
modules/player/service/pet_fusion_tx.go
Normal file
@@ -0,0 +1,297 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/cool"
|
||||
baseservice "blazing/modules/base/service"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
var (
|
||||
errPetFusionInsufficientItems = errors.New("pet fusion insufficient items")
|
||||
errPetFusionPetNotFound = errors.New("pet fusion pet not found")
|
||||
errPetFusionPlayerNotFound = errors.New("pet fusion player not found")
|
||||
)
|
||||
|
||||
type PetFusionTxResult struct {
|
||||
NewPet *model.PetInfo
|
||||
CostItemUsed bool
|
||||
UpdatedAux *model.PetInfo
|
||||
}
|
||||
|
||||
func (s *UserService) PetFusionTx(
|
||||
currentInfo model.PlayerInfo,
|
||||
masterCatchTime uint32,
|
||||
auxCatchTime uint32,
|
||||
materialCounts map[uint32]int,
|
||||
goldItemIDs []uint32,
|
||||
keepAuxItemID uint32,
|
||||
failureItemID uint32,
|
||||
cost int64,
|
||||
newPet *model.PetInfo,
|
||||
failedAux *model.PetInfo,
|
||||
) (*PetFusionTxResult, errorcode.ErrorCode) {
|
||||
if s == nil || s.Pet == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
userID := s.Pet.userid
|
||||
nextInfo := currentInfo
|
||||
if nextInfo.Coins < cost {
|
||||
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
||||
}
|
||||
nextInfo.Coins -= cost
|
||||
|
||||
result := &PetFusionTxResult{}
|
||||
err := g.DB().Transaction(context.TODO(), func(ctx context.Context, tx gdb.TX) error {
|
||||
if err := updatePlayerInfoTx(tx, userID, nextInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := consumeItemCountsTx(tx, userID, materialCounts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if newPet == nil {
|
||||
used, err := consumeOptionalItemTx(tx, userID, goldItemIDs, failureItemID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result.CostItemUsed = used
|
||||
if !used && failedAux != nil {
|
||||
if err := updatePetDataTx(tx, userID, auxCatchTime, *failedAux); err != nil {
|
||||
return err
|
||||
}
|
||||
auxCopy := *failedAux
|
||||
result.UpdatedAux = &auxCopy
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := syncPetSnapshotBeforeDeleteTx(tx, userID, currentInfo, masterCatchTime); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deletePetTx(tx, userID, masterCatchTime); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
used, err := consumeOptionalItemTx(tx, userID, goldItemIDs, keepAuxItemID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result.CostItemUsed = used
|
||||
if !used {
|
||||
if err := syncPetSnapshotBeforeDeleteTx(tx, userID, currentInfo, auxCatchTime); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deletePetTx(tx, userID, auxCatchTime); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
catchTime, err := addPetTx(tx, s.Pet, newPet, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
petCopy := *newPet
|
||||
petCopy.CatchTime = catchTime
|
||||
result.NewPet = &petCopy
|
||||
return nil
|
||||
})
|
||||
if err == nil {
|
||||
return result, 0
|
||||
}
|
||||
|
||||
switch {
|
||||
case errors.Is(err, errPetFusionInsufficientItems):
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
case errors.Is(err, errPetFusionPetNotFound):
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotFusionReady2
|
||||
case errors.Is(err, errPetFusionPlayerNotFound):
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
default:
|
||||
cool.Logger.Error(context.TODO(), "pet fusion tx failed", userID, err)
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
}
|
||||
|
||||
func updatePlayerInfoTx(tx gdb.TX, userID uint32, info model.PlayerInfo) error {
|
||||
res, err := tx.Model(model.NewPlayer()).Where("player_id", userID).Data("data", info).Update()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
affected, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
return errPetFusionPlayerNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func consumeItemCountsTx(tx gdb.TX, userID uint32, itemCounts map[uint32]int) error {
|
||||
for itemID, count := range itemCounts {
|
||||
if err := updateItemCountTx(tx, userID, itemID, -count); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func consumeOptionalItemTx(tx gdb.TX, userID uint32, itemIDs []uint32, target uint32) (bool, error) {
|
||||
for _, itemID := range itemIDs {
|
||||
if itemID != target {
|
||||
continue
|
||||
}
|
||||
if err := updateItemCountTx(tx, userID, target, -1); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func updateItemCountTx(tx gdb.TX, userID uint32, id uint32, count int) error {
|
||||
if cool.Config.ServerInfo.IsVip != 0 && count < 0 {
|
||||
return nil
|
||||
}
|
||||
if id == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
baseModel := tx.Model(model.NewPlayerBag()).
|
||||
Where("player_id", userID).
|
||||
Where("is_vip", cool.Config.ServerInfo.IsVip)
|
||||
|
||||
ok, err := baseModel.Where("item_id", id).Exist()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ok {
|
||||
updateModel := tx.Model(model.NewPlayerBag()).
|
||||
Where("player_id", userID).
|
||||
Where("is_vip", cool.Config.ServerInfo.IsVip).
|
||||
Where("item_id", id)
|
||||
if count < 0 {
|
||||
updateModel = updateModel.Where("item_cnt + ? >= 0", count)
|
||||
}
|
||||
|
||||
result, err := updateModel.Increment("item_cnt", count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
affected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
return errPetFusionInsufficientItems
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if count <= 0 {
|
||||
return errPetFusionInsufficientItems
|
||||
}
|
||||
|
||||
_, err = tx.Model(model.NewPlayerBag()).Data(g.Map{
|
||||
"player_id": userID,
|
||||
"item_id": id,
|
||||
"item_cnt": count,
|
||||
"is_vip": cool.Config.ServerInfo.IsVip,
|
||||
}).Insert()
|
||||
return err
|
||||
}
|
||||
|
||||
func updatePetDataTx(tx gdb.TX, userID uint32, catchTime uint32, pet model.PetInfo) error {
|
||||
res, err := tx.Model(model.NewPet()).
|
||||
Where("player_id", userID).
|
||||
Where("is_vip", cool.Config.ServerInfo.IsVip).
|
||||
Where("catch_time", catchTime).
|
||||
Data("data", pet).
|
||||
Update()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
affected, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
return errPetFusionPetNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func syncPetSnapshotBeforeDeleteTx(tx gdb.TX, userID uint32, info model.PlayerInfo, catchTime uint32) error {
|
||||
pet, ok := findPetDataSnapshotInPlayerInfo(info, catchTime)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return updatePetDataTx(tx, userID, catchTime, pet)
|
||||
}
|
||||
|
||||
func findPetDataSnapshotInPlayerInfo(info model.PlayerInfo, catchTime uint32) (model.PetInfo, bool) {
|
||||
for i := range info.PetList {
|
||||
if info.PetList[i].CatchTime == catchTime {
|
||||
return info.PetList[i], true
|
||||
}
|
||||
}
|
||||
for i := range info.BackupPetList {
|
||||
if info.BackupPetList[i].CatchTime == catchTime {
|
||||
return info.BackupPetList[i], true
|
||||
}
|
||||
}
|
||||
return model.PetInfo{}, false
|
||||
}
|
||||
|
||||
func deletePetTx(tx gdb.TX, userID uint32, catchTime uint32) error {
|
||||
res, err := tx.Model(model.NewPet()).
|
||||
Where("player_id", userID).
|
||||
Where("is_vip", cool.Config.ServerInfo.IsVip).
|
||||
Where("catch_time", catchTime).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
affected, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
return errPetFusionPetNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addPetTx(tx gdb.TX, petService *PetService, petInfo *model.PetInfo, saleCount uint32) (uint32, error) {
|
||||
if petInfo == nil {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
catchTime, err := petService.nextCatchTime(tx.Model(baseservice.NewBaseSysUserService().Model))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
petCopy := *petInfo
|
||||
petCopy.CatchTime = catchTime
|
||||
playerPet := model.Pet{
|
||||
PlayerID: petService.userid,
|
||||
Data: petCopy,
|
||||
CatchTime: catchTime,
|
||||
Free: 0,
|
||||
SaleCount: saleCount,
|
||||
}
|
||||
playerPet.IsVip = cool.Config.ServerInfo.IsVip
|
||||
if _, err := tx.Model(model.NewPet()).Insert(playerPet); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return catchTime, nil
|
||||
}
|
||||
50
modules/player/service/pet_fusion_tx_test.go
Normal file
50
modules/player/service/pet_fusion_tx_test.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/modules/player/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFindPetDataSnapshotInPlayerInfo(t *testing.T) {
|
||||
t.Run("pet list", func(t *testing.T) {
|
||||
want := model.PetInfo{CatchTime: 1001, Level: 55}
|
||||
info := model.PlayerInfo{
|
||||
PetList: []model.PetInfo{want},
|
||||
}
|
||||
|
||||
got, ok := findPetDataSnapshotInPlayerInfo(info, want.CatchTime)
|
||||
if !ok {
|
||||
t.Fatal("expected pet snapshot in pet list")
|
||||
}
|
||||
if got.CatchTime != want.CatchTime || got.Level != want.Level {
|
||||
t.Fatalf("unexpected pet snapshot: %+v", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("backup pet list", func(t *testing.T) {
|
||||
want := model.PetInfo{CatchTime: 2002, Level: 66}
|
||||
info := model.PlayerInfo{
|
||||
BackupPetList: []model.PetInfo{want},
|
||||
}
|
||||
|
||||
got, ok := findPetDataSnapshotInPlayerInfo(info, want.CatchTime)
|
||||
if !ok {
|
||||
t.Fatal("expected pet snapshot in backup pet list")
|
||||
}
|
||||
if got.CatchTime != want.CatchTime || got.Level != want.Level {
|
||||
t.Fatalf("unexpected pet snapshot: %+v", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("not found", func(t *testing.T) {
|
||||
info := model.PlayerInfo{
|
||||
PetList: []model.PetInfo{{CatchTime: 3003}},
|
||||
BackupPetList: []model.PetInfo{{CatchTime: 4004}},
|
||||
}
|
||||
|
||||
_, ok := findPetDataSnapshotInPlayerInfo(info, 9999)
|
||||
if ok {
|
||||
t.Fatal("expected missing pet snapshot")
|
||||
}
|
||||
})
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user