Merge branch 'main' of https://cnb.cool/blzing/blazing
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -26,7 +26,7 @@ func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (res
|
|||||||
if data1.EggNum > 10 || data1.EggNum <= 0 {
|
if data1.EggNum > 10 || data1.EggNum <= 0 {
|
||||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
|
||||||
}
|
}
|
||||||
if r <= 0 || data1.EggNum >= r {
|
if r <= 0 || data1.EggNum > r {
|
||||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
||||||
}
|
}
|
||||||
if err := c.Service.Item.UPDATE(400501, int(-data1.EggNum)); err != nil {
|
if err := c.Service.Item.UPDATE(400501, int(-data1.EggNum)); err != nil {
|
||||||
|
|||||||
@@ -15,21 +15,18 @@ func petSetExpLimit(currentPet *playermodel.PetInfo) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
simulatedPet := *currentPet
|
simulatedPet := *currentPet
|
||||||
var allowedExp int64
|
allowedExp := simulatedPet.NextLvExp - simulatedPet.Exp
|
||||||
|
if allowedExp < 0 {
|
||||||
|
allowedExp = 0
|
||||||
|
}
|
||||||
|
|
||||||
for simulatedPet.Level < 100 {
|
for simulatedPet.Level < 100 && simulatedPet.NextLvExp > 0 {
|
||||||
needExp := simulatedPet.NextLvExp - simulatedPet.Exp
|
|
||||||
if needExp <= 0 {
|
|
||||||
simulatedPet.Exp = simulatedPet.NextLvExp
|
|
||||||
simulatedPet.Level++
|
|
||||||
simulatedPet.Update(true)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
allowedExp += needExp
|
|
||||||
simulatedPet.Exp += needExp
|
|
||||||
simulatedPet.Level++
|
simulatedPet.Level++
|
||||||
simulatedPet.Update(true)
|
simulatedPet.Update(true)
|
||||||
|
if simulatedPet.Level >= 100 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
allowedExp += simulatedPet.NextLvExp
|
||||||
}
|
}
|
||||||
|
|
||||||
return allowedExp
|
return allowedExp
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
package player
|
package player
|
||||||
|
|
||||||
|
import "blazing/modules/player/model"
|
||||||
|
|
||||||
type AI_player struct {
|
type AI_player struct {
|
||||||
baseplayer
|
baseplayer
|
||||||
|
|
||||||
CanCapture int
|
CanCapture int
|
||||||
BossScript string
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,15 +35,21 @@ func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
|||||||
petInfo.Hp = utils.Min(currentHP, petInfo.MaxHp)
|
petInfo.Hp = utils.Min(currentHP, petInfo.MaxHp)
|
||||||
}
|
}
|
||||||
addExp = utils.Min(addExp, p.Info.ExpPool)
|
addExp = utils.Min(addExp, p.Info.ExpPool)
|
||||||
|
if addExp <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
originalLevel := petInfo.Level
|
originalLevel := petInfo.Level
|
||||||
exp := int64(petInfo.Exp) + addExp
|
allocatedExp := addExp
|
||||||
p.Info.ExpPool -= addExp //减去已使用的经验
|
p.Info.ExpPool -= addExp //减去已使用的经验
|
||||||
gainedExp := exp //已获得的经验
|
|
||||||
for exp >= int64(petInfo.NextLvExp) {
|
currentExp := petInfo.Exp + addExp
|
||||||
|
for currentExp >= petInfo.NextLvExp && petInfo.NextLvExp > 0 {
|
||||||
petInfo.Level++
|
petInfo.Level++
|
||||||
petInfo.Update(true)
|
petInfo.Update(true)
|
||||||
|
currentExp -= petInfo.LvExp
|
||||||
}
|
}
|
||||||
petInfo.Exp = (exp)
|
petInfo.Exp = currentExp
|
||||||
|
|
||||||
// 重新计算面板
|
// 重新计算面板
|
||||||
if originalLevel != petInfo.Level {
|
if originalLevel != petInfo.Level {
|
||||||
petInfo.CalculatePetPane(panelLimit)
|
petInfo.CalculatePetPane(panelLimit)
|
||||||
@@ -78,7 +84,7 @@ func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
|||||||
var petUpdateInfo info.UpdatePropInfo
|
var petUpdateInfo info.UpdatePropInfo
|
||||||
|
|
||||||
copier.Copy(&petUpdateInfo, petInfo)
|
copier.Copy(&petUpdateInfo, petInfo)
|
||||||
petUpdateInfo.Exp = uint32(gainedExp)
|
petUpdateInfo.Exp = uint32(allocatedExp)
|
||||||
updateOutbound.Data = append(updateOutbound.Data, petUpdateInfo)
|
updateOutbound.Data = append(updateOutbound.Data, petUpdateInfo)
|
||||||
p.SendPack(header.Pack(updateOutbound)) //准备包由各自发,因为协议不一样
|
p.SendPack(header.Pack(updateOutbound)) //准备包由各自发,因为协议不一样
|
||||||
|
|
||||||
|
|||||||
@@ -87,3 +87,71 @@ func TestAddPetExpRecalculatesPanelForLevelAbove100(t *testing.T) {
|
|||||||
t.Fatalf("expected exp pool to be consumed normally, got %d", player.Info.ExpPool)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
havs := itemService.CheakItem(400501)
|
havs := itemService.CheakItem(400501)
|
||||||
if havs <= int64(count) {
|
if havs < int64(count) {
|
||||||
ctx.Send("扭蛋币不足,当前扭蛋币数量:" + gconv.String(havs))
|
ctx.Send("扭蛋币不足,当前扭蛋币数量:" + gconv.String(havs))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -532,18 +532,20 @@ func (petinfo *PetInfo) Update(isup bool) {
|
|||||||
if evolveCount >= maxEvolveTimes {
|
if evolveCount >= maxEvolveTimes {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// 进化完成后,统一更新经验(原逻辑保留)
|
|
||||||
petinfo.LvExp = petinfo.NextLvExp
|
|
||||||
// 获取当前宠物形态的配置
|
// 获取当前宠物形态的配置
|
||||||
basic, ok := xmlres.PetMAP[int(petinfo.ID)]
|
basic, ok := xmlres.PetMAP[int(petinfo.ID)]
|
||||||
// 配置不存在,直接退出循环
|
// 配置不存在,直接退出循环
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
petinfo.NextLvExp = calculateExperience(petinfo.Level, basic.GetBasic())
|
|
||||||
if !isup {
|
if !isup {
|
||||||
|
petinfo.LvExp = calculatePreviousLevelExperience(petinfo.Level, basic.GetBasic())
|
||||||
|
petinfo.NextLvExp = calculateExperience(petinfo.Level, basic.GetBasic())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 升级时保留上一等级需求,供经验结算使用。
|
||||||
|
petinfo.LvExp = petinfo.NextLvExp
|
||||||
|
petinfo.NextLvExp = calculateExperience(petinfo.Level, basic.GetBasic())
|
||||||
// 检查是否满足进化条件
|
// 检查是否满足进化条件
|
||||||
canEvolve := basic.EvolvesTo != 0 && // 有明确的进化目标
|
canEvolve := basic.EvolvesTo != 0 && // 有明确的进化目标
|
||||||
int(petinfo.Level) >= basic.EvolvingLv && // 等级达到进化要求
|
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 计算指定等级和种族值所需的经验值
|
// calculateExperience 计算指定等级和种族值所需的经验值
|
||||||
// level: 当前等级
|
// level: 当前等级
|
||||||
// baseValue: 种族值
|
// baseValue: 种族值
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func (s *ItemService) UPDATE(id uint32, count int) error {
|
|||||||
if ok {
|
if ok {
|
||||||
updateModel := s.dbm(s.Model).Where("item_id", id)
|
updateModel := s.dbm(s.Model).Where("item_id", id)
|
||||||
if count < 0 {
|
if count < 0 {
|
||||||
updateModel = updateModel.Where("item_cnt + ? > 0", count)
|
updateModel = updateModel.Where("item_cnt + ? >= 0", count)
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := updateModel.Increment("item_cnt", count)
|
result, err := updateModel.Increment("item_cnt", count)
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ func updateItemCountTx(tx gdb.TX, userID uint32, id uint32, count int) error {
|
|||||||
Where("is_vip", cool.Config.ServerInfo.IsVip).
|
Where("is_vip", cool.Config.ServerInfo.IsVip).
|
||||||
Where("item_id", id)
|
Where("item_id", id)
|
||||||
if count < 0 {
|
if count < 0 {
|
||||||
updateModel = updateModel.Where("item_cnt + ? > 0", count)
|
updateModel = updateModel.Where("item_cnt + ? >= 0", count)
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := updateModel.Increment("item_cnt", count)
|
result, err := updateModel.Increment("item_cnt", count)
|
||||||
|
|||||||
Reference in New Issue
Block a user