public virtual void PerformCraft(IPerformCraftEvent evt) { if (evt.Item is null) { evt.Cancel(); } else { evt.Complete(); } }
public void PerformCraft(IPerformCraftEvent evt) { evt.Complete(); }
public override void receiveLeftClick(int x, int y, bool playSound = true) { if (frozen) { return; } if (btnCancel.containsPoint(x, y)) { if (!readyToClose()) { Game1.playSound("cancel"); return; } Game1.playSound("smallSelect"); exitThisMenu(); Game1.player.forceCanMove(); return; } if (Location is null) { return; } Vector2 mouseTile = new( (Game1.viewport.X + Game1.getOldMouseX(ui_scale: false)) / 64, (Game1.viewport.Y + Game1.getOldMouseY(ui_scale: false)) / 64 ); if (Action == ActionType.Build && Blueprint != null) { Game1.player.team.buildLock.RequestLock(delegate { if (!Location.buildStructure( Blueprint, mouseTile, Game1.player, true )) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CantBuild"), Color.Red, 3500f)); return; } Building building = Location.buildings.Last(); int day = Game1.dayOfMonth; while (Utility.isFestivalDay(day, Game1.currentSeason)) { day++; } // We use dayUpdate to finish the construction so that any // custom behavior gets called. building.daysOfConstructionLeft.Value = 1; building.dayUpdate(day); frozen = true; DelayedAction.functionAfterDelay(delegate { Event.Complete(); exitThisMenu(); Game1.player.forceCanMove(); }, 2000); }); } if (Action == ActionType.Upgrade && Blueprint != null) { Building?building = Location.getBuildingAt(mouseTile); if (building != null) { if (building.buildingType.Value == Blueprint.nameOfBuildingToUpgrade) { building.showUpgradeAnimation(Location); Game1.playSound("axe"); int day = Game1.dayOfMonth; while (Utility.isFestivalDay(day, Game1.currentSeason)) { day++; } // We use dayUpdate to finish the construction so that any // custom behavior gets called. building.daysUntilUpgrade.Value = 1; building.dayUpdate(day); frozen = true; DelayedAction.functionAfterDelay(delegate { Event.Complete(); exitThisMenu(); Game1.player.forceCanMove(); }, 2000); } else { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CantUpgrade_BuildingType"), Color.Red, 3500f)); } } } if (Action == ActionType.Demolish) { Building?building = Location.getBuildingAt(mouseTile); if (building != null) { Cabin?cabin = building.indoors.Value as Cabin; if (cabin != null && !Game1.IsMasterGame) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CantDemolish_LockFailed"), Color.Red, 3500f)); return; } if (!CanDemolish(building)) { return; } if (building.daysOfConstructionLeft.Value > 0 || building.daysUntilUpgrade.Value > 0) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CantDemolish_DuringConstruction"), Color.Red, 3500f)); return; } void lockFailed() { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CantDemolish_LockFailed"), Color.Red, 3500f)); } void continueDemolish() { if (Location == null || !Location.buildings.Contains(building)) { return; } if (building.indoors.Value is AnimalHouse house && house.animalsThatLiveHere.Count > 0) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CantDemolish_AnimalsHere"), Color.Red, 3500f)); return; } if (building.indoors.Value != null && building.indoors.Value.farmers.Any()) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CantDemolish_PlayerHere"), Color.Red, 3500f)); return; } if (building.indoors.Value is Cabin cabin) { string name = cabin.GetCellarName(); foreach (Farmer who in Game1.getAllFarmers()) { if (who.currentLocation != null && who.currentLocation.Name == name) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CantDemolish_PlayerHere"), Color.Red, 3500f)); return; } } if (cabin.farmhand.Value.isActive()) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CantDemolish_FarmhandOnline"), Color.Red, 3500f)); return; } } building.BeforeDemolish(); Chest?chest = null; if (building.indoors.Value is Cabin cbn) { List <Item> list = cbn.demolish(); if (list.Count > 0) { chest = new Chest(playerChest: true); chest.fixLidFrame(); chest.items.Set(list); } } if (Location.destroyStructure(building)) { Game1.flashAlpha = 1f; building.showDestroyedAnimation(Location); Game1.playSound("explosion"); if (Location is Farm farm) { Utility.spreadAnimalsAround(building, farm); } frozen = true; if (chest != null) { Location.objects[new Vector2( building.tileX.Value + building.tilesWide.Value / 2, building.tileY.Value + building.tilesHigh.Value / 2 )] = chest; } // TODO: Config option to return materials to the player? /*if (DemolishCheckBlueprint == null || DemolishCheckBlueprint.name != building.buildingType.Value) * DemolishCheckBlueprint = new BluePrint(building.buildingType.Value); * * if (DemolishCheckBlueprint != null) { * foreach (var entry in DemolishCheckBlueprint.itemsRequired) { * Game1.player.addItemToInventory(new StardewValley.Object(entry.Key, entry.Value)); * } * }*/ DelayedAction.functionAfterDelay(delegate { Event.Complete(); exitThisMenu(); Game1.player.forceCanMove(); }, 2000); } } if (cabin != null && cabin.farmhand.Value.isCustomized.Value) { checkingDemolish = true; Game1.currentLocation.createQuestionDialogue( Game1.content.LoadString(@"Strings\UI:Carpenter_DemolishCabinConfirm", cabin.farmhand.Value.Name), Game1.currentLocation.createYesNoResponses(), delegate(Farmer who, string answer) { Game1.activeClickableMenu = this; if (answer == "Yes") { Game1.player.team.demolishLock.RequestLock(continueDemolish, lockFailed); } } ); return; } Game1.player.team.demolishLock.RequestLock(continueDemolish, lockFailed); } } if (Action == ActionType.Move) { if (MovingBuilding == null) { MovingBuilding = Location.getBuildingAt(mouseTile); if (MovingBuilding != null) { if (MovingBuilding.daysOfConstructionLeft.Value > 0) { MovingBuilding = null; return; } if (!CanMove(MovingBuilding)) { MovingBuilding = null; return; } MovingBuilding.isMoving = true; Game1.playSound("axchop"); } } else if (Location.buildStructure(MovingBuilding, mouseTile, Game1.player)) { MovingBuilding.isMoving = false; if (MovingBuilding is ShippingBin bin) { bin.initLid(); } if (MovingBuilding is GreenhouseBuilding green && Location is Farm farm) { farm.greenhouseMoved.Value = true; } MovingBuilding.performActionOnBuildingPlacement(); MovingBuilding = null; Game1.playSound("axchop"); DelayedAction.playSoundAfterDelay("dirtyHit", 50); DelayedAction.playSoundAfterDelay("dirtyHit", 150); } else { Game1.playSound("cancel"); } } if (Action == ActionType.Paint) { Building bld = Location.getBuildingAt(mouseTile); if (bld == null) { mouseTile.Y++; bld = Location.getBuildingAt(mouseTile); if (bld == null) { mouseTile.Y++; bld = Location.getBuildingAt(mouseTile); } } if (bld != null) { if (!bld.CanBePainted()) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CannotPaint"), Color.Red, 3500f)); return; } if (!CanPaint(bld)) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CannotPaint_Permission"), Color.Red, 3500f)); return; } bld.color.Value = Color.White; SetChildMenu(new BuildingPaintMenu(bld)); return; } else if (Location is Farm farm && farm.GetHouseRect().Contains(Utility.Vector2ToPoint(mouseTile))) { // Check Farmhouse if (!CanPaintHouse()) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CannotPaint"), Color.Red, 3500f)); return; } if (!CanPaint(null)) { Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString(@"Strings\UI:Carpenter_CannotPaint_Permission"), Color.Red, 3500f)); return; } SetChildMenu(new BuildingPaintMenu( "House", () => farm.paintedHouseTexture ?? Farm.houseTextures, farm.houseSource.Value, farm.housePaintColor.Value )); } } }