コード例 #1
0
        public static void OnNewDay()
        {
            OnNewDayForLocation(Game1.getFarm());
            OnNewDayForLocation(Game1.getLocationFromName(GreenhouseName));

            void OnNewDayForLocation(GameLocation location)
            {
                string locationName = FarmName;

                if (location.IsFarm)
                {
                    locationName = FarmName;
                }
                else if (location.IsGreenhouse)
                {
                    locationName = GreenhouseName;
                }

                ModEntry.GetMonitor().Log("Running Cultivation.OnNewDay for " + locationName, LogLevel.Trace);

                //Spawn weeds
                if (location.IsFarm && !Game1.IsWinter)
                {
                    List <Vector2> adjacents = new List <Vector2>();
                    foreach (Vector2 compostTile in Composting.CompostAppliedDays.Keys)
                    {
                        adjacents.AddRange(GetAdjacentTiles(compostTile));
                        adjacents.Add(compostTile);
                    }

                    foreach (Vector2 vec in adjacents)
                    {
                        if (CheckChance(Game1.wasRainingYesterday ? config.fertilized_rain_weed_grow_chance : config.fertilized_weed_grow_chance) && location.doesTileHaveProperty((int)vec.X, (int)vec.Y, "Diggable", "Back") != null && !location.isTileOccupied(vec, "") && location.isTilePassable(new Location((int)vec.X, (int)vec.Y), Game1.viewport))
                        {
                            int weedId = GameLocation.getWeedForSeason(random, Game1.currentSeason);
                            location.objects.Add(vec, new Object(vec, weedId, 1));
                        }
                    }
                }

                TempWaterStop[locationName].Clear();

                foreach (Vector2 vec in TempWaterOneDay[locationName])
                {
                    if (location.terrainFeatures.TryGetValue(vec, out TerrainFeature tf) && tf is HoeDirt hd)
                    {
                        hd.state.Value = HoeDirt.watered;
                        TempWaterStop[locationName].Add(vec);
                    }
                }

                TempWaterOneDay[locationName].Clear();

                foreach (Vector2 vec in TempWaterTwoDays[locationName])
                {
                    if (location.terrainFeatures.TryGetValue(vec, out TerrainFeature tf) && tf is HoeDirt hd)
                    {
                        hd.state.Value = HoeDirt.watered;
                        TempWaterOneDay[locationName].Add(vec);
                    }
                }

                TempWaterTwoDays[locationName].Clear();


                foreach (Vector2 vec in TempQualityFertilizer[locationName])
                {
                    if (location.terrainFeatures.TryGetValue(vec, out TerrainFeature tf) && tf is HoeDirt hd)
                    {
                        hd.fertilizer.Value = HoeDirt.noFertilizer;
                    }
                }
                TempQualityFertilizer[locationName].Clear();

                foreach (Vector2 vec in TempQualityIIFertilizer[locationName])
                {
                    if (location.terrainFeatures.TryGetValue(vec, out TerrainFeature tf) && tf is HoeDirt hd)
                    {
                        hd.fertilizer.Value = HoeDirt.noFertilizer;
                    }
                }
                TempQualityIIFertilizer[locationName].Clear();
            }
        }
コード例 #2
0
        public static void AddTrait(CropTrait trait, List <CropTrait> traits, int id)
        {
            ITranslationHelper trans = ModEntry.GetHelper().Translation;

            void add()
            {
                ModEntry.GetMonitor().Log($"Added {trait} to {CropSeedsDisplayName(id)}", LogLevel.Trace);
                Game1.showGlobalMessage(trans.Get("cult.msg_traitinc", new { traitdesc = GetTraitDescr(trait), seed = CropSeedsDisplayName(id), trait = GetTraitName(trait) }));
                Game1.playSound("achievement");
                traits.Add(trait);
                CropTraits[id] = traits;
            }

            bool alreadyContains() => traits.Contains(trait);

            CropTrait newTrait = GetNewRandomTrait(traits);

            if (traits.Contains(newTrait))
            {
                ModEntry.GetMonitor().Log("Bug: tried to find new trait with full list or returned wrong trait", LogLevel.Error);
                return;
            }

            if (alreadyContains())
            {
                switch (trait)
                {
                case CropTrait.PestResistanceI:
                    AddTrait(CropTrait.PestResistanceII, traits, id);
                    break;

                case CropTrait.WaterI:
                    AddTrait(CropTrait.WaterII, traits, id);
                    break;

                case CropTrait.QualityI:
                    AddTrait(CropTrait.QualityII, traits, id);
                    break;

                case CropTrait.SpeedI:
                    AddTrait(CropTrait.SpeedII, traits, id);
                    break;

                default:
                    AddTrait(newTrait, traits, id);
                    break;
                }
            }
            else
            {
                switch (trait)
                {
                case CropTrait.PestResistanceII:
                    if (traits.Contains(CropTrait.PestResistanceI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.PestResistanceI;
                        add();
                    }
                    break;

                case CropTrait.WaterII:
                    if (traits.Contains(CropTrait.WaterI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.WaterI;
                        add();
                    }

                    break;

                case CropTrait.QualityII:
                    if (traits.Contains(CropTrait.QualityI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.QualityI;
                        add();
                    }

                    break;

                case CropTrait.SpeedII:
                    if (traits.Contains(CropTrait.SpeedI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.SpeedI;
                        add();
                    }
                    break;

                default:
                    add();
                    break;
                }
            }
        }
コード例 #3
0
        public static void OnEndDay()
        {
            OnEndDayForLocation(Game1.getFarm());
            OnEndDayForLocation(Game1.getLocationFromName(GreenhouseName));

            void OnEndDayForLocation(GameLocation location)
            {
                string locationName = FarmName;

                if (location.IsFarm)
                {
                    locationName = FarmName;
                }
                else if (location.IsGreenhouse)
                {
                    locationName = GreenhouseName;
                }

                ModEntry.GetMonitor().Log("Running Cultivation.OnEndDay for " + locationName, LogLevel.Trace);

                foreach (KeyValuePair <Vector2, TerrainFeature> pair in location.terrainFeatures.Pairs)
                {
                    if (pair.Key is Vector2 vec && pair.Value is HoeDirt hd && hd.crop is Crop crop && crop != null)
                    {
                        if (crop.isWildSeedCrop())
                        {
                        }
                        else
                        {
                            List <CropTrait> traits = GetTraits(crop);

                            //ModEntry.GetMonitor().Log($"Traits for {vec}: ");
                            //traits.ForEach((CropTrait obj) => ModEntry.GetMonitor().Log(obj.ToString()));
                            //ModEntry.GetMonitor().Log($"GetWater returns "+GetWater(vec, traits, location.IsGreenhouse));

                            switch (GetQuality(vec, traits, location.IsGreenhouse))
                            {
                            case 0:     //normal
                                break;

                            case 1:     //better
                                if (hd.fertilizer.Value == HoeDirt.noFertilizer)
                                {
                                    TempQualityFertilizer[locationName].Add(vec);
                                    hd.fertilizer.Value = HoeDirt.fertilizerLowQuality;
                                }
                                break;

                            case 2:     //best
                                if (hd.fertilizer.Value == HoeDirt.noFertilizer)
                                {
                                    TempQualityIIFertilizer[locationName].Add(vec);
                                    hd.fertilizer.Value = HoeDirt.fertilizerHighQuality;
                                }
                                break;

                            default:
                                ModEntry.GetMonitor().Log("Bug: GetQuality returned wrong value", LogLevel.Error);
                                break;
                            }

                            switch (GetSpeed(vec, traits, location.IsGreenhouse))
                            {
                            case 0:     //reduced
                                if (GetRandomInt(100) <= config.minimal_speed_ungrow_chance)
                                {
                                    UngrowCrop(hd.crop, vec, "lacking speed trait or compost");
                                }
                                break;

                            case 1:     //normal
                                break;

                            case 2:     //better
                                if (GetRandomInt(100) <= config.speed_i_trait_grow_chance)
                                {
                                    hd.crop.newDay(HoeDirt.watered, HoeDirt.noFertilizer, (int)vec.X, (int)vec.Y, location);
                                }
                                break;

                            case 3:     //best
                                if (GetRandomInt(100) <= config.speed_ii_trait_grow_chance)
                                {
                                    hd.crop.newDay(HoeDirt.watered, HoeDirt.noFertilizer, (int)vec.X, (int)vec.Y, location);
                                }
                                break;

                            default:
                                ModEntry.GetMonitor().Log("Bug: GetSpeed returned wrong value", LogLevel.Error);
                                break;
                            }

                            switch (GetWater(vec, traits, location.IsGreenhouse))
                            {
                            case 0:     //reduced
                                if (hd.state.Value != HoeDirt.watered)
                                {
                                    UngrowCrop(hd.crop, vec, "lacking water trait or compost");
                                }
                                break;

                            case 1:     //normal
                                break;

                            case 2:     //better
                                if (hd.state.Value == HoeDirt.watered && !TempWaterOneDay[locationName].Contains(vec) && !TempWaterStop[locationName].Contains(vec))
                                {
                                    TempWaterOneDay[locationName].Add(vec);
                                }
                                break;

                            case 3:     //best
                                if (hd.state.Value == HoeDirt.watered && !TempWaterOneDay[locationName].Contains(vec) && !TempWaterStop[locationName].Contains(vec))
                                {
                                    TempWaterTwoDays[locationName].Add(vec);
                                }
                                break;

                            default:
                                ModEntry.GetMonitor().Log("Bug: GetWater returned wrong value", LogLevel.Error);
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        public static void OnEndDay()
        {
            foreach (KeyValuePair <Vector2, TerrainFeature> pair in Game1.getFarm().terrainFeatures.Pairs)
            {
                if (pair.Key is Vector2 vec && pair.Value is HoeDirt hd && hd.crop is Crop crop && crop != null)
                {
                    if (crop.isWildSeedCrop())
                    {
                        //TODO
                    }
                    else
                    {
                        List <CropTrait> traits = GetTraits(crop);

                        switch (GetQuality(vec, traits))
                        {
                        case 0:     //normal
                            break;

                        case 1:     //better
                            if (hd.fertilizer.Value == HoeDirt.noFertilizer)
                            {
                                TempQualityFertilizer.Add(vec);
                                hd.fertilizer.Value = HoeDirt.fertilizerLowQuality;
                            }
                            break;

                        case 2:     //best
                            if (hd.fertilizer.Value == HoeDirt.noFertilizer)
                            {
                                TempQualityIIFertilizer.Add(vec);
                                hd.fertilizer.Value = HoeDirt.fertilizerHighQuality;
                            }
                            break;

                        default:
                            ModEntry.GetMonitor().Log("Bug: GetQuality returned wrong value", LogLevel.Error);
                            break;
                        }

                        switch (GetSpeed(vec, traits))
                        {
                        case 0:     //reduced
                            if (GetRandomInt(100) <= config.minimal_speed_ungrow_chance)
                            {
                                UngrowCrop(hd.crop, vec, "lacking speed trait or compost");
                            }
                            break;

                        case 1:     //normal
                            break;

                        case 2:     //better
                            if (GetRandomInt(100) <= config.speed_i_trait_grow_chance)
                            {
                                hd.crop.newDay(HoeDirt.watered, HoeDirt.noFertilizer, (int)vec.X, (int)vec.Y, Game1.getFarm());
                            }
                            break;

                        case 3:     //best
                            if (GetRandomInt(100) <= config.speed_ii_trait_grow_chance)
                            {
                                hd.crop.newDay(HoeDirt.watered, HoeDirt.noFertilizer, (int)vec.X, (int)vec.Y, Game1.getFarm());
                            }
                            break;

                        default:
                            ModEntry.GetMonitor().Log("Bug: GetSpeed returned wrong value", LogLevel.Error);
                            break;
                        }

                        switch (GetWater(vec, traits))
                        {
                        case 0:     //reduced
                            if (hd.state.Value != HoeDirt.watered)
                            {
                                UngrowCrop(hd.crop, vec, "lacking water trait or compost");
                            }
                            break;

                        case 1:     //normal
                            break;

                        case 2:     //better
                            if (hd.state.Value == HoeDirt.watered && !TempWaterOneDay.Contains(vec) && !TempWaterStop.Contains(vec))
                            {
                                TempWaterOneDay.Add(vec);
                            }
                            break;

                        case 3:     //best
                            if (hd.state.Value == HoeDirt.watered && !TempWaterOneDay.Contains(vec) && !TempWaterStop.Contains(vec))
                            {
                                TempWaterTwoDays.Add(vec);
                            }
                            break;

                        default:
                            ModEntry.GetMonitor().Log("Bug: GetWater returned wrong value", LogLevel.Error);
                            break;
                        }
                    }
                }
            }
        }
コード例 #5
0
 public static SaveData AddToSaveData <T>(SaveData data, string name, T value)
 {
     ModEntry.GetHelper().Reflection.GetField <T>(data, name).SetValue(value);
     return(data);
 }
コード例 #6
0
 public static void AddBlueprint(CarpenterMenu menu)
 {
     ModEntry.GetHelper().Reflection.GetField <List <BluePrint> >(menu, "blueprints").GetValue().Add(GetComposterBlueprint());
 }
コード例 #7
0
        public static void AddTrait(CropTrait trait, List <CropTrait> traits, int id)
        {
            ITranslationHelper trans = ModEntry.GetHelper().Translation;

            string gettraitdescr()
            {
                switch (trait)
                {
                case CropTrait.PestResistanceI:
                case CropTrait.PestResistanceII:
                    return(trans.Get("cult.msg_traitdesc_pestres"));

                case CropTrait.QualityI:
                case CropTrait.QualityII:
                    return(trans.Get("cult.msg_traitdesc_quality"));

                case CropTrait.WaterI:
                case CropTrait.WaterII:
                    return(trans.Get("cult.msg_traitdesc_water"));

                case CropTrait.SpeedI:
                case CropTrait.SpeedII:
                    return(trans.Get("cult.msg_traitdesc_speed"));

                default:
                    return("ERROR gettraitdescr");
                }
            }

            string gettraitname()
            {
                switch (trait)
                {
                case CropTrait.PestResistanceI:
                    return(trans.Get("cult.msg_trait_pestresI"));

                case CropTrait.PestResistanceII:
                    return(trans.Get("cult.msg_trait_pestresII"));

                case CropTrait.QualityI:
                    return(trans.Get("cult.msg_trait_qualityI"));

                case CropTrait.QualityII:
                    return(trans.Get("cult.msg_trait_qualityII"));

                case CropTrait.WaterI:
                    return(trans.Get("cult.msg_trait_waterI"));

                case CropTrait.WaterII:
                    return(trans.Get("cult.msg_trait_waterII"));

                case CropTrait.SpeedI:
                    return(trans.Get("cult.msg_trait_speedI"));

                case CropTrait.SpeedII:
                    return(trans.Get("cult.msg_trait_speedII"));

                default:
                    return("ERROR gettraitname");
                }
            }

            void add()
            {
                ModEntry.GetMonitor().Log($"Added {trait} to {CropSeedsName(id)}", LogLevel.Trace);
                Game1.showGlobalMessage(trans.Get("cult.msg_traitinc", new { traitdesc = gettraitdescr(), seed = CropSeedsName(id), trait = gettraitname() }));
                traits.Add(trait);
                CropTraits[id] = traits;
            }

            bool alreadyContains() => traits.Contains(trait);

            CropTrait newTrait = GetNewRandomTrait(traits);

            if (traits.Contains(newTrait))
            {
                ModEntry.GetMonitor().Log("Bug: tried to find new trait with full list or returned wrong trait", LogLevel.Error);
                return;
            }

            if (alreadyContains())
            {
                switch (trait)
                {
                case CropTrait.PestResistanceI:
                    AddTrait(CropTrait.PestResistanceII, traits, id);
                    break;

                case CropTrait.WaterI:
                    AddTrait(CropTrait.WaterII, traits, id);
                    break;

                case CropTrait.QualityI:
                    AddTrait(CropTrait.QualityII, traits, id);
                    break;

                case CropTrait.SpeedI:
                    AddTrait(CropTrait.SpeedII, traits, id);
                    break;

                default:
                    AddTrait(newTrait, traits, id);
                    break;
                }
            }
            else
            {
                switch (trait)
                {
                case CropTrait.PestResistanceII:
                    if (traits.Contains(CropTrait.PestResistanceI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.PestResistanceI;
                        add();
                    }
                    break;

                case CropTrait.WaterII:
                    if (traits.Contains(CropTrait.WaterI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.WaterI;
                        add();
                    }

                    break;

                case CropTrait.QualityII:
                    if (traits.Contains(CropTrait.QualityI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.QualityI;
                        add();
                    }

                    break;

                case CropTrait.SpeedII:
                    if (traits.Contains(CropTrait.SpeedI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.SpeedI;
                        add();
                    }
                    break;

                default:
                    add();
                    break;
                }
            }
        }
コード例 #8
0
        public override void performHoverAction(int x, int y)
        {
            hoverApplyButton    = false;
            hoverActivateButton = false;
            hoverCancelButton   = false;

            if (!applyMode)
            {
                Item item = playerInventoryMenu.getItemAt(x, y);
                if (item == null)
                {
                    item = compostInventoryMenu.getItemAt(x, y);
                }

                if (state == State.fill && item != null)
                {
                    int   brown = Browns(item);
                    int   green = Greens(item);
                    float parts = (float)(green + brown) / Composting.one_part;

                    if (brown > 0 || green > 0)
                    {
                        hoverText = ModEntry.GetHelper().Translation.Get("composter.brown") + ": " + brown + " / " + ModEntry.GetHelper().Translation.Get("composter.green") + ": " + green + " (" + ModEntry.GetHelper().Translation.Get("composter.parts", new { parts }) + ")";
                    }
                    else
                    {
                        hoverText = "";
                    }
                }
                else if (state == State.fill && nutritionsComponent.GetBoundingBox().Contains(x, y))
                {
                    hoverText = ModEntry.GetHelper().Translation.Get("composter.greenbar");
                }
                else if (state == State.fill && nutritionsComponent.GoodDistribution() && activateButton.containsPoint(x, y))
                {
                    hoverText           = ModEntry.GetHelper().Translation.Get("composter.activate_button");
                    hoverActivateButton = true;
                }
                else if (state == State.ready && applyButton.containsPoint(x, y))
                {
                    hoverText        = ModEntry.GetHelper().Translation.Get("composter.apply_button");
                    hoverApplyButton = true;
                }
                else if (applyButton.containsPoint(x, y))
                {
                    hoverText        = ModEntry.GetHelper().Translation.Get("composter.apply_button_show");
                    hoverApplyButton = true;
                }
                else
                {
                    hoverText = "";
                }
            }
            else if (applyMode)
            {
                if (cancelButton.containsPoint(x, y))
                {
                    //hoverText = ModEntry.GetHelper().Translation.Get("composter.cancel_button");
                    hoverCancelButton = true;
                }
                else
                {
                    hoverText = "";
                }
            }

            base.performHoverAction(x, y);
        }
コード例 #9
0
        public override void draw(SpriteBatch b)
        {
            Rectangle rectButton(Rectangle rect, bool hover)
            {
                int off = hover ? hover_button_inc / 2 : 0;

                return(new Rectangle(rect.X - off, rect.Y - off, rect.Width + off + off, rect.Height + off + off));
            }

            if (!applyMode)
            {
                base.draw(b);

                //IClickableMenu.drawTextureBox(b, xPositionOnScreen - 96, yPositionOnScreen - 16, compostInventoryMenu.width + 64, compostInventoryMenu.height*2 + space + nutrition_area_height + space + 64*2, Color.White);
                IClickableMenu.drawTextureBox(b, xPositionOnScreen, yPositionOnScreen, width, height, Color.White);

                compostInventoryMenu.draw(b);
                playerInventoryMenu.draw(b);
                if (state == State.fill)
                {
                    nutritionsComponent.draw(b);
                }

                b.Draw(Game1.mouseCursors, rectButton(applyButton.bounds, hoverApplyButton), CursorsOkButtonRect, Color.White);

                if (state == State.fill && nutritionsComponent.GoodDistribution())
                {
                    b.Draw(Game1.mouseCursors, rectButton(activateButton.bounds, hoverActivateButton), CursorsPlayButtonRect, Color.White);
                }

                //int needed = nutritionsComponent.ItemsNeeded();
                //needed = needed <= 0 ? 0 : needed;

                switch (state)
                {
                case State.fill:
                    SpriteText.drawStringWithScrollCenteredAt(b, ModEntry.GetHelper().Translation.Get("composter.fillheadline", new { parts = nutritionsComponent.Parts(), min_needed = Composting.config.composter_min_parts }), Game1.viewport.Width / 2, 64);
                    break;

                case State.ready:
                    SpriteText.drawStringWithScrollCenteredAt(b, ModEntry.GetHelper().Translation.Get("composter.readyheadline", new { amount = Composting.ComposterCompostLeft[BinPos] }), Game1.viewport.Width / 2, 64);
                    break;

                case State.active:
                    SpriteText.drawStringWithScrollCenteredAt(b, ModEntry.GetHelper().Translation.Get("composter.activeheadline", new { amount = Composting.ComposterDaysLeft[BinPos] }), Game1.viewport.Width / 2, 64);
                    break;
                }
            }
            else //applyMode
            {
                int color = 0; //1: red, 0: green

                foreach (Vector2 v in greenTiles)
                {
                    b.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, (new Vector2(v.X, v.Y)) * 64f), CursorsColoredTileRect(color), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 0.999f);
                }
                foreach (Vector2 vec in Composting.CompostAppliedDays.Keys)
                {
                    b.DrawString(Game1.smallFont, Composting.CompostAppliedDays[vec].ToString(), Game1.GlobalToLocal(Game1.viewport, new Vector2(vec.X * Game1.tileSize + Game1.tileSize / 2, vec.Y * Game1.tileSize + Game1.tileSize / 2)), Color.White);
                }

                b.Draw(Game1.mouseCursors, rectButton(cancelButton.bounds, hoverCancelButton), CursorsCancelButtonRect, Color.White);
                if (Composting.ComposterCompostLeft.ContainsKey(BinPos) && Composting.ComposterCompostLeft[BinPos] > 0)
                {
                    SpriteText.drawStringWithScrollCenteredAt(b, ModEntry.GetHelper().Translation.Get("composter.applyheadline", new { amount = Composting.ComposterCompostLeft[BinPos] }), Game1.viewport.Width / 2, 64);
                }
            }

            drawMouse(b);
            if (heldItem != null)
            {
                heldItem.drawInMenu(b, new Vector2(Game1.getOldMouseX() + 32, Game1.getOldMouseY() - 32), 1);
            }

            if (hoverText.Length > 0)
            {
                drawHoverText(b, hoverText, Game1.smallFont, 0, 0, -1, null, -1, null, null, 0, -1, -1, -1, -1, 1f, null);
            }
        }
コード例 #10
0
 private void ShowError(string msg, object args = null)
 {
     Game1.showRedMessage(args == null ? ModEntry.GetHelper().Translation.Get(msg) : ModEntry.GetHelper().Translation.Get(msg, args));
 }