示例#1
0
        public void CompleteHarvest(HarvestData data)
        {
            IClientGameUpdate       update;
            List <GameActionNotice> notices;

            AgricolaGame   game;
            AgricolaPlayer player = GetPlayer();

            if (player != null)
            {
                try
                {
                    game = player.Game as AgricolaGame;
                    var result = game.CompleteHarvest(player, data, out update, out notices);
                    if (result)
                    {
                        if (notices != null)
                        {
                            foreach (var notice in notices)
                            {
                                Clients.Group(game.Id.ToString()).message(notice);
                            }
                        }

                        UpdateGameState(game, update);
                    }
                }
                catch (Exception e)
                {
                    Clients.Caller.error(e.StackTrace);
                    throw;
                }
            }
        }
 private void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     if (File.Exists(xmlPath))
     {
         try
         {
             XmlDocument xmlDoc = new XmlDocument();
             xmlDoc.Load(xmlPath);
             foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
             {
                 var harvest = new HarvestData
                 {
                     Name      = node.ChildNodes[0].InnerText,
                     Count     = Convert.ToInt32(node.ChildNodes[1].InnerText),
                     Type      = node.ChildNodes[2].InnerText,
                     Price     = node.ChildNodes[3].InnerText,
                     Comment   = node.ChildNodes[4].InnerText,
                     Lock      = Convert.ToBoolean(node.ChildNodes[5].InnerText),
                     CraftType = (CraftTypes)Enum.Parse(typeof(CraftTypes), node.ChildNodes[6].InnerText)
                 };
                 Harvests.Add(harvest);
             }
         }
         catch (Exception)
         {
             MessageBox.Show("Please delete your previous datafile from Documents/Harvester and restart the application");
         }
     }
 }
示例#3
0
            public void AddHarvest(HarvestData item)
            {
                ItemStats all   = new ItemStats(" All", this);
                int       index = items.IndexOf(all);

                if (index > -1)
                {
                    all = items[index];
                }
                else
                {
                    items.Add(all);
                }
                ItemStats unique = new ItemStats(item.itemName, this);

                index = items.IndexOf(unique);
                if (index > -1)
                {
                    unique = items[index];
                }
                else
                {
                    items.Add(unique);
                }

                all.AddHarvest(item);
                unique.AddHarvest(item);
            }
        private void OnCLEMInitialiseActivity(object sender, EventArgs e)
        {
            InsideMultiHarvestSequence = false;

            // activity is performed in CLEMDoCutAndCarry not CLEMGetResources
            this.AllocationStyle = ResourceAllocationStyle.Manual;

            fileCrop = simulation.FindAllDescendants().Where(a => a.Name == ModelNameFileCrop).FirstOrDefault() as IFileCrop;
            if (fileCrop == null)
            {
                throw new ApsimXException(this, String.Format("Unable to locate crop data reader [x={0}] requested by [a={1}]", this.ModelNameFileCrop ?? "Unknown", this.Name));
            }

            LinkedResourceItem = Resources.FindResourceType <ResourceBaseWithTransactions, IResourceType>(this, StoreItemName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop);
            if ((LinkedResourceItem as Model).Parent is GrazeFoodStore)
            {
                // set manager of graze food store if linked
                (LinkedResourceItem as GrazeFoodStoreType).Manager = (Parent as IPastureManager);
                addReason = "Growth";
            }

            // look up tree until we find a parent to allow nested crop products for rotate vs mixed cropping/products
            parentManagementActivity = FindAncestor <CropActivityManageCrop>();

            // Retrieve harvest data from the forage file for the entire run.
            // only get entries where a harvest happened (Amtkg > 0)
            HarvestData = fileCrop.GetCropDataForEntireRun(parentManagementActivity.LinkedLandItem.SoilType, CropName,
                                                           clock.StartDate, clock.EndDate).Where(a => a.AmtKg > 0).OrderBy(a => a.Year * 100 + a.Month).ToList <CropDataType>();
            if ((HarvestData == null) || (HarvestData.Count == 0))
            {
                Summary.WriteWarning(this, $"Unable to locate any harvest data in [x={fileCrop.Name}] using [x={fileCrop.FileName}] for soil type [{parentManagementActivity.LinkedLandItem.SoilType}] and crop name [{CropName}] between the dates [{clock.StartDate.ToShortDateString()}] and [{clock.EndDate.ToShortDateString()}]");
            }

            IsTreeCrop = (TreesPerHa == 0) ? false : true;  //using this boolean just makes things more readable.

            UnitsToHaConverter = (parentManagementActivity.LinkedLandItem.Parent as Land).UnitsOfAreaToHaConversion;

            // locate a cut and carry limiter associated with this event.
            limiter = LocateCutAndCarryLimiter(this);

            // check if harvest type tags have been provided
            HarvestTagsUsed = HarvestData.Where(a => a.HarvestType != "").Count() > 0;

            if (LinkedResourceItem is GrazeFoodStoreType)
            {
                double       firstMonthsGrowth = 0;
                CropDataType cropData          = HarvestData.Where(a => a.Year == clock.StartDate.Year && a.Month == clock.StartDate.Month).FirstOrDefault();
                if (cropData != null)
                {
                    firstMonthsGrowth = cropData.AmtKg;
                }

                (LinkedResourceItem as GrazeFoodStoreType).SetupStartingPasturePools(UnitsToHaConverter * (Parent as CropActivityManageCrop).Area * UnitsToHaConverter, firstMonthsGrowth);
                addReason = "Growth";
            }
        }
 private void OnCLEMStartOfTimeStep(object sender, EventArgs e)
 {
     // get next harvest and store previous harvest
     while (HarvestData.Count() > 0 && Clock.Today.Year * 100 + Clock.Today.Month > HarvestData.First().Year * 100 + HarvestData.First().Month)
     {
         PreviousHarvest = HarvestData.FirstOrDefault();
         HarvestData.RemoveAt(0);
     }
     NextHarvest = HarvestData.FirstOrDefault();
 }
示例#6
0
 private void OnCLEMEndOfTimeStep(object sender, EventArgs e)
 {
     // rotate harvest if needed
     if (HarvestData.Count() > 0 && Clock.Today.Year * 100 + Clock.Today.Month == HarvestData.First().Year * 100 + HarvestData.First().Month)
     {
         if (this.ActivityEnabled)
         {
             parentManagementActivity.RotateCrop();
         }
     }
 }
 private void OnCLEMEndOfTimeStep(object sender, EventArgs e)
 {
     // rotate harvest if needed
     if ((this.ActivityEnabled & Status != ActivityStatus.Ignored) && HarvestData.Count() > 0 && clock.Today.Year * 100 + clock.Today.Month == HarvestData.First().Year * 100 + HarvestData.First().Month)
     {
         // don't rotate if no harvest tags or harvest type is not equal to "last"
         if (!HarvestTagsUsed || NextHarvest.HarvestType == "last")
         {
             parentManagementActivity.RotateCrop();
         }
     }
 }
 private void OnCLEMEndOfTimeStep(object sender, EventArgs e)
 {
     // rotate harvest if needed
     if (HarvestData.Count() > 0 && Clock.Today.Year * 100 + Clock.Today.Month == HarvestData.First().Year * 100 + HarvestData.First().Month)
     {
         // don't rotate activities that may have just had their enabled status changed in this timestep
         if (this.ActivityEnabled & Status != ActivityStatus.Ignored)
         {
             parentManagementActivity.RotateCrop();
         }
     }
 }
示例#9
0
        private void PopulateLV2()
        {
            listView1.Columns.Clear();
            listView1.Items.Clear();
            if (listBox2.SelectedIndex > -1)
            {
                NodeStats nS = null;
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    if (harvestStats.items[i].name == (string)listBox1.Items[listBox1.SelectedIndex])
                    {
                        nS = harvestStats.items[i];
                    }
                }
                ItemStats iS = null;
                for (int i = 0; i < listBox2.Items.Count; i++)
                {
                    if (nS.items[i].name == (string)listBox2.Items[listBox2.SelectedIndex])
                    {
                        iS = nS.items[i];
                    }
                }

                listView1.Columns.Clear();
                listView1.Items.Clear();
                listView1.Columns.Add("Time");
                listView1.Columns.Add("Action");
                listView1.Columns.Add("Amount");
                listView1.Columns.Add("Item Name");
                listView1.Columns.Add("Node Name");
                listView1.Columns.Add("Rare");
                listView1.Columns.Add("Bountiful");
                iS.items.Sort();
                for (int i = 0; i < iS.items.Count; i++)
                {
                    HarvestData  hD  = iS.items[i];
                    ListViewItem lvi = new ListViewItem(hD.time.ToLongTimeString());
                    lvi.SubItems.Add(hD.actionVerb);
                    lvi.SubItems.Add(hD.amount.ToString());
                    lvi.SubItems.Add(hD.itemName);
                    lvi.SubItems.Add(hD.nodeType);
                    lvi.SubItems.Add(hD.rare.ToString());
                    lvi.SubItems.Add(hD.bountiful.ToString());
                    listView1.Items.Add(lvi);
                }
                ResizeLVCols();
                label1.Text = String.Format("Data Selected: {0} - {1}", iS.parent.name, iS.name);
            }
        }
示例#10
0
        private void OnCLEMDoCutAndCarry(object sender, EventArgs e)
        {
            int year  = Clock.Today.Year;
            int month = Clock.Today.Month;

            if (NextHarvest != null)
            {
                //if this month is a harvest month for this crop
                if ((year == NextHarvest.HarvestDate.Year) && (month == NextHarvest.HarvestDate.Month))
                {
                    if (this.TimingOK)
                    {
                        double totalamount;
                        if (IsTreeCrop)
                        {
                            totalamount = NextHarvest.AmtKg * TreesPerHa * parentManagementActivity.Area * UnitsToHaConverter * (PercentKept / 100);
                        }
                        else
                        {
                            totalamount = NextHarvest.AmtKg * parentManagementActivity.Area * UnitsToHaConverter * (PercentKept / 100);
                        }

                        if (totalamount > 0)
                        {
                            //if Npct column was not in the file
                            if (double.IsNaN(NextHarvest.Npct))
                            {
                                //Add without adding any new nitrogen.
                                //The nitrogen value for this feed item in the store remains the same.
                                LinkedResourceItem.Add(totalamount, this.Name, "Harvest");
                            }
                            else
                            {
                                FoodResourcePacket packet = new FoodResourcePacket()
                                {
                                    Amount   = totalamount,
                                    PercentN = NextHarvest.Npct
                                };
                                LinkedResourceItem.Add(packet, this.Name, "Harvest");
                            }
                        }
                        SetStatusSuccess();
                    }
                    HarvestData.RemoveAt(0);
                }
            }
        }
示例#11
0
            public void AddHarvest(HarvestData item)
            {
                NodeStats all   = new NodeStats(" All", this);
                int       index = items.IndexOf(all);

                if (index > -1)
                {
                    all = items[index];
                }
                else
                {
                    items.Add(all);
                }
                NodeStats uniqueAction = new NodeStats(item.actionVerb, this);

                index = items.IndexOf(uniqueAction);
                if (index > -1)
                {
                    uniqueAction = items[index];
                }
                else
                {
                    items.Add(uniqueAction);
                }
                NodeStats uniqueNode = new NodeStats(item.nodeType, this);

                index = items.IndexOf(uniqueNode);
                if (index > -1)
                {
                    uniqueNode = items[index];
                }
                else
                {
                    items.Add(uniqueNode);
                }

                all.AddHarvest(item);
                uniqueAction.AddHarvest(item);
                uniqueNode.AddHarvest(item);
            }
示例#12
0
        public bool CompleteHarvest(AgricolaPlayer player, HarvestData data, out IClientGameUpdate update, out List <GameActionNotice> notices)
        {
            if (Mode == GameMode.Harvest && player.Harvesting && CanCompleteHarvest(player, data))
            {
                var conversions = data.FeedResources;
                var feedNotice  = new List <INoticePredicate>();
                int begAmount;
                player.FeedFamily(data.FeedResources, feedNotice, out begAmount);

                notices = new List <GameActionNotice>();
                ActionService.AssignAnimals(player, data.AnimalData, notices);

                UpdateScorecards();

                if (begAmount > 0)
                {
                    feedNotice.Add(new IdPredicate(begAmount));
                }

                notices.Add(new GameActionNotice(player.Name, NoticeVerb.Fed.ToString(), feedNotice));
                if (IsHarvestComplete())
                {
                    update = StartNextRound(notices);
                }
                else
                {
                    update = new PartialGameUpdate();
                    ((PartialGameUpdate)update).AddPlayer(player);
                }
                return(true);
            }

            update  = null;
            notices = null;
            return(false);
        }
示例#13
0
        private void OnCLEMStartOfTimeStep(object sender, EventArgs e)
        {
            // if harvest tags provided for this crop then they will be used to define previous, next etc

            // while date month > harvest record look for previous and delete past events

            if (HarvestData.Count() > 0)
            {
                int clockYrMth = CalculateYearMonth(Clock.Today);
                int position; // passed -1, current 0, future 1
                do
                {
                    int harvestYrMth = CalculateYearMonth(HarvestData.First().HarvestDate);
                    position = (clockYrMth > harvestYrMth) ? -1 : ((clockYrMth == harvestYrMth) ? 0 : 1);

                    // check for valid sequence
                    if (HarvestTagsUsed && HarvestData.FirstOrDefault().HarvestType != "")
                    {
                        if (previousTag == HarvestData.FirstOrDefault().HarvestType)
                        {
                            string warn = $"Invalid sequence of HarvetTags detected in [a={this.Name}]\r\nEnsure tags are ordered first, last in sequence.";
                            if (!Warnings.Exists(warn))
                            {
                                Summary.WriteWarning(this, warn);
                                Warnings.Add(warn);
                            }
                        }
                        previousTag = HarvestData.FirstOrDefault().HarvestType;
                    }


                    switch (position)
                    {
                    case -1:
                        if (HarvestTagsUsed)
                        {
                            switch (HarvestData.FirstOrDefault().HarvestType)
                            {
                            case "first":
                                if (!performedHarvest)
                                {
                                    InsideMultiHarvestSequence  = true;
                                    StartCurrentSequenceHarvest = HarvestData.FirstOrDefault();
                                    EndCurrentSequenceHarvest   = HarvestData.Where(a => a.HarvestType == "last").FirstOrDefault();
                                }
                                break;

                            case "last":
                                // hit tagged last to delete as we've passed this date so out of multi harvest sequence
                                InsideMultiHarvestSequence = false;
                                PreviousHarvest            = HarvestData.FirstOrDefault();
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            PreviousHarvest = HarvestData.FirstOrDefault();
                        }
                        HarvestData.RemoveAt(0);
                        break;

                    case 0:
                        performedHarvest = true;
                        if (HarvestTagsUsed)
                        {
                            switch (HarvestData.FirstOrDefault().HarvestType)
                            {
                            case "first":
                                // hit tagged first for current time step
                                InsideMultiHarvestSequence  = true;
                                StartCurrentSequenceHarvest = HarvestData.FirstOrDefault();
                                PreviousHarvest             = null;
                                EndCurrentSequenceHarvest   = HarvestData.Where(a => a.HarvestType == "last").FirstOrDefault();
                                break;

                            default:
                                NextHarvest     = HarvestData.FirstOrDefault();
                                PreviousHarvest = null;
                                break;
                            }
                        }
                        else
                        {
                            NextHarvest     = HarvestData.FirstOrDefault();
                            PreviousHarvest = null;
                        }
                        break;

                    case 1:
                        if (HarvestTagsUsed)
                        {
                            switch (HarvestData.FirstOrDefault().HarvestType)
                            {
                            case "first":
                                // hit tagged first for next harvest
                                NextHarvest = HarvestData.FirstOrDefault();
                                break;

                            default:
                                NextHarvest = HarvestData.FirstOrDefault();
                                break;
                            }
                        }
                        else
                        {
                            NextHarvest = HarvestData.FirstOrDefault();
                        }
                        break;

                    default:
                        break;
                    }
                } while (HarvestData.Count > 0 && position == -1);
            }
        }
示例#14
0
 private void OnCLEMStartOfTimeStep(object sender, EventArgs e)
 {
     PreviousHarvest = NextHarvest;
     NextHarvest     = HarvestData.FirstOrDefault();
 }
示例#15
0
 public void AddHarvest(HarvestData item)
 {
     items.Add(item);
 }
示例#16
0
        void oFormActMain_OnLogLineRead(bool isImport, LogLineEventArgs logInfo)
        {
            bool isRare;

            if (logInfo.detectedType == 0)
            {
                if (logInfo.logLine.EndsWith("You have found a rare item!"))
                {
                    rareNext = true;
                }
                if (logInfo.logLine.EndsWith("You make a bountiful harvest!"))
                {
                    bountifulHarvest = true;
                }
                Match regLineMatch = regHarvestAction.Match(logInfo.logLine);
                if (regLineMatch.Success)
                {
                    // The bountiful event is always the first log line of a harvest when it occurs.
                    // If the harvest is bountiful, there can be 2 harvest events.
                    // Both harvest events will have a common harvest (quantity > 1) and a rare quantity of 1.
                    // The rare flag should be set on a quantity of 1 harvest.
                    // The bountiful flag should be set for the first common harvest if the bountiful line was passed.
                    int qty = 0;
                    if (int.TryParse(regLineMatch.Groups["number"].Value, out qty))
                    {
                        isRare = false;
                        if (qty == 1 && rareNext)
                        {
                            isRare = true;
                        }
                        harvestStats.AddHarvest(new HarvestData(logInfo.detectedTime,
                                                                regHarvestAction.Replace(logInfo.logLine, "$1"), Int32.Parse(regHarvestAction.Replace(logInfo.logLine, "$2")),
                                                                regHarvestAction.Replace(logInfo.logLine, "$3"), regHarvestAction.Replace(logInfo.logLine, "$4"), isRare, bountifulHarvest, false));
                        if (isRare)
                        {
                            rareNext = false;
                        }
                        bountifulHarvest = false;
                        PopulateLBs();
                    }
                }
                else
                {
                    Match regBonusActionMatch = regBonusHarvestAction.Match(logInfo.logLine);
                    if (regBonusActionMatch.Success)
                    {
                        if (bonusHarvestData == null)
                        {
                            bonusHarvestData = new HarvestData(logInfo.detectedTime, regBonusActionMatch.Groups["actor"].Value, 0, "",
                                                               regBonusActionMatch.Groups["nodeType"].Value, false, false, true);
                        }
                        else
                        {
                            if (bonusHarvestData.time == logInfo.detectedTime)
                            {
                                bonusHarvestData.nodeType = regBonusActionMatch.Groups["nodeType"].Value;
                                harvestStats.AddHarvest(bonusHarvestData);
                                PopulateLBs();
                            }
                            bonusHarvestData = null;
                        }
                    }
                    else
                    {
                        Match regBonusHarvestMatch = regBonusHarvestReceive.Match(logInfo.logLine);
                        if (regBonusHarvestMatch.Success)
                        {
                            int qty = 0;
                            if (int.TryParse(regBonusHarvestMatch.Groups["number"].Value, out qty))
                            {
                                if (bonusHarvestData == null)
                                {
                                    bonusHarvestData = new HarvestData(logInfo.detectedTime, regBonusHarvestMatch.Groups["action"].Value, qty,
                                                                       regBonusHarvestMatch.Groups["itemName"].Value, "", false, false, true);
                                }
                                else
                                {
                                    if (bonusHarvestData.time == logInfo.detectedTime)
                                    {
                                        bonusHarvestData.amount     = qty;
                                        bonusHarvestData.actionVerb = regBonusHarvestMatch.Groups["action"].Value;
                                        bonusHarvestData.itemName   = regBonusHarvestMatch.Groups["itemName"].Value;
                                        harvestStats.AddHarvest(bonusHarvestData);
                                        PopulateLBs();
                                    }
                                    bonusHarvestData = null;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#17
0
        private async void FinishButton(object sender, RoutedEventArgs e)
        {
            var button = (Button)sender;

            button.IsEnabled        = false;
            userPlane.Visibility    = Visibility.Collapsed;
            dataRec.Visibility      = Visibility.Visible;
            detailsButton.IsEnabled = false;
            if (string.IsNullOrEmpty(PoeSessIdText.Text) || string.IsNullOrEmpty(UserNameText.Text) || string.IsNullOrEmpty(StashTabIndex.Text))
            {
                MessageBox.Show("Please fill every TextBox!");
                button.IsEnabled        = true;
                detailsButton.IsEnabled = true;
                userPlane.Visibility    = Visibility.Visible;
                dataRec.Visibility      = Visibility.Collapsed;
                return;
            }

            if (!new Regex(@"^[0-9]+(\,[0-9]+)*$").IsMatch(StashTabIndex.Text))
            {
                MessageBox.Show("Please use valid numbers for the Stash Tab Index.");
                button.IsEnabled        = true;
                detailsButton.IsEnabled = true;
                userPlane.Visibility    = Visibility.Visible;
                dataRec.Visibility      = Visibility.Collapsed;
                return;
            }
            List <string> errors = new List <string>();

            Main.Harvests.Clear();

            foreach (var split in StashTabIndex.Text.Split(","))
            {
                if (!int.TryParse(split, out int res))
                {
                    errors.Add($"{split} is not a valid number for stash index \r\n");
                    continue;
                }
                if (res == 0)
                {
                    errors.Add($"Stash tab index cannot be 0 or negative! \r\n");
                    continue;
                }
                var baseAddress     = new Uri("https://www.pathofexile.com/character-window/get-stash-items?league=Harvest&tabs=0&tabIndex=" + (res - 1).ToString() + "&accountName=" + UserNameText.Text);
                var cookieContainer = new CookieContainer();
                using var handler = new HttpClientHandler()
                      {
                          CookieContainer = cookieContainer
                      };

                using var client = new HttpClient(handler)
                      {
                          BaseAddress = baseAddress
                      };
                client.DefaultRequestHeaders.Add("User-Agent", "Harvest Beta 3_3 Horticrafting station extraction tool githubdotcomslashJeyR01slashHarvester");
                cookieContainer.Add(baseAddress, new Cookie("POESESSID", PoeSessIdText.Text));
                var result = await client.PostAsync(baseAddress, null);

                if (result.IsSuccessStatusCode)
                {
                    var resp = await result.Content.ReadAsStringAsync();

                    try
                    {
                        JObject jsont = JObject.Parse(resp);

                        JArray array = (JArray)jsont["items"];

                        if (array == null || array.Count == 0)
                        {
                            errors.Add($"Couldn't find any items in the selected stash tab ({split})! \r\n");
                            Thread.Sleep(1000);
                            continue;
                        }

                        foreach (var item in array)
                        {
                            var nametoken = item["typeLine"];
                            if (nametoken == null)
                            {
                                continue;
                            }
                            var name = (string)nametoken;
                            if (name != null && name == "Horticrafting Station")
                            {
                                var mods = (JArray)item["craftedMods"];
                                if (mods != null && mods.Count != 0)
                                {
                                    var      note       = item["note"];
                                    string[] priceNotes = new string[3] {
                                        "-", "-", "-"
                                    };
                                    if (note != null)
                                    {
                                        try
                                        {
                                            var notsplit = (string)note;
                                            if (notsplit.Count(p => p == '/') == 2)
                                            {
                                                priceNotes = notsplit.Split("/");
                                            }
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                    for (int i = 0; i < mods.Count; i++)
                                    {
                                        var modname = (string)mods[i];
                                        modname = modname.Replace("{", string.Empty).Replace("}", string.Empty).Replace("<white>", string.Empty);
                                        modname = modname.Remove(modname.Length - 4, 4);


                                        if (Main.Harvests.Any(p => p.Name == modname))
                                        {
                                            var craft = Main.Harvests.First(p => p.Name == modname);
                                            craft.Count++;
                                            if (priceNotes[i] != "-")
                                            {
                                                craft.SetPrice(priceNotes[i]);
                                            }
                                        }
                                        else
                                        {
                                            var craft = new HarvestData(Main.CheckBaseType(modname))
                                            {
                                                Comment = "Write a comment here!",
                                                Count   = 1,
                                                Name    = modname,
                                                //Price = "40c",
                                                //Type = Main.CheckBaseType(modname)
                                            };
                                            Main.Harvests.Add(craft);

                                            if (priceNotes[i] != "-")
                                            {
                                                craft.SetPrice(priceNotes[i]);
                                            }
                                        }

                                        //<white>{Remove} a random <white>{non-Life} modifier from an item and <white>{add} a new <white>{Life} modifier (78)
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        errors.Add($"Requesting Stash Tab {split} failed. \r\n");
                    }
                }
                else
                {
                    errors.Add($"Requesting Stash Tab {split} failed. Webserver responded with statuscode {result.StatusCode} \r\n");
                    //button.IsEnabled = true;
                    //userPlane.Visibility = Visibility.Visible;
                    //dataRec.Visibility = Visibility.Collapsed;
                    //break;
                }

                Thread.Sleep(1000); // as to not hammer the API
            }

            LatestDetails = new UpdateDetails
            {
                Sessionid = PoeSessIdText.Text,
                StashTabs = StashTabIndex.Text,
                UserName  = UserNameText.Text
            };
            SaveLastLogin();

            if (errors.Any(p => p != null))
            {
                var stringb = new StringBuilder();
                foreach (var item in errors.Where(p => p != null))
                {
                    stringb.Append(item);
                }
                MessageBox.Show(stringb.ToString());
                button.IsEnabled        = true;
                detailsButton.IsEnabled = true;
                userPlane.Visibility    = Visibility.Visible;
                dataRec.Visibility      = Visibility.Collapsed;
            }
            else
            {
                if (Main.Harvests.Any())
                {
                    MessageBox.Show("Successfully loaded the stash tabs!");
                    App.Current.Windows.OfType <PoeStashWindow>().First().Close();
                }
                else
                {
                    MessageBox.Show("Couldn't find any horti stations in the selectd stash tabs.");
                    button.IsEnabled        = true;
                    detailsButton.IsEnabled = true;
                    userPlane.Visibility    = Visibility.Visible;
                    dataRec.Visibility      = Visibility.Collapsed;
                }
            }
        }
示例#18
0
        /// <summary>
        /// Checks if the player can complete their harvest with the specified information
        /// </summary>
        /// <param name="player"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool CanCompleteHarvest(AgricolaPlayer player, HarvestData data)
        {
            if (!player.CanFeedFamily(data.FeedResources))
            {
                return(false);
            }

            var sheepUsedAsFood  = 0;
            var boarUsedAsFood   = 0;
            var cattleUsedAsFood = 0;

            var availableConversions = Curator.GetHarvestFoodValues(player);

            foreach (var conversion in data.FeedResources)
            {
                var conversionDefinition = availableConversions.FirstOrDefault(x => x.Id == conversion.Id &&
                                                                               x.InType == conversion.InType && x.InAmount == conversion.InAmount &&
                                                                               x.OutType == conversion.OutType);
                if (conversionDefinition == null)
                {
                    return(false);
                }

                if (conversionDefinition.InLimit.HasValue && conversionDefinition.InLimit.Value < conversion.Count / conversion.InAmount)
                {
                    return(false);
                }

                if (conversionDefinition.InType == Resource.Sheep)
                {
                    sheepUsedAsFood += conversion.Count * conversionDefinition.InAmount;
                }
                else if (conversionDefinition.InType == Resource.Boar)
                {
                    boarUsedAsFood += conversion.Count * conversionDefinition.InAmount;
                }
                else if (conversionDefinition.InType == Resource.Cattle)
                {
                    cattleUsedAsFood += conversion.Count * conversionDefinition.InAmount;
                }
            }

            // Calculate how many animals are left over after feeding during harvest
            // We aren't concerned with cooked animals yet, as the only animals that can be passed in as cooked
            // are the baby animals
            var sheepAfterFeeding  = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Sheep) - sheepUsedAsFood;
            var boarAfterFeeding   = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Boar) - boarUsedAsFood;
            var cattleAfterFeeding = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Cattle) - cattleUsedAsFood;

            data.AnimalData.Free[AnimalResource.Sheep]  += sheepUsedAsFood;
            data.AnimalData.Free[AnimalResource.Boar]   += boarUsedAsFood;
            data.AnimalData.Free[AnimalResource.Cattle] += cattleUsedAsFood;

            // Figure out which animals will breed
            var newAnimals = new Dictionary <AnimalResource, int>();

            newAnimals[AnimalResource.Sheep]  = sheepAfterFeeding >= 2 ? 1 : 0;
            newAnimals[AnimalResource.Boar]   = boarAfterFeeding >= 2 ? 1 : 0;
            newAnimals[AnimalResource.Cattle] = cattleAfterFeeding >= 2 ? 1 : 0;

            if (!ActionService.CanAssignAnimals(player, data.AnimalData, newAnimals))
            {
                return(false);
            }

            return(true);
        }