refactor: 重构战斗属性和特效应用逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -44,7 +44,7 @@ func (Controller) PlayerFightBoss(req *ChallengeBossInboundInfo, p *player.Playe
|
|||||||
ai := player.NewAI_player(monsterInfo)
|
ai := player.NewAI_player(monsterInfo)
|
||||||
ai.CanCapture = resolveBossCaptureRate(bossConfigs[0].IsCapture, leadMonsterID)
|
ai.CanCapture = resolveBossCaptureRate(bossConfigs[0].IsCapture, leadMonsterID)
|
||||||
ai.BossScript = bossConfigs[0].Script
|
ai.BossScript = bossConfigs[0].Script
|
||||||
ai.Prop[0] = 2
|
ai.AddBattleProp(0, 2)
|
||||||
|
|
||||||
var fightC *fight.FightC
|
var fightC *fight.FightC
|
||||||
fightC, err = fight.NewFight(p, ai, p.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
fightC, err = fight.NewFight(p, ai, p.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
||||||
|
|||||||
@@ -41,6 +41,35 @@ func (t *BattlePetEntity) Alive() bool {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *BattlePetEntity) AddBattleAttr(attr int, value uint32) {
|
||||||
|
if t == nil || value == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch attr {
|
||||||
|
case 0:
|
||||||
|
t.Info.MaxHp += value
|
||||||
|
t.Info.Hp += value
|
||||||
|
case 1, 2, 3, 4, 5:
|
||||||
|
t.Info.Prop[attr-1] += value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *BattlePetEntity) ApplyInitEffectBonus(effect model.PetEffectInfo) {
|
||||||
|
if t == nil || effect.EID != 26 || len(effect.Args) < 2 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i+1 < len(effect.Args); i += 2 {
|
||||||
|
attr := effect.Args[i]
|
||||||
|
value := effect.Args[i+1]
|
||||||
|
if value <= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
t.AddBattleAttr(attr, uint32(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 创建精灵实例
|
// 创建精灵实例
|
||||||
func CreateBattlePetEntity(info model.PetInfo) *BattlePetEntity {
|
func CreateBattlePetEntity(info model.PetInfo) *BattlePetEntity {
|
||||||
ret := &BattlePetEntity{}
|
ret := &BattlePetEntity{}
|
||||||
|
|||||||
@@ -145,28 +145,6 @@ func (our *Input) SetCurPetAt(index int, pet *info.BattlePetEntity) {
|
|||||||
our.CurPet[index] = pet
|
our.CurPet[index] = pet
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyInitPetEffectBonus(pet *info.BattlePetEntity, effect model.PetEffectInfo) {
|
|
||||||
if pet == nil || effect.EID != 26 || len(effect.Args) < 2 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i+1 < len(effect.Args); i += 2 {
|
|
||||||
attr := effect.Args[i]
|
|
||||||
value := effect.Args[i+1]
|
|
||||||
if value <= 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
switch attr {
|
|
||||||
case 0:
|
|
||||||
pet.Info.MaxHp += uint32(value)
|
|
||||||
pet.Info.Hp += uint32(value)
|
|
||||||
case 1, 2, 3, 4, 5:
|
|
||||||
pet.Info.Prop[attr-1] += uint32(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 非原地交换:收集非0血量精灵 + 0血量精灵,拼接后返回
|
// 非原地交换:收集非0血量精灵 + 0血量精灵,拼接后返回
|
||||||
func (our *Input) SortPet() {
|
func (our *Input) SortPet() {
|
||||||
var nonZeroHP []*info.BattlePetEntity // 收集血量>0的精灵(保持原顺序)
|
var nonZeroHP []*info.BattlePetEntity // 收集血量>0的精灵(保持原顺序)
|
||||||
@@ -189,7 +167,7 @@ func (our *Input) SortPet() {
|
|||||||
|
|
||||||
t.Duration(-1)
|
t.Duration(-1)
|
||||||
|
|
||||||
applyInitPetEffectBonus(s, e1)
|
s.ApplyInitEffectBonus(e1)
|
||||||
our.AddEffect(our, t)
|
our.AddEffect(our, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ func buildFight(opts *fightBuildOptions) (*FightC, errorcode.ErrorCode) {
|
|||||||
if ai.CanCapture > 0 {
|
if ai.CanCapture > 0 {
|
||||||
opp.CanCapture = ai.CanCapture
|
opp.CanCapture = ai.CanCapture
|
||||||
}
|
}
|
||||||
opp.AttackValue.Prop = ai.Prop
|
ai.ApplyBattleProps(opp.AttackValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import (
|
|||||||
|
|
||||||
type PetItemHandler func(itemid uint32, ctx *model.PetInfo) bool
|
type PetItemHandler func(itemid uint32, ctx *model.PetInfo) bool
|
||||||
|
|
||||||
const maxHPUpEffectIdx uint16 = 60000
|
|
||||||
|
|
||||||
// RangeHandler 范围ID处理器(用于ID区间匹配)
|
// RangeHandler 范围ID处理器(用于ID区间匹配)
|
||||||
type RangeHandler struct {
|
type RangeHandler struct {
|
||||||
Start uint32
|
Start uint32
|
||||||
@@ -121,19 +119,9 @@ func handleNewSeIdxPetItem(itemid uint32, onpet *model.PetInfo) errorcode.ErrorC
|
|||||||
}
|
}
|
||||||
if itemCfg.NewSeIdx == 0 {
|
if itemCfg.NewSeIdx == 0 {
|
||||||
if itemCfg.MaxHPUp > 0 {
|
if itemCfg.MaxHPUp > 0 {
|
||||||
for _, eff := range onpet.EffectInfo {
|
if !onpet.AddMaxHPUpEffect(itemid, itemCfg.MaxHPUp) {
|
||||||
if eff.Status == 8 {
|
return errorcode.ErrorCodes.ErrCannotInjectPillAgain
|
||||||
return errorcode.ErrorCodes.ErrCannotInjectPillAgain
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onpet.EffectInfo = append(onpet.EffectInfo, model.PetEffectInfo{
|
|
||||||
ItemID: itemid,
|
|
||||||
Idx: maxHPUpEffectIdx,
|
|
||||||
Status: 8,
|
|
||||||
EID: 26,
|
|
||||||
Args: []int{0, itemCfg.MaxHPUp},
|
|
||||||
})
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return errorcode.ErrorCodes.ErrItemUnusable
|
return errorcode.ErrorCodes.ErrItemUnusable
|
||||||
|
|||||||
@@ -44,6 +44,27 @@ func (p *baseplayer) GetPetInfo(limitlevel uint32) []model.PetInfo {
|
|||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *baseplayer) AddBattleProp(index int, level int8) {
|
||||||
|
if p == nil || index < 0 || index >= len(p.Prop) || level == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Prop[index] += level
|
||||||
|
if p.Prop[index] > 6 {
|
||||||
|
p.Prop[index] = 6
|
||||||
|
}
|
||||||
|
if p.Prop[index] < -6 {
|
||||||
|
p.Prop[index] = -6
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *baseplayer) ApplyBattleProps(target *model.AttackValue) {
|
||||||
|
if p == nil || target == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
target.Prop = p.Prop
|
||||||
|
}
|
||||||
func (f *baseplayer) InvitePlayer(ff common.PlayerI) {
|
func (f *baseplayer) InvitePlayer(ff common.PlayerI) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ package admin
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/modules/player/service"
|
"blazing/modules/player/service"
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SignRecordController struct {
|
type SignRecordController struct {
|
||||||
@@ -18,3 +21,16 @@ func init() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResetAllReq struct {
|
||||||
|
g.Meta `path:"/resetAll" method:"POST"`
|
||||||
|
Authorization string `json:"Authorization" in:"header"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SignRecordController) ResetAll(ctx context.Context, req *ResetAllReq) (res *cool.BaseRes, err error) {
|
||||||
|
result, err := service.NewSignService(0).ResetAll()
|
||||||
|
if err != nil {
|
||||||
|
return cool.Fail(err.Error()), nil
|
||||||
|
}
|
||||||
|
return cool.Ok(result), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -383,6 +383,13 @@ func (pet *PetInfo) RnadEffect() {
|
|||||||
// 7 :繁殖加成
|
// 7 :繁殖加成
|
||||||
// 8 :体力提升加成
|
// 8 :体力提升加成
|
||||||
|
|
||||||
|
const (
|
||||||
|
maxHPUpEffectIdx uint16 = 60000
|
||||||
|
maxHPUpEffectStatus byte = 8
|
||||||
|
maxHPUpEffectEID uint16 = 26
|
||||||
|
maxHPUpEffectCap = 20
|
||||||
|
)
|
||||||
|
|
||||||
// 繁殖加成,体力提升加成 ,这里是防止和其他重复所以定义不同类别,但是实际上,能量珠那些事调用不同id的effect实现
|
// 繁殖加成,体力提升加成 ,这里是防止和其他重复所以定义不同类别,但是实际上,能量珠那些事调用不同id的effect实现
|
||||||
// <!-- Stat: 精灵特效Stat: 0: 无效(默认值), 1: 永久, 2: 有`有效次数'的特效 3: 爆发特效 4: 异能精灵特质,5特训,6魂印-->
|
// <!-- Stat: 精灵特效Stat: 0: 无效(默认值), 1: 永久, 2: 有`有效次数'的特效 3: 爆发特效 4: 异能精灵特质,5特训,6魂印-->
|
||||||
func (pet *PetInfo) GetEffect(ptype int) (int, *PetEffectInfo, bool) {
|
func (pet *PetInfo) GetEffect(ptype int) (int, *PetEffectInfo, bool) {
|
||||||
@@ -393,6 +400,47 @@ func (pet *PetInfo) GetEffect(ptype int) (int, *PetEffectInfo, bool) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pet *PetInfo) AddMaxHPUpEffect(itemID uint32, value int) bool {
|
||||||
|
if pet == nil || value <= 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, eff, ok := pet.GetEffect(int(maxHPUpEffectStatus)); ok {
|
||||||
|
current := 0
|
||||||
|
if len(eff.Args) >= 2 && eff.Args[0] == 0 && eff.Args[1] > 0 {
|
||||||
|
current = eff.Args[1]
|
||||||
|
}
|
||||||
|
if current >= maxHPUpEffectCap {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
next := current + value
|
||||||
|
if next > maxHPUpEffectCap {
|
||||||
|
next = maxHPUpEffectCap
|
||||||
|
}
|
||||||
|
|
||||||
|
eff.ItemID = itemID
|
||||||
|
eff.Idx = maxHPUpEffectIdx
|
||||||
|
eff.Status = maxHPUpEffectStatus
|
||||||
|
eff.EID = maxHPUpEffectEID
|
||||||
|
eff.Args = []int{0, next}
|
||||||
|
return next > current
|
||||||
|
}
|
||||||
|
|
||||||
|
if value > maxHPUpEffectCap {
|
||||||
|
value = maxHPUpEffectCap
|
||||||
|
}
|
||||||
|
|
||||||
|
pet.EffectInfo = append(pet.EffectInfo, PetEffectInfo{
|
||||||
|
ItemID: itemID,
|
||||||
|
Idx: maxHPUpEffectIdx,
|
||||||
|
Status: maxHPUpEffectStatus,
|
||||||
|
EID: maxHPUpEffectEID,
|
||||||
|
Args: []int{0, value},
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (pet *PetInfo) Downgrade(level uint32) {
|
func (pet *PetInfo) Downgrade(level uint32) {
|
||||||
|
|
||||||
for pet.Level > uint32(level) {
|
for pet.Level > uint32(level) {
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ type SignClaimResult struct {
|
|||||||
Rewards []SignRewardResult `json:"rewards,omitempty"`
|
Rewards []SignRewardResult `json:"rewards,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SignResetResult 表示管理端执行的签到重置结果。
|
||||||
|
type SignResetResult struct {
|
||||||
|
SignRecordRows int64 `json:"sign_record_rows"`
|
||||||
|
CdkLogRows int64 `json:"cdk_log_rows"`
|
||||||
|
ResetCdkIDs []uint32 `json:"reset_cdk_ids"`
|
||||||
|
}
|
||||||
|
|
||||||
// SignService 管理玩家签到进度。
|
// SignService 管理玩家签到进度。
|
||||||
type SignService struct {
|
type SignService struct {
|
||||||
BaseService
|
BaseService
|
||||||
@@ -117,6 +124,46 @@ func (s *SignService) Claim() (*SignClaimResult, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SignService) ResetAll() (*SignResetResult, error) {
|
||||||
|
result := &SignResetResult{}
|
||||||
|
|
||||||
|
signRes, err := cool.DBM(model.NewSignInRecord()).Delete()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if signRes != nil {
|
||||||
|
result.SignRecordRows, _ = signRes.RowsAffected()
|
||||||
|
}
|
||||||
|
|
||||||
|
configs := configservice.NewSignInService().GetEnabled()
|
||||||
|
cdkIDs := make([]uint32, 0, len(configs))
|
||||||
|
seen := make(map[uint32]struct{}, len(configs))
|
||||||
|
for _, cfg := range configs {
|
||||||
|
if cfg.CdkID == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := seen[cfg.CdkID]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[cfg.CdkID] = struct{}{}
|
||||||
|
cdkIDs = append(cdkIDs, cfg.CdkID)
|
||||||
|
}
|
||||||
|
sort.Slice(cdkIDs, func(i, j int) bool { return cdkIDs[i] < cdkIDs[j] })
|
||||||
|
result.ResetCdkIDs = cdkIDs
|
||||||
|
|
||||||
|
if len(cdkIDs) > 0 {
|
||||||
|
cdkRes, err := cool.DBM(model.NewCdkLog()).WhereIn("code_id", cdkIDs).Delete()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if cdkRes != nil {
|
||||||
|
result.CdkLogRows, _ = cdkRes.RowsAffected()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SignService) grantReachedStageRewards(record *model.SignInRecord) ([]SignRewardResult, error) {
|
func (s *SignService) grantReachedStageRewards(record *model.SignInRecord) ([]SignRewardResult, error) {
|
||||||
configs := configservice.NewSignInService().GetEnabled()
|
configs := configservice.NewSignInService().GetEnabled()
|
||||||
if len(configs) == 0 {
|
if len(configs) == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user