Esempio n. 1
0
        //Harvest Coops
        private void HarvestProducts()
        {
            Farm    pFarm  = Game1.getFarm();
            SFarmer Player = Game1.player;

            foreach (Building building in pFarm.buildings)
            {
                if (building is Coop)
                {
                    List <Vector2> coops = new List <Vector2>();

                    foreach (KeyValuePair <Vector2, SObject> pair in building.indoors.Objects)
                    {
                        SObject @object = pair.Value;
                        if (@object.isAnimalProduct() || @object.parentSheetIndex == 107)
                        {
                            if (this.AddToPlayer(@object, Player))
                            {
                                coops.Add(pair.Key);
                                Player.gainExperience(0, 5);
                            }
                        }
                    }
                    foreach (Vector2 iLocation in coops)
                    {
                        building.indoors.removeObject(iLocation, false);
                    }
                }
            }
        }
Esempio n. 2
0
        //Harvest Truffles
        private void HarvestTruffles()
        {
            Farm           pFarm    = Game1.getFarm();
            SFarmer        Player   = Game1.player;
            List <Vector2> truffles = new List <Vector2>();

            //Go through each truffle that needs to be removed.
            foreach (KeyValuePair <Vector2, SObject> pair in pFarm.Objects)
            {
                SObject @object = pair.Value;

                if (@object.name == "Truffle")
                {
                    bool doubleHarvest = false;

                    if (Player.professions.Contains(16))
                    {
                        @object.quality = 4;
                    }
                    double randomNum    = Game1.random.NextDouble();
                    bool   doubleChance = randomNum < 0.2 ? true : false;

                    if (Player.professions.Contains(13) && doubleChance)
                    {
                        @object.Stack = 2;
                        doubleHarvest = true;
                    }

                    if (this.AddToPlayer(@object, Player))
                    {
                        truffles.Add(pair.Key);
                        Player.gainExperience(2, 7);

                        if (doubleHarvest)
                        {
                            Player.gainExperience(2, 7);
                        }
                    }
                }
            }

            //Now we remove them
            foreach (Vector2 iLocation in truffles)
            {
                pFarm.removeObject(iLocation, false);
            }
        }
Esempio n. 3
0
        public static void digUpArtifactSpot(GameLocation location, int xLocation, int yLocation, SFarmer who)
        {
            string name        = ModEntry.MapName(location);
            Random random      = new Random(xLocation * 2000 + yLocation + (int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.daysPlayed);
            int    objectIndex = -1;
            Random artifact    = new Random();
            int    oIndex      = artifact.Next(0, ModEntry.instance.needArtifacts.Count);
            double rnd         = random.NextDouble();
            double addedChance = ModEntry.instance.artifactLuck();

            if (ModEntry.instance.debugging)
            {
                ModEntry.instance.Monitor.Log($"Rnd: {rnd} Added Chance: {addedChance}", LogLevel.Info);
            }
            //Process now
            if (ModEntry.instance.config.EnableArtifactLuck && ModEntry.instance.needArtifacts.Count != 0)
            {
                foreach (KeyValuePair <int, string> objectInfo in Game1.objectInformation)
                {
                    string[] oInfo = objectInfo.Value.Split('/');
                    if (oInfo[3].Contains("Arch"))
                    {
                        string[] locationChance = oInfo[6].Split(' ');
                        int      i = 0;
                        while (i < locationChance.Length)
                        {
                            if (locationChance[i].Equals(name) && rnd < (Convert.ToDouble(locationChance[i + 1], (IFormatProvider)CultureInfo.InvariantCulture) + addedChance))
                            {
                                if (ModEntry.instance.debugging)
                                {
                                    ModEntry.instance.Monitor.Log($"Spawned Needed Artifact {ModEntry.instance.needArtifacts[oIndex]}.", LogLevel.Info);
                                }
                                objectIndex = ModEntry.instance.needArtifacts[oIndex];
                                break;
                            }
                            i += 2;
                        }
                    }
                    if (objectIndex != -1)
                    {
                        break;
                    }
                }
            }
            else
            {
                foreach (KeyValuePair <int, string> objectInfo in Game1.objectInformation)
                {
                    string[] oInfo = objectInfo.Value.Split('/');
                    if (oInfo[3].Contains("Arch"))
                    {
                        string[] locationChance = oInfo[6].Split(' ');
                        int      i = 0;
                        while (i < locationChance.Length)
                        {
                            if (locationChance[i].Equals(name) && rnd < Convert.ToDouble(locationChance[i + 1], (IFormatProvider)CultureInfo.InvariantCulture))
                            {
                                if (ModEntry.instance.debugging)
                                {
                                    ModEntry.instance.Monitor.Log($"Spawned Default Item: {objectInfo.Key}", LogLevel.Info);
                                }
                                objectIndex = objectInfo.Key;
                                break;
                            }
                            i += 2;
                        }
                    }
                    if (objectIndex != -1)
                    {
                        break;
                    }
                }
            }
            if (rnd < 0.2 && !(Game1.currentLocation is Farm) && objectIndex == -1 || rnd < 0.2 && objectIndex == -1)
            {
                objectIndex = 102;
                if (ModEntry.instance.debugging)
                {
                    ModEntry.instance.Monitor.Log($"Changed objectIndex to 102(Lost Book)", LogLevel.Info);
                }
            }
            if (objectIndex == 102 && who.archaeologyFound.ContainsKey(102) && who.archaeologyFound[102][0] >= 21)
            {
                objectIndex = 770;
                if (ModEntry.instance.debugging)
                {
                    ModEntry.instance.Monitor.Log($"Changed objectIndex to 770(Mixed Seeds)", LogLevel.Info);
                }
            }
            //Start Spawning Items.
            if (objectIndex != -1)
            {
                Game1.createObjectDebris(objectIndex, xLocation, yLocation, who.uniqueMultiplayerID);
                who.gainExperience(5, 25);
                if (ModEntry.instance.debugging)
                {
                    ModEntry.instance.Monitor.Log($"objectIndex wasnt -1", LogLevel.Info);
                }
            }
            else if (Game1.currentSeason.Equals("winter") && rnd < 0.5 && !(Game1.currentLocation is Desert))
            {
                if (rnd < 0.4)
                {
                    Game1.createObjectDebris(416, xLocation, yLocation, who.uniqueMultiplayerID);
                    if (ModEntry.instance.debugging)
                    {
                        ModEntry.instance.Monitor.Log($"Season was winter. Changed objectIndex to 416(Snow Yam).", LogLevel.Info);
                    }
                }
                else
                {
                    Game1.createObjectDebris(412, xLocation, yLocation, who.uniqueMultiplayerID);
                    if (ModEntry.instance.debugging)
                    {
                        ModEntry.instance.Monitor.Log($"Season was winter. Changed objectIndex to 412(Winter Root)", LogLevel.Info);
                    }
                }
            }
            else
            {
                Dictionary <string, string> locations = Game1.content.Load <Dictionary <string, string> >("Data\\Locations");
                string[] mapObjChance = locations[name].Split('/')[8].Split(' ');
                if (mapObjChance.Length == 0 || mapObjChance.Equals("-1"))
                {
                    if (ModEntry.instance.debugging)
                    {
                        ModEntry.instance.Monitor.Log($"mapObjChance was either Zero or 01", LogLevel.Info);
                    }
                    return;
                }
                int i = 0;
                while (i < mapObjChance.Length)
                {
                    if (rnd < Convert.ToDouble(mapObjChance[i + 1]))
                    {
                        int objI = Convert.ToInt32(mapObjChance[i]);
                        if (Game1.objectInformation.ContainsKey(objI))
                        {
                            if (Game1.objectInformation[objI].Split('/').Contains("Arch") || objI == 102)
                            {
                                if (objI == 102 && who.archaeologyFound.ContainsKey(102) && who.archaeologyFound[102][0] >= 21)
                                {
                                    objI = 770;
                                    if (ModEntry.instance.debugging)
                                    {
                                        ModEntry.instance.Monitor.Log($"Lost Books exceeded 21 Changed to 770 (Mixed Seeds)", LogLevel.Info);
                                    }
                                    Game1.createObjectDebris(objI, xLocation, yLocation, who.uniqueMultiplayerID);
                                    break;
                                }
                            }
                        }
                        if (ModEntry.instance.debugging)
                        {
                            ModEntry.instance.Monitor.Log($"Created Multiple Objected {objI}", LogLevel.Info);
                        }
                        Game1.createMultipleObjectDebris(objI, xLocation, yLocation, random.Next(1, 4), who.uniqueMultiplayerID);
                        break;
                    }
                    i += 2;
                }
            }
        }
Esempio n. 4
0
        private void startPetting()
        {
            SFarmer Player = Game1.player;

            this.locations = GetAllLocations().ToArray();
            foreach (FarmAnimal animal in this.getAnimals())
            {
                try
                {
                    //Pet Animal
                    if (!animal.wasPet && this.EnablePetting)
                    {
                        animal.pet(Player);
                    }
                    //Do Harvest
                    if (animal.currentProduce > 0 && this.HarvestProduct)
                    {
                        if (animal.type.Equals("Pig"))
                        {
                            if (this.HarvestTruffle)
                            {
                                SObject @object = new SObject(animal.currentProduce, 1, false, -1, animal.produceQuality);
                                this.AddToPlayer(@object, Player);
                                animal.currentProduce = 0;
                                this.count++;
                            }
                        }
                        else
                        {
                            SObject @object = new SObject(animal.currentProduce, 1, false, -1, animal.produceQuality);
                            this.AddToPlayer(@object, Player);
                            animal.currentProduce = 0;
                            this.count++;
                        }
                    }
                }
                catch (Exception e)
                {
                    this.Monitor.Log($"Enountered an Error: {e.ToString()}.");
                }
            }
            //Start Harvesting of crops.
            foreach (GameLocation loc in this.locations)
            {
                if (loc.name.Contains("FarmExpan") || loc.name.Contains("Greenhouse") || loc.isFarm)
                {
                    foreach (KeyValuePair <Vector2, TerrainFeature> pair in loc.terrainFeatures)
                    {
                        var harvest = true;
                        if (pair.Value is HoeDirt dirt)
                        {
                            if (dirt.crop != null)
                            {
                                Crop crop = dirt.crop;
                                if (crop.currentPhase >= crop.phaseDays.Count - 1 && (!crop.fullyGrown || crop.dayOfCurrentPhase <= 0))
                                {
                                    SObject i = this.HarvestedCrop(dirt, crop, (int)pair.Key.X, (int)pair.Key.Y);
                                    if (this.AddToPlayer(i, Player))
                                    {
                                        harvest = true;
                                        //Todo SunFlowers
                                    }
                                    else
                                    {
                                        harvest = false;
                                    }
                                    if (harvest)
                                    {
                                        int PlaceHolder = 0;
                                        if (PlaceHolder == 1)
                                        {
                                            //Will be to sale
                                        }
                                        else
                                        {
                                            if (crop.regrowAfterHarvest != -1)
                                            {
                                                crop.dayOfCurrentPhase = crop.regrowAfterHarvest;
                                            }
                                            else
                                            {
                                                dirt.destroyCrop(pair.Key);
                                            }
                                            if (crop.dead)
                                            {
                                                dirt.destroyCrop(pair.Key);
                                            }
                                        }
                                        float exp = (float)(16.0 * Math.Log(0.018 * Convert.ToInt32(Game1.objectInformation[crop.indexOfHarvest].Split('/')[1]) + 1.0, Math.E));
                                        Player.gainExperience(0, (int)Math.Round(exp));
                                        count++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.HarvestTruffles();
            this.HarvestProducts();
            this.CheckPets();
            if (this.count > 0 && this.HelperCost > 0)
            {
                int  total       = this.count * this.HelperCost;
                bool EnoughMoney = Player.Money >= total ? true : false;
                if (EnoughMoney)
                {
                    Player.Money = Math.Max(0, (Player.Money - total));
                    string msg = $"Dear {Player.name}^^ We came by while you were sleeping and took care of your farm for you. ^We did a total of {this.count} tasks for you at a cost of {total} Gold.^We also pet and watered your pet, if you have one. Free of charge.^^Sincerly MizzionInc";
                    this.count = 0;
                    Game1.activeClickableMenu = (IClickableMenu) new LetterViewerMenu(msg);
                }
            }
        }