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 {
|
||||
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)
|
||||
}
|
||||
if err := c.Service.Item.UPDATE(400501, int(-data1.EggNum)); err != nil {
|
||||
|
||||
@@ -15,21 +15,18 @@ func petSetExpLimit(currentPet *playermodel.PetInfo) int64 {
|
||||
}
|
||||
|
||||
simulatedPet := *currentPet
|
||||
var allowedExp int64
|
||||
allowedExp := simulatedPet.NextLvExp - simulatedPet.Exp
|
||||
if allowedExp < 0 {
|
||||
allowedExp = 0
|
||||
}
|
||||
|
||||
for simulatedPet.Level < 100 {
|
||||
needExp := simulatedPet.NextLvExp - simulatedPet.Exp
|
||||
if needExp <= 0 {
|
||||
simulatedPet.Exp = simulatedPet.NextLvExp
|
||||
simulatedPet.Level++
|
||||
simulatedPet.Update(true)
|
||||
continue
|
||||
}
|
||||
|
||||
allowedExp += needExp
|
||||
simulatedPet.Exp += needExp
|
||||
for simulatedPet.Level < 100 && simulatedPet.NextLvExp > 0 {
|
||||
simulatedPet.Level++
|
||||
simulatedPet.Update(true)
|
||||
if simulatedPet.Level >= 100 {
|
||||
break
|
||||
}
|
||||
allowedExp += simulatedPet.NextLvExp
|
||||
}
|
||||
|
||||
return allowedExp
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -35,15 +35,21 @@ func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
||||
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 exp >= int64(petInfo.NextLvExp) {
|
||||
|
||||
currentExp := petInfo.Exp + addExp
|
||||
for currentExp >= petInfo.NextLvExp && petInfo.NextLvExp > 0 {
|
||||
petInfo.Level++
|
||||
petInfo.Update(true)
|
||||
currentExp -= petInfo.LvExp
|
||||
}
|
||||
petInfo.Exp = (exp)
|
||||
petInfo.Exp = currentExp
|
||||
|
||||
// 重新计算面板
|
||||
if originalLevel != petInfo.Level {
|
||||
petInfo.CalculatePetPane(panelLimit)
|
||||
@@ -78,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)) //准备包由各自发,因为协议不一样
|
||||
|
||||
|
||||
@@ -87,3 +87,71 @@ func TestAddPetExpRecalculatesPanelForLevelAbove100(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user