引入属性、伤害管线
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using SepCore.Battle;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using UnityEngine;
|
||||
@@ -209,10 +210,19 @@ namespace SepCore.CustomUtility
|
||||
return;
|
||||
}
|
||||
|
||||
int entityDamageHP = CalcDamageHP(projectileImpactData.AttackBase, projectileImpactData.AttackStat,
|
||||
entityImpactData.DefenseStat, entityImpactData.DodgeStat);
|
||||
DamageContext context = new DamageContext
|
||||
{
|
||||
BaseDamage = projectileImpactData.AttackBase,
|
||||
DamageScalingStat = projectileImpactData.DamageType.ToScalingStat(),
|
||||
ScalingRatio = projectileImpactData.ScalingRatio,
|
||||
BaseCritChance = projectileImpactData.BaseCritChance,
|
||||
CritMultiplier = projectileImpactData.CritMultiplier,
|
||||
AttackerPipeline = projectileImpactData.AttributeProvider,
|
||||
DefenderPipeline = entityImpactData.AttributeProvider
|
||||
};
|
||||
|
||||
entity.ApplyDamage(enemyProjectile, entityDamageHP);
|
||||
DamageResult result = DamagePipeline.Calculate(in context);
|
||||
entity.ApplyDamage(enemyProjectile, in result, enemyProjectile.CachedTransform.position);
|
||||
enemyProjectile.Expire();
|
||||
return;
|
||||
}
|
||||
@@ -228,43 +238,23 @@ namespace SepCore.CustomUtility
|
||||
return;
|
||||
}
|
||||
|
||||
int entityDamageHP = CalcDamageHP(weaponImpactData.AttackBase, weaponImpactData.AttackStat,
|
||||
entityImpactData.DefenseStat, entityImpactData.DodgeStat);
|
||||
DamageContext context = new DamageContext
|
||||
{
|
||||
BaseDamage = weaponImpactData.AttackBase,
|
||||
DamageScalingStat = weaponImpactData.DamageType.ToScalingStat(),
|
||||
ScalingRatio = weaponImpactData.ScalingRatio,
|
||||
BaseCritChance = weaponImpactData.BaseCritChance,
|
||||
CritMultiplier = weaponImpactData.CritMultiplier,
|
||||
AttackerPipeline = weaponImpactData.AttributeProvider,
|
||||
DefenderPipeline = entityImpactData.AttributeProvider
|
||||
};
|
||||
|
||||
entity.ApplyDamage(weapon, entityDamageHP);
|
||||
DamageResult result = DamagePipeline.Calculate(in context);
|
||||
entity.ApplyDamage(weapon, in result, entity.CachedTransform.position);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static int CalcDamageHP(int attack, StatProperty attackStat, StatProperty defenseStat,
|
||||
StatProperty dodgeStat)
|
||||
{
|
||||
// 1. 处理闪避(从全局表读取闪避率上限)
|
||||
float maxDodge = GameEntry.Luban.Global.MaxDodgeRate / 1000f;
|
||||
if (dodgeStat != null)
|
||||
{
|
||||
if (Random.value < Mathf.Clamp(dodgeStat.Value, 0f, maxDodge)) return 0;
|
||||
}
|
||||
|
||||
// 2. 处理攻击加成 最终伤害 = (基础伤害 + 伤害提升固定值) * 伤害提升率
|
||||
float damage = attack;
|
||||
if (attackStat != null)
|
||||
{
|
||||
damage = (attack + attackStat.Value) * attackStat.Percent;
|
||||
}
|
||||
|
||||
// 3. 处理防御加成 最终伤害 = (基础伤害 - 防御提升固定值) / 防御提升率
|
||||
if (defenseStat != null)
|
||||
{
|
||||
damage = (damage - defenseStat.Value) / defenseStat.Percent;
|
||||
}
|
||||
|
||||
// 4. 将伤害限制为保底伤害,避免堆防御导致无法造成伤害
|
||||
int minDamage = GameEntry.Luban.Global.MinDamage;
|
||||
if (damage < minDamage) return minDamage;
|
||||
return Mathf.CeilToInt(damage);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Auto)]
|
||||
private struct CampPair
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user