/// <summary>
        /// Function call Store Procedure GEtHREmployees
        /// </summary>
        /// <returns>All HR employees from HREmployee table</returns>
        #region HRTeam
        public HREntities GetHREmployee()
        {
            using (SqlConnection con = new SqlConnection
                                           (ConfigurationManager.ConnectionStrings["SQLProviderConnectionString"].ConnectionString))
            {
                HREntities employees = new HREntities();
                SqlCommand cmd       = new SqlCommand("dbo.GetHREmployees", con);

                try
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;;
                    con.Open();
                }
                catch (SqlException ex)
                {
                    Logger.Logger.Addlog(ex.Message + ',' + ex.Procedure + ',' + ex.LineNumber);
                }

                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    HREntity employee = new HREntity();
                    employee.Id       = Int32.Parse(reader[0].ToString());
                    employee.Name     = reader[1].ToString();
                    employee.LastName = reader[2].ToString();
                    employee.Phone    = reader[3].ToString();
                    employee.Address  = reader[4].ToString();
                    employees.ListOfEntities.Add(employee);
                }
                return(employees);
            }
        }
Esempio n. 2
0
        private List <HREntity> GetAllEntitiesOnBoard()
        {
            List <HREntity> ret = new List <HREntity>();

            HREntity HeroFriend = HRPlayer.GetLocalPlayer().GetHero();

            ret.Add(HeroFriend);

            HREntity HeroEnemy = HRPlayer.GetEnemyPlayer().GetHero();

            ret.Add(HeroEnemy);

            HREntity HeroAbility = HRPlayer.GetLocalPlayer().GetHeroPower();

            ret.Add(HeroAbility);

            foreach (HRCard c in HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.PLAY))
            {
                ret.Add(c.GetEntity());
            }
            foreach (HRCard c in HRCard.GetCards(HRPlayer.GetEnemyPlayer(), HRCardZone.PLAY))
            {
                ret.Add(c.GetEntity());
            }
            return(ret);
        }
Esempio n. 3
0
        private List <HREntity> getallEntitys()
        {
            List <HREntity> result         = new List <HREntity>();
            HREntity        ownhero        = HRPlayer.GetLocalPlayer().GetHero();
            HREntity        enemyhero      = HRPlayer.GetEnemyPlayer().GetHero();
            HREntity        ownHeroAbility = HRPlayer.GetLocalPlayer().GetHeroPower();
            List <HRCard>   list2          = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.PLAY);
            List <HRCard>   list3          = HRCard.GetCards(HRPlayer.GetEnemyPlayer(), HRCardZone.PLAY);

            result.Add(ownhero);
            result.Add(enemyhero);
            result.Add(ownHeroAbility);

            foreach (HRCard item in list2)
            {
                result.Add(item.GetEntity());
            }
            foreach (HRCard item in list3)
            {
                result.Add(item.GetEntity());
            }



            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// received id
        /// created HRentityId entity and send it to GEtEmployeeById function
        /// In the response, the function receives HREntity Model
        /// </summary>
        /// <param name="employee"></param>
        /// <returns>HREntity Model</returns>
        public Models.EmployeeHRModel GetHREmployeeById(HREntityID employee)
        {
            HREntity       deserialized = null;
            string         baseUrl      = ConfigurationManager.ConnectionStrings["HRServerName"].ConnectionString;
            HttpWebRequest request      = Utils.Functionals.Communicator.PostReques <HREntity>(baseUrl + DestinationNames.GetHREmployeeId, "POST", employee);

            try
            {
                WebResponse response = request.GetResponse();
                deserialized = Utils.Functionals.Communicator.ParseResponse <HREntity>(response.GetResponseStream());
            }
            catch (WebException ex)
            {
                Logger.Logger.Addlog(ex.InnerException + " " + ex.Message);
            }

            Models.EmployeeHRModel hrmodel = new EmployeeHRModel();
            hrmodel.Id           = deserialized.Id;
            hrmodel.Name         = deserialized.Name;
            hrmodel.LastName     = deserialized.LastName;
            hrmodel.Passport     = deserialized.Passport;
            hrmodel.Phone        = deserialized.Phone;
            hrmodel.SocialId     = deserialized.SocialId;
            hrmodel.Address      = deserialized.Address;
            hrmodel.DateOfBirth  = deserialized.DateOfBirth;
            hrmodel.DateOfHiring = deserialized.DateOfHiring;
            hrmodel.Description  = deserialized.Description;

            return(hrmodel);
        }
Esempio n. 5
0
        private void getHandcards()
        {
            handCards.Clear();
            this.anzcards      = 0;
            this.enemyAnzCards = 0;
            List <HRCard> list = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND);

            list.AddRange(HRCard.GetCards(HRPlayer.GetEnemyPlayer(), HRCardZone.HAND));

            foreach (HRCard item in list)
            {
                HREntity entitiy = item.GetEntity();

                if (entitiy.GetControllerId() == this.ownPlayerController && entitiy.GetZonePosition() >= 1) // own handcard
                {
                    CardDB.Card c = CardDB.Instance.getCardDataFromID(entitiy.GetCardId());
                    //c.cost = entitiy.GetCost();
                    //c.entityID = entitiy.GetEntityId();

                    Handmanager.Handcard hc = new Handmanager.Handcard();
                    hc.card     = c;
                    hc.position = entitiy.GetZonePosition();
                    hc.entity   = entitiy.GetEntityId();
                    hc.manacost = entitiy.GetCost();
                    handCards.Add(hc);
                    this.anzcards++;
                }

                if (entitiy.GetControllerId() != this.ownPlayerController && entitiy.GetZonePosition() >= 1) // enemy handcard
                {
                    this.enemyAnzCards++;
                }
            }
        }
        /// <summary>
        /// Function receive HREntity Datamodel and insert it into HREmployee table
        /// </summary>
        /// <param name="Datamodel HRntity employee"></param>
        /// <returns>Returned meesage about result </returns>
        public string AddHREmployee(HREntity employee)
        {
            using (SqlConnection con = new SqlConnection
                                           (ConfigurationManager.ConnectionStrings["SQLProviderConnectionString"].ConnectionString))
            {            //its called when  added new employee
                if (employee.Id == 0)
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("dbo.AddHREmployee", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Name", employee.Name);
                        cmd.Parameters.AddWithValue("@SurName", employee.LastName);
                        cmd.Parameters.AddWithValue("@Phone", employee.Phone);
                        cmd.Parameters.AddWithValue("@Address", employee.Address);
                        cmd.Parameters.AddWithValue("@DateOfBirth", employee.DateOfBirth.Date);
                        cmd.Parameters.AddWithValue("@Passport", employee.Passport);
                        cmd.Parameters.AddWithValue("@SocialCard", employee.SocialId);
                        cmd.Parameters.AddWithValue("@Description", employee.Description);
                        cmd.Parameters.AddWithValue("@DateOfHiring", employee.DateOfHiring.Date);
                        con.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException ex)
                    {
                        Logger.Logger.Addlog(ex.Message + ',' + ex.Procedure + ',' + ex.LineNumber);
                    };
                }

                //its call when updated existed employee
                else
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("dbo.UpdateHREmployee", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Id", employee.Id);
                        cmd.Parameters.AddWithValue("@Name", employee.Name);
                        cmd.Parameters.AddWithValue("@SurName", employee.LastName);
                        cmd.Parameters.AddWithValue("@Phone", employee.Phone);
                        cmd.Parameters.AddWithValue("@Address", employee.Address);
                        cmd.Parameters.AddWithValue("@DateOfBirth", employee.DateOfBirth);
                        cmd.Parameters.AddWithValue("@Passport", employee.Passport);
                        cmd.Parameters.AddWithValue("@SocialCard", employee.SocialId);
                        cmd.Parameters.AddWithValue("@Description", employee.Description);
                        cmd.Parameters.AddWithValue("@DateOfHiring", employee.DateOfHiring);
                        con.Open();

                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException ex)
                    {
                        Logger.Logger.Addlog(ex.Message + ',' + ex.Procedure + ',' + ex.LineNumber);
                    };
                }
            }
            return("Added");
        }
Esempio n. 7
0
        /// <summary>
        /// function received HREntityId entity ,deserialized it
        /// call GetHREmployeeByid function from sqlprovider
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns> serialized HREntity object</returns>
        public byte[] HRGetEmployeeById(byte[] bytes)
        {
            Stream          stream   = new MemoryStream(bytes);
            BinaryFormatter bf       = new BinaryFormatter();
            HREntityID      HRId     = (HREntityID)bf.Deserialize(stream);
            HREntity        employee = new HREntity();

            employee = _sqlProvider.GetHREmployeeById(HRId.Id);
            return(Utils.Functionals.Formatter.GetBinary <HREntity>(employee));
        }
Esempio n. 8
0
        private List <HRCard> GetConditionalCards(
            List <HRCard> playableList, PlayerState EnemyState, PlayerState LocalState)
        {
            List <HRCard> result = new List <HRCard>();

            foreach (var card in playableList)
            {
                HREntity tmp = null;
                if (CanHandleCard(card, EnemyState, LocalState, ref tmp))
                {
                    result.Add(card);
                }
            }
            return(result);
        }
Esempio n. 9
0
        private bool CanHandleCard(
            HRCard item, PlayerState EnemyState, PlayerState LocalState, ref HREntity Target)
        {
            string cardID = item.GetEntity().GetCardId().ToUpper();

            switch (cardID)
            {
            case "CS2_122": // "Raid Leader"
                return(LocalState.Minions > 0);

            case "EX1_066": // "Acidic Swamp Ooze"
                return(EnemyState.Player.HasWeapon() || LocalState.Minions < EnemyState.Minions);

            default:
                break;
            }
            return(true);
        }
Esempio n. 10
0
        protected virtual ActionBase Attack()
        {
            HREntity target = GetNextAttackToAttack();

            if (target != null)
            {
                var current = PlayerState.GetPossibleAttack(
                    HRPlayer.GetLocalPlayer(),
                    target.GetRemainingHP() + target.GetArmor());

                if (current.Cards.Count > 0)
                {
                    return(new AttackAction(current.Cards[0], target));
                }
            }

            return(null);
        }
Esempio n. 11
0
        private HREngine.API.Actions.ActionBase HandleBattleMulliganPhase()
        {
            SmartCc = new Simulation();


            SmartCc.CreateLogFolder();
            SmartCc.TurnCount = 0;

            if (HRMulligan.IsMulliganActive())
            {
                List <HRCard> Choices       = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND);
                List <Card>   ParsedChoices = new List <Card>();
                foreach (HRCard card in Choices)
                {
                    HREntity entity = card.GetEntity();
                    Card     c      = Card.Create(entity.GetCardId(), true, entity.GetEntityId());
                    c.CurrentCost = entity.GetCost();
                    ParsedChoices.Add(c);
                }

                List <HRCard> CardsToKeep = new List <HRCard>();
                foreach (Card c in ProfileInterface.Behavior.HandleMulligan(ParsedChoices))
                {
                    foreach (HRCard card in Choices)
                    {
                        if (c.Id == card.GetEntity().GetEntityId())
                        {
                            CardsToKeep.Add(card);
                        }
                    }
                }

                foreach (HRCard card in Choices)
                {
                    if (!CardsToKeep.Contains(card))
                    {
                        HRMulligan.ToggleCard(card);
                    }
                }
                return(null);
            }
            return(null);
        }
Esempio n. 12
0
        private void getHandcards()
        {
            handCards.Clear();
            this.anzcards      = 0;
            this.enemyAnzCards = 0;
            List <HRCard> list = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND);

            foreach (HRCard item in list)
            {
                HREntity entitiy = item.GetEntity();

                if (entitiy.GetControllerId() == this.ownPlayerController && entitiy.GetZonePosition() >= 1) // own handcard
                {
                    CardDB.Card c = CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(entitiy.GetCardId()));
                    //c.cost = entitiy.GetCost();
                    //c.entityID = entitiy.GetEntityId();

                    Handmanager.Handcard hc = new Handmanager.Handcard();
                    hc.card      = c;
                    hc.position  = entitiy.GetZonePosition();
                    hc.entity    = entitiy.GetEntityId();
                    hc.manacost  = entitiy.GetCost();
                    hc.addattack = 0;
                    if (c.name == CardDB.cardName.bolvarfordragon)
                    {
                        hc.addattack = entitiy.GetATK() - 1; // -1 because it starts with 1, we count only the additional attackvalue
                    }
                    handCards.Add(hc);
                    this.anzcards++;
                }
                //maybe check if it has BRM_028e on it?
            }

            Dictionary <int, HREntity> allEntitys = HRGame.GetEntityMap();

            foreach (HREntity ent in allEntitys.Values)
            {
                if (ent.GetControllerId() != this.ownPlayerController && ent.GetZonePosition() >= 1 && ent.GetZone() == HRCardZone.HAND) // enemy handcard
                {
                    this.enemyAnzCards++;
                }
            }
        }
Esempio n. 13
0
        public HREntities GetHREmployee()
        {
            HREntity employee = new HREntity();

            employee.Name         = "Garnik";
            employee.LastName     = "Gexamich";
            employee.DateOfBirth  = new DateTime(2016, 4, 4);
            employee.Passport     = "1234445";
            employee.DateOfHiring = new DateTime(2017, 4, 4);

            HREntity employee1 = new HREntity();

            employee1.Name = "Romantik";

            HREntities employees = new HREntities();

            employees.ListOfEntities.Add(employee);
            employees.ListOfEntities.Add(employee1);
            return(employees);
        }
Esempio n. 14
0
        protected override HRCard GetMinionByPriority(HRCard lastMinion)
        {
            HREntity result = null;

            if (HRPlayer.GetLocalPlayer().GetNumEnemyMinionsInPlay() <
                HRPlayer.GetLocalPlayer().GetNumFriendlyMinionsInPlay() ||
                HRPlayer.GetLocalPlayer().GetNumEnemyMinionsInPlay() < 4)
            {
                result = HRBattle.GetNextMinionByPriority(MinionPriority.Hero);
            }
            else
            {
                result = HRBattle.GetNextMinionByPriority(MinionPriority.LowestHealth);
            }

            if (result != null && (lastMinion == null || lastMinion != null && lastMinion.GetEntity().GetCardId() != result.GetCardId()))
            {
                return(result.GetCard());
            }

            return(null);
        }
        /// <summary>
        /// Create HTTpRequest for send id to GEtHREmployeeByid function
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns>serialized HRMployee datamodel</returns>
        public byte[] GetHREmployeeById(byte[] bytes)
        {
            HREntity hrentity = null;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseUrl + HRDestinations.GetDalEmployeeId);
                request.Method      = "POST";
                request.ContentType = "application/octet-stream";
                using (Stream strRequest = request.GetRequestStream())
                {
                    strRequest.Write(bytes, 0, bytes.Length);
                }
                HttpWebResponse response = Utils.Functionals.Communicator.CreateResponse(request);
                hrentity = Utils.Functionals.Communicator.ParseResponse <HREntity>(response.GetResponseStream());
            }
            catch (WebException ex)
            {
                Logger.Logger.Addlog(ex.InnerException.ToString() + " " + ex.Message.ToString());
            }
            return(Utils.Functionals.Formatter.GetBinary <HREntity>(hrentity));
        }
Esempio n. 16
0
        protected virtual HREntity GetNextAttackToAttack()
        {
            HREntity result = null;

            if (HRPlayer.GetLocalPlayer().GetNumEnemyMinionsInPlay() <
                HRPlayer.GetLocalPlayer().GetNumFriendlyMinionsInPlay() ||
                HRPlayer.GetLocalPlayer().GetNumEnemyMinionsInPlay() < 4)
            {
                result = HRBattle.GetNextMinionByPriority(MinionPriority.Hero);
            }
            else
            {
                result = HRBattle.GetNextMinionByPriority(MinionPriority.LowestHealth);
            }

            if (result == null)
            {
                return(HRPlayer.GetEnemyPlayer().GetHero());
            }

            return(result);
        }
        /// <summary>
        /// function call GEtHREmployeeByID Store Procedure
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns> marked employee</returns>
        public HREntity GetHREmployeeById(int id)
        {
            HREntity emp = new HREntity();

            using (SqlConnection con = new SqlConnection
                                           (ConfigurationManager.ConnectionStrings["SQLProviderConnectionString"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("dbo.GethrEmployeeById", con);

                try
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@HRID", id);

                    con.Open();
                }
                catch (SqlException ex)
                {
                    Logger.Logger.Addlog(ex.Message + ',' + ex.Procedure + ',' + ex.LineNumber);
                }

                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    emp.Id           = Int32.Parse(reader[0].ToString());
                    emp.Name         = reader[1].ToString();
                    emp.LastName     = reader[2].ToString();
                    emp.Phone        = reader[3].ToString();
                    emp.Address      = reader[4].ToString();
                    emp.DateOfBirth  = DateTime.Parse(reader[5].ToString());
                    emp.Passport     = reader[6].ToString();
                    emp.SocialId     = reader[7].ToString();
                    emp.Description  = reader[8].ToString();
                    emp.DateOfHiring = DateTime.Parse(reader[9].ToString());
                }
            }
            return(emp);
        }
Esempio n. 18
0
        private void getHandcards()
        {
            handCards.Clear();
            this.anzcards      = 0;
            this.enemyAnzCards = 0;
            List <HRCard> list = HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.HAND);

            foreach (HRCard item in list)
            {
                HREntity entitiy = item.GetEntity();

                if (entitiy.GetControllerId() == this.ownPlayerController && entitiy.GetZonePosition() >= 1) // own handcard
                {
                    CardDB.Card c = CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(entitiy.GetCardId()));
                    //c.cost = entitiy.GetCost();
                    //c.entityID = entitiy.GetEntityId();

                    Handmanager.Handcard hc = new Handmanager.Handcard();
                    hc.card     = c;
                    hc.position = entitiy.GetZonePosition();
                    hc.entity   = entitiy.GetEntityId();
                    hc.manacost = entitiy.GetCost();
                    handCards.Add(hc);
                    this.anzcards++;
                }
            }

            Dictionary <int, HREntity> allEntitys = HRGame.GetEntityMap();

            foreach (HREntity ent in allEntitys.Values)
            {
                if (ent.GetControllerId() != this.ownPlayerController && ent.GetZonePosition() >= 1 && ent.GetZone() == HRCardZone.HAND) // enemy handcard
                {
                    this.enemyAnzCards++;
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// received Employee Model, convert it to datamodel
        /// and send to HR layer
        /// </summary>
        /// <param name="HREntity"></param>
        /// <returns></returns>
        public string PostEmployee(EmployeeHRModel HREntity)
        {
            HREntities entitiy = new HREntities();
            //Convert Model to Entity
            HREntity hrentiy = new HREntity();
            {
                hrentiy.Id            = HREntity.Id;
                hrentiy.Name          = HREntity.Name;
                hrentiy.LastName      = HREntity.LastName;
                hrentiy.DateOfBirth   = HREntity.DateOfBirth;
                hrentiy.DateOfHiring  = HREntity.DateOfHiring;
                hrentiy.Address       = HREntity.Address;
                hrentiy.Description   = HREntity.Description;
                hrentiy.MaritalStatus = HREntity.MaritalStatus;
                hrentiy.Passport      = HREntity.Passport;
                hrentiy.Phone         = HREntity.Phone;
                hrentiy.SocialId      = HREntity.SocialId;
                entitiy.ListOfEntities.Add(hrentiy);
            }
            string         baseUrl = ConfigurationManager.ConnectionStrings["HRServerName"].ConnectionString;
            HttpWebRequest request = Utils.Functionals.Communicator.PostReques <HREntities>(baseUrl + DestinationNames.AddHREmployee, @"POST", entitiy);

            return(Utils.Functionals.Communicator.GetResponse(request.GetResponse()));
        }
Esempio n. 20
0
        /// <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();
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
        private void getHerostuff()
        {
            Dictionary <int, HREntity> allEntitys = HRGame.GetEntityMap();

            HRPlayer ownPlayer   = HRPlayer.GetLocalPlayer();
            HRPlayer enemyPlayer = HRPlayer.GetEnemyPlayer();

            HREntity ownhero        = ownPlayer.GetHero();
            HREntity enemyhero      = enemyPlayer.GetHero();
            HREntity ownHeroAbility = ownPlayer.GetHeroPower();

            //player stuff#########################
            //this.currentMana =ownPlayer.GetTag(HRGameTag.RESOURCES) - ownPlayer.GetTag(HRGameTag.RESOURCES_USED) + ownPlayer.GetTag(HRGameTag.TEMP_RESOURCES);
            this.currentMana  = ownPlayer.GetNumAvailableResources();
            this.ownMaxMana   = ownPlayer.GetTag(HRGameTag.RESOURCES);
            this.enemyMaxMana = enemyPlayer.GetTag(HRGameTag.RESOURCES);
            enemySecretCount  = HRCard.GetCards(enemyPlayer, HRCardZone.SECRET).Count;
            enemySecretCount  = 0;
            //count enemy secrets
            enemySecretList.Clear();
            foreach (HREntity ent in allEntitys.Values)
            {
                if (ent.IsSecret() && ent.GetControllerId() == enemyPlayer.GetControllerId() && ent.GetZone() == HRCardZone.SECRET)
                {
                    enemySecretCount++;
                    enemySecretList.Add(ent.GetTag(HRGameTag.ENTITY_ID));
                }
            }



            this.ownSecretList            = ownPlayer.GetSecretDefinitions();
            this.numMinionsPlayedThisTurn = ownPlayer.GetTag(HRGameTag.NUM_MINIONS_PLAYED_THIS_TURN);
            this.cardsPlayedThisTurn      = ownPlayer.GetTag(HRGameTag.NUM_CARDS_PLAYED_THIS_TURN);
            //if (ownPlayer.HasCombo()) this.cardsPlayedThisTurn = 1;
            this.ueberladung = ownPlayer.GetTag(HRGameTag.RECALL_OWED);

            //get weapon stuff
            this.ownHeroWeapon        = "";
            this.heroWeaponAttack     = 0;
            this.heroWeaponDurability = 0;

            this.ownHeroFatigue   = ownhero.GetFatigue();
            this.enemyHeroFatigue = enemyhero.GetFatigue();

            this.ownDecksize   = 0;
            this.enemyDecksize = 0;
            //count decksize
            foreach (HREntity ent in allEntitys.Values)
            {
                if (ent.GetControllerId() == ownPlayer.GetControllerId() && ent.GetZone() == HRCardZone.DECK)
                {
                    ownDecksize++;
                }
                if (ent.GetControllerId() == enemyPlayer.GetControllerId() && ent.GetZone() == HRCardZone.DECK)
                {
                    enemyDecksize++;
                }
            }

            //own hero stuff###########################
            int heroAtk     = ownhero.GetATK();
            int heroHp      = ownhero.GetHealth() - ownhero.GetDamage();
            int heroDefence = ownhero.GetArmor();

            this.heroname = Hrtprozis.Instance.heroIDtoName(ownhero.GetCardId());

            bool heroImmuneToDamageWhileAttacking = false;
            bool herofrozen             = ownhero.IsFrozen();
            int  heroNumAttacksThisTurn = ownhero.GetNumAttacksThisTurn();
            bool heroHasWindfury        = ownhero.HasWindfury();
            bool heroImmune             = (ownhero.GetTag(HRGameTag.CANT_BE_DAMAGED) == 1) ? true : false;

            //Helpfunctions.Instance.ErrorLog(ownhero.GetName() + " ready params ex: " + exausted + " " + heroAtk + " " + numberofattacks + " " + herofrozen);


            if (ownPlayer.HasWeapon())
            {
                HREntity weapon = ownPlayer.GetWeaponCard().GetEntity();
                this.ownHeroWeapon               = CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(weapon.GetCardId())).name.ToString();
                this.heroWeaponAttack            = weapon.GetATK();
                this.heroWeaponDurability        = weapon.GetTag(HRGameTag.DURABILITY) - weapon.GetTag(HRGameTag.DAMAGE);//weapon.GetDurability();
                heroImmuneToDamageWhileAttacking = false;
                if (this.ownHeroWeapon == "gladiatorslongbow")
                {
                    heroImmuneToDamageWhileAttacking = true;
                }
                if (this.ownHeroWeapon == "doomhammer")
                {
                    heroHasWindfury = true;
                }

                //Helpfunctions.Instance.ErrorLog("weapon: " + ownHeroWeapon + " " + heroWeaponAttack + " " + heroWeaponDurability);
            }



            //enemy hero stuff###############################################################
            this.enemyHeroname = Hrtprozis.Instance.heroIDtoName(enemyhero.GetCardId());

            int  enemyAtk        = enemyhero.GetATK();
            int  enemyHp         = enemyhero.GetHealth() - enemyhero.GetDamage();
            int  enemyDefence    = enemyhero.GetArmor();
            bool enemyfrozen     = enemyhero.IsFrozen();
            bool enemyHeroImmune = (enemyhero.GetTag(HRGameTag.CANT_BE_DAMAGED) == 1) ? true : false;

            this.enemyHeroWeapon       = "";
            this.enemyWeaponAttack     = 0;
            this.enemyWeaponDurability = 0;
            if (enemyPlayer.HasWeapon())
            {
                HREntity weapon = enemyPlayer.GetWeaponCard().GetEntity();
                this.enemyHeroWeapon       = CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(weapon.GetCardId())).name.ToString();
                this.enemyWeaponAttack     = weapon.GetATK();
                this.enemyWeaponDurability = weapon.GetDurability();
            }


            //own hero ablity stuff###########################################################

            this.heroAbility       = CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(ownHeroAbility.GetCardId()));
            this.ownAbilityisReady = (ownHeroAbility.IsExhausted()) ? false : true; // if exhausted, ability is NOT ready
            this.enemyAbility      = CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(enemyhero.GetHeroPower().GetCardId()));

            //generate Heros
            this.ownHero             = new Minion();
            this.enemyHero           = new Minion();
            this.ownHero.isHero      = true;
            this.enemyHero.isHero    = true;
            this.ownHero.own         = true;
            this.enemyHero.own       = false;
            this.ownHero.maxHp       = ownhero.GetHealth();
            this.enemyHero.maxHp     = enemyhero.GetHealth();
            this.ownHero.entitiyID   = ownhero.GetEntityId();
            this.enemyHero.entitiyID = enemyhero.GetEntityId();

            this.ownHero.Angr   = heroAtk;
            this.ownHero.Hp     = heroHp;
            this.ownHero.armor  = heroDefence;
            this.ownHero.frozen = herofrozen;
            this.ownHero.immuneWhileAttacking = heroImmuneToDamageWhileAttacking;
            this.ownHero.immune             = heroImmune;
            this.ownHero.numAttacksThisTurn = heroNumAttacksThisTurn;
            this.ownHero.windfury           = heroHasWindfury;

            this.enemyHero.Angr   = enemyAtk;
            this.enemyHero.Hp     = enemyHp;
            this.enemyHero.frozen = enemyfrozen;
            this.enemyHero.armor  = enemyDefence;
            this.enemyHero.immune = enemyHeroImmune;
            this.enemyHero.Ready  = false;

            this.ownHero.updateReadyness();


            //load enchantments of the heros
            List <miniEnch> miniEnchlist = new List <miniEnch>();

            foreach (HREntity ent in allEntitys.Values)
            {
                if (ent.GetTag(HRGameTag.ATTACHED) == this.ownHero.entitiyID && ent.GetZone() == HRCardZone.PLAY)
                {
                    CardDB.cardIDEnum id = CardDB.Instance.cardIdstringToEnum(ent.GetCardId());
                    int controler        = ent.GetTag(HRGameTag.CONTROLLER);
                    int creator          = ent.GetTag(HRGameTag.CREATOR);
                    miniEnchlist.Add(new miniEnch(id, creator, controler));
                }
            }

            this.ownHero.loadEnchantments(miniEnchlist, ownhero.GetTag(HRGameTag.CONTROLLER));

            miniEnchlist.Clear();

            foreach (HREntity ent in allEntitys.Values)
            {
                if (ent.GetTag(HRGameTag.ATTACHED) == this.enemyHero.entitiyID && ent.GetZone() == HRCardZone.PLAY)
                {
                    CardDB.cardIDEnum id = CardDB.Instance.cardIdstringToEnum(ent.GetCardId());
                    int controler        = ent.GetTag(HRGameTag.CONTROLLER);
                    int creator          = ent.GetTag(HRGameTag.CREATOR);
                    miniEnchlist.Add(new miniEnch(id, creator, controler));
                }
            }

            this.enemyHero.loadEnchantments(miniEnchlist, enemyhero.GetTag(HRGameTag.CONTROLLER));
            //fastmode weapon correction:
            if (ownHero.Angr < this.heroWeaponAttack)
            {
                ownHero.Angr = this.heroWeaponAttack;
            }
            if (enemyHero.Angr < this.enemyWeaponAttack)
            {
                enemyHero.Angr = this.enemyWeaponAttack;
            }
        }
Esempio n. 23
0
        private void getMinions()
        {
            Dictionary <int, HREntity> allEntitys = HRGame.GetEntityMap();

            ownMinions.Clear();
            enemyMinions.Clear();
            HRPlayer ownPlayer   = HRPlayer.GetLocalPlayer();
            HRPlayer enemyPlayer = HRPlayer.GetEnemyPlayer();

            // ALL minions on Playfield:
            List <HRCard> list = HRCard.GetCards(ownPlayer, HRCardZone.PLAY);

            list.AddRange(HRCard.GetCards(enemyPlayer, HRCardZone.PLAY));

            List <HREntity> enchantments = new List <HREntity>();


            foreach (HRCard item in list)
            {
                HREntity entitiy = item.GetEntity();
                int      zp      = entitiy.GetZonePosition();

                if (entitiy.GetCardType() == HRCardType.MINION && zp >= 1)
                {
                    //Helpfunctions.Instance.ErrorLog("zonepos " + zp);
                    CardDB.Card c = CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(entitiy.GetCardId()));
                    Minion      m = new Minion();
                    m.name          = c.name;
                    m.handcard.card = c;
                    m.Angr          = entitiy.GetATK();
                    m.maxHp         = entitiy.GetHealth();
                    m.Hp            = m.maxHp - entitiy.GetDamage();
                    if (m.Hp <= 0)
                    {
                        continue;
                    }
                    m.wounded = false;
                    if (m.maxHp > m.Hp)
                    {
                        m.wounded = true;
                    }


                    m.exhausted = entitiy.IsExhausted();

                    m.taunt = (entitiy.HasTaunt()) ? true : false;

                    m.numAttacksThisTurn = entitiy.GetNumAttacksThisTurn();

                    int temp = entitiy.GetNumTurnsInPlay();
                    m.playedThisTurn = (temp == 0) ? true : false;

                    m.windfury = (entitiy.HasWindfury()) ? true : false;

                    m.frozen = (entitiy.IsFrozen()) ? true : false;

                    m.divineshild = (entitiy.HasDivineShield()) ? true : false;

                    m.stealth = (entitiy.IsStealthed()) ? true : false;

                    m.poisonous = (entitiy.IsPoisonous()) ? true : false;

                    m.immune = (entitiy.IsImmune()) ? true : false;

                    m.silenced = (entitiy.GetTag(HRGameTag.SILENCED) >= 1) ? true : false;

                    m.charge = 0;

                    if (!m.silenced && m.name == CardDB.cardName.southseadeckhand && entitiy.GetTag(HRGameTag.CHARGE) == 1)
                    {
                        m.charge = 1;
                    }
                    if (!m.silenced && m.handcard.card.Charge)
                    {
                        m.charge = 1;
                    }

                    m.zonepos = zp;

                    m.entitiyID = entitiy.GetEntityId();


                    //Helpfunctions.Instance.ErrorLog(  m.name + " ready params ex: " + m.exhausted + " charge: " +m.charge + " attcksthisturn: " + m.numAttacksThisTurn + " playedthisturn " + m.playedThisTurn );


                    List <miniEnch> enchs = new List <miniEnch>();
                    foreach (HREntity ent in allEntitys.Values)
                    {
                        if (ent.GetTag(HRGameTag.ATTACHED) == m.entitiyID && ent.GetZone() == HRCardZone.PLAY)
                        {
                            CardDB.cardIDEnum id = CardDB.Instance.cardIdstringToEnum(ent.GetCardId());
                            int creator          = ent.GetTag(HRGameTag.CREATOR);
                            int controler        = ent.GetTag(HRGameTag.CONTROLLER);
                            enchs.Add(new miniEnch(id, creator, controler));
                        }
                    }

                    m.loadEnchantments(enchs, entitiy.GetControllerId());



                    m.Ready = false; // if exhausted, he is NOT ready

                    m.updateReadyness();


                    if (entitiy.GetControllerId() == this.ownPlayerController) // OWN minion
                    {
                        m.own = true;
                        this.ownMinions.Add(m);
                    }
                    else
                    {
                        m.own = false;
                        this.enemyMinions.Add(m);
                    }
                }
                // minions added

                /*
                 * if (entitiy.GetCardType() == HRCardType.WEAPON)
                 * {
                 *  //Helpfunctions.Instance.ErrorLog("found weapon!");
                 *  if (entitiy.GetControllerId() == this.ownPlayerController) // OWN weapon
                 *  {
                 *      this.ownHeroWeapon = CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(entitiy.GetCardId())).name.ToString();
                 *      this.heroWeaponAttack = entitiy.GetATK();
                 *      this.heroWeaponDurability = entitiy.GetDurability();
                 *      //this.heroImmuneToDamageWhileAttacking = false;
                 *
                 *
                 *  }
                 *  else
                 *  {
                 *      this.enemyHeroWeapon = CardDB.Instance.getCardDataFromID(CardDB.Instance.cardIdstringToEnum(entitiy.GetCardId())).name.ToString();
                 *      this.enemyWeaponAttack = entitiy.GetATK();
                 *      this.enemyWeaponDurability = entitiy.GetDurability();
                 *  }
                 * }
                 *
                 * if (entitiy.GetCardType() == HRCardType.ENCHANTMENT)
                 * {
                 *
                 *  enchantments.Add(entitiy);
                 * }
                 */
            }

            /*foreach (HRCard item in list)
             * {
             *  foreach (HREntity e in item.GetEntity().GetEnchantments())
             *  {
             *      enchantments.Add(e);
             *  }
             * }
             *
             *
             * // add enchantments to minions
             * setEnchantments(enchantments);*/
        }
Esempio n. 24
0
        private void SeedSmartCc()
        {
            SmartCc.SimuCount++;
            Board root = new Board();

            HREntity HeroEnemy = HRPlayer.GetEnemyPlayer().GetHero();

            Card ce = Card.Create(HeroEnemy.GetCardId(), false, HeroEnemy.GetEntityId());

            root.HeroEnemy = ce;

            HREntity HeroFriend = HRPlayer.GetLocalPlayer().GetHero();

            root.HeroFriend = Card.Create(HeroFriend.GetCardId(), true, HeroFriend.GetEntityId());

            root.HeroEnemy.CurrentHealth = HeroEnemy.GetHealth() - HeroEnemy.GetDamage();
            root.HeroEnemy.MaxHealth     = 30;

            root.HeroEnemy.CurrentArmor   = HeroEnemy.GetArmor();
            root.HeroFriend.CurrentHealth = HeroFriend.GetHealth() - HeroFriend.GetDamage();
            root.HeroFriend.MaxHealth     = 30;
            root.HeroFriend.IsFrozen      = HeroFriend.IsFrozen();

            root.HeroFriend.CurrentArmor = HeroFriend.GetArmor();
            root.HeroFriend.CurrentAtk   = HeroFriend.GetATK();

            if (HRCard.GetCards(HRPlayer.GetEnemyPlayer(), HRCardZone.SECRET).Count > 0)
            {
                root.SecretEnemy = true;
            }

            if (HRPlayer.GetEnemyPlayer().HasWeapon())
            {
                HRCard weaponEnemyCard = HRPlayer.GetEnemyPlayer().GetWeaponCard();
                if (weaponEnemyCard != null)
                {
                    root.WeaponEnemy = Card.Create(weaponEnemyCard.GetEntity().GetCardId(), false, weaponEnemyCard.GetEntity().GetEntityId());
                }
            }

            if (HRPlayer.GetLocalPlayer().HasWeapon())
            {
                HRCard weaponFriendCard = HRPlayer.GetLocalPlayer().GetWeaponCard();
                if (weaponFriendCard != null)
                {
                    root.WeaponFriend         = Card.Create(weaponFriendCard.GetEntity().GetCardId(), true, weaponFriendCard.GetEntity().GetEntityId());
                    root.WeaponFriend.IsTired = (weaponFriendCard.GetEntity().GetNumAttacksThisTurn() > 0 || HeroFriend.GetNumAttacksThisTurn() > 0);
                }
            }

            root.ManaAvailable = HRPlayer.GetLocalPlayer().GetNumAvailableResources();

            foreach (HREntity e in GetEnemyEntitiesOnBoard())
            {
                Card newc = Card.Create(e.GetCardId(), false, e.GetEntityId());
                newc.CurrentAtk    = e.GetATK();
                newc.CurrentHealth = e.GetHealth() - e.GetDamage();
                newc.MaxHealth     = e.GetHealth();
                foreach (HREntity az in e.GetEnchantments())
                {
                    Buff b = Buff.GetBuffById(az.GetCardId());
                    if (b != null)
                    {
                        b.OwnerId = az.GetCreatorId();
                        newc.AddBuff(b);
                        newc.currentAtk    -= b.Atk;
                        newc.CurrentHealth -= b.Hp;
                        newc.maxHealth     -= b.Hp;
                    }
                }

                newc.CurrentCost    = e.GetCost();
                newc.IsCharge       = e.HasCharge();
                newc.IsDivineShield = e.HasDivineShield();
                newc.IsEnraged      = e.IsEnraged();
                newc.IsFrozen       = e.IsFrozen();
                newc.HasFreeze      = e.IsFreeze();
                newc.IsStealth      = e.IsStealthed();
                newc.IsSilenced     = e.IsSilenced();
                newc.HasPoison      = e.IsPoisonous();
                newc.IsWindfury     = e.HasWindfury();
                newc.IsTaunt        = e.HasTaunt();
                newc.Index          = e.GetTag(HRGameTag.ZONE_POSITION) - 1;
                // HRLog.Write(e.GetName() + " at " + newc.Index.ToString());
                root.MinionEnemy.Add(newc);
            }
            foreach (HREntity e in GetFriendEntitiesOnBoard())
            {
                Card newc = Card.Create(e.GetCardId(), true, e.GetEntityId());

                newc.CurrentAtk    = e.GetATK();
                newc.CurrentHealth = e.GetHealth() - e.GetDamage();
                newc.MaxHealth     = e.GetHealth();
                foreach (HREntity az in e.GetEnchantments())
                {
                    Buff b = Buff.GetBuffById(az.GetCardId());
                    if (b != null)
                    {
                        b.OwnerId = az.GetCreatorId();
                        newc.AddBuff(b);
                        newc.currentAtk    -= b.Atk;
                        newc.CurrentHealth -= b.Hp;
                        newc.MaxHealth     -= b.Hp;
                    }
                }
                newc.CurrentCost    = e.GetCost();
                newc.IsCharge       = e.HasCharge();
                newc.IsDivineShield = e.HasDivineShield();
                newc.IsEnraged      = e.IsEnraged();
                newc.IsFrozen       = e.IsFrozen();
                newc.HasFreeze      = e.IsFreeze();
                newc.IsStealth      = e.IsStealthed();
                newc.IsSilenced     = e.IsSilenced();
                newc.HasPoison      = e.IsPoisonous();
                newc.IsWindfury     = e.HasWindfury();
                newc.IsTaunt        = e.HasTaunt();
                newc.IsTired        = e.IsExhausted();
                newc.IsImmune       = e.IsImmune();
                newc.Index          = e.GetTag(HRGameTag.ZONE_POSITION) - 1;
                newc.CountAttack    = e.GetTag(HRGameTag.NUM_ATTACKS_THIS_TURN);

                root.MinionFriend.Add(newc);
            }
            foreach (HRCard c in HRCard.GetCards(HRPlayer.GetLocalPlayer(), HRCardZone.SECRET))
            {
                Card newc = Card.Create(c.GetEntity().GetCardId(), true, c.GetEntity().GetEntityId());
                root.Secret.Add(newc);
            }
            foreach (HRCard c in GetAllCardsInHand())
            {
                Card newc = Card.Create(c.GetEntity().GetCardId(), true, c.GetEntity().GetEntityId());
                root.Hand.Add(newc);
            }
            if (!HRPlayer.GetLocalPlayer().GetHeroPower().IsExhausted())
            {
                root.Ability = Card.Create(HRPlayer.GetLocalPlayer().GetHeroPower().GetCardId(), true, HRPlayer.GetLocalPlayer().GetHeroPower().GetEntityId());
            }
            if (!HRPlayer.GetEnemyPlayer().GetHeroPower().IsExhausted())
            {
                root.EnemyAbility = Card.Create(HRPlayer.GetEnemyPlayer().GetHeroPower().GetCardId(), false, HRPlayer.GetEnemyPlayer().GetHeroPower().GetEntityId());
            }
            root.TurnCount = SmartCc.TurnCount + 1;
            SmartCc.root   = root;
        }
Esempio n. 25
0
 public static HREngine.Private.HREngineRules GetRulesForCard(HREntity Card)
 {
     return GetRulesForCard(Card.GetCardId());
 }
Esempio n. 26
0
 public static bool HasRule(HREntity Card)
 {
     return HasRule(Card.GetCardId());
 }
Esempio n. 27
0
 public string AddHREmployee(HREntity employee)
 {
     return("Added");
 }
Esempio n. 28
0
        private void getMinions()
        {
            ownMinions.Clear();
            enemyMinions.Clear();
            HRPlayer ownPlayer   = HRPlayer.GetLocalPlayer();
            HRPlayer enemyPlayer = HRPlayer.GetEnemyPlayer();

            // ALL minions on Playfield:
            List <HRCard> list = HRCard.GetCards(ownPlayer, HRCardZone.PLAY);

            list.AddRange(HRCard.GetCards(enemyPlayer, HRCardZone.PLAY));

            List <HREntity> enchantments = new List <HREntity>();


            foreach (HRCard item in list)
            {
                HREntity entitiy = item.GetEntity();
                int      zp      = entitiy.GetZonePosition();

                if (entitiy.GetCardType() == HRCardType.MINION && zp >= 1)
                {
                    //HRLog.Write("zonepos " + zp);
                    CardDB.Card c = CardDB.Instance.getCardDataFromID(entitiy.GetCardId());
                    Minion      m = new Minion();
                    m.name          = c.name;
                    m.handcard.card = c;
                    m.Angr          = entitiy.GetATK();
                    m.maxHp         = entitiy.GetHealth();
                    m.Hp            = m.maxHp - entitiy.GetDamage();
                    m.wounded       = false;
                    if (m.maxHp > m.Hp)
                    {
                        m.wounded = true;
                    }


                    m.exhausted = entitiy.IsExhausted();

                    m.taunt = (entitiy.HasTaunt()) ? true : false;

                    m.charge = (entitiy.HasCharge()) ? true : false;

                    m.numAttacksThisTurn = entitiy.GetNumAttacksThisTurn();

                    int temp = entitiy.GetNumTurnsInPlay();
                    m.playedThisTurn = (temp == 0) ? true : false;

                    m.windfury = (entitiy.HasWindfury()) ? true : false;

                    m.frozen = (entitiy.IsFrozen()) ? true : false;

                    m.divineshild = (entitiy.HasDivineShield()) ? true : false;

                    m.stealth = (entitiy.IsStealthed()) ? true : false;

                    m.poisonous = (entitiy.IsPoisonous()) ? true : false;

                    m.immune = (entitiy.IsImmune()) ? true : false;

                    m.silenced = (entitiy.GetTag(HRGameTag.SILENCED) >= 1) ? true:false;


                    m.zonepos = zp;
                    m.id      = m.zonepos - 1;

                    m.entitiyID = entitiy.GetEntityId();

                    m.enchantments.Clear();

                    //HRLog.Write(  m.name + " ready params ex: " + m.exhausted + " charge: " +m.charge + " attcksthisturn: " + m.numAttacksThisTurn + " playedthisturn " + m.playedThisTurn );

                    m.Ready = false; // if exhausted, he is NOT ready

                    if (!m.playedThisTurn && !m.exhausted && !m.frozen && (m.numAttacksThisTurn == 0 || (m.numAttacksThisTurn == 1 && m.windfury)))
                    {
                        m.Ready = true;
                    }

                    if (m.playedThisTurn && m.charge && (m.numAttacksThisTurn == 0 || (m.numAttacksThisTurn == 1 && m.windfury)))
                    {
                        //m.exhausted = false;
                        m.Ready = true;
                    }

                    if (!m.silenced && (m.name == "ancientwatcher" || m.name == "ragnarosthefirelord"))
                    {
                        m.Ready = false;
                    }


                    if (entitiy.GetControllerId() == this.ownPlayerController) // OWN minion
                    {
                        this.ownMinions.Add(m);
                    }
                    else
                    {
                        this.enemyMinions.Add(m);
                    }
                }
                // minions added

                if (entitiy.GetCardType() == HRCardType.WEAPON)
                {
                    //HRLog.Write("found weapon!");
                    if (entitiy.GetControllerId() == this.ownPlayerController) // OWN weapon
                    {
                        this.ownHeroWeapon        = CardDB.Instance.getCardDataFromID(entitiy.GetCardId()).name;
                        this.heroWeaponAttack     = entitiy.GetATK();
                        this.heroWeaponDurability = entitiy.GetDurability();
                        //this.heroImmuneToDamageWhileAttacking = false;
                    }
                    else
                    {
                        this.enemyHeroWeapon       = CardDB.Instance.getCardDataFromID(entitiy.GetCardId()).name;
                        this.enemyWeaponAttack     = entitiy.GetATK();
                        this.enemyWeaponDurability = entitiy.GetDurability();
                    }
                }

                if (entitiy.GetCardType() == HRCardType.ENCHANTMENT)
                {
                    enchantments.Add(entitiy);
                }
            }

            foreach (HRCard item in list)
            {
                foreach (HREntity e in item.GetEntity().GetEnchantments())
                {
                    enchantments.Add(e);
                }
            }


            // add enchantments to minions
            setEnchantments(enchantments);
        }
Esempio n. 29
0
        private void getHerostuff()
        {
            HRPlayer ownPlayer   = HRPlayer.GetLocalPlayer();
            HRPlayer enemyPlayer = HRPlayer.GetEnemyPlayer();

            HREntity ownhero        = ownPlayer.GetHero();
            HREntity enemyhero      = enemyPlayer.GetHero();
            HREntity ownHeroAbility = ownPlayer.GetHeroPower();

            //player stuff#########################
            //this.currentMana =ownPlayer.GetTag(HRGameTag.RESOURCES) - ownPlayer.GetTag(HRGameTag.RESOURCES_USED) + ownPlayer.GetTag(HRGameTag.TEMP_RESOURCES);
            this.currentMana = ownPlayer.GetNumAvailableResources();
            this.ownMaxMana  = ownPlayer.GetTag(HRGameTag.RESOURCES);//ownPlayer.GetRealTimeTempMana();
            Helpfunctions.Instance.logg("#######################################################################");
            Helpfunctions.Instance.logg("#######################################################################");
            Helpfunctions.Instance.logg("start calculations, current time: " + DateTime.Now.ToString("HH:mm:ss"));
            Helpfunctions.Instance.logg("#######################################################################");
            Helpfunctions.Instance.logg("mana " + currentMana + "/" + ownMaxMana);
            Helpfunctions.Instance.logg("own secretsCount: " + ownPlayer.GetSecretDefinitions().Count);
            enemySecretCount = HRCard.GetCards(enemyPlayer, HRCardZone.SECRET).Count;
            enemySecretCount = 0;
            Helpfunctions.Instance.logg("enemy secretsCount: " + enemySecretCount);
            this.ownSecretList            = ownPlayer.GetSecretDefinitions();
            this.numMinionsPlayedThisTurn = ownPlayer.GetTag(HRGameTag.NUM_MINIONS_PLAYED_THIS_TURN);
            this.cardsPlayedThisTurn      = ownPlayer.GetTag(HRGameTag.NUM_CARDS_PLAYED_THIS_TURN);
            //if (ownPlayer.HasCombo()) this.cardsPlayedThisTurn = 1;
            this.ueberladung = ownPlayer.GetTag(HRGameTag.RECALL_OWED);


            //get weapon stuff
            this.ownHeroWeapon        = "";
            this.heroWeaponAttack     = 0;
            this.heroWeaponDurability = 0;

            this.ownHeroFatigue   = ownhero.GetFatigue();
            this.enemyHeroFatigue = enemyhero.GetFatigue();
            //this.ownDecksize = HRCard.GetCards(ownPlayer, HRCardZone.DECK).Count;

            //this.enemyDecksize = HRCard.GetCards(enemyPlayer, HRCardZone.DECK).Count;



            this.enemyHeroWeapon       = "";
            this.enemyWeaponAttack     = 0;
            this.enemyWeaponDurability = 0;
            if (enemyPlayer.HasWeapon())
            {
                HREntity weapon = enemyPlayer.GetWeaponCard().GetEntity();
                this.enemyHeroWeapon       = CardDB.Instance.getCardDataFromID(weapon.GetCardId()).name;
                this.enemyWeaponAttack     = weapon.GetATK();
                this.enemyWeaponDurability = weapon.GetDurability();
            }


            //own hero stuff###########################
            this.heroAtk     = ownhero.GetATK();
            this.heroHp      = ownhero.GetHealth() - ownhero.GetDamage();
            this.heroDefence = ownhero.GetArmor();
            this.heroname    = Hrtprozis.Instance.heroIDtoName(ownhero.GetCardId());
            bool exausted = false;

            exausted           = ownhero.IsExhausted();
            this.ownheroisread = true;

            this.heroImmuneToDamageWhileAttacking = (ownhero.IsImmune()) ? true : false;
            this.herofrozen             = ownhero.IsFrozen();
            this.heroNumAttacksThisTurn = ownhero.GetNumAttacksThisTurn();
            this.heroHasWindfury        = ownhero.HasWindfury();
            //int numberofattacks = ownhero.GetNumAttacksThisTurn();

            //HRLog.Write(ownhero.GetName() + " ready params ex: " + exausted + " " + heroAtk + " " + numberofattacks + " " + herofrozen);

            if (exausted == true)
            {
                this.ownheroisread = false;
            }
            if (exausted == false && this.heroAtk == 0)
            {
                this.ownheroisread = false;
            }
            if (herofrozen)
            {
                ownheroisread = false;
            }


            if (ownPlayer.HasWeapon())
            {
                HREntity weapon = ownPlayer.GetWeaponCard().GetEntity();
                this.ownHeroWeapon                    = CardDB.Instance.getCardDataFromID(weapon.GetCardId()).name;
                this.heroWeaponAttack                 = weapon.GetATK();
                this.heroWeaponDurability             = weapon.GetTag(HRGameTag.DURABILITY) - weapon.GetTag(HRGameTag.DAMAGE);//weapon.GetDurability();
                this.heroImmuneToDamageWhileAttacking = false;
                if (this.ownHeroWeapon == "gladiatorslongbow")
                {
                    this.heroImmuneToDamageWhileAttacking = true;
                }

                //HRLog.Write("weapon: " + ownHeroWeapon + " " + heroWeaponAttack + " " + heroWeaponDurability);
            }

            //enemy hero stuff###############################################################
            this.enemyAtk = enemyhero.GetATK();

            this.enemyHp = enemyhero.GetHealth() - enemyhero.GetDamage();

            this.enemyHeroname = Hrtprozis.Instance.heroIDtoName(enemyhero.GetCardId());

            this.enemyDefence = enemyhero.GetArmor();

            this.enemyfrozen = enemyhero.IsFrozen();



            //own hero ablity stuff###########################################################

            this.heroAbility       = CardDB.Instance.getCardDataFromID(ownHeroAbility.GetCardId());
            this.ownAbilityisReady = (ownHeroAbility.IsExhausted()) ? false : true; // if exhausted, ability is NOT ready
        }
Esempio n. 30
0
 private bool CanHandleCard(
  HRCard item, PlayerState EnemyState, PlayerState LocalState, ref HREntity Target)
 {
     string cardID = item.GetEntity().GetCardId().ToUpper();
      switch (cardID)
      {
     case "CS2_122": // "Raid Leader"
        return LocalState.Minions > 0;
     case "EX1_066": // "Acidic Swamp Ooze"
        return EnemyState.Player.HasWeapon() || LocalState.Minions < EnemyState.Minions;
     default:
        break;
      }
      return true;
 }
Esempio n. 31
0
        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);
        }
Esempio n. 32
0
        /// <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();
        }
Esempio n. 33
0
        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);
        }