void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e) { Vector2 grabTile = e.Cursor.GrabTile; //Monitor.Log($"obj: {Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y)?.Name}"); //Object obj2 = Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y); //Monitor.Log("1" + (obj2 is Object && obj2 != null)); //Monitor.Log("2" + (e.Button.IsActionButton())); //Monitor.Log("3" + obj2.Name.Equals("Seed Maker")); //Monitor.Log("4" + (obj2.heldObject?.Value != null)); //Monitor.Log("5" + obj2.heldObject.Value.CanBeGrabbed); if (Game1.currentLocation != null && Game1.activeClickableMenu == null && Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y) is Object obj && obj != null && e.Button.IsActionButton() && obj.Name.Equals("Seed Maker")) { if (obj.heldObject?.Value != null && obj.heldObject?.Value.Category == Object.SeedsCategory && obj.readyForHarvest && Game1.player.couldInventoryAcceptThisObject(obj.heldObject.Value.ParentSheetIndex, obj.heldObject.Value.Stack)) { //Monitor.Log("Detected Seeds in Seed Maker", LogLevel.Alert); Cultivation.NewSeeds(obj.heldObject.Value.ParentSheetIndex); } else if (obj.heldObject?.Value == null && Game1.player.ActiveObject?.Category == Object.SeedsCategory) { if (Cultivation.GetCropItemFromSeeds(Game1.player.ActiveObject) is Object crop) { Game1.activeClickableMenu = new SeedsInfoMenu(Game1.player.ActiveObject, crop); } } } /*if (e.Button.IsActionButton() && Game1.currentLocation is Farm farm && Game1.activeClickableMenu == null && Composting.IsComposter(farm.getBuildingAt(grabTile))) * { * Game1.activeClickableMenu = new ComposterMenu(); * }*/ }
void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e) { Vector2 grabTile = e.Cursor.GrabTile; if (Game1.currentLocation != null && Game1.activeClickableMenu == null && e.Button.IsActionButton()) { if (Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y) is Object obj && obj != null && obj.Name.Equals("Seed Maker")) { if (obj.heldObject?.Value != null && obj.heldObject?.Value.Category == Object.SeedsCategory && obj.readyForHarvest && Game1.player.couldInventoryAcceptThisObject(obj.heldObject.Value.ParentSheetIndex, obj.heldObject.Value.Stack)) { //Monitor.Log("Detected Seeds in Seed Maker", LogLevel.Alert); //Cultivation.NewSeeds(obj.heldObject.Value.ParentSheetIndex); //TODO should be unneccessary now } else if (obj.heldObject?.Value == null && Game1.player.ActiveObject?.Category == Object.SeedsCategory) { if (Cultivation.GetCropItemFromSeeds(Game1.player.ActiveObject) is Object crop) { Game1.activeClickableMenu = new SeedsInfoMenu(Game1.player.ActiveObject, crop, false); } } } else if (Game1.currentLocation is Farm farm && farm.getBuildingAt(grabTile) is CompostingBin && Game1.player.ActiveObject?.Category == Object.SeedsCategory) { if (Cultivation.GetCropItemFromSeeds(Game1.player.ActiveObject) is Object crop) { Game1.activeClickableMenu = new SeedsInfoMenu(Game1.player.ActiveObject, crop, true); } }
public SeedsInfoMenu(StardewValley.Object seeds, StardewValley.Object crop) : base(" ") { this.seeds = seeds; this.crop = crop; List <CropTrait> traits = Cultivation.GetTraits(seeds); drawTraits = Cultivation.GetTraits(seeds).Where((CropTrait trait) => { if (traits.Contains(CropTrait.PestResistanceII) && trait == CropTrait.PestResistanceI) { return(false); } if (traits.Contains(CropTrait.WaterII) && trait == CropTrait.WaterI) { return(false); } if (traits.Contains(CropTrait.SpeedII) && trait == CropTrait.SpeedI) { return(false); } if (traits.Contains(CropTrait.QualityII) && trait == CropTrait.QualityI) { return(false); } return(true); }).ToList(); }
void SeedMakerController_HeldItemRemoved(object sender, SeedMakerEventArgs e) { if (e.HeldItem != null && e.HeldItem.Category == Object.SeedsCategory) { Cultivation.NewSeeds(e.HeldItem.ParentSheetIndex); } }
public override void draw(SpriteBatch b) { base.draw(b); if ((int)ModEntry.GetHelper().Reflection.GetField <float>(this, "scale").GetValue() == 1) { SpriteText.drawString(b, ModEntry.GetHelper().Translation.Get(withCompost ? "cult.msg_headline_traitinfo_compost" : "cult.msg_headline_traitinfo", new { seeds = seeds.DisplayName }), xPositionOnScreen + 32, yPositionOnScreen + 32, 999999, width - 64, 999999, 0.75f, 0.865f, false, -1, "", -1 /*8 7*/); if (cropObj.isWildSeedCrop()) { SpriteText.drawString(b, ModEntry.GetHelper().Translation.Get("cult.msg_wild_seed"), xPositionOnScreen + 32, 2 * (48 + 16) + yPositionOnScreen + 32, 999999, width - 64, 999999, 0.75f, 0.865f, false, -1, "", -1); } else { for (int i = 1; i <= drawTraits.Count; i++) { SpriteText.drawString(b, Cultivation.GetTraitName(drawTraits[i - 1]) + ": " + Cultivation.GetTraitLongDescr(drawTraits[i - 1]), xPositionOnScreen + 32, i * 2 * (48 + 16) + yPositionOnScreen + 32, 999999, width - 64, 999999, 0.75f, 0.865f, false, -1, "", -1 /*8 7*/); //SpriteText.drawString(b, Cultivation.GetTraitLongDescr(drawTraits[i - 1]), xPositionOnScreen + 32 + 32, (i+1) * 2 * 48 + yPositionOnScreen + 32, 999999, width - 64, 999999, 0.75f, 0.865f, false, -1, "", -1/*8 7*/); } //if (drawTraits.Count == 0) // SpriteText.drawString(b, ModEntry.GetHelper().Translation.Get("cult.msg_non"), xPositionOnScreen + 32, 2 * (48 + 16) + yPositionOnScreen + 32, 999999, width - 64, 999999, 0.75f, 0.865f, false, -1, "", -1/*8 7*/); } } if (!Game1.options.hardwareCursor) { b.Draw(Game1.mouseCursors, new Vector2((float)Game1.getMouseX(), (float)Game1.getMouseY()), Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 0, 16, 16), Color.White, 0f, Vector2.Zero, 4f + Game1.dialogueButtonScale / 150f, SpriteEffects.None, 1f); } }
/// <summary> /// Pests eat the crop by decreasing its phase. If the phase reaches 0, the crop is set to dead. /// </summary> /// <returns><c>true</c>, if crop was killed or is non-existent, <c>false</c> otherwise.</returns> public bool NomNom() { if (hd.crop == null) { return(true); } return(Cultivation.UngrowCrop(hd.crop, pos, "Pest")); }
public override void Entry(IModHelper helper) { _Monitor = Monitor; _Helper = helper; Config conf = helper.ReadConfig <Config>(); Pests.Init(conf); Cultivation.Init(conf); Composting.Init(conf); SMC = new SeedMakerController(helper, Monitor); SMC.HeldItemRemoved += SeedMakerController_HeldItemRemoved; helper.Events.Display.RenderingHud += Display_RenderingHud; helper.Events.GameLoop.DayStarted += GameLoop_DayStarted; helper.Events.Input.ButtonPressed += Input_ButtonPressed; helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked; helper.Events.GameLoop.Saving += GameLoop_Saving; helper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded; helper.Events.GameLoop.DayEnding += GameLoop_DayEnding; helper.Events.Display.MenuChanged += Display_MenuChanged; helper.Events.World.BuildingListChanged += World_BuildingListChanged; //helper.Events.Player.Warped += Player_Warped; Helper.ConsoleCommands.Add("cpc_clearcompost", "", (string arg1, string[] arg2) => { Composting.CompostAppliedDays.Clear(); Composting.ComposterDaysLeft.Clear(); Composting.ComposterCompostLeft.Clear(); }); Helper.ConsoleCommands.Add("cpc_clearcomposterinv", "", (string arg1, string[] arg2) => { Composting.ComposterContents.Clear(); }); Helper.ConsoleCommands.Add("cpc_clearpests", "", (string arg1, string[] arg2) => { Pests.pests.Clear(); }); Helper.ConsoleCommands.Add("cpc_cleartraits", "", (string arg1, string[] arg2) => { Cultivation.CropSeeds.Clear(); Cultivation.CropTraits.Clear(); }); }
void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e) { Composting.Load(); Cultivation.Load(); Pests.Load(); /* * for (int i = 0; i < 10; i++) * Helper.ConsoleCommands.Trigger("player_add", new string[2] { "name", "Seed Maker" }); * Helper.ConsoleCommands.Trigger("player_add", new string[3] { "name", "Melon", "100" }); * */ }
void GameLoop_Saving(object sender, StardewModdingAPI.Events.SavingEventArgs e) { try { SaveData data = new SaveData(); Pests.Save(data); Cultivation.Save(data); Composting.Save(data); ModEntry.GetHelper().Data.WriteSaveData <SaveData>(nameof(SaveData), data); } finally { Composting.ResetCompostingBins(); } }
void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e) { Vector2 grabTile = e.Cursor.GrabTile; //Monitor.Log($"obj: {Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y)?.Name}"); //Object obj2 = Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y); //Monitor.Log("1" + (obj2 is Object && obj2 != null)); //Monitor.Log("2" + (e.Button.IsActionButton())); //Monitor.Log("3" + obj2.Name.Equals("Seed Maker")); //Monitor.Log("4" + (obj2.heldObject?.Value != null)); //Monitor.Log("5" + obj2.heldObject.Value.CanBeGrabbed); if (Game1.currentLocation != null && Game1.currentLocation.getObjectAtTile((int)grabTile.X, (int)grabTile.Y) is Object obj && obj != null && e.Button.IsActionButton() && obj.Name.Equals("Seed Maker") && obj.heldObject?.Value != null && obj.heldObject?.Value.Category == Object.SeedsCategory && obj.readyForHarvest && !Game1.player.isInventoryFull()) { //Monitor.Log("Detected Seeds in Seed Maker", LogLevel.Alert); Cultivation.NewSeeds(obj.heldObject.Value.ParentSheetIndex); } }
public override void Entry(IModHelper helper) { _Monitor = Monitor; _Helper = helper; Config conf = helper.ReadConfig <Config>(); Pests.Init(conf); Cultivation.Init(conf); helper.Events.Display.RenderingHud += Display_RenderingHud; helper.Events.GameLoop.DayStarted += GameLoop_DayStarted; helper.Events.Input.ButtonPressed += Input_ButtonPressed; helper.Events.GameLoop.Saving += GameLoop_Saving; helper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded; helper.Events.GameLoop.DayEnding += GameLoop_DayEnding; }
public SeedsInfoMenu(StardewValley.Object seeds, StardewValley.Object crop, bool withCompost) : base(" ") { this.seeds = seeds; this.crop = crop; this.withCompost = withCompost; cropObj = new Crop(seeds.ParentSheetIndex, 0, 0); List <CropTrait> traits = Cultivation.GetTraits(seeds); drawTraits = Cultivation.GetTraits(seeds).Where((CropTrait trait) => { if (traits.Contains(CropTrait.PestResistanceII) && trait == CropTrait.PestResistanceI) { return(false); } if (traits.Contains(CropTrait.WaterII) && trait == CropTrait.WaterI) { return(false); } if (traits.Contains(CropTrait.SpeedII) && trait == CropTrait.SpeedI) { return(false); } if (traits.Contains(CropTrait.QualityII) && trait == CropTrait.QualityI) { return(false); } return(true); }).ToList(); AddMissingTraits(drawTraits); if (withCompost) { IncreaseTraits(drawTraits); } }
void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e) { SaveData data = null; try { data = Helper.Data.ReadSaveData <SaveData>(nameof(SaveData)); } finally { if (data == null) { Monitor.Log($"No save data with key '{nameof(SaveData)}' found"); data = new SaveData(); } data.InitNullValues(); Composting.Load(data); Cultivation.Load(data); Pests.Load(data); } }
public static Pest TryInfestCrop(Vector2 pos, HoeDirt hd) { if (hd == null || hd != null && hd.crop == null || hd.crop.dead.Value || hd.crop.isWildSeedCrop() || pests.Exists((Pest p) => p.HasPosition(pos))) { return(null); } List <CropTrait> traits = Cultivation.GetTraits(hd.crop); switch (Cultivation.GetPestRes(pos, traits, false)) { case 0: break; case 1: if (CheckChance(config.pest_resistance_i_chance)) { return(null); } break; case 2: if (CheckChance(config.pest_resistance_ii_chance)) { return(null); } break; default: ModEntry.GetMonitor().Log("Bug: GetPestRes returned wrong value", LogLevel.Error); break; } Pest pest = new Pest(pos, hd); return(pest); }
void GameLoop_Saving(object sender, StardewModdingAPI.Events.SavingEventArgs e) { Pests.Save(); Cultivation.Save(); }
void GameLoop_DayEnding(object sender, StardewModdingAPI.Events.DayEndingEventArgs e) { Cultivation.OnEndDay(); }
void GameLoop_DayStarted(object sender, StardewModdingAPI.Events.DayStartedEventArgs e) { Composting.OnNewDay(); Pests.OnNewDay(); Cultivation.OnNewDay(); }