All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat(fight): 添加旧组队协议支持并优化战斗系统 - 实现了旧组队协议相关功能,包括GroupReadyFightFinish、GroupUseSkill、 GroupUseItem、GroupChangePet和GroupEscape方法 - 新增组队战斗相关的入站信息结构体定义 - 实现了组队BOSS战斗逻辑,添加groupBossSlotLimit常量 - 重构宠物技能设置逻辑,调整金币消耗时机 - 优化战斗循环逻辑,添加对无行动槽位的处理 - 改进AI行动逻辑,增加多位置目标选择
339 lines
8.3 KiB
Go
339 lines
8.3 KiB
Go
package input
|
||
|
||
import (
|
||
element "blazing/common/data/Element"
|
||
"blazing/common/utils"
|
||
|
||
"blazing/logic/service/fight/action"
|
||
"blazing/logic/service/fight/info"
|
||
|
||
"github.com/alpacahq/alpacadecimal"
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
"github.com/gogf/gf/v2/util/grand"
|
||
)
|
||
|
||
// 计算暴击
|
||
func (our *Input) CalculateCrit(opp *Input, skill *info.SkillEntity) {
|
||
ourPet := our.CurrentPet()
|
||
oppPet := opp.CurrentPet()
|
||
if ourPet == nil || oppPet == nil {
|
||
return
|
||
}
|
||
|
||
skill.Crit = 0
|
||
if skill.Category() == info.Category.STATUS { //属性技能不用算暴击
|
||
return
|
||
}
|
||
CritRate := utils.Max(skill.XML.CritRate, 1)
|
||
|
||
//CritAtkFirst: 先出手时必定致命一击; 默认: 0
|
||
if skill.XML.CritAtkFirst != 0 && our.FightC.IsFirst(our.Player) {
|
||
CritRate = 16
|
||
}
|
||
//CritAtkSecond: 后出手时必定致命一击; 默认: 0
|
||
if skill.XML.CritAtkSecond != 0 && !our.FightC.IsFirst(our.Player) {
|
||
CritRate = 16
|
||
}
|
||
// CritSelfHalfHp: 自身体力低于一半时必定致命一击; 默认: 0
|
||
if skill.XML.CritSelfHalfHp != 0 && (ourPet.HP < int(ourPet.Info.MaxHp)/2) {
|
||
CritRate = 16
|
||
}
|
||
// CritFoeHalfHp: 对方体力低于一半时必定致命一击; 默认: 0
|
||
if skill.XML.CritSelfHalfHp != 0 && (oppPet.HP < int(oppPet.Info.MaxHp)/2) {
|
||
CritRate = 16
|
||
}
|
||
|
||
//todo 暴击伤害
|
||
if t := grand.Meet(CritRate, 16); t {
|
||
skill.Crit = 1
|
||
}
|
||
|
||
}
|
||
|
||
// 恢复血量
|
||
func (our *Input) Heal(in *Input, ac action.BattleActionI, value alpacadecimal.Decimal) {
|
||
currentPet := our.CurrentPet()
|
||
if currentPet == nil {
|
||
return
|
||
}
|
||
healValue := int(value.IntPart())
|
||
|
||
if ac != nil {
|
||
if _, ok := ac.(*action.UseItemAction); !ok {
|
||
our.ExecWithOpponent(in, func(t Effect) bool {
|
||
t.Heal_Pre(ac, &healValue)
|
||
return true
|
||
})
|
||
}
|
||
}
|
||
|
||
//使用道具回血
|
||
if _, ok := ac.(*action.UseItemAction); !ok &&
|
||
ac != nil &&
|
||
in == our &&
|
||
healValue > 0 {
|
||
our.AttackValue.GainHp += int32(healValue) //道具有专门的回血包
|
||
}
|
||
|
||
if healValue >= 0 {
|
||
currentPet.Info.ModelHP(int64(healValue))
|
||
if our.AttackValue != nil {
|
||
our.AttackValue.RemainHp = int32(currentPet.Info.Hp)
|
||
our.AttackValue.MaxHp = currentPet.Info.MaxHp
|
||
}
|
||
return
|
||
}
|
||
|
||
damage := uint32(-healValue)
|
||
if damage >= currentPet.Info.Hp {
|
||
currentPet.Info.Hp = 0
|
||
if our.AttackValue != nil {
|
||
our.AttackValue.RemainHp = 0
|
||
our.AttackValue.MaxHp = currentPet.Info.MaxHp
|
||
}
|
||
return
|
||
}
|
||
currentPet.Info.Hp -= damage
|
||
if our.AttackValue != nil {
|
||
our.AttackValue.RemainHp = int32(currentPet.Info.Hp)
|
||
our.AttackValue.MaxHp = currentPet.Info.MaxHp
|
||
}
|
||
|
||
}
|
||
func (our *Input) HealPP(value int) {
|
||
currentPet := our.CurrentPet()
|
||
if currentPet == nil {
|
||
return
|
||
}
|
||
|
||
currentPet.Info.HealPP(value)
|
||
|
||
}
|
||
func (our *Input) DelPP(value int) {
|
||
currentPet := our.CurrentPet()
|
||
if currentPet == nil {
|
||
return
|
||
}
|
||
|
||
for i := 0; i < len(currentPet.Info.SkillList); i++ {
|
||
if uint32(value) > currentPet.Info.SkillList[i].PP {
|
||
currentPet.Info.SkillList[i].PP = 0
|
||
} else {
|
||
currentPet.Info.SkillList[i].PP -= uint32(value)
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
// Damage 对方对我方造成伤害,处理伤害计算和扣减血量逻辑,包括各种增伤、减伤效果
|
||
// /红伤只允许调用一次来保持锁伤
|
||
// 这个方法是对对方造成伤害
|
||
// 伤害落实 // 血量扣减节点比如触发回神,反弹也在这里实现
|
||
func (our *Input) Damage(in *Input, sub *info.DamageZone) {
|
||
currentPet := our.CurrentPet()
|
||
if currentPet == nil {
|
||
return
|
||
}
|
||
attacker := in
|
||
if attacker == nil {
|
||
attacker = our
|
||
}
|
||
// if sub.Type == info.DamageType.Red { //每回合计算伤害的时候重置伤害
|
||
// our.Opp.SumDamage = sub.Damage
|
||
|
||
// }
|
||
// 对方对我方造成,需要吃到对方的加成
|
||
var ok bool
|
||
if our != attacker {
|
||
ok = attacker.ExecWithOpponent(our, func(t Effect) bool {
|
||
|
||
t.DamageAdd(sub) //红伤落实前,我方增伤
|
||
|
||
return true
|
||
})
|
||
|
||
//sub.BeforeMul = sub.Damage
|
||
if ok {
|
||
ok = attacker.ExecWithOpponent(our, func(t Effect) bool {
|
||
|
||
t.Damage_Mul(sub) //红伤落实前,我方增伤
|
||
|
||
return true
|
||
})
|
||
}
|
||
//sub.BeforeFloor = sub.Damage
|
||
if ok {
|
||
ok = attacker.ExecWithOpponent(our, func(t Effect) bool {
|
||
|
||
t.DamageFloor(sub) //红伤落实,内部有befer
|
||
|
||
return true
|
||
})
|
||
}
|
||
}
|
||
|
||
// sub.BeforeMul = sub.Damage
|
||
if ok {
|
||
ok = our.ExecWithOpponent(attacker, func(t Effect) bool {
|
||
|
||
t.DamageDivEx(sub) //红伤落实,内部有befer
|
||
|
||
return true
|
||
})
|
||
}
|
||
|
||
//sub.BeforeSUB = sub.Damage
|
||
if ok {
|
||
ok = our.ExecWithOpponent(attacker, func(t Effect) bool {
|
||
|
||
t.DamageSubEx(sub)
|
||
|
||
return true
|
||
})
|
||
}
|
||
//sub.BeforeLocked = sub.Damage
|
||
if ok {
|
||
our.ExecWithOpponent(attacker, func(t Effect) bool {
|
||
|
||
t.DamageLockEx(sub)
|
||
|
||
return true
|
||
})
|
||
}
|
||
// sub.BeforeLock = sub.Damage
|
||
if ok && attacker != our {
|
||
ok = attacker.ExecWithOpponent(our, func(t Effect) bool {
|
||
|
||
t.DamageLock(sub)
|
||
|
||
return true
|
||
})
|
||
}
|
||
if ok {
|
||
our.ExecWithOpponent(attacker, func(t Effect) bool {
|
||
|
||
t.Damage_Shield(sub)
|
||
|
||
return true
|
||
})
|
||
}
|
||
if sub.Damage.Cmp(alpacadecimal.Zero) < 0 {
|
||
sub.Damage = alpacadecimal.Zero
|
||
}
|
||
if shieldAbsorb := our.AbsorbShieldDamage(sub.Damage); shieldAbsorb.Cmp(alpacadecimal.Zero) > 0 {
|
||
sub.Damage = sub.Damage.Sub(shieldAbsorb)
|
||
}
|
||
if sub.Type == info.DamageType.Red { //红才会产生造成伤害
|
||
attacker.SumDamage = sub.Damage.Add(attacker.SumDamage) // 叠加总伤害 这里相当于记录红伤
|
||
|
||
}
|
||
if sub.Type == info.DamageType.Red { //红才会产生造成伤害
|
||
attacker.AttackValue.LostHp += uint32(sub.Damage.IntPart()) //红伤落实
|
||
|
||
}
|
||
|
||
if uint32(sub.Damage.IntPart()) > currentPet.Info.Hp {
|
||
|
||
currentPet.Info.Hp = 0
|
||
} else {
|
||
currentPet.Info.Hp = currentPet.Info.Hp - uint32(sub.Damage.IntPart())
|
||
}
|
||
if our.AttackValue != nil {
|
||
our.AttackValue.RemainHp = int32(currentPet.Info.Hp)
|
||
our.AttackValue.MaxHp = currentPet.Info.MaxHp
|
||
}
|
||
|
||
//todo 待实现死亡effet
|
||
|
||
}
|
||
|
||
// 计算技能威力
|
||
func (our *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) alpacadecimal.Decimal {
|
||
if deftype == nil {
|
||
return alpacadecimal.Zero
|
||
}
|
||
ourPet := our.CurrentPet()
|
||
defPet := deftype.CurrentPet()
|
||
if ourPet == nil || defPet == nil {
|
||
return alpacadecimal.Zero
|
||
}
|
||
|
||
// 1. 计算等级因子 (level * 0.4 + 2)
|
||
levelFactor := alpacadecimal.NewFromInt(int64(ourPet.Info.Level)).
|
||
Mul(alpacadecimal.NewFromFloat(0.4)).Add(alpacadecimal.NewFromInt(2))
|
||
|
||
var (
|
||
attackDec alpacadecimal.Decimal //攻击值
|
||
defenseDec alpacadecimal.Decimal //防御值
|
||
|
||
)
|
||
|
||
switch skill.Category() { //判断技能类型
|
||
case info.Category.PHYSICAL:
|
||
attackDec = our.GetProp(0)
|
||
defenseDec = deftype.GetProp(1)
|
||
|
||
case info.Category.SPECIAL:
|
||
|
||
attackDec = our.GetProp(2)
|
||
defenseDec = deftype.GetProp(3)
|
||
|
||
default:
|
||
return alpacadecimal.Zero
|
||
}
|
||
// 8. DmgBindLv: 使对方受到的伤害值等于等级; 默认: 0
|
||
// 9. PwrBindDv: 1,威力(power)取决于潜力(个体值)*5; 2,威力(power)取决于最大体力*1/3+潜力(个体值); 默认: 0
|
||
// 10. PwrDouble: 攻击时,若对方处于异常状态, 则威力翻倍;
|
||
// 11. DmgBindHpDv: 造成的伤害等于自身剩余体力*1/2+潜力(个体值); 默认: 0
|
||
if skill.XML.DmgBindLv != 0 {
|
||
|
||
skill.XML.Power = int(defPet.Info.Level)
|
||
|
||
}
|
||
if skill.XML.PwrBindDv != 0 {
|
||
if skill.XML.PwrBindDv == 1 {
|
||
|
||
skill.XML.Power = int(ourPet.Info.Dv * 5)
|
||
|
||
}
|
||
if skill.XML.PwrBindDv == 2 {
|
||
skill.XML.Power = int(ourPet.Info.Hp/3 + ourPet.Info.Dv)
|
||
}
|
||
|
||
}
|
||
if skill.XML.PwrDouble != 0 {
|
||
|
||
if deftype.StatEffect_Exist_all() {
|
||
skill.XML.Power = skill.XML.Power * 2
|
||
}
|
||
|
||
}
|
||
if skill.XML.DmgBindHpDv != 0 {
|
||
skill.XML.Power = int(ourPet.Info.Hp/2 + ourPet.Info.Dv)
|
||
|
||
}
|
||
// 5. 基础伤害公式:等级因子 * 威力因子 * 攻击 / 防御 / 50 + 2
|
||
baseDamage := levelFactor.
|
||
Div(alpacadecimal.NewFromInt(50)).
|
||
Mul(alpacadecimal.NewFromInt(int64(skill.XML.Power))).
|
||
Mul(attackDec.Div(defenseDec)).
|
||
Add(alpacadecimal.NewFromInt(2))
|
||
|
||
var typeRate alpacadecimal.Decimal
|
||
//fmt.Println(skill.Type().ID, defPet.Type().ID)
|
||
t, _ := element.Calculator.GetOffensiveMultiplier(skill.GetType().ID, defPet.GetType().ID)
|
||
our.AttackValue.Offensive = gconv.Float32(t)
|
||
|
||
typeRate = alpacadecimal.NewFromFloat(t)
|
||
|
||
damage := baseDamage.
|
||
Mul(skill.CriticalsameTypeBonus()). // 同属性加成
|
||
Mul(typeRate). // 克制系数
|
||
|
||
Mul(skill.Criticalrandom()) //随机波动
|
||
//println(baseDamage.IntPart(), damage.IntPart(), attackDec.IntPart(), defenseDec.IntPart(), "技能伤害")
|
||
return damage
|
||
|
||
}
|