using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TcgEngine.Gameplay;
namespace TcgEngine
{
///
/// Effect that sets stats equal to a dynamic calculated value from a pile (number of cards on board/hand/deck)
///
[CreateAssetMenu(fileName = "effect", menuName = "TcgEngine/Effect/AddStatCount", order = 10)]
public class EffectAddStatCount : EffectData
{
public EffectStatType type;
public PileType pile;
[Header("Count Traits")]
public CardType has_type;
public TeamData has_team;
public TraitData has_trait;
[Header("Team Mana (only for Mana type)")]
public string team_id = ""; // 当type为Mana时,指定影响的阵营
public override void DoEffect(GameLogic logic, AbilityData ability, Card caster, Player target)
{
int val = GetCount(logic.GetGameData(), caster) * ability.value;
if (type == EffectStatType.HP)
{
target.hp += val;
target.hp_max += ability.value;
}
if (type == EffectStatType.Mana)
{
// 如果指定了阵营,影响阵营mana;否则影响通用mana
if (!string.IsNullOrEmpty(team_id))
{
target.AddTeamMana(team_id, val, val);
}
else
{
Debug.Log($"AddStatCount Mana 通用: {val}");
target.mana += val;
target.mana_max += val;
target.mana = Mathf.Max(target.mana, 0);
target.mana_max = Mathf.Clamp(target.mana_max, 0, GameplayData.Get().mana_max);
}
}
}
public override void DoEffect(GameLogic logic, AbilityData ability, Card caster, Card target)
{
int val = GetCount(logic.GetGameData(), caster) * ability.value;
if (type == EffectStatType.Attack)
target.attack += val;
if (type == EffectStatType.HP)
target.hp += val;
if (type == EffectStatType.Mana)
target.mana += val;
if (type == EffectStatType.ManaFire)
target.mana_fire += val;
if (type == EffectStatType.ManaForest)
target.mana_forest += val;
if (type == EffectStatType.ManaWater)
target.mana_water += val;
}
public override void DoOngoingEffect(GameLogic logic, AbilityData ability, Card caster, Card target)
{
int val = GetCount(logic.GetGameData(), caster) * ability.value;
if (type == EffectStatType.Attack)
target.attack_ongoing += val;
if (type == EffectStatType.HP)
target.hp_ongoing += val;
if (type == EffectStatType.Mana)
target.mana_ongoing += val;
if (type == EffectStatType.ManaFire)
target.mana_fire_ongoing += val;
if (type == EffectStatType.ManaForest)
target.mana_forest_ongoing += val;
if (type == EffectStatType.ManaWater)
target.mana_water_ongoing += val;
}
private int GetCount(Game data, Card caster)
{
Player player = data.GetPlayer(caster.player_id);
return CountPile(player, pile);
}
private int CountPile(Player player, PileType pile)
{
List card_pile = null;
if (pile == PileType.Hand)
card_pile = player.cards_hand;
if (pile == PileType.Board)
card_pile = player.cards_board;
if (pile == PileType.Equipped)
card_pile = player.cards_equip;
if (pile == PileType.Deck)
card_pile = player.cards_deck;
if (pile == PileType.Discard)
card_pile = player.cards_discard;
if (pile == PileType.Secret)
card_pile = player.cards_secret;
if (pile == PileType.Temp)
card_pile = player.cards_temp;
if (card_pile != null)
{
int count = 0;
foreach (Card card in card_pile)
{
if (IsTrait(card))
count++;
}
return count;
}
return 0;
}
private bool IsTrait(Card card)
{
bool is_type = card.CardData.type == has_type || has_type == CardType.None;
bool is_team = card.CardData.team == has_team || has_team == null;
bool is_trait = card.HasTrait(has_trait) || has_trait == null;
return (is_type && is_team && is_trait);
}
}
}