private void OnHearthrockWindow(int windowID) { int width = HearthrockWidth - UnitySpacing * 2 - UnityBorderSize * 2; int offset_left = UnitySpacing + UnityBorderSize; int button_offset_top = UnityBorderSize + UnitySpacing + UnityTitleHeight; int select_offset_top = button_offset_top + UnityButtonHeight + UnitySpacing; int select_height = HearthrockHeight - select_offset_top - UnityBorderSize - UnitySpacing; HearthrockMode = GUI.SelectionGrid(new Rect(offset_left, select_offset_top, width, select_height), HearthrockMode, HearthrockModes, 2); if (GUI.Button(new Rect(offset_left, button_offset_top, width, UnityButtonHeight), HearthrockStates[HearthrockState])) { if (HearthrockState == 0 || HearthrockState == 2) { HearthrockState = 1; HearthrockEngine.Message("Hearthrock Started"); } else { HearthrockState = 2; HearthrockEngine.Message("Hearthrock Paused"); } Engine.Clear(); } }
public static RockAction RockIt() { RockAction action = new RockAction(); Player player = GameState.Get().GetFriendlySidePlayer(); Player player_enemy = GameState.Get().GetFirstOpponentPlayer(GameState.Get().GetFriendlySidePlayer()); Card hero = player.GetHeroCard(); Card hero_enemy = player_enemy.GetHeroCard(); int resource = player.GetNumAvailableResources(); List <Card> curSecretCardList = player.GetSecretZone().GetCards(); List <Card> crads = player.GetHandZone().GetCards(); foreach (Card card in crads) { HearthrockEngine.Log(card.GetEntity().GetName() + " :=: " + card.GetEntity().GetCardId()); } List <Card> minions = player.GetBattlefieldZone().GetCards(); List <Card> minions_enemy = player_enemy.GetBattlefieldZone().GetCards(); Card heropower = player.GetHeroPowerCard(); // find best match taunt attacker List <Card> minion_taunts_enemy = new List <Card>(); List <Card> minion_dangerous_enemy = new List <Card>(); List <Card> minion_notaunts = new List <Card>(); List <Card> minion_taunts = new List <Card>(); List <Card> minion_attacker = new List <Card>(); int attack_count_enemy = 0; foreach (Card minion_enemy in minions_enemy) { if (!minion_enemy.GetEntity().CanAttack()) { continue; } attack_count_enemy += minion_enemy.GetEntity().GetATK(); if (minion_enemy.GetEntity().HasWindfury()) { attack_count_enemy += minion_enemy.GetEntity().GetATK(); } } attack_count_enemy += hero_enemy.GetEntity().GetATK(); int my_army_attack_count = 0; foreach (Card card in minions) { if (isActive(card)) { my_army_attack_count += card.GetEntity().GetATK(); } } int player_enemy_defense = 0; foreach (Card card_oppo in minions_enemy) { if (card_oppo.GetEntity().CanBeAttacked() && !card_oppo.GetEntity().IsStealthed()) { if (card_oppo.GetEntity().HasTaunt()) { player_enemy_defense += card_oppo.GetEntity().GetCurrentHealth(); } } } string killMessage = " enemy health: " + hero_enemy.GetEntity().GetCurrentHealth().ToString(); killMessage += " enemy mionion defense: " + player_enemy_defense.ToString(); killMessage += " my total attack : " + my_army_attack_count.ToString(); bool canKill = (hero_enemy.GetEntity().GetCurrentHealth() + player_enemy_defense < my_army_attack_count); killMessage += " canKill: " + canKill.ToString(); HearthrockEngine.Log(killMessage); foreach (Card card_oppo in minions_enemy) { if (card_oppo.GetEntity().CanBeAttacked() && !card_oppo.GetEntity().IsStealthed()) { if (card_oppo.GetEntity().HasTaunt()) { minion_taunts_enemy.Add(card_oppo); } else if (IsEnimyDangerous(card_oppo.GetEntity())) { if (!canKill) { minion_dangerous_enemy.Add(card_oppo); } } } } foreach (Card card in minions) { if (card.GetEntity().CanAttack() && !card.GetEntity().IsExhausted() && !card.GetEntity().IsFrozen() && !card.GetEntity().IsAsleep() && card.GetEntity().GetATK() > 0) { if (card.GetEntity().HasTaunt()) { minion_taunts.Add(card); } else { minion_notaunts.Add(card); } minion_attacker.Add(card); } } minions_enemy.Sort(new CardPowerComparer()); minion_taunts_enemy.Sort(new CardPowerComparer()); minion_notaunts.Sort(new CardPowerComparer()); minion_notaunts.Reverse(); minion_taunts.Sort(new CardPowerComparer()); minion_taunts.Reverse(); minion_attacker.Sort(new CardPowerComparer()); minion_attacker.Reverse(); // PlayEmergencyCard RockAction action_temp = PlayEmergencyCard(resource, crads, hero, hero_enemy, attack_count_enemy); if (action_temp != null) { action = action_temp; return(action); } // if coin necessory Card coin_card = null; bool need_coin_card = false; foreach (Card card in crads) { if (card.GetEntity().GetCardId() == "GAME_005") { coin_card = card; continue; } if (resource == card.GetEntity().GetCost() - 1) { need_coin_card = true; } } // use coin if (coin_card != null && need_coin_card) { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = coin_card; return(action); } // PlayEmergencyCard again action_temp = PlayEmergencyCard(resource, crads, hero, hero_enemy, attack_count_enemy); if (action_temp != null) { action = action_temp; return(action); } // use as much spell as possible foreach (Card card in crads) { // but not the coin if (card.GetEntity().GetCardId() == "GAME_005") { continue; } if (resource < card.GetEntity().GetCost()) { continue; } //if (card.GetEntity().IsSpell() || card.GetEntity().IsWeapon()) //{ // action.type = HEARTHROCK_ACTIONTYPE.PLAY; // action.card1 = card; // return action; //} // play 动物伙伴 if (card.GetEntity().GetCardId() == "NEW1_031") { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } if (card.GetEntity().GetCardId() == "OG_211") { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } if (card.GetEntity().HasBattlecry()) { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } //if (card.GetEntity().IsSpell()) { // action.type = HEARTHROCK_ACTIONTYPE.PLAY; // action.card1 = card; // return action; //} if (player.GetWeaponCard() == null) { // 鹰角弓 if (card.GetEntity().GetCardId() == "EX1_536") { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } } // 关门放狗 if (card.GetEntity().GetCardId() == "EX1_538") { if (minions_enemy.Count > 0) { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } } // 快速射击 if (card.GetEntity().GetCardId() == "BRM_013") { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } // 杀戮命令 if (card.GetEntity().GetCardId() == "EX1_539") { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } } // find a minion which can use all resource foreach (Card card in crads) { if (resource < card.GetEntity().GetCost()) { continue; } if (card.GetEntity().IsMinion() && GameState.Get().GetFriendlySidePlayer().GetBattlefieldZone().GetCards().Count < 6 && (card.GetEntity().GetCost() == resource || ((card.GetEntity().GetCost() == resource - 2) && HeroSpellReady))) { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } } // find a minion which can use all resource foreach (Card card in crads) { if (resource < card.GetEntity().GetCost()) { continue; } if (card.GetEntity().IsMinion() && GameState.Get().GetFriendlySidePlayer().GetBattlefieldZone().GetCards().Count < 6) { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } if (card.GetEntity().IsMinion() && GameState.Get().GetFriendlySidePlayer().GetBattlefieldZone().GetCards().Count == 6) { if (card.GetEntity().HasCharge() || card.GetEntity().HasTaunt()) { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } } } // play 奥秘 foreach (Card card in crads) { if (resource < card.GetEntity().GetCost()) { continue; } if (card.GetEntity().IsSecret()) { bool tmpCheck = false; foreach (Card secretCard in player.GetSecretZone().GetCards()) { if (secretCard.GetEntity().GetCardId().Equals(card.GetEntity().GetCardId())) { tmpCheck = true; break; } } if (!tmpCheck) { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = card; return(action); } } } // begin attack { // deal with his taunts // PlayKill notaunts > taunts action_temp = PlayKill(minion_taunts_enemy, minion_notaunts); if (action_temp != null) { action = action_temp; return(action); } // PlayKill taunts > taunts action_temp = PlayKill(minion_taunts_enemy, minion_taunts); if (action_temp != null) { action = action_temp; return(action); } //deal damage with no taunt foreach (Card card_oppo in minion_taunts_enemy) { foreach (Card card in minion_notaunts) { action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = card; action.card2 = card_oppo; return(action); } } //deal damage with taunt foreach (Card card_oppo in minion_taunts_enemy) { foreach (Card card in minion_taunts) { action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = card; action.card2 = card_oppo; return(action); } } } { // deal with his dangerous // TODO: should check maybe i can kill him // PlayKill notaunts > dangerous action_temp = PlayKill(minion_dangerous_enemy, minion_notaunts); if (action_temp != null) { action = action_temp; return(action); } //deal damage with no taunt foreach (Card card_oppo in minion_dangerous_enemy) { foreach (Card card in minion_notaunts) { action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = card; action.card2 = card_oppo; return(action); } } } { // deal with enemy depends on my health // TODO: should check maybe i can kill him // no taunt, but in danger if (minion_taunts_enemy.Count == 0 && (hero.GetEntity().GetHealth() - attack_count_enemy) < 10) { foreach (Card card_oppo in minions_enemy) { // find dangerous card if (card_oppo.GetEntity().GetATK() - card_oppo.GetEntity().GetHealth() > 3) { foreach (Card card in minion_attacker) { // if can kill, kill if (card.GetEntity().GetATK() >= card_oppo.GetEntity().GetHealth()) { action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = card; action.card2 = card_oppo; return(action); } } } } } // no taunt, but in great danger if (minion_taunts_enemy.Count == 0 && (hero.GetEntity().GetHealth() - attack_count_enemy) < 0) { foreach (Card card_oppo in minions_enemy) { // find dangerous card if (card_oppo.GetEntity().GetATK() - card_oppo.GetEntity().GetHealth() > 1) { foreach (Card card in minion_attacker) { if (card.GetEntity().GetATK() > card_oppo.GetEntity().GetATK()) { continue; } // if can kill, kill if (card.GetEntity().GetATK() >= card_oppo.GetEntity().GetHealth()) { action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = card; action.card2 = card_oppo; return(action); } } } } } } // END deal with enemy depends on my health // attack his face! foreach (Card card in minions) { if (card.GetEntity().CanAttack() && !card.GetEntity().IsExhausted() && !card.GetEntity().IsFrozen() && !card.GetEntity().IsAsleep() && card.GetEntity().GetATK() > 0) { foreach (Card card_oppo in minions_enemy) { // for bug, should noy run if (card_oppo.GetEntity().HasTaunt()) { action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = card; action.card2 = card_oppo; return(action); } } action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = card; action.card2 = player_enemy.GetHeroCard(); return(action); } } // deal with hero weapon and atk HearthrockEngine.Log("HasWeapon " + player.HasWeapon()); if (player.HasWeapon()) { HearthrockEngine.Log("HasWeapon CanAttack " + player.GetWeaponCard().GetEntity().CanAttack()); } if (minion_taunts_enemy.Count == 0 && player.HasWeapon() && player.GetWeaponCard().GetEntity().CanAttack() && !player.GetWeaponCard().GetEntity().IsFrozen() && !player.GetWeaponCard().GetEntity().IsExhausted() && !player.GetWeaponCard().GetEntity().IsAsleep()) { action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = player.GetWeaponCard(); action.card2 = player_enemy.GetHeroCard(); return(action); } Entity me = player.GetHeroCard().GetEntity(); if (minion_taunts_enemy.Count == 0 && me.CanAttack() && me.GetATK() > 0 && !me.IsFrozen() && !me.IsExhausted() && !me.IsAsleep()) { action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = player.GetHeroCard(); action.card2 = player_enemy.GetHeroCard(); return(action); } if (resource >= 2 && HeroSpellReady) { HeroSpellReady = false; TAG_CLASS hero_class = player.GetHeroCard().GetEntity().GetClass(); switch (hero_class) { case TAG_CLASS.WARLOCK: if (crads.Count > 8) { return(action); } if (hero.GetEntity().GetCurrentHealth() < 5) { return(action); } else if (hero.GetEntity().GetCurrentHealth() < 12) { if (attack_count_enemy + 2 > hero.GetEntity().GetCurrentHealth()) { return(action); } else { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = heropower; return(action); } } else { action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = heropower; return(action); } case TAG_CLASS.HUNTER: case TAG_CLASS.DRUID: case TAG_CLASS.PALADIN: case TAG_CLASS.ROGUE: case TAG_CLASS.SHAMAN: case TAG_CLASS.WARRIOR: action.type = HEARTHROCK_ACTIONTYPE.PLAY; action.card1 = heropower; return(action); case TAG_CLASS.PRIEST: action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = heropower; action.card2 = player.GetHeroCard(); return(action); case TAG_CLASS.MAGE: action.type = HEARTHROCK_ACTIONTYPE.ATTACK; action.card1 = heropower; action.card2 = player_enemy.GetHeroCard(); return(action); default: break; } } return(action); }