Skip to content

Commit

Permalink
增加查询指定等级的升级经验功能
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteReimu committed Jun 18, 2024
1 parent 61a8353 commit ee85192
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions maplebot/bots.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ func handleGroupMessage(message *GroupMessage) bool {
} else if text.Text == "升级经验" {
sendGroupMessage(message, calculateLevelExp()...)
return true
} else if strings.HasPrefix(text.Text, "升级经验 ") {
content := strings.TrimSpace(text.Text[len("升级经验"):])
parts := strings.SplitN(content, " ", 2)
if len(parts) == 2 {
start, _ := strconv.Atoi(parts[0])
end, _ := strconv.Atoi(parts[1])
sendGroupMessage(message, calculateExpBetweenLevel(int64(start), int64(end))...)
}
return true
} else if text.Text == "爆炸次数" || strings.HasPrefix(text.Text, "爆炸次数 ") {
sendGroupMessage(message, calculateBoomCount(text.Text[len("爆炸次数"):])...)
return true
Expand Down
26 changes: 26 additions & 0 deletions maplebot/level_exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ import (
"strconv"
)

func calculateExpBetweenLevel(start, end int64) MessageChain {
if start < 1 || end > 300 || start >= end {
return nil
}
var exp int64
for i := start; i < end; i++ {
exp += int64(levelExpData.GetFloat64(fmt.Sprintf("data.%d", i)))
}
var s string
switch {
case exp < 1000:
s = fmt.Sprintf("%d", exp)

Check failure on line 24 in maplebot/level_exp.go

View workflow job for this annotation

GitHub Actions / build

fmt.Sprintf can be replaced with faster strconv.FormatInt (perfsprint)
case exp < 1000000:
s = fmt.Sprintf("%.2fK", float64(exp)/1000)
case exp < 1000000000:
s = fmt.Sprintf("%.2fM", float64(exp)/1000000)
case exp < 1000000000000:
s = fmt.Sprintf("%.2fB", float64(exp)/1000000000)
case exp < 1000000000000000:
s = fmt.Sprintf("%.2fT", float64(exp)/1000000000000)
default:
s = fmt.Sprintf("%.2fQ", float64(exp)/1000000000000000)
}
return MessageChain{&Text{Text: fmt.Sprintf("从%d级到%d级需要经验:%s", start, end, s)}}
}

func calculateLevelExp() MessageChain {
labels := make([]string, 0, 100)
values := [][]float64{make([]float64, 0, 100)}
Expand Down

0 comments on commit ee85192

Please sign in to comment.