public static HREngine.Private.HREngineRules GetRulesForCard(String CardID) { if (!HasRule(CardID)) { return(null); } try { string strFilePath = String.Format("{0}{1}.xml", HRSettings.Get.CustomRuleFilePath, CardID.ToUpper()); byte[] buffer = File.ReadAllBytes(strFilePath); if (buffer.Length > 0) { XmlSerializer serialzer = new XmlSerializer(typeof(HREngine.Private.HREngineRules)); object result = serialzer.Deserialize(new MemoryStream(buffer)); if (result != null) { return((HREngine.Private.HREngineRules)result); } } } catch (Exception e) { HRLog.Write("Exception when deserialize XML Rule."); HRLog.Write(e.Message); } return(null); }
private HREngine.API.Actions.ActionBase HandleBattleMulliganPhase() { HRLog.Write("handle mulligan"); if (HRMulligan.IsMulliganActive()) { var list = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND); foreach (var item in list) { if (item.GetEntity().GetCost() >= 4) { HRLog.Write("Rejecting Mulligan Card " + item.GetEntity().GetName() + " because it cost is >= 4."); HRMulligan.ToggleCard(item); } if (item.GetEntity().GetCardId() == "EX1_308" || item.GetEntity().GetCardId() == "EX1_622" || item.GetEntity().GetCardId() == "EX1_005") { HRLog.Write("Rejecting Mulligan Card " + item.GetEntity().GetName() + " because it is soulfire or shadow word: death"); HRMulligan.ToggleCard(item); } } sf.setnewLoggFile(); return(null); //HRMulligan.EndMulligan(); } return(null); }
public void updateEverything(BotBase botbase) { HRPlayer ownPlayer = HRPlayer.GetLocalPlayer(); HRPlayer enemyPlayer = HRPlayer.GetEnemyPlayer(); ownPlayerController = ownPlayer.GetHero().GetControllerId(); //ownPlayer.GetHero().GetControllerId() // create hero + minion data getHerostuff(); getMinions(); getHandcards(); // send ai the data: Hrtprozis.Instance.setOwnPlayer(ownPlayerController); Handmanager.Instance.setOwnPlayer(ownPlayerController); Hrtprozis.Instance.updatePlayer(this.ownMaxMana, this.currentMana, this.cardsPlayedThisTurn, this.numMinionsPlayedThisTurn, this.ueberladung, ownPlayer.GetHero().GetEntityId(), enemyPlayer.GetHero().GetEntityId()); Hrtprozis.Instance.updateOwnHero(this.ownHeroWeapon, this.heroWeaponAttack, this.heroWeaponDurability, this.heroImmuneToDamageWhileAttacking, this.heroAtk, this.heroHp, this.heroDefence, this.heroname, this.ownheroisread, this.ownheroAlreadyAttacked, this.herofrozen, this.heroAbility, this.ownAbilityisReady); Hrtprozis.Instance.updateEnemyHero(this.enemyHeroWeapon, this.enemyWeaponAttack, this.enemyWeaponDurability, this.enemyAtk, this.enemyHp, this.enemyDefence, this.enemyHeroname, this.enemyfrozen); Hrtprozis.Instance.updateMinions(this.ownMinions, this.enemyMinions); Handmanager.Instance.setHandcards(this.handCards, this.anzcards, this.enemyAnzCards); // print data Hrtprozis.Instance.printHero(); Hrtprozis.Instance.printOwnMinions(); Hrtprozis.Instance.printEnemyMinions(); Handmanager.Instance.printcards(); // calculate stuff HRLog.Write("calculating stuff..."); Ai.Instance.dosomethingclever(botbase); }
protected virtual ActionBase PlayCardsToField() { // Get all available cards... List <HRCard> availableCards = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND); if (availableCards.Count > 0) { HRCard coin = null; foreach (var item in availableCards) { #region Skip The Coin string cardID = item.GetEntity().GetCardId(); if (cardID == "GAME_005" || cardID == "GAME_005e") { coin = item; continue; } #endregion if (item.GetEntity().GetCost() <= HRPlayer.GetLocalPlayer().GetNumAvailableResources()) { if (HRBattle.CanUseCard(item.GetEntity()) && HRCardManager.IsCardAllowedByRule(item)) { return(new PlayCardAction(item)); } } } #region The Coin Feature // Feature: The Coin // https://github.com/juce-mmocrawlerbots/HREngine/issues/13 if (coin != null) { foreach (var card in availableCards) { if (card.GetEntity().GetCardId() != coin.GetEntity().GetCardId()) { if (card.GetEntity().IsMinion() || card.GetEntity().IsSpell() || (!HRPlayer.GetLocalPlayer().HasWeapon() && card.GetEntity().IsWeapon())) { if (card.GetEntity().GetCost() <= (HRPlayer.GetLocalPlayer().GetNumAvailableResources() + 1)) { HRLog.Write( String.Format("Spawn [{0}] and then [{1}]", coin.GetEntity().GetName(), card.GetEntity().GetName())); NextFixedAction = new PlayCardAction(card); return(new PlayCardAction(coin)); } } } } } #endregion } return(null); }
public Silverfish() { HRLog.Write("init Silverfish"); sttngs.setFilePath(this.path); /*OnBattleStateUpdate = UpdateBattleState; * OnMulliganStateUpdate = UpdateMulliganState; * RejectedCardList = new Dictionary<int, HRCard>(); * NextFixedAction = null;*/ }
public SmartCC() { try { string path = (HRSettings.Get.CustomRuleFilePath).Split(new string[] { "Common" }, StringSplitOptions.RemoveEmptyEntries)[0]; CardTemplate.DatabasePath = path; CardTemplate.LoadAll(); OnBattleStateUpdate = HandleOnBattleStateUpdate; OnMulliganStateUpdate = HandleBattleMulliganPhase; // Use ProcessStartInfo class ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = false; startInfo.UseShellExecute = false; startInfo.FileName = CardTemplate.DatabasePath + "" + Path.DirectorySeparatorChar + "Bots" + Path.DirectorySeparatorChar + "SmartCC" + Path.DirectorySeparatorChar + "SmartCompiler.exe"; startInfo.WindowStyle = ProcessWindowStyle.Hidden; StreamReader str = new StreamReader(CardTemplate.DatabasePath + "" + Path.DirectorySeparatorChar + "Bots" + Path.DirectorySeparatorChar + "SmartCC" + Path.DirectorySeparatorChar + "Config" + Path.DirectorySeparatorChar + "useProfiles"); startInfo.Arguments = "\"" + CardTemplate.DatabasePath + Path.DirectorySeparatorChar + "\"" + " " + str.ReadLine(); str.Close(); try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close. using (Process exeProcess = Process.Start(startInfo)) { exeProcess.WaitForExit(); } } catch { Console.WriteLine("Compiler error"); } } catch (Exception Exception) { HRLog.Write(Exception.Message); HRLog.Write(Environment.StackTrace); } ValuesInterface.LoadValuesFromFile(); ProfileInterface.LoadBehavior(); }
private HREngine.API.Actions.ActionBase HandleBattleMulliganPhase() { HRLog.Write("handle mulligan"); if (HRMulligan.IsMulliganActive()) { var list = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND); foreach (var item in list) { if (item.GetEntity().GetCost() >= 4) { HRLog.Write("Rejecting Mulligan Card " + item.GetEntity().GetName() + " because it cost is >= 4."); HRMulligan.ToggleCard(item); } } return(null); //HRMulligan.EndMulligan(); } return(null); }
public Silverfish() { HRLog.Write("init Silverfish"); string path = (HRSettings.Get.CustomRuleFilePath).Remove(HRSettings.Get.CustomRuleFilePath.Length - 13) + "UltimateLogs" + System.IO.Path.DirectorySeparatorChar; System.IO.Directory.CreateDirectory(path); sttngs.setFilePath((HRSettings.Get.CustomRuleFilePath).Remove(HRSettings.Get.CustomRuleFilePath.Length - 13)); if (!singleLog) { sttngs.setLoggPath(path); } else { sttngs.setLoggPath((HRSettings.Get.CustomRuleFilePath).Remove(HRSettings.Get.CustomRuleFilePath.Length - 13)); sttngs.setLoggFile("UILogg.txt"); Helpfunctions.Instance.createNewLoggfile(); } /*OnBattleStateUpdate = UpdateBattleState; * OnMulliganStateUpdate = UpdateMulliganState; * RejectedCardList = new Dictionary<int, HRCard>(); * NextFixedAction = null;*/ }
/// <summary> /// [EN] /// This handler is executed when the local player turn is active. /// /// [DE] /// Dieses Event wird ausgelöst wenn der Spieler am Zug ist. /// </summary> private HREngine.API.Actions.ActionBase HandleOnBattleStateUpdate() { try { if (HRBattle.IsInTargetMode() && dirtytarget >= 0) { HRLog.Write("dirty targeting..."); HREntity target = getEntityWithNumber(dirtytarget); dirtytarget = -1; return(new HREngine.API.Actions.TargetAction(target)); } //SafeHandleBattleLocalPlayerTurnHandler(); sf.updateEverything(this); Action moveTodo = Ai.Instance.bestmove; if (moveTodo == null) { HRLog.Write("end turn"); return(null); } HRLog.Write("play action"); moveTodo.print(); if (moveTodo.cardplay) { HRCard cardtoplay = getCardWithNumber(moveTodo.cardEntitiy); if (moveTodo.enemytarget >= 0) { HREntity target = getEntityWithNumber(moveTodo.enemyEntitiy); HRLog.Write("play: " + cardtoplay.GetEntity().GetName() + " target: " + target.GetName()); Helpfunctions.Instance.logg("play: " + cardtoplay.GetEntity().GetName() + " target: " + target.GetName()); if (moveTodo.handcard.card.type == CardDB.cardtype.MOB) { return(new HREngine.API.Actions.PlayCardAction(cardtoplay, target, moveTodo.owntarget + 1)); } return(new HREngine.API.Actions.PlayCardAction(cardtoplay, target)); } else { HRLog.Write("play: " + cardtoplay.GetEntity().GetName() + " target nothing"); if (moveTodo.handcard.card.type == CardDB.cardtype.MOB) { return(new HREngine.API.Actions.PlayCardAction(cardtoplay, null, moveTodo.owntarget + 1)); } return(new HREngine.API.Actions.PlayCardAction(cardtoplay)); } } if (moveTodo.minionplay) { HREntity attacker = getEntityWithNumber(moveTodo.ownEntitiy); HREntity target = getEntityWithNumber(moveTodo.enemyEntitiy); HRLog.Write("minion attack: " + attacker.GetName() + " target: " + target.GetName()); Helpfunctions.Instance.logg("minion attack: " + attacker.GetName() + " target: " + target.GetName()); return(new HREngine.API.Actions.AttackAction(attacker, target)); } if (moveTodo.heroattack) { HREntity attacker = getEntityWithNumber(moveTodo.ownEntitiy); HREntity target = getEntityWithNumber(moveTodo.enemyEntitiy); this.dirtytarget = moveTodo.enemyEntitiy; //HRLog.Write("heroattack: attkr:" + moveTodo.ownEntitiy + " defender: " + moveTodo.enemyEntitiy); HRLog.Write("heroattack: " + attacker.GetName() + " target: " + target.GetName()); Helpfunctions.Instance.logg("heroattack: " + attacker.GetName() + " target: " + target.GetName()); if (HRPlayer.GetLocalPlayer().HasWeapon()) { HRLog.Write("hero attack with weapon"); return(new HREngine.API.Actions.AttackAction(HRPlayer.GetLocalPlayer().GetWeaponCard().GetEntity(), target)); } HRLog.Write("hero attack without weapon"); //HRLog.Write("attacker entity: " + HRPlayer.GetLocalPlayer().GetHero().GetEntityId()); return(new HREngine.API.Actions.AttackAction(HRPlayer.GetLocalPlayer().GetHero(), target)); } if (moveTodo.useability) { HRCard cardtoplay = HRPlayer.GetLocalPlayer().GetHeroPower().GetCard(); if (moveTodo.enemytarget >= 0) { HREntity target = getEntityWithNumber(moveTodo.enemyEntitiy); HRLog.Write("use ablitiy: " + cardtoplay.GetEntity().GetName() + " target " + target.GetName()); Helpfunctions.Instance.logg("use ablitiy: " + cardtoplay.GetEntity().GetName() + " target " + target.GetName()); return(new HREngine.API.Actions.PlayCardAction(cardtoplay, target)); } else { HRLog.Write("use ablitiy: " + cardtoplay.GetEntity().GetName() + " target nothing"); Helpfunctions.Instance.logg("use ablitiy: " + cardtoplay.GetEntity().GetName() + " target nothing"); return(new HREngine.API.Actions.PlayCardAction(cardtoplay)); } } } catch (Exception Exception) { HRLog.Write(Exception.Message); HRLog.Write(Environment.StackTrace); } return(null); //HRBattle.FinishRound(); }
private HREngine.API.Actions.ActionBase HandleOnBattleStateUpdate() { if (SmartCc == null) { SmartCc = new Simulation(); SmartCc.CreateLogFolder(); SmartCc.TurnCount = 0; } while (true) { if (SmartCc.NeedCalculation) { HRLog.Write("Seed"); SeedSmartCc(); HRLog.Write("Simulation"); StreamReader str = new StreamReader(CardTemplate.DatabasePath + "Bots/SmartCC/Config/useThreading"); string use = str.ReadLine(); str.Close(); if (use == "true") { SmartCc.Simulate(true); } else { SmartCc.Simulate(false); } HRLog.Write("Simulation Done"); } if (SmartCc.ActionStack.Count <= 0) { HRLog.Write("Simulation didnt found any action"); } else { HRLog.Write("Actions :"); foreach (Action a in SmartCc.ActionStack) { HRLog.Write(a.ToString()); } } ActionToDo = SmartCc.GetNextAction(); try { switch (ActionToDo.Type) { case Action.ActionType.TARGET: HREntity targett = GetEntityById(ActionToDo.Target.Id); return(new HREngine.API.Actions.TargetAction(targett)); case Action.ActionType.CHOICE: if (HREngine.API.HRChoice.IsChoiceActive()) { List <HREntity> choices = HRChoice.GetChoiceCards(); if (SmartCc.ChoiceTarget != null) { SmartCc.InsertTargetAction(SmartCc.ChoiceTarget); SmartCc.ChoiceTarget = null; } return(new HREngine.API.Actions.ChoiceAction(choices[ActionToDo.Choice - 1])); } else { return(null); } case Action.ActionType.CAST_ABILITY: HRCard cardAbility = HRPlayer.GetLocalPlayer().GetHeroPower().GetCard(); if (ActionToDo.Target != null) { HREntity target = GetEntityById(ActionToDo.Target.Id); return(new HREngine.API.Actions.PlayCardAction(cardAbility, target, ActionToDo.Index + 1)); } else { return(new HREngine.API.Actions.PlayCardAction(cardAbility, null, ActionToDo.Index + 1)); } case Action.ActionType.CAST_WEAPON: case Action.ActionType.CAST_MINION: case Action.ActionType.CAST_SPELL: HRCard card = GetCardById(ActionToDo.Actor.Id); if (ActionToDo.Actor.HasChoices) { HRLog.Write("CARD HAS CHOICES"); if (ActionToDo.Target != null) { SmartCc.ChoiceTarget = ActionToDo.Target; } SmartCc.InsertChoiceAction(ActionToDo.Choice); } if (ActionToDo.Target != null) { HREntity target = GetEntityById(ActionToDo.Target.Id); return(new HREngine.API.Actions.PlayCardAction(card, target, ActionToDo.Index + 1)); } else { return(new HREngine.API.Actions.PlayCardAction(card, null, ActionToDo.Index + 1)); } case Action.ActionType.HERO_ATTACK: HREntity attackerAttack = GetEntityById(ActionToDo.Actor.Id); HREntity targetAttack = GetEntityById(ActionToDo.Target.Id); if (HRPlayer.GetLocalPlayer().HasWeapon()) { return(new HREngine.API.Actions.AttackAction(HRPlayer.GetLocalPlayer().GetWeaponCard().GetEntity(), targetAttack)); } return(new HREngine.API.Actions.AttackAction(HRPlayer.GetLocalPlayer().GetHero(), targetAttack)); case Action.ActionType.MINION_ATTACK: HREntity attackerAttackM = GetEntityById(ActionToDo.Actor.Id); HREntity targetAttackM = GetEntityById(ActionToDo.Target.Id); return(new HREngine.API.Actions.AttackAction(attackerAttackM, targetAttackM)); case Action.ActionType.END_TURN: HRLog.Write("EndTurn"); SmartCc.TurnCount++; SmartCc.SimuCount = 0; //HRBattle.FinishRound(); return(null); case Action.ActionType.RESIMULATE: HRLog.Write("Resimulate"); SmartCc.NeedCalculation = true; continue; } } catch (Exception Exception) { HRLog.Write(Exception.Message); HRLog.Write(Environment.StackTrace); return(null); } HRLog.Write("Action not handled"); return(null); } SmartCc.NeedCalculation = true; return(null); }
protected virtual HREngine.API.Actions.ActionBase UpdateBattleState() { HREngine.API.Actions.ActionBase result = NextFixedAction; if (result != null) { NextFixedAction = null; return(result); } // If a previous action was not handled successful the Bot remains // in target mode. // Target here with 'LastTarget'. If the specified Target is null // the bot automatically selects the best target based on a rule // or enemy condition. if (HRBattle.IsInTargetMode()) { HRLog.Write("Targeting..."); HREntity TargetEntity = PlayCardAction.LastTarget; if (TargetEntity == null) { HRCardManager.GetTargetForCard(PlayCardAction.LastPlayedCard); if (TargetEntity == null) { TargetEntity = GetNextAttackToAttack(); } } return(new TargetAction(TargetEntity)); } var localPlayerState = new PlayerState(HRPlayer.GetLocalPlayer()); var enemyPlayerState = new PlayerState(HRPlayer.GetEnemyPlayer()); // Fix: Druid: doesn't attack (and even other) // https://github.com/Hearthcrawler/HREngine/issues/40 if (!localPlayerState.Player.HasWeapon() && localPlayerState.Player.GetHero().CanAttack() && localPlayerState.Player.GetHero().GetATK() > 0 && HRBattle.CanUseCard(localPlayerState.Player.GetHero())) { return(new AttackAction( localPlayerState.Player.GetHero(), GetNextAttackToAttack())); } if (!enemyPlayerState.Player.HasATauntMinion()) { if (enemyPlayerState.Player.GetHero().CanBeAttacked()) { var current = PlayerState.GetPossibleAttack( localPlayerState.Player, enemyPlayerState.Health); if (current.Attack >= enemyPlayerState.Health) { if (current.Cards.Count > 0) { return(new AttackAction(current.Cards[0], enemyPlayerState.Player.GetHero())); } } } } if (IsDefaultHealingEnabled()) { if (localPlayerState.Player.GetHero().GetClass() == HRClass.PRIEST) { if (localPlayerState.Player.GetHeroPower().GetCost() <= localPlayerState.Mana) { if (localPlayerState.Health <= 17) { if (HRBattle.CanUseCard(localPlayerState.Player.GetHeroPower())) { return(new PlayCardAction( localPlayerState.Player.GetHeroPower().GetCard(), HRPlayer.GetLocalPlayer().GetHero())); } } else { // FIX: Heal minions if possible // https://github.com/Hearthcrawler/HREngine/issues/27 foreach (var item in localPlayerState.ReadyMinions) { if (item.GetRemainingHP() < item.GetHealth()) { // Heal damaged minions... if (HRBattle.CanUseCard(localPlayerState.Player.GetHeroPower())) { return(new PlayCardAction( localPlayerState.Player.GetHeroPower().GetCard(), HRPlayer.GetLocalPlayer().GetHero())); } } } } } } } // Next cards to push... if (HRPlayer.GetLocalPlayer().GetNumFriendlyMinionsInPlay() < 7) { result = PlayCardsToField(); if (result != null) { return(result); } else { // There are no cards to play.. if (localPlayerState.Player.GetHero().GetClass() == HRClass.WARLOCK) { // Can we use our hero power? // Warlock should not suicide. // FIX: https://github.com/Hearthcrawler/HREngine/issues/30 if (localPlayerState.Health >= 10) { // At least 3 mana left if we draw a card, okay? if (localPlayerState.Player.GetHeroPower().GetCost() + 3 <= localPlayerState.Mana) { if (HRBattle.CanUseCard(localPlayerState.Player.GetHeroPower())) { return(new PlayCardAction(localPlayerState.Player.GetHeroPower().GetCard())); } } } } } } // Priority: Always attack taunt minions first. if (enemyPlayerState.TauntMinions.Count > 0) { result = AttackTauntMinions(enemyPlayerState); if (result != null) { return(result); } } // Bot does not attack when there is stealthed taunts // Fix: https://github.com/Hearthcrawler/HREngine/issues/60 // If AttackTauntMinions() cannot attack because of stealthed - the action is null // and the bot should continue with default attack routine. // // Attack other minions or hero... result = Attack(); if (result != null) { return(result); } // Use Hero Power that make sense at last... if (localPlayerState.Player.GetHeroPower().GetCost() <= localPlayerState.Mana) { switch (localPlayerState.Player.GetHero().GetClass()) { case HRClass.DRUID: case HRClass.WARRIOR: case HRClass.MAGE: case HRClass.PALADIN: case HRClass.HUNTER: case HRClass.SHAMAN: case HRClass.ROGUE: { if (HRBattle.CanUseCard(localPlayerState.Player.GetHeroPower())) { return(new PlayCardAction(localPlayerState.Player.GetHeroPower().GetCard())); } } break; default: break; } } return(null); }
public BoardControl() { HRLog.Write("BoardControl custom class initialized."); }