public static PlayerPossibleAttack GetPossibleAttack(HRPlayer Player, int RequiredAttack, int Limit = -1) { var result = new PlayerPossibleAttack(); var playerState = new PlayerState(Player); var minions = playerState.ReadyMinions; // FIX: Only use cards to attack that are really needed to defeat somone. // (sorted by attack) var sorting = new Sorting(); sorting.SortByAttack(ref minions, Sorting.SortMode.Descending); // Loop through all minions that can attack.. foreach (var item in minions) { if (HRCardManager.CanAttackWithCard(item.GetCard())) { if (Limit == -1) { result.Attack += item.GetATK(); result.Cards.Add(item); } else if (result.Cards.Count + 1 == Limit) { // Try to find a combination that matches... if (result.Attack + item.GetATK() >= RequiredAttack) { result.Attack += item.GetATK(); result.Cards.Add(item); } } else { result.Attack += item.GetATK(); result.Cards.Add(item); } } } if (result.Attack < RequiredAttack) { int remainingMana = Player.GetNumAvailableResources(); // Check other resources that can deal damage. // Deal damage with hero power? if (Player.GetHeroPower().GetATK() > 0) { if (Player.GetHeroPower().GetCost() <= remainingMana) { result.Attack += Player.GetHeroPower().GetATK(); result.Cost += Player.GetHeroPower().GetCost(); result.Cards.Add(Player.GetHeroPower()); remainingMana -= Player.GetHeroPower().GetCost(); } } // Hero Card most times: Weapons and other special stuff. if (Player.HasWeapon() && Player.GetWeaponCard().GetEntity().GetATK() > 0 && Player.GetWeaponCard().GetEntity().CanAttack() && Player.GetWeaponCard().GetEntity().GetCost() <= remainingMana) { if (HRCardManager.CanAttackWithCard(Player.GetHero().GetCard())) { result.Attack += Player.GetWeaponCard().GetEntity().GetATK(); result.Cost += Player.GetWeaponCard().GetEntity().GetCost(); result.Cards.Add(Player.GetWeaponCard().GetEntity()); remainingMana -= Player.GetHero().GetCost(); } } // Remaining cards on hand? List <HRCard> playerHand = HRCard.GetCards(Player, HRCardZone.HAND); foreach (var item in playerHand) { if ((item.GetEntity().IsSpell() || (item.GetEntity().IsMinion() && item.GetEntity().HasCharge())) && item.GetEntity().GetATK() > 0) { int cost = item.GetEntity().GetCost(); if (cost <= remainingMana) { result.Attack += item.GetEntity().GetATK(); result.Cost += cost; result.Cards.Add(item.GetEntity()); remainingMana -= cost; } } } } return(result); }
public static PlayerPossibleAttack GetPossibleAttack(HRPlayer Player, int RequiredAttack, int Limit = -1) { var result = new PlayerPossibleAttack(); var playerState = new PlayerState(Player); var minions = playerState.ReadyMinions; // FIX: Only use cards to attack that are really needed to defeat somone. // (sorted by attack) var sorting = new Sorting(); sorting.SortByAttack(ref minions, Sorting.SortMode.Descending); // Loop through all minions that can attack.. foreach (var item in minions) { if (HRCardManager.CanAttackWithCard(item.GetCard())) { if (Limit == -1) { result.Attack += item.GetATK(); result.Cards.Add(item); } else if (result.Cards.Count + 1 == Limit) { // Try to find a combination that matches... if (result.Attack + item.GetATK() >= RequiredAttack) { result.Attack += item.GetATK(); result.Cards.Add(item); } } else { result.Attack += item.GetATK(); result.Cards.Add(item); } } } if (result.Attack < RequiredAttack) { int remainingMana = Player.GetNumAvailableResources(); // Check other resources that can deal damage. // Deal damage with hero power? if (Player.GetHeroPower().GetATK() > 0) { if (Player.GetHeroPower().GetCost() <= remainingMana) { result.Attack += Player.GetHeroPower().GetATK(); result.Cost += Player.GetHeroPower().GetCost(); result.Cards.Add(Player.GetHeroPower()); remainingMana -= Player.GetHeroPower().GetCost(); } } // Hero Card most times: Weapons and other special stuff. if (Player.HasWeapon() && Player.GetWeaponCard().GetEntity().GetATK() > 0 && Player.GetWeaponCard().GetEntity().CanAttack() && Player.GetWeaponCard().GetEntity().GetCost() <= remainingMana) { if (HRCardManager.CanAttackWithCard(Player.GetHero().GetCard())) { result.Attack += Player.GetWeaponCard().GetEntity().GetATK(); result.Cost += Player.GetWeaponCard().GetEntity().GetCost(); result.Cards.Add(Player.GetWeaponCard().GetEntity()); remainingMana -= Player.GetHero().GetCost(); } } // Remaining cards on hand? List<HRCard> playerHand = HRCard.GetCards(Player, HRCardZone.HAND); foreach (var item in playerHand) { if ((item.GetEntity().IsSpell() || (item.GetEntity().IsMinion() && item.GetEntity().HasCharge())) && item.GetEntity().GetATK() > 0) { int cost = item.GetEntity().GetCost(); if (cost <= remainingMana) { result.Attack += item.GetEntity().GetATK(); result.Cost += cost; result.Cards.Add(item.GetEntity()); remainingMana -= cost; } } } } return result; }