半血双倍伤害&击杀钩子
This commit is contained in:
@@ -12,8 +12,15 @@ namespace TcgEngine
|
||||
[CreateAssetMenu(fileName = "effect", menuName = "TcgEngine/Effect/Damage", order = 10)]
|
||||
public class EffectDamage : EffectData
|
||||
{
|
||||
[Header("伤害设置")]
|
||||
public TraitData bonus_damage;
|
||||
|
||||
[Header("半血翻倍")]
|
||||
public bool double_damage_on_half_hp = false; // 当目标生命值低于50%时伤害翻倍
|
||||
|
||||
[Header("击杀触发")]
|
||||
public AbilityData kill_trigger_ability = null; // 击杀后触发的技能
|
||||
|
||||
public override void DoEffect(GameLogic logic, AbilityData ability, Card caster, Player target)
|
||||
{
|
||||
int damage = GetDamage(logic.GameData, caster, ability.value);
|
||||
@@ -22,8 +29,21 @@ namespace TcgEngine
|
||||
|
||||
public override void DoEffect(GameLogic logic, AbilityData ability, Card caster, Card target)
|
||||
{
|
||||
int damage = GetDamage(logic.GameData, caster, ability.value);
|
||||
int damage = GetDamageWithHalfHpBonus(logic.GameData, caster, ability.value, target);
|
||||
|
||||
// 是否可以击杀
|
||||
int target_hp_before = target != null ? target.GetHP() : 0;
|
||||
bool will_kill = target != null && target_hp_before <= damage;
|
||||
|
||||
// 造成伤害
|
||||
logic.DamageCard(caster, target, damage, true);
|
||||
|
||||
// 如果击杀了目标且配置了击杀触发技能,则触发技能
|
||||
if (will_kill && target != null && kill_trigger_ability != null)
|
||||
{
|
||||
Debug.Log("满足击杀条件");
|
||||
TriggerKillAbility(logic, caster, target);
|
||||
}
|
||||
}
|
||||
|
||||
private int GetDamage(Game data, Card caster, int value)
|
||||
@@ -33,5 +53,33 @@ namespace TcgEngine
|
||||
return damage;
|
||||
}
|
||||
|
||||
private int GetDamageWithHalfHpBonus(Game data, Card caster, int value, Card target)
|
||||
{
|
||||
int damage = GetDamage(data, caster, value);
|
||||
|
||||
// 半血伤害翻倍
|
||||
if (double_damage_on_half_hp && target != null)
|
||||
{
|
||||
int current_hp = target.GetHP();
|
||||
int max_hp = target.CardData.hp;
|
||||
float hp_percentage = (float)current_hp / max_hp;
|
||||
|
||||
if (hp_percentage <= 0.5f) // 生命值低于等于50%
|
||||
{
|
||||
damage *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
return damage;
|
||||
}
|
||||
|
||||
private void TriggerKillAbility(GameLogic logic, Card caster, Card killed_target)
|
||||
{
|
||||
if (kill_trigger_ability != null && caster != null)
|
||||
{
|
||||
Debug.Log("触发击杀钩子");
|
||||
logic.TriggerAbilityDelayed(kill_trigger_ability, caster, killed_target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user