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 {
|
||||
|
||||
@@ -35,15 +35,32 @@ 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
|
||||
p.Info.ExpPool -= addExp //减去已使用的经验
|
||||
gainedExp := exp //已获得的经验
|
||||
for exp >= int64(petInfo.NextLvExp) {
|
||||
|
||||
remainingExp := addExp
|
||||
for remainingExp > 0 {
|
||||
needExp := petInfo.NextLvExp - petInfo.Exp
|
||||
if needExp <= 0 {
|
||||
petInfo.Exp = petInfo.NextLvExp
|
||||
petInfo.Level++
|
||||
petInfo.Update(true)
|
||||
continue
|
||||
}
|
||||
if remainingExp < needExp {
|
||||
petInfo.Exp += remainingExp
|
||||
break
|
||||
}
|
||||
|
||||
petInfo.Exp += needExp
|
||||
remainingExp -= needExp
|
||||
petInfo.Level++
|
||||
petInfo.Update(true)
|
||||
}
|
||||
petInfo.Exp = (exp)
|
||||
|
||||
// 重新计算面板
|
||||
if originalLevel != petInfo.Level {
|
||||
petInfo.CalculatePetPane(panelLimit)
|
||||
@@ -78,7 +95,6 @@ func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
||||
var petUpdateInfo info.UpdatePropInfo
|
||||
|
||||
copier.Copy(&petUpdateInfo, petInfo)
|
||||
petUpdateInfo.Exp = uint32(gainedExp)
|
||||
updateOutbound.Data = append(updateOutbound.Data, petUpdateInfo)
|
||||
p.SendPack(header.Pack(updateOutbound)) //准备包由各自发,因为协议不一样
|
||||
|
||||
|
||||
@@ -87,3 +87,38 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func init() {
|
||||
}
|
||||
|
||||
havs := itemService.CheakItem(400501)
|
||||
if havs <= int64(count) {
|
||||
if havs < int64(count) {
|
||||
ctx.Send("扭蛋币不足,当前扭蛋币数量:" + gconv.String(havs))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user