protected override HREntity GetNextAttackToAttack() { var enemyState = new PlayerState(HRPlayer.GetEnemyPlayer()); if (enemyState.Minions > 0) { var list = enemyState.TauntMinions; if (list.Count == 0) { list = enemyState.AttackableMinions; } var sorting = new Sorting(); sorting.SortByHealth(ref list); foreach (var minion in list) { if (minion.CanBeAttacked()) return minion; } } return enemyState.Player.GetHero(); }
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; }
protected override ActionBase PlayCardsToField() { var EnemyState = new PlayerState(HRPlayer.GetEnemyPlayer()); var LocalState = new PlayerState(HRPlayer.GetLocalPlayer()); var Sorting = new Sorting(); // Retreive cards that can be played. List<HRCard> playableList = GetPlayableCards(HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND)); // Update list with conditions matching this custom class. GetConditionalCards(playableList, EnemyState, LocalState); // Sort by cost (ascending) Sorting.SortByCost(ref playableList); // Finally sort by custom priority playableList = SortByPriority(playableList); // Taunts if (LocalState.TauntMinions.Count == 0) { foreach (var minion in playableList) { HREntity Target = null; if (minion.GetEntity().HasTaunt() && CanHandleCard(minion, EnemyState, LocalState, ref Target)) { return new PlayCardAction(minion, Target); } } } // Charges foreach (var minion in playableList) { HREntity Target = null; if (minion.GetEntity().HasCharge() && CanHandleCard(minion, EnemyState, LocalState, ref Target)) { return new PlayCardAction(minion, Target); } } // All other available foreach (var minion in playableList) { HREntity Target = null; if (CanHandleCard(minion, EnemyState, LocalState, ref Target)) return new PlayCardAction(minion, Target); } // Use Hero Power that make sense at last... if (LocalState.Player.GetHeroPower().GetCost() <= LocalState.Mana) { if (LocalState.Player.GetHero().GetClass() == HRClass.HUNTER) { if (HRBattle.CanUseCard(LocalState.Player.GetHeroPower())) return new PlayCardAction(LocalState.Player.GetHeroPower().GetCard()); } } if (LocalState.Player.HasWeapon()) { if (HRBattle.CanUseCard(LocalState.Player.GetHeroCard().GetEntity())) { return new AttackAction(LocalState.Player.GetWeaponCard().GetEntity(), GetNextAttackToAttack()); } } return null; }
private List<HRCard> SortByPriority(List<HRCard> conditionalList) { var sorting = new Sorting(); sorting.SortByCost(ref conditionalList); var prioritySystem = new Dictionary<string, int>() { }; conditionalList.Sort(delegate(HRCard PartX, HRCard PartY) { int partXPriority = 99; int partYPriority = 99; if (prioritySystem.ContainsKey(PartX.GetEntity().GetCardId().ToUpper())) partXPriority = prioritySystem[PartX.GetEntity().GetCardId().ToUpper()]; if (prioritySystem.ContainsKey(PartY.GetEntity().GetCardId().ToUpper())) partYPriority = prioritySystem[PartY.GetEntity().GetCardId().ToUpper()]; if (partXPriority < partYPriority || partXPriority == partYPriority) return -1; return 1; }); return conditionalList; }