/// <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 (this.isgoingtoconcede) { if (HREngine.API.Utilities.HRSettings.Get.SelectedGameMode == HRGameMode.ARENA) { this.isgoingtoconcede = false; } else { return(new HREngine.API.Actions.ConcedeAction()); } } if (Settings.Instance.passiveWaiting && sf.waitingForSilver) { if (!this.sf.readActionFile(true)) { return(new HREngine.API.Actions.MakeNothingAction()); } } if (Settings.Instance.learnmode && (HRBattle.IsInTargetMode() || HRChoice.IsChoiceActive())) { return(new HREngine.API.Actions.MakeNothingAction()); } if (HRBattle.IsInTargetMode() && dirtytarget >= 0) { Helpfunctions.Instance.ErrorLog("dirty targeting..."); HREntity target = getEntityWithNumber(dirtytarget); dirtytarget = -1; return(new HREngine.API.Actions.TargetAction(target)); } if (HRChoice.IsChoiceActive()) { if (this.dirtychoice >= 1) { List <HREntity> choices = HRChoice.GetChoiceCards(); int choice = this.dirtychoice; this.dirtychoice = -1; string ccId = this.choiceCardId; this.choiceCardId = ""; HREntity target = choices[choice - 1]; if (ccId == "EX1_160") { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "EX1_160b") { target = hre; } if (choice == 2 && hre.GetCardId() == "EX1_160a") { target = hre; } } } if (ccId == "NEW1_008") { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "NEW1_008a") { target = hre; } if (choice == 2 && hre.GetCardId() == "NEW1_008b") { target = hre; } } } if (ccId == "EX1_178") { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "EX1_178a") { target = hre; } if (choice == 2 && hre.GetCardId() == "EX1_178b") { target = hre; } } } if (ccId == "EX1_573") { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "EX1_573a") { target = hre; } if (choice == 2 && hre.GetCardId() == "EX1_573b") { target = hre; } } } if (ccId == "EX1_165")//druid of the claw { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "EX1_165t1") { target = hre; } if (choice == 2 && hre.GetCardId() == "EX1_165t2") { target = hre; } } } if (ccId == "EX1_166")//keeper of the grove { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "EX1_166a") { target = hre; } if (choice == 2 && hre.GetCardId() == "EX1_166b") { target = hre; } } } if (ccId == "EX1_155") { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "EX1_155a") { target = hre; } if (choice == 2 && hre.GetCardId() == "EX1_155b") { target = hre; } } } if (ccId == "EX1_164") { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "EX1_164a") { target = hre; } if (choice == 2 && hre.GetCardId() == "EX1_164b") { target = hre; } } } if (ccId == "New1_007")//starfall { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "New1_007b") { target = hre; } if (choice == 2 && hre.GetCardId() == "New1_007a") { target = hre; } } } if (ccId == "EX1_154")//warth { foreach (HREntity hre in choices) { if (choice == 1 && hre.GetCardId() == "EX1_154a") { target = hre; } if (choice == 2 && hre.GetCardId() == "EX1_154b") { target = hre; } } } Helpfunctions.Instance.logg("chooses the card: " + target.GetCardId()); return(new HREngine.API.Actions.ChoiceAction(target)); } else { //Todo: ultimate tracking-simulation! List <HREntity> choices = HRChoice.GetChoiceCards(); Random r = new Random(); int choice = r.Next(0, choices.Count); Helpfunctions.Instance.logg("chooses a random card"); return(new HREngine.API.Actions.ChoiceAction(choices[choice])); } } bool templearn = sf.updateEverything(behave, Settings.Instance.useExternalProcess, Settings.Instance.passiveWaiting); if (templearn == true) { Settings.Instance.printlearnmode = true; } if (Settings.Instance.passiveWaiting && sf.waitingForSilver) { return(new HREngine.API.Actions.MakeNothingAction()); } if (Settings.Instance.learnmode) { if (Settings.Instance.printlearnmode) { Ai.Instance.simmulateWholeTurnandPrint(); } Settings.Instance.printlearnmode = false; return(new HREngine.API.Actions.MakeNothingAction()); } if (Ai.Instance.bestmoveValue <= -900 && Settings.Instance.enemyConcede) { return(new HREngine.API.Actions.ConcedeAction()); } Action moveTodo = Ai.Instance.bestmove; if (moveTodo == null || moveTodo.actionType == actionEnum.endturn) { Helpfunctions.Instance.ErrorLog("end turn"); return(null); } Helpfunctions.Instance.ErrorLog("play action"); moveTodo.print(); if (moveTodo.actionType == actionEnum.playcard) { HRCard cardtoplay = getCardWithNumber(moveTodo.card.entity); if (moveTodo.target != null) { HREntity target = getEntityWithNumber(moveTodo.target.entitiyID); Helpfunctions.Instance.ErrorLog("play: " + cardtoplay.GetEntity().GetName() + " target: " + target.GetName()); Helpfunctions.Instance.logg("play: " + cardtoplay.GetEntity().GetName() + " target: " + target.GetName() + " choice: " + moveTodo.druidchoice); if (moveTodo.druidchoice >= 1) { this.dirtytarget = moveTodo.target.entitiyID; this.dirtychoice = moveTodo.druidchoice; //1=leftcard, 2= rightcard this.choiceCardId = moveTodo.card.card.cardIDenum.ToString(); } if (moveTodo.card.card.type == CardDB.cardtype.MOB) { return(new HREngine.API.Actions.PlayCardAction(cardtoplay, target, moveTodo.place)); } return(new HREngine.API.Actions.PlayCardAction(cardtoplay, target)); } else { Helpfunctions.Instance.ErrorLog("play: " + cardtoplay.GetEntity().GetName() + " target nothing"); Helpfunctions.Instance.logg("play: " + cardtoplay.GetEntity().GetName() + " choice: " + moveTodo.druidchoice); if (moveTodo.druidchoice >= 1) { this.dirtychoice = moveTodo.druidchoice; //1=leftcard, 2= rightcard this.choiceCardId = moveTodo.card.card.cardIDenum.ToString(); } if (moveTodo.card.card.type == CardDB.cardtype.MOB) { return(new HREngine.API.Actions.PlayCardAction(cardtoplay, null, moveTodo.place)); } return(new HREngine.API.Actions.PlayCardAction(cardtoplay)); } } if (moveTodo.actionType == actionEnum.attackWithMinion) { HREntity attacker = getEntityWithNumber(moveTodo.own.entitiyID); HREntity target = getEntityWithNumber(moveTodo.target.entitiyID); Helpfunctions.Instance.ErrorLog("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.actionType == actionEnum.attackWithHero) { HREntity attacker = getEntityWithNumber(moveTodo.own.entitiyID); HREntity target = getEntityWithNumber(moveTodo.target.entitiyID); this.dirtytarget = moveTodo.target.entitiyID; Helpfunctions.Instance.ErrorLog("heroattack: " + attacker.GetName() + " target: " + target.GetName()); Helpfunctions.Instance.logg("heroattack: " + attacker.GetName() + " target: " + target.GetName()); if (HRPlayer.GetLocalPlayer().HasWeapon()) { Helpfunctions.Instance.ErrorLog("hero attack with weapon"); return(new HREngine.API.Actions.AttackAction(HRPlayer.GetLocalPlayer().GetWeaponCard().GetEntity(), target)); } Helpfunctions.Instance.ErrorLog("hero attack without weapon"); //Helpfunctions.Instance.ErrorLog("attacker entity: " + HRPlayer.GetLocalPlayer().GetHero().GetEntityId()); //return new HREngine.API.Actions.AttackAction(HRPlayer.GetLocalPlayer().GetHero(), target); return(new HREngine.API.Actions.PlayCardAction(HRPlayer.GetLocalPlayer().GetHeroCard(), target)); } if (moveTodo.actionType == actionEnum.useHeroPower) { HRCard cardtoplay = HRPlayer.GetLocalPlayer().GetHeroPower().GetCard(); if (moveTodo.target != null) { HREntity target = getEntityWithNumber(moveTodo.target.entitiyID); Helpfunctions.Instance.ErrorLog("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 { Helpfunctions.Instance.ErrorLog("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) { Helpfunctions.Instance.ErrorLog(Exception.Message); Helpfunctions.Instance.ErrorLog(Environment.StackTrace); if (Settings.Instance.learnmode) { return(new HREngine.API.Actions.MakeNothingAction()); } } 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); }