Skip to content

Commit

Permalink
avoid implicit conversion of net types
Browse files Browse the repository at this point in the history
Their implicit conversion rules can be unintuitive and error-prone, which can lead to unexpected bugs.
  • Loading branch information
Pathoschild committed Jun 14, 2021
1 parent 66ec2c0 commit 5bddd49
Show file tree
Hide file tree
Showing 33 changed files with 219 additions and 210 deletions.
2 changes: 1 addition & 1 deletion BetterMeteorites/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)

private void OnClumpRemoved(ResourceClump value)
{
if (value.parentSheetIndex == ResourceClump.meteoriteIndex)
if (value.parentSheetIndex.Value == ResourceClump.meteoriteIndex)
{
Random r = new Random((int)value.tile.X * 1000 + (int)value.tile.Y);
Game1.createMultipleObjectDebris(StardewValley.Object.stone, (int)value.tile.X, (int)value.tile.Y, 75 + r.Next(175));
Expand Down
2 changes: 1 addition & 1 deletion BiggerCraftables/Patches/UtilityPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static bool Before_PlayersCanPlaceItemHere(GameLocation location, Item i
__result = false;
return false;
}
if (item == null || item is Tool || Game1.eventUp || (bool)f.bathingClothes || f.onBridge.Value)
if (item == null || item is Tool || Game1.eventUp || f.bathingClothes.Value || f.onBridge.Value)
{
__result = false;
return false;
Expand Down
4 changes: 2 additions & 2 deletions BugNet/BugNetTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class BugNetTool : MeleeWeapon, ICustomWeaponDraw

public BugNetTool()
{
this.category.Value = StardewValley.Object.toolCategory;
this.Category = StardewValley.Object.toolCategory;
this.Name = "Bug Net";
this.ParentSheetIndex = MeleeWeapon.scythe; // Gets us out of annoying stuff

Expand Down Expand Up @@ -59,7 +59,7 @@ public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float
float num2 = Mod.Instance.Helper.Reflection.GetField<float>(typeof(MeleeWeapon), "addedSwordScale").GetValue();
if (!drawShadow)
num2 = 0;
spriteBatch.Draw(BugNetTool.Texture, location + (this.type == 1 ? new Vector2(Game1.tileSize * 2 / 3, Game1.tileSize / 3) : new Vector2(Game1.tileSize / 2, Game1.tileSize / 2)), new Rectangle(0, 0, 16, 16), Color.White * transparency, 0.0f, new Vector2(8f, 8f), Game1.pixelZoom * (scaleSize + num2), SpriteEffects.None, layerDepth);
spriteBatch.Draw(BugNetTool.Texture, location + (this.type.Value == 1 ? new Vector2(Game1.tileSize * 2 / 3, Game1.tileSize / 3) : new Vector2(Game1.tileSize / 2, Game1.tileSize / 2)), new Rectangle(0, 0, 16, 16), Color.White * transparency, 0.0f, new Vector2(8f, 8f), Game1.pixelZoom * (scaleSize + num2), SpriteEffects.None, layerDepth);
if (num1 <= 0.0 || drawShadow)
return;
spriteBatch.Draw(Game1.staminaRect, new Rectangle((int)location.X, (int)location.Y + (Game1.tileSize - (int)(num1 * (double)Game1.tileSize)), Game1.tileSize, (int)(num1 * (double)Game1.tileSize)), Color.Red * 0.66f);
Expand Down
33 changes: 16 additions & 17 deletions BuildableLocationsFramework/Framework/BuildableAnimalLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ internal class BuildableAnimalLocation : BuildableGameLocation, IAnimalLocation
{
public NetLongDictionary<FarmAnimal, NetRef<FarmAnimal>> Animals { get; } = new();

private void MyWarpHome(FarmAnimal farmAnimal, FarmAnimal a)
private void MyWarpHome(FarmAnimal farmAnimal)
{
if (farmAnimal.home == null)
if (farmAnimal.home?.indoors.Value is not AnimalHouse animalHouse)
return;
(farmAnimal.home.indoors.Value as AnimalHouse).animals.Add((long)farmAnimal.myID, farmAnimal);
this.Animals.Remove((long)farmAnimal.myID);

animalHouse.animals.Add(farmAnimal.myID.Value, farmAnimal);
this.Animals.Remove(farmAnimal.myID.Value);
farmAnimal.controller = null;
farmAnimal.setRandomPosition(farmAnimal.home.indoors);
farmAnimal.setRandomPosition(animalHouse);
++farmAnimal.home.currentOccupants.Value;
}

Expand Down Expand Up @@ -70,7 +71,7 @@ public override void timeUpdate(int timeElapsed)

foreach (Building building in this.buildings)
{
if ((int)building.daysOfConstructionLeft <= 0)
if (building.daysOfConstructionLeft.Value <= 0)
{
building.performTenMinuteAction(timeElapsed);
if (building.indoors.Value != null && !Game1.locations.Contains(building.indoors.Value) && timeElapsed >= 10)
Expand Down Expand Up @@ -117,7 +118,7 @@ public bool CheckPetAnimal(Vector2 position, Farmer who)
{
foreach (KeyValuePair<long, FarmAnimal> pair in this.Animals.Pairs)
{
if (!(bool)pair.Value.wasPet && pair.Value.GetCursorPetBoundingBox().Contains((int)position.X, (int)position.Y))
if (!pair.Value.wasPet.Value && pair.Value.GetCursorPetBoundingBox().Contains((int)position.X, (int)position.Y))
{
pair.Value.pet(who);
return true;
Expand All @@ -130,7 +131,7 @@ public bool CheckPetAnimal(Rectangle rect, Farmer who)
{
foreach (KeyValuePair<long, FarmAnimal> pair in this.Animals.Pairs)
{
if (!(bool)pair.Value.wasPet && pair.Value.GetBoundingBox().Intersects(rect))
if (!pair.Value.wasPet.Value && pair.Value.GetBoundingBox().Intersects(rect))
{
pair.Value.pet(who);
return true;
Expand All @@ -143,7 +144,7 @@ public bool CheckInspectAnimal(Vector2 position, Farmer who)
{
foreach (KeyValuePair<long, FarmAnimal> pair in this.Animals.Pairs)
{
if ((bool)pair.Value.wasPet && pair.Value.GetCursorPetBoundingBox().Contains((int)position.X, (int)position.Y))
if (pair.Value.wasPet.Value && pair.Value.GetCursorPetBoundingBox().Contains((int)position.X, (int)position.Y))
{
pair.Value.pet(who);
return true;
Expand All @@ -156,7 +157,7 @@ public bool CheckInspectAnimal(Rectangle rect, Farmer who)
{
foreach (KeyValuePair<long, FarmAnimal> pair in this.Animals.Pairs)
{
if ((bool)pair.Value.wasPet && pair.Value.GetBoundingBox().Intersects(rect))
if (pair.Value.wasPet.Value && pair.Value.GetBoundingBox().Intersects(rect))
{
pair.Value.pet(who);
return true;
Expand Down Expand Up @@ -188,23 +189,21 @@ protected override void resetLocalState()
{
KeyValuePair<long, FarmAnimal> keyValuePair = this.Animals.Pairs.ElementAt(index);
FarmAnimal farmAnimal = keyValuePair.Value;
keyValuePair = this.Animals.Pairs.ElementAt(index);
FarmAnimal a = keyValuePair.Value;
this.MyWarpHome(farmAnimal, a);
this.MyWarpHome(farmAnimal);
}
}

if (this.isThereABuildingUnderConstruction() && (int)this.getBuildingUnderConstruction().daysOfConstructionLeft > 0 && Game1.getCharacterFromName("Robin").currentLocation.Equals(this))
Building underConstruction = this.getBuildingUnderConstruction();
if (underConstruction?.daysOfConstructionLeft.Value > 0 && Game1.getCharacterFromName("Robin").currentLocation.Equals(this))
{
Building underConstruction = this.getBuildingUnderConstruction();
this.temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(399, 262, (int)(NetFieldBase<int, NetInt>)underConstruction.daysOfConstructionLeft == 1 ? 29 : 9, 43), new Vector2((int)underConstruction.tileX + (int)underConstruction.tilesWide / 2, (int)underConstruction.tileY + (int)underConstruction.tilesHigh / 2) * 64f + new Vector2(-16f, -144f), false, 0.0f, Color.White)
this.temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Rectangle(399, 262, underConstruction.daysOfConstructionLeft.Value == 1 ? 29 : 9, 43), new Vector2(underConstruction.tileX.Value + underConstruction.tilesWide.Value / 2, underConstruction.tileY.Value + underConstruction.tilesHigh.Value / 2) * 64f + new Vector2(-16f, -144f), false, 0.0f, Color.White)
{
id = 16846f,
scale = 4f,
interval = 999999f,
animationLength = 1,
totalNumberOfLoops = 99999,
layerDepth = (((int)underConstruction.tileY + (int)underConstruction.tilesHigh / 2) * 64 + 32) / 10000f
layerDepth = ((underConstruction.tileY.Value + underConstruction.tilesHigh.Value / 2) * 64 + 32) / 10000f
});
}
else
Expand Down
20 changes: 10 additions & 10 deletions BuildableLocationsFramework/Patches/CarpenterMenuPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ public static bool Before_ReceiveLeftClick(CarpenterMenu __instance, int x, int
}
if (!__instance_onFarm.GetValue() && __instance.demolishButton.containsPoint(x, y) && __instance.demolishButton.visible)
{
Game1.globalFadeToBlack(new Game1.afterFadeFunction(__instance.setUpForBuildingPlacement));
Game1.globalFadeToBlack(__instance.setUpForBuildingPlacement);
Game1.playSound("smallSelect");
__instance_onFarm.SetValue(true);
__instance_demolishing.SetValue(true);
}
if (!__instance_onFarm.GetValue() && __instance.moveButton.containsPoint(x, y) && __instance.moveButton.visible)
{
Game1.globalFadeToBlack(new Game1.afterFadeFunction(__instance.setUpForBuildingPlacement));
Game1.globalFadeToBlack(__instance.setUpForBuildingPlacement);
Game1.playSound("smallSelect");
__instance_onFarm.SetValue(true);
__instance_moving.SetValue(true);
}
if (__instance.okButton.containsPoint(x, y) && !__instance_onFarm.GetValue() && (Game1.player.Money >= __instance_price.GetValue() && __instance_blueprints.GetValue()[__instance_currentBlueprintIndex.GetValue()].doesFarmerHaveEnoughResourcesToBuild()))
{
Game1.globalFadeToBlack(new Game1.afterFadeFunction(__instance.setUpForBuildingPlacement));
Game1.globalFadeToBlack(__instance.setUpForBuildingPlacement);
Game1.playSound("smallSelect");
__instance_onFarm.SetValue(true);
}
Expand All @@ -155,7 +155,7 @@ void ContinueDemolish()
{
if (!__instance_demolishing.GetValue() || destroyed == null || !farm.buildings.Contains(destroyed))
return;
if ((int)destroyed.daysOfConstructionLeft > 0 || (int)destroyed.daysUntilUpgrade > 0)
if (destroyed.daysOfConstructionLeft.Value > 0 || destroyed.daysUntilUpgrade.Value > 0)
Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_DuringConstruction"), Color.Red, 3500f));
else if (destroyed.indoors.Value is AnimalHouse house && house.animalsThatLiveHere.Count > 0)
Game1.addHUDMessage(new HUDMessage(Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_AnimalsHere"), Color.Red, 3500f));
Expand Down Expand Up @@ -206,7 +206,7 @@ void ContinueDemolish()
__instance_freeze.SetValue(true);
if (chest == null)
return;
farm.objects[new Vector2((int)destroyed.tileX + (int)destroyed.tilesWide / 2, (int)destroyed.tileY + (int)destroyed.tilesHigh / 2)] = chest;
farm.objects[new Vector2(destroyed.tileX.Value + destroyed.tilesWide.Value / 2, destroyed.tileY.Value + destroyed.tilesHigh.Value / 2)] = chest;
}
}
}
Expand All @@ -227,7 +227,7 @@ void ContinueDemolish()
}
if (destroyed?.indoors.Value is Cabin cabinB)
{
if (cabinB.farmhand.Value != null && (bool)cabinB.farmhand.Value.isCustomized)
if (cabinB.farmhand.Value != null && cabinB.farmhand.Value.isCustomized.Value)
{
Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\UI:Carpenter_DemolishCabinConfirm", cabinB.farmhand.Value.Name), Game1.currentLocation.createYesNoResponses(), (f, answer) =>
{
Expand All @@ -237,7 +237,7 @@ void ContinueDemolish()
Game1.player.team.demolishLock.RequestLock(ContinueDemolish, BuildingLockFailed);
}
else
DelayedAction.functionAfterDelay(new DelayedAction.delayedBehavior(__instance.returnToCarpentryMenu), 500);
DelayedAction.functionAfterDelay(__instance.returnToCarpentryMenu, 500);
});
goto ret;
}
Expand All @@ -255,7 +255,7 @@ void ContinueDemolish()
buildingAt.daysUntilUpgrade.Value = 2;
buildingAt.showUpgradeAnimation(Game1.getFarm());
Game1.playSound("axe");
DelayedAction.functionAfterDelay(new DelayedAction.delayedBehavior(__instance.returnToCarpentryMenuAfterSuccessfulBuild), 1500);
DelayedAction.functionAfterDelay(__instance.returnToCarpentryMenuAfterSuccessfulBuild, 1500);
__instance_freeze.SetValue(true);
}
else
Expand All @@ -272,7 +272,7 @@ void ContinueDemolish()
__instance_buildingToMove.SetValue(((BuildableGameLocation)CarpenterMenuPatcher.ReturnCurrentLocationAnyways("Farm")).getBuildingAt(new Vector2((Game1.viewport.X + Game1.getMouseX()) / 64, (Game1.viewport.Y + Game1.getMouseY()) / 64)));
if (__instance_buildingToMove.GetValue() == null)
goto ret;
if ((int)__instance_buildingToMove.GetValue().daysOfConstructionLeft > 0)
if (__instance_buildingToMove.GetValue().daysOfConstructionLeft.Value > 0)
__instance_buildingToMove.SetValue(null);
else if (!Game1.IsMasterGame && !__instance.hasPermissionsToMove(__instance_buildingToMove.GetValue()))
{
Expand Down Expand Up @@ -306,7 +306,7 @@ void ContinueDemolish()
if (__instance.tryToBuild())
{
__instance.CurrentBlueprint.consumeResources();
DelayedAction.functionAfterDelay(new DelayedAction.delayedBehavior(__instance.returnToCarpentryMenuAfterSuccessfulBuild), 2000);
DelayedAction.functionAfterDelay(__instance.returnToCarpentryMenuAfterSuccessfulBuild, 2000);
__instance_freeze.SetValue(true);
}
else
Expand Down
Loading

0 comments on commit 5bddd49

Please sign in to comment.