diff --git a/GeneralMods/Revitalize/Content/Graphics/Items/Tools/ChainSawWorking.png b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/ChainSawWorking.png new file mode 100644 index 00000000..1d84809b Binary files /dev/null and b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/ChainSawWorking.png differ diff --git a/GeneralMods/Revitalize/Content/Graphics/Items/Tools/Chainsaw.png b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/Chainsaw.png new file mode 100644 index 00000000..f98ec62d Binary files /dev/null and b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/Chainsaw.png differ diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs index 42f997f7..ec68f1a9 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs @@ -247,12 +247,12 @@ namespace Revitalize.Framework.Objects.Items.Tools return new AxeExtended(this.info.Copy(), this.UpgradeLevel, this.workingTexture.Copy()); } - public object getReplacement() + public virtual object getReplacement() { return new StardewValley.Tools.Axe { UpgradeLevel = this.UpgradeLevel }; } - public void rebuild(Dictionary additionalSaveData, object replacement) + public virtual void rebuild(Dictionary additionalSaveData, object replacement) { this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); this.upgradeLevel.Value = (replacement as Axe).UpgradeLevel; diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/Chainsaw.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/Chainsaw.cs new file mode 100644 index 00000000..796657fa --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/Chainsaw.cs @@ -0,0 +1,253 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Netcode; +using Newtonsoft.Json; +using Revitalize.Framework.Energy; +using Revitalize.Framework.Utilities; +using StardewValley; +using StardewValley.Tools; +using StardustCore.UIUtilities; +using xTile.ObjectModel; + +namespace Revitalize.Framework.Objects.Items.Tools +{ + public class Chainsaw:AxeExtended,IEnergyInterface + { + + private Texture2D energyTexture; + [JsonIgnore] + public EnergyManager EnergyManager + { + get => this.info.EnergyManager; + set + { + this.info.EnergyManager = value; + this.info.requiresUpdate = true; + } + } + public Chainsaw() + { + + } + + public Chainsaw(BasicItemInformation ItemInfo, int UpgradeLevel, Texture2DExtended WorkingTexture) + { + this.info = ItemInfo; + this.upgradeLevel.Value = UpgradeLevel; + this.guid = Guid.NewGuid(); + this.workingTexture = WorkingTexture; + this.updateInfo(); + } + + + public override void draw(SpriteBatch b) + { + if (this.lastUser == null || this.lastUser.toolPower <= 0 || !this.lastUser.canReleaseTool) + return; + this.updateInfo(); + foreach (Vector2 vector2 in this.tilesAffected(this.lastUser.GetToolLocation(false) / 64f, this.lastUser.toolPower, this.lastUser)) + this.info.animationManager.draw(b, Game1.GlobalToLocal(new Vector2((float)((int)vector2.X * 64), (float)((int)vector2.Y * 64))), Color.White, 4f, SpriteEffects.None, 0.01f); + } + + public override void drawAttachments(SpriteBatch b, int x, int y) + { + this.updateInfo(); + //base.drawAttachments(b, x, y); + //this.info.animationManager.draw(b,) + + + } + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color color, bool drawShadow) + { + this.updateInfo(); + this.info.animationManager.draw(spriteBatch, location, color * transparency, 4f * scaleSize, SpriteEffects.None, layerDepth); + //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, color, drawShadow); + if (this.energyTexture == null) + { + this.initializeEnergyTexture(); + } + spriteBatch.Draw(this.energyTexture, new Rectangle((int)location.X + 8, (int)location.Y + Game1.tileSize / 2, (int)((Game1.tileSize - 16) * this.EnergyManager.energyPercentRemaining), (int)16), new Rectangle(0, 0, 1, 1), EnergyUtilities.GetEnergyRemainingColor(this.EnergyManager), 0f, Vector2.Zero, SpriteEffects.None, layerDepth); + } + private void initializeEnergyTexture() + { + this.energyTexture = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1); + Color[] color = new Color[1]; + color[0] = new Color(255, 255, 255); + this.energyTexture.SetData(color, 0, 1); + } + + public override bool beginUsing(GameLocation location, int x, int y, Farmer who) + { + this.updateInfo(); + Revitalize.Framework.Hacks.ColorChanger.SwapAxeTextures(this.workingTexture.texture); + this.Update(who.FacingDirection, 0, who); + who.EndUsingTool(); + return true; + } + public override void endUsing(GameLocation location, Farmer who) + { + if (this.EnergyManager.hasEnoughEnergy(this.getEnergyConsumptionRate()) == false) + { + Game1.toolAnimationDone(who); + who.canReleaseTool = false; + who.UsingTool = false; + who.canMove = true; + return; + } + + who.stopJittering(); + who.canReleaseTool = false; + int num = (double)who.Stamina <= 0.0 ? 2 : 1; + if (Game1.isAnyGamePadButtonBeingPressed() || !who.IsLocalPlayer) + who.lastClick = who.GetToolLocation(false); + else + { + who.FarmerSprite.nextOffset = 0; + switch (who.FacingDirection) + { + case 0: + ((FarmerSprite)who.Sprite).animateOnce(176, 60f * (float)num, 8); + break; + case 1: + ((FarmerSprite)who.Sprite).animateOnce(168, 60f * (float)num, 8); + break; + case 2: + ((FarmerSprite)who.Sprite).animateOnce(160, 60f * (float)num, 8); + break; + case 3: + ((FarmerSprite)who.Sprite).animateOnce(184, 60f * (float)num, 8); + break; + } + + } + } + + private void baseDoFunction(GameLocation location, int x, int y, int power, Farmer who) + { + this.lastUser = who; + Game1.recentMultiplayerRandom = new Random((int)(short)Game1.random.Next((int)short.MinValue, 32768)); + ToolFactory.getIndexFromTool(this); + if (who.FarmerSprite.currentAnimationIndex <= 0) + return; + MeleeWeapon.timedHitTimer = 500; + + } + + public override void DoFunction(GameLocation location, int x, int y, int power, Farmer who) + { + if (this.EnergyManager.hasEnoughEnergy(this.getEnergyConsumptionRate()) == true) + { + } + else + { + Game1.showRedMessage("Out of energy!"); + return; + } + //base.DoFunction(location, x, y, power, who); + //who.Stamina -= (float)(2 * power) - (float)who.ForagingLevel * 0.1f; + this.baseDoFunction(location, x, y, power, who); + this.EnergyManager.consumeEnergy(this.getEnergyConsumptionRate()); + + int tileX = x / 64; + int tileY = y / 64; + Rectangle rectangle = new Rectangle(tileX * 64, tileY * 64, 64, 64); + Vector2 index1 = new Vector2((float)tileX, (float)tileY); + if (location.Map.GetLayer("Buildings").Tiles[tileX, tileY] != null) + { + PropertyValue propertyValue = (PropertyValue)null; + location.Map.GetLayer("Buildings").Tiles[tileX, tileY].TileIndexProperties.TryGetValue("TreeStump", out propertyValue); + if (propertyValue != null) + { + Game1.drawObjectDialogue(Game1.content.LoadString("Strings\\StringsFromCSFiles:Axe.cs.14023")); + return; + } + } + location.performToolAction((Tool)this, tileX, tileY); + if (location.terrainFeatures.ContainsKey(index1) && location.terrainFeatures[index1].performToolAction((Tool)this, 0, index1, location)) + location.terrainFeatures.Remove(index1); + Rectangle boundingBox; + if (location.largeTerrainFeatures != null) + { + for (int index2 = location.largeTerrainFeatures.Count - 1; index2 >= 0; --index2) + { + boundingBox = location.largeTerrainFeatures[index2].getBoundingBox(); + if (boundingBox.Intersects(rectangle) && location.largeTerrainFeatures[index2].performToolAction((Tool)this, 0, index1, location)) + location.largeTerrainFeatures.RemoveAt(index2); + } + } + Vector2 index3 = new Vector2((float)tileX, (float)tileY); + if (!location.Objects.ContainsKey(index3) || location.Objects[index3].Type == null || !location.Objects[index3].performToolAction((Tool)this, location)) + return; + if (location.Objects[index3].Type.Equals((object)"Crafting") && location.Objects[index3].Fragility != 2) + { + NetCollection debris1 = location.debris; + int objectIndex = location.Objects[index3].bigCraftable.Value ? -location.Objects[index3].ParentSheetIndex : location.Objects[index3].ParentSheetIndex; + Vector2 toolLocation = who.GetToolLocation(false); + boundingBox = who.GetBoundingBox(); + double x1 = (double)boundingBox.Center.X; + boundingBox = who.GetBoundingBox(); + double y1 = (double)boundingBox.Center.Y; + Vector2 playerPosition = new Vector2((float)x1, (float)y1); + Debris debris2 = new Debris(objectIndex, toolLocation, playerPosition); + debris1.Add(debris2); + } + location.Objects[index3].performRemoveAction(index3, location); + location.Objects.Remove(index3); + } + + public override void actionWhenStopBeingHeld(Farmer who) + { + Revitalize.Framework.Hacks.ColorChanger.ResetAxeTexture(); + base.actionWhenStopBeingHeld(who); + } + + public override Color getCategoryColor() + { + return this.info.categoryColor; + } + + public override string getCategoryName() + { + return this.info.categoryName; + } + + public override string getDescription() + { + StringBuilder b = new StringBuilder(); + b.Append("Energy: "); + b.Append(this.EnergyManager.remainingEnergy); + b.Append("/"); + b.Append(this.EnergyManager.maxEnergy); + b.Append(System.Environment.NewLine); + b.Append(this.info.description); + return b.ToString(); + } + + public override Item getOne() + { + return new Chainsaw(this.info.Copy(), this.UpgradeLevel, this.workingTexture.Copy()); + } + + public override object getReplacement() + { + return new StardewValley.Tools.Axe { UpgradeLevel = this.UpgradeLevel }; + } + + public override void rebuild(Dictionary additionalSaveData, object replacement) + { + this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); + this.upgradeLevel.Value = (replacement as Axe).UpgradeLevel; + } + + private int getEnergyConsumptionRate() + { + return this.UpgradeLevel + 1; + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/MiningDrill.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/MiningDrill.cs index 61e52b93..4399efcb 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/MiningDrill.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/MiningDrill.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Netcode; +using Newtonsoft.Json; using Revitalize.Framework.Energy; using Revitalize.Framework.Utilities; using StardewValley; @@ -20,8 +21,8 @@ namespace Revitalize.Framework.Objects.Items.Tools private int boulderTileY; private int hitsToBoulder; private Texture2D energyTexture; - private bool hadEnoughEnergy; + [JsonIgnore] public EnergyManager EnergyManager { get => this.info.EnergyManager; @@ -149,11 +150,9 @@ namespace Revitalize.Framework.Objects.Items.Tools //base.DoFunction(location, x, y, power, who); if (this.EnergyManager.hasEnoughEnergy(this.getEnergyConsumptionRate()) == true) { - this.hadEnoughEnergy = true; } else { - this.hadEnoughEnergy = false; Game1.showRedMessage("Out of energy!"); return; } @@ -163,14 +162,6 @@ namespace Revitalize.Framework.Objects.Items.Tools //Drain energy here; this.EnergyManager.consumeEnergy(this.getEnergyConsumptionRate()); //Double check to prevent animation from happening with even no power - if (this.EnergyManager.hasEnoughEnergy(this.getEnergyConsumptionRate()) == true) - { - this.hadEnoughEnergy = true; - } - else - { - this.hadEnoughEnergy = false; - } Utility.clampToTile(new Vector2((float)x, (float)y)); diff --git a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs index 7725d39c..a6ed3818 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs @@ -297,7 +297,7 @@ namespace Revitalize.Framework.Objects WateringCanExtended titaniumCan = new WateringCanExtended(new BasicItemInformation("Titanium Watering Can", "Omegasis.Revitalize.Items.Tools.TitaniumWateringCan", "A sturdy watering can made from titanium.", "Tool", Color.SlateGray, 0, 0, false, 500, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "TitaniumWateringCan"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumWateringCan"), new Animation(0, 0, 16, 16)), Color.White, true, null, null), 3, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "TitaniumWateringCanWorking"), 125); MiningDrill miningDrillV1 = new MiningDrill(new BasicItemInformation("Simple Mining Drill", "Omegasis.Revitalize.Items.Tools.MiningDrillV1", "A drill used in mining. Consumes energy instead of stamina.", "Tool", Color.SlateGray, 0, 0, false, 1000, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "MiningDrill"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "MiningDrill"), new Animation(0, 0, 16, 16)), Color.White, true, null, null,new Energy.EnergyManager(200, Enums.EnergyInteractionType.Consumes)), 2, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "MiningDrillWorking")); - + Chainsaw chainsawV1 = new Chainsaw(new BasicItemInformation("Simple Chainsaw", "Omegasis.Revitalize.Items.Tools.ChainsawV1", "A chainsaw used to fell trees and chop wood. Consumes energy instead of stamina.", "Tool", Color.SlateGray, 0, 0, false, 1000, false, false, TextureManager.GetTexture(ModCore.Manifest, "Tools", "Chainsaw"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "Chainsaw"), new Animation(0, 0, 16, 16)), Color.White, true, null, null, new Energy.EnergyManager(200, Enums.EnergyInteractionType.Consumes)), 2, TextureManager.GetExtendedTexture(ModCore.Manifest, "Tools", "ChainsawWorking")); this.Tools.Add("BronzePickaxe", bronzePick); this.Tools.Add("HardenedPickaxe", steelPick); @@ -316,6 +316,7 @@ namespace Revitalize.Framework.Objects this.Tools.Add("TitaniumWateringCan", titaniumCan); this.Tools.Add("MiningDrillV1", miningDrillV1); + this.Tools.Add("ChainsawV1", chainsawV1); } /// diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 8349c541..a01cf47f 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -572,7 +572,8 @@ namespace Revitalize ModCore.ObjectManager.GetItem("ChargingStation",1), ModCore.ObjectManager.GetItem("Grinder",1), new StardewValley.Object((int)Enums.SDVObject.CopperOre,10), - ModCore.ObjectManager.GetTool("MiningDrillV1") + ModCore.ObjectManager.GetTool("MiningDrillV1"), + ModCore.ObjectManager.GetTool("ChainsawV1") }); } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 1d21d711..28c0b0d9 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -156,6 +156,7 @@ + @@ -320,6 +321,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest