场上没有卡牌时自动上场
This commit is contained in:
@@ -174,6 +174,9 @@ namespace TcgEngine.Gameplay
|
|||||||
game_data.turn_timer = GameplayData.Get().turn_duration;
|
game_data.turn_timer = GameplayData.Get().turn_duration;
|
||||||
player.history_list.Clear();
|
player.history_list.Clear();
|
||||||
|
|
||||||
|
//清除本回合已上场的卡牌数量
|
||||||
|
player.cards_played_this_turn = 0;
|
||||||
|
|
||||||
//Player poison
|
//Player poison
|
||||||
if (player.HasStatus(StatusType.Poisoned))
|
if (player.HasStatus(StatusType.Poisoned))
|
||||||
player.hp -= player.GetStatusValue(StatusType.Poisoned);
|
player.hp -= player.GetStatusValue(StatusType.Poisoned);
|
||||||
@@ -997,6 +1000,81 @@ namespace TcgEngine.Gameplay
|
|||||||
|
|
||||||
cards_to_clear.Add(card); //Will be Clear() in the next UpdateOngoing, so that simultaneous damage effects work
|
cards_to_clear.Add(card); //Will be Clear() in the next UpdateOngoing, so that simultaneous damage effects work
|
||||||
onCardDiscarded?.Invoke(card);
|
onCardDiscarded?.Invoke(card);
|
||||||
|
|
||||||
|
// 检查场上是否为空,如果为空则强制召唤角色牌
|
||||||
|
if (was_on_board)
|
||||||
|
{
|
||||||
|
CheckAndForceSummonCharacter(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查并强制召唤角色牌
|
||||||
|
public virtual void CheckAndForceSummonCharacter(Player player)
|
||||||
|
{
|
||||||
|
// 检查场上是否为空
|
||||||
|
if (player.cards_board.Count > 0)
|
||||||
|
return; // 场上还有牌,不需要强制召唤
|
||||||
|
|
||||||
|
// 检查手牌中是否有角色牌
|
||||||
|
Card characterCard = GetRandomCharacterFromHand(player);
|
||||||
|
if (characterCard != null)
|
||||||
|
{
|
||||||
|
// 从手牌强制上场角色牌
|
||||||
|
ForceSummonCharacterFromHand(player, characterCard);
|
||||||
|
}
|
||||||
|
else if (player.cards_hand.Count == 0 && player.cards_deck.Count > 0)
|
||||||
|
{
|
||||||
|
// 没有手牌但卡组还有牌,判为输
|
||||||
|
EndGame(GetOpponentId(player.player_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从手牌中获取随机角色牌
|
||||||
|
private Card GetRandomCharacterFromHand(Player player)
|
||||||
|
{
|
||||||
|
List<Card> characterCards = new List<Card>();
|
||||||
|
foreach (Card card in player.cards_hand)
|
||||||
|
{
|
||||||
|
if (card.CardData.IsCharacter())
|
||||||
|
{
|
||||||
|
characterCards.Add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (characterCards.Count > 0)
|
||||||
|
{
|
||||||
|
return characterCards[random.Next(0, characterCards.Count)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 强制从手牌召唤角色牌,设置为疲劳状态,不消耗mana
|
||||||
|
private void ForceSummonCharacterFromHand(Player player, Card characterCard)
|
||||||
|
{
|
||||||
|
// 找到一个空的卡槽
|
||||||
|
Slot emptySlot = player.GetRandomEmptySlot(random);
|
||||||
|
if (emptySlot.IsValid())
|
||||||
|
{
|
||||||
|
// 不消耗mana强制上场
|
||||||
|
PlayCard(characterCard, emptySlot, true); // skip_cost = true
|
||||||
|
|
||||||
|
// 设置为疲劳状态
|
||||||
|
characterCard.exhausted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取对手ID
|
||||||
|
private int GetOpponentId(int playerId)
|
||||||
|
{
|
||||||
|
foreach (Player player in game_data.players)
|
||||||
|
{
|
||||||
|
if (player.player_id != playerId)
|
||||||
|
{
|
||||||
|
return player.player_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1; // 找不到对手时返回-1
|
||||||
}
|
}
|
||||||
|
|
||||||
public int RollRandomValue(int dice)
|
public int RollRandomValue(int dice)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace TcgEngine
|
|||||||
public int mana = 0;
|
public int mana = 0;
|
||||||
public int mana_max = 0;
|
public int mana_max = 0;
|
||||||
public int kill_count = 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
|
public Dictionary<string, Card> cards_all = new Dictionary<string, Card>(); //Dictionnary for quick access to any card by UID
|
||||||
public Card hero = null;
|
public Card hero = null;
|
||||||
|
|
||||||
@@ -556,10 +556,18 @@ namespace TcgEngine
|
|||||||
|
|
||||||
public virtual bool IsDead()
|
public virtual bool IsDead()
|
||||||
{
|
{
|
||||||
if (cards_hand.Count == 0 && cards_board.Count == 0 && cards_deck.Count == 0)
|
// 原有的死亡判定:血量为0
|
||||||
return true;
|
|
||||||
if (hp <= 0)
|
if (hp <= 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// 新增的死亡判定:无手牌、无场上卡牌,且卡组中还有牌
|
||||||
|
if (cards_hand.Count == 0 && cards_board.Count == 0 && cards_deck.Count > 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// 原有的死亡判定:所有牌都没有了
|
||||||
|
if (cards_hand.Count == 0 && cards_board.Count == 0 && cards_deck.Count == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user