Beispiel #1
0
 public EReturnCode Init(EInitMode _initMode)
 {
     throw new NotImplementedException();
 }
Beispiel #2
0
        /// <summary>
        /// Resolve the ids and names of the controlled villages
        /// </summary>
        /// <param name="_initMode">The initialization mode</param>
        /// <returns>
        /// Returns the code of the error if one has occured. 
        /// Note that this code would be "SUCCESS" if everything was ok.
        /// </returns>
        protected EReturnCode ResolveVillages(EInitMode _initMode)
        {
            Int32  id;
            String name;

            EReturnCode returnCode = EReturnCode.SUCCESS;

            try
            {
                HtmlNode baseNode = this.HPage.GetPagePlayer().DocumentNode;

                HtmlNodeCollection hnColl = baseNode.SelectNodes(".//li[@class=' active']");
                foreach (HtmlNode hnLi in hnColl)
                {
                    String idValue;

                    HtmlNode hn = hnLi.SelectSingleNode(".//a[@class='active']");

                    idValue = hn.GetAttributeValue(HInfo.PHtmlAttributes.HRef, String.Empty);
                    idValue = idValue.Substring(idValue.IndexOf("=", StringComparison.Ordinal) + 1,
                        // start index
                        idValue.IndexOf("&", StringComparison.Ordinal) - // length
                        idValue.IndexOf("=", StringComparison.Ordinal) - 1); // length

                    id = Int32.Parse(idValue);
                    name = hn.SelectSingleNode(HInfo.PXPathExpr.DivVillageName).InnerText;

                    // add new village to dictionary
                    IVillage village = new Village(this.HPage, id, name);
                    returnCode = village.Init(_initMode);
                    this.Villages.Add(id, village);
                }
            }
            catch (Exception exception)
            {
                HInfo.LogHandler.Error("Unable to resolve the id and name of the villages", exception);
                return EReturnCode.FAIL;
            }

            return returnCode;
        }
Beispiel #3
0
        public EReturnCode Init(EInitMode _initMode)
        {
            EReturnCode returnCode;

            try
            {
                HInfo.LogHandler.Debug("START INIT");

                if (!this.LogedIn)
                {
                    return EReturnCode.NOT_LOGED_IN;
                }

                returnCode = this.ResolvePlayer();
                if (returnCode != EReturnCode.SUCCESS)
                {
                    return returnCode;
                }

                returnCode = this.ResolveVillages(_initMode);
                if (returnCode != EReturnCode.SUCCESS)
                {
                    return returnCode;
                }

                this.Initialized = true;
                return EReturnCode.SUCCESS;
            }
            catch (Exception exception)
            {
                HInfo.LogHandler.Debug("ERROR: Init - ", exception);
                return EReturnCode.FAIL;
            }
            finally
            {
                HInfo.LogHandler.Debug("END Init");
            }
        }
Beispiel #4
0
        protected EReturnCode ResolveVillageBuildings(EInitMode _initMode)
        {
            IBuilding building;
              String value;
              Int32  id;
              String name;
              EBuildingType type;

              HInfo.LogHandler.Debug(String.Format("START RESOLVE VILLAGE BUILDINGS OF VILLAGE {0}", this.Name));
              try
              {
            HtmlNode baseNode = HPage.GetPageVillage(this.ID).GetElementbyId("clickareas");

            foreach (HtmlNode hnFarm in baseNode.SelectNodes(HInfo.PXPathExpr.AreaVillage))
            {
              // resolve id
              value = hnFarm.GetAttributeValue(HInfo.PHtmlAttributes.HRef, String.Empty);
              value = value.Substring(value.IndexOf('=') + 1);
              id = Int32.Parse(value);

              // resoble name
              value = hnFarm.GetAttributeValue(HInfo.PHtmlAttributes.Alt, String.Empty);
              name = !value.Contains(" ") ? value : value.Substring(0, value.IndexOf(' '));

              // resolve type
              type = HInfo.PDictionary.Buildings[name];

              building = new Building(this.HPage, this.ID, id, name);
              building.Init(_initMode);

              // create dictionary if this type doesn't exists already in it
              if (!this.Buildings.ContainsKey(type))
              {
            IDictionary<Int32, IBuilding> dictionary = new Dictionary<Int32, IBuilding>();
            this.Buildings.Add(type, dictionary);
              }

              this.Buildings[type].Add(id, building);
            }
              }
              catch (Exception exception)
              {
            HInfo.LogHandler.Error(String.Format("Unable to resolve the village buildings of village {0}", this.Name), exception);
            return EReturnCode.FAIL;
              }
              finally
              {
            HInfo.LogHandler.Debug(String.Format("END RESOLVE VILLAGE BUILDINGS OF VILLAGE {0}", this.Name));
              }

              return EReturnCode.SUCCESS;
        }
Beispiel #5
0
        public EReturnCode Init(EInitMode _initMode)
        {
            EReturnCode returnCode;

              // Coordinates
              if ((returnCode = this.ResolveCoordinates()) != EReturnCode.SUCCESS)
              { return returnCode; }

              // Ressources
              if ((returnCode = this.ResolveRessources()) != EReturnCode.SUCCESS)
              { return returnCode; }

              // Acceptance
              if ((returnCode = this.ResolveAcceptance()) != EReturnCode.SUCCESS)
              { return returnCode; }

              // Inhabitants
              if ((returnCode = this.ResolveInhabitants()) != EReturnCode.SUCCESS)
              { return returnCode; }

              // Farm buildings
              if ((returnCode = this.ResolveFarmBuildings(_initMode)) != EReturnCode.SUCCESS)
              { return returnCode; }

              // Village buildings
              if ((returnCode = this.ResolveVillageBuildings(_initMode)) != EReturnCode.SUCCESS)
              { return returnCode; }

              // Full resolve
              if (_initMode == EInitMode.FULL)
              {
              }

              return returnCode;
        }
Beispiel #6
0
        public EReturnCode Init(EInitMode _initMode)
        {
            EReturnCode returnCode = EReturnCode.UNKNOWN;

              if (_initMode == EInitMode.FULL)
              {
            if ((returnCode = this.ResolveCosts()) != EReturnCode.SUCCESS)
            {
              return returnCode;
            }

            if ((returnCode = this.ResolveUpgradeable()) != EReturnCode.SUCCESS)
            {
              return returnCode;
            }

            if ((returnCode = this.ResolveUpgradeDuration()) != EReturnCode.SUCCESS)
            {
              return returnCode;
            }

            if ((returnCode = this.ResolveUpgradeEnding()) != EReturnCode.SUCCESS)
            {
              return returnCode;
            }

            if ((returnCode = this.ResolveUnoderConstruction()) != EReturnCode.SUCCESS)
            {
              return returnCode;
            }
              }

              this.Initialized = true;
              return returnCode;
        }