测试三阵营
This commit is contained in:
@@ -22,6 +22,16 @@ namespace TcgEngine
|
||||
public int attack = 0;
|
||||
public int hp = 0;
|
||||
|
||||
// 新增:三种元素法力值
|
||||
public int mana_fire = 0;
|
||||
public int mana_forest = 0;
|
||||
public int mana_water = 0;
|
||||
|
||||
// 新增:三种元素法力值的临时加成
|
||||
public int mana_fire_ongoing = 0;
|
||||
public int mana_forest_ongoing = 0;
|
||||
public int mana_water_ongoing = 0;
|
||||
|
||||
public int mana_ongoing = 0;
|
||||
public int attack_ongoing = 0;
|
||||
public int hp_ongoing = 0;
|
||||
@@ -45,11 +55,18 @@ namespace TcgEngine
|
||||
public Card(string card_id, string uid, int player_id) { this.card_id = card_id; this.uid = uid; this.player_id = player_id; }
|
||||
|
||||
public virtual void Refresh() { exhausted = false; }
|
||||
public virtual void ClearOngoing() { ongoing_status.Clear(); ongoing_traits.Clear(); ClearOngoingAbility(); attack_ongoing = 0; hp_ongoing = 0; mana_ongoing = 0; }
|
||||
public virtual void ClearOngoing()
|
||||
{
|
||||
ongoing_status.Clear(); ongoing_traits.Clear(); ClearOngoingAbility(); attack_ongoing = 0; hp_ongoing = 0; mana_ongoing = 0;
|
||||
// 新增:清除元素法力值临时加成
|
||||
mana_fire_ongoing = 0;
|
||||
mana_forest_ongoing = 0;
|
||||
mana_water_ongoing = 0;
|
||||
}
|
||||
|
||||
public virtual void Clear()
|
||||
{
|
||||
ClearOngoing(); Refresh(); damage = 0; status.Clear();
|
||||
ClearOngoing(); Refresh(); damage = 0; status.Clear();
|
||||
SetCard(CardData, VariantData); //Reset to initial stats
|
||||
equipped_uid = null;
|
||||
}
|
||||
@@ -67,7 +84,11 @@ namespace TcgEngine
|
||||
variant_id = cvariant.id;
|
||||
attack = icard.attack;
|
||||
hp = icard.hp;
|
||||
// 设置法力值
|
||||
mana = icard.mana;
|
||||
mana_fire = icard.mana_fire;
|
||||
mana_forest = icard.mana_forest;
|
||||
mana_water = icard.mana_water;
|
||||
SetTraits(icard);
|
||||
SetAbilities(icard);
|
||||
}
|
||||
@@ -93,7 +114,7 @@ namespace TcgEngine
|
||||
foreach (AbilityData ability in icard.abilities)
|
||||
AddAbility(ability);
|
||||
}
|
||||
|
||||
|
||||
//------ Custom Traits/Stats ---------
|
||||
|
||||
public void SetTrait(string id, int value)
|
||||
@@ -200,7 +221,7 @@ namespace TcgEngine
|
||||
all_traits.AddRange(ongoing_traits);
|
||||
return all_traits;
|
||||
}
|
||||
|
||||
|
||||
//Alternate names since traits/stats are stored in same var
|
||||
public void SetStat(string id, int value) => SetTrait(id, value);
|
||||
public void AddStat(string id, int value) => AddTrait(id, value);
|
||||
@@ -212,6 +233,27 @@ namespace TcgEngine
|
||||
public bool HasStat(string id) => HasTrait(id);
|
||||
public List<CardTrait> GetAllStats() => GetAllTraits();
|
||||
|
||||
// 新增:获取元素法力值的方法
|
||||
public virtual int GetManaFire() { return Mathf.Max(mana_fire + mana_fire_ongoing, 0); }
|
||||
public virtual int GetManaForest() { return Mathf.Max(mana_forest + mana_forest_ongoing, 0); }
|
||||
public virtual int GetManaWater() { return Mathf.Max(mana_water + mana_water_ongoing, 0); }
|
||||
|
||||
|
||||
// 新增:设置元素法力值的方法
|
||||
public void SetManaFire(int value) { mana_fire = value; }
|
||||
public void SetManaForest(int value) { mana_forest = value; }
|
||||
public void SetManaWater(int value) { mana_water = value; }
|
||||
|
||||
// 新增:增加元素法力值的方法
|
||||
public void AddManaFire(int value) { mana_fire += value; }
|
||||
public void AddManaForest(int value) { mana_forest += value; }
|
||||
public void AddManaWater(int value) { mana_water += value; }
|
||||
|
||||
// 新增:增加元素法力值临时加成的方法
|
||||
public void AddManaFireOngoing(int value) { mana_fire_ongoing += value; }
|
||||
public void AddManaForestOngoing(int value) { mana_forest_ongoing += value; }
|
||||
public void AddManaWaterOngoing(int value) { mana_water_ongoing += value; }
|
||||
|
||||
//------ Status Effects ---------
|
||||
|
||||
public void AddStatus(StatusData status, int value, int duration)
|
||||
@@ -331,8 +373,8 @@ namespace TcgEngine
|
||||
public void AddAbility(AbilityData ability)
|
||||
{
|
||||
abilities.Add(ability.id);
|
||||
if (abilities_data != null)
|
||||
abilities_data.Add(ability);
|
||||
if (abilities_data != null)
|
||||
abilities_data.Add(ability);
|
||||
}
|
||||
|
||||
public void RemoveAbility(AbilityData ability)
|
||||
@@ -457,7 +499,7 @@ namespace TcgEngine
|
||||
// return false;
|
||||
//if (!skip_cost && exhausted)
|
||||
// return false; //no more action
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool CanDoActivatedAbilities()
|
||||
@@ -484,13 +526,14 @@ namespace TcgEngine
|
||||
|
||||
//----------------
|
||||
|
||||
public CardData CardData
|
||||
{
|
||||
get {
|
||||
if(data == null || data.id != card_id)
|
||||
public CardData CardData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null || data.id != card_id)
|
||||
data = CardData.Get(card_id); //Optimization, store for future use
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public VariantData VariantData
|
||||
@@ -507,7 +550,8 @@ namespace TcgEngine
|
||||
|
||||
public int Hash
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
if (hash == 0)
|
||||
hash = Mathf.Abs(uid.GetHashCode()); //Optimization, store for future use
|
||||
return hash;
|
||||
@@ -550,6 +594,14 @@ namespace TcgEngine
|
||||
dest.hp = source.hp;
|
||||
dest.mana = source.mana;
|
||||
|
||||
dest.mana_fire = source.mana_fire;
|
||||
dest.mana_forest = source.mana_forest;
|
||||
dest.mana_water = source.mana_water;
|
||||
|
||||
dest.mana_fire_ongoing = source.mana_fire_ongoing;
|
||||
dest.mana_forest_ongoing = source.mana_forest_ongoing;
|
||||
dest.mana_water_ongoing = source.mana_water_ongoing;
|
||||
|
||||
dest.mana_ongoing = source.mana_ongoing;
|
||||
dest.attack_ongoing = source.attack_ongoing;
|
||||
dest.hp_ongoing = source.hp_ongoing;
|
||||
@@ -560,8 +612,8 @@ namespace TcgEngine
|
||||
CardTrait.CloneList(source.ongoing_traits, dest.ongoing_traits);
|
||||
CardStatus.CloneList(source.status, dest.status);
|
||||
CardStatus.CloneList(source.ongoing_status, dest.ongoing_status);
|
||||
GameTool.CloneList(source.abilities, dest.abilities);
|
||||
GameTool.CloneList(source.abilities_ongoing, dest.abilities_ongoing);
|
||||
GameTool.CloneList(source.abilities, dest.abilities);
|
||||
GameTool.CloneList(source.abilities_ongoing, dest.abilities_ongoing);
|
||||
GameTool.CloneListRefNull(source.abilities_data, ref dest.abilities_data); //No need to deep copy since AbilityData doesn't change dynamically, its just a reference
|
||||
}
|
||||
|
||||
@@ -615,7 +667,7 @@ namespace TcgEngine
|
||||
}
|
||||
}
|
||||
|
||||
if(dest.Count > source.Count)
|
||||
if (dest.Count > source.Count)
|
||||
dest.RemoveRange(source.Count, dest.Count - source.Count);
|
||||
}
|
||||
}
|
||||
@@ -641,7 +693,8 @@ namespace TcgEngine
|
||||
this.permanent = (duration == 0);
|
||||
}
|
||||
|
||||
public StatusData StatusData {
|
||||
public StatusData StatusData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null || data.effect != type)
|
||||
|
||||
@@ -106,12 +106,18 @@ namespace TcgEngine
|
||||
return false;
|
||||
|
||||
Player player = GetPlayer(card.player_id);
|
||||
if (!skip_cost && !player.CanPayMana(card))
|
||||
if (!skip_cost && !player.CanPayTeamMana(card))
|
||||
return false; //Cant pay mana
|
||||
if (!player.HasCard(player.cards_hand, card))
|
||||
return false; // Card not in hand
|
||||
if (player.is_ai && card.CardData.IsDynamicManaCost() && player.mana == 0)
|
||||
return false; // AI cant play X-cost card at 0 cost
|
||||
// AI 不能在没有对应阵营mana时使用动态费用卡牌
|
||||
if (player.is_ai && card.CardData.IsDynamicManaCost())
|
||||
{
|
||||
string team_id = card.CardData.team?.id;
|
||||
int available_mana = string.IsNullOrEmpty(team_id) ? player.mana : player.GetTeamMana(team_id);
|
||||
if (available_mana == 0)
|
||||
return false; // AI cant play X-cost card at 0 cost
|
||||
}
|
||||
|
||||
if (card.CardData.IsBoardCard())
|
||||
{
|
||||
|
||||
@@ -124,6 +124,12 @@ namespace TcgEngine.Gameplay
|
||||
player.mana_max = pdeck != null ? pdeck.start_mana : GameplayData.Get().mana_start;
|
||||
player.mana = player.mana_max;
|
||||
|
||||
//初始化三种阵营mana
|
||||
int start_mana = pdeck != null ? pdeck.start_mana : GameplayData.Get().mana_start;
|
||||
player.SetTeamMana("fire", start_mana, start_mana);
|
||||
player.SetTeamMana("forest", start_mana, start_mana);
|
||||
player.SetTeamMana("water", start_mana, start_mana);
|
||||
|
||||
//Draw starting cards 开始抽卡
|
||||
int dcards = pdeck != null ? pdeck.start_cards : GameplayData.Get().cards_start;
|
||||
DrawCard(player, dcards);
|
||||
@@ -147,6 +153,7 @@ namespace TcgEngine.Gameplay
|
||||
StartTurn();
|
||||
}
|
||||
|
||||
//开始回合
|
||||
public virtual void StartTurn()
|
||||
{
|
||||
if (game_data.state == GameState.GameEnded)
|
||||
@@ -165,11 +172,27 @@ namespace TcgEngine.Gameplay
|
||||
DrawCard(player, GameplayData.Get().cards_per_turn);
|
||||
}
|
||||
|
||||
|
||||
//Mana
|
||||
player.mana_max += GameplayData.Get().mana_per_turn;
|
||||
player.mana_max = Mathf.Min(player.mana_max, GameplayData.Get().mana_max);
|
||||
player.mana = player.mana_max;
|
||||
|
||||
//阵营Mana增长:基础每回合+1,场上有对应阵营角色额外+1
|
||||
UpdateTeamMana(player, "fire");
|
||||
UpdateTeamMana(player, "forest");
|
||||
UpdateTeamMana(player, "water");
|
||||
|
||||
// 回合开始时检查所有阵营mana,如果超过5则设置为5
|
||||
if (player.GetTeamMana("fire") > 5)
|
||||
player.SetTeamMana("fire", 5);
|
||||
if (player.GetTeamMana("forest") > 5)
|
||||
player.SetTeamMana("forest", 5);
|
||||
if (player.GetTeamMana("water") > 5)
|
||||
player.SetTeamMana("water", 5);
|
||||
if (player.mana > 5)
|
||||
player.mana = 5;
|
||||
|
||||
//Turn timer and history
|
||||
game_data.turn_timer = GameplayData.Get().turn_duration;
|
||||
player.history_list.Clear();
|
||||
@@ -425,9 +448,9 @@ namespace TcgEngine.Gameplay
|
||||
{
|
||||
Player player = game_data.GetPlayer(card.player_id);
|
||||
|
||||
//Cost
|
||||
//Cost - 使用阵营mana支付
|
||||
if (!skip_cost)
|
||||
player.PayMana(card);
|
||||
player.PayTeamMana(card);
|
||||
|
||||
//Play card
|
||||
player.RemoveCardFromAllGroups(card);
|
||||
@@ -1999,6 +2022,22 @@ namespace TcgEngine.Gameplay
|
||||
return random;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新指定阵营的mana,基础每回合+1,场上有对应阵营角色额外+角色数量
|
||||
/// </summary>
|
||||
private void UpdateTeamMana(Player player, string team_id)
|
||||
{
|
||||
int base_increase = GameplayData.Get().mana_per_turn; // 基础增长
|
||||
int team_bonus = player.GetBoardTeamCount(team_id); // 场上同阵营角色数量
|
||||
int total_increase = base_increase + team_bonus;
|
||||
|
||||
// 增加最大mana
|
||||
player.AddTeamMana(team_id, 0, total_increase);
|
||||
|
||||
// 当前mana设置为最大值
|
||||
player.SetTeamMana(team_id, player.GetTeamManaMax(team_id));
|
||||
}
|
||||
|
||||
public Game GameData { get { return game_data; } }
|
||||
public ResolveQueue ResolveQueue { get { return resolve_queue; } }
|
||||
}
|
||||
|
||||
@@ -23,8 +23,34 @@ namespace TcgEngine
|
||||
|
||||
public int hp;
|
||||
public int hp_max;
|
||||
|
||||
// 三种阵营mana系统
|
||||
[System.Serializable]
|
||||
public class TeamMana
|
||||
{
|
||||
public int current = 0;
|
||||
public int max = 0;
|
||||
|
||||
public TeamMana(int start_value = 0)
|
||||
{
|
||||
current = start_value;
|
||||
max = start_value;
|
||||
}
|
||||
}
|
||||
// 新mana
|
||||
|
||||
public int mana_fire = 0;
|
||||
public int mana_forest = 0;
|
||||
public int mana_water = 0;
|
||||
|
||||
// 保留原有mana属性以兼容现有代码,将作为通用mana使用
|
||||
public int mana = 0;
|
||||
public int mana_max = 0;
|
||||
|
||||
// 新增:三种元素法力值的最大值
|
||||
public int mana_fire_max = 0;
|
||||
public int mana_forest_max = 0;
|
||||
public int mana_water_max = 0;
|
||||
public int kill_count = 0;
|
||||
public int cards_played_this_turn = 0; // 本回合已上场的卡牌数量
|
||||
public Dictionary<string, Card> cards_all = new Dictionary<string, Card>(); //Dictionnary for quick access to any card by UID
|
||||
@@ -591,7 +617,11 @@ namespace TcgEngine
|
||||
dest.hp_max = source.hp_max;
|
||||
dest.mana = source.mana;
|
||||
dest.mana_max = source.mana_max;
|
||||
dest.kill_count = source.kill_count;
|
||||
|
||||
// 复制新mana
|
||||
dest.mana_fire = source.mana;
|
||||
dest.mana_forest = source.mana;
|
||||
dest.mana_water = source.mana;
|
||||
|
||||
Card.CloneNull(source.hero, ref dest.hero);
|
||||
Card.CloneDict(source.cards_all, dest.cards_all);
|
||||
@@ -606,6 +636,165 @@ namespace TcgEngine
|
||||
CardStatus.CloneList(source.status, dest.status);
|
||||
CardStatus.CloneList(source.ongoing_status, dest.ongoing_status);
|
||||
}
|
||||
|
||||
//------------- 阵营Mana相关方法 -------------
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定阵营的当前mana值
|
||||
/// </summary>
|
||||
public int GetTeamMana(string team_id)
|
||||
{
|
||||
if (team_id == "fire") return mana_fire;
|
||||
if (team_id == "forest") return mana_forest;
|
||||
if (team_id == "water") return mana_water;
|
||||
|
||||
Debug.Log($"GetTeamMana: {team_id} not found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定阵营的最大mana值
|
||||
/// </summary>
|
||||
public int GetTeamManaMax(string team_id)
|
||||
{
|
||||
return mana_max;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定阵营的mana值
|
||||
/// </summary>
|
||||
public void SetTeamMana(string team_id, int current, int max = -1)
|
||||
{
|
||||
if (team_id == "fire")
|
||||
{
|
||||
mana_fire = current;
|
||||
if (max >= 0) mana_fire = max;
|
||||
}
|
||||
else if (team_id == "forest")
|
||||
{
|
||||
mana_forest = current;
|
||||
if (max >= 0) mana_forest = max;
|
||||
}
|
||||
else if (team_id == "water")
|
||||
{
|
||||
mana_water = current;
|
||||
if (max >= 0) mana_water = max;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加指定阵营的mana值
|
||||
/// </summary>
|
||||
public void AddTeamMana(string team_id, int current_add = 0, int max_add = 0)
|
||||
{
|
||||
if (team_id == "fire")
|
||||
{
|
||||
mana_fire += current_add;
|
||||
mana_fire = Mathf.Max(mana_fire, 0);
|
||||
mana_fire = Mathf.Clamp(mana_fire, 0, GameplayData.Get().mana_max);
|
||||
}
|
||||
else if (team_id == "forest")
|
||||
{
|
||||
mana_forest += current_add;
|
||||
mana_forest = Mathf.Max(mana_forest, 0);
|
||||
mana_forest = Mathf.Clamp(mana_forest, 0, GameplayData.Get().mana_max);
|
||||
}
|
||||
else if (team_id == "water")
|
||||
{
|
||||
mana_water += current_add;
|
||||
mana_water = Mathf.Max(mana_water, 0);
|
||||
mana_water = Mathf.Clamp(mana_water, 0, GameplayData.Get().mana_max);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否有足够的阵营mana支付卡牌费用
|
||||
/// </summary>
|
||||
public virtual bool CanPayTeamMana(Card card)
|
||||
{
|
||||
if (card.CardData.IsDynamicManaCost())
|
||||
return true;
|
||||
|
||||
string team_id = card.CardData.team?.id;
|
||||
if (string.IsNullOrEmpty(team_id)){
|
||||
Debug.Log($"not CanPayTeamMana checking team mana: {mana} >= {card.GetMana()}");
|
||||
return mana >= card.GetMana(); // 使用通用mana
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Checking team mana for {team_id}: {GetTeamMana(team_id)} >= {card.GetMana()}");
|
||||
return GetTeamMana(team_id) >= card.GetMana();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 支付卡牌的阵营mana费用
|
||||
/// </summary>
|
||||
public virtual void PayTeamMana(Card card)
|
||||
{
|
||||
if (card.CardData.IsDynamicManaCost())
|
||||
return;
|
||||
|
||||
string team_id = card.CardData.team?.id;
|
||||
if (string.IsNullOrEmpty(team_id))
|
||||
{
|
||||
Debug.Log($"PayTeamMana 通用mana: {mana} -= {card.GetMana()}");
|
||||
mana -= card.GetMana(); // 使用通用mana
|
||||
return;
|
||||
}
|
||||
|
||||
int cost = card.GetMana();
|
||||
if (team_id == "fire")
|
||||
{
|
||||
mana_fire -= cost;
|
||||
mana_fire = Mathf.Max(mana_fire, 0);
|
||||
}
|
||||
else if (team_id == "forest")
|
||||
{
|
||||
mana_forest -= cost;
|
||||
mana_forest = Mathf.Max(mana_forest, 0);
|
||||
}
|
||||
else if (team_id == "water")
|
||||
{
|
||||
mana_water -= cost;
|
||||
mana_water = Mathf.Max(mana_water, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取场上指定阵营的角色数量
|
||||
/// </summary>
|
||||
public int GetBoardTeamCount(string team_id)
|
||||
{
|
||||
int count = 0;
|
||||
Debug.Log($"Checking board for {team_id} characters. Total cards on board: {cards_board.Count}");
|
||||
|
||||
foreach (Card card in cards_board)
|
||||
{
|
||||
if (card.CardData.IsCharacter() && card.CardData.team?.id == team_id)
|
||||
{
|
||||
count++;
|
||||
Debug.Log($"Found {team_id} character: {card.CardData.title}");
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"Total {team_id} characters on board: {count}");
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试方法:打印当前所有阵营mana状态
|
||||
/// </summary>
|
||||
public void DebugTeamMana()
|
||||
{
|
||||
Debug.Log($"=== Player {player_id} Team Mana Debug ===");
|
||||
Debug.Log($"General: {mana}/{mana_max}");
|
||||
Debug.Log($"Board cards: {cards_board.Count}");
|
||||
Debug.Log($"Fire characters on board: {GetBoardTeamCount("fire")}");
|
||||
Debug.Log($"Forest characters on board: {GetBoardTeamCount("forest")}");
|
||||
Debug.Log($"Water characters on board: {GetBoardTeamCount("water")}");
|
||||
Debug.Log("=====================================");
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
||||
Reference in New Issue
Block a user