diff --git a/logic/controller/fight_boss.go b/logic/controller/fight_boss.go index 178505390..64ddbc273 100644 --- a/logic/controller/fight_boss.go +++ b/logic/controller/fight_boss.go @@ -201,10 +201,11 @@ func (h Controller) OnPlayerFightNpcMonster(data1 *fight.FightNpcMonsterInboundI EXP: exp * 2, } if refPet.Item != 0 { - p.ItemAdd(refPet.Item, uint32(grand.Intn(2)+1)) + count := uint32(grand.Intn(2) + 1) + p.ItemAdd(refPet.Item, count) items.ItemList = append(items.ItemList, data.ItemInfo{ ItemId: refPet.Item, - ItemCnt: uint32(grand.Intn(2) + 1), + ItemCnt: count, }) } diff --git a/logic/main.go b/logic/main.go index 34ea9d602..3bd8e3d2b 100644 --- a/logic/main.go +++ b/logic/main.go @@ -94,8 +94,8 @@ func main() { } const ( - memThresholdRatio = 0.9 // 内存占用阈值70% - checkInterval = 3 * time.Second // 内存检测间隔,可按需调整 + memThresholdRatio = 0.9 // 内存占用阈值70% + checkInterval = 10 * time.Second // 内存检测间隔,可按需调整 ) // 监控内存,超阈值则优雅退出程序 diff --git a/logic/service/fight/boss/NewSeIdx_27.go b/logic/service/fight/boss/NewSeIdx_27.go index f9666ae13..1e6327c51 100644 --- a/logic/service/fight/boss/NewSeIdx_27.go +++ b/logic/service/fight/boss/NewSeIdx_27.go @@ -35,7 +35,7 @@ func (e *NewSel27) DamageDivEx(t *info.DamageZone) bool { return true } - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero return true } diff --git a/logic/service/fight/boss/NewSeIdx_36.go b/logic/service/fight/boss/NewSeIdx_36.go index 5dcbcb5a2..5f73811e7 100644 --- a/logic/service/fight/boss/NewSeIdx_36.go +++ b/logic/service/fight/boss/NewSeIdx_36.go @@ -45,7 +45,7 @@ func (e *NewSel36) DamageDivEx(t *info.DamageZone) bool { if int(e.Args()[e.index].IntPart()) != e.Ctx().SkillEntity.Type { - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero } return true diff --git a/logic/service/fight/boss/NewSeIdx_39.go b/logic/service/fight/boss/NewSeIdx_39.go index 6fe75e642..e16bdde3b 100644 --- a/logic/service/fight/boss/NewSeIdx_39.go +++ b/logic/service/fight/boss/NewSeIdx_39.go @@ -31,6 +31,9 @@ func (e *NewSel39) Skill_Use_ex() bool { if e.ID().GetCatchTime() != e.Ctx().Our.CurrentPet.Info.CatchTime { return true } + if e.Ctx().Opp.SumDamage.IntPart() == 0 { + e.can = false + } if e.Ctx().Opp.SumDamage.IntPart()%2 == 0 { e.can = true diff --git a/logic/service/fight/boss/NewSeIdx_406.go b/logic/service/fight/boss/NewSeIdx_406.go index 5485283e2..3497094bd 100644 --- a/logic/service/fight/boss/NewSeIdx_406.go +++ b/logic/service/fight/boss/NewSeIdx_406.go @@ -22,7 +22,7 @@ func (e *NewSel406) DamageDivEx(t *info.DamageZone) bool { success, _, _ := e.Input.Player.Roll(int(e.Args()[0].IntPart()), 100) if success { // 完全阻挡这次攻击,设置伤害为0 - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero } return true } diff --git a/logic/service/fight/boss/NewSeIdx_48.go b/logic/service/fight/boss/NewSeIdx_48.go index 34e4da655..4c32bd0b8 100644 --- a/logic/service/fight/boss/NewSeIdx_48.go +++ b/logic/service/fight/boss/NewSeIdx_48.go @@ -27,10 +27,10 @@ func (e *NewSel48) DamageDivEx(t *info.DamageZone) bool { attackCategory := int(e.Args()[0].IntPart()) if e.Ctx().SkillEntity.Category() == info.Category.PHYSICAL && attackCategory == 1 { // 物理攻击无效 - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero } else if e.Ctx().SkillEntity.Category() == info.Category.SPECIAL && attackCategory == 3 { // 特殊攻击无效 - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero } return true diff --git a/logic/service/fight/boss/NewSeIdx_5.go b/logic/service/fight/boss/NewSeIdx_5.go index 790fb1b73..9952d3a3a 100644 --- a/logic/service/fight/boss/NewSeIdx_5.go +++ b/logic/service/fight/boss/NewSeIdx_5.go @@ -30,7 +30,7 @@ func (e *NewSel5) DamageLockEx(t *info.DamageZone) bool { return true } - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero return true } diff --git a/logic/service/fight/boss/NewSeIdx_52.go b/logic/service/fight/boss/NewSeIdx_52.go index c280a4008..3fecfb030 100644 --- a/logic/service/fight/boss/NewSeIdx_52.go +++ b/logic/service/fight/boss/NewSeIdx_52.go @@ -30,10 +30,10 @@ func (e *NewSel52) DamageDivEx(t *info.DamageZone) bool { // 检查攻击类型 if roundMod == 1 && e.Ctx().SkillEntity.Category() == info.Category.SPECIAL { // 第3n+1回合,免疫特殊攻击,伤害为0 - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero } else if roundMod == 2 && e.Ctx().SkillEntity.Category() == info.Category.PHYSICAL { // 第3n+2回合,免疫物理攻击,伤害为0 - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero } // 第3n+3回合免疫属性攻击(这里暂时没有明确的属性类型,可能需要更复杂的处理) diff --git a/logic/service/fight/boss/NewSeIdx_61.go b/logic/service/fight/boss/NewSeIdx_61.go index 06ebc1250..15648ae4b 100644 --- a/logic/service/fight/boss/NewSeIdx_61.go +++ b/logic/service/fight/boss/NewSeIdx_61.go @@ -28,7 +28,7 @@ func (e *NewSel61) DamageDivEx(t *info.DamageZone) bool { //fmt.Println("Effect46_o", t.Damage) if t.Type == info.DamageType.Red { - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero } diff --git a/logic/service/fight/effect/effect_131.go b/logic/service/fight/effect/effect_131.go index e73b9eb4f..e279325d8 100644 --- a/logic/service/fight/effect/effect_131.go +++ b/logic/service/fight/effect/effect_131.go @@ -36,7 +36,7 @@ func (e *Effect131) DamageLockEx(t *info.DamageZone) bool { // 注:需确保BattlePetEntity的Gender字段类型为int/int8,与xGender类型匹配 if int(e.Ctx().Opp.CurrentPet.Gender) == int(xGender) { // 将伤害置为0,实现当前回合伤害免疫 - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero } // 返回true表示允许后续流程继续(仅修改伤害值,不阻断流程) diff --git a/logic/service/fight/effect/effect_46.go b/logic/service/fight/effect/effect_46.go index dd30bad79..b51ede82d 100644 --- a/logic/service/fight/effect/effect_46.go +++ b/logic/service/fight/effect/effect_46.go @@ -28,7 +28,7 @@ func (e *Effect46) DamageDivEx(t *info.DamageZone) bool { //fmt.Println("Effect46_o", t.Damage) if t.Type == info.DamageType.Red { e.conut++ - t.Damage = alpacadecimal.NewFromInt(0) + t.Damage = alpacadecimal.Zero } if e.Args()[0].IntPart() == e.conut { diff --git a/logic/service/fight/effect/effect_status.go b/logic/service/fight/effect/effect_status.go index 6a2655372..e22f49c33 100644 --- a/logic/service/fight/effect/effect_status.go +++ b/logic/service/fight/effect/effect_status.go @@ -179,7 +179,7 @@ func (e *Weakened) DamageDivEx(t *info.DamageZone) bool { // 1. 定义衰弱等级对应的倍率表(索引对应等级,0级无倍率) // 索引0: 0%(未衰弱)、1:25%、2:50%、3:100%、4:250%、5:500% weakenedMultiples := []alpacadecimal.Decimal{ - alpacadecimal.NewFromInt(0), // 0级 + alpacadecimal.Zero, // 0级 alpacadecimal.NewFromFloat(0.25), // 1级(25%) alpacadecimal.NewFromFloat(0.5), // 2级(50%) alpacadecimal.NewFromFloat(1.0), // 3级(100%) diff --git a/logic/service/fight/info/BattleSkillEntity.go b/logic/service/fight/info/BattleSkillEntity.go index 31e2c40fc..58a2a3105 100644 --- a/logic/service/fight/info/BattleSkillEntity.go +++ b/logic/service/fight/info/BattleSkillEntity.go @@ -56,9 +56,9 @@ type SkillEntity struct { xmlres.Move Info *model.SkillInfo - // DamageValue decimal.Decimal // 伤害值 - Rand *rand.Rand - Pet *BattlePetEntity + DamageValue alpacadecimal.Decimal // 伤害值 + Rand *rand.Rand + Pet *BattlePetEntity //MaxValue func(ahp, bhp uint32) decimal.Decimal Crit uint32 AttackTime uint32 //记录技能实际是否命中,0表示未命中,1表示命中,2表示必中 diff --git a/logic/service/fight/input/ai.go b/logic/service/fight/input/ai.go new file mode 100644 index 000000000..7d72ec5c1 --- /dev/null +++ b/logic/service/fight/input/ai.go @@ -0,0 +1,87 @@ +package input + +func (our *Input) GetAction() { + + next := our.Exec(func(t Effect) bool { + + return t.HookAction() + }) + if !next { + return + } + // 获取己方当前宠物和对方当前宠物 + selfPet := our.FightC.GetCurrPET(our.Player) + //没血就切换精灵 + if selfPet.Info.Hp <= 0 { + for _, v := range our.AllPet { + if v.Info.Hp > 0 { + our.FightC.ChangePet(our.Player, v.Info.CatchTime) + return + } + } + // 如果没有可用宠物,则直接返回,不执行任何操作 + return + } + //oppPet := opp.FightC.GetCurrPET(opp.Player) + skills := selfPet.Skills + + // 空技能列表直接返回,避免错误 + if len(skills) == 0 { + return + } + var usedskill uint32 + for _, s := range skills { + if s == nil { + continue + } + if !s.CanUse() { + continue + } + // 计算技能对对方的伤害(假设CalculatePower返回伤害值,或需从技能中获取) + s.DamageValue = our.CalculatePower(our.Opp, s) + + // 判断是否能秒杀(伤害 >= 对方当前生命值) + if uint32(s.DamageValue.IntPart()) >= our.Opp.CurrentPet.Info.Hp { // 假设oppPet.HP为对方当前剩余生命值 + our.FightC.UseSkill(our.Player, uint32(s.ID)) + } + } + if usedskill == 0 { + + for _, s := range skills { + if s == nil { + continue + } + if !s.CanUse() { + continue + } + our.FightC.UseSkill(our.Player, uint32(s.ID)) + } + + } + our.FightC.UseSkill(our.Player, 0) + // // 若存在能秒杀的技能,优先使用(选伤害最高的,避免浪费高伤害技能) + // if len(killableSkills) > 0 { + // bestKillSkill := killableSkills[0].SkillEntity + // maxDamage := killableSkills[0].damage + // for _, ks := range killableSkills[1:] { + // if ks.damage.Cmp(maxDamage) > 0 { // 使用decimal的比较方法比较伤害值 + // if ks.CanUse() { + // maxDamage = ks.damage + // bestKillSkill = ks.SkillEntity + // } + + // } + // } + // our.FightC.UseSkill(our.Player, uint32(bestKillSkill.ID)) + // return + // } + // if len(allSkills) <= 0 { + // our.FightC.UseSkill(our.Player, 0) + // return + // } + + // 优化随机选择技能的逻辑,直接使用随机索引 + // randomIdx := grand.Intn(len(allSkills)) + // our.FightC.UseSkill(our.Player, uint32(allSkills[randomIdx].ID)) + +} diff --git a/logic/service/fight/input/effect.go b/logic/service/fight/input/effect.go index 61ef970f1..9dea19187 100644 --- a/logic/service/fight/input/effect.go +++ b/logic/service/fight/input/effect.go @@ -3,9 +3,6 @@ package input import ( "blazing/common/utils" "blazing/logic/service/fight/info" - "blazing/modules/player/model" - - "fmt" "github.com/alpacahq/alpacadecimal" "github.com/brunoga/deep" @@ -165,23 +162,17 @@ func IS_Stat(v Effect) bool { // -func (our *Input) GetCurrAttr(id int) model.PetInfo { - - //todo 获取前GetEffect - return our.CurrentPet.Info - - //todo 获取后GetEffect -} - // 比较两个[]int是否内容相等 func equalInts(a, b []alpacadecimal.Decimal) bool { // 先判断长度是否相等 + if len(a) != len(b) { return false } // 逐个比较元素 for i := range a { - if a[i].IntPart() != b[i].IntPart() { + + if a[i].Cmp(b[i]) != 0 { return false } } @@ -218,7 +209,7 @@ func (our *Input) AddEffect(in *Input, e Effect) Effect { if v.ID().Base == e.ID().Base && //找到相同的效果id v.Alive() && //如果之前的效果还存活 equalInts(v.Args(), e.Args()) { //如果层数可以叠加或者是无限层数 - fmt.Println("重复效果", e.ID().Suffix(), v.ID().Suffix()) + //fmt.Println("重复效果", e.ID().Suffix(), v.ID().Suffix()) if !v.CanStack() { //说明进行了替换 v.Alive(false) //不允许叠层,取消效果 diff --git a/logic/service/fight/input/fight.go b/logic/service/fight/input/fight.go index 35c3ee19d..ffb18e3a6 100644 --- a/logic/service/fight/input/fight.go +++ b/logic/service/fight/input/fight.go @@ -10,7 +10,6 @@ import ( "github.com/alpacahq/alpacadecimal" "github.com/gogf/gf/v2/util/gconv" - "github.com/gogf/gf/v2/util/grand" ) // 计算暴击 @@ -191,96 +190,6 @@ func (our *Input) Damage(in *Input, sub *info.DamageZone) { } -func (our *Input) GetAction() { - - next := our.Exec(func(t Effect) bool { - - return t.HookAction() - }) - if !next { - return - } - // 获取己方当前宠物和对方当前宠物 - selfPet := our.FightC.GetCurrPET(our.Player) - //没血就切换精灵 - if selfPet.Info.Hp <= 0 { - for _, v := range our.AllPet { - if v.Info.Hp > 0 { - our.FightC.ChangePet(our.Player, v.Info.CatchTime) - return - } - } - // 如果没有可用宠物,则直接返回,不执行任何操作 - return - } - //oppPet := opp.FightC.GetCurrPET(opp.Player) - skills := selfPet.Skills - - // 空技能列表直接返回,避免错误 - if len(skills) == 0 { - return - } - - // 步骤1:计算所有技能的伤害,并筛选出能秒杀对方的技能 - var killableSkills []struct { - *info.SkillEntity // 技能对象(假设原技能类型为skill) - damage alpacadecimal.Decimal // 技能实际伤害 - } - // 存储所有技能及伤害(用于后续筛选) - type skillWithDamage struct { - *info.SkillEntity - damage alpacadecimal.Decimal - } - allSkills := make([]skillWithDamage, 0, len(skills)) - - for _, s := range skills { - if s == nil { - continue - } - if !s.CanUse() { - continue - } - // 计算技能对对方的伤害(假设CalculatePower返回伤害值,或需从技能中获取) - damage := our.CalculatePower(our.Opp, s) - - allSkills = append(allSkills, skillWithDamage{SkillEntity: s, damage: damage}) - - // 判断是否能秒杀(伤害 >= 对方当前生命值) - if uint32(damage.IntPart()) >= our.Opp.CurrentPet.Info.Hp { // 假设oppPet.HP为对方当前剩余生命值 - killableSkills = append(killableSkills, struct { - *info.SkillEntity - damage alpacadecimal.Decimal - }{s, damage}) - } - } - - // 若存在能秒杀的技能,优先使用(选伤害最高的,避免浪费高伤害技能) - if len(killableSkills) > 0 { - bestKillSkill := killableSkills[0].SkillEntity - maxDamage := killableSkills[0].damage - for _, ks := range killableSkills[1:] { - if ks.damage.Cmp(maxDamage) > 0 { // 使用decimal的比较方法比较伤害值 - if ks.CanUse() { - maxDamage = ks.damage - bestKillSkill = ks.SkillEntity - } - - } - } - our.FightC.UseSkill(our.Player, uint32(bestKillSkill.ID)) - return - } - if len(allSkills) <= 0 { - our.FightC.UseSkill(our.Player, 0) - return - } - - // 优化随机选择技能的逻辑,直接使用随机索引 - randomIdx := grand.Intn(len(allSkills)) - our.FightC.UseSkill(our.Player, uint32(allSkills[randomIdx].ID)) - return -} - // 计算技能威力 func (our *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) alpacadecimal.Decimal { @@ -305,7 +214,7 @@ func (our *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) alpaca defenseDec = alpacadecimal.NewFromInt(int64(deftype.GetProp(3, false))) default: - return alpacadecimal.NewFromInt(0) + return alpacadecimal.Zero } // 5. 基础伤害公式:等级因子 * 威力因子 * 攻击 / 防御 / 50 + 2 diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go index 62900305b..42dbc7764 100644 --- a/logic/service/fight/input/input.go +++ b/logic/service/fight/input/input.go @@ -176,7 +176,7 @@ func (our *Input) ResetAttackValue() { our.AttackValue.IsCritical = 0 our.AttackValue.GainHp = 0 our.AttackValue.LostHp = 0 - our.SumDamage = alpacadecimal.NewFromInt(0) + our.SumDamage = alpacadecimal.Zero //our.CanUseSkill = true } diff --git a/logic/service/player/done.go b/logic/service/player/done.go index e2ee6e025..615793844 100644 --- a/logic/service/player/done.go +++ b/logic/service/player/done.go @@ -1,9 +1,5 @@ package player -import ( - "blazing/modules/player/model" -) - type Done struct { *Player //对玩家进行操作 // *bus.Topic[*model.MilestoneEX] @@ -45,29 +41,29 @@ func NewDone(P *Player) Done { // } -// 分发事件 ,指定事件+1 并触发是否完成 -func (d *Player) Exec(Donetype model.EnumMilestone, id []uint32, fn func(*model.MilestoneEX) uint32) { +// // 分发事件 ,指定事件+1 并触发是否完成 +// func (d *Player) Exec(Donetype model.EnumMilestone, id []uint32, fn func(*model.MilestoneEX) uint32) { - d.Service.Done.Exec(Donetype, id, func(t *model.MilestoneEX) bool { - //这里给予即时奖励,并将用户计数+1 - t.Count++ - //然后有需要自动发送奖励地方,发送完奖励给置真 +// d.Service.Done.Exec(Donetype, id, func(t *model.MilestoneEX) bool { +// //这里给予即时奖励,并将用户计数+1 +// t.Count++ +// //然后有需要自动发送奖励地方,发送完奖励给置真 - if fn != nil { - t1 := fn(t) - if t1 != 0 { - t.Results = append(t.Results, t1) //把本次的记录添加 - } - } +// if fn != nil { +// t1 := fn(t) +// if t1 != 0 { +// t.Results = append(t.Results, t1) //把本次的记录添加 +// } +// } - // d.Topic.Pub(t) //异步发送,然后给事件+1 +// // d.Topic.Pub(t) //异步发送,然后给事件+1 - // d.Topic.PubAsyncCallBack(s, func() { //如果没执行完,说明奖励没发完,直接掉线 - // d.Service.Done.Exec(s) //给计数器加1 - // }) //提交触发里程碑奖励 - return true - }) //给计数器加1 -} +// // d.Topic.PubAsyncCallBack(s, func() { //如果没执行完,说明奖励没发完,直接掉线 +// // d.Service.Done.Exec(s) //给计数器加1 +// // }) //提交触发里程碑奖励 +// return true +// }) //给计数器加1 +// } // IsPrefixBasicSlice 判断切片 B 是否是切片 A 的前缀 // 泛型约束支持 int | string | bool | uint32 类型的切片 diff --git a/logic/service/player/player.go b/logic/service/player/player.go index c82191e55..62a1f5444 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -2,7 +2,6 @@ package player import ( "blazing/common/data" - "blazing/common/data/xmlres" "blazing/common/socket/errorcode" "blazing/common/utils" "blazing/cool" @@ -14,6 +13,7 @@ import ( "blazing/modules/base/service" config "blazing/modules/config/service" + dictrvice "blazing/modules/dict/service" blservice "blazing/modules/player/service" "context" @@ -193,8 +193,8 @@ func (p *Player) ItemAdd(ItemId, ItemCnt uint32) (result bool) { p.Info.EVPool = p.Info.EVPool + ItemCnt default: - itemx, ok := xmlres.ItemsMAP[int(ItemId)] - if !ok { + itemmax := dictrvice.NewDictInfoService().GetMax(ItemId) + if itemmax == 0 { cool.Logger.Error(context.TODO(), "物品不存在", ItemId) t1 := common.NewTomeeHeader(2601, p.Info.UserID) @@ -204,11 +204,8 @@ func (p *Player) ItemAdd(ItemId, ItemCnt uint32) (result bool) { return false } - if itemx.Max == 0 { - itemx.Max = 1 - } - if p.Service.Item.CheakItem(ItemId)+ItemCnt > uint32(itemx.Max) { + if p.Service.Item.CheakItem(ItemId)+ItemCnt > uint32(itemmax) { println(p.Info.UserID, "物品超过拥有最大限制", ItemId) t1 := common.NewTomeeHeader(2601, p.Info.UserID) diff --git a/modules/config/service/pet_fusion_material_service.go b/modules/config/service/pet_fusion_material_service.go index 6422cb6a7..0d14b9e80 100644 --- a/modules/config/service/pet_fusion_material_service.go +++ b/modules/config/service/pet_fusion_material_service.go @@ -33,7 +33,7 @@ func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 { cacheKey := strings.Join(gconv.Strings(Material1[:]), ":") println(cacheKey, "获取融合id") - fusions := service.DictInfoServiceS.GetData("fusion") + fusions := service.NewDictInfoService().GetData("fusion") for _, v := range Material1 { // if v < 10000 { @@ -57,12 +57,12 @@ func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 { "material4": Material1[3], "is_enable": 1, } - m.Where(condition) .Scan(&effect) + m.Where(condition).Scan(&effect) //这时候有可能效果是空的,那么这时候就再次查询默认的特性,保证每次必会生成一个数据库有的特性 //也许这个时候的特性配方就是随机从数据库中查找一个特性 if effect == nil { - effect2s := service.DictInfoServiceS.GetData("effect") + effect2s := service.NewDictInfoService().GetData("effect") for _, v := range effect2s { return gconv.Uint32(v.Value) } diff --git a/modules/dict/controller/admin/dict_info.go b/modules/dict/controller/admin/dict_info.go index 593c30bef..355cb9f23 100644 --- a/modules/dict/controller/admin/dict_info.go +++ b/modules/dict/controller/admin/dict_info.go @@ -19,7 +19,7 @@ func init() { &cool.Controller{ Prefix: "/admin/dict/info", Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"}, - Service: service.DictInfoServiceS, + Service: service.NewDictInfoService(), }, } // 注册路由 @@ -34,7 +34,7 @@ type DictInfoDataReq struct { // Data 方法 获得字典数据 func (c *DictInfoController) Data(ctx context.Context, req *DictInfoDataReq) (res *cool.BaseRes, err error) { - service := service.DictInfoServiceS + service := service.NewDictInfoService() data, err := service.Data(ctx, req.Types) res = cool.Ok(data) return diff --git a/modules/dict/model/dict_info.go b/modules/dict/model/dict_info.go index f6e796935..f0da8f43b 100644 --- a/modules/dict/model/dict_info.go +++ b/modules/dict/model/dict_info.go @@ -11,7 +11,7 @@ type DictInfo struct { *cool.Model TypeID int32 `gorm:"column:typeId;type:int;not null" json:"typeId"` // 类型ID Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 名称 - ordernum int32 `gorm:"column:ordernum;type:int;not null" json:"ordernum"` // 排序 + Ordernum int32 `gorm:"column:ordernum;type:int;not null" json:"ordernum"` // 排序 Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注 Value int32 `gorm:"column:value;type:int;not null" json:"value"` ParentID *int32 `gorm:"column:parentId;type:int" json:"parentId"` // 父ID diff --git a/modules/dict/service/dict_info.go b/modules/dict/service/dict_info.go index d985c1d0b..a4cb20005 100644 --- a/modules/dict/service/dict_info.go +++ b/modules/dict/service/dict_info.go @@ -87,11 +87,27 @@ func (s *DictInfoService) GetData(types string) (data map[uint32]model.DictInfo) }) return fusions +} +func (s *DictInfoService) GetMax(value uint32) (max uint32) { + + m := cool.DBM(s.Model) + var ress *model.DictInfo + m.Where("value", value).Cache(gdb.CacheOption{ + // Duration: time.Hour, + + Force: false, + }).Scan(&ress) + if ress == nil { + return 0 + } + + return uint32(ress.Ordernum) + } // ModifyAfter 修改后 func (s *DictInfoService) ModifyAfter(ctx context.Context, method string, param map[string]interface{}) (err error) { - + defer s.Service.ModifyAfter(ctx, method, param) if method == "Delete" { // 删除后,同时删除子节点 ids, ok := param["ids"] @@ -128,8 +144,6 @@ func delChildDict(id int64) error { return err } -var DictInfoServiceS = NewDictInfoService() - // NewDictInfoService 初始化 DictInfoService func NewDictInfoService() *DictInfoService { return &DictInfoService{ diff --git a/modules/player/model/done.go b/modules/player/model/done.go index 59053ba81..cfbd219a9 100644 --- a/modules/player/model/done.go +++ b/modules/player/model/done.go @@ -3,19 +3,34 @@ package model import ( "blazing/cool" - "github.com/samber/lo" "github.com/tnnmigga/enum" ) +var MilestoneEnum = enum.New[struct { + CollectElfCount EnumMilestone `enum:"3515"` // 收集精灵数量 + DailyTaskCount EnumMilestone `enum:"3510"` // 日常任务次数 + MaxLevelCount EnumMilestone `enum:"3511"` // 满级数量 + SingleAttrCount EnumMilestone `enum:"3512"` // 单属性数量 + DoubleAttrCount EnumMilestone `enum:"3513"` // 双属性数量 + Arena EnumMilestone `enum:"3508"` // 擂台 + Brawl EnumMilestone `enum:"3504"` // 乱斗 + ElfKing EnumMilestone `enum:"3503"` // 精灵王 + BaseVisit EnumMilestone `enum:"3506"` // 基地拜访 + BaseVisitedCount EnumMilestone `enum:"3520"` // 基地被拜访次数 + WinSPTType EnumMilestone `enum:"3521"` // 战胜spt种类 + CollectElfType EnumMilestone `enum:"3522"` // 收集精灵种类 + DefeatWildElfCount EnumMilestone `enum:"3523"` // 击败野生精灵次数 +}]() + type EnumMilestone int -var MilestoneMode = enum.New[struct { - BOSS EnumMilestone //boss类 地图ID->BOSSID ,胜利次数 mapid bossid petid,防止换boss后数据不可用 - ITEM EnumMilestone //物品类 物品ID 使用精灵 - Fight EnumMilestone //挑战类 对战模式->对战类型->1是赢,0是总局数 - Moster EnumMilestone //野怪统计 地图ID->怪物ID - Task EnumMilestone -}]() +// var MilestoneMode = enum.New[struct { +// BOSS EnumMilestone //boss类 地图ID->BOSSID ,胜利次数 mapid bossid petid,防止换boss后数据不可用 +// ITEM EnumMilestone //物品类 物品ID 使用精灵 +// Fight EnumMilestone //挑战类 对战模式->对战类型->1是赢,0是总局数 +// Moster EnumMilestone //野怪统计 地图ID->怪物ID +// Task EnumMilestone +// }]() const TableNameMilestone = "player_milestone" @@ -30,31 +45,31 @@ type Milestone struct { Count uint32 `gorm:"not null;comment:'里程碑完成次数'" json:"count"` } -// MilestoneEX 里程碑扩展结构体,用于业务层解析后的数据操作 -type MilestoneEX struct { - Milestone - Args []uint32 // 解析后的里程碑详细数据 - Results []uint32 `json:"results"` // 解析后的里程碑详细数据 -} +// // MilestoneEX 里程碑扩展结构体,用于业务层解析后的数据操作 +// type MilestoneEX struct { +// Milestone +// Args []uint32 // 解析后的里程碑详细数据 +// Results []uint32 `json:"results"` // 解析后的里程碑详细数据 +// } -// 检查是否触发过,成功返回触发的次数,失败返回0 -func (m *MilestoneEX) CheakNoNumber(count uint32) bool { - // if v.DoneType == model.MilestoneMode.BOSS && IsPrefixBasicSlice(v.Args, []uint32{mapid, bossid}) && v.Count == count { +// // 检查是否触发过,成功返回触发的次数,失败返回0 +// func (m *MilestoneEX) CheakNoNumber(count uint32) bool { +// // if v.DoneType == model.MilestoneMode.BOSS && IsPrefixBasicSlice(v.Args, []uint32{mapid, bossid}) && v.Count == count { - _, ok := lo.Find(m.Results, func(v1 uint32) bool { //寻找是否触发过 - //大于触发值就触发,然后1的返回false,因为没有奖励,这样就可以一直触发 - return v1 == count //大于等于就触发 - }) - //没找到且次数满足才能返回真 - if !ok && m.Count >= count { - return true - } +// _, ok := lo.Find(m.Results, func(v1 uint32) bool { //寻找是否触发过 +// //大于触发值就触发,然后1的返回false,因为没有奖励,这样就可以一直触发 +// return v1 == count //大于等于就触发 +// }) +// //没找到且次数满足才能返回真 +// if !ok && m.Count >= count { +// return true +// } - //已经触发过 - return false +// //已经触发过 +// return false - // } -} +// // } +// } // TableName 返回表名 func (*Milestone) TableName() string { diff --git a/modules/player/service/done.go b/modules/player/service/done.go index 23c8fe48e..1ef4dafcc 100644 --- a/modules/player/service/done.go +++ b/modules/player/service/done.go @@ -3,49 +3,45 @@ package service import ( "blazing/cool" "blazing/modules/player/model" - "context" - "strings" - - "github.com/gogf/gf/v2/util/gconv" ) type DoneService struct { BaseService } -func (s *DoneService) Exec(data model.EnumMilestone, id []uint32, fn func(*model.MilestoneEX) bool) { - if cool.Config.ServerInfo.IsVip != 0 { - cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid) - return - } - arss := strings.Join(gconv.Strings(id), "-") - m := s.PModel(s.Model).Where("done_type", data).Where("args", arss) - var tt *model.MilestoneEX - m.Scan(&tt) - if tt == nil { - tt = &model.MilestoneEX{ - Milestone: model.Milestone{ - DoneType: data, - Args: strings.Join(gconv.Strings(id), "-"), - //Count: 1, - }, - } - } +// func (s *DoneService) Exec(data model.EnumMilestone, id []uint32, fn func(*model.MilestoneEX) bool) { +// if cool.Config.ServerInfo.IsVip != 0 { +// cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid) +// return +// } +// arss := strings.Join(gconv.Strings(id), "-") +// m := s.PModel(s.Model).Where("done_type", data).Where("args", arss) +// var tt *model.MilestoneEX +// m.Scan(&tt) +// if tt == nil { +// tt = &model.MilestoneEX{ +// Milestone: model.Milestone{ +// DoneType: data, +// Args: strings.Join(gconv.Strings(id), "-"), +// //Count: 1, +// }, +// } +// } - tt.Args = id - ook := fn(tt) - if !ook { //不需要保存 - return - } - tt.PlayerID = uint64(s.userid) - tt.Milestone.Args = strings.Join(gconv.Strings(id), "-") +// tt.Args = id +// ook := fn(tt) +// if !ook { //不需要保存 +// return +// } +// tt.PlayerID = uint64(s.userid) +// tt.Milestone.Args = strings.Join(gconv.Strings(id), "-") - _, err := m.Save(tt) - if err != nil { - panic(err) - } +// _, err := m.Save(tt) +// if err != nil { +// panic(err) +// } -} +// } func NewDoneService(id uint32) *DoneService { return &DoneService{