Compare commits
76 Commits
f9543a5156
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9452e36782 | ||
|
|
1efc8517e1 | ||
|
|
ab2928db1d | ||
|
|
a9999bb93f | ||
|
|
34b65f6399 | ||
|
|
2ce1057566 | ||
|
|
d30028157a | ||
|
|
f0a8f521b6 | ||
|
|
0ae65cee45 | ||
|
|
11bf46c7e4 | ||
|
|
c4b5748e5c | ||
|
|
1f1fbd09d4 | ||
|
|
b1ca3df3ae | ||
|
|
57676e998f | ||
|
|
5500684e29 | ||
|
|
7fd89800fa | ||
|
|
b46a1f442b | ||
|
|
eb76c22c41 | ||
|
|
a6386daad8 | ||
|
|
b59beed45f | ||
|
|
77909a5940 | ||
|
|
c4d3ab725c | ||
|
|
808da76bd0 | ||
|
|
dcbd9950d3 | ||
|
|
4b42a64da0 | ||
|
|
d517c822ef | ||
|
|
04038cd16b | ||
|
|
ec608d69cd | ||
|
|
fd5341da1a | ||
|
|
5967414da4 | ||
|
|
da118dc826 | ||
|
|
823eef00ac | ||
|
|
7844c5b76b | ||
|
|
4abd179a23 | ||
|
|
a3e88c7357 | ||
|
|
4e1a9a815f | ||
|
|
de3ae0bca2 | ||
|
|
b1ff4d3a2a | ||
|
|
24b52e14c3 | ||
|
|
2b92baf530 | ||
|
|
819d5f667b | ||
|
|
de6c700bb3 | ||
|
|
3232efd05a | ||
|
|
0c79fee8af | ||
|
|
3d77e146e9 | ||
|
|
a43a25c610 | ||
|
|
3cfde577eb | ||
|
|
85f9c02ced | ||
|
|
9f7fd83626 | ||
|
|
ee8b0a2182 | ||
|
|
6e95e014fa | ||
|
|
61a135b3a7 | ||
|
|
5a81534e84 | ||
|
|
523d835ac0 | ||
|
|
5a7e20efec | ||
|
|
5f47bf0589 | ||
|
|
a58ef20fab | ||
|
|
3999f34f77 | ||
|
|
6f51a2e349 | ||
|
|
de755f8fd0 | ||
|
|
803aa71771 | ||
|
|
4a77066d08 | ||
|
|
c9b5f8569f | ||
|
|
ddbfe91d8b | ||
|
|
74ac6ce940 | ||
|
|
43b0bc2dec | ||
|
|
b953e7831a | ||
|
|
62d93f65e7 | ||
|
|
7dfa9c297e | ||
|
|
f95fd49efd | ||
|
|
ce1a2a3588 | ||
|
|
3739c2a6f9 | ||
|
|
eca7dd86e1 | ||
|
|
e161e3626f | ||
|
|
e1a994ba11 | ||
|
|
82bb99d141 |
3
.cnb.yml
3
.cnb.yml
@@ -27,5 +27,4 @@ main:
|
|||||||
username: ${GIT_USERNAME}
|
username: ${GIT_USERNAME}
|
||||||
password: ${GIT_ACCESS_TOKEN}
|
password: ${GIT_ACCESS_TOKEN}
|
||||||
force: true
|
force: true
|
||||||
|
sync_mode: push
|
||||||
#sync_mode: rebase
|
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ ENV GOMODCACHE=/workspace/.cache/gomod
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
# 2. Codex 配置 (更换时修改这里,重新 build)
|
# 2. Codex 配置 (更换时修改这里,重新 build)
|
||||||
# ==========================================
|
# ==========================================
|
||||||
ENV CODEX_BASE_URL="http://fast.jnm.lol/v1"
|
ENV CODEX_BASE_URL="https://api.jucode.cn/v1"
|
||||||
|
|
||||||
ENV CODEX_MODEL="gpt-5.4"
|
ENV CODEX_MODEL="gpt-5.4"
|
||||||
|
|
||||||
ENV OPENAI_API_KEY="pk_live_d15iVqaSMxD_XLHh0nrFPJ_fzFZy8IfR4Cd62bERl8g"
|
ENV OPENAI_API_KEY="sk-E0ZZIFNnD0RkhMC9pT2AGMutz9vNy2VLNrgyyobT5voa81pQ"
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# 3. 安装系统依赖、Golang、Code-server
|
# 3. 安装系统依赖、Golang、Code-server
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ skip_clone: true
|
|||||||
steps:
|
steps:
|
||||||
# ========== 1. 替代clone:拉取代码(核心依赖) ==========
|
# ========== 1. 替代clone:拉取代码(核心依赖) ==========
|
||||||
prepare:
|
prepare:
|
||||||
image: alpine/git
|
image: docker.1ms.run/alpine/git
|
||||||
environment:
|
environment:
|
||||||
# WOODPECKER_SSH_KEY:
|
# WOODPECKER_SSH_KEY:
|
||||||
# from_secret: WOODPECKER_SSH_KEY
|
# from_secret: WOODPECKER_SSH_KEY
|
||||||
@@ -70,7 +70,7 @@ steps:
|
|||||||
|
|
||||||
# ========== 4. 编译Logic服务(完全参考GitHub Actions编译配置) ==========
|
# ========== 4. 编译Logic服务(完全参考GitHub Actions编译配置) ==========
|
||||||
build_logic:
|
build_logic:
|
||||||
image: golang:1.25
|
image: docker.m.daocloud.io/golang:1.25
|
||||||
depends_on: [prepare]
|
depends_on: [prepare]
|
||||||
environment:
|
environment:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
@@ -142,7 +142,7 @@ steps:
|
|||||||
|
|
||||||
# ========== 6. SCP推送产物(依赖编译+配置解析) ==========
|
# ========== 6. SCP推送产物(依赖编译+配置解析) ==========
|
||||||
scp-exe-to-servers: # 与fetch-deploy-config同级,缩进2个空格
|
scp-exe-to-servers: # 与fetch-deploy-config同级,缩进2个空格
|
||||||
image: appleboy/drone-scp:1.6.2 # 子元素,缩进4个空格
|
image: docker.1ms.run/appleboy/drone-scp:1.6.2 # 子元素,缩进4个空格
|
||||||
settings: # 子元素,缩进4个空格
|
settings: # 子元素,缩进4个空格
|
||||||
host: &ssh_host 43.248.3.21
|
host: &ssh_host 43.248.3.21
|
||||||
port: &ssh_port 22
|
port: &ssh_port 22
|
||||||
@@ -158,7 +158,7 @@ steps:
|
|||||||
depends_on: # 子元素,缩进4个空格
|
depends_on: # 子元素,缩进4个空格
|
||||||
- build_logic # depends_on内的项,缩进6个空格
|
- build_logic # depends_on内的项,缩进6个空格
|
||||||
start-login-logic:
|
start-login-logic:
|
||||||
image: appleboy/drone-ssh:1.6.2
|
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/ghcr.io/appleboy/drone-ssh:1.7.7
|
||||||
depends_on: [scp-exe-to-servers]
|
depends_on: [scp-exe-to-servers]
|
||||||
settings: # 子元素,缩进4个空格
|
settings: # 子元素,缩进4个空格
|
||||||
host: *ssh_host
|
host: *ssh_host
|
||||||
|
|||||||
56
common/contrib/drivers/pgsql/cmd/codexcheck/main.go
Normal file
56
common/contrib/drivers/pgsql/cmd/codexcheck/main.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
const dsn = "user=user_YrK4j7 password=password_jSDm76 host=43.248.3.21 port=5432 dbname=bl sslmode=disable timezone=Asia/Shanghai"
|
||||||
|
|
||||||
|
db, err := sql.Open("postgres", dsn)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
var (
|
||||||
|
id int64
|
||||||
|
cdkCode string
|
||||||
|
cdkType int64
|
||||||
|
exchangeRemainCount int64
|
||||||
|
bindUserID int64
|
||||||
|
validEndTime sql.NullTime
|
||||||
|
remark sql.NullString
|
||||||
|
)
|
||||||
|
|
||||||
|
err = db.QueryRow(`
|
||||||
|
select id, cdk_code, type, exchange_remain_count, bind_user_id, valid_end_time, remark
|
||||||
|
from config_gift_cdk
|
||||||
|
where cdk_code = $1
|
||||||
|
`, "nrTbdXFBhKkaTdDk").Scan(
|
||||||
|
&id,
|
||||||
|
&cdkCode,
|
||||||
|
&cdkType,
|
||||||
|
&exchangeRemainCount,
|
||||||
|
&bindUserID,
|
||||||
|
&validEndTime,
|
||||||
|
&remark,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("id=%d\ncdk_code=%s\ntype=%d\nexchange_remain_count=%d\nbind_user_id=%d\nvalid_end_time=%v\nremark=%q\n",
|
||||||
|
id,
|
||||||
|
cdkCode,
|
||||||
|
cdkType,
|
||||||
|
exchangeRemainCount,
|
||||||
|
bindUserID,
|
||||||
|
validEndTime.Time,
|
||||||
|
remark.String,
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package cool
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"blazing/cool/coolconfig"
|
"blazing/cool/coolconfig"
|
||||||
@@ -158,13 +159,34 @@ func (c *Controller) Page(ctx context.Context, req *PageReq) (res *BaseRes, err
|
|||||||
// 注册控制器到路由
|
// 注册控制器到路由
|
||||||
func RegisterController(c IController) {
|
func RegisterController(c IController) {
|
||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
var sController = &Controller{}
|
var sController *Controller
|
||||||
|
rv := reflect.ValueOf(c)
|
||||||
|
if rv.IsValid() && rv.Kind() == reflect.Ptr {
|
||||||
|
ev := rv.Elem()
|
||||||
|
if ev.IsValid() {
|
||||||
|
field := ev.FieldByName("Controller")
|
||||||
|
if field.IsValid() && !field.IsNil() {
|
||||||
|
if ctrl, ok := field.Interface().(*Controller); ok && ctrl != nil {
|
||||||
|
sController = ctrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sController == nil {
|
||||||
|
sController = &Controller{}
|
||||||
gconv.Struct(c, &sController)
|
gconv.Struct(c, &sController)
|
||||||
|
}
|
||||||
if coolconfig.Config.Eps {
|
if coolconfig.Config.Eps {
|
||||||
model := sController.Service.GetModel()
|
model := sController.Service.GetModel()
|
||||||
|
tableName := ""
|
||||||
|
if model != nil {
|
||||||
|
tableName = strings.TrimSpace(model.TableName())
|
||||||
|
}
|
||||||
|
if tableName != "" && tableName != "this_table_should_not_exist" {
|
||||||
columns := getModelInfo(ctx, sController.Prefix, model)
|
columns := getModelInfo(ctx, sController.Prefix, model)
|
||||||
ModelInfo[sController.Prefix] = columns
|
ModelInfo[sController.Prefix] = columns
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g.Server().Group(
|
g.Server().Group(
|
||||||
sController.Prefix, func(group *ghttp.RouterGroup) {
|
sController.Prefix, func(group *ghttp.RouterGroup) {
|
||||||
group.Middleware(MiddlewareHandlerResponse)
|
group.Middleware(MiddlewareHandlerResponse)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package coolconfig
|
package coolconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
@@ -72,7 +74,7 @@ type file struct {
|
|||||||
func newConfig() *sConfig {
|
func newConfig() *sConfig {
|
||||||
var ctx g.Ctx
|
var ctx g.Ctx
|
||||||
config := &sConfig{
|
config := &sConfig{
|
||||||
AutoMigrate: GetCfgWithDefault(ctx, "blazing.autoMigrate", g.NewVar(false)).Bool(),
|
AutoMigrate: hasDebugArg(),
|
||||||
Name: GetCfgWithDefault(ctx, "server.name", g.NewVar("")).String(),
|
Name: GetCfgWithDefault(ctx, "server.name", g.NewVar("")).String(),
|
||||||
|
|
||||||
Eps: GetCfgWithDefault(ctx, "blazing.eps", g.NewVar(false)).Bool(),
|
Eps: GetCfgWithDefault(ctx, "blazing.eps", g.NewVar(false)).Bool(),
|
||||||
@@ -97,6 +99,19 @@ func newConfig() *sConfig {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasDebugArg() bool {
|
||||||
|
for _, arg := range os.Args[1:] {
|
||||||
|
if arg == "-debug" || arg == "--debug" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(arg, "-debug=") || strings.HasPrefix(arg, "--debug=") {
|
||||||
|
value := strings.TrimSpace(strings.SplitN(arg, "=", 2)[1])
|
||||||
|
return value != "" && value != "0" && !strings.EqualFold(value, "false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// qiniu 七牛云配置
|
// qiniu 七牛云配置
|
||||||
type qiniu struct {
|
type qiniu struct {
|
||||||
AccessKey string `json:"ak"`
|
AccessKey string `json:"ak"`
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cool
|
|||||||
import (
|
import (
|
||||||
_ "blazing/contrib/drivers/pgsql"
|
_ "blazing/contrib/drivers/pgsql"
|
||||||
"blazing/cool/cooldb"
|
"blazing/cool/cooldb"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/encoding/gjson"
|
"github.com/gogf/gf/v2/encoding/gjson"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
@@ -10,6 +11,11 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
autoMigrateMu sync.Mutex
|
||||||
|
autoMigrateModels []IModel
|
||||||
|
)
|
||||||
|
|
||||||
// 初始化数据库连接供gorm使用
|
// 初始化数据库连接供gorm使用
|
||||||
func InitDB(group string) (*gorm.DB, error) {
|
func InitDB(group string) (*gorm.DB, error) {
|
||||||
// var ctx context.Context
|
// var ctx context.Context
|
||||||
@@ -54,9 +60,39 @@ func getDBbyModel(model IModel) *gorm.DB {
|
|||||||
|
|
||||||
// 根据entity结构体创建表
|
// 根据entity结构体创建表
|
||||||
func CreateTable(model IModel) error {
|
func CreateTable(model IModel) error {
|
||||||
if Config.AutoMigrate {
|
autoMigrateMu.Lock()
|
||||||
|
autoMigrateModels = append(autoMigrateModels, model)
|
||||||
|
autoMigrateMu.Unlock()
|
||||||
|
|
||||||
|
if !Config.AutoMigrate {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
db := getDBbyModel(model)
|
db := getDBbyModel(model)
|
||||||
return db.AutoMigrate(model)
|
return db.AutoMigrate(model)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunAutoMigrate 显式执行已注册模型的建表/迁移。
|
||||||
|
func RunAutoMigrate() error {
|
||||||
|
if !Config.AutoMigrate {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
autoMigrateMu.Lock()
|
||||||
|
models := append([]IModel(nil), autoMigrateModels...)
|
||||||
|
autoMigrateMu.Unlock()
|
||||||
|
|
||||||
|
seen := make(map[string]struct{}, len(models))
|
||||||
|
for _, model := range models {
|
||||||
|
key := model.GroupName() + ":" + model.TableName()
|
||||||
|
if _, ok := seen[key]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[key] = struct{}{}
|
||||||
|
|
||||||
|
db := getDBbyModel(model)
|
||||||
|
if err := db.AutoMigrate(model); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ type EffectArg struct {
|
|||||||
SideEffect []struct {
|
SideEffect []struct {
|
||||||
ID int `json:"ID"`
|
ID int `json:"ID"`
|
||||||
SideEffectArgcount int `json:"SideEffectArgcount"`
|
SideEffectArgcount int `json:"SideEffectArgcount"`
|
||||||
SideEffectArg string `json:"SideEffectArg,omitempty"`
|
SideEffectArg rawFlexibleString `json:"SideEffectArg,omitempty"`
|
||||||
} `json:"SideEffect"`
|
} `json:"SideEffect"`
|
||||||
} `json:"SideEffects"`
|
} `json:"SideEffects"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ import (
|
|||||||
_ "blazing/common/data/xmlres/packed"
|
_ "blazing/common/data/xmlres/packed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/ECUST-XX/xml"
|
"github.com/ECUST-XX/xml"
|
||||||
"github.com/gogf/gf/v2/os/gres"
|
"github.com/gogf/gf/v2/os/gres"
|
||||||
@@ -16,27 +13,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var path string
|
var path string
|
||||||
var diskConfigPath string
|
|
||||||
|
|
||||||
func readConfigContent(path string) []byte {
|
func readConfigContent(path string) []byte {
|
||||||
content := gres.GetContent(path)
|
return gres.GetContent(path)
|
||||||
if len(content) > 0 {
|
|
||||||
return content
|
|
||||||
}
|
|
||||||
|
|
||||||
if diskConfigPath == "" {
|
|
||||||
return content
|
|
||||||
}
|
|
||||||
|
|
||||||
diskPath := filepath.Join(diskConfigPath, strings.TrimPrefix(path, "config/"))
|
|
||||||
data, err := os.ReadFile(diskPath)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("[xmlres] readConfigContent fallback failed: path=%s disk=%s err=%v\n", path, diskPath, err)
|
|
||||||
return content
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("[xmlres] readConfigContent fallback hit: path=%s disk=%s len=%d\n", path, diskPath, len(data))
|
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getXml[T any](path string) T {
|
func getXml[T any](path string) T {
|
||||||
@@ -93,9 +72,6 @@ var (
|
|||||||
|
|
||||||
func Initfile() {
|
func Initfile() {
|
||||||
//gres.Dump()
|
//gres.Dump()
|
||||||
path1, _ := os.Getwd()
|
|
||||||
diskConfigPath = filepath.Join(path1, "public", "config")
|
|
||||||
path = path1 + "/public/config/"
|
|
||||||
path = "config/"
|
path = "config/"
|
||||||
MapConfig = getXml[Maps](path + "210.xml")
|
MapConfig = getXml[Maps](path + "210.xml")
|
||||||
|
|
||||||
|
|||||||
26
common/data/xmlres/json_compat_test.go
Normal file
26
common/data/xmlres/json_compat_test.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package xmlres
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMoveUnmarshalJSONAcceptsNumericName(t *testing.T) {
|
||||||
|
var move Move
|
||||||
|
if err := json.Unmarshal([]byte(`{"ID":10001,"Name":1,"Category":1,"Type":8,"Power":35,"MaxPP":35,"Accuracy":95}`), &move); err != nil {
|
||||||
|
t.Fatalf("unmarshal move failed: %v", err)
|
||||||
|
}
|
||||||
|
if move.Name != "1" {
|
||||||
|
t.Fatalf("expected numeric name to convert to string, got %q", move.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEffectArgUnmarshalJSONAcceptsNumericSideEffectArg(t *testing.T) {
|
||||||
|
var cfg EffectArg
|
||||||
|
if err := json.Unmarshal([]byte(`{"SideEffects":{"SideEffect":[{"ID":1,"SideEffectArgcount":1,"SideEffectArg":3}]}}`), &cfg); err != nil {
|
||||||
|
t.Fatalf("unmarshal effect arg failed: %v", err)
|
||||||
|
}
|
||||||
|
if got := string(cfg.SideEffects.SideEffect[0].SideEffectArg); got != "3" {
|
||||||
|
t.Fatalf("expected numeric side effect arg to convert to string, got %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -115,7 +115,7 @@ type Move struct {
|
|||||||
func (m *Move) UnmarshalJSON(data []byte) error {
|
func (m *Move) UnmarshalJSON(data []byte) error {
|
||||||
type moveAlias struct {
|
type moveAlias struct {
|
||||||
ID int `json:"ID"`
|
ID int `json:"ID"`
|
||||||
Name string `json:"Name"`
|
Name rawFlexibleString `json:"Name"`
|
||||||
Category int `json:"Category"`
|
Category int `json:"Category"`
|
||||||
Type int `json:"Type"`
|
Type int `json:"Type"`
|
||||||
Power int `json:"Power"`
|
Power int `json:"Power"`
|
||||||
@@ -150,7 +150,7 @@ func (m *Move) UnmarshalJSON(data []byte) error {
|
|||||||
|
|
||||||
*m = Move{
|
*m = Move{
|
||||||
ID: aux.ID,
|
ID: aux.ID,
|
||||||
Name: aux.Name,
|
Name: string(aux.Name),
|
||||||
Category: aux.Category,
|
Category: aux.Category,
|
||||||
Type: aux.Type,
|
Type: aux.Type,
|
||||||
Power: aux.Power,
|
Power: aux.Power,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"blazing/logic/service/fight/pvp"
|
"blazing/logic/service/fight/pvp"
|
||||||
"blazing/logic/service/fight/pvpwire"
|
"blazing/logic/service/fight/pvpwire"
|
||||||
|
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -16,7 +15,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ListenFunc 监听函数
|
// ListenFunc 监听函数
|
||||||
// ListenFunc 改造后的 Redis PubSub 监听函数,支持自动重连和心跳保活
|
// ListenFunc 改造后的 Redis PubSub 监听函数,支持自动重连。
|
||||||
|
// 注意:PubSub 连接只负责订阅和接收,避免在同一连接上并发 PING。
|
||||||
func ListenFunc(ctx g.Ctx) {
|
func ListenFunc(ctx g.Ctx) {
|
||||||
if !cool.IsRedisMode {
|
if !cool.IsRedisMode {
|
||||||
panic(gerror.New("集群模式下, 请使用Redis作为缓存"))
|
panic(gerror.New("集群模式下, 请使用Redis作为缓存"))
|
||||||
@@ -26,7 +26,6 @@ func ListenFunc(ctx g.Ctx) {
|
|||||||
const (
|
const (
|
||||||
subscribeTopic = "cool:func" // 订阅的主题
|
subscribeTopic = "cool:func" // 订阅的主题
|
||||||
retryDelay = 10 * time.Second // 连接失败重试间隔
|
retryDelay = 10 * time.Second // 连接失败重试间隔
|
||||||
heartbeatInterval = 30 * time.Second // 心跳保活间隔
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 外层循环:负责连接断开后的整体重连
|
// 外层循环:负责连接断开后的整体重连
|
||||||
@@ -47,47 +46,25 @@ func ListenFunc(ctx g.Ctx) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 启动心跳保活协程,防止连接因空闲被断开
|
// 2. 订阅主题
|
||||||
heartbeatCtx, heartbeatCancel := context.WithCancel(context.Background())
|
|
||||||
go func() {
|
|
||||||
ticker := time.NewTicker(heartbeatInterval)
|
|
||||||
defer func() {
|
|
||||||
ticker.Stop()
|
|
||||||
heartbeatCancel()
|
|
||||||
}()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-heartbeatCtx.Done():
|
|
||||||
cool.Logger.Info(ctx, "心跳协程退出")
|
|
||||||
return
|
|
||||||
case <-ticker.C:
|
|
||||||
// 发送 PING 心跳,保持连接活跃
|
|
||||||
_, pingErr := conn.Do(ctx, "PING")
|
|
||||||
if pingErr != nil {
|
|
||||||
cool.Logger.Error(ctx, "Redis 心跳失败,触发重连", "error", pingErr)
|
|
||||||
// 心跳失败时主动关闭连接,触发外层重连
|
|
||||||
_ = conn.Close(ctx)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// 3. 订阅主题
|
|
||||||
_, err = conn.Do(ctx, "subscribe", subscribeTopic)
|
_, err = conn.Do(ctx, "subscribe", subscribeTopic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cool.Logger.Error(ctx, "订阅 Redis 主题失败", "topic", subscribeTopic, "error", err)
|
cool.Logger.Error(ctx, "订阅 Redis 主题失败", "topic", subscribeTopic, "error", err)
|
||||||
heartbeatCancel() // 关闭心跳协程
|
|
||||||
_ = conn.Close(ctx)
|
_ = conn.Close(ctx)
|
||||||
time.Sleep(retryDelay)
|
time.Sleep(retryDelay)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cool.Logger.Info(ctx, "成功订阅 Redis 主题", "topic", subscribeTopic)
|
cool.Logger.Info(ctx, "成功订阅 Redis 主题", "topic", subscribeTopic)
|
||||||
_, err = conn.Do(ctx, "subscribe", "sun:join") //加入队列
|
_, err = conn.Do(ctx, "subscribe", "sun:join") //加入队列
|
||||||
|
if err != nil {
|
||||||
|
cool.Logger.Error(ctx, "订阅 Redis 主题失败", "topic", "sun:join", "error", err)
|
||||||
|
_ = conn.Close(ctx)
|
||||||
|
time.Sleep(retryDelay)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cool.Logger.Info(ctx, "成功订阅 Redis 主题", "topic", "sun:join")
|
||||||
|
|
||||||
// 4. 循环接收消息
|
// 3. 循环接收消息
|
||||||
connError := false
|
connError := false
|
||||||
for !connError {
|
for !connError {
|
||||||
select {
|
select {
|
||||||
@@ -130,15 +107,15 @@ func ListenFunc(ctx g.Ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 清理资源,准备重连
|
// 4. 清理资源,准备重连
|
||||||
heartbeatCancel() // 关闭心跳协程
|
|
||||||
_ = conn.Close(ctx) // 关闭当前连接
|
_ = conn.Close(ctx) // 关闭当前连接
|
||||||
// Logger.Warn(ctx, "Redis 连接异常,准备重连", "retry_after", retryDelay)
|
cool.Logger.Info(ctx, "Redis 订阅连接异常,准备重连", "retry_after", retryDelay)
|
||||||
time.Sleep(retryDelay)
|
time.Sleep(retryDelay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenFight 完全对齐 ListenFunc 写法,修复收不到消息问题
|
// ListenFight 完全对齐 ListenFunc 写法,修复收不到消息问题。
|
||||||
|
// 注意:PubSub 连接只负责订阅和接收,避免在同一连接上并发 PING。
|
||||||
func ListenFight(ctx g.Ctx) {
|
func ListenFight(ctx g.Ctx) {
|
||||||
if !cool.IsRedisMode {
|
if !cool.IsRedisMode {
|
||||||
panic(gerror.New("集群模式下, 请使用Redis作为缓存"))
|
panic(gerror.New("集群模式下, 请使用Redis作为缓存"))
|
||||||
@@ -147,7 +124,6 @@ func ListenFight(ctx g.Ctx) {
|
|||||||
// 定义常量配置(对齐 ListenFunc 风格)
|
// 定义常量配置(对齐 ListenFunc 风格)
|
||||||
const (
|
const (
|
||||||
retryDelay = 10 * time.Second // 连接失败重试间隔
|
retryDelay = 10 * time.Second // 连接失败重试间隔
|
||||||
heartbeatInterval = 30 * time.Second // 心跳保活间隔
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 提前拼接订阅主题(避免重复拼接,便于日志打印)
|
// 提前拼接订阅主题(避免重复拼接,便于日志打印)
|
||||||
@@ -176,35 +152,7 @@ func ListenFight(ctx g.Ctx) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 启动心跳保活协程(完全对齐 ListenFunc 逻辑)
|
// 2. 订阅主题(对齐 ListenFunc 的错误处理,替换 panic 为优雅重连)
|
||||||
heartbeatCtx, heartbeatCancel := context.WithCancel(context.Background())
|
|
||||||
go func() {
|
|
||||||
ticker := time.NewTicker(heartbeatInterval)
|
|
||||||
defer func() {
|
|
||||||
ticker.Stop()
|
|
||||||
heartbeatCancel()
|
|
||||||
}()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-heartbeatCtx.Done():
|
|
||||||
cool.Logger.Info(ctx, "心跳协程退出")
|
|
||||||
return
|
|
||||||
case <-ticker.C:
|
|
||||||
// 发送 PING 心跳,保持连接活跃
|
|
||||||
_, pingErr := conn.Do(ctx, "PING")
|
|
||||||
if pingErr != nil {
|
|
||||||
cool.Logger.Error(ctx, "Redis 心跳失败,触发重连", "error", pingErr)
|
|
||||||
// 心跳失败时主动关闭连接,触发外层重连
|
|
||||||
_ = conn.Close(ctx)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cool.Logger.Debug(ctx, "Redis 心跳发送成功,连接正常")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// 3. 订阅主题(对齐 ListenFunc 的错误处理,替换 panic 为优雅重连)
|
|
||||||
subscribeTopics := []string{startTopic, pvpServerTopic}
|
subscribeTopics := []string{startTopic, pvpServerTopic}
|
||||||
if cool.Config.GameOnlineID == pvp.CoordinatorOnlineID {
|
if cool.Config.GameOnlineID == pvp.CoordinatorOnlineID {
|
||||||
subscribeTopics = append(subscribeTopics, pvpCoordinatorTopic)
|
subscribeTopics = append(subscribeTopics, pvpCoordinatorTopic)
|
||||||
@@ -214,7 +162,6 @@ func ListenFight(ctx g.Ctx) {
|
|||||||
_, err = conn.Do(ctx, "subscribe", topic)
|
_, err = conn.Do(ctx, "subscribe", topic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cool.Logger.Error(ctx, "订阅 Redis 主题失败", "topic", topic, "error", err)
|
cool.Logger.Error(ctx, "订阅 Redis 主题失败", "topic", topic, "error", err)
|
||||||
heartbeatCancel()
|
|
||||||
_ = conn.Close(ctx)
|
_ = conn.Close(ctx)
|
||||||
time.Sleep(retryDelay)
|
time.Sleep(retryDelay)
|
||||||
subscribeFailed = true
|
subscribeFailed = true
|
||||||
@@ -240,7 +187,7 @@ func ListenFight(ctx g.Ctx) {
|
|||||||
// 打印监听提示(保留原有日志)
|
// 打印监听提示(保留原有日志)
|
||||||
fmt.Println("监听战斗", startTopic)
|
fmt.Println("监听战斗", startTopic)
|
||||||
|
|
||||||
// 4. 循环接收消息(完全对齐 ListenFunc 逻辑)
|
// 3. 循环接收消息(完全对齐 ListenFunc 逻辑)
|
||||||
connError := false
|
connError := false
|
||||||
for !connError {
|
for !connError {
|
||||||
select {
|
select {
|
||||||
@@ -282,9 +229,9 @@ func ListenFight(ctx g.Ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 清理资源,准备重连(完全对齐 ListenFunc)
|
// 4. 清理资源,准备重连(完全对齐 ListenFunc)
|
||||||
heartbeatCancel() // 关闭心跳协程
|
|
||||||
_ = conn.Close(ctx) // 关闭当前连接
|
_ = conn.Close(ctx) // 关闭当前连接
|
||||||
|
cool.Logger.Info(ctx, "Redis 战斗订阅连接异常,准备重连", "retry_after", retryDelay)
|
||||||
time.Sleep(retryDelay)
|
time.Sleep(retryDelay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,17 +21,25 @@ type PVPMatchJoinPayload struct {
|
|||||||
Nick string `json:"nick"`
|
Nick string `json:"nick"`
|
||||||
FightMode uint32 `json:"fightMode"`
|
FightMode uint32 `json:"fightMode"`
|
||||||
Status uint32 `json:"status"`
|
Status uint32 `json:"status"`
|
||||||
|
IsVip uint32 `json:"isVip"`
|
||||||
|
IsDebug uint8 `json:"isDebug"`
|
||||||
CatchTimes []uint32 `json:"catchTimes"`
|
CatchTimes []uint32 `json:"catchTimes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type pvpMatchQueueKey struct {
|
||||||
|
FightMode uint32
|
||||||
|
IsVip uint32
|
||||||
|
IsDebug uint8
|
||||||
|
}
|
||||||
|
|
||||||
type pvpMatchCoordinator struct {
|
type pvpMatchCoordinator struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
queues map[uint32][]pvpwire.QueuePlayerSnapshot
|
queues map[pvpMatchQueueKey][]pvpwire.QueuePlayerSnapshot
|
||||||
lastSeen map[uint32]time.Time
|
lastSeen map[uint32]time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultPVPMatchCoordinator = &pvpMatchCoordinator{
|
var defaultPVPMatchCoordinator = &pvpMatchCoordinator{
|
||||||
queues: make(map[uint32][]pvpwire.QueuePlayerSnapshot),
|
queues: make(map[pvpMatchQueueKey][]pvpwire.QueuePlayerSnapshot),
|
||||||
lastSeen: make(map[uint32]time.Time),
|
lastSeen: make(map[uint32]time.Time),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +59,8 @@ func (m *pvpMatchCoordinator) JoinOrUpdate(payload PVPMatchJoinPayload) error {
|
|||||||
Nick: payload.Nick,
|
Nick: payload.Nick,
|
||||||
FightMode: payload.FightMode,
|
FightMode: payload.FightMode,
|
||||||
Status: payload.Status,
|
Status: payload.Status,
|
||||||
|
IsVip: payload.IsVip,
|
||||||
|
IsDebug: payload.IsDebug,
|
||||||
JoinedAtUnix: now.Unix(),
|
JoinedAtUnix: now.Unix(),
|
||||||
CatchTimes: append([]uint32(nil), payload.CatchTimes...),
|
CatchTimes: append([]uint32(nil), payload.CatchTimes...),
|
||||||
}
|
}
|
||||||
@@ -62,11 +72,12 @@ func (m *pvpMatchCoordinator) JoinOrUpdate(payload PVPMatchJoinPayload) error {
|
|||||||
m.removeUserLocked(payload.UserID)
|
m.removeUserLocked(payload.UserID)
|
||||||
m.lastSeen[payload.UserID] = now
|
m.lastSeen[payload.UserID] = now
|
||||||
|
|
||||||
queue := m.queues[payload.FightMode]
|
queueKey := newPVPMatchQueueKey(player)
|
||||||
|
queue := m.queues[queueKey]
|
||||||
if len(queue) > 0 {
|
if len(queue) > 0 {
|
||||||
host := queue[0]
|
host := queue[0]
|
||||||
queue = queue[1:]
|
queue = queue[1:]
|
||||||
m.queues[payload.FightMode] = queue
|
m.queues[queueKey] = queue
|
||||||
delete(m.lastSeen, host.UserID)
|
delete(m.lastSeen, host.UserID)
|
||||||
delete(m.lastSeen, payload.UserID)
|
delete(m.lastSeen, payload.UserID)
|
||||||
|
|
||||||
@@ -79,7 +90,7 @@ func (m *pvpMatchCoordinator) JoinOrUpdate(payload PVPMatchJoinPayload) error {
|
|||||||
}
|
}
|
||||||
match = &result
|
match = &result
|
||||||
} else {
|
} else {
|
||||||
m.queues[payload.FightMode] = append(queue, player)
|
m.queues[queueKey] = append(queue, player)
|
||||||
}
|
}
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
|
|
||||||
@@ -109,7 +120,7 @@ func (m *pvpMatchCoordinator) Cancel(userID uint32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *pvpMatchCoordinator) pruneExpiredLocked(now time.Time) {
|
func (m *pvpMatchCoordinator) pruneExpiredLocked(now time.Time) {
|
||||||
for mode, queue := range m.queues {
|
for key, queue := range m.queues {
|
||||||
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
||||||
for _, queued := range queue {
|
for _, queued := range queue {
|
||||||
last := m.lastSeen[queued.UserID]
|
last := m.lastSeen[queued.UserID]
|
||||||
@@ -119,12 +130,12 @@ func (m *pvpMatchCoordinator) pruneExpiredLocked(now time.Time) {
|
|||||||
}
|
}
|
||||||
next = append(next, queued)
|
next = append(next, queued)
|
||||||
}
|
}
|
||||||
m.queues[mode] = next
|
m.queues[key] = next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *pvpMatchCoordinator) removeUserLocked(userID uint32) {
|
func (m *pvpMatchCoordinator) removeUserLocked(userID uint32) {
|
||||||
for mode, queue := range m.queues {
|
for key, queue := range m.queues {
|
||||||
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
||||||
for _, queued := range queue {
|
for _, queued := range queue {
|
||||||
if queued.UserID == userID {
|
if queued.UserID == userID {
|
||||||
@@ -132,7 +143,15 @@ func (m *pvpMatchCoordinator) removeUserLocked(userID uint32) {
|
|||||||
}
|
}
|
||||||
next = append(next, queued)
|
next = append(next, queued)
|
||||||
}
|
}
|
||||||
m.queues[mode] = next
|
m.queues[key] = next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPVPMatchQueueKey(player pvpwire.QueuePlayerSnapshot) pvpMatchQueueKey {
|
||||||
|
return pvpMatchQueueKey{
|
||||||
|
FightMode: player.FightMode,
|
||||||
|
IsVip: player.IsVip,
|
||||||
|
IsDebug: player.IsDebug,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
config "blazing/modules/config/service"
|
config "blazing/modules/config/service"
|
||||||
@@ -20,6 +21,18 @@ type ServerHandler struct{}
|
|||||||
|
|
||||||
const kickForwardTimeout = 3 * time.Second
|
const kickForwardTimeout = 3 * time.Second
|
||||||
|
|
||||||
|
// A 服强关,留下僵尸在线状态:B 服可以通过 login 清理后登录。
|
||||||
|
// login 服不可用:B 服不会放行,仍提示系统忙。
|
||||||
|
func isDisconnectedLogicReverseClientError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
errText := err.Error()
|
||||||
|
return strings.Contains(errText, "websocket routine exiting") ||
|
||||||
|
strings.Contains(errText, "sendRequest failed") ||
|
||||||
|
strings.Contains(errText, "closed out channel")
|
||||||
|
}
|
||||||
|
|
||||||
// 实现踢人
|
// 实现踢人
|
||||||
func (*ServerHandler) Kick(_ context.Context, userid uint32) error {
|
func (*ServerHandler) Kick(_ context.Context, userid uint32) error {
|
||||||
useid1, err := share.ShareManager.GetUserOnline(userid)
|
useid1, err := share.ShareManager.GetUserOnline(userid)
|
||||||
@@ -57,6 +70,11 @@ func (*ServerHandler) Kick(_ context.Context, userid uint32) error {
|
|||||||
cool.DeleteClientOnly(useid2)
|
cool.DeleteClientOnly(useid2)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if isDisconnectedLogicReverseClientError(callErr) {
|
||||||
|
_ = share.ShareManager.DeleteUserOnline(userid)
|
||||||
|
cool.DeleteClientOnly(useid2)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// 仍在线则返回失败,不按成功处理
|
// 仍在线则返回失败,不按成功处理
|
||||||
return callErr
|
return callErr
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
|
|||||||
if v != nil {
|
if v != nil {
|
||||||
v.Close()
|
v.Close()
|
||||||
if v.Player != nil {
|
if v.Player != nil {
|
||||||
v.Player.Save() //保存玩家数据
|
v.Player.SaveOnDisconnect() //保存玩家数据
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -121,7 +121,23 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ws := c.Context().(*player.ClientData).Wsmsg
|
client := c.Context().(*player.ClientData)
|
||||||
|
if s.discorse && !client.IsCrossDomainChecked() {
|
||||||
|
handled, ready, action := handle(c)
|
||||||
|
if action != gnet.None {
|
||||||
|
return action
|
||||||
|
}
|
||||||
|
if handled {
|
||||||
|
client.MarkCrossDomainChecked()
|
||||||
|
return gnet.None
|
||||||
|
}
|
||||||
|
if !ready {
|
||||||
|
return gnet.None
|
||||||
|
}
|
||||||
|
client.MarkCrossDomainChecked()
|
||||||
|
}
|
||||||
|
|
||||||
|
ws := client.Wsmsg
|
||||||
if ws.Tcp {
|
if ws.Tcp {
|
||||||
return s.handleTCP(c)
|
return s.handleTCP(c)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,6 +115,10 @@ var ErrorCodes = enum.New[struct {
|
|||||||
ErrPokemonLevelTooLow ErrorCode `enum:"13007"`
|
ErrPokemonLevelTooLow ErrorCode `enum:"13007"`
|
||||||
// 不能展示背包里的精灵!
|
// 不能展示背包里的精灵!
|
||||||
ErrCannotShowBagPokemon ErrorCode `enum:"13017"`
|
ErrCannotShowBagPokemon ErrorCode `enum:"13017"`
|
||||||
|
// 基地展示精灵数量已达上限!
|
||||||
|
ErrRoomShowPetLimit ErrorCode `enum:"13019"`
|
||||||
|
// 该精灵不在仓库中,无法设为基地展示!
|
||||||
|
ErrPetNotInWarehouse ErrorCode `enum:"13021"`
|
||||||
// 你今天已经被吃掉过一回了,明天再来吧!
|
// 你今天已经被吃掉过一回了,明天再来吧!
|
||||||
ErrAlreadyEatenToday ErrorCode `enum:"17018"`
|
ErrAlreadyEatenToday ErrorCode `enum:"17018"`
|
||||||
// 该道具已经在使用中,无法重复使用。
|
// 该道具已经在使用中,无法重复使用。
|
||||||
|
|||||||
10
help/ftp.md
Normal file
10
help/ftp.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
FTP地址:38.102.84.92 [ 端口:21 ]
|
||||||
|
FTP用户名:m1584920
|
||||||
|
FTP密码:7WKimiwDH5RL2SLs
|
||||||
|
空间容量:10G
|
||||||
|
有效期至:2027-04-21(1年)
|
||||||
|
|
||||||
|
文件上传之后,其URL地址是:
|
||||||
|
https://m1584920.772988.xyz/文件名+文件格式,如果文件名有中文,请注意编码问题,如果你不懂这个就遇到再跟我说。
|
||||||
|
|
||||||
|
PS:如果需要绑定你的域名,手续费¥30
|
||||||
18
help/server_show冠名索引修复.sql
Normal file
18
help/server_show冠名索引修复.sql
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
-- server_show 冠名索引修复
|
||||||
|
-- 目的:
|
||||||
|
-- 1. 允许同一服务器存在多个不同玩家的冠名记录
|
||||||
|
-- 2. 保证同一玩家对同一服务器只有一条记录(续费更新该记录)
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
-- 历史上 server_id 被建成了单列唯一约束/唯一索引,会拦截同服多冠名
|
||||||
|
ALTER TABLE server_show DROP CONSTRAINT IF EXISTS idx_server_show_server_id;
|
||||||
|
DROP INDEX IF EXISTS idx_server_show_server_id;
|
||||||
|
|
||||||
|
-- 保留普通查询索引
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_server_show_server_id ON server_show (server_id);
|
||||||
|
|
||||||
|
-- 保证“一个玩家对一个服务器最多一条”
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_server_show_server_owner ON server_show (server_id, owner);
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
73
help/初始化SPT配置.sql
Normal file
73
help/初始化SPT配置.sql
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
-- 初始化/修复 SPT 配置表(PostgreSQL)
|
||||||
|
-- 用法:在 sun 数据库执行本文件
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS config_spt (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
"createTime" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
|
"updateTime" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
|
deleted_at TIMESTAMPTZ NULL,
|
||||||
|
is_enable INTEGER NOT NULL DEFAULT 1,
|
||||||
|
remark VARCHAR(255) NOT NULL DEFAULT '',
|
||||||
|
task_id INTEGER NOT NULL,
|
||||||
|
title VARCHAR(64) NOT NULL DEFAULT '',
|
||||||
|
pet_id INTEGER NOT NULL DEFAULT 0,
|
||||||
|
online INTEGER NOT NULL DEFAULT 1,
|
||||||
|
level INTEGER NOT NULL DEFAULT 1,
|
||||||
|
enter_id INTEGER NOT NULL DEFAULT 0,
|
||||||
|
description TEXT NOT NULL DEFAULT ''
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_config_spt_task_id ON config_spt(task_id);
|
||||||
|
|
||||||
|
ALTER TABLE config_spt DROP COLUMN IF EXISTS seat_id;
|
||||||
|
|
||||||
|
INSERT INTO config_spt
|
||||||
|
(task_id, title, pet_id, online, level, enter_id, description, is_enable, remark)
|
||||||
|
VALUES
|
||||||
|
(301,'蘑菇怪',47,1,1,12,'生活在克洛斯星,被艾里逊的液氮冻伤而发狂,使用火焰喷射器可以使它安静下来。制服它可以获得草系精灵小蘑菇。',1,'破除防护罩'),
|
||||||
|
(302,'钢牙鲨',34,1,1,21,'海洋星海底的危险怪兽,据说它躲藏的洞穴中有制作黑武士装的黑晶矿石。记住,到海底一定要穿上耐压的潜水套装。',1,''),
|
||||||
|
(303,'里奥斯',42,1,2,17,'海盗艾里逊在火山被它困住,战胜它有机会获得火系精灵“胡里亚”。在火山,你会用到喷水装的。',1,'扑灭火焰屏障'),
|
||||||
|
(304,'阿克希亚',50,1,4,40,'塞西利亚星的守护者,正义的精灵圣兽,它是不可战胜的,千年来一直等待着宿命的对手。',1,''),
|
||||||
|
(305,'提亚斯',69,1,3,27,'云霄星出现了一只极具攻击性的变异精灵,拥有很多蛋的它虽然想要努力呵护自己的孩子却力不从心,看来需要大家帮帮忙啊。',1,''),
|
||||||
|
(306,'雷伊',70,1,3,32,'赫尔卡星天空中划过一道闪电,映出了一个酷似精灵的黑影,它全身被电流包围,从它的神态中可以看出它正等待来自各方的挑战。',1,'雷雨天'),
|
||||||
|
(307,'纳多雷',88,1,3,106,'在双子阿尔法星上,特派队遇见了一只巨大的精灵,经过多次挑战后,它仍然丝毫无损,赛尔们是否有办法战胜这只精灵呢?',1,''),
|
||||||
|
(308,'雷纳多',113,1,3,49,'彪悍的雷纳多盘踞在双子贝塔星上,和双子阿尔法星的纳多雷遥相对应,守护着星球上所有精灵的。',1,''),
|
||||||
|
(309,'尤纳斯',132,1,4,314,'黑暗之门的制造者,拥有能够抵御一切的暗影屏障和所有能量来源的黑暗之核。',1,''),
|
||||||
|
(310,'魔狮迪露',187,1,4,53,'魔狮迪露具有神秘的力量,能使自己的体力突破界限,但同时也会受到未知的惩罚。',1,''),
|
||||||
|
(311,'哈莫雷特',216,1,5,60,'拥有无比巨大的身躯,集水火草三种原能为一身,龙系的神秘力量使它所向无敌。失忆的它,似乎还有很多谜团……',1,''),
|
||||||
|
(312,'奈尼芬多',264,1,4,325,'奈尼芬多是爱迪星的守护者,凄美的歌声连月亮都为之倾倒,据说只有音乐的力量才能够唤醒它。',1,''),
|
||||||
|
(316,'厄尔塞拉',421,1,5,61,'浑身散发着各色光芒,任何邪恶在她的光芒下消散无形',1,''),
|
||||||
|
(50,'卡特斯',169,1,2,110,'作为暗黑武斗场的试炼精灵,守护着试炼之门,它的气度和风度非同一般,杀气重重很难对付!',1,''),
|
||||||
|
(51,'魔牙鲨',171,1,3,503,'暗黑第一门的魔牙鲨,被赋予了传说中的暗黑斗气,隐藏在暗影中攻击时它的能力可以被放大增强。',1,''),
|
||||||
|
(53,'贝鲁基德',174,1,3,504,'暗黑第二门的贝鲁基德,暗黑火焰环绕周身,凶悍的外表下藏着善战勇敢的心。',1,''),
|
||||||
|
(55,'巴弗洛',177,1,3,505,'勇猛凶横的巴弗洛把守着暗黑武斗场Ⅲ-Ⅰ门,霹雳闪电般的羽翼攻击、震荡心胸的音乐攻击,让人防不胜防。',1,''),
|
||||||
|
(56,'奇拉塔顿',183,1,3,505,'勇敢的奇拉塔顿驻守在暗黑武斗场Ⅲ-Ⅱ门的那一边,身为大地之子的它驾驭着反物质能量,纵横无敌。',1,''),
|
||||||
|
(59,'西萨拉斯',195,1,3,506,'拥有强大反物质电力的暗黑Ⅳ-Ⅰ门守护者,雷霆之刃震撼寰宇天地,电流之剑穿透空间阻隔,威慑四方。',1,''),
|
||||||
|
(60,'克林卡修',192,1,4,506,'暗黑Ⅳ-Ⅱ门守护者冰雪灵兽克林卡修,冰雪之爪具有猛烈的攻击力,果敢不张扬的个性,让它成为忍者般的精灵。',1,''),
|
||||||
|
(76,'卡库',222,1,4,507,'暗黑Ⅴ-Ⅰ门是武学之门,守门精灵不张扬、不蛮横、步步为营,每出一招都会致命。',1,''),
|
||||||
|
(77,'赫德卡',224,1,4,507,'驻守暗黑V-II门的铁血赫德卡,有着铜墙铁壁的防守能力,有着超级强力的电光炮,它的防御之门你能够开启吗?',1,''),
|
||||||
|
(78,'伊兰罗尼',227,1,5,507,'守护暗黑Ⅴ-Ⅲ门的伊兰罗尼是优雅得体的淑女,擅长在裙摆飘飘、光芒闪耀间使出杀手。',1,''),
|
||||||
|
(117,'斯加尔卡',356,1,5,508,'暗黑VI-I门的守护者,擅长使用暗黑电能的家伙,比起折磨对手的身体,斯加尔卡更喜欢震慑对手的心灵。',1,''),
|
||||||
|
(118,'艾尔伊洛',297,1,5,508,'暗黑VI-II门的守护者,历经了炼狱洗礼的艾尔伊洛开始崇尚爽快的攻击方式,喜欢凭借精湛的技巧近距地伤害对手。',1,''),
|
||||||
|
(119,'布林克克',359,1,5,508,'暗黑VI-III门的守护者,拥有海妖之力的庇护,体内充满着混沌的能量企图吞噬整个海洋。',1,''),
|
||||||
|
(502,'魔花使者',438,1,5,509,'暗黑VII-I门的守护者,比恩特的进化形态,浑身散发着反物质世界中的黑暗气息,散发出来的毒粉是它的致命武器。',1,''),
|
||||||
|
(503,'莫尔加斯',441,1,5,509,'暗黑VII-II门的守护者,莫鲁格尔的进化形态,受到了反物质世界的影响,浑身被黑暗所包围,拥有极强的防御能力,所有攻击在它面前都显得非常渺小。',1,''),
|
||||||
|
(504,'萨诺拉斯',435,1,5,509,'暗黑VII-III门的守护者,萨诺的进化形态,经过岩浆洗礼的皮肤拥有独特的降温功能,即使在极其炎热的环境下依然不受影响。',1,''),
|
||||||
|
(606,'帕多尼',656,1,5,510,'暗黑Ⅷ-Ⅰ门的守护者,浑身充斥着暗黑能量,暗黑能量会随着它的歌神散发出来。',1,''),
|
||||||
|
(607,'加洛德',659,1,5,510,'暗黑Ⅷ-Ⅱ门的守护,暗黑能量的注入,使它的脾气变得暴躁,擅长与对手近身搏斗,浑身的尖刺、催生出的植物都是它进攻的利器。',1,''),
|
||||||
|
(608,'萨多拉尼',661,1,5,510,'暗黑Ⅷ-Ⅲ门的守护,将暗黑能量融入自身,肢体变得非常结实有力,虽然体积很小,但是却拥有了堪比巨龙的神力。',1,'')
|
||||||
|
ON CONFLICT (task_id) DO UPDATE
|
||||||
|
SET
|
||||||
|
title = EXCLUDED.title,
|
||||||
|
pet_id = EXCLUDED.pet_id,
|
||||||
|
online = EXCLUDED.online,
|
||||||
|
level = EXCLUDED.level,
|
||||||
|
enter_id = EXCLUDED.enter_id,
|
||||||
|
description = EXCLUDED.description,
|
||||||
|
is_enable = EXCLUDED.is_enable,
|
||||||
|
remark = EXCLUDED.remark,
|
||||||
|
"updateTime" = NOW();
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -82,7 +82,9 @@ func (h Controller) DASHIbeiR(req *C2s_MASTER_REWARDSR, c *player.Player) (resul
|
|||||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrAwardAlreadyClaimed)
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrAwardAlreadyClaimed)
|
||||||
}
|
}
|
||||||
|
|
||||||
consumeMasterCupItems(c, requiredItems)
|
if err := consumeMasterCupItems(c, requiredItems); err != nil {
|
||||||
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrInsufficientItems)
|
||||||
|
}
|
||||||
progress.Set(uint(req.ElementType))
|
progress.Set(uint(req.ElementType))
|
||||||
taskData.Data = progress.Bytes()
|
taskData.Data = progress.Bytes()
|
||||||
if taskErr = c.Service.Task.SetTask(taskData); taskErr != nil {
|
if taskErr = c.Service.Task.SetTask(taskData); taskErr != nil {
|
||||||
@@ -130,10 +132,13 @@ func hasEnoughMasterCupItems(c *player.Player, requiredItems []ItemS) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func consumeMasterCupItems(c *player.Player, requiredItems []ItemS) {
|
func consumeMasterCupItems(c *player.Player, requiredItems []ItemS) error {
|
||||||
for _, item := range requiredItems {
|
for _, item := range requiredItems {
|
||||||
c.Service.Item.UPDATE(item.ItemId, -int(item.ItemCnt))
|
if err := c.Service.Item.UPDATE(item.ItemId, -int(item.ItemCnt)); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendMasterCupRewardItems(c *player.Player, result *S2C_MASTER_REWARDSR, itemList []data.ItemInfo) {
|
func appendMasterCupRewardItems(c *player.Player, result *S2C_MASTER_REWARDSR, itemList []data.ItemInfo) {
|
||||||
|
|||||||
@@ -26,12 +26,11 @@ func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (res
|
|||||||
if data1.EggNum > 10 || data1.EggNum <= 0 {
|
if data1.EggNum > 10 || data1.EggNum <= 0 {
|
||||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
|
||||||
}
|
}
|
||||||
if r < 0 {
|
if r <= 0 || data1.EggNum > r {
|
||||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
||||||
}
|
}
|
||||||
if data1.EggNum > r {
|
if err := c.Service.Item.UPDATE(400501, int(-data1.EggNum)); err != nil {
|
||||||
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
|
||||||
|
|
||||||
}
|
}
|
||||||
result = &S2C_EGG_GAME_PLAY{ListInfo: []data.ItemInfo{}}
|
result = &S2C_EGG_GAME_PLAY{ListInfo: []data.ItemInfo{}}
|
||||||
if grand.Meet(int(data1.EggNum), 100) {
|
if grand.Meet(int(data1.EggNum), 100) {
|
||||||
@@ -52,8 +51,6 @@ func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (res
|
|||||||
for _, item := range addedItems {
|
for _, item := range addedItems {
|
||||||
result.ListInfo = append(result.ListInfo, data.ItemInfo{ItemId: item.ItemId, ItemCnt: item.ItemCnt})
|
result.ListInfo = append(result.ListInfo, data.ItemInfo{ItemId: item.ItemId, ItemCnt: item.ItemCnt})
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Service.Item.UPDATE(400501, int(-data1.EggNum))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ func (h Controller) GET_XUANCAI(data *C2s_GET_XUANCAI, c *player.Player) (result
|
|||||||
|
|
||||||
// 检查该位是否未被选中(避免重复)
|
// 检查该位是否未被选中(避免重复)
|
||||||
if (result.Status & mask) == 0 {
|
if (result.Status & mask) == 0 {
|
||||||
|
result.Status |= mask
|
||||||
itemID := uint32(400686 + randBitIdx + 1)
|
itemID := uint32(400686 + randBitIdx + 1)
|
||||||
selectedItems = append(selectedItems, itemID)
|
selectedItems = append(selectedItems, itemID)
|
||||||
itemMask[itemID] = mask
|
itemMask[itemID] = mask
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func startMapBossFight(
|
|||||||
ai *player.AI_player,
|
ai *player.AI_player,
|
||||||
fn func(model.FightOverInfo),
|
fn func(model.FightOverInfo),
|
||||||
) (*fight.FightC, errorcode.ErrorCode) {
|
) (*fight.FightC, errorcode.ErrorCode) {
|
||||||
ourPets := p.GetPetInfo(100)
|
ourPets := p.GetPetInfo(p.CurrentMapPetLevelLimit())
|
||||||
oppPets := ai.GetPetInfo(0)
|
oppPets := ai.GetPetInfo(0)
|
||||||
if mapNode != nil && mapNode.IsGroupBoss != 0 {
|
if mapNode != nil && mapNode.IsGroupBoss != 0 {
|
||||||
if len(ourPets) > 0 && len(oppPets) > 0 {
|
if len(ourPets) > 0 && len(oppPets) > 0 {
|
||||||
@@ -98,8 +98,8 @@ func (Controller) OnPlayerFightNpcMonster(req *FightNpcMonsterInboundInfo, p *pl
|
|||||||
if err = p.CanFight(); err != 0 {
|
if err = p.CanFight(); err != 0 {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if req.Number > 9 {
|
if int(req.Number) >= len(p.Data) {
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
return nil, errorcode.ErrorCodes.ErrPokemonNotHere
|
||||||
}
|
}
|
||||||
|
|
||||||
refPet := p.Data[req.Number]
|
refPet := p.Data[req.Number]
|
||||||
@@ -114,7 +114,7 @@ func (Controller) OnPlayerFightNpcMonster(req *FightNpcMonsterInboundInfo, p *pl
|
|||||||
p.Fightinfo.Status = fightinfo.BattleMode.FIGHT_WITH_NPC
|
p.Fightinfo.Status = fightinfo.BattleMode.FIGHT_WITH_NPC
|
||||||
p.Fightinfo.Mode = fightinfo.BattleMode.MULTI_MODE
|
p.Fightinfo.Mode = fightinfo.BattleMode.MULTI_MODE
|
||||||
|
|
||||||
_, err = fight.NewFight(p, ai, p.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
_, err = fight.NewFight(p, ai, p.GetPetInfo(p.CurrentMapPetLevelLimit()), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
||||||
handleNpcFightRewards(p, foi, monster)
|
handleNpcFightRewards(p, foi, monster)
|
||||||
})
|
})
|
||||||
if err != 0 {
|
if err != 0 {
|
||||||
@@ -236,7 +236,7 @@ func shouldGrantBossWinBonus(fightC *fight.FightC, playerID uint32, bossConfig c
|
|||||||
|
|
||||||
func buildNpcMonsterInfo(refPet player.OgrePetInfo, mapID uint32) (*model.PetInfo, *model.PlayerInfo, errorcode.ErrorCode) {
|
func buildNpcMonsterInfo(refPet player.OgrePetInfo, mapID uint32) (*model.PetInfo, *model.PlayerInfo, errorcode.ErrorCode) {
|
||||||
if refPet.ID == 0 {
|
if refPet.ID == 0 {
|
||||||
return nil, nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
return nil, nil, errorcode.ErrorCodes.ErrPokemonNotHere
|
||||||
}
|
}
|
||||||
|
|
||||||
monster := model.GenPetInfo(
|
monster := model.GenPetInfo(
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -207,32 +206,8 @@ func buildTowerMonsterInfo(towerBoss configmodel.BaseTowerConfig) (*model.Player
|
|||||||
monsterInfo := &model.PlayerInfo{Nick: towerBoss.Name}
|
monsterInfo := &model.PlayerInfo{Nick: towerBoss.Name}
|
||||||
for i, boss := range bosses {
|
for i, boss := range bosses {
|
||||||
monster := model.GenPetInfo(int(boss.MonID), 24, int(boss.Nature), 0, int(boss.Lv), nil, 0)
|
monster := model.GenPetInfo(int(boss.MonID), 24, int(boss.Nature), 0, int(boss.Lv), nil, 0)
|
||||||
if boss.Hp != 0 {
|
monster.ConfigBoss(boss.PetBaseConfig)
|
||||||
monster.Hp = uint32(boss.Hp)
|
appendPetEffects(monster, boss.Effect)
|
||||||
monster.MaxHp = uint32(boss.Hp)
|
|
||||||
}
|
|
||||||
|
|
||||||
for statIdx, prop := range boss.Prop {
|
|
||||||
if prop != 0 {
|
|
||||||
monster.Prop[statIdx] = prop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for skillIdx := 0; skillIdx < len(monster.SkillList) && skillIdx < len(boss.SKill); skillIdx++ {
|
|
||||||
if boss.SKill[skillIdx] != 0 {
|
|
||||||
monster.SkillList[skillIdx].ID = boss.SKill[skillIdx]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
effects := service.NewEffectService().Args(boss.Effect)
|
|
||||||
for _, effect := range effects {
|
|
||||||
monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
|
|
||||||
Idx: uint16(effect.ID),
|
|
||||||
EID: gconv.Uint16(effect.Eid),
|
|
||||||
Args: gconv.Ints(effect.Args),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
monster.CatchTime = uint32(i)
|
monster.CatchTime = uint32(i)
|
||||||
monsterInfo.PetList = append(monsterInfo.PetList, *monster)
|
monsterInfo.PetList = append(monsterInfo.PetList, *monster)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"blazing/common/rpc"
|
"blazing/common/rpc"
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
|
"blazing/cool"
|
||||||
"blazing/logic/service/common"
|
"blazing/logic/service/common"
|
||||||
"blazing/logic/service/fight"
|
"blazing/logic/service/fight"
|
||||||
"blazing/logic/service/fight/pvp"
|
"blazing/logic/service/fight/pvp"
|
||||||
@@ -37,6 +38,8 @@ func (h Controller) JoINtop(data *PetTOPLEVELnboundInfo, c *player.Player) (resu
|
|||||||
Nick: c.Info.Nick,
|
Nick: c.Info.Nick,
|
||||||
FightMode: fightMode,
|
FightMode: fightMode,
|
||||||
Status: status,
|
Status: status,
|
||||||
|
IsVip: cool.Config.ServerInfo.IsVip,
|
||||||
|
IsDebug: cool.Config.ServerInfo.IsDebug,
|
||||||
CatchTimes: pvp.AvailableCatchTimes(c.GetPetInfo(0)),
|
CatchTimes: pvp.AvailableCatchTimes(c.GetPetInfo(0)),
|
||||||
}
|
}
|
||||||
if callErr := Maincontroller.RPCClient.MatchJoinOrUpdate(joinPayload); callErr != nil {
|
if callErr := Maincontroller.RPCClient.MatchJoinOrUpdate(joinPayload); callErr != nil {
|
||||||
|
|||||||
@@ -87,6 +87,14 @@ type C2S_RoomPetInfo struct {
|
|||||||
CatchTime uint32 `json:"catchTime"`
|
CatchTime uint32 `json:"catchTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// C2S_RoomPetShowToggle 基地展示精灵添加/移除请求
|
||||||
|
type C2S_RoomPetShowToggle struct {
|
||||||
|
Head common.TomeeHeader `cmd:"2326" struc:"skip"`
|
||||||
|
CatchTime uint32 `json:"catchTime"`
|
||||||
|
PetID uint32 `json:"petID"`
|
||||||
|
Flag uint32 `json:"flag"` // 1=添加展示, 0=移除展示
|
||||||
|
}
|
||||||
|
|
||||||
// C2S_BUY_FITMENT 定义请求或响应数据结构。
|
// C2S_BUY_FITMENT 定义请求或响应数据结构。
|
||||||
type C2S_BUY_FITMENT struct {
|
type C2S_BUY_FITMENT struct {
|
||||||
Head common.TomeeHeader `cmd:"10004" struc:"skip"`
|
Head common.TomeeHeader `cmd:"10004" struc:"skip"`
|
||||||
|
|||||||
@@ -99,6 +99,12 @@ type GetPetLearnableSkillsInboundInfo struct {
|
|||||||
CatchTime uint32 `json:"catchTime"`
|
CatchTime uint32 `json:"catchTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CommitPetSkillsInboundInfo struct {
|
||||||
|
Head common.TomeeHeader `cmd:"52313" struc:"skip"`
|
||||||
|
CatchTime uint32 `json:"catchTime"`
|
||||||
|
Skill [4]uint32 `json:"skill"`
|
||||||
|
}
|
||||||
|
|
||||||
type C2S_PetFusion struct {
|
type C2S_PetFusion struct {
|
||||||
Head common.TomeeHeader `cmd:"2351" struc:"skip"`
|
Head common.TomeeHeader `cmd:"2351" struc:"skip"`
|
||||||
Mcatchtime uint32 `json:"mcatchtime" msgpack:"mcatchtime"`
|
Mcatchtime uint32 `json:"mcatchtime" msgpack:"mcatchtime"`
|
||||||
|
|||||||
@@ -18,10 +18,13 @@ func (h Controller) ItemSale(data *C2S_ITEM_SALE, c *player.Player) (result *fig
|
|||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := c.Service.Item.UPDATE(data.ItemId, -gconv.Int(data.Amount)); err != nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
|
}
|
||||||
|
|
||||||
itemConfig := xmlres.ItemsMAP[int(data.ItemId)]
|
itemConfig := xmlres.ItemsMAP[int(data.ItemId)]
|
||||||
if itemConfig.SellPrice != 0 {
|
if itemConfig.SellPrice != 0 {
|
||||||
c.Info.Coins += int64(int64(data.Amount) * int64(itemConfig.SellPrice))
|
c.Info.Coins += int64(int64(data.Amount) * int64(itemConfig.SellPrice))
|
||||||
}
|
}
|
||||||
c.Service.Item.UPDATE(data.ItemId, -gconv.Int(data.Amount))
|
|
||||||
return result, 0
|
return result, 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
// ItemDefaultLeftTime 道具默认剩余时间(毫秒)
|
// ItemDefaultLeftTime 道具默认剩余时间(毫秒)
|
||||||
ItemDefaultLeftTime = 360000
|
ItemDefaultLeftTime = 360000
|
||||||
|
// UniversalNatureItemID 全能性格转化剂Ω
|
||||||
|
UniversalNatureItemID uint32 = 300136
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetUserItemList 获取用户道具列表
|
// GetUserItemList 获取用户道具列表
|
||||||
@@ -33,11 +35,16 @@ func (h Controller) GetUserItemList(data *ItemListInboundInfo, c *player.Player)
|
|||||||
// c: 当前玩家对象
|
// c: 当前玩家对象
|
||||||
// 返回: 使用后的宠物信息和错误码
|
// 返回: 使用后的宠物信息和错误码
|
||||||
func (h Controller) UsePetItemOutOfFight(data *C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *player.Player) (result *item.S2C_USE_PET_ITEM_OUT_OF_FIGHT, err errorcode.ErrorCode) {
|
func (h Controller) UsePetItemOutOfFight(data *C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *player.Player) (result *item.S2C_USE_PET_ITEM_OUT_OF_FIGHT, err errorcode.ErrorCode) {
|
||||||
_, currentPet, found := c.FindPet(data.CatchTime)
|
slot, found := c.FindPetBagSlot(data.CatchTime)
|
||||||
if !found {
|
if !found {
|
||||||
return nil, errorcode.ErrorCodes.Err10401
|
return nil, errorcode.ErrorCodes.Err10401
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if currentPet == nil {
|
||||||
|
return nil, errorcode.ErrorCodes.Err10401
|
||||||
|
}
|
||||||
|
|
||||||
itemID := uint32(data.ItemID)
|
itemID := uint32(data.ItemID)
|
||||||
if c.Service.Item.CheakItem(itemID) == 0 {
|
if c.Service.Item.CheakItem(itemID) == 0 {
|
||||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
@@ -51,7 +58,10 @@ func (h Controller) UsePetItemOutOfFight(data *C2S_USE_PET_ITEM_OUT_OF_FIGHT, c
|
|||||||
return nil, errcode
|
return nil, errcode
|
||||||
}
|
}
|
||||||
refreshPetPaneKeepHP(currentPet, oldHP)
|
refreshPetPaneKeepHP(currentPet, oldHP)
|
||||||
c.Service.Item.UPDATE(itemID, -1)
|
if err := c.Service.Item.UPDATE(itemID, -1); err != nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
|
}
|
||||||
|
c.Service.Info.Save(*c.Info)
|
||||||
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
|
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
|
||||||
copier.Copy(&result, currentPet)
|
copier.Copy(&result, currentPet)
|
||||||
return result, 0
|
return result, 0
|
||||||
@@ -83,7 +93,10 @@ func (h Controller) UsePetItemOutOfFight(data *C2S_USE_PET_ITEM_OUT_OF_FIGHT, c
|
|||||||
return nil, errcode
|
return nil, errcode
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Service.Item.UPDATE(itemID, -1)
|
if err := c.Service.Item.UPDATE(itemID, -1); err != nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
|
}
|
||||||
|
c.Service.Info.Save(*c.Info)
|
||||||
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
|
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
|
||||||
copier.Copy(&result, currentPet)
|
copier.Copy(&result, currentPet)
|
||||||
return result, 0
|
return result, 0
|
||||||
@@ -126,7 +139,9 @@ func (h Controller) handlexuancaiItem(currentPet *model.PetInfo, c *player.Playe
|
|||||||
return errorcode.ErrorCodes.ErrItemUnusable
|
return errorcode.ErrorCodes.ErrItemUnusable
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Service.Item.UPDATE(itemid, -100)
|
if err := c.Service.Item.UPDATE(itemid, -100); err != nil {
|
||||||
|
return errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,11 +197,24 @@ func (h Controller) handleRegularPetItem(itemID uint32, currentPet *model.PetInf
|
|||||||
// c: 当前玩家对象
|
// c: 当前玩家对象
|
||||||
// 返回: 无数据和错误码
|
// 返回: 无数据和错误码
|
||||||
func (h Controller) ResetNature(data *C2S_PET_RESET_NATURE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) ResetNature(data *C2S_PET_RESET_NATURE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
_, currentPet, found := c.FindPet(data.CatchTime)
|
slot, found := c.FindPetBagSlot(data.CatchTime)
|
||||||
if !found {
|
if !found {
|
||||||
return nil, errorcode.ErrorCodes.Err10401
|
return nil, errorcode.ErrorCodes.Err10401
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if currentPet == nil {
|
||||||
|
return nil, errorcode.ErrorCodes.Err10401
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.ItemId != UniversalNatureItemID {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrItemUnusable
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := xmlres.NatureRootMap[int(data.Nature)]; !ok {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrItemUnusable
|
||||||
|
}
|
||||||
|
|
||||||
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
|
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
|
||||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
}
|
}
|
||||||
@@ -194,7 +222,10 @@ func (h Controller) ResetNature(data *C2S_PET_RESET_NATURE, c *player.Player) (r
|
|||||||
currentHP := currentPet.Hp
|
currentHP := currentPet.Hp
|
||||||
currentPet.Nature = data.Nature
|
currentPet.Nature = data.Nature
|
||||||
refreshPetPaneKeepHP(currentPet, currentHP)
|
refreshPetPaneKeepHP(currentPet, currentHP)
|
||||||
c.Service.Item.UPDATE(data.ItemId, -1)
|
if err := c.Service.Item.UPDATE(data.ItemId, -1); err != nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
|
}
|
||||||
|
c.Service.Info.Save(*c.Info)
|
||||||
return result, 0
|
return result, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,29 +253,38 @@ func (h Controller) UseSpeedupItem(data *C2S_USE_SPEEDUP_ITEM, c *player.Player)
|
|||||||
if c.Info.TwoTimes != 0 {
|
if c.Info.TwoTimes != 0 {
|
||||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||||
}
|
}
|
||||||
c.Info.TwoTimes += 50 // 玩家对象新增 TwoTimesExp 字段存储双倍剩余次数
|
|
||||||
case 300067:
|
case 300067:
|
||||||
if c.Info.TwoTimes != 0 {
|
if c.Info.TwoTimes != 0 {
|
||||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||||
}
|
}
|
||||||
c.Info.TwoTimes += 25 // 玩家对象新增 TwoTimesExp 字段存储双倍剩余次数
|
|
||||||
case 300051: // 假设1002是三倍经验加速器道具ID
|
case 300051: // 假设1002是三倍经验加速器道具ID
|
||||||
if c.Info.ThreeTimes != 0 {
|
if c.Info.ThreeTimes != 0 {
|
||||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||||
}
|
}
|
||||||
c.Info.ThreeTimes += 50 // 玩家对象新增 ThreeTimesExp 字段存储三倍剩余次数
|
|
||||||
case 300115:
|
case 300115:
|
||||||
if c.Info.ThreeTimes != 0 {
|
if c.Info.ThreeTimes != 0 {
|
||||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||||
}
|
}
|
||||||
c.Info.ThreeTimes += 30 // 玩家对象新增 ThreeTimesExp 字段存储三倍剩余次数
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError // 未知道具ID
|
return nil, errorcode.ErrorCodes.ErrSystemError // 未知道具ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 扣减道具(数量-1)
|
// 3. 扣减道具(数量-1)
|
||||||
c.Service.Item.UPDATE(data.ItemID, -1)
|
if err := c.Service.Item.UPDATE(data.ItemID, -1); err != nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
|
}
|
||||||
|
|
||||||
|
switch data.ItemID {
|
||||||
|
case 300027: // 假设1001是双倍经验加速器道具ID
|
||||||
|
c.Info.TwoTimes += 50 // 玩家对象新增 TwoTimesExp 字段存储双倍剩余次数
|
||||||
|
case 300067:
|
||||||
|
c.Info.TwoTimes += 25 // 玩家对象新增 TwoTimesExp 字段存储双倍剩余次数
|
||||||
|
case 300051: // 假设1002是三倍经验加速器道具ID
|
||||||
|
c.Info.ThreeTimes += 50 // 玩家对象新增 ThreeTimesExp 字段存储三倍剩余次数
|
||||||
|
case 300115:
|
||||||
|
c.Info.ThreeTimes += 30 // 玩家对象新增 ThreeTimesExp 字段存储三倍剩余次数
|
||||||
|
}
|
||||||
result.ThreeTimes = uint32(c.Info.ThreeTimes) // 返回三倍经验剩余次数
|
result.ThreeTimes = uint32(c.Info.ThreeTimes) // 返回三倍经验剩余次数
|
||||||
result.TwoTimes = uint32(c.Info.TwoTimes) // 返回双倍经验剩余次数
|
result.TwoTimes = uint32(c.Info.TwoTimes) // 返回双倍经验剩余次数
|
||||||
|
|
||||||
@@ -275,10 +315,11 @@ func (h Controller) UseEnergyXishou(data *C2S_USE_ENERGY_XISHOU, c *player.Playe
|
|||||||
}
|
}
|
||||||
// 2. 核心业务逻辑:更新能量吸收器剩余次数
|
// 2. 核心业务逻辑:更新能量吸收器剩余次数
|
||||||
// (注:可根据道具ID配置不同的次数加成,此处默认+1)
|
// (注:可根据道具ID配置不同的次数加成,此处默认+1)
|
||||||
|
if err := c.Service.Item.UPDATE(data.ItemID, -1); err != nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
|
}
|
||||||
c.Info.EnergyTime += 40 // 玩家对象新增 EnergyTimes 字段存储能量吸收剩余次数
|
c.Info.EnergyTime += 40 // 玩家对象新增 EnergyTimes 字段存储能量吸收剩余次数
|
||||||
|
|
||||||
// 3. 扣减道具(数量-1)
|
|
||||||
c.Service.Item.UPDATE(data.ItemID, -1)
|
|
||||||
result = &item.S2C_USE_ENERGY_XISHOU{
|
result = &item.S2C_USE_ENERGY_XISHOU{
|
||||||
EnergyTimes: uint32(c.Info.EnergyTime),
|
EnergyTimes: uint32(c.Info.EnergyTime),
|
||||||
}
|
}
|
||||||
@@ -309,6 +350,9 @@ func (h Controller) UseAutoFightItem(data *C2S_USE_AUTO_FIGHT_ITEM, c *player.Pl
|
|||||||
if c.Info.AutoFightTime != 0 {
|
if c.Info.AutoFightTime != 0 {
|
||||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||||
}
|
}
|
||||||
|
if err := c.Service.Item.UPDATE(data.ItemID, -1); err != nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||||
|
}
|
||||||
result = &item.S2C_USE_AUTO_FIGHT_ITEM{}
|
result = &item.S2C_USE_AUTO_FIGHT_ITEM{}
|
||||||
// 2. 核心业务逻辑:开启自动战斗 + 更新剩余次数
|
// 2. 核心业务逻辑:开启自动战斗 + 更新剩余次数
|
||||||
c.Info.AutoFight = 3 // 按需求设置自动战斗flag为3(需测试)
|
c.Info.AutoFight = 3 // 按需求设置自动战斗flag为3(需测试)
|
||||||
@@ -324,8 +368,6 @@ func (h Controller) UseAutoFightItem(data *C2S_USE_AUTO_FIGHT_ITEM, c *player.Pl
|
|||||||
c.Info.AutoFightTime += 50
|
c.Info.AutoFightTime += 50
|
||||||
}
|
}
|
||||||
result.AutoFightTimes = c.Info.AutoFightTime
|
result.AutoFightTimes = c.Info.AutoFightTime
|
||||||
// 3. 扣减道具(数量-1)
|
|
||||||
c.Service.Item.UPDATE(data.ItemID, -1)
|
|
||||||
|
|
||||||
return result, 0
|
return result, 0
|
||||||
}
|
}
|
||||||
|
|||||||
60
logic/controller/item_use_test.go
Normal file
60
logic/controller/item_use_test.go
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/common/data/xmlres"
|
||||||
|
"blazing/logic/service/player"
|
||||||
|
playermodel "blazing/modules/player/model"
|
||||||
|
blservice "blazing/modules/player/service"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUsePetItemOutOfFightAppliesToBackupPetInMemory(t *testing.T) {
|
||||||
|
petID := firstPetIDForControllerTest(t)
|
||||||
|
backupPet := playermodel.GenPetInfo(petID, 31, 0, 0, 50, nil, 0)
|
||||||
|
if backupPet == nil {
|
||||||
|
t.Fatal("failed to generate backup pet")
|
||||||
|
}
|
||||||
|
if backupPet.MaxHp <= 1 {
|
||||||
|
t.Fatalf("expected generated pet to have max hp > 1, got %d", backupPet.MaxHp)
|
||||||
|
}
|
||||||
|
backupPet.Hp = 1
|
||||||
|
|
||||||
|
testPlayer := player.NewPlayer(nil)
|
||||||
|
testPlayer.Info = &playermodel.PlayerInfo{
|
||||||
|
UserID: 1,
|
||||||
|
PetList: []playermodel.PetInfo{},
|
||||||
|
BackupPetList: []playermodel.PetInfo{*backupPet},
|
||||||
|
}
|
||||||
|
testPlayer.Service = blservice.NewUserService(testPlayer.Info.UserID)
|
||||||
|
|
||||||
|
itemID, recoverHP := firstRecoverHPItemForControllerTest(t)
|
||||||
|
if recoverHP <= 0 {
|
||||||
|
t.Fatalf("expected positive recover hp for item %d, got %d", itemID, recoverHP)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := (Controller{}).UsePetItemOutOfFight(&C2S_USE_PET_ITEM_OUT_OF_FIGHT{
|
||||||
|
CatchTime: backupPet.CatchTime,
|
||||||
|
ItemID: int32(itemID),
|
||||||
|
}, testPlayer)
|
||||||
|
if err != 0 {
|
||||||
|
t.Fatalf("expected backup pet item use to succeed in-memory, got err=%d", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
updatedPet := testPlayer.Info.BackupPetList[0]
|
||||||
|
if updatedPet.Hp <= 1 {
|
||||||
|
t.Fatalf("expected backup pet hp to increase in memory, got hp=%d", updatedPet.Hp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func firstRecoverHPItemForControllerTest(t *testing.T) (uint32, int) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
for id, cfg := range xmlres.ItemsMAP {
|
||||||
|
if cfg.HP > 0 {
|
||||||
|
return uint32(id), cfg.HP
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Fatal("xmlres.ItemsMAP has no HP recovery item")
|
||||||
|
return 0, 0
|
||||||
|
}
|
||||||
@@ -19,20 +19,13 @@ func (h Controller) SavePetBagOrder(
|
|||||||
return nil, 0
|
return nil, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// PetRetrieveFromWarehouse 领回仓库精灵
|
// PetRetrieveFromWarehouse 从放生仓库领回精灵
|
||||||
func (h Controller) PetRetrieveFromWarehouse(
|
func (h Controller) PetRetrieveFromWarehouse(
|
||||||
data *PET_RETRIEVE, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
data *PET_RETRIEVE, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
if _, ok := player.FindPetBagSlot(data.CatchTime); ok {
|
if !player.Service.Pet.UpdateFree(data.CatchTime, 1, 0) {
|
||||||
return nil, 0
|
return nil, errorcode.ErrorCodes.ErrPokemonIDMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
petInfo := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
|
||||||
if petInfo == nil {
|
|
||||||
return nil, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
player.AddPetToAvailableBag(petInfo.Data)
|
|
||||||
|
|
||||||
return nil, 0
|
return nil, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ func (h Controller) GetPetBargeList(data *PetBargeListInboundInfo, player *playe
|
|||||||
ret.PetBargeList = append(ret.PetBargeList, pet.PetBargeListInfo{
|
ret.PetBargeList = append(ret.PetBargeList, pet.PetBargeListInfo{
|
||||||
PetId: uint32(v.Args[0]),
|
PetId: uint32(v.Args[0]),
|
||||||
EnCntCnt: 1,
|
EnCntCnt: 1,
|
||||||
IsCatched: uint32(v.Results[0]),
|
IsCatched: uint32(v.Results[1]),
|
||||||
IsKilled: uint32(v.Results[1]),
|
IsKilled: uint32(v.Results[0]),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ func (h Controller) PetELV(data *C2S_PET_EVOLVTION, c *player.Player) (result *f
|
|||||||
return nil, errorcode.ErrorCodes.ErrInsufficientItemsMulti
|
return nil, errorcode.ErrorCodes.ErrInsufficientItemsMulti
|
||||||
}
|
}
|
||||||
if branch.EvolvItem != 0 {
|
if branch.EvolvItem != 0 {
|
||||||
c.Service.Item.UPDATE(uint32(branch.EvolvItem), -branch.EvolvItemCount)
|
if err := c.Service.Item.UPDATE(uint32(branch.EvolvItem), -branch.EvolvItemCount); err != nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrInsufficientItemsMulti
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPet.ID = uint32(branch.MonTo)
|
currentPet.ID = uint32(branch.MonTo)
|
||||||
|
|||||||
@@ -17,11 +17,16 @@ const (
|
|||||||
// c: 当前玩家对象
|
// c: 当前玩家对象
|
||||||
// 返回: 分配结果和错误码
|
// 返回: 分配结果和错误码
|
||||||
func (h Controller) PetEVDiy(data *PetEV, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) PetEVDiy(data *PetEV, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
_, currentPet, found := c.FindPet(data.CacthTime)
|
slot, found := c.FindPetBagSlot(data.CacthTime)
|
||||||
if !found {
|
if !found {
|
||||||
return nil, errorcode.ErrorCodes.Err10401
|
return nil, errorcode.ErrorCodes.Err10401
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if currentPet == nil {
|
||||||
|
return nil, errorcode.ErrorCodes.Err10401
|
||||||
|
}
|
||||||
|
|
||||||
var targetTotal uint32
|
var targetTotal uint32
|
||||||
var currentTotal uint32
|
var currentTotal uint32
|
||||||
for i, evValue := range data.EVs {
|
for i, evValue := range data.EVs {
|
||||||
|
|||||||
45
logic/controller/pet_ev_test.go
Normal file
45
logic/controller/pet_ev_test.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"blazing/logic/service/player"
|
||||||
|
playermodel "blazing/modules/player/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPetEVDiy_AppliesToBackupPet(t *testing.T) {
|
||||||
|
p := player.NewPlayer(nil)
|
||||||
|
p.Info = &playermodel.PlayerInfo{
|
||||||
|
EVPool: 20,
|
||||||
|
PetList: []playermodel.PetInfo{
|
||||||
|
{CatchTime: 1},
|
||||||
|
},
|
||||||
|
BackupPetList: []playermodel.PetInfo{
|
||||||
|
{
|
||||||
|
CatchTime: 2,
|
||||||
|
Level: 100,
|
||||||
|
Ev: [6]uint32{0, 4, 0, 0, 0, 0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
data := &PetEV{
|
||||||
|
CacthTime: 2,
|
||||||
|
EVs: [6]uint32{0, 8, 4, 0, 0, 0},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := (Controller{}).PetEVDiy(data, p)
|
||||||
|
if err != 0 {
|
||||||
|
t.Fatalf("PetEVDiy returned error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
got := p.Info.BackupPetList[0].Ev
|
||||||
|
want := [6]uint32{0, 8, 4, 0, 0, 0}
|
||||||
|
if got != want {
|
||||||
|
t.Fatalf("backup pet EV mismatch, got %v want %v", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if gotPool, wantPool := p.Info.EVPool, int64(12); gotPool != wantPool {
|
||||||
|
t.Fatalf("EVPool mismatch, got %d want %d", gotPool, wantPool)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,16 +65,33 @@ func (h Controller) PetFusion(data *C2S_PetFusion, c *player.Player) (result *pe
|
|||||||
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
||||||
}
|
}
|
||||||
|
|
||||||
consumeItems(c, materialCounts)
|
|
||||||
c.Info.Coins -= petFusionCost
|
|
||||||
|
|
||||||
if resultPetID == 0 {
|
if resultPetID == 0 {
|
||||||
if useOptionalItem(c, data.GoldItem1[:], petFusionFailureItemID) {
|
failedAux := *auxPet
|
||||||
result.CostItemFlag = 1
|
if auxPet.Level > 5 {
|
||||||
} else if auxPet.Level > 5 {
|
failedAux.Downgrade(auxPet.Level - 5)
|
||||||
auxPet.Downgrade(auxPet.Level - 5)
|
|
||||||
} else {
|
} else {
|
||||||
auxPet.Downgrade(1)
|
failedAux.Downgrade(1)
|
||||||
|
}
|
||||||
|
txResult, errCode := c.Service.PetFusionTx(
|
||||||
|
*c.Info,
|
||||||
|
data.Mcatchtime,
|
||||||
|
data.Auxcatchtime,
|
||||||
|
materialCounts,
|
||||||
|
data.GoldItem1[:],
|
||||||
|
petFusionKeepAuxItemID,
|
||||||
|
petFusionFailureItemID,
|
||||||
|
petFusionCost,
|
||||||
|
nil,
|
||||||
|
&failedAux,
|
||||||
|
)
|
||||||
|
if errCode != 0 {
|
||||||
|
return result, errCode
|
||||||
|
}
|
||||||
|
c.Info.Coins -= petFusionCost
|
||||||
|
if txResult.CostItemUsed {
|
||||||
|
result.CostItemFlag = 1
|
||||||
|
} else if txResult.UpdatedAux != nil {
|
||||||
|
*auxPet = *txResult.UpdatedAux
|
||||||
}
|
}
|
||||||
return &pet.PetFusionInfo{}, 0
|
return &pet.PetFusionInfo{}, 0
|
||||||
}
|
}
|
||||||
@@ -101,18 +118,37 @@ func (h Controller) PetFusion(data *C2S_PetFusion, c *player.Player) (result *pe
|
|||||||
newPet.RandomByWeightShiny()
|
newPet.RandomByWeightShiny()
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Service.Pet.PetAdd(newPet, 0)
|
txResult, errCode := c.Service.PetFusionTx(
|
||||||
//println(c.Info.UserID, "进行融合", len(c.Info.PetList), masterPet.ID, auxPet.ID, newPet.ID)
|
*c.Info,
|
||||||
|
data.Mcatchtime,
|
||||||
c.PetDel(data.Mcatchtime)
|
data.Auxcatchtime,
|
||||||
if useOptionalItem(c, data.GoldItem1[:], petFusionKeepAuxItemID) {
|
materialCounts,
|
||||||
result.CostItemFlag = 1
|
data.GoldItem1[:],
|
||||||
} else {
|
petFusionKeepAuxItemID,
|
||||||
c.PetDel(data.Auxcatchtime)
|
petFusionFailureItemID,
|
||||||
|
petFusionCost,
|
||||||
|
newPet,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
if errCode != 0 {
|
||||||
|
return result, errCode
|
||||||
}
|
}
|
||||||
|
|
||||||
result.ObtainTime = newPet.CatchTime
|
c.Info.Coins -= petFusionCost
|
||||||
result.StarterCpTm = newPet.ID
|
if txResult.CostItemUsed {
|
||||||
|
result.CostItemFlag = 1
|
||||||
|
} else {
|
||||||
|
removePetFromPlayerInfo(c, data.Auxcatchtime)
|
||||||
|
}
|
||||||
|
removePetFromPlayerInfo(c, data.Mcatchtime)
|
||||||
|
|
||||||
|
if txResult.NewPet == nil {
|
||||||
|
return result, errorcode.ErrorCodes.ErrSystemError
|
||||||
|
}
|
||||||
|
c.Info.PetList = append(c.Info.PetList, *txResult.NewPet)
|
||||||
|
|
||||||
|
result.ObtainTime = txResult.NewPet.CatchTime
|
||||||
|
result.StarterCpTm = txResult.NewPet.ID
|
||||||
return result, 0
|
return result, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,21 +185,10 @@ func hasEnoughItems(c *player.Player, itemCounts map[uint32]int) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func consumeItems(c *player.Player, itemCounts map[uint32]int) {
|
func removePetFromPlayerInfo(c *player.Player, catchTime uint32) {
|
||||||
for itemID, count := range itemCounts {
|
index, _, ok := c.FindPet(catchTime)
|
||||||
_ = c.Service.Item.UPDATE(itemID, -count)
|
if !ok {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
c.Info.PetList = append(c.Info.PetList[:index], c.Info.PetList[index+1:]...)
|
||||||
|
|
||||||
func useOptionalItem(c *player.Player, itemIDs []uint32, target uint32) bool {
|
|
||||||
if c.Service.Item.CheakItem(target) <= 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for _, itemID := range itemIDs {
|
|
||||||
if itemID == target {
|
|
||||||
_ = c.Service.Item.UPDATE(target, -1)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,36 +4,41 @@ import (
|
|||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/common"
|
"blazing/logic/service/common"
|
||||||
"blazing/logic/service/pet"
|
"blazing/logic/service/pet"
|
||||||
"blazing/logic/service/player"
|
playersvc "blazing/logic/service/player"
|
||||||
"blazing/modules/player/model"
|
"blazing/modules/player/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetPetInfo 获取精灵信息
|
// GetPetInfo 获取精灵信息
|
||||||
func (h Controller) GetPetInfo(
|
func (h Controller) GetPetInfo(
|
||||||
data *GetPetInfoInboundInfo,
|
data *GetPetInfoInboundInfo,
|
||||||
player *player.Player) (result *model.PetInfo,
|
player *playersvc.Player) (result *model.PetInfo,
|
||||||
err errorcode.ErrorCode) {
|
err errorcode.ErrorCode) {
|
||||||
_, petInfo, found := player.FindPet(data.CatchTime)
|
levelLimit := player.CurrentMapPetLevelLimit()
|
||||||
if found {
|
if slot, found := player.FindPetBagSlot(data.CatchTime); found {
|
||||||
result = petInfo
|
if petInfo := slot.PetInfoPtr(); petInfo != nil {
|
||||||
|
petCopy := playersvc.ApplyPetLevelLimit(*petInfo, levelLimit)
|
||||||
|
result = &petCopy
|
||||||
return result, 0
|
return result, 0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
ret := player.Service.Pet.PetInfoOneByCatchTime(data.CatchTime)
|
||||||
if ret == nil {
|
if ret == nil {
|
||||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||||
}
|
}
|
||||||
|
|
||||||
result = &ret.Data
|
petData := ret.Data
|
||||||
|
petData = playersvc.ApplyPetLevelLimit(petData, levelLimit)
|
||||||
|
result = &petData
|
||||||
return result, 0
|
return result, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserBagPetInfo 获取主背包和并列备用精灵列表
|
// GetUserBagPetInfo 获取主背包和并列备用精灵列表
|
||||||
func (h Controller) GetUserBagPetInfo(
|
func (h Controller) GetUserBagPetInfo(
|
||||||
data *GetUserBagPetInfoInboundEmpty,
|
data *GetUserBagPetInfoInboundEmpty,
|
||||||
player *player.Player) (result *pet.GetUserBagPetInfoOutboundInfo,
|
player *playersvc.Player) (result *pet.GetUserBagPetInfoOutboundInfo,
|
||||||
err errorcode.ErrorCode) {
|
err errorcode.ErrorCode) {
|
||||||
return player.GetUserBagPetInfo(), 0
|
return player.GetUserBagPetInfo(player.CurrentMapPetLevelLimit()), 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPetListInboundEmpty 定义请求或响应数据结构。
|
// GetPetListInboundEmpty 定义请求或响应数据结构。
|
||||||
@@ -44,7 +49,7 @@ type GetPetListInboundEmpty struct {
|
|||||||
// GetPetList 获取当前主背包列表
|
// GetPetList 获取当前主背包列表
|
||||||
func (h Controller) GetPetList(
|
func (h Controller) GetPetList(
|
||||||
data *GetPetListInboundEmpty,
|
data *GetPetListInboundEmpty,
|
||||||
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
player *playersvc.Player) (result *pet.GetPetListOutboundInfo,
|
||||||
err errorcode.ErrorCode) {
|
err errorcode.ErrorCode) {
|
||||||
return buildPetListOutboundInfo(player.Info.PetList), 0
|
return buildPetListOutboundInfo(player.Info.PetList), 0
|
||||||
}
|
}
|
||||||
@@ -57,7 +62,7 @@ type GetPetListFreeInboundEmpty struct {
|
|||||||
// GetPetReleaseList 获取仓库可放生列表
|
// GetPetReleaseList 获取仓库可放生列表
|
||||||
func (h Controller) GetPetReleaseList(
|
func (h Controller) GetPetReleaseList(
|
||||||
data *GetPetListFreeInboundEmpty,
|
data *GetPetListFreeInboundEmpty,
|
||||||
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
player *playersvc.Player) (result *pet.GetPetListOutboundInfo,
|
||||||
err errorcode.ErrorCode) {
|
err errorcode.ErrorCode) {
|
||||||
|
|
||||||
return buildPetListOutboundInfo(player.WarehousePetList()), 0
|
return buildPetListOutboundInfo(player.WarehousePetList()), 0
|
||||||
@@ -66,14 +71,13 @@ func (h Controller) GetPetReleaseList(
|
|||||||
// PlayerShowPet 精灵展示
|
// PlayerShowPet 精灵展示
|
||||||
func (h Controller) PlayerShowPet(
|
func (h Controller) PlayerShowPet(
|
||||||
data *PetShowInboundInfo,
|
data *PetShowInboundInfo,
|
||||||
player *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) {
|
player *playersvc.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) {
|
||||||
result = &pet.PetShowOutboundInfo{
|
result = &pet.PetShowOutboundInfo{
|
||||||
UserID: data.Head.UserID,
|
UserID: data.Head.UserID,
|
||||||
CatchTime: data.CatchTime,
|
CatchTime: data.CatchTime,
|
||||||
Flag: data.Flag,
|
Flag: data.Flag,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, currentPet, ok := player.FindPet(data.CatchTime)
|
|
||||||
if data.Flag == 0 {
|
if data.Flag == 0 {
|
||||||
player.SetPetDisplay(0, nil)
|
player.SetPetDisplay(0, nil)
|
||||||
player.GetSpace().RefreshUserInfo(player)
|
player.GetSpace().RefreshUserInfo(player)
|
||||||
@@ -81,7 +85,14 @@ func (h Controller) PlayerShowPet(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
// 仅允许背包精灵跟随:仓库中的精灵不允许跟随
|
||||||
|
slot, found := player.FindPetBagSlot(data.CatchTime)
|
||||||
|
if !found {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrCannotShowBagPokemon
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if currentPet == nil {
|
||||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,39 @@ import (
|
|||||||
"blazing/logic/service/fight"
|
"blazing/logic/service/fight"
|
||||||
"blazing/logic/service/pet"
|
"blazing/logic/service/pet"
|
||||||
"blazing/logic/service/player"
|
"blazing/logic/service/player"
|
||||||
|
playermodel "blazing/modules/player/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func petSetExpLimit(currentPet *playermodel.PetInfo) int64 {
|
||||||
|
if currentPet == nil || currentPet.Level >= 100 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
simulatedPet := *currentPet
|
||||||
|
allowedExp := simulatedPet.NextLvExp - simulatedPet.Exp
|
||||||
|
if allowedExp < 0 {
|
||||||
|
allowedExp = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for simulatedPet.Level < 100 && simulatedPet.NextLvExp > 0 {
|
||||||
|
simulatedPet.Level++
|
||||||
|
simulatedPet.Update(true)
|
||||||
|
if simulatedPet.Level >= 100 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
allowedExp += simulatedPet.NextLvExp
|
||||||
|
}
|
||||||
|
|
||||||
|
return allowedExp
|
||||||
|
}
|
||||||
|
|
||||||
|
func minInt64(a, b int64) int64 {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
// PetReleaseToWarehouse 将精灵从仓库包中放生
|
// PetReleaseToWarehouse 将精灵从仓库包中放生
|
||||||
func (h Controller) PetReleaseToWarehouse(
|
func (h Controller) PetReleaseToWarehouse(
|
||||||
data *PET_ROWEI, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
data *PET_ROWEI, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
@@ -17,9 +48,8 @@ func (h Controller) PetReleaseToWarehouse(
|
|||||||
if inBag || inBackup || freeForbidden == 1 {
|
if inBag || inBackup || freeForbidden == 1 {
|
||||||
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
||||||
}
|
}
|
||||||
|
if !player.Service.Pet.UpdateFree(data.CatchTime, 0, 1) {
|
||||||
if !player.Service.Pet.UpdateFree(data.CatchTime, 1) {
|
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, 0
|
return nil, 0
|
||||||
@@ -32,10 +62,12 @@ func (h Controller) PetOneCure(
|
|||||||
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
||||||
}
|
}
|
||||||
|
|
||||||
_, currentPet, ok := player.FindPet(data.CatchTime)
|
if slot, ok := player.FindPetBagSlot(data.CatchTime); ok {
|
||||||
if ok {
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if currentPet != nil {
|
||||||
defer currentPet.Cure()
|
defer currentPet.Cure()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &pet.PetOneCureOutboundInfo{
|
return &pet.PetOneCureOutboundInfo{
|
||||||
CatchTime: data.CatchTime,
|
CatchTime: data.CatchTime,
|
||||||
@@ -63,11 +95,17 @@ func (h Controller) PetFirst(
|
|||||||
func (h Controller) SetPetExp(
|
func (h Controller) SetPetExp(
|
||||||
data *PetSetExpInboundInfo,
|
data *PetSetExpInboundInfo,
|
||||||
player *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
player *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
||||||
_, currentPet, found := player.FindPet(data.CatchTime)
|
slot, found := player.FindPetBagSlot(data.CatchTime)
|
||||||
if !found || currentPet.Level >= 100 {
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if !found || currentPet == nil || currentPet.Level >= 100 {
|
||||||
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
||||||
}
|
}
|
||||||
|
|
||||||
player.AddPetExp(currentPet, data.Exp)
|
allowedExp := petSetExpLimit(currentPet)
|
||||||
|
if allowedExp <= 0 {
|
||||||
|
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, errorcode.ErrorCodes.ErrSystemError
|
||||||
|
}
|
||||||
|
|
||||||
|
player.AddPetExp(currentPet, minInt64(data.Exp, allowedExp))
|
||||||
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, 0
|
return &pet.PetSetExpOutboundInfo{Exp: player.Info.ExpPool}, 0
|
||||||
}
|
}
|
||||||
|
|||||||
75
logic/controller/pet_manage_test.go
Normal file
75
logic/controller/pet_manage_test.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/common/data/xmlres"
|
||||||
|
"blazing/common/socket/errorcode"
|
||||||
|
"blazing/logic/service/player"
|
||||||
|
playermodel "blazing/modules/player/model"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func firstPetIDForControllerTest(t *testing.T) int {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
for id := range xmlres.PetMAP {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Fatal("xmlres.PetMAP is empty")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetPetExpCapsLevelAt100(t *testing.T) {
|
||||||
|
petID := firstPetIDForControllerTest(t)
|
||||||
|
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 99, nil, 0)
|
||||||
|
if petInfo == nil {
|
||||||
|
t.Fatal("failed to generate test pet")
|
||||||
|
}
|
||||||
|
|
||||||
|
expPool := petInfo.NextLvExp + 10_000
|
||||||
|
testPlayer := player.NewPlayer(nil)
|
||||||
|
testPlayer.Info = &playermodel.PlayerInfo{
|
||||||
|
ExpPool: expPool,
|
||||||
|
PetList: []playermodel.PetInfo{*petInfo},
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPet := &testPlayer.Info.PetList[0]
|
||||||
|
result, err := (Controller{}).SetPetExp(&PetSetExpInboundInfo{
|
||||||
|
CatchTime: currentPet.CatchTime,
|
||||||
|
Exp: expPool,
|
||||||
|
}, testPlayer)
|
||||||
|
if err != 0 {
|
||||||
|
t.Fatalf("expected SetPetExp to succeed, got err=%d", err)
|
||||||
|
}
|
||||||
|
if currentPet.Level != 100 {
|
||||||
|
t.Fatalf("expected pet level to stop at 100, got %d", currentPet.Level)
|
||||||
|
}
|
||||||
|
if result.Exp != 10_000 {
|
||||||
|
t.Fatalf("expected overflow exp to remain in pool, got %d", result.Exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetPetExpRejectsPetAtLevel100(t *testing.T) {
|
||||||
|
petID := firstPetIDForControllerTest(t)
|
||||||
|
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||||
|
if petInfo == nil {
|
||||||
|
t.Fatal("failed to generate test pet")
|
||||||
|
}
|
||||||
|
|
||||||
|
testPlayer := player.NewPlayer(nil)
|
||||||
|
testPlayer.Info = &playermodel.PlayerInfo{
|
||||||
|
ExpPool: 50_000,
|
||||||
|
PetList: []playermodel.PetInfo{*petInfo},
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := (Controller{}).SetPetExp(&PetSetExpInboundInfo{
|
||||||
|
CatchTime: petInfo.CatchTime,
|
||||||
|
Exp: 12_345,
|
||||||
|
}, testPlayer)
|
||||||
|
if err != errorcode.ErrorCodes.ErrSystemError {
|
||||||
|
t.Fatalf("expected level-100 pet to be rejected, got err=%d", err)
|
||||||
|
}
|
||||||
|
if result.Exp != 50_000 {
|
||||||
|
t.Fatalf("expected exp pool to remain unchanged, got %d", result.Exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,18 @@ type GetPetLearnableSkillsOutboundInfo struct {
|
|||||||
SkillList []uint32 `json:"skillList"`
|
SkillList []uint32 `json:"skillList"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isSameUint32Slice(a []uint32, b []uint32) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for index := range a {
|
||||||
|
if a[index] != b[index] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func collectPetLearnableSkillList(currentPet *model.PetInfo) []uint32 {
|
func collectPetLearnableSkillList(currentPet *model.PetInfo) []uint32 {
|
||||||
skillSet := make(map[uint32]struct{})
|
skillSet := make(map[uint32]struct{})
|
||||||
skills := make([]uint32, 0)
|
skills := make([]uint32, 0)
|
||||||
@@ -55,8 +67,9 @@ func (h Controller) GetPetLearnableSkills(
|
|||||||
data *GetPetLearnableSkillsInboundInfo,
|
data *GetPetLearnableSkillsInboundInfo,
|
||||||
c *player.Player,
|
c *player.Player,
|
||||||
) (result *GetPetLearnableSkillsOutboundInfo, err errorcode.ErrorCode) {
|
) (result *GetPetLearnableSkillsOutboundInfo, err errorcode.ErrorCode) {
|
||||||
_, currentPet, ok := c.FindPet(data.CatchTime)
|
slot, ok := c.FindPetBagSlot(data.CatchTime)
|
||||||
if !ok {
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if !ok || currentPet == nil {
|
||||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,8 +82,9 @@ func (h Controller) GetPetLearnableSkills(
|
|||||||
func (h Controller) SetPetSkill(data *ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
|
func (h Controller) SetPetSkill(data *ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
|
||||||
const setSkillCost = 50
|
const setSkillCost = 50
|
||||||
|
|
||||||
_, currentPet, ok := c.FindPet(data.CatchTime)
|
slot, ok := c.FindPetBagSlot(data.CatchTime)
|
||||||
if !ok {
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if !ok || currentPet == nil {
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,8 +149,9 @@ func (h Controller) SetPetSkill(data *ChangeSkillInfo, c *player.Player) (result
|
|||||||
func (h Controller) SortPetSkills(data *C2S_Skill_Sort, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) SortPetSkills(data *C2S_Skill_Sort, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
const skillSortCost = 50
|
const skillSortCost = 50
|
||||||
|
|
||||||
_, currentPet, ok := c.FindPet(data.CapTm)
|
slot, ok := c.FindPetBagSlot(data.CapTm)
|
||||||
if !ok {
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if !ok || currentPet == nil {
|
||||||
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,3 +199,89 @@ func (h Controller) SortPetSkills(data *C2S_Skill_Sort, c *player.Player) (resul
|
|||||||
|
|
||||||
return nil, 0
|
return nil, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommitPetSkills 按最终技能列表一次性提交学习/替换/排序结果。
|
||||||
|
func (h Controller) CommitPetSkills(
|
||||||
|
data *CommitPetSkillsInboundInfo,
|
||||||
|
c *player.Player,
|
||||||
|
) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
const setSkillCost = 50
|
||||||
|
const skillSortCost = 50
|
||||||
|
|
||||||
|
slot, ok := c.FindPetBagSlot(data.CatchTime)
|
||||||
|
currentPet := slot.PetInfoPtr()
|
||||||
|
if !ok || currentPet == nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||||
|
}
|
||||||
|
|
||||||
|
currentSkillSet := make(map[uint32]model.SkillInfo, len(currentPet.SkillList))
|
||||||
|
currentSkillOrder := make([]uint32, 0, len(currentPet.SkillList))
|
||||||
|
for _, skill := range currentPet.SkillList {
|
||||||
|
if skill.ID == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
currentSkillSet[skill.ID] = skill
|
||||||
|
currentSkillOrder = append(currentSkillOrder, skill.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
finalSkillIDs := make([]uint32, 0, 4)
|
||||||
|
usedSkillSet := make(map[uint32]struct{}, 4)
|
||||||
|
for _, skillID := range data.Skill {
|
||||||
|
if skillID == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, exists := usedSkillSet[skillID]; exists {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
usedSkillSet[skillID] = struct{}{}
|
||||||
|
finalSkillIDs = append(finalSkillIDs, skillID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(finalSkillIDs) == 0 {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
||||||
|
}
|
||||||
|
if len(finalSkillIDs) > 4 {
|
||||||
|
finalSkillIDs = finalSkillIDs[:4]
|
||||||
|
}
|
||||||
|
if isSameUint32Slice(currentSkillOrder, finalSkillIDs) {
|
||||||
|
return nil, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
learnableSkillSet := make(map[uint32]struct{})
|
||||||
|
for _, skillID := range collectPetLearnableSkillList(currentPet) {
|
||||||
|
learnableSkillSet[skillID] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
newSkillCount := 0
|
||||||
|
finalSkillList := make([]model.SkillInfo, 0, len(finalSkillIDs))
|
||||||
|
for _, skillID := range finalSkillIDs {
|
||||||
|
if skill, exists := currentSkillSet[skillID]; exists {
|
||||||
|
finalSkillList = append(finalSkillList, skill)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, exists := learnableSkillSet[skillID]; !exists {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
||||||
|
}
|
||||||
|
skillInfo, exists := xmlres.SkillMap[int(skillID)]
|
||||||
|
if !exists {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrSystemBusy
|
||||||
|
}
|
||||||
|
newSkillCount++
|
||||||
|
finalSkillList = append(finalSkillList, model.SkillInfo{
|
||||||
|
ID: skillID,
|
||||||
|
PP: uint32(skillInfo.MaxPP),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
totalCost := int64(newSkillCount * setSkillCost)
|
||||||
|
if newSkillCount == 0 {
|
||||||
|
totalCost += int64(skillSortCost)
|
||||||
|
}
|
||||||
|
if totalCost > 0 && !c.GetCoins(totalCost) {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
||||||
|
}
|
||||||
|
c.Info.Coins -= totalCost
|
||||||
|
currentPet.SkillList = finalSkillList
|
||||||
|
|
||||||
|
return nil, 0
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/modules/player/model"
|
"blazing/modules/player/model"
|
||||||
|
"blazing/modules/player/service"
|
||||||
|
|
||||||
"blazing/logic/service/pet"
|
"blazing/logic/service/pet"
|
||||||
"blazing/logic/service/player"
|
"blazing/logic/service/player"
|
||||||
@@ -32,17 +33,45 @@ func (h Controller) GetFitmentUsing(data *FitmentUseringInboundInfo, c *player.P
|
|||||||
func (h Controller) GetRoomPetShowInfo(data *PetRoomListInboundInfo, c *player.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) GetRoomPetShowInfo(data *PetRoomListInboundInfo, c *player.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) {
|
||||||
result = &room.PetRoomListOutboundInfo{}
|
result = &room.PetRoomListOutboundInfo{}
|
||||||
result.Pets = make([]pet.PetShortInfo, 0)
|
result.Pets = make([]pet.PetShortInfo, 0)
|
||||||
roomInfo := c.Service.Room.Get(data.TargetUserID)
|
showPets := service.NewPetService(data.TargetUserID).GetShowPets()
|
||||||
for _, catchTime := range roomInfo.ShowPokemon {
|
for i := range showPets {
|
||||||
petInfo := c.Service.Pet.PetInfoOneOther(data.TargetUserID, catchTime)
|
|
||||||
if petInfo.Data.ID == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var petShortInfo pet.PetShortInfo
|
var petShortInfo pet.PetShortInfo
|
||||||
copier.Copy(&petShortInfo, &petInfo.Data)
|
copier.Copy(&petShortInfo, &showPets[i].Data)
|
||||||
if petInfo.ID != 0 {
|
|
||||||
result.Pets = append(result.Pets, petShortInfo)
|
result.Pets = append(result.Pets, petShortInfo)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRoomPetShowInfo 设置基地展示精灵并返回最新展示列表(cmd:2323)
|
||||||
|
func (h Controller) SetRoomPetShowInfo(data *C2S_PET_ROOM_SHOW, c *player.Player) (result *room.S2C_PET_ROOM_SHOW, err errorcode.ErrorCode) {
|
||||||
|
result = &room.S2C_PET_ROOM_SHOW{}
|
||||||
|
result.PetShowList = make([]pet.PetShortInfo, 0)
|
||||||
|
|
||||||
|
catchTimes := make([]uint32, 0, len(data.PetShowList))
|
||||||
|
seen := make(map[uint32]struct{}, len(data.PetShowList))
|
||||||
|
for _, item := range data.PetShowList {
|
||||||
|
ct := uint32(item.CatchTime)
|
||||||
|
if ct == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := seen[ct]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[ct] = struct{}{}
|
||||||
|
catchTimes = append(catchTimes, ct)
|
||||||
|
}
|
||||||
|
|
||||||
|
petSvc := service.NewPetService(c.Info.UserID)
|
||||||
|
if !petSvc.SetShowCatchTimes(catchTimes) {
|
||||||
|
err = errorcode.ErrorCodes.ErrSystemError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
showPets := petSvc.GetShowPets()
|
||||||
|
for i := range showPets {
|
||||||
|
var petShortInfo pet.PetShortInfo
|
||||||
|
copier.Copy(&petShortInfo, &showPets[i].Data)
|
||||||
|
result.PetShowList = append(result.PetShowList, petShortInfo)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -77,6 +106,9 @@ func (h Controller) GetAllFurniture(data *FitmentAllInboundEmpty, c *player.Play
|
|||||||
// 返回: 精灵详细信息和错误码
|
// 返回: 精灵详细信息和错误码
|
||||||
func (h Controller) GetRoomPetInfo(data *C2S_RoomPetInfo, c *player.Player) (result *pet.RoomPetInfo, err errorcode.ErrorCode) {
|
func (h Controller) GetRoomPetInfo(data *C2S_RoomPetInfo, c *player.Player) (result *pet.RoomPetInfo, err errorcode.ErrorCode) {
|
||||||
petInfo := c.Service.Pet.PetInfoOneOther(data.UserID, data.CatchTime)
|
petInfo := c.Service.Pet.PetInfoOneOther(data.UserID, data.CatchTime)
|
||||||
|
if petInfo == nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
||||||
|
}
|
||||||
result = &pet.RoomPetInfo{}
|
result = &pet.RoomPetInfo{}
|
||||||
copier.CopyWithOption(result, &petInfo.Data, copier.Option{DeepCopy: true})
|
copier.CopyWithOption(result, &petInfo.Data, copier.Option{DeepCopy: true})
|
||||||
result.OwnerId = data.UserID
|
result.OwnerId = data.UserID
|
||||||
|
|||||||
@@ -2,11 +2,8 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
"blazing/logic/service/pet"
|
|
||||||
"blazing/logic/service/player"
|
"blazing/logic/service/player"
|
||||||
"blazing/logic/service/room"
|
"blazing/logic/service/room"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetFitment 设置基地家具摆放
|
// SetFitment 设置基地家具摆放
|
||||||
@@ -18,29 +15,3 @@ func (h Controller) SetFitment(data *SET_FITMENT, c *player.Player) (result *roo
|
|||||||
c.Service.Room.Set(data.Fitments)
|
c.Service.Room.Set(data.Fitments)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPet 设置基地展示的精灵
|
|
||||||
// data: 包含精灵展示列表的输入信息
|
|
||||||
// c: 当前玩家对象
|
|
||||||
// 返回: 精灵展示列表和错误码
|
|
||||||
func (h Controller) SetPet(data *C2S_PET_ROOM_SHOW, c *player.Player) (result *room.S2C_PET_ROOM_SHOW, err errorcode.ErrorCode) {
|
|
||||||
var showPetCatchTimes []uint32
|
|
||||||
for _, petShowInfo := range data.PetShowList {
|
|
||||||
if petShowInfo.CatchTime != 0 {
|
|
||||||
showPetCatchTimes = append(showPetCatchTimes, petShowInfo.CatchTime)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.Service.Room.Show(showPetCatchTimes)
|
|
||||||
result = &room.S2C_PET_ROOM_SHOW{}
|
|
||||||
result.PetShowList = make([]pet.PetShortInfo, len(showPetCatchTimes))
|
|
||||||
for _, catchTime := range showPetCatchTimes {
|
|
||||||
petInfo := c.Service.Pet.PetInfoOneByCatchTime(catchTime)
|
|
||||||
if petInfo == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var petShortInfo pet.PetShortInfo
|
|
||||||
copier.Copy(&petShortInfo, &petInfo.Data)
|
|
||||||
result.PetShowList = append(result.PetShowList, petShortInfo)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"blazing/common/socket/errorcode"
|
"blazing/common/socket/errorcode"
|
||||||
logicplayer "blazing/logic/service/player"
|
logicplayer "blazing/logic/service/player"
|
||||||
"blazing/logic/service/user"
|
"blazing/logic/service/user"
|
||||||
|
baseservice "blazing/modules/base/service"
|
||||||
configservice "blazing/modules/config/service"
|
configservice "blazing/modules/config/service"
|
||||||
playerservice "blazing/modules/player/service"
|
playerservice "blazing/modules/player/service"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -14,6 +15,11 @@ import (
|
|||||||
func (h Controller) CDK(data *C2S_GET_GIFT_COMPLETE, player *logicplayer.Player) (result *user.S2C_GET_GIFT_COMPLETE, err errorcode.ErrorCode) {
|
func (h Controller) CDK(data *C2S_GET_GIFT_COMPLETE, player *logicplayer.Player) (result *user.S2C_GET_GIFT_COMPLETE, err errorcode.ErrorCode) {
|
||||||
result = &user.S2C_GET_GIFT_COMPLETE{}
|
result = &user.S2C_GET_GIFT_COMPLETE{}
|
||||||
|
|
||||||
|
userInfo := baseservice.NewBaseSysUserService().GetPerson(data.Head.UserID)
|
||||||
|
if userInfo == nil || userInfo.QQ == 0 {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
||||||
|
}
|
||||||
|
|
||||||
cdkCode := strings.Trim(data.PassText, "\x00")
|
cdkCode := strings.Trim(data.PassText, "\x00")
|
||||||
cdkService := configservice.NewCdkService()
|
cdkService := configservice.NewCdkService()
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@@ -22,6 +28,9 @@ func (h Controller) CDK(data *C2S_GET_GIFT_COMPLETE, player *logicplayer.Player)
|
|||||||
if r == nil {
|
if r == nil {
|
||||||
return nil, errorcode.ErrorCodes.ErrMolecularCodeNotExists
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeNotExists
|
||||||
}
|
}
|
||||||
|
if r.Type != configservice.CDKTypeReward {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeNotExists
|
||||||
|
}
|
||||||
if r.BindUserId != 0 && r.BindUserId != data.Head.UserID {
|
if r.BindUserId != 0 && r.BindUserId != data.Head.UserID {
|
||||||
return nil, errorcode.ErrorCodes.ErrMolecularCodeFrozen
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeFrozen
|
||||||
}
|
}
|
||||||
@@ -35,7 +44,12 @@ func (h Controller) CDK(data *C2S_GET_GIFT_COMPLETE, player *logicplayer.Player)
|
|||||||
return nil, errorcode.ErrorCodes.ErrMolecularCodeGiftsGone
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeGiftsGone
|
||||||
}
|
}
|
||||||
|
|
||||||
reward, grantErr := playerservice.NewCdkService(data.Head.UserID).GrantConfigReward(uint32(r.ID))
|
reward, grantErr := playerservice.NewCdkService(data.Head.UserID).GrantConfigReward(
|
||||||
|
uint32(r.ID),
|
||||||
|
func(itemID uint32, count int64) bool {
|
||||||
|
return player.ItemAdd(int64(itemID), count)
|
||||||
|
},
|
||||||
|
)
|
||||||
if grantErr != nil {
|
if grantErr != nil {
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ func (f *FightC) Over(c common.PlayerI, res model.EnumBattleOverReason) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
f.overl.Do(func() {
|
f.overl.Do(func() {
|
||||||
f.Reason = res
|
f.Reason = normalizeFightOverReason(res)
|
||||||
if f.GetInputByPlayer(c, true) != nil {
|
if f.GetInputByPlayer(c, true) != nil {
|
||||||
f.WinnerId = f.GetInputByPlayer(c, true).UserID
|
f.WinnerId = f.GetInputByPlayer(c, true).UserID
|
||||||
}
|
}
|
||||||
@@ -370,7 +370,7 @@ func (f *FightC) collectFightPetInfos(inputs []*input.Input) []info.FightPetInfo
|
|||||||
Hp: currentPet.Info.Hp,
|
Hp: currentPet.Info.Hp,
|
||||||
MaxHp: currentPet.Info.MaxHp,
|
MaxHp: currentPet.Info.MaxHp,
|
||||||
Level: currentPet.Info.Level,
|
Level: currentPet.Info.Level,
|
||||||
Catchable: uint32(fighter.CanCapture),
|
Catchable: fightPetCatchableFlag(fighter.CanCapture),
|
||||||
}
|
}
|
||||||
if fighter.AttackValue != nil {
|
if fighter.AttackValue != nil {
|
||||||
fightInfo.Prop = fighter.AttackValue.Prop
|
fightInfo.Prop = fighter.AttackValue.Prop
|
||||||
@@ -380,6 +380,13 @@ func (f *FightC) collectFightPetInfos(inputs []*input.Input) []info.FightPetInfo
|
|||||||
return infos
|
return infos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fightPetCatchableFlag(catchRate int) uint32 {
|
||||||
|
if catchRate > 0 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// checkBothPlayersReady 检查PVP战斗中双方是否都已准备完成
|
// checkBothPlayersReady 检查PVP战斗中双方是否都已准备完成
|
||||||
// 参数c为当前准备的玩家,返回true表示双方均准备完成
|
// 参数c为当前准备的玩家,返回true表示双方均准备完成
|
||||||
func (f *FightC) checkBothPlayersReady(currentPlayer common.PlayerI) bool {
|
func (f *FightC) checkBothPlayersReady(currentPlayer common.PlayerI) bool {
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ func (e *Effect1181) OnSkill() bool {
|
|||||||
type Effect1182 struct{ node.EffectNode }
|
type Effect1182 struct{ node.EffectNode }
|
||||||
|
|
||||||
func (e *Effect1182) Skill_Use() bool {
|
func (e *Effect1182) Skill_Use() bool {
|
||||||
if len(e.Args()) < 2 || e.Ctx().Our == nil || e.Ctx().Our.CurPet[0] == nil || e.Ctx().Opp == nil || e.Ctx().Opp.CurPet[0] == nil {
|
if len(e.Args()) < 2 || e.Ctx().Our == nil || e.Ctx().Our.CurPet[0] == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,9 +153,15 @@ func (e *Effect1182) Skill_Use() bool {
|
|||||||
if targetHP.Cmp(alpacadecimal.Zero) < 0 {
|
if targetHP.Cmp(alpacadecimal.Zero) < 0 {
|
||||||
targetHP = alpacadecimal.Zero
|
targetHP = alpacadecimal.Zero
|
||||||
}
|
}
|
||||||
if e.Ctx().Opp.CurPet[0].GetHP().Cmp(targetHP) > 0 {
|
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||||
e.Ctx().Opp.CurPet[0].Info.Hp = uint32(targetHP.IntPart())
|
if target == nil || target.CurrentPet() == nil {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
if target.CurrentPet().GetHP().Cmp(targetHP) > 0 {
|
||||||
|
target.CurrentPet().Info.Hp = uint32(targetHP.IntPart())
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
sub := e.Ctx().Our.InitEffect(input.EffectType.Sub, 1182, int(e.Args()[1].IntPart()))
|
sub := e.Ctx().Our.InitEffect(input.EffectType.Sub, 1182, int(e.Args()[1].IntPart()))
|
||||||
if sub != nil {
|
if sub != nil {
|
||||||
|
|||||||
@@ -10,20 +10,23 @@ type Effect169 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Effect169) OnSkill() bool {
|
func (e *Effect169) OnSkill() bool {
|
||||||
|
|
||||||
chance := e.Args()[1].IntPart()
|
chance := e.Args()[1].IntPart()
|
||||||
success, _, _ := e.Input.Player.Roll(int(chance), 100)
|
success, _, _ := e.Input.Player.Roll(int(chance), 100)
|
||||||
if success {
|
if success {
|
||||||
// 添加异常状态
|
e.ForEachOpponentSlot(func(target *input.Input) bool {
|
||||||
statusEffect := e.CarrierInput().InitEffect(input.EffectType.Status, int(e.Args()[2].IntPart())) // 以麻痹为例
|
if target == nil {
|
||||||
if statusEffect != nil {
|
return true
|
||||||
e.TargetInput().AddEffect(e.CarrierInput(), statusEffect)
|
|
||||||
}
|
}
|
||||||
|
statusEffect := e.CarrierInput().InitEffect(input.EffectType.Status, int(e.Args()[2].IntPart()))
|
||||||
|
if statusEffect != nil {
|
||||||
|
target.AddEffect(e.CarrierInput(), statusEffect)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
input.InitEffect(input.EffectType.Skill, 169, &Effect169{})
|
input.InitEffect(input.EffectType.Skill, 169, &Effect169{})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ func (e *Effect2194) OnSkill() bool {
|
|||||||
if e.Ctx().Opp.CurPet[0] == nil {
|
if e.Ctx().Opp.CurPet[0] == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
addStatusByID(e.Ctx().Our, e.Ctx().Opp, int(info.PetStatus.DrainedHP))
|
addTimedStatus(e.Ctx().Our, e.Ctx().Opp, int(info.PetStatus.DrainedHP), 4)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -444,7 +444,7 @@ func (e *Effect2278) Skill_Use() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
damage := marked.GetHP().Mul(alpacadecimal.NewFromInt(percent)).Div(hundred)
|
damage := marked.GetMaxHP().Mul(alpacadecimal.NewFromInt(percent)).Div(hundred)
|
||||||
if damage.Cmp(alpacadecimal.Zero) > 0 {
|
if damage.Cmp(alpacadecimal.Zero) > 0 {
|
||||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
||||||
Type: info.DamageType.Percent,
|
Type: info.DamageType.Percent,
|
||||||
|
|||||||
@@ -14,16 +14,23 @@ type Effect85 struct {
|
|||||||
// 执行时逻辑
|
// 执行时逻辑
|
||||||
// ----------------------
|
// ----------------------
|
||||||
func (e *Effect85) OnSkill() bool {
|
func (e *Effect85) OnSkill() bool {
|
||||||
|
carrier := e.CarrierInput()
|
||||||
for i, v := range e.Ctx().Opp.Prop[:] {
|
opp := e.OpponentInput()
|
||||||
if v > 0 {
|
if carrier == nil || opp == nil {
|
||||||
e.Ctx().Our.SetProp(e.Ctx().Our, int8(i), v)
|
|
||||||
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(i), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
|
e.transferPositiveProps(carrier, opp)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// transferPositiveProps 使用显式入参执行业务逻辑,避免嵌套结算时再从 Ctx 取到漂移后的对象。
|
||||||
|
func (e *Effect85) transferPositiveProps(carrier, opp *input.Input) {
|
||||||
|
for i, v := range opp.Prop[:] {
|
||||||
|
if v > 0 {
|
||||||
|
carrier.SetProp(carrier, int8(i), v)
|
||||||
|
opp.SetProp(carrier, int8(i), 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------
|
// ----------------------
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (e *Effect13) OnSkill() bool {
|
|||||||
if eff == nil {
|
if eff == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
eff.Duration(e.EffectNode.SideEffectArgs[0] - 1)
|
eff.Duration(e.EffectNode.SideEffectArgs[0])
|
||||||
|
|
||||||
e.Ctx().Opp.AddEffect(e.Ctx().Our, eff)
|
e.Ctx().Opp.AddEffect(e.Ctx().Our, eff)
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package effect
|
package effect
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"blazing/logic/service/fight/input"
|
||||||
"blazing/logic/service/fight/node"
|
"blazing/logic/service/fight/node"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,14 +42,16 @@ type Effect5 struct {
|
|||||||
// 技能触发时调用
|
// 技能触发时调用
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
func (e *Effect5) Skill_Use() bool {
|
func (e *Effect5) Skill_Use() bool {
|
||||||
|
|
||||||
// 概率判定
|
// 概率判定
|
||||||
ok, _, _ := e.Input.Player.Roll(e.SideEffectArgs[1], 100)
|
ok, _, _ := e.Input.Player.Roll(e.SideEffectArgs[1], 100)
|
||||||
if !ok {
|
if !ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[2]))
|
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||||
|
target.SetProp(e.Ctx().Our, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[2]))
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"blazing/logic/service/fight/info"
|
"blazing/logic/service/fight/info"
|
||||||
"blazing/logic/service/fight/input"
|
"blazing/logic/service/fight/input"
|
||||||
"blazing/logic/service/fight/node"
|
"blazing/logic/service/fight/node"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Effect 724: {0}回合内受到攻击{1}%恢复1/{2}体力
|
// Effect 724: {0}回合内受到攻击{1}%恢复1/{2}体力
|
||||||
@@ -85,6 +86,7 @@ func (e *Effect727) Action_end() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("[Effect727] Action_end RESET: Our.Prop %v -> LastTurnEndProp %v\n", e.Ctx().Our.Prop, e.Ctx().Our.LastTurnEndProp)
|
||||||
e.Ctx().Our.AttackValue.Prop = e.Ctx().Our.LastTurnEndProp
|
e.Ctx().Our.AttackValue.Prop = e.Ctx().Our.LastTurnEndProp
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,19 @@ type Effect76 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Effect76) OnSkill() bool {
|
func (e *Effect76) OnSkill() bool {
|
||||||
|
|
||||||
// 概率判定
|
// 概率判定
|
||||||
ok, _, _ := e.Input.Player.Roll(int(e.Args()[0].IntPart()), 100)
|
ok, _, _ := e.Input.Player.Roll(int(e.Args()[0].IntPart()), 100)
|
||||||
if !ok {
|
if !ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
|
||||||
|
damage := alpacadecimal.NewFromInt(int64(e.SideEffectArgs[2]))
|
||||||
|
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||||
|
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||||
Type: info.DamageType.Fixed,
|
Type: info.DamageType.Fixed,
|
||||||
Damage: alpacadecimal.NewFromInt(int64(e.SideEffectArgs[2])),
|
Damage: damage,
|
||||||
|
})
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ var effectInfoByID = map[int]string{
|
|||||||
29: "额外附加{0}点固定伤害",
|
29: "额外附加{0}点固定伤害",
|
||||||
31: "",
|
31: "",
|
||||||
32: "使用后{0}回合攻击击中对象要害概率增加1/16",
|
32: "使用后{0}回合攻击击中对象要害概率增加1/16",
|
||||||
33: "消除对手能力提升状态",
|
33: "消除敌方阵营所有强化",
|
||||||
34: "将所受的伤害{0}倍反馈给对手",
|
34: "将所受的伤害{0}倍反馈给对手",
|
||||||
35: "惩罚,对方能力等级越高,此技能威力越大",
|
35: "惩罚,对方能力等级越高,此技能威力越大",
|
||||||
36: "命中时{0}%的概率秒杀对方",
|
36: "命中时{0}%的概率秒杀对方",
|
||||||
@@ -120,7 +120,7 @@ var effectInfoByID = map[int]string{
|
|||||||
164: "{0}回合内若受到攻击则有{1}%概率令对手{2}",
|
164: "{0}回合内若受到攻击则有{1}%概率令对手{2}",
|
||||||
165: "{0}回合内每回合防御和特防等级+{1}",
|
165: "{0}回合内每回合防御和特防等级+{1}",
|
||||||
166: "{0}回合内若对手使用属性攻击则{2}%对手{1}等级{3}",
|
166: "{0}回合内若对手使用属性攻击则{2}%对手{1}等级{3}",
|
||||||
169: "{0}回合内每回合额外附加{1}%概率令对手{2}",
|
169: "{0}回合内每回合额外附加{1}%概率令对方阵营全体{2}",
|
||||||
170: "若先出手,则免疫当回合伤害并回复1/{0}的最大体力值",
|
170: "若先出手,则免疫当回合伤害并回复1/{0}的最大体力值",
|
||||||
171: "{0}回合内自身使用属性技能时能较快出手",
|
171: "{0}回合内自身使用属性技能时能较快出手",
|
||||||
172: "若后出手,则给予对方损伤的1/{0}会回复自己的体力",
|
172: "若后出手,则给予对方损伤的1/{0}会回复自己的体力",
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (e *Effect3) Skill_Use() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Effect 33: 消除对手能力提升状态
|
// Effect 33: 消除敌方阵营所有强化
|
||||||
type Effect33 struct {
|
type Effect33 struct {
|
||||||
node.EffectNode
|
node.EffectNode
|
||||||
Reverse bool
|
Reverse bool
|
||||||
@@ -38,13 +38,17 @@ type Effect33 struct {
|
|||||||
// 执行时逻辑
|
// 执行时逻辑
|
||||||
// ----------------------
|
// ----------------------
|
||||||
func (e *Effect33) Skill_Use() bool {
|
func (e *Effect33) Skill_Use() bool {
|
||||||
|
e.ForEachOpponentSlot(func(target *input.Input) bool {
|
||||||
for i, v := range e.Ctx().Opp.Prop[:] {
|
if target == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for i, v := range target.Prop[:] {
|
||||||
if v > 0 {
|
if v > 0 {
|
||||||
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(i), 0)
|
target.SetProp(e.Ctx().Our, int8(i), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -54,8 +58,8 @@ func (e *Effect33) Skill_Use() bool {
|
|||||||
// ----------------------
|
// ----------------------
|
||||||
func init() {
|
func init() {
|
||||||
// {3, false, 0}, // 解除自身能力下降状态
|
// {3, false, 0}, // 解除自身能力下降状态
|
||||||
// {33, true, 0}, // 消除对手能力提升状态{3, false, 0}, // 解除自身能力下降状态
|
// {33, true, 0}, // 消除敌方阵营所有强化{3, false, 0}, // 解除自身能力下降状态
|
||||||
// {33, true, 0}, // 消除对手能力提升状态
|
// {33, true, 0}, // 消除敌方阵营所有强化
|
||||||
input.InitEffect(input.EffectType.Skill, 3, &Effect3{})
|
input.InitEffect(input.EffectType.Skill, 3, &Effect3{})
|
||||||
input.InitEffect(input.EffectType.Skill, 33, &Effect33{})
|
input.InitEffect(input.EffectType.Skill, 33, &Effect33{})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,24 +39,17 @@ func (e *StatusCannotAct) ActionStart(attacker, defender *action.SelectSkillActi
|
|||||||
// 睡眠状态:受击后解除
|
// 睡眠状态:受击后解除
|
||||||
type StatusSleep struct {
|
type StatusSleep struct {
|
||||||
StatusCannotAct
|
StatusCannotAct
|
||||||
hasTriedAct bool // 标记是否尝试过行动
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试出手时标记状态
|
|
||||||
func (e *StatusSleep) ActionStart(attacker, defender *action.SelectSkillAction) bool {
|
|
||||||
e.hasTriedAct = true
|
|
||||||
return e.StatusCannotAct.ActionStart(attacker, defender)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 技能使用后处理:非状态类技能触发后解除睡眠
|
|
||||||
func (e *StatusSleep) Skill_Use_ex() bool {
|
func (e *StatusSleep) Skill_Use_ex() bool {
|
||||||
if !e.hasTriedAct {
|
|
||||||
return true
|
if e.Ctx().SkillEntity != nil {
|
||||||
}
|
if e.Ctx().SkillEntity.AttackTime != 0 && e.Ctx().Category() != info.Category.STATUS {
|
||||||
// 技能实体存在且非状态类型技能,解除睡眠
|
|
||||||
if e.Ctx().SkillEntity != nil && e.Ctx().Category() != info.Category.STATUS {
|
|
||||||
e.Alive(false)
|
e.Alive(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +59,7 @@ type ContinuousDamage struct {
|
|||||||
isheal bool //是否回血
|
isheal bool //是否回血
|
||||||
}
|
}
|
||||||
|
|
||||||
// 技能命中前触发伤害(1/8最大生命值真实伤害)
|
// 行动开始触发持续伤害:当中招方轮到自己行动时结算。
|
||||||
func (e *ContinuousDamage) ActionStart(attacker, defender *action.SelectSkillAction) bool {
|
func (e *ContinuousDamage) ActionStart(attacker, defender *action.SelectSkillAction) bool {
|
||||||
carrier := e.CarrierInput()
|
carrier := e.CarrierInput()
|
||||||
source := e.SourceInput()
|
source := e.SourceInput()
|
||||||
@@ -131,15 +124,13 @@ func (e *ParasiticSeed) SwitchOut(in *input.Input) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 技能命中前触发寄生效果
|
// 回合开始触发寄生效果。寄生属于完整回合流程的一部分,不依赖本回合是否成功出手。
|
||||||
func (e *ParasiticSeed) ActionStartEx(attacker, defender *action.SelectSkillAction) bool {
|
func (e *ParasiticSeed) TurnStart(attacker, defender *action.SelectSkillAction) {
|
||||||
carrier := e.CarrierInput()
|
carrier := e.CarrierInput()
|
||||||
source := e.SourceInput()
|
source := e.SourceInput()
|
||||||
opp := e.TargetInput()
|
|
||||||
if carrier == nil {
|
if carrier == nil {
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
// 过滤特定类型单位(假设1是植物类型,使用枚举替代魔法数字)
|
|
||||||
|
|
||||||
damage := alpacadecimal.NewFromInt(int64(carrier.CurPet[0].Info.MaxHp)).
|
damage := alpacadecimal.NewFromInt(int64(carrier.CurPet[0].Info.MaxHp)).
|
||||||
Div(alpacadecimal.NewFromInt(8))
|
Div(alpacadecimal.NewFromInt(8))
|
||||||
@@ -149,13 +140,12 @@ func (e *ParasiticSeed) ActionStartEx(attacker, defender *action.SelectSkillActi
|
|||||||
Type: info.DamageType.True,
|
Type: info.DamageType.True,
|
||||||
Damage: damage,
|
Damage: damage,
|
||||||
})
|
})
|
||||||
if opp == nil || opp.CurPet[0].GetHP().IntPart() == 0 {
|
if source == nil || source.CurPet[0] == nil || source.CurPet[0].GetHP().IntPart() == 0 {
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 给对方回血(不受回血限制影响)
|
// 给寄生种子的施放者回血(不受回血限制影响)
|
||||||
opp.Heal(carrier, nil, damage)
|
source.Heal(carrier, nil, damage)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Flammable struct {
|
type Flammable struct {
|
||||||
@@ -271,9 +261,9 @@ func init() {
|
|||||||
// 批量注册不能行动的状态
|
// 批量注册不能行动的状态
|
||||||
nonActingStatuses := []info.EnumPetStatus{
|
nonActingStatuses := []info.EnumPetStatus{
|
||||||
info.PetStatus.Paralysis, // 麻痹
|
info.PetStatus.Paralysis, // 麻痹
|
||||||
info.PetStatus.Tired, // 疲惫
|
|
||||||
info.PetStatus.Fear, // 害怕
|
info.PetStatus.Fear, // 害怕
|
||||||
info.PetStatus.Petrified, // 石化
|
info.PetStatus.Petrified, // 石化
|
||||||
|
info.PetStatus.Tired, // 疲惫
|
||||||
}
|
}
|
||||||
for _, status := range nonActingStatuses {
|
for _, status := range nonActingStatuses {
|
||||||
effect := &StatusCannotAct{}
|
effect := &StatusCannotAct{}
|
||||||
|
|||||||
@@ -83,6 +83,10 @@ func (e *Effect201) OnSkill() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !carrier.IsMultiInputBattle() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
divisorIndex := len(args) - 1
|
divisorIndex := len(args) - 1
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
divisorIndex = 1
|
divisorIndex = 1
|
||||||
@@ -110,10 +114,6 @@ func (e *Effect201) OnSkill() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !carrier.IsMultiInputBattle() {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
team := carrier.Team
|
team := carrier.Team
|
||||||
if len(team) == 0 {
|
if len(team) == 0 {
|
||||||
team = []*input.Input{carrier}
|
team = []*input.Input{carrier}
|
||||||
|
|||||||
@@ -42,6 +42,27 @@ func TestEffect201HealAllIgnoredInSingleInputBattle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEffect201SingleTargetIgnoredInSingleInputBattle(t *testing.T) {
|
||||||
|
carrier := newEffect201TestInput(40, 100)
|
||||||
|
opponent := newEffect201TestInput(60, 100)
|
||||||
|
carrier.Team = []*input.Input{carrier}
|
||||||
|
carrier.OppTeam = []*input.Input{opponent}
|
||||||
|
|
||||||
|
eff := &Effect201{}
|
||||||
|
eff.SetArgs(carrier, 2)
|
||||||
|
eff.EffectNode.EffectContextHolder.Ctx = input.Ctx{
|
||||||
|
LegacySides: input.LegacySides{Our: carrier, Opp: opponent},
|
||||||
|
EffectBinding: input.EffectBinding{Carrier: carrier, Source: carrier},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !eff.OnSkill() {
|
||||||
|
t.Fatalf("expected effect to finish successfully")
|
||||||
|
}
|
||||||
|
if got := carrier.CurrentPet().Info.Hp; got != 40 {
|
||||||
|
t.Fatalf("expected single-input single-target heal to be ignored, got hp %d", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEffect201HealAllWorksInMultiInputBattle(t *testing.T) {
|
func TestEffect201HealAllWorksInMultiInputBattle(t *testing.T) {
|
||||||
carrier := newEffect201TestInput(40, 100)
|
carrier := newEffect201TestInput(40, 100)
|
||||||
ally := newEffect201TestInput(10, 80)
|
ally := newEffect201TestInput(10, 80)
|
||||||
|
|||||||
@@ -5,3 +5,7 @@ import "blazing/logic/service/fight/input"
|
|||||||
func initskill(id int, e input.Effect) {
|
func initskill(id int, e input.Effect) {
|
||||||
input.InitEffect(input.EffectType.Skill, id, e)
|
input.InitEffect(input.EffectType.Skill, id, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initskillFactory(id int, factory func() input.Effect) {
|
||||||
|
input.InitEffectFactory(input.EffectType.Skill, id, factory)
|
||||||
|
}
|
||||||
|
|||||||
@@ -158,7 +158,10 @@ func registerSelfDamageSkillHitEffects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for effectID, handler := range handlers {
|
for effectID, handler := range handlers {
|
||||||
initskill(effectID, newSkillHitRegistrarEffect(handler))
|
currentHandler := handler
|
||||||
|
initskillFactory(effectID, func() input.Effect {
|
||||||
|
return newSkillHitRegistrarEffect(currentHandler)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,11 +207,17 @@ func registerSelfDamageOnSkillEffects() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||||
|
if target == nil || target.CurrentPet() == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||||
Type: info.DamageType.Fixed,
|
Type: info.DamageType.Fixed,
|
||||||
Damage: opponentDamage,
|
Damage: opponentDamage,
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
|
})
|
||||||
|
return true
|
||||||
},
|
},
|
||||||
556: func(e *onSkillRegistrarEffect) bool {
|
556: func(e *onSkillRegistrarEffect) bool {
|
||||||
currentHP := e.Ctx().Our.CurPet[0].Info.Hp
|
currentHP := e.Ctx().Our.CurPet[0].Info.Hp
|
||||||
@@ -223,7 +232,10 @@ func registerSelfDamageOnSkillEffects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for effectID, handler := range handlers {
|
for effectID, handler := range handlers {
|
||||||
initskill(effectID, newOnSkillRegistrarEffect(handler))
|
currentHandler := handler
|
||||||
|
initskillFactory(effectID, func() input.Effect {
|
||||||
|
return newOnSkillRegistrarEffect(currentHandler)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,11 +247,17 @@ func registerSelfDamageSkillUseEffects() {
|
|||||||
Type: info.DamageType.Fixed,
|
Type: info.DamageType.Fixed,
|
||||||
Damage: damage,
|
Damage: damage,
|
||||||
})
|
})
|
||||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||||
|
if target == nil || target.CurrentPet() == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||||
Type: info.DamageType.Fixed,
|
Type: info.DamageType.Fixed,
|
||||||
Damage: damage,
|
Damage: damage,
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
|
})
|
||||||
|
return true
|
||||||
},
|
},
|
||||||
112: func(e *skillUseRegistrarEffect) bool {
|
112: func(e *skillUseRegistrarEffect) bool {
|
||||||
e.Ctx().Our.Damage(e.Ctx().Our, &info.DamageZone{
|
e.Ctx().Our.Damage(e.Ctx().Our, &info.DamageZone{
|
||||||
@@ -247,9 +265,23 @@ func registerSelfDamageSkillUseEffects() {
|
|||||||
Damage: alpacadecimal.NewFromInt(int64(e.Ctx().Our.CurPet[0].Info.MaxHp)),
|
Damage: alpacadecimal.NewFromInt(int64(e.Ctx().Our.CurPet[0].Info.MaxHp)),
|
||||||
})
|
})
|
||||||
damage := int64(grand.N(250, 300))
|
damage := int64(grand.N(250, 300))
|
||||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||||
|
if target == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
targetPet := target.CurrentPet()
|
||||||
|
if targetPet == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
remainHP := targetPet.GetHP().Sub(alpacadecimal.NewFromInt(1))
|
||||||
|
if remainHP.Cmp(alpacadecimal.Zero) <= 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||||
Type: info.DamageType.Fixed,
|
Type: info.DamageType.Fixed,
|
||||||
Damage: alpacadecimal.Min(alpacadecimal.NewFromInt(damage), e.Ctx().Opp.CurPet[0].GetHP().Sub(alpacadecimal.NewFromInt(1))),
|
Damage: alpacadecimal.Min(alpacadecimal.NewFromInt(damage), remainHP),
|
||||||
|
})
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
@@ -274,28 +306,44 @@ func registerSelfDamageSkillUseEffects() {
|
|||||||
randomDamage = grand.N(minDamage, maxDamage)
|
randomDamage = grand.N(minDamage, maxDamage)
|
||||||
}
|
}
|
||||||
|
|
||||||
remainHP := e.Ctx().Opp.CurPet[0].GetHP().Sub(alpacadecimal.NewFromInt(1))
|
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||||
|
if target == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
targetPet := target.CurrentPet()
|
||||||
|
if targetPet == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
remainHP := targetPet.GetHP().Sub(alpacadecimal.NewFromInt(1))
|
||||||
if remainHP.Cmp(alpacadecimal.Zero) <= 0 {
|
if remainHP.Cmp(alpacadecimal.Zero) <= 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
damage := alpacadecimal.Min(alpacadecimal.NewFromInt(int64(randomDamage)), remainHP)
|
damage := alpacadecimal.Min(alpacadecimal.NewFromInt(int64(randomDamage)), remainHP)
|
||||||
e.Ctx().Opp.Damage(e.Ctx().Our, &info.DamageZone{
|
target.Damage(e.Ctx().Our, &info.DamageZone{
|
||||||
Type: info.DamageType.Fixed,
|
Type: info.DamageType.Fixed,
|
||||||
Damage: damage,
|
Damage: damage,
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
|
})
|
||||||
|
return true
|
||||||
},
|
},
|
||||||
1380: func(e *skillUseRegistrarEffect) bool {
|
1380: func(e *skillUseRegistrarEffect) bool {
|
||||||
if len(e.Args()) < 3 {
|
if len(e.Args()) < 3 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
applyAllPropDown(e.Ctx().Our, e.Ctx().Opp, int8(e.Args()[0].IntPart()))
|
forEachEnemyTargetBySkill(e.Ctx().Our, e.Ctx().Opp, e.Ctx().SkillEntity, func(target *input.Input) bool {
|
||||||
|
if target == nil || target.CurrentPet() == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
applyAllPropDown(e.Ctx().Our, target, int8(e.Args()[0].IntPart()))
|
||||||
sub := e.Ctx().Our.InitEffect(input.EffectType.Sub, 1380, int(e.Args()[1].IntPart()), int(e.Args()[2].IntPart()))
|
sub := e.Ctx().Our.InitEffect(input.EffectType.Sub, 1380, int(e.Args()[1].IntPart()), int(e.Args()[2].IntPart()))
|
||||||
if sub != nil {
|
if sub != nil {
|
||||||
e.Ctx().Opp.AddEffect(e.Ctx().Our, sub)
|
target.AddEffect(e.Ctx().Our, sub)
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
e.Ctx().Our.Damage(e.Ctx().Our, &info.DamageZone{
|
e.Ctx().Our.Damage(e.Ctx().Our, &info.DamageZone{
|
||||||
Type: info.DamageType.Fixed,
|
Type: info.DamageType.Fixed,
|
||||||
Damage: e.Ctx().Our.CurPet[0].GetHP(),
|
Damage: e.Ctx().Our.CurPet[0].GetHP(),
|
||||||
@@ -305,7 +353,10 @@ func registerSelfDamageSkillUseEffects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for effectID, handler := range handlers {
|
for effectID, handler := range handlers {
|
||||||
initskill(effectID, newSkillUseRegistrarEffect(handler))
|
currentHandler := handler
|
||||||
|
initskillFactory(effectID, func() input.Effect {
|
||||||
|
return newSkillUseRegistrarEffect(currentHandler)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,7 +390,10 @@ func registerSelfDamageComparePreOnSkillEffects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for effectID, effect := range effects {
|
for effectID, effect := range effects {
|
||||||
initskill(effectID, effect)
|
currentEffect := effect
|
||||||
|
initskillFactory(effectID, func() input.Effect {
|
||||||
|
return newComparePreOnSkillRegistrarEffect(currentEffect.comparePreHandler, currentEffect.onSkillHandler)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
34
logic/service/fight/effect/skill_target_helper.go
Normal file
34
logic/service/fight/effect/skill_target_helper.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package effect
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/logic/service/fight/info"
|
||||||
|
"blazing/logic/service/fight/input"
|
||||||
|
)
|
||||||
|
|
||||||
|
// forEachEnemyTargetBySkill 在普通情况下对单个目标生效;
|
||||||
|
// 当技能为 AtkType=3(仅自己)且当前目标仍在己方时,改为遍历敌方全部站位。
|
||||||
|
func forEachEnemyTargetBySkill(carrier, target *input.Input, skill *info.SkillEntity, fn func(*input.Input) bool) {
|
||||||
|
if fn == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if carrier == nil {
|
||||||
|
if target != nil {
|
||||||
|
fn(target)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if skill == nil || skill.XML.AtkType != 3 || !isSameSideTarget(carrier, target) {
|
||||||
|
if target != nil {
|
||||||
|
fn(target)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, opponent := range carrier.OpponentSlots() {
|
||||||
|
if opponent == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !fn(opponent) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,12 +7,21 @@ import "blazing/modules/player/model"
|
|||||||
// 0=normal end 1=player lost/offline 2=overtime 3=draw 4=system error 5=npc escape.
|
// 0=normal end 1=player lost/offline 2=overtime 3=draw 4=system error 5=npc escape.
|
||||||
func buildFightOverPayload(over model.FightOverInfo) *model.FightOverInfo {
|
func buildFightOverPayload(over model.FightOverInfo) *model.FightOverInfo {
|
||||||
payload := over
|
payload := over
|
||||||
payload.Reason = mapFightOverReasonFor2506(over.Reason)
|
payload.Reason = model.EnumBattleOverReason(mapUnifiedFightOverReason(over.Reason))
|
||||||
return &payload
|
return &payload
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapFightOverReasonFor2506(reason model.EnumBattleOverReason) model.EnumBattleOverReason {
|
func normalizeFightOverReason(reason model.EnumBattleOverReason) model.EnumBattleOverReason {
|
||||||
switch reason {
|
if reason == model.BattleOverReason.DefaultEnd {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return reason
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapUnifiedFightOverReason(reason model.EnumBattleOverReason) uint32 {
|
||||||
|
switch normalizeFightOverReason(reason) {
|
||||||
|
case 0, model.BattleOverReason.Cacthok:
|
||||||
|
return 0
|
||||||
case model.BattleOverReason.PlayerOffline:
|
case model.BattleOverReason.PlayerOffline:
|
||||||
return 1
|
return 1
|
||||||
case model.BattleOverReason.PlayerOVerTime:
|
case model.BattleOverReason.PlayerOVerTime:
|
||||||
@@ -20,12 +29,12 @@ func mapFightOverReasonFor2506(reason model.EnumBattleOverReason) model.EnumBatt
|
|||||||
case model.BattleOverReason.NOTwind:
|
case model.BattleOverReason.NOTwind:
|
||||||
return 3
|
return 3
|
||||||
case model.BattleOverReason.PlayerEscape:
|
case model.BattleOverReason.PlayerEscape:
|
||||||
// Player-initiated escape is handled by 2410 on the flash side; 2506 should
|
return 5
|
||||||
// still land in a non-error bucket instead of "system error".
|
|
||||||
return 1
|
|
||||||
case model.BattleOverReason.Cacthok, model.BattleOverReason.DefaultEnd:
|
|
||||||
return 0
|
|
||||||
default:
|
default:
|
||||||
return 4
|
return 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mapFightOverReasonFor2506(reason model.EnumBattleOverReason) model.EnumBattleOverReason {
|
||||||
|
return model.EnumBattleOverReason(mapUnifiedFightOverReason(reason))
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"blazing/logic/service/fight/action"
|
"blazing/logic/service/fight/action"
|
||||||
"blazing/logic/service/fight/info"
|
"blazing/logic/service/fight/info"
|
||||||
"blazing/logic/service/fight/input"
|
"blazing/logic/service/fight/input"
|
||||||
|
_ "blazing/logic/service/fight/itemover"
|
||||||
|
_ "blazing/logic/service/fight/rule"
|
||||||
"blazing/modules/player/model"
|
"blazing/modules/player/model"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
@@ -133,7 +135,20 @@ func (f *FightC) getSkillParticipants(skillAction *action.SelectSkillAction) (*i
|
|||||||
if skillAction == nil {
|
if skillAction == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return f.GetInputByAction(skillAction, false), f.GetInputByAction(skillAction, true)
|
attacker := f.GetInputByAction(skillAction, false)
|
||||||
|
defender := f.GetInputByAction(skillAction, true)
|
||||||
|
if attacker != nil && defender == attacker && shouldResolveOpponentAsTarget(skillAction.SkillEntity) {
|
||||||
|
if opponent, _ := attacker.OpponentSlotAtOrNextLiving(0); opponent != nil {
|
||||||
|
defender = opponent
|
||||||
|
} else if opponent := f.roundOpponentInput(attacker); opponent != nil {
|
||||||
|
defender = opponent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attacker, defender
|
||||||
|
}
|
||||||
|
|
||||||
|
func shouldResolveOpponentAsTarget(skill *info.SkillEntity) bool {
|
||||||
|
return skill != nil && skill.XML.AtkType == 3
|
||||||
}
|
}
|
||||||
|
|
||||||
// setEffectSkillContext 统一设置技能阶段 effect 上下文。
|
// setEffectSkillContext 统一设置技能阶段 effect 上下文。
|
||||||
@@ -184,20 +199,63 @@ func (f *FightC) collectAttackValues(inputs []*input.Input) []model.AttackValue
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
attackValue := *fighter.AttackValue
|
attackValue := *fighter.AttackValue
|
||||||
|
if attackValue.SkillID == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
attackValue.ActorIndex = uint32(actorIndex)
|
attackValue.ActorIndex = uint32(actorIndex)
|
||||||
values = append(values, attackValue)
|
values = append(values, attackValue)
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FightC) buildAttackValueForBroadcast(fighter *input.Input, fallbackActorIndex int) model.AttackValue {
|
||||||
|
if fighter == nil {
|
||||||
|
return model.AttackValue{}
|
||||||
|
}
|
||||||
|
if fighter.AttackValue == nil {
|
||||||
|
empty := info.NewAttackValue(fighter.UserID)
|
||||||
|
fighter.AttackValue = empty
|
||||||
|
}
|
||||||
|
attackValue := *fighter.AttackValue
|
||||||
|
attackValue.ActorIndex = uint32(fallbackActorIndex)
|
||||||
|
if attackValue.UserID == 0 && fighter.Player != nil && fighter.Player.GetInfo() != nil {
|
||||||
|
attackValue.UserID = fighter.Player.GetInfo().UserID
|
||||||
|
}
|
||||||
|
return attackValue
|
||||||
|
}
|
||||||
|
|
||||||
func (f *FightC) buildNoteUseSkillOutboundInfo() info.NoteUseSkillOutboundInfo {
|
func (f *FightC) buildNoteUseSkillOutboundInfo() info.NoteUseSkillOutboundInfo {
|
||||||
result := info.NoteUseSkillOutboundInfo{}
|
result := info.NoteUseSkillOutboundInfo{}
|
||||||
result.FirstAttackInfo = append(result.FirstAttackInfo, f.collectAttackValues(f.Our)...)
|
if f.First != nil {
|
||||||
result.SecondAttackInfo = append(result.SecondAttackInfo, f.collectAttackValues(f.Opp)...)
|
result.FirstAttackInfo = f.buildAttackValueForBroadcast(f.First, f.First.TeamSlotIndex())
|
||||||
|
}
|
||||||
|
if f.Second != nil {
|
||||||
|
result.SecondAttackInfo = f.buildAttackValueForBroadcast(f.Second, f.Second.TeamSlotIndex())
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FightC) roundOpponentInput(attacker *input.Input) *input.Input {
|
||||||
|
if attacker == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, opponent := range attacker.OpponentSlots() {
|
||||||
|
if opponent != nil {
|
||||||
|
return opponent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func shouldSkipSecondAction(first, second *input.Input) bool {
|
||||||
|
if first == nil || second == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
firstPet := first.CurrentPet()
|
||||||
|
secondPet := second.CurrentPet()
|
||||||
|
return firstPet == nil || firstPet.Info.Hp <= 0 || secondPet == nil || secondPet.Info.Hp <= 0
|
||||||
|
}
|
||||||
|
|
||||||
// enterturn 处理战斗回合逻辑
|
// enterturn 处理战斗回合逻辑
|
||||||
// 回合有先手方和后手方,同时有攻击方和被攻击方
|
// 回合有先手方和后手方,同时有攻击方和被攻击方
|
||||||
func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) {
|
func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) {
|
||||||
@@ -245,9 +303,11 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
|
|||||||
f.First, _ = f.getSkillParticipants(firstAttack)
|
f.First, _ = f.getSkillParticipants(firstAttack)
|
||||||
f.Second, _ = f.getSkillParticipants(secondAttack)
|
f.Second, _ = f.getSkillParticipants(secondAttack)
|
||||||
case firstAttack != nil:
|
case firstAttack != nil:
|
||||||
f.First, f.Second = f.getSkillParticipants(firstAttack)
|
f.First, _ = f.getSkillParticipants(firstAttack)
|
||||||
|
f.Second = f.roundOpponentInput(f.First)
|
||||||
case secondAttack != nil:
|
case secondAttack != nil:
|
||||||
f.First, f.Second = f.getSkillParticipants(secondAttack)
|
f.First, _ = f.getSkillParticipants(secondAttack)
|
||||||
|
f.Second = f.roundOpponentInput(f.First)
|
||||||
}
|
}
|
||||||
if f.First == nil {
|
if f.First == nil {
|
||||||
f.First = f.primaryOur()
|
f.First = f.primaryOur()
|
||||||
@@ -275,25 +335,32 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if firstAttack == nil && secondAttack == nil {
|
skipActionStage := firstAttack == nil && secondAttack == nil
|
||||||
firstAttack, secondAttack = secondAttack, firstAttack //互换先手权
|
|
||||||
f.First, f.Second = f.Second, f.First
|
|
||||||
}
|
|
||||||
var attacker, defender *input.Input
|
var attacker, defender *input.Input
|
||||||
f.TrueFirst = f.First
|
f.TrueFirst = f.First
|
||||||
//开始回合操作
|
//开始回合操作。若双方本回合都未出手,则只走完整回合流程,不进入动作阶段。
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; !skipActionStage && i < 2; i++ {
|
||||||
var originalSkill *info.SkillEntity //原始技能
|
var originalSkill *info.SkillEntity //原始技能
|
||||||
var currentSkill *info.SkillEntity //当前技能
|
var currentSkill *info.SkillEntity //当前技能
|
||||||
var currentAction *action.SelectSkillAction
|
var currentAction *action.SelectSkillAction
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
currentAction = firstAttack
|
currentAction = firstAttack
|
||||||
|
if currentAction == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
attacker, defender = f.getSkillParticipants(firstAttack)
|
attacker, defender = f.getSkillParticipants(firstAttack)
|
||||||
originalSkill = f.copySkill(firstAttack)
|
originalSkill = f.copySkill(firstAttack)
|
||||||
//先手阶段,先修复后手效果
|
//先手阶段,先修复后手效果
|
||||||
f.Second.RecoverEffect()
|
f.Second.RecoverEffect()
|
||||||
} else {
|
} else {
|
||||||
currentAction = secondAttack
|
currentAction = secondAttack
|
||||||
|
if currentAction == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if shouldSkipSecondAction(f.First, f.Second) {
|
||||||
|
secondAttack = nil
|
||||||
|
continue
|
||||||
|
}
|
||||||
attacker, defender = f.getSkillParticipants(secondAttack)
|
attacker, defender = f.getSkillParticipants(secondAttack)
|
||||||
originalSkill = f.copySkill(secondAttack)
|
originalSkill = f.copySkill(secondAttack)
|
||||||
//取消后手历史效果
|
//取消后手历史效果
|
||||||
@@ -332,7 +399,6 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
|
|||||||
|
|
||||||
}
|
}
|
||||||
//先手权不一定出手
|
//先手权不一定出手
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
f.setActionAttackValue(currentAction)
|
f.setActionAttackValue(currentAction)
|
||||||
|
|
||||||
@@ -449,11 +515,13 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
|
|||||||
// })
|
// })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if attackValueResult.FirstAttackInfo.UserID != 0 || attackValueResult.SecondAttackInfo.UserID != 0 {
|
||||||
f.BroadcastPlayers(func(p common.PlayerI) {
|
f.BroadcastPlayers(func(p common.PlayerI) {
|
||||||
if !f.LegacyGroupProtocol {
|
if !f.LegacyGroupProtocol {
|
||||||
f.sendFightPacket(p, fightPacketSkillResult, &attackValueResult)
|
f.sendFightPacket(p, fightPacketSkillResult, &attackValueResult)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
f.Broadcast(func(fighter *input.Input) {
|
f.Broadcast(func(fighter *input.Input) {
|
||||||
fighter.CanChange = 0
|
fighter.CanChange = 0
|
||||||
})
|
})
|
||||||
@@ -482,11 +550,12 @@ func (f *FightC) TURNOVER(cur *input.Input) {
|
|||||||
if f.IsWin(f.GetInputByPlayer(cur.Player, true)) { //然后检查是否战斗结束
|
if f.IsWin(f.GetInputByPlayer(cur.Player, true)) { //然后检查是否战斗结束
|
||||||
|
|
||||||
f.FightOverInfo.WinnerId = f.GetInputByPlayer(cur.Player, true).UserID
|
f.FightOverInfo.WinnerId = f.GetInputByPlayer(cur.Player, true).UserID
|
||||||
f.FightOverInfo.Reason = model.BattleOverReason.DefaultEnd
|
f.FightOverInfo.Reason = normalizeFightOverReason(model.BattleOverReason.DefaultEnd)
|
||||||
f.WinnerId = f.FightOverInfo.WinnerId
|
f.WinnerId = f.FightOverInfo.WinnerId
|
||||||
f.Reason = model.BattleOverReason.DefaultEnd
|
f.Reason = f.FightOverInfo.Reason
|
||||||
|
|
||||||
f.closefight = true
|
f.closefight = true
|
||||||
// break
|
// break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ import (
|
|||||||
"blazing/modules/player/model"
|
"blazing/modules/player/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// <!--
|
||||||
|
// GBTL:
|
||||||
|
// 1. AtkNum:本技能同时攻击数量, 默认:1(不能为0)
|
||||||
|
// 2. AtkType:攻击类型: 0:所有人, 1:仅己方, 2:仅对方, 3:仅自己, 默认:2
|
||||||
|
// -->
|
||||||
const (
|
const (
|
||||||
groupCmdReadyToFight uint32 = 7555
|
groupCmdReadyToFight uint32 = 7555
|
||||||
groupCmdReadyFightFinish uint32 = 7556
|
groupCmdReadyFightFinish uint32 = 7556
|
||||||
@@ -426,38 +431,15 @@ func (f *FightC) buildLegacyGroupOverInfo(over *model.FightOverInfo) *legacyGrou
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mapLegacyGroupFightOverReason(reason model.EnumBattleOverReason) uint32 {
|
func mapLegacyGroupFightOverReason(reason model.EnumBattleOverReason) uint32 {
|
||||||
switch reason {
|
return mapUnifiedFightOverReason(reason)
|
||||||
case model.BattleOverReason.PlayerOffline:
|
|
||||||
return 2
|
|
||||||
case model.BattleOverReason.PlayerOVerTime:
|
|
||||||
return 3
|
|
||||||
case model.BattleOverReason.NOTwind:
|
|
||||||
return 4
|
|
||||||
case model.BattleOverReason.DefaultEnd:
|
|
||||||
return 1
|
|
||||||
case model.BattleOverReason.PlayerEscape:
|
|
||||||
return 6
|
|
||||||
default:
|
|
||||||
return 5
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveLegacyGroupFightOverReason(over *model.FightOverInfo) uint32 {
|
func resolveLegacyGroupFightOverReason(over *model.FightOverInfo) uint32 {
|
||||||
if over == nil {
|
if over == nil {
|
||||||
return 5
|
return mapUnifiedFightOverReason(0)
|
||||||
}
|
|
||||||
switch over.Reason {
|
|
||||||
case model.BattleOverReason.PlayerOffline:
|
|
||||||
return 2
|
|
||||||
case model.BattleOverReason.PlayerOVerTime:
|
|
||||||
return 3
|
|
||||||
case model.BattleOverReason.PlayerEscape:
|
|
||||||
return 6
|
|
||||||
case model.BattleOverReason.NOTwind:
|
|
||||||
return 4
|
|
||||||
}
|
}
|
||||||
if over.WinnerId != 0 {
|
if over.WinnerId != 0 {
|
||||||
return 1
|
return mapUnifiedFightOverReason(0)
|
||||||
}
|
}
|
||||||
return mapLegacyGroupFightOverReason(over.Reason)
|
return mapLegacyGroupFightOverReason(over.Reason)
|
||||||
}
|
}
|
||||||
@@ -515,15 +497,23 @@ func (f *FightC) sendLegacyRoundBroadcast(firstAttack, secondAttack *action.Sele
|
|||||||
if f == nil || !f.LegacyGroupProtocol {
|
if f == nil || !f.LegacyGroupProtocol {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if firstAttack != nil {
|
if f.legacySkillExecuted(firstAttack) {
|
||||||
f.sendLegacyGroupSkillHurt(firstAttack)
|
f.sendLegacyGroupSkillHurt(firstAttack)
|
||||||
}
|
}
|
||||||
if secondAttack != nil {
|
if f.legacySkillExecuted(secondAttack) {
|
||||||
f.sendLegacyGroupSkillHurt(secondAttack)
|
f.sendLegacyGroupSkillHurt(secondAttack)
|
||||||
}
|
}
|
||||||
f.sendLegacyGroupBoutDone()
|
f.sendLegacyGroupBoutDone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FightC) legacySkillExecuted(skillAction *action.SelectSkillAction) bool {
|
||||||
|
if f == nil || skillAction == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
attacker := f.GetInputByAction(skillAction, false)
|
||||||
|
return attacker != nil && attacker.AttackValue != nil && attacker.AttackValue.SkillID != 0
|
||||||
|
}
|
||||||
|
|
||||||
func (f *FightC) sendLegacyGroupSkillHurt(skillAction *action.SelectSkillAction) {
|
func (f *FightC) sendLegacyGroupSkillHurt(skillAction *action.SelectSkillAction) {
|
||||||
if f == nil || !f.LegacyGroupProtocol || skillAction == nil {
|
if f == nil || !f.LegacyGroupProtocol || skillAction == nil {
|
||||||
return
|
return
|
||||||
@@ -603,10 +593,10 @@ func (f *FightC) buildLegacyGroupSkillAttackInfo(skillAction *action.SelectSkill
|
|||||||
if attackValue == nil {
|
if attackValue == nil {
|
||||||
attackValue = info.NewAttackValue(self.UserID)
|
attackValue = info.NewAttackValue(self.UserID)
|
||||||
}
|
}
|
||||||
if skillAction != nil && skillAction.SkillEntity != nil {
|
if attackValue.SkillID != 0 {
|
||||||
result.MoveID = uint32(skillAction.SkillEntity.XML.ID)
|
|
||||||
} else {
|
|
||||||
result.MoveID = attackValue.SkillID
|
result.MoveID = attackValue.SkillID
|
||||||
|
} else if skillAction != nil && skillAction.SkillEntity != nil {
|
||||||
|
result.MoveID = uint32(skillAction.SkillEntity.XML.ID)
|
||||||
}
|
}
|
||||||
result.IsCrit = attackValue.IsCritical
|
result.IsCrit = attackValue.IsCritical
|
||||||
result.EffectName = attackValue.State
|
result.EffectName = attackValue.State
|
||||||
|
|||||||
61
logic/service/fight/group_legacy_test.go
Normal file
61
logic/service/fight/group_legacy_test.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package fight
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"blazing/logic/service/fight/action"
|
||||||
|
fightinfo "blazing/logic/service/fight/info"
|
||||||
|
"blazing/logic/service/fight/input"
|
||||||
|
"blazing/modules/player/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSendLegacyRoundBroadcastSkipsUnexecutedAction(t *testing.T) {
|
||||||
|
ourPlayer := &stubPlayer{info: model.PlayerInfo{UserID: 1001}}
|
||||||
|
oppPlayer := &stubPlayer{info: model.PlayerInfo{UserID: 2002}}
|
||||||
|
|
||||||
|
our := input.NewInput(nil, ourPlayer)
|
||||||
|
our.InitAttackValue()
|
||||||
|
our.AttackValue.SkillID = 111
|
||||||
|
our.SetCurPetAt(0, fightinfo.CreateBattlePetEntity(model.PetInfo{
|
||||||
|
ID: 11,
|
||||||
|
Hp: 80,
|
||||||
|
MaxHp: 100,
|
||||||
|
CatchTime: 101,
|
||||||
|
}))
|
||||||
|
|
||||||
|
opp := input.NewInput(nil, oppPlayer)
|
||||||
|
opp.InitAttackValue()
|
||||||
|
opp.SetCurPetAt(0, fightinfo.CreateBattlePetEntity(model.PetInfo{
|
||||||
|
ID: 22,
|
||||||
|
Hp: 0,
|
||||||
|
MaxHp: 100,
|
||||||
|
CatchTime: 202,
|
||||||
|
}))
|
||||||
|
|
||||||
|
fc := &FightC{
|
||||||
|
Our: []*input.Input{our},
|
||||||
|
Opp: []*input.Input{opp},
|
||||||
|
LegacyGroupProtocol: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
firstAttack := &action.SelectSkillAction{
|
||||||
|
BaseAction: action.BaseAction{PlayerID: ourPlayer.info.UserID, ActorIndex: 0, TargetIndex: 0},
|
||||||
|
}
|
||||||
|
secondAttack := &action.SelectSkillAction{
|
||||||
|
BaseAction: action.BaseAction{PlayerID: oppPlayer.info.UserID, ActorIndex: 0, TargetIndex: 0},
|
||||||
|
}
|
||||||
|
|
||||||
|
fc.sendLegacyRoundBroadcast(firstAttack, secondAttack)
|
||||||
|
|
||||||
|
for _, player := range []*stubPlayer{ourPlayer, oppPlayer} {
|
||||||
|
if len(player.sentCmds) != 2 {
|
||||||
|
t.Fatalf("expected one skill packet plus bout done, got %v", player.sentCmds)
|
||||||
|
}
|
||||||
|
if player.sentCmds[0] != groupCmdSkillHurt {
|
||||||
|
t.Fatalf("expected first packet to be skill hurt, got %d", player.sentCmds[0])
|
||||||
|
}
|
||||||
|
if player.sentCmds[1] != groupCmdBoutDone {
|
||||||
|
t.Fatalf("expected second packet to be bout done, got %d", player.sentCmds[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -196,10 +196,8 @@ type PropDict struct {
|
|||||||
|
|
||||||
// NoteUseSkillOutboundInfo 战斗技能使用通知的出站信息结构体
|
// NoteUseSkillOutboundInfo 战斗技能使用通知的出站信息结构体
|
||||||
type NoteUseSkillOutboundInfo struct {
|
type NoteUseSkillOutboundInfo struct {
|
||||||
FirstAttackInfoLen uint32 `struc:"sizeof=FirstAttackInfo"`
|
FirstAttackInfo model.AttackValue // 本轮先手方精灵在释放技能结束后的状态
|
||||||
FirstAttackInfo []model.AttackValue // 本轮先手方精灵在释放技能结束后的状态
|
SecondAttackInfo model.AttackValue // 本轮后手方精灵在释放技能结束后的状态
|
||||||
SecondAttackInfoLen uint32 `struc:"sizeof=SecondAttackInfo"`
|
|
||||||
SecondAttackInfo []model.AttackValue // 本轮后手方精灵在释放技能结束后的状态
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type FightStartOutboundInfo struct {
|
type FightStartOutboundInfo struct {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ var EffectType = enum.New[struct {
|
|||||||
}]()
|
}]()
|
||||||
|
|
||||||
var NodeM = make(map[int64]Effect, 0)
|
var NodeM = make(map[int64]Effect, 0)
|
||||||
|
var NodeFactoryM = make(map[int64]func() Effect, 0)
|
||||||
|
|
||||||
func InitEffect(etype EnumEffectType, id int, t Effect) {
|
func InitEffect(etype EnumEffectType, id int, t Effect) {
|
||||||
pr := EffectIDCombiner{}
|
pr := EffectIDCombiner{}
|
||||||
@@ -41,6 +42,13 @@ func InitEffect(etype EnumEffectType, id int, t Effect) {
|
|||||||
|
|
||||||
NodeM[pr.EffectID()] = t
|
NodeM[pr.EffectID()] = t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InitEffectFactory(etype EnumEffectType, id int, factory func() Effect) {
|
||||||
|
pr := EffectIDCombiner{}
|
||||||
|
pr.Combine(etype, 0, gconv.Uint16(id))
|
||||||
|
|
||||||
|
NodeFactoryM[pr.EffectID()] = factory
|
||||||
|
}
|
||||||
func GeteffectIDs(etype EnumEffectType) []uint32 {
|
func GeteffectIDs(etype EnumEffectType) []uint32 {
|
||||||
|
|
||||||
var ret []uint32 = make([]uint32, 0)
|
var ret []uint32 = make([]uint32, 0)
|
||||||
@@ -60,6 +68,19 @@ func geteffect[T int | byte | uint16](etype EnumEffectType, id T) Effect {
|
|||||||
pr := EffectIDCombiner{}
|
pr := EffectIDCombiner{}
|
||||||
pr.Combine(etype, 0, gconv.Uint16(id))
|
pr.Combine(etype, 0, gconv.Uint16(id))
|
||||||
|
|
||||||
|
if factory, ok := NodeFactoryM[pr.EffectID()]; ok {
|
||||||
|
eff := factory()
|
||||||
|
if eff == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
eff.ID(pr)
|
||||||
|
if etype == EffectType.Status {
|
||||||
|
eff.CanStack(true)
|
||||||
|
eff.Duration(grand.N(1, 2))
|
||||||
|
}
|
||||||
|
return eff
|
||||||
|
}
|
||||||
|
|
||||||
//todo 获取前GetEffect
|
//todo 获取前GetEffect
|
||||||
ret, ok := NodeM[pr.EffectID()]
|
ret, ok := NodeM[pr.EffectID()]
|
||||||
if ok {
|
if ok {
|
||||||
|
|||||||
@@ -107,6 +107,10 @@ func (our *Input) HealPP(value int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentPet.Info.HealPP(value)
|
currentPet.Info.HealPP(value)
|
||||||
|
if our.AttackValue != nil {
|
||||||
|
our.AttackValue.SkillList = append(our.AttackValue.SkillList[:0], currentPet.Info.SkillList...)
|
||||||
|
our.AttackValue.SkillListLen = uint32(len(our.AttackValue.SkillList))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
func (our *Input) DelPP(value int) {
|
func (our *Input) DelPP(value int) {
|
||||||
@@ -123,6 +127,10 @@ func (our *Input) DelPP(value int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if our.AttackValue != nil {
|
||||||
|
our.AttackValue.SkillList = append(our.AttackValue.SkillList[:0], currentPet.Info.SkillList...)
|
||||||
|
our.AttackValue.SkillListLen = uint32(len(our.AttackValue.SkillList))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +306,7 @@ func (our *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) alpaca
|
|||||||
|
|
||||||
}
|
}
|
||||||
if skill.XML.PwrBindDv == 2 {
|
if skill.XML.PwrBindDv == 2 {
|
||||||
skill.XML.Power = int(ourPet.Info.Hp/3 + ourPet.Info.Dv)
|
skill.XML.Power = int(ourPet.Info.MaxHp/3 + ourPet.Info.Dv)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -284,7 +284,9 @@ func (our *Input) GenInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
our.RemainHp = int32(currentPet.Info.Hp)
|
our.RemainHp = int32(currentPet.Info.Hp)
|
||||||
our.SkillList = currentPet.Info.SkillList
|
our.MaxHp = currentPet.Info.MaxHp
|
||||||
|
our.SkillList = append(our.SkillList[:0], currentPet.Info.SkillList...)
|
||||||
|
our.SkillListLen = uint32(len(our.SkillList))
|
||||||
|
|
||||||
// f.Second.SkillList = f.Second.CurPet.Info.SkillList
|
// f.Second.SkillList = f.Second.CurPet.Info.SkillList
|
||||||
// f.Second.RemainHp = int32(f.Second.CurPet.Info.Hp)
|
// f.Second.RemainHp = int32(f.Second.CurPet.Info.Hp)
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package input
|
package input
|
||||||
|
|
||||||
|
// OnSetPropReset 是一个调试钩子,在 SetProp(level==0) 重置 Prop 时被调用。
|
||||||
|
// 外部包可设置此变量来追踪 Prop 被重置的时机和调用栈。
|
||||||
|
var OnSetPropReset func(target *Input, index int8)
|
||||||
|
|
||||||
func (our *Input) HasPropADD() bool {
|
func (our *Input) HasPropADD() bool {
|
||||||
for _, v := range our.Prop[:] {
|
for _, v := range our.Prop[:] {
|
||||||
if v > 0 {
|
if v > 0 {
|
||||||
@@ -55,6 +59,9 @@ func (target *Input) SetProp(source *Input, index, level int8) bool {
|
|||||||
|
|
||||||
if target.AttackValue.Prop[index] != 0 {
|
if target.AttackValue.Prop[index] != 0 {
|
||||||
target.AttackValue.Prop[index] = 0
|
target.AttackValue.Prop[index] = 0
|
||||||
|
if OnSetPropReset != nil {
|
||||||
|
OnSetPropReset(target, index)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func (f *FightC) battleLoop() {
|
|||||||
if player := f.primaryOppPlayer(); player != nil {
|
if player := f.primaryOppPlayer(); player != nil {
|
||||||
f.WinnerId = player.GetInfo().UserID
|
f.WinnerId = player.GetInfo().UserID
|
||||||
}
|
}
|
||||||
f.Reason = model.BattleOverReason.DefaultEnd
|
f.Reason = normalizeFightOverReason(model.BattleOverReason.DefaultEnd)
|
||||||
f.FightOverInfo.WinnerId = f.WinnerId
|
f.FightOverInfo.WinnerId = f.WinnerId
|
||||||
f.FightOverInfo.Reason = f.Reason
|
f.FightOverInfo.Reason = f.Reason
|
||||||
f.closefight = true
|
f.closefight = true
|
||||||
@@ -86,7 +86,7 @@ func (f *FightC) battleLoop() {
|
|||||||
if player := f.primaryOurPlayer(); player != nil {
|
if player := f.primaryOurPlayer(); player != nil {
|
||||||
f.WinnerId = player.GetInfo().UserID
|
f.WinnerId = player.GetInfo().UserID
|
||||||
}
|
}
|
||||||
f.Reason = model.BattleOverReason.DefaultEnd
|
f.Reason = normalizeFightOverReason(model.BattleOverReason.DefaultEnd)
|
||||||
f.FightOverInfo.WinnerId = f.WinnerId
|
f.FightOverInfo.WinnerId = f.WinnerId
|
||||||
f.FightOverInfo.Reason = f.Reason
|
f.FightOverInfo.Reason = f.Reason
|
||||||
f.closefight = true
|
f.closefight = true
|
||||||
@@ -586,6 +586,7 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
|
|||||||
if r <= 0 {
|
if r <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
source.Player.(*player.Player).Service.Item.UPDATE(a.ItemID, -1)
|
source.Player.(*player.Player).Service.Item.UPDATE(a.ItemID, -1)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
|||||||
@@ -297,9 +297,6 @@ func buildFight(opts *fightBuildOptions) (*FightC, errorcode.ErrorCode) {
|
|||||||
f.bindInputFightContext(f.Our, f.Opp)
|
f.bindInputFightContext(f.Our, f.Opp)
|
||||||
f.linkTeamViews()
|
f.linkTeamViews()
|
||||||
|
|
||||||
f.ReadyInfo.OurInfo, f.ReadyInfo.OurPetList = initfightready(f.primaryOur())
|
|
||||||
f.ReadyInfo.OpponentInfo, f.ReadyInfo.OpponentPetList = initfightready(f.primaryOpp())
|
|
||||||
|
|
||||||
loadtime := 120 * time.Second
|
loadtime := 120 * time.Second
|
||||||
if f.Info.Status == info.BattleMode.FIGHT_WITH_NPC {
|
if f.Info.Status == info.BattleMode.FIGHT_WITH_NPC {
|
||||||
if opp := f.primaryOpp(); opp != nil {
|
if opp := f.primaryOpp(); opp != nil {
|
||||||
@@ -313,6 +310,9 @@ func buildFight(opts *fightBuildOptions) (*FightC, errorcode.ErrorCode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f.ReadyInfo.OurInfo, f.ReadyInfo.OurPetList = initfightready(f.primaryOur())
|
||||||
|
f.ReadyInfo.OpponentInfo, f.ReadyInfo.OpponentPetList = initfightready(f.primaryOpp())
|
||||||
f.FightStartOutboundInfo = f.buildFightStartInfo()
|
f.FightStartOutboundInfo = f.buildFightStartInfo()
|
||||||
|
|
||||||
f.BroadcastPlayers(func(p common.PlayerI) {
|
f.BroadcastPlayers(func(p common.PlayerI) {
|
||||||
|
|||||||
@@ -59,9 +59,15 @@ type session struct {
|
|||||||
banPickDeadline time.Time
|
banPickDeadline time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type queueKey struct {
|
||||||
|
FightMode uint32
|
||||||
|
IsVip uint32
|
||||||
|
IsDebug uint8
|
||||||
|
}
|
||||||
|
|
||||||
type manager struct {
|
type manager struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
queues map[uint32][]pvpwire.QueuePlayerSnapshot
|
queues map[queueKey][]pvpwire.QueuePlayerSnapshot
|
||||||
lastSeen map[uint32]time.Time
|
lastSeen map[uint32]time.Time
|
||||||
localQueues map[uint32]*localQueueTicket
|
localQueues map[uint32]*localQueueTicket
|
||||||
sessions map[string]*session
|
sessions map[string]*session
|
||||||
@@ -69,7 +75,7 @@ type manager struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var defaultManager = &manager{
|
var defaultManager = &manager{
|
||||||
queues: make(map[uint32][]pvpwire.QueuePlayerSnapshot),
|
queues: make(map[queueKey][]pvpwire.QueuePlayerSnapshot),
|
||||||
lastSeen: make(map[uint32]time.Time),
|
lastSeen: make(map[uint32]time.Time),
|
||||||
localQueues: make(map[uint32]*localQueueTicket),
|
localQueues: make(map[uint32]*localQueueTicket),
|
||||||
sessions: make(map[string]*session),
|
sessions: make(map[string]*session),
|
||||||
@@ -222,6 +228,8 @@ func (m *manager) queueHeartbeatLoop(p *player.Player, ticket *localQueueTicket)
|
|||||||
Nick: p.Info.Nick,
|
Nick: p.Info.Nick,
|
||||||
FightMode: ticket.fightMode,
|
FightMode: ticket.fightMode,
|
||||||
Status: ticket.status,
|
Status: ticket.status,
|
||||||
|
IsVip: cool.Config.ServerInfo.IsVip,
|
||||||
|
IsDebug: cool.Config.ServerInfo.IsDebug,
|
||||||
JoinedAtUnix: time.Now().Unix(),
|
JoinedAtUnix: time.Now().Unix(),
|
||||||
CatchTimes: filterAvailableCatchTimes(p.GetPetInfo(0)),
|
CatchTimes: filterAvailableCatchTimes(p.GetPetInfo(0)),
|
||||||
},
|
},
|
||||||
@@ -254,12 +262,13 @@ func (m *manager) handleQueueJoin(payload pvpwire.QueueJoinPayload) {
|
|||||||
m.pruneExpiredQueueLocked(now)
|
m.pruneExpiredQueueLocked(now)
|
||||||
playerInfo := payload.Player
|
playerInfo := payload.Player
|
||||||
m.lastSeen[playerInfo.UserID] = now
|
m.lastSeen[playerInfo.UserID] = now
|
||||||
queue := m.queues[playerInfo.FightMode]
|
queueBucket := newQueueKey(playerInfo)
|
||||||
|
queue := m.queues[queueBucket]
|
||||||
|
|
||||||
for idx, queued := range queue {
|
for idx, queued := range queue {
|
||||||
if queued.UserID == playerInfo.UserID {
|
if queued.UserID == playerInfo.UserID {
|
||||||
queue[idx] = playerInfo
|
queue[idx] = playerInfo
|
||||||
m.queues[playerInfo.FightMode] = queue
|
m.queues[queueBucket] = queue
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,7 +276,7 @@ func (m *manager) handleQueueJoin(payload pvpwire.QueueJoinPayload) {
|
|||||||
if len(queue) > 0 {
|
if len(queue) > 0 {
|
||||||
host := queue[0]
|
host := queue[0]
|
||||||
queue = queue[1:]
|
queue = queue[1:]
|
||||||
m.queues[playerInfo.FightMode] = queue
|
m.queues[queueBucket] = queue
|
||||||
delete(m.lastSeen, host.UserID)
|
delete(m.lastSeen, host.UserID)
|
||||||
delete(m.lastSeen, playerInfo.UserID)
|
delete(m.lastSeen, playerInfo.UserID)
|
||||||
|
|
||||||
@@ -286,7 +295,7 @@ func (m *manager) handleQueueJoin(payload pvpwire.QueueJoinPayload) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m.queues[playerInfo.FightMode] = append(queue, playerInfo)
|
m.queues[queueBucket] = append(queue, playerInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *manager) handleQueueCancel(payload pvpwire.QueueCancelPayload) {
|
func (m *manager) handleQueueCancel(payload pvpwire.QueueCancelPayload) {
|
||||||
@@ -294,7 +303,7 @@ func (m *manager) handleQueueCancel(payload pvpwire.QueueCancelPayload) {
|
|||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
delete(m.lastSeen, payload.UserID)
|
delete(m.lastSeen, payload.UserID)
|
||||||
for mode, queue := range m.queues {
|
for key, queue := range m.queues {
|
||||||
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
||||||
for _, queued := range queue {
|
for _, queued := range queue {
|
||||||
if queued.UserID == payload.UserID {
|
if queued.UserID == payload.UserID {
|
||||||
@@ -302,7 +311,7 @@ func (m *manager) handleQueueCancel(payload pvpwire.QueueCancelPayload) {
|
|||||||
}
|
}
|
||||||
next = append(next, queued)
|
next = append(next, queued)
|
||||||
}
|
}
|
||||||
m.queues[mode] = next
|
m.queues[key] = next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,7 +556,7 @@ func (m *manager) closeSession(sessionID, reason string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *manager) pruneExpiredQueueLocked(now time.Time) {
|
func (m *manager) pruneExpiredQueueLocked(now time.Time) {
|
||||||
for mode, queue := range m.queues {
|
for key, queue := range m.queues {
|
||||||
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
next := make([]pvpwire.QueuePlayerSnapshot, 0, len(queue))
|
||||||
for _, queued := range queue {
|
for _, queued := range queue {
|
||||||
last := m.lastSeen[queued.UserID]
|
last := m.lastSeen[queued.UserID]
|
||||||
@@ -557,7 +566,15 @@ func (m *manager) pruneExpiredQueueLocked(now time.Time) {
|
|||||||
}
|
}
|
||||||
next = append(next, queued)
|
next = append(next, queued)
|
||||||
}
|
}
|
||||||
m.queues[mode] = next
|
m.queues[key] = next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newQueueKey(player pvpwire.QueuePlayerSnapshot) queueKey {
|
||||||
|
return queueKey{
|
||||||
|
FightMode: player.FightMode,
|
||||||
|
IsVip: player.IsVip,
|
||||||
|
IsDebug: player.IsDebug,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ type QueuePlayerSnapshot struct {
|
|||||||
Nick string `json:"nick"`
|
Nick string `json:"nick"`
|
||||||
FightMode uint32 `json:"fightMode"`
|
FightMode uint32 `json:"fightMode"`
|
||||||
Status uint32 `json:"status"`
|
Status uint32 `json:"status"`
|
||||||
|
IsVip uint32 `json:"isVip"`
|
||||||
|
IsDebug uint8 `json:"isDebug"`
|
||||||
JoinedAtUnix int64 `json:"joinedAtUnix"`
|
JoinedAtUnix int64 `json:"joinedAtUnix"`
|
||||||
CatchTimes []uint32 `json:"catchTimes"`
|
CatchTimes []uint32 `json:"catchTimes"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
type stubPlayer struct {
|
type stubPlayer struct {
|
||||||
info model.PlayerInfo
|
info model.PlayerInfo
|
||||||
|
sentCmds []uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*stubPlayer) ApplyPetDisplayInfo(*spaceinfo.SimpleInfo) {}
|
func (*stubPlayer) ApplyPetDisplayInfo(*spaceinfo.SimpleInfo) {}
|
||||||
@@ -26,7 +27,7 @@ func (*stubPlayer) SetFightC(common.FightI) {}
|
|||||||
func (*stubPlayer) QuitFight() {}
|
func (*stubPlayer) QuitFight() {}
|
||||||
func (*stubPlayer) MessWin(bool) {}
|
func (*stubPlayer) MessWin(bool) {}
|
||||||
func (*stubPlayer) CanFight() errorcode.ErrorCode { return 0 }
|
func (*stubPlayer) CanFight() errorcode.ErrorCode { return 0 }
|
||||||
func (*stubPlayer) SendPackCmd(uint32, any) {}
|
func (p *stubPlayer) SendPackCmd(cmd uint32, _ any) { p.sentCmds = append(p.sentCmds, cmd) }
|
||||||
func (*stubPlayer) GetPetInfo(uint32) []model.PetInfo { return nil }
|
func (*stubPlayer) GetPetInfo(uint32) []model.PetInfo { return nil }
|
||||||
|
|
||||||
func TestFightActionEnvelopeEncodedTargetIndex(t *testing.T) {
|
func TestFightActionEnvelopeEncodedTargetIndex(t *testing.T) {
|
||||||
@@ -111,3 +112,70 @@ func TestBuildFightStateStartEnvelope(t *testing.T) {
|
|||||||
t.Fatalf("unexpected right fighter snapshot: %+v", envelope.Right[0])
|
t.Fatalf("unexpected right fighter snapshot: %+v", envelope.Right[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildNoteUseSkillOutboundInfoUsesActionOrder(t *testing.T) {
|
||||||
|
ourPlayer := &stubPlayer{info: model.PlayerInfo{UserID: 1001}}
|
||||||
|
oppPlayer := &stubPlayer{info: model.PlayerInfo{UserID: 2002}}
|
||||||
|
|
||||||
|
our := input.NewInput(nil, ourPlayer)
|
||||||
|
our.InitAttackValue()
|
||||||
|
our.AttackValue.SkillID = 111
|
||||||
|
our.AttackValue.RemainHp = 80
|
||||||
|
our.AttackValue.MaxHp = 100
|
||||||
|
|
||||||
|
opp := input.NewInput(nil, oppPlayer)
|
||||||
|
opp.InitAttackValue()
|
||||||
|
opp.AttackValue.SkillID = 222
|
||||||
|
opp.AttackValue.RemainHp = 70
|
||||||
|
opp.AttackValue.MaxHp = 100
|
||||||
|
|
||||||
|
fc := &FightC{
|
||||||
|
Our: []*input.Input{our},
|
||||||
|
Opp: []*input.Input{opp},
|
||||||
|
First: opp,
|
||||||
|
Second: our,
|
||||||
|
}
|
||||||
|
|
||||||
|
result := fc.buildNoteUseSkillOutboundInfo()
|
||||||
|
|
||||||
|
if result.FirstAttackInfo.UserID != 2002 || result.FirstAttackInfo.SkillID != 222 {
|
||||||
|
t.Fatalf("expected first attack info to belong to acting opponent, got %+v", result.FirstAttackInfo)
|
||||||
|
}
|
||||||
|
if result.SecondAttackInfo.UserID != 1001 || result.SecondAttackInfo.SkillID != 111 {
|
||||||
|
t.Fatalf("expected second attack info to keep the idle side placeholder, got %+v", result.SecondAttackInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildNoteUseSkillOutboundInfoUsesAttackValueSkillPP(t *testing.T) {
|
||||||
|
player := &stubPlayer{info: model.PlayerInfo{UserID: 1001}}
|
||||||
|
|
||||||
|
fighter := input.NewInput(nil, player)
|
||||||
|
fighter.InitAttackValue()
|
||||||
|
fighter.AttackValue.SkillID = 300
|
||||||
|
fighter.AttackValue.SkillList = []model.SkillInfo{{ID: 300, PP: 1}}
|
||||||
|
fighter.AttackValue.SkillListLen = 1
|
||||||
|
fighter.AttackValue.RemainHp = 50
|
||||||
|
fighter.AttackValue.MaxHp = 100
|
||||||
|
|
||||||
|
currentPet := fightinfo.CreateBattlePetEntity(model.PetInfo{
|
||||||
|
ID: 11,
|
||||||
|
Name: "Alpha",
|
||||||
|
Level: 20,
|
||||||
|
Hp: 50,
|
||||||
|
MaxHp: 100,
|
||||||
|
CatchTime: 101,
|
||||||
|
SkillList: []model.SkillInfo{{ID: 300, PP: 0}},
|
||||||
|
})
|
||||||
|
currentPet.BindController(player.info.UserID)
|
||||||
|
fighter.SetCurPetAt(0, currentPet)
|
||||||
|
|
||||||
|
fc := &FightC{First: fighter}
|
||||||
|
|
||||||
|
result := fc.buildNoteUseSkillOutboundInfo()
|
||||||
|
if len(result.FirstAttackInfo.SkillList) != 1 {
|
||||||
|
t.Fatalf("expected one skill in broadcast snapshot, got %+v", result.FirstAttackInfo.SkillList)
|
||||||
|
}
|
||||||
|
if result.FirstAttackInfo.SkillList[0].PP != 1 {
|
||||||
|
t.Fatalf("expected broadcast PP to come from attack value cache, got %+v", result.FirstAttackInfo.SkillList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,3 +23,9 @@ type C2S_Skill_Sort struct {
|
|||||||
Skill [4]uint32 `json:"skill_1"` // 技能1(对应C# uint skill_1)
|
Skill [4]uint32 `json:"skill_1"` // 技能1(对应C# uint skill_1)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CommitPetSkillsInfo struct {
|
||||||
|
Head common.TomeeHeader `cmd:"52313" struc:"skip"`
|
||||||
|
CatchTime uint32 `json:"catchTime"`
|
||||||
|
Skill [4]uint32 `json:"skill"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ func (p *Player) IsMatch(t configmodel.Event) bool {
|
|||||||
if len(p.Info.PetList) == 0 {
|
if len(p.Info.PetList) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if p.Info.PetList[0].Hp == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
firstPetID := int32(p.Info.PetList[0].ID)
|
firstPetID := int32(p.Info.PetList[0].ID)
|
||||||
_, ok := lo.Find(t.FirstSprites, func(item int32) bool {
|
_, ok := lo.Find(t.FirstSprites, func(item int32) bool {
|
||||||
@@ -105,7 +108,9 @@ func (p *Player) GenMonster() {
|
|||||||
if atomic.LoadUint32(&p.Canmon) == 0 { //已经进入地图或者没在战斗中,就可以刷新怪
|
if atomic.LoadUint32(&p.Canmon) == 0 { //已经进入地图或者没在战斗中,就可以刷新怪
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if p.GetSpace().PitS == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
var oldnum, newNum int
|
var oldnum, newNum int
|
||||||
var replce []int
|
var replce []int
|
||||||
p.monsters, oldnum, newNum = replaceOneNumber(p.monsters)
|
p.monsters, oldnum, newNum = replaceOneNumber(p.monsters)
|
||||||
@@ -115,15 +120,13 @@ func (p *Player) GenMonster() {
|
|||||||
p.Data = [9]OgrePetInfo{} //切地图清空
|
p.Data = [9]OgrePetInfo{} //切地图清空
|
||||||
replce = p.monsters[:] //产生替换新的精灵
|
replce = p.monsters[:] //产生替换新的精灵
|
||||||
|
|
||||||
|
} else {
|
||||||
|
p.Data[oldnum] = OgrePetInfo{}
|
||||||
}
|
}
|
||||||
p.MapNPC.Reset(10 * time.Second)
|
p.MapNPC.Reset(10 * time.Second)
|
||||||
p.Data[oldnum] = OgrePetInfo{} //切地图清空
|
|
||||||
|
|
||||||
for _, i := range replce {
|
for _, i := range replce {
|
||||||
if p.GetSpace().PitS == nil {
|
p.Data[i] = OgrePetInfo{} //切地图清空
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
ogreconfig, ok := p.GetSpace().PitS.Load(i) //service.NewMapPitService().GetData(p.Info.MapID, uint32(i))
|
ogreconfig, ok := p.GetSpace().PitS.Load(i) //service.NewMapPitService().GetData(p.Info.MapID, uint32(i))
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
@@ -134,7 +137,6 @@ func (p *Player) GenMonster() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Data[i] = OgrePetInfo{}
|
|
||||||
p.Data[i].ID = uint32(v.RefreshID[grand.Intn(len(v.RefreshID))])
|
p.Data[i].ID = uint32(v.RefreshID[grand.Intn(len(v.RefreshID))])
|
||||||
|
|
||||||
if p.Data[i].ID != 0 {
|
if p.Data[i].ID != 0 {
|
||||||
@@ -198,7 +200,7 @@ func replaceOneNumber(original [3]int) ([3]int, int, int) {
|
|||||||
originalMap[num] = true
|
originalMap[num] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 8; i++ {
|
for i := 0; i < 9; i++ {
|
||||||
if !originalMap[i] {
|
if !originalMap[i] {
|
||||||
candidates = append(candidates, i)
|
candidates = append(candidates, i)
|
||||||
}
|
}
|
||||||
|
|||||||
49
logic/service/player/Monster_test.go
Normal file
49
logic/service/player/Monster_test.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
configmodel "blazing/modules/config/model"
|
||||||
|
playermodel "blazing/modules/player/model"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsMatchFirstSpritesRequiresLivingLeadPet(t *testing.T) {
|
||||||
|
player := &Player{
|
||||||
|
baseplayer: baseplayer{
|
||||||
|
Info: &playermodel.PlayerInfo{
|
||||||
|
PetList: []playermodel.PetInfo{
|
||||||
|
{ID: 1001, Hp: 0},
|
||||||
|
{ID: 2002, Hp: 100},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
event := configmodel.Event{
|
||||||
|
FirstSprites: []int32{1001},
|
||||||
|
}
|
||||||
|
|
||||||
|
if player.IsMatch(event) {
|
||||||
|
t.Fatalf("expected dead lead pet to fail FirstSprites match")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIsMatchFirstSpritesAcceptsLivingLeadPet(t *testing.T) {
|
||||||
|
player := &Player{
|
||||||
|
baseplayer: baseplayer{
|
||||||
|
Info: &playermodel.PlayerInfo{
|
||||||
|
PetList: []playermodel.PetInfo{
|
||||||
|
{ID: 1001, Hp: 100},
|
||||||
|
{ID: 2002, Hp: 100},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
event := configmodel.Event{
|
||||||
|
FirstSprites: []int32{1001},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !player.IsMatch(event) {
|
||||||
|
t.Fatalf("expected living lead pet to pass FirstSprites match")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,16 @@
|
|||||||
package player
|
package player
|
||||||
|
|
||||||
|
import "blazing/modules/player/model"
|
||||||
|
|
||||||
type AI_player struct {
|
type AI_player struct {
|
||||||
baseplayer
|
baseplayer
|
||||||
|
|
||||||
CanCapture int
|
CanCapture int
|
||||||
BossScript string
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,17 +32,19 @@ func (p *baseplayer) GetInfo() *model.PlayerInfo {
|
|||||||
return p.Info
|
return p.Info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ApplyPetLevelLimit(pet model.PetInfo, limitlevel uint32) model.PetInfo {
|
||||||
|
originalHP := pet.Hp
|
||||||
|
pet.CalculatePetPane(limitlevel)
|
||||||
|
pet.Hp = utils.Min(originalHP, pet.MaxHp)
|
||||||
|
return pet
|
||||||
|
}
|
||||||
|
|
||||||
func (p *baseplayer) GetPetInfo(limitlevel uint32) []model.PetInfo {
|
func (p *baseplayer) GetPetInfo(limitlevel uint32) []model.PetInfo {
|
||||||
|
|
||||||
var ret []model.PetInfo
|
ret := make([]model.PetInfo, 0, len(p.Info.PetList))
|
||||||
|
|
||||||
for _, pet := range p.Info.PetList {
|
for _, pet := range p.Info.PetList {
|
||||||
if limitlevel > 0 {
|
ret = append(ret, ApplyPetLevelLimit(pet, limitlevel))
|
||||||
pet.Level = utils.Min(pet.Level, limitlevel)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = append(ret, pet)
|
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ func (player *Player) WarehousePetList() []model.PetInfo {
|
|||||||
return make([]model.PetInfo, 0)
|
return make([]model.PetInfo, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result := make([]model.PetInfo, 0, len(allPets))
|
result := make([]model.PetInfo, 0, len(allPets))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -25,32 +24,35 @@ func (player *Player) WarehousePetList() []model.PetInfo {
|
|||||||
|
|
||||||
// AddPetExp 添加宠物经验
|
// AddPetExp 添加宠物经验
|
||||||
func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
||||||
if addExp < 0 {
|
if petInfo == nil || addExp <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
panelLimit := p.CurrentMapPetLevelLimit()
|
||||||
|
if petInfo.Level > 100 {
|
||||||
|
currentHP := petInfo.Hp
|
||||||
|
petInfo.Update(false)
|
||||||
|
petInfo.CalculatePetPane(panelLimit)
|
||||||
|
petInfo.Hp = utils.Min(currentHP, petInfo.MaxHp)
|
||||||
|
}
|
||||||
addExp = utils.Min(addExp, p.Info.ExpPool)
|
addExp = utils.Min(addExp, p.Info.ExpPool)
|
||||||
|
if addExp <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
originalLevel := petInfo.Level
|
originalLevel := petInfo.Level
|
||||||
exp := int64(petInfo.Exp) + addExp
|
allocatedExp := addExp
|
||||||
p.Info.ExpPool -= 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.Level++
|
||||||
|
|
||||||
exp -= int64(petInfo.LvExp)
|
|
||||||
petInfo.Update(true)
|
petInfo.Update(true)
|
||||||
if originalLevel < 100 && petInfo.Level == 100 { //升到100了
|
currentExp -= petInfo.LvExp
|
||||||
p.Info.ExpPool += exp //减去已使用的经验
|
|
||||||
gainedExp -= exp
|
|
||||||
exp = 0
|
|
||||||
break //停止升级
|
|
||||||
}
|
}
|
||||||
|
petInfo.Exp = currentExp
|
||||||
|
|
||||||
}
|
|
||||||
petInfo.Exp = (exp)
|
|
||||||
// 重新计算面板
|
// 重新计算面板
|
||||||
if originalLevel != petInfo.Level {
|
if originalLevel != petInfo.Level {
|
||||||
petInfo.CalculatePetPane(100)
|
petInfo.CalculatePetPane(panelLimit)
|
||||||
|
|
||||||
petInfo.Cure()
|
petInfo.Cure()
|
||||||
p.Info.PetMaxLevel = utils.Max(petInfo.Level, p.Info.PetMaxLevel)
|
p.Info.PetMaxLevel = utils.Max(petInfo.Level, p.Info.PetMaxLevel)
|
||||||
@@ -82,7 +84,7 @@ func (p *Player) AddPetExp(petInfo *model.PetInfo, addExp int64) {
|
|||||||
var petUpdateInfo info.UpdatePropInfo
|
var petUpdateInfo info.UpdatePropInfo
|
||||||
|
|
||||||
copier.Copy(&petUpdateInfo, petInfo)
|
copier.Copy(&petUpdateInfo, petInfo)
|
||||||
petUpdateInfo.Exp = uint32(gainedExp)
|
petUpdateInfo.Exp = uint32(allocatedExp)
|
||||||
updateOutbound.Data = append(updateOutbound.Data, petUpdateInfo)
|
updateOutbound.Data = append(updateOutbound.Data, petUpdateInfo)
|
||||||
p.SendPack(header.Pack(updateOutbound)) //准备包由各自发,因为协议不一样
|
p.SendPack(header.Pack(updateOutbound)) //准备包由各自发,因为协议不一样
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ func (slot PetBagSlot) PetInfo() model.PetInfo {
|
|||||||
return slot.info
|
return slot.info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (slot PetBagSlot) PetInfoPtr() *model.PetInfo {
|
||||||
|
if !slot.IsValid() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &(*slot.list)[slot.index]
|
||||||
|
}
|
||||||
|
|
||||||
func (slot PetBagSlot) IsMainBag() bool {
|
func (slot PetBagSlot) IsMainBag() bool {
|
||||||
return slot.main
|
return slot.main
|
||||||
}
|
}
|
||||||
@@ -99,12 +106,20 @@ func validatePetBagOrder(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildLimitedPetList(petList []model.PetInfo, limitlevel uint32) []model.PetInfo {
|
||||||
|
result := make([]model.PetInfo, 0, len(petList))
|
||||||
|
for _, petInfo := range petList {
|
||||||
|
result = append(result, ApplyPetLevelLimit(petInfo, limitlevel))
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// GetUserBagPetInfo 返回主背包和并列备用精灵列表。
|
// GetUserBagPetInfo 返回主背包和并列备用精灵列表。
|
||||||
func (p *Player) GetUserBagPetInfo() *pet.GetUserBagPetInfoOutboundInfo {
|
func (p *Player) GetUserBagPetInfo(limitlevel uint32) *pet.GetUserBagPetInfoOutboundInfo {
|
||||||
|
|
||||||
result := &pet.GetUserBagPetInfoOutboundInfo{
|
result := &pet.GetUserBagPetInfoOutboundInfo{
|
||||||
PetList: p.Info.PetList,
|
PetList: buildLimitedPetList(p.Info.PetList, limitlevel),
|
||||||
BackupPetList: p.Info.BackupPetList,
|
BackupPetList: buildLimitedPetList(p.Info.BackupPetList, limitlevel),
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
157
logic/service/player/pet_test.go
Normal file
157
logic/service/player/pet_test.go
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
package player
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/common/data/xmlres"
|
||||||
|
playermodel "blazing/modules/player/model"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func firstPetIDForTest(t *testing.T) int {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
for id := range xmlres.PetMAP {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Fatal("xmlres.PetMAP is empty")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddPetExpAllowsLevelBeyond100WhilePanelStaysCapped(t *testing.T) {
|
||||||
|
petID := firstPetIDForTest(t)
|
||||||
|
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||||
|
expectedPanel := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||||
|
if petInfo == nil {
|
||||||
|
t.Fatalf("failed to generate test pet")
|
||||||
|
}
|
||||||
|
if expectedPanel == nil {
|
||||||
|
t.Fatalf("failed to generate expected test pet")
|
||||||
|
}
|
||||||
|
|
||||||
|
player := &Player{
|
||||||
|
baseplayer: baseplayer{
|
||||||
|
Info: &playermodel.PlayerInfo{
|
||||||
|
ExpPool: 1_000_000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
player.AddPetExp(petInfo, petInfo.NextLvExp+10_000)
|
||||||
|
|
||||||
|
if petInfo.Level <= 100 {
|
||||||
|
t.Fatalf("expected pet level to continue beyond 100, got %d", petInfo.Level)
|
||||||
|
}
|
||||||
|
if petInfo.MaxHp != expectedPanel.MaxHp {
|
||||||
|
t.Fatalf("expected max hp to stay capped at 100-level panel, got %d want %d", petInfo.MaxHp, expectedPanel.MaxHp)
|
||||||
|
}
|
||||||
|
if petInfo.Prop != expectedPanel.Prop {
|
||||||
|
t.Fatalf("expected props to stay capped at 100-level panel, got %+v want %+v", petInfo.Prop, expectedPanel.Prop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddPetExpRecalculatesPanelForLevelAbove100(t *testing.T) {
|
||||||
|
petID := firstPetIDForTest(t)
|
||||||
|
petInfo := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||||
|
expectedPanel := playermodel.GenPetInfo(petID, 31, 0, 0, 100, nil, 0)
|
||||||
|
if petInfo == nil {
|
||||||
|
t.Fatalf("failed to generate test pet")
|
||||||
|
}
|
||||||
|
if expectedPanel == nil {
|
||||||
|
t.Fatalf("failed to generate expected test pet")
|
||||||
|
}
|
||||||
|
petInfo.Level = 101
|
||||||
|
petInfo.Exp = 7
|
||||||
|
petInfo.MaxHp = 1
|
||||||
|
petInfo.Hp = 999999
|
||||||
|
|
||||||
|
player := &Player{
|
||||||
|
baseplayer: baseplayer{
|
||||||
|
Info: &playermodel.PlayerInfo{
|
||||||
|
ExpPool: 50_000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
player.AddPetExp(petInfo, 12_345)
|
||||||
|
|
||||||
|
if petInfo.Level < 101 {
|
||||||
|
t.Fatalf("expected level above 100 to be preserved, got %d", petInfo.Level)
|
||||||
|
}
|
||||||
|
if petInfo.MaxHp != expectedPanel.MaxHp {
|
||||||
|
t.Fatalf("expected max hp to be recalculated using level 100 cap, got %d want %d", petInfo.MaxHp, expectedPanel.MaxHp)
|
||||||
|
}
|
||||||
|
if petInfo.Hp != petInfo.MaxHp {
|
||||||
|
t.Fatalf("expected hp to be clamped to recalculated max hp, got hp=%d maxHp=%d", petInfo.Hp, petInfo.MaxHp)
|
||||||
|
}
|
||||||
|
if player.Info.ExpPool != 50_000-12_345 {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -228,6 +228,21 @@ func (p *Player) GetSpace() *space.Space {
|
|||||||
return space.GetSpace(p.Info.MapID)
|
return space.GetSpace(p.Info.MapID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Player) CurrentMapPetLevelLimit() uint32 {
|
||||||
|
if p == nil {
|
||||||
|
return 100
|
||||||
|
}
|
||||||
|
currentSpace := p.GetSpace()
|
||||||
|
if currentSpace != nil && currentSpace.IsLevelBreakMap {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return 100
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Player) IsCurrentMapLevelBreak() bool {
|
||||||
|
return p != nil && p.CurrentMapPetLevelLimit() == 0
|
||||||
|
}
|
||||||
|
|
||||||
// CanFight 检查玩家是否可以进行战斗
|
// CanFight 检查玩家是否可以进行战斗
|
||||||
// 0无战斗,1PVP,2,BOOS,3PVE
|
// 0无战斗,1PVP,2,BOOS,3PVE
|
||||||
func (p *Player) CanFight() errorcode.ErrorCode {
|
func (p *Player) CanFight() errorcode.ErrorCode {
|
||||||
@@ -419,7 +434,15 @@ func (p *Player) ItemAdd(ItemId, ItemCnt int64) (result bool) {
|
|||||||
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
p.Service.Item.UPDATE(uint32(ItemId), gconv.Int(ItemCnt))
|
if err := p.Service.Item.UPDATE(uint32(ItemId), gconv.Int(ItemCnt)); err != nil {
|
||||||
|
cool.Logger.Error(context.TODO(), "item add update failed", p.Info.UserID, ItemId, ItemCnt, err)
|
||||||
|
|
||||||
|
t1 := common.NewTomeeHeader(2601, p.Info.UserID)
|
||||||
|
t1.Result = uint32(errorcode.ErrorCodes.ErrSystemError200007)
|
||||||
|
|
||||||
|
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,14 @@ func (p *Player) Save() {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
cool.CacheManager.Remove(cacheCtx, fmt.Sprintf("player:%d", p.Info.UserID))
|
cool.CacheManager.Remove(cacheCtx, fmt.Sprintf("player:%d", p.Info.UserID))
|
||||||
newtime := time.Now().Unix()
|
newtime := time.Now().Unix()
|
||||||
p.Info.TimeToday = p.Info.TimeToday + newtime - int64(p.Logintime) //保存电池时间
|
if p.Logintime > 0 {
|
||||||
// p.Info.FightTime = p.Info.FightTime + (newtime - int64(p.Logintime))
|
onlineSeconds := newtime - int64(p.Logintime)
|
||||||
p.Info.OnlineTime = p.Info.OnlineTime + (newtime-int64(p.Logintime))/60 //每次退出时候保存已经在线的分钟数
|
if onlineSeconds > 0 {
|
||||||
|
p.Info.TimeToday += onlineSeconds //保存电池时间
|
||||||
|
// p.Info.FightTime += onlineSeconds
|
||||||
|
p.Info.OnlineTime += onlineSeconds / 60 //每次退出时候保存已经在线的分钟数
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if p.FightC != nil {
|
if p.FightC != nil {
|
||||||
|
|
||||||
@@ -63,6 +68,7 @@ func (p *Player) Save() {
|
|||||||
|
|
||||||
Mainplayer.Delete(p.Info.UserID)
|
Mainplayer.Delete(p.Info.UserID)
|
||||||
share.ShareManager.DeleteUserOnline(p.Info.UserID) //设置用户登录服务器
|
share.ShareManager.DeleteUserOnline(p.Info.UserID) //设置用户登录服务器
|
||||||
|
p.Logintime = 0
|
||||||
|
|
||||||
}
|
}
|
||||||
func (p *Player) SaveOnDisconnect() {
|
func (p *Player) SaveOnDisconnect() {
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TaskCompletionContext 封装任务完成时的上下文。
|
||||||
|
// 这里除了保留任务配置和默认奖励,也给自定义任务完成逻辑暴露了返回包与开关位,
|
||||||
|
// 用来兼容“固定发物品/精灵”之外的奖励场景。
|
||||||
|
// 这套扩展最初是为任务发放特训技能、皮肤而补上的:
|
||||||
|
// 特训奖励不能完全按静态表直发,需要结合额外条件做特判,
|
||||||
|
// 例如通过挖矿/对话进度限制特训次数,满足条件后再允许完成任务。
|
||||||
type TaskCompletionContext struct {
|
type TaskCompletionContext struct {
|
||||||
TaskID uint32
|
TaskID uint32
|
||||||
OutState int
|
OutState int
|
||||||
@@ -21,8 +27,12 @@ type TaskCompletionContext struct {
|
|||||||
SkipDefaultReward bool
|
SkipDefaultReward bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TaskCompletionHandler 定义任务完成前的自定义处理器。
|
||||||
|
// 处理器可用于补充校验、写入额外奖励,或在任务完全走自定义发奖时跳过默认奖励流程。
|
||||||
type TaskCompletionHandler func(*Player, *TaskCompletionContext) errorcode.ErrorCode
|
type TaskCompletionHandler func(*Player, *TaskCompletionContext) errorcode.ErrorCode
|
||||||
|
|
||||||
|
// taskCompletionRegistry 按任务 ID 维护自定义完成处理器。
|
||||||
|
// 默认任务仍然走 task 配表里的固定奖励;只有存在特判需求的任务才在这里注册。
|
||||||
var taskCompletionRegistry = struct {
|
var taskCompletionRegistry = struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
handlers map[uint32]TaskCompletionHandler
|
handlers map[uint32]TaskCompletionHandler
|
||||||
@@ -30,11 +40,16 @@ var taskCompletionRegistry = struct {
|
|||||||
handlers: make(map[uint32]TaskCompletionHandler),
|
handlers: make(map[uint32]TaskCompletionHandler),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// taskRewardGrantResult 汇总本次任务实际发放的奖励,
|
||||||
|
// 便于后续统一推送给前端展示。
|
||||||
type taskRewardGrantResult struct {
|
type taskRewardGrantResult struct {
|
||||||
Pet *playermodel.PetInfo
|
Pet *playermodel.PetInfo
|
||||||
Items []data.ItemInfo
|
Items []data.ItemInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegisterTaskCompletionHandler 注册任务完成时的自定义处理器。
|
||||||
|
// 用于覆盖“任务奖励固定为物品和精灵”的旧模型,让指定任务在完成前后插入额外逻辑。
|
||||||
|
// 当前这套机制主要服务于特训技能、皮肤等特殊奖励,以及需要额外次数/进度校验的任务。
|
||||||
func RegisterTaskCompletionHandler(taskID uint32, handler TaskCompletionHandler) {
|
func RegisterTaskCompletionHandler(taskID uint32, handler TaskCompletionHandler) {
|
||||||
if taskID == 0 || handler == nil {
|
if taskID == 0 || handler == nil {
|
||||||
return
|
return
|
||||||
@@ -45,6 +60,9 @@ func RegisterTaskCompletionHandler(taskID uint32, handler TaskCompletionHandler)
|
|||||||
taskCompletionRegistry.Unlock()
|
taskCompletionRegistry.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegisterTaskTalkLimitHandler 注册一个基于挖矿/采集对话进度的完成限制。
|
||||||
|
// 历史上特训任务需要通过挖矿次数限制可领取次数,因此复用了 Talk 进度作为准入条件。
|
||||||
|
// 当指定 talkID 的进度不足 needCount 时,任务不能完成也不能领奖。
|
||||||
func RegisterTaskTalkLimitHandler(taskID, talkID, needCount uint32) {
|
func RegisterTaskTalkLimitHandler(taskID, talkID, needCount uint32) {
|
||||||
RegisterTaskCompletionHandler(taskID, func(p *Player, _ *TaskCompletionContext) errorcode.ErrorCode {
|
RegisterTaskCompletionHandler(taskID, func(p *Player, _ *TaskCompletionContext) errorcode.ErrorCode {
|
||||||
if p == nil || p.Service == nil || p.Service.Talk == nil {
|
if p == nil || p.Service == nil || p.Service.Talk == nil {
|
||||||
@@ -67,6 +85,7 @@ func (p *Player) getTaskGift(taskID int, outState int) *tasklogic.TaskResult {
|
|||||||
return tasklogic.GetTaskInfo(taskID, outState)
|
return tasklogic.GetTaskInfo(taskID, outState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hasTaskCompletionHandler 判断任务是否存在自定义完成处理器。
|
||||||
func hasTaskCompletionHandler(taskID uint32) bool {
|
func hasTaskCompletionHandler(taskID uint32) bool {
|
||||||
taskCompletionRegistry.RLock()
|
taskCompletionRegistry.RLock()
|
||||||
_, ok := taskCompletionRegistry.handlers[taskID]
|
_, ok := taskCompletionRegistry.handlers[taskID]
|
||||||
@@ -74,6 +93,7 @@ func hasTaskCompletionHandler(taskID uint32) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getTaskCompletionHandler 获取任务的自定义完成处理器。
|
||||||
func getTaskCompletionHandler(taskID uint32) TaskCompletionHandler {
|
func getTaskCompletionHandler(taskID uint32) TaskCompletionHandler {
|
||||||
taskCompletionRegistry.RLock()
|
taskCompletionRegistry.RLock()
|
||||||
handler := taskCompletionRegistry.handlers[taskID]
|
handler := taskCompletionRegistry.handlers[taskID]
|
||||||
@@ -81,6 +101,8 @@ func getTaskCompletionHandler(taskID uint32) TaskCompletionHandler {
|
|||||||
return handler
|
return handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// canCompleteTaskReward 判断任务是否具备可执行的奖励逻辑。
|
||||||
|
// 只要存在默认奖励,或已注册自定义处理器,就允许进入完成流程。
|
||||||
func (p *Player) canCompleteTaskReward(taskID, outState int) bool {
|
func (p *Player) canCompleteTaskReward(taskID, outState int) bool {
|
||||||
if taskID <= 0 {
|
if taskID <= 0 {
|
||||||
return false
|
return false
|
||||||
@@ -88,6 +110,10 @@ func (p *Player) canCompleteTaskReward(taskID, outState int) bool {
|
|||||||
return p.getTaskGift(taskID, outState) != nil || hasTaskCompletionHandler(uint32(taskID))
|
return p.getTaskGift(taskID, outState) != nil || hasTaskCompletionHandler(uint32(taskID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplyTaskCompletion 执行任务完成时的奖励发放入口。
|
||||||
|
// 流程分两层:
|
||||||
|
// 1. 先执行自定义处理器,处理特训/皮肤/额外次数校验等特殊逻辑;
|
||||||
|
// 2. 若未要求跳过默认奖励,再回落到原有的物品/精灵发奖逻辑。
|
||||||
func (p *Player) ApplyTaskCompletion(taskID uint32, outState int, result *tasklogic.CompleteTaskOutboundInfo) (*taskRewardGrantResult, errorcode.ErrorCode) {
|
func (p *Player) ApplyTaskCompletion(taskID uint32, outState int, result *tasklogic.CompleteTaskOutboundInfo) (*taskRewardGrantResult, errorcode.ErrorCode) {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||||
@@ -125,6 +151,8 @@ func (p *Player) ApplyTaskCompletion(taskID uint32, outState int, result *tasklo
|
|||||||
return p.grantTaskReward(ctx.Reward, result), 0
|
return p.grantTaskReward(ctx.Reward, result), 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// grantTaskReward 发放 task 配表里的默认奖励。
|
||||||
|
// 这里仍负责原有的固定奖励模型:物品、精灵、称号,以及配置里声明的任务宠奖励。
|
||||||
func (p *Player) grantTaskReward(reward *tasklogic.TaskResult, result *tasklogic.CompleteTaskOutboundInfo) *taskRewardGrantResult {
|
func (p *Player) grantTaskReward(reward *tasklogic.TaskResult, result *tasklogic.CompleteTaskOutboundInfo) *taskRewardGrantResult {
|
||||||
granted := &taskRewardGrantResult{
|
granted := &taskRewardGrantResult{
|
||||||
Items: make([]data.ItemInfo, 0),
|
Items: make([]data.ItemInfo, 0),
|
||||||
@@ -169,6 +197,7 @@ func (p *Player) grantTaskReward(reward *tasklogic.TaskResult, result *tasklogic
|
|||||||
return granted
|
return granted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendTaskCompletionBonus 将任务奖励转换为旧的奖励展示协议并推送给前端。
|
||||||
func (p *Player) SendTaskCompletionBonus(bonusID uint32, granted *taskRewardGrantResult) {
|
func (p *Player) SendTaskCompletionBonus(bonusID uint32, granted *taskRewardGrantResult) {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -39,3 +39,9 @@ type C2S_RoomPetInfo struct {
|
|||||||
// CatchTime 精灵的捕获时间(Unix时间戳/前端自定义时间格式)
|
// CatchTime 精灵的捕获时间(Unix时间戳/前端自定义时间格式)
|
||||||
CatchTime uint32 `json:"catchTime"`
|
CatchTime uint32 `json:"catchTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// S2C_RoomPetShowToggle 基地展示精灵添加/移除响应
|
||||||
|
type S2C_RoomPetShowToggle struct {
|
||||||
|
PetShowListLen uint32 `json:"PetShowListLen" struc:"sizeof=PetShowList"`
|
||||||
|
PetShowList []pet.PetShortInfo `json:"PetShowList"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,64 +21,7 @@ type TimeBossRule struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Timed boss schedule config.
|
// Timed boss schedule config.
|
||||||
var timeBossRules = []TimeBossRule{
|
var timeBossRules = []TimeBossRule{}
|
||||||
{
|
|
||||||
PetID: 261,
|
|
||||||
Week: 1,
|
|
||||||
ShowHours: []int{12, 17, 18, 24},
|
|
||||||
ShowMinute: 35,
|
|
||||||
LastTime: 40,
|
|
||||||
MapIDs: []uint32{15, 105, 54},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
PetID: 261,
|
|
||||||
Week: 2,
|
|
||||||
ShowHours: []int{17, 18, 24},
|
|
||||||
ShowMinute: 0,
|
|
||||||
LastTime: 5,
|
|
||||||
MapIDs: []uint32{15, 105, 54},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
PetID: 261,
|
|
||||||
Week: 3,
|
|
||||||
ShowHours: []int{17, 18, 24},
|
|
||||||
ShowMinute: 0,
|
|
||||||
LastTime: 5,
|
|
||||||
MapIDs: []uint32{15, 105, 54},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
PetID: 261,
|
|
||||||
Week: 4,
|
|
||||||
ShowHours: []int{12, 17, 18, 24},
|
|
||||||
ShowMinute: 35,
|
|
||||||
LastTime: 40,
|
|
||||||
MapIDs: []uint32{15, 105, 54},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
PetID: 261,
|
|
||||||
Week: 5,
|
|
||||||
ShowHours: []int{17, 18, 24},
|
|
||||||
ShowMinute: 0,
|
|
||||||
LastTime: 5,
|
|
||||||
MapIDs: []uint32{15, 105, 54},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
PetID: 261,
|
|
||||||
Week: 6,
|
|
||||||
ShowHours: []int{17, 18, 24},
|
|
||||||
ShowMinute: 0,
|
|
||||||
LastTime: 5,
|
|
||||||
MapIDs: []uint32{15, 105, 54},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
PetID: 261,
|
|
||||||
Week: 7,
|
|
||||||
ShowHours: generateHourRange(0, 23),
|
|
||||||
ShowMinute: 0,
|
|
||||||
LastTime: 10,
|
|
||||||
MapIDs: []uint32{15, 105, 54},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
registeredCronIDs = make(map[string]bool)
|
registeredCronIDs = make(map[string]bool)
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ type Space struct {
|
|||||||
TimeBoss info.S2C_2022
|
TimeBoss info.S2C_2022
|
||||||
|
|
||||||
IsTime bool
|
IsTime bool
|
||||||
|
IsLevelBreakMap bool
|
||||||
DropItemIds []uint32
|
DropItemIds []uint32
|
||||||
PitS *csmap.CsMap[int, []model.MapPit]
|
PitS *csmap.CsMap[int, []model.MapPit]
|
||||||
MapNodeS *csmap.CsMap[uint32, *model.MapNode]
|
MapNodeS *csmap.CsMap[uint32, *model.MapNode]
|
||||||
@@ -185,6 +186,9 @@ func (ret *Space) init() {
|
|||||||
if r.IsTimeSpace != 0 {
|
if r.IsTimeSpace != 0 {
|
||||||
ret.IsTime = true
|
ret.IsTime = true
|
||||||
}
|
}
|
||||||
|
if r.IsLevelBreakMap != 0 {
|
||||||
|
ret.IsLevelBreakMap = true
|
||||||
|
}
|
||||||
ret.MapBossSInfo = info.MapModelBroadcastInfo{}
|
ret.MapBossSInfo = info.MapModelBroadcastInfo{}
|
||||||
ret.MapBossSInfo.INFO = make([]info.MapModelBroadcastEntry, 0)
|
ret.MapBossSInfo.INFO = make([]info.MapModelBroadcastEntry, 0)
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ var (
|
|||||||
g.DB().SetDebug(true)
|
g.DB().SetDebug(true)
|
||||||
// service.NewServerService().SetServerScreen(0, "sss")
|
// service.NewServerService().SetServerScreen(0, "sss")
|
||||||
cool.Config.ServerInfo.IsDebug = 1
|
cool.Config.ServerInfo.IsDebug = 1
|
||||||
|
cool.Config.AutoMigrate = true
|
||||||
|
}
|
||||||
|
if err = cool.RunAutoMigrate(); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if cool.IsRedisMode {
|
if cool.IsRedisMode {
|
||||||
go rpc.ListenFunc(ctx)
|
go rpc.ListenFunc(ctx)
|
||||||
@@ -71,7 +75,6 @@ var limiter *ratelimit.Rule = ratelimit.NewRule()
|
|||||||
|
|
||||||
// 简单规则案例
|
// 简单规则案例
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
//步骤二:增加一条或者多条规则组成复合规则,此复合规则必须至少包含一条规则
|
//步骤二:增加一条或者多条规则组成复合规则,此复合规则必须至少包含一条规则
|
||||||
limiter.AddRule(time.Second*1, 20)
|
limiter.AddRule(time.Second*1, 20)
|
||||||
//步骤三:调用函数判断某用户是否允许访问 allow:= r.AllowVisit(user)
|
//步骤三:调用函数判断某用户是否允许访问 allow:= r.AllowVisit(user)
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ redis:
|
|||||||
pass: "redis_TxYnSy"
|
pass: "redis_TxYnSy"
|
||||||
|
|
||||||
blazing:
|
blazing:
|
||||||
autoMigrate: true
|
|
||||||
eps: true
|
eps: true
|
||||||
file:
|
file:
|
||||||
mode: "local" # local | minio | oss
|
mode: "local" # local | minio | oss
|
||||||
|
|||||||
@@ -140,6 +140,8 @@ func init() {
|
|||||||
g.Server().BindMiddleware("/admin/*/open/*", BaseAuthorityMiddlewareOpen)
|
g.Server().BindMiddleware("/admin/*/open/*", BaseAuthorityMiddlewareOpen)
|
||||||
g.Server().BindMiddleware("/rpc/*", BaseAuthorityMiddlewareOpen)
|
g.Server().BindMiddleware("/rpc/*", BaseAuthorityMiddlewareOpen)
|
||||||
g.Server().BindMiddleware("/admin/*/comm/*", BaseAuthorityMiddlewareComm)
|
g.Server().BindMiddleware("/admin/*/comm/*", BaseAuthorityMiddlewareComm)
|
||||||
|
g.Server().BindMiddleware("/seer/game/cdk/*", BaseAuthorityMiddlewareComm)
|
||||||
|
g.Server().BindMiddleware("/seer/game/cdk/*", BaseAuthorityMiddleware)
|
||||||
g.Server().BindMiddleware("/admin/*", BaseAuthorityMiddleware)
|
g.Server().BindMiddleware("/admin/*", BaseAuthorityMiddleware)
|
||||||
// g.Server().BindMiddleware("/*", AutoI18n)
|
// g.Server().BindMiddleware("/*", AutoI18n)
|
||||||
g.Server().BindMiddleware("/*", MiddlewareCORS)
|
g.Server().BindMiddleware("/*", MiddlewareCORS)
|
||||||
|
|||||||
@@ -52,6 +52,18 @@ func (s *BaseSysUserService) GetPerson(userId uint32) (res *model.BaseSysUser) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *BaseSysUserService) GetByUsername(username string) (res *model.BaseSysUser) {
|
||||||
|
if strings.TrimSpace(username) == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
m := cool.DBM(s.Model)
|
||||||
|
m.Where("username", strings.ToLower(strings.TrimSpace(username))).FieldsEx("password").Scan(&res)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (s *BaseSysUserService) SetdepartmentId(userId, departmentId uint32) (res *model.BaseSysUser) {
|
func (s *BaseSysUserService) SetdepartmentId(userId, departmentId uint32) (res *model.BaseSysUser) {
|
||||||
m := cool.DBM(s.Model)
|
m := cool.DBM(s.Model)
|
||||||
m.Where("id", userId).Data("departmentId", departmentId).Update()
|
m.Where("id", userId).Data("departmentId", departmentId).Update()
|
||||||
@@ -386,6 +398,7 @@ func (s *BaseSysUserService) ServiceUpdate(ctx context.Context, req *cool.Update
|
|||||||
var (
|
var (
|
||||||
admin = cool.GetAdmin(ctx)
|
admin = cool.GetAdmin(ctx)
|
||||||
m = cool.DBM(s.Model)
|
m = cool.DBM(s.Model)
|
||||||
|
updateResult sql.Result
|
||||||
)
|
)
|
||||||
|
|
||||||
r := g.RequestFromCtx(ctx)
|
r := g.RequestFromCtx(ctx)
|
||||||
@@ -424,15 +437,15 @@ func (s *BaseSysUserService) ServiceUpdate(ctx context.Context, req *cool.Update
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 如果请求的password不为空并且密码加密后的值有变动,说明要修改密码
|
// // 如果请求的password不为空并且密码加密后的值有变动,说明要修改密码
|
||||||
var rPassword = r.Get("password", "").String()
|
// var rPassword = r.Get("password", "").String()
|
||||||
if rPassword != "" && rPassword != userInfo["password"].String() {
|
// if rPassword != "" && rPassword != userInfo["password"].String() {
|
||||||
rMap["password"], _ = gmd5.Encrypt(rPassword)
|
// rMap["password"], _ = gmd5.Encrypt(rPassword)
|
||||||
rMap["passwordV"] = userInfo["passwordV"].Int() + 1
|
// rMap["passwordV"] = userInfo["passwordV"].Int() + 1
|
||||||
cool.CacheManager.Set(ctx, fmt.Sprintf("admin:passwordVersion:%d", userId), rMap["passwordV"], 0)
|
// cool.CacheManager.Set(ctx, fmt.Sprintf("admin:passwordVersion:%d", userId), rMap["passwordV"], 0)
|
||||||
} else {
|
// } else {
|
||||||
delete(rMap, "password")
|
// delete(rMap, "password")
|
||||||
}
|
// }
|
||||||
delete(rMap, "goldbean")
|
delete(rMap, "goldbean")
|
||||||
|
|
||||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
||||||
@@ -470,13 +483,17 @@ func (s *BaseSysUserService) ServiceUpdate(ctx context.Context, req *cool.Update
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = m.TX(tx).Update(rMap)
|
updateResult, err = m.TX(tx).Data(rMap).Where("id", userId).Update()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
data = updateResult
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,64 @@ package blazing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "blazing/modules/config/controller"
|
_ "blazing/modules/config/controller"
|
||||||
_ "blazing/modules/config/model"
|
|
||||||
_ "blazing/modules/config/service"
|
_ "blazing/modules/config/service"
|
||||||
|
|
||||||
|
"blazing/cool"
|
||||||
|
configModel "blazing/modules/config/model"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/encoding/gjson"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
var (
|
||||||
|
ctx = gctx.GetInitCtx()
|
||||||
|
)
|
||||||
|
cool.Logger.Debug(ctx, "module config init start ...")
|
||||||
|
|
||||||
|
// 首次初始化 SPT 默认数据(不依赖 XML)。
|
||||||
|
sptModel := configModel.NewSptConfig()
|
||||||
|
count, err := g.DB("default").Model(sptModel.TableName()).Count()
|
||||||
|
if err != nil {
|
||||||
|
cool.Logger.Warning(ctx, "count config_spt failed:", err)
|
||||||
|
} else if count == 0 {
|
||||||
|
initPath := "modules/config/resource/initjson/config_spt.json"
|
||||||
|
content := gfile.GetBytes(initPath)
|
||||||
|
if len(content) == 0 {
|
||||||
|
cool.Logger.Warning(ctx, "config_spt init file is empty:", initPath)
|
||||||
|
} else {
|
||||||
|
jsonData, jErr := gjson.LoadContent(content)
|
||||||
|
if jErr != nil {
|
||||||
|
cool.Logger.Warning(ctx, "load config_spt init json failed:", jErr)
|
||||||
|
} else {
|
||||||
|
_, err = g.DB("default").Model(sptModel.TableName()).Data(jsonData.Var()).Insert()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
cool.Logger.Warning(ctx, "insert default config_spt failed:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
menuCount, err := g.DB("default").Model("base_sys_menu").Where("router", "/config/spt").Count()
|
||||||
|
if err != nil {
|
||||||
|
cool.Logger.Warning(ctx, "count SPT menu failed:", err)
|
||||||
|
} else if menuCount == 0 {
|
||||||
|
_, err = g.DB("default").Model("base_sys_menu").Data(g.Map{
|
||||||
|
"parentId": 2,
|
||||||
|
"name": "SPT配置",
|
||||||
|
"router": "/config/spt",
|
||||||
|
"viewPath": "config/views/spt.vue",
|
||||||
|
"icon": "icon-menu",
|
||||||
|
"ordernum": 70,
|
||||||
|
"keepAlive": true,
|
||||||
|
"isShow": true,
|
||||||
|
"type": 1,
|
||||||
|
}).Insert()
|
||||||
|
if err != nil {
|
||||||
|
cool.Logger.Warning(ctx, "insert SPT menu failed:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cool.Logger.Debug(ctx, "module config init finished ...")
|
||||||
|
}
|
||||||
|
|||||||
20
modules/config/controller/admin/collect_plan.go
Normal file
20
modules/config/controller/admin/collect_plan.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/cool"
|
||||||
|
"blazing/modules/config/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CollectPlanController struct {
|
||||||
|
*cool.Controller
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cool.RegisterController(&CollectPlanController{
|
||||||
|
&cool.Controller{
|
||||||
|
Prefix: "/admin/config/collectPlan",
|
||||||
|
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
|
||||||
|
Service: service.NewCollectPlanService(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
33
modules/config/controller/admin/spt.go
Normal file
33
modules/config/controller/admin/spt.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/cool"
|
||||||
|
"blazing/modules/config/model"
|
||||||
|
"blazing/modules/config/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SptController struct {
|
||||||
|
*cool.Controller
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// 仅为新加的 SPT 表做定点迁移,避免首次启用 EPS 时读取表结构报错。
|
||||||
|
db, err := cool.InitDB("default")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err = db.AutoMigrate(model.NewSptConfig()); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err = db.Exec("ALTER TABLE config_spt DROP COLUMN IF EXISTS seat_id").Error; err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cool.RegisterController(&SptController{
|
||||||
|
&cool.Controller{
|
||||||
|
Prefix: "/admin/config/spt",
|
||||||
|
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
|
||||||
|
Service: service.NewSptService(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -28,7 +28,7 @@ type PetBaseConfig struct {
|
|||||||
Nature int32 `gorm:"not null;default:0;comment:'BOSS属性-性格'" json:"nature"`
|
Nature int32 `gorm:"not null;default:0;comment:'BOSS属性-性格'" json:"nature"`
|
||||||
Effect []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS特性'" json:"effect"`
|
Effect []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'BOSS特性'" json:"effect"`
|
||||||
Lv int32 `gorm:"not null;comment:'BOSS等级(LvHpMatchUser非0时此配置无效)'" json:"lv"`
|
Lv int32 `gorm:"not null;comment:'BOSS等级(LvHpMatchUser非0时此配置无效)'" json:"lv"`
|
||||||
Color string `gorm:"comment:'BOSS颜色'" json:"color"`
|
ColorID uint32 `gorm:"not null;default:0;comment:'BOSS颜色配置ID'" json:"color_id"`
|
||||||
Skin int32 `gorm:"not null;default:0;comment:'BOSS皮肤ID'" json:"skin"`
|
Skin int32 `gorm:"not null;default:0;comment:'BOSS皮肤ID'" json:"skin"`
|
||||||
Hp int32 `gorm:"comment:'BOSS血量值(LvHpMatchUser非0时此配置无效)'" json:"hp"`
|
Hp int32 `gorm:"comment:'BOSS血量值(LvHpMatchUser非0时此配置无效)'" json:"hp"`
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/dop251/goja"
|
"github.com/dop251/goja"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -157,6 +160,27 @@ func bindBossScriptFunctions(vm *goja.Runtime, hookAction any) {
|
|||||||
ctx.SwitchPetFn(uint32(catchTime))
|
ctx.SwitchPetFn(uint32(catchTime))
|
||||||
return goja.Undefined()
|
return goja.Undefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
_ = vm.Set("debug", func(call goja.FunctionCall) goja.Value {
|
||||||
|
logCtx := context.Background()
|
||||||
|
if len(call.Arguments) == 0 {
|
||||||
|
g.Log().Debugf(logCtx, "[boss-script] debug() called with no arguments")
|
||||||
|
return goja.Undefined()
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := make([]string, 0, len(call.Arguments))
|
||||||
|
for _, arg := range call.Arguments {
|
||||||
|
exported := arg.Export()
|
||||||
|
if bytes, err := json.Marshal(exported); err == nil {
|
||||||
|
parts = append(parts, string(bytes))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
parts = append(parts, arg.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
g.Log().Debugf(logCtx, "[boss-script] %s", strings.Join(parts, " "))
|
||||||
|
return goja.Undefined()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultHookActionResult(hookAction any) bool {
|
func defaultHookActionResult(hookAction any) bool {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type CDKConfig struct {
|
|||||||
|
|
||||||
// 核心字段
|
// 核心字段
|
||||||
CDKCode string `gorm:"not null;size:16;uniqueIndex;comment:'CDK编号(唯一标识,用于玩家兑换)'" json:"cdk_code" description:"CDK编号"`
|
CDKCode string `gorm:"not null;size:16;uniqueIndex;comment:'CDK编号(唯一标识,用于玩家兑换)'" json:"cdk_code" description:"CDK编号"`
|
||||||
CDKType uint32 `gorm:"column:type;not null;default:0;comment:'CDK类型:0普通奖励,1服务器冠名'" json:"type" description:"CDK类型"`
|
Type uint32 `gorm:"column:type;not null;default:0;comment:'CDK类型:0普通奖励,1服务器冠名'" json:"type" description:"CDK类型"`
|
||||||
|
|
||||||
//cdk可兑换次数,where不等于0
|
//cdk可兑换次数,where不等于0
|
||||||
ExchangeRemainCount int64 `gorm:"not null;default:1;comment:'CDK剩余可兑换次数(不能为0才允许兑换,支持查询where !=0)'" json:"exchange_remain_count" description:"剩余可兑换次数"`
|
ExchangeRemainCount int64 `gorm:"not null;default:1;comment:'CDK剩余可兑换次数(不能为0才允许兑换,支持查询where !=0)'" json:"exchange_remain_count" description:"剩余可兑换次数"`
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user