Files
2025-08-26 17:12:46 +08:00

76 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TcgEngine.Gameplay;
namespace TcgEngine
{
/// <summary>
/// Effect to make a card attack a target
/// </summary>
[CreateAssetMenu(fileName = "effect", menuName = "TcgEngine/Effect/Attack", order = 10)]
public class EffectAttack : EffectData
{
public EffectAttackerType attacker_type;
public override void DoEffect(GameLogic logic, AbilityData ability, Card caster, Player target)
{
Card attacker = GetAttacker(logic.GetGameData(), caster);
if (attacker != null)
{
logic.AttackPlayer(attacker, target, true);
}
}
public override void DoEffect(GameLogic logic, AbilityData ability, Card caster, Card target)
{
Card attack = GetAttacker(logic.GetGameData(), caster);
if (attack != null)
{
logic.AttackTarget(attack, target, true);
}
}
public Card GetAttacker(Game gdata, Card caster)
{
if (attacker_type == EffectAttackerType.Self)
return caster;
if (attacker_type == EffectAttackerType.AbilityTriggerer)
return gdata.GetCard(gdata.ability_triggerer);
if (attacker_type == EffectAttackerType.LastPlayed)
return gdata.GetCard(gdata.last_played);
if (attacker_type == EffectAttackerType.LastTargeted)
return gdata.GetCard(gdata.last_target);
if (attacker_type == EffectAttackerType.LastTargetedLeft)
{
Card lastTarget = gdata.GetCard(gdata.last_target);
if (lastTarget != null && lastTarget.slot.x > Slot.x_min)
{
Slot leftSlot = new Slot(lastTarget.slot.x - 1, lastTarget.slot.y, lastTarget.slot.p);
return gdata.GetSlotCard(leftSlot);
}
}
if (attacker_type == EffectAttackerType.LastTargetedRight)
{
Card lastTarget = gdata.GetCard(gdata.last_target);
if (lastTarget != null && lastTarget.slot.x < Slot.x_max)
{
Slot rightSlot = new Slot(lastTarget.slot.x + 1, lastTarget.slot.y, lastTarget.slot.p);
return gdata.GetSlotCard(rightSlot);
}
}
return null;
}
}
public enum EffectAttackerType
{
Self = 1,
AbilityTriggerer = 25,
LastPlayed = 70,
LastTargeted = 72,
LastTargetedLeft = 73,
LastTargetedRight = 74,
}
}