Example #1
0
        private bool CheckForAction(Farmer farmer, CrabPot pot, CrabNetStats stats)
        {
            if (!this.CanAfford(farmer, this.CostPerCheck, stats))
            {
                return(false);
            }

            if (pot.tileIndexToShow == 714)
            {
                if (farmer.IsMainPlayer && !this.AddItemToInventory(pot.heldObject.Value, farmer, Game1.getFarm()))
                {
                    Game1.addHUDMessage(new HUDMessage("Inventory Full", Color.Red, 3500f));
                    return(false);
                }
                Dictionary <int, string> dictionary = this.Helper.Content.Load <Dictionary <int, string> >("Data\\Fish", ContentSource.GameContent);
                if (dictionary.ContainsKey(pot.heldObject.Value.ParentSheetIndex))
                {
                    string[] strArray = dictionary[pot.heldObject.Value.ParentSheetIndex].Split('/');
                    int      minValue = strArray.Length > 5 ? Convert.ToInt32(strArray[5]) : 1;
                    int      num      = strArray.Length > 5 ? Convert.ToInt32(strArray[6]) : 10;
                    farmer.caughtFish(pot.heldObject.Value.ParentSheetIndex, Game1.random.Next(minValue, num + 1));
                }
                pot.readyForHarvest.Value = false;
                pot.heldObject.Value      = null;
                pot.tileIndexToShow       = 710;
                pot.bait.Value            = null;
                farmer.gainExperience(1, 5);

                return(true);
            }
            return(false);
        }
Example #2
0
        private bool CheckForAction(Farmer farmer, CrabPot pot, CrabNetStats stats)
        {
            if (!this.CanAfford(farmer, this.CostPerCheck, stats))
            {
                return(false);
            }

            if (pot.tileIndexToShow == 714)
            {
                if (farmer.IsMainPlayer && !this.AddItemToInventory(pot.heldObject.Value, farmer, Game1.getFarm()))
                {
                    Game1.addHUDMessage(new HUDMessage("Inventory Full", Color.Red, 3500f));
                    return(false);
                }
                Dictionary <int, string> dictionary = this.Helper.Content.Load <Dictionary <int, string> >("Data\\Fish", ContentSource.GameContent);
                if (this.GetFishSize(pot.heldObject.Value.ParentSheetIndex, out int minSize, out int maxSize))
                {
                    farmer.caughtFish(pot.heldObject.Value.ParentSheetIndex, Game1.random.Next(minSize, maxSize + 1));
                }
                pot.readyForHarvest.Value = false;
                pot.heldObject.Value      = null;
                pot.tileIndexToShow       = 710;
                pot.bait.Value            = null;
                farmer.gainExperience(1, 5);

                return(true);
            }
            return(false);
        }
Example #3
0
        private void ShowMessage(CrabNetStats stats, int totalCost)
        {
            string message = "";

            if (this.Checker.ToLower() == "spouse")
            {
                if (Game1.player.isMarried())
                {
                    message += this.DialogueManager.PerformReplacement(this.Dialog[1], stats, this.Config);
                }
                else
                {
                    message += this.DialogueManager.PerformReplacement(this.Dialog[2], stats, this.Config);
                }

                if (totalCost > 0 && !this.Free)
                {
                    message += this.DialogueManager.PerformReplacement(this.Dialog[3], stats, this.Config);
                }

                HUDMessage msg = new HUDMessage(message);
                Game1.addHUDMessage(msg);
            }
            else
            {
                NPC character = Game1.getCharacterFromName(this.Checker);
                if (character != null)
                {
                    message += this.DialogueManager.PerformReplacement(this.GetRandomMessage(this.Greetings), stats, this.Config);
                    message += " " + this.DialogueManager.PerformReplacement(this.Dialog[4], stats, this.Config);

                    if (!this.Free)
                    {
                        this.DialogueManager.PerformReplacement(this.Dialog[5], stats, this.Config);

                        if (stats.HasUnfinishedBusiness())
                        {
                            if (this.InventoryAndChestFull)
                            {
                                message += this.DialogueManager.PerformReplacement(this.GetRandomMessage(this.InventoryMessages), stats, this.Config);
                            }
                            else
                            {
                                if (this.AllowFreebies)
                                {
                                    message += this.DialogueManager.PerformReplacement(this.GetRandomMessage(this.FreebieMessages), stats, this.Config);
                                }
                                else
                                {
                                    message += " " + this.DialogueManager.PerformReplacement(this.GetRandomMessage(this.UnfinishedMessages), stats, this.Config);
                                }
                            }
                        }

                        message += this.DialogueManager.PerformReplacement(this.GetRandomMessage(this.Smalltalk), stats, this.Config);
                        message += "#$e#";
                    }
                    else
                    {
                        message += this.DialogueManager.PerformReplacement(this.GetRandomMessage(this.Smalltalk), stats, this.Config);
                        message += "#$e#";
                    }

                    character.CurrentDialogue.Push(new Dialogue(message, character));
                    Game1.drawDialogue(character);
                }
                else
                {
                    message += this.DialogueManager.PerformReplacement(this.Dialog[6], stats, this.Config);
                    HUDMessage msg = new HUDMessage(message);
                    Game1.addHUDMessage(msg);
                }
            }
        }
Example #4
0
 private bool CanAfford(Farmer farmer, int amount, CrabNetStats stats)
 {
     // Calculate the running cost (need config passed for that) and determine if additional puts you over.
     return((amount + stats.RunningTotal) <= farmer.Money);
 }
Example #5
0
        private void IterateOverCrabPots()
        {
            // reset this each time invoked, it is a flag to determine if uncompleted work is due to inventory or money.
            this.InventoryAndChestFull = false;
            CrabNetStats stats = new CrabNetStats();

            foreach (GameLocation location in Game1.locations)
            {
                if (location.IsOutdoors)
                {
                    foreach (SObject obj in location.Objects.Values)
                    {
                        if (obj.Name == "Crab Pot")
                        {
                            stats.NumTotal++;

                            if (!this.Free && !this.CanAfford(Game1.player, this.CostPerCheck, stats) && !this.AllowFreebies)
                            {
                                this.Monitor.Log("Couldn't afford to check.", LogLevel.Trace);
                                stats.NotChecked++;
                                continue;
                            }

                            stats.NumChecked++;
                            stats.RunningTotal += this.CostPerCheck;

                            CrabPot pot = (CrabPot)obj;

                            if (pot.heldObject.Value != null && pot.heldObject.Value.Category != -21)
                            {
                                if (!this.Free && !this.CanAfford(Game1.player, this.CostPerEmpty, stats) && !this.AllowFreebies)
                                {
                                    this.Monitor.Log("Couldn't afford to empty.", LogLevel.Trace);
                                    stats.NotEmptied++;
                                    continue;
                                }

                                if (this.CheckForAction(Game1.player, pot, stats))
                                {
                                    stats.NumEmptied++;
                                    stats.RunningTotal += this.CostPerEmpty;
                                }
                            }
                            else
                            {
                                stats.NothingToRetrieve++;
                            }

                            if (pot.bait.Value == null && pot.heldObject.Value == null && !Game1.player.professions.Contains(11))
                            {
                                SObject b = new SObject(this.BaitChoice, 1);

                                if (!this.Free && !this.CanAfford(Game1.player, this.BaitCost, stats) && !this.AllowFreebies && this.ChargeForBait)
                                {
                                    this.Monitor.Log("Couldn't afford to bait.", LogLevel.Trace);
                                    stats.NotBaited++;
                                    continue;
                                }

                                if (this.PerformObjectDropInAction(b, Game1.player, pot))
                                {
                                    stats.NumBaited++;
                                    if (this.ChargeForBait)
                                    {
                                        stats.RunningTotal += this.BaitCost;
                                    }
                                }
                            }
                            else
                            {
                                stats.NothingToBait++;
                            }
                        }
                    }
                }
            }

            int totalCost = (stats.NumChecked * this.CostPerCheck);

            totalCost += (stats.NumEmptied * this.CostPerEmpty);
            if (this.ChargeForBait)
            {
                totalCost += (this.BaitCost * stats.NumBaited);
            }
            if (this.Free)
            {
                totalCost = 0;
            }

            if (this.LoggingEnabled)
            {
                this.Monitor.Log($"CrabNet checked {stats.NumChecked} pots. You used {stats.NumBaited} bait to reset.", LogLevel.Trace);
                if (!this.Free)
                {
                    this.Monitor.Log($"Total cost was {totalCost}g. Checks: {stats.NumChecked * this.CostPerCheck}, Emptied: {stats.NumEmptied * this.CostPerEmpty}, Bait: {stats.NumBaited * this.BaitCost}", LogLevel.Trace);
                }
            }

            if (!this.Free)
            {
                Game1.player.Money = Math.Max(0, Game1.player.Money + (-1 * totalCost));
            }

            if (this.EnableMessages)
            {
                this.ShowMessage(stats, totalCost);
            }
        }