Files
bl/common/utils/help.go
昔念 3e1887c7b8 ```
feat(broadcast): 添加全服广播功能并完善相关逻辑

新增 Broadcast 结构体及 Server 的 Broadcast 方法,用于实现全服广播消息,
并在 RPC 客户端中增加对应接口。同时在 fight 模块中添加聊天信息结构体和处理逻辑。

refactor(pet_skill): 优化宠物技能设置逻辑

修复宠物技能替换判断条件错误的问题,并调整相关逻辑顺序以提高代码可读性与健壮性。

feat(chat): 实现战斗内聊天功能

新增战斗中的聊天指令结构体 ChatInfo 和对应的控制器方法 FightChat,
支持玩家在战斗中发送聊天消息。

refactor(item_buy): 调整金币购买道具的扣费方式

将原直接比较金币数量改为调用
2025-11-25 16:36:55 +08:00

27 lines
578 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
func FindWithIndex[T any](slice []T, predicate func(item T) bool) (int, *T, bool) {
for i := range slice {
if predicate(slice[i]) {
return i, &slice[i], true
}
}
return -1, nil, false
}
func LastFourElements[T any](s []T, n1 int) []T {
n := len(s)
if n <= n1 {
// 切片长度小于等于4时返回整个切片
return s
}
// 切片长度大于4时返回最后4个元素从n-4索引到末尾
return s[n-n1:]
}
func RemoveLast(s string) string {
if s == "" {
return ""
}
runes := []rune(s)
return string(runes[:len(runes)-1])
}