111 lines
3.7 KiB
C#
111 lines
3.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TcgEngine.Gameplay;
|
|
|
|
namespace TcgEngine
|
|
{
|
|
/// <summary>
|
|
/// Effect that damages a card or a player (lose hp)
|
|
/// </summary>
|
|
|
|
[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);
|
|
logic.DamagePlayer(caster, target, damage);
|
|
}
|
|
|
|
public override void DoEffect(GameLogic logic, AbilityData ability, Card caster, Card target)
|
|
{
|
|
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;
|
|
|
|
// 无敌状态
|
|
if (target.HasStatus(StatusType.Invincibility))
|
|
{
|
|
will_kill = false;
|
|
}
|
|
|
|
// 免疫伤害
|
|
if (target.HasStatus(StatusType.Shell))
|
|
{
|
|
Debug.Log("目标处于贝壳状态,免疫本次伤害");
|
|
will_kill = false;
|
|
}
|
|
|
|
int armor_reduction = 0;
|
|
int damageBeforeArmor = 0;
|
|
// 护甲状态
|
|
if (target.HasStatus(StatusType.Armor))
|
|
{
|
|
armor_reduction = target.GetStatusValue(StatusType.Armor);
|
|
damageBeforeArmor = Mathf.Max(0, damage - armor_reduction);
|
|
if (damageBeforeArmor > 0)
|
|
{
|
|
will_kill = false;
|
|
}
|
|
}
|
|
|
|
// 造成伤害
|
|
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)
|
|
{
|
|
Player player = data.GetPlayer(caster.player_id);
|
|
int damage = value + caster.GetTraitValue(bonus_damage) + player.GetTraitValue(bonus_damage);
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |