fix: 修正宠物面板计算参数

This commit is contained in:
xinian
2026-03-23 22:00:05 +08:00
committed by cnb
parent 705eb31007
commit 09d58c1f14
11 changed files with 418 additions and 76 deletions

View File

@@ -0,0 +1,61 @@
package robot
import (
"blazing/modules/player/service"
"bytes"
"fmt"
"github.com/fogleman/gg"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
func init() {
zero.OnCommand("行情").
Handle(func(ctx *zero.Ctx) {
var msgs []string
for _, v := range service.NewGoldListService(0).Get() {
msgs = append(msgs, fmt.Sprintf("数量:%d 汇率:%.2f 所需金币:%.2f", v.ExchangeNum, 1/v.Rate, float64(v.ExchangeNum)*v.Rate))
}
// ======================
// 生成行情图片
// ======================
const (
width = 400
lineHeight = 24
padding = 15
)
lineCount := len(msgs)
height := padding*2 + lineHeight*lineCount + 40
// 创建图片
img := gg.NewContext(width, height)
// 背景色
img.SetRGB255(245, 247, 250)
img.Clear()
// 标题
img.SetRGB255(44, 62, 80)
img.LoadFontFace("/opt/blazing/build/simhei.ttf", 20) // 黑体,解决中文乱码
img.DrawString("骄阳号金豆集市行情列表", padding, 30) //📊
// 画内容
img.SetRGB255(30, 30, 30)
img.LoadFontFace("/opt/blazing/build/simhei.ttf", 16)
for i, line := range msgs {
y := 60 + i*lineHeight
img.DrawString(line, padding, float64(y))
}
// 保存为图片到内存(不落地文件)
var buf bytes.Buffer
img.EncodePNG(&buf) // 👈 就是你要的这个方法!
// ======================
// 发送图片zeroBot 标准方式)
// ======================
ctx.Send(message.ImageBytes(buf.Bytes()))
})
}

View File

@@ -651,7 +651,7 @@ func GenPetInfo(
}
// ---- 属性计算 ----
p.CalculatePetPane(true)
p.CalculatePetPane(0)
p.Update(false)

View File

@@ -2,6 +2,7 @@ package model
import (
"blazing/common/data/xmlres"
"blazing/common/utils"
)
// 实现获取等级范围内可学习的技能
@@ -32,26 +33,30 @@ func (c *PetInfo) calculatePetPanelSize(base, ev uint32, natureCorrect float64)
}
// 计算生成面板,只允许第一次生成超过100比如boss,不允许额外超过
func (p *PetInfo) CalculatePetPane(frist bool) {
if !frist {
func (p *PetInfo) CalculatePetPane(limit uint32) {
// if !frist {
if p.Level > 100 {
// if p.Level > 100 {
oldlveel := p.Level
p.Level = 100
defer func() {
p.Level = oldlveel
}()
}
// oldlveel := p.Level
// p.Level = 100
// defer func() {
// p.Level = oldlveel
// }()
// }
}
// }
naxml := xmlres.NatureRootMap[int(p.Nature)]
petxml := xmlres.PetMAP[int(p.ID)]
// 计算各项属性
level := p.Level
if limit > 0 {
level = utils.Min(p.Level, 100)
}
p.MaxHp = p.calculatePetHPPanelSize(
uint32(petxml.HP),
p.Dv,
p.Level,
level,
p.Ev[0],
)
p.Hp = p.MaxHp