diff --git a/logic/controller/fight_boss野怪和地图怪.go b/logic/controller/fight_boss野怪和地图怪.go index 13018db00..0cec2ac57 100644 --- a/logic/controller/fight_boss野怪和地图怪.go +++ b/logic/controller/fight_boss野怪和地图怪.go @@ -8,6 +8,7 @@ import ( "blazing/logic/service/fight" "blazing/logic/service/fight/info" + "blazing/logic/service/fight/input" "blazing/logic/service/player" configmodel "blazing/modules/config/model" @@ -97,12 +98,34 @@ func (Controller) PlayerFightBoss(data1 *fight.ChallengeBossInboundInfo, p *play } ai.Prop[0] = 2 - fight.NewFight(p, ai, func(foi model.FightOverInfo) { + var fighc *fight.FightC + fighc, _ = fight.NewFight(p, ai, func(foi model.FightOverInfo) { if mdata.WinBonusID != 0 { - if foi.Reason == 0 && foi.WinnerId == p.Info.UserID { - p.SptCompletedTask(mdata.WinBonusID, 1) + if len(mdata.Rule) == 0 { + if foi.Reason == 0 && foi.WinnerId == p.Info.UserID { + p.SptCompletedTask(mdata.WinBonusID, 1) + } + } else { + //说明是带规则的 + iswin := true + for _, v := range service.NewFightRuleService().GetByRuleIdxs(mdata.Rule) { + r := input.GetRule(int64(v.RuleIdx)) + if r != nil { + r.SetArgs(v.Args...) + + if !(r.Exec(fighc, &foi)) { + iswin = false + break + } + } + + } + if iswin { + p.SptCompletedTask(mdata.WinBonusID, 1) + } } + } //p.Done.Exec(model.MilestoneMode.BOSS, []uint32{p.Info.MapID, data.BossId, uint32(foi.Reason)}, nil) diff --git a/logic/service/fight/input/rule.go b/logic/service/fight/input/rule.go index feeedd43f..57d3f696a 100644 --- a/logic/service/fight/input/rule.go +++ b/logic/service/fight/input/rule.go @@ -6,3 +6,7 @@ func InitRule(id int64, t RuleI) { RuleM[id] = t } +func GetRule(id int64) RuleI { + + return RuleM[id] +} diff --git a/modules/config/controller/admin/fight_rule.go b/modules/config/controller/admin/fight_rule.go new file mode 100644 index 000000000..baa015622 --- /dev/null +++ b/modules/config/controller/admin/fight_rule.go @@ -0,0 +1,22 @@ +package admin + +import ( + "blazing/cool" + "blazing/modules/config/service" +) + +// FightRuleController 战胜规则Admin控制器 +type FightRuleController struct { + *cool.Controller +} + +func init() { + var fightRuleController = &FightRuleController{ + &cool.Controller{ + Prefix: "/admin/config/fightRule", + Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"}, + Service: service.NewFightRuleService(), + }, + } + cool.RegisterController(fightRuleController) +} diff --git a/modules/config/model/fight_rule.go b/modules/config/model/fight_rule.go new file mode 100644 index 000000000..4f73ded43 --- /dev/null +++ b/modules/config/model/fight_rule.go @@ -0,0 +1,39 @@ +package model + +import ( + "blazing/cool" +) + +// 表名常量 +const TableNameFightRule = "config_fight_rule" + +// FightRule 战胜规则配置表 +// 对应 rule 包中 Rule300-Rule316 的配置参数 +type FightRule struct { + *cool.Model // 嵌入基础Model(包含主键、创建/更新时间等通用字段) + + RuleIdx uint32 `gorm:"not null;uniqueIndex:idx_rule_idx;comment:'规则索引(300-316)'" json:"rule_idx"` + Args []int `gorm:"type:jsonb;comment:'规则参数(JSON数组,对应RuleBase.args)'" json:"args"` + Desc string `gorm:"type:varchar(255);default:'';comment:'规则描述'" json:"desc"` +} + +// TableName 指定表名 +func (*FightRule) TableName() string { + return TableNameFightRule +} + +// GroupName 指定表分组 +func (*FightRule) GroupName() string { + return "default" +} + +// NewFightRule 创建战胜规则表实例 +func NewFightRule() *FightRule { + return &FightRule{ + Model: cool.NewModel(), + } +} + +func init() { + cool.CreateTable(&FightRule{}) +} diff --git a/modules/config/model/map_node.go b/modules/config/model/map_node.go index 71fc20949..6b395bab7 100644 --- a/modules/config/model/map_node.go +++ b/modules/config/model/map_node.go @@ -53,7 +53,7 @@ type MapNode struct { //完成后的脚本回调,比如战胜和击败绑定不同的任务ID,以及剧情绑定不同的ID //回调通boss打完给前端发送固定事件 //PlotFinishScript string `gorm:"type:text;comment:'剧情完成后脚本回调'" json:"plot_finish_script" description:"剧情完成后脚本回调"` - + Rule []uint32 `gorm:"type:jsonb; ;comment:'战胜规则'" json:"rule"` BossIds []uint32 `gorm:"type:jsonb; ;comment:'塔层BOSS ID列表'" json:"boss_ids"` } diff --git a/modules/config/service/fight_rule_service.go b/modules/config/service/fight_rule_service.go new file mode 100644 index 000000000..38d861ada --- /dev/null +++ b/modules/config/service/fight_rule_service.go @@ -0,0 +1,41 @@ +package service + +import ( + "blazing/cool" + "blazing/modules/config/model" +) + +type FightRuleService struct { + *cool.Service +} + +// GetByRuleIdx 根据规则索引查询规则配置 +func (s *FightRuleService) GetByRuleIdx(ruleIdx uint32) *model.FightRule { + var rule *model.FightRule + dbm_notenable(s.Model).Where("rule_idx", ruleIdx).Scan(&rule) + return rule +} + +// GetByRuleIdxs 根据规则索引批量查询规则配置 +func (s *FightRuleService) GetByRuleIdxs(ruleIdxs []uint32) []model.FightRule { + var rules []model.FightRule + dbm_notenable(s.Model).WhereIn("rule_idx", ruleIdxs).Scan(&rules) + return rules +} + +func NewFightRuleService() *FightRuleService { + return &FightRuleService{ + &cool.Service{ + Model: model.NewFightRule(), + UniqueKey: map[string]string{"idx_rule_idx": "规则索引不能重复"}, + PageQueryOp: &cool.QueryOp{ + KeyWordField: []string{"desc"}, + FieldEQ: []string{"rule_idx"}, + }, + ListQueryOp: &cool.QueryOp{ + KeyWordField: []string{"desc"}, + FieldEQ: []string{"rule_idx"}, + }, + }, + } +}