Probably going to quit. Multiplayer can't sync inventories effectively so what's the point?

This commit is contained in:
JoshuaNavarro 2019-09-22 00:18:48 -07:00
parent 1c6e04929c
commit 0d373b5d83
19 changed files with 366 additions and 250 deletions

View File

@ -122,7 +122,7 @@ namespace Revitalize.Framework.Energy
}
public EnergyManager(int Capacity,Enums.EnergyInteractionType EnergyType) : this(0, Capacity,EnergyType)
public EnergyManager(int Capacity, Enums.EnergyInteractionType EnergyType) : this(0, Capacity, EnergyType)
{
}
@ -149,27 +149,21 @@ namespace Revitalize.Framework.Energy
{
int amountBeforeConsumption = this.remainingEnergy;
this.remainingEnergy = Math.Max(0, this.remainingEnergy - amount);
if (this.remainingEnergy != amountBeforeConsumption)
{
this.requiresUpdate = true;
}
this.requiresUpdate = true;
}
public void produceEnergy(int amount)
{
int amountBeforeProduction = this.remainingEnergy;
this.remainingEnergy = Math.Min(this.maxEnergy, this.remainingEnergy + amount);
if (this.remainingEnergy != amountBeforeProduction)
{
this.requiresUpdate = true;
}
this.requiresUpdate = true;
}
public void transferEnergyFromAnother(EnergyManager other,int amount)
public void transferEnergyFromAnother(EnergyManager other, int amount)
{
if (this.canReceieveEnergy)
{
int actualAmount = Math.Min(amount,other.remainingEnergy);
int actualAmount = Math.Min(amount, other.remainingEnergy);
int selfCapacity = this.capacityRemaining;
this.produceEnergy(Math.Min(actualAmount, selfCapacity));
other.consumeEnergy(Math.Min(actualAmount, selfCapacity));
@ -197,7 +191,7 @@ namespace Revitalize.Framework.Energy
public EnergyManager Copy()
{
return new EnergyManager(this.maxEnergy,this.energyInteractionType);
return new EnergyManager(this.maxEnergy, this.energyInteractionType);
}
}

View File

@ -8,12 +8,7 @@ namespace Revitalize.Framework.Energy
{
public interface IEnergyInterface
{
EnergyManager EnergyManager
{
get;
set;
}
ref EnergyManager GetEnergyManager();
void SetEnergyManager(ref EnergyManager Manager);
}
}

View File

@ -110,7 +110,7 @@ namespace Revitalize.Framework.Menus
{
if (this.infoButton.recipe.timeToCraft == 0)
{
this.machine.InventoryManager.dumpBufferToItems();
this.machine.GetInventoryManager().dumpBufferToItems();
}
else
{
@ -145,12 +145,12 @@ namespace Revitalize.Framework.Menus
this.hoverText = "Crafting in progress...";
hovered = true;
}
if (this.machine.MinutesUntilReady == 0 && this.machine.InventoryManager.hasItemsInBuffer)
if (this.machine.MinutesUntilReady == 0 && this.machine.GetInventoryManager().hasItemsInBuffer)
{
this.hoverText = "Items in buffer. Please make room in the inventory for: " + System.Environment.NewLine + this.machine.InventoryManager + " items.";
this.hoverText = "Items in buffer. Please make room in the inventory for: " + System.Environment.NewLine + this.machine.GetInventoryManager() + " items.";
hovered = true;
}
if (this.machine.InventoryManager.IsFull)
if (this.machine.GetInventoryManager().IsFull)
{
this.hoverText = "Inventory is full!";
hovered = true;
@ -196,8 +196,8 @@ namespace Revitalize.Framework.Menus
if (this.machine != null)
{
if (this.machine.InventoryManager.hasItemsInBuffer) canCraft = false;
if (this.machine.InventoryManager.IsFull) canCraft = false;
if (this.machine.GetInventoryManager().hasItemsInBuffer) canCraft = false;
if (this.machine.GetInventoryManager().IsFull) canCraft = false;
}
return canCraft;

View File

@ -57,7 +57,7 @@ namespace Revitalize.Framework.Menus.Machines
{
get
{
return this.objectSource.EnergyManager;
return this.objectSource.GetEnergyManager();
}
}

View File

@ -259,19 +259,7 @@ namespace Revitalize.Framework.Objects
}
}
private InventoryManager _inventory;
public InventoryManager inventory
{
get
{
return this._inventory;
}
set
{
this._inventory = value;
this.requiresUpdate = true;
}
}
public InventoryManager inventory;
private LightManager _lightManager;
@ -317,7 +305,8 @@ namespace Revitalize.Framework.Objects
}
}
private Energy.EnergyManager _energyManager;
//private Energy.EnergyManager _energyManager;
/*
public Energy.EnergyManager EnergyManager
{
get
@ -330,6 +319,9 @@ namespace Revitalize.Framework.Objects
this.requiresUpdate = true;
}
}
*/
public Energy.EnergyManager EnergyManager;
private bool _alwaysDrawAbovePlayer;
public bool AlwaysDrawAbovePlayer
@ -399,6 +391,7 @@ namespace Revitalize.Framework.Objects
this.shakeTimer = 0;
this.EnergyManager = new Energy.EnergyManager();
this._alwaysDrawAbovePlayer = false;
this.ColorManager = new ColorManager(Enums.DyeBlendMode.Blend, 0.5f);
}
public BasicItemInformation(string name, string id, string description, string categoryName, Color categoryColor,int edibility, int fragility, bool isLamp, int price, bool canBeSetOutdoors, bool canBeSetIndoors, Texture2D texture, AnimationManager animationManager, Color drawColor, bool ignoreBoundingBox, InventoryManager Inventory, LightManager Lights,Energy.EnergyManager EnergyManager=null,bool AlwaysDrawAbovePlayer=false,NamedColor DyedColor=null, ColorManager ColorManager=null)
@ -453,12 +446,12 @@ namespace Revitalize.Framework.Objects
/// <returns></returns>
public BasicItemInformation Copy()
{
return new BasicItemInformation(this.name, this.id,this.description, this.categoryName, this.categoryColor, this.edibility, this.fragility, this.isLamp, this.price, this.canBeSetOutdoors, this.canBeSetIndoors, this.animationManager.getTexture(), this.animationManager, this.DrawColor, this.ignoreBoundingBox, this._inventory.Copy(), this._lightManager.Copy(),this._energyManager.Copy(),this.AlwaysDrawAbovePlayer,this.DyedColor,this.ColorManager);
return new BasicItemInformation(this.name, this.id,this.description, this.categoryName, this.categoryColor, this.edibility, this.fragility, this.isLamp, this.price, this.canBeSetOutdoors, this.canBeSetIndoors, this.animationManager.getTexture(), this.animationManager, this.DrawColor, this.ignoreBoundingBox, this.inventory.Copy(), this._lightManager.Copy(),this.EnergyManager.Copy(),this.AlwaysDrawAbovePlayer,this.DyedColor,this.ColorManager);
}
public bool requiresSyncUpdate()
{
return this.requiresUpdate || this.animationManagerRequiresUpdate() || this.inventoryManagerRequiresUpdate() || this.lightManagerRequiresUpdate() || this.energyManagerRequiresUpdate();
return this.requiresUpdate || this.animationManagerRequiresUpdate() || this.inventoryManagerRequiresUpdate() || this.lightManagerRequiresUpdate() || this.energyManagerRequiresUpdate() || this.colorManagerRequiresUpdate();
}
public void forceUpdate()
@ -472,8 +465,8 @@ namespace Revitalize.Framework.Objects
}
private bool inventoryManagerRequiresUpdate()
{
if (this._inventory == null) return false;
else return this._inventory.requiresUpdate;
if (this.inventory == null) return false;
else return this.inventory.requiresUpdate;
}
private bool lightManagerRequiresUpdate()
{
@ -483,17 +476,35 @@ namespace Revitalize.Framework.Objects
private bool energyManagerRequiresUpdate()
{
if (this._energyManager == null) return false;
else return this._energyManager.requiresUpdate;
if (this.EnergyManager == null)
{
//ModCore.log("Energy manager is NULL! " + this.name);
return false;
}
else
{
if (this.EnergyManager.requiresUpdate)
{
//ModCore.log("Energy manager requres an update: " + this.name);
}
return this.EnergyManager.requiresUpdate;
}
}
private bool colorManagerRequiresUpdate()
{
if (this._colorManager == null) return false;
else return this._colorManager.requiresUpdate;
}
public void cleanAfterUpdate()
{
this.requiresUpdate = false;
this._inventory.requiresUpdate = false;
this.inventory.requiresUpdate = false;
this._animationManager.requiresUpdate = false;
this._lightManager.requiresUpdate = false;
this._energyManager.requiresUpdate = false;
this.EnergyManager.requiresUpdate = false;
this._colorManager.requiresUpdate = false;
}
/// <summary>

View File

@ -20,9 +20,9 @@ namespace Revitalize.Framework.Objects
// -Inventories
/// <summary>A custom object template.</summary>
public class CustomObject : PySObject,IEnergyInterface
public class CustomObject : PySObject, IEnergyInterface
{
[JsonIgnore]
public virtual string text
{
get
@ -42,7 +42,7 @@ namespace Revitalize.Framework.Objects
}
}
[JsonIgnore]
public override string Name
{
@ -83,7 +83,7 @@ namespace Revitalize.Framework.Objects
}
}
}
[JsonIgnore]
public override string DisplayName
{
get
@ -107,7 +107,7 @@ namespace Revitalize.Framework.Objects
}
}
[JsonIgnore]
public string id
{
get
@ -131,11 +131,7 @@ namespace Revitalize.Framework.Objects
{
get
{
if (this.info == null)
{
this.updateInfo();
}
this.updateInfo();
//ModCore.log("Location Name is: " + this.info.locationName);
if (this._location == null)
{
@ -174,30 +170,6 @@ namespace Revitalize.Framework.Objects
}
}
[JsonIgnore]
/// <summary>
/// Accesses the energy manager for all objects.
/// </summary>
public virtual EnergyManager EnergyManager
{
get
{
if (this.info == null)
{
this.updateInfo();
return this.info.EnergyManager;
}
else
{
return this.info.EnergyManager;
}
}
set
{
this.info.EnergyManager = value;
}
}
/// <summary>The display texture for this object.</summary>
[JsonIgnore]
public Texture2D displayTexture => this.animationManager.getTexture();
@ -330,13 +302,13 @@ namespace Revitalize.Framework.Objects
MouseState mState = Mouse.GetState();
KeyboardState keyboardState = Game1.GetKeyboardState();
if (mState.RightButton == ButtonState.Pressed && keyboardState.IsKeyDown(Keys.LeftShift)==false && keyboardState.IsKeyDown(Keys.RightShift)==false)
if (mState.RightButton == ButtonState.Pressed && keyboardState.IsKeyDown(Keys.LeftShift) == false && keyboardState.IsKeyDown(Keys.RightShift) == false)
{
//ModCore.log("Right clicked!");
return this.rightClicked(who);
}
if (mState.RightButton == ButtonState.Pressed && (keyboardState.IsKeyDown(Keys.LeftShift)==true || keyboardState.IsKeyDown(Keys.RightShift)==true))
if (mState.RightButton == ButtonState.Pressed && (keyboardState.IsKeyDown(Keys.LeftShift) == true || keyboardState.IsKeyDown(Keys.RightShift) == true))
return this.shiftRightClicked(who);
return base.checkForAction(who, justCheckingForActivity);
@ -628,7 +600,7 @@ namespace Revitalize.Framework.Objects
}
/// <summary>What happens when the object is drawn when held by a player.</summary>
public virtual void drawFullyInMenu(SpriteBatch spriteBatch, Vector2 objectPosition,float Depth)
public virtual void drawFullyInMenu(SpriteBatch spriteBatch, Vector2 objectPosition, float Depth)
{
this.updateInfo();
if (this.animationManager == null)
@ -637,7 +609,7 @@ namespace Revitalize.Framework.Objects
}
if (this.displayTexture == null) Revitalize.ModCore.log("Display texture is null");
spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, this.info.DrawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None,Depth);
spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, this.info.DrawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Depth);
//base.drawWhenHeld(spriteBatch, objectPosition, f);
}
@ -671,7 +643,7 @@ namespace Revitalize.Framework.Objects
{
if (ModCore.Configs.objectsConfig.showDyedColorName)
{
return this.info.getDyedColorName() +" "+ this.info.name;
return this.info.getDyedColorName() + " " + this.info.name;
}
//Load in a file that has all object names referenced here or something.
return this.info.name;
@ -769,16 +741,42 @@ namespace Revitalize.Framework.Objects
public override void updateWhenCurrentLocation(GameTime time, GameLocation environment)
{
if (this.info == null)
{
this.updateInfo();
}
this.updateInfo();
if (this.location == null)
{
this.location = environment;
}
base.updateWhenCurrentLocation(time, environment);
}
public virtual ref EnergyManager GetEnergyManager()
{
if (this.info == null)
{
this.updateInfo();
}
return ref this.info.EnergyManager;
}
public virtual void SetEnergyManager(ref EnergyManager Manager)
{
this.info.EnergyManager = Manager;
}
public virtual ref InventoryManager GetInventoryManager()
{
if (this.info == null)
{
this.updateInfo();
return ref this.info.inventory;
}
return ref this.info.inventory;
}
public virtual void SetInventoryManager(InventoryManager Manager)
{
this.info.inventory = Manager;
}
}
}

View File

@ -249,5 +249,15 @@ namespace Revitalize.Framework.Objects.Items.Tools
{
return this.UpgradeLevel + 1;
}
public ref EnergyManager GetEnergyManager()
{
return ref this.info.EnergyManager;
}
public void SetEnergyManager(ref EnergyManager Manager)
{
this.info.EnergyManager = Manager;
}
}
}

View File

@ -22,17 +22,6 @@ namespace Revitalize.Framework.Objects.Items.Tools
private int hitsToBoulder;
private Texture2D energyTexture;
[JsonIgnore]
public EnergyManager EnergyManager
{
get => this.info.EnergyManager;
set
{
this.info.EnergyManager = value;
this.info.requiresUpdate = true;
}
}
public MiningDrill()
{
@ -75,7 +64,7 @@ namespace Revitalize.Framework.Objects.Items.Tools
{
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);
spriteBatch.Draw(this.energyTexture, new Rectangle((int)location.X + 8, (int)location.Y + Game1.tileSize / 2, (int)((Game1.tileSize - 16) * this.GetEnergyManager().energyPercentRemaining), (int)16), new Rectangle(0, 0, 1, 1), EnergyUtilities.GetEnergyRemainingColor(this.GetEnergyManager()), 0f, Vector2.Zero, SpriteEffects.None, layerDepth);
}
public override bool beginUsing(GameLocation location, int x, int y, Farmer who)
@ -89,7 +78,7 @@ namespace Revitalize.Framework.Objects.Items.Tools
public override void endUsing(GameLocation location, Farmer who)
{
if (this.EnergyManager.hasEnoughEnergy(this.getEnergyConsumptionRate()) == false)
if (this.GetEnergyManager().hasEnoughEnergy(this.getEnergyConsumptionRate()) == false)
{
Game1.toolAnimationDone(who);
who.canReleaseTool = false;
@ -148,7 +137,7 @@ namespace Revitalize.Framework.Objects.Items.Tools
public override void DoFunction(GameLocation location, int x, int y, int power, Farmer who)
{
//base.DoFunction(location, x, y, power, who);
if (this.EnergyManager.hasEnoughEnergy(this.getEnergyConsumptionRate()) == true)
if (this.GetEnergyManager().hasEnoughEnergy(this.getEnergyConsumptionRate()) == true)
{
}
else
@ -160,7 +149,7 @@ namespace Revitalize.Framework.Objects.Items.Tools
power = who.toolPower;
//who.Stamina -= (float)(2 * (power + 1)) - (float)who.MiningLevel * 0.1f;
//Drain energy here;
this.EnergyManager.consumeEnergy(this.getEnergyConsumptionRate());
this.GetEnergyManager().consumeEnergy(this.getEnergyConsumptionRate());
//Double check to prevent animation from happening with even no power
@ -358,9 +347,9 @@ namespace Revitalize.Framework.Objects.Items.Tools
{
StringBuilder b = new StringBuilder();
b.Append("Energy: ");
b.Append(this.EnergyManager.remainingEnergy);
b.Append(this.GetEnergyManager().remainingEnergy);
b.Append("/");
b.Append(this.EnergyManager.maxEnergy);
b.Append(this.GetEnergyManager().maxEnergy);
b.Append(System.Environment.NewLine);
b.Append(this.info.description);
return b.ToString();
@ -387,5 +376,15 @@ namespace Revitalize.Framework.Objects.Items.Tools
{
return this.UpgradeLevel + 1;
}
public ref EnergyManager GetEnergyManager()
{
return ref this.info.EnergyManager;
}
public void SetEnergyManager(ref EnergyManager Manager)
{
this.info.EnergyManager = Manager;
}
}
}

View File

@ -66,6 +66,7 @@ namespace Revitalize.Framework.Objects.Machines
public override bool minutesElapsed(int minutes, GameLocation environment)
{
this.updateInfo();
if (this.updatesContainerObjectForProduction)
{
//ModCore.log("Update container object for production!");
@ -73,22 +74,22 @@ namespace Revitalize.Framework.Objects.Machines
int remaining = minutes;
//ModCore.log("Minutes elapsed: " + remaining);
List<MultiTiledObject> energySources = new List<MultiTiledObject>();
if (this.ConsumesEnergy || this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Storage)
if (this.ConsumesEnergy || this.GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Storage)
{
//ModCore.log("This machine drains energy: " + this.info.name);
energySources = this.EnergyGraphSearchSources(); //Only grab the network once.
}
this.drainEnergyFromNetwork(energySources);
foreach(Item I in this.InventoryManager.items)
foreach(Item I in this.GetInventoryManager().items)
{
if (I is null) continue;
if (I is IEnergyInterface==false) continue;
IEnergyInterface o = (IEnergyInterface)I;
if (o.EnergyManager.canReceieveEnergy)
if (o.GetEnergyManager().canReceieveEnergy)
{
this.EnergyManager.transferEnergyToAnother(o.EnergyManager, Math.Min(this.EnergyManager.remainingEnergy, o.EnergyManager.capacityRemaining));
this.GetEnergyManager().transferEnergyToAnother(o.GetEnergyManager(), Math.Min(this.GetEnergyManager().remainingEnergy, o.GetEnergyManager().capacityRemaining));
}
if (this.EnergyManager.hasEnergy == false) break;
if (this.GetEnergyManager().hasEnergy == false) break;
}
return false;

View File

@ -80,7 +80,7 @@ namespace Revitalize.Framework.Objects.Machines.EnergyGeneration
public override void produceEnergy()
{
if (this.EnergyManager.canReceieveEnergy)
if (this.GetEnergyManager().canReceieveEnergy)
{
int energy= this.energyRequiredPer10Minutes;
if (WeatherUtilities.IsWetWeather())
@ -96,7 +96,7 @@ namespace Revitalize.Framework.Objects.Machines.EnergyGeneration
{
if (this.location.IsOutdoors == false) return;
}
this.EnergyManager.produceEnergy(energy);
this.GetEnergyManager().produceEnergy(energy);
}
}
@ -104,11 +104,6 @@ namespace Revitalize.Framework.Objects.Machines.EnergyGeneration
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
{
this.updateInfo();
if (this.info.ignoreBoundingBox == true)
{
x *= -1;
y *= -1;
}
if (this.info == null)
{

View File

@ -64,10 +64,10 @@ namespace Revitalize.Framework.Objects.Machines
public override bool minutesElapsed(int minutes, GameLocation environment)
{
this.updateInfo();
if (this.updatesContainerObjectForProduction)
{
if (this.energyRequiredPer10Minutes != ModCore.Configs.machinesConfig.grinderEnergyConsumption) this.energyRequiredPer10Minutes = ModCore.Configs.machinesConfig.grinderEnergyConsumption;
ModCore.log("Update container object for production!");
//this.MinutesUntilReady -= minutes;
int remaining = minutes;
@ -85,10 +85,10 @@ namespace Revitalize.Framework.Objects.Machines
if (this.ConsumesEnergy)
{
this.drainEnergyFromNetwork(energySources); //Continually drain from the network.
if (this.EnergyManager.remainingEnergy < ModCore.Configs.machinesConfig.grinderEnergyConsumption) return false;
if (this.GetEnergyManager().remainingEnergy < ModCore.Configs.machinesConfig.grinderEnergyConsumption) return false;
else
{
this.EnergyManager.consumeEnergy(ModCore.Configs.machinesConfig.grinderEnergyConsumption); //Consume the required amount of energy necessary.
this.GetEnergyManager().consumeEnergy(ModCore.Configs.machinesConfig.grinderEnergyConsumption); //Consume the required amount of energy necessary.
}
}
else
@ -98,7 +98,7 @@ namespace Revitalize.Framework.Objects.Machines
remaining -= 10;
this.containerObject.MinutesUntilReady -= 10;
if (this.containerObject.MinutesUntilReady <= 0 && this.InventoryManager.IsFull == false)
if (this.containerObject.MinutesUntilReady <= 0 && this.GetInventoryManager().IsFull == false)
{
this.produceItem();
this.consumeItemForGrinding();
@ -206,7 +206,10 @@ namespace Revitalize.Framework.Objects.Machines
try
{
this.animationManager.tickAnimation();
if (this.animationManager.canTickAnimation())
{
this.animationManager.tickAnimation();
}
// Log.AsyncC("Tick animation");
}
catch (Exception err)
@ -220,9 +223,9 @@ namespace Revitalize.Framework.Objects.Machines
public override void produceItem()
{
if (this.InventoryManager.hasItemsInBuffer)
if (this.GetInventoryManager().hasItemsInBuffer)
{
this.InventoryManager.dumpBufferToItems();
this.GetInventoryManager().dumpBufferToItems();
}
}
@ -230,31 +233,31 @@ namespace Revitalize.Framework.Objects.Machines
{
Item itemToRemove = null;
foreach(Item I in this.InventoryManager.items)
foreach(Item I in this.GetInventoryManager().items)
{
if(I.canStackWith(new StardewValley.Object((int)Enums.SDVObject.CopperOre, 1))){
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("CopperSand", 2));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("CopperSand", 2));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
}
if (I.canStackWith(new StardewValley.Object((int)Enums.SDVObject.IronOre, 1)))
{
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("IronSand", 2));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("IronSand", 2));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
}
if (I.canStackWith(new StardewValley.Object((int)Enums.SDVObject.GoldOre, 1)))
{
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("GoldSand", 2));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("GoldSand", 2));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
}
if (I.canStackWith(new StardewValley.Object((int)Enums.SDVObject.IridiumOre, 1)))
{
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("IridiumSand", 2));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("IridiumSand", 2));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
@ -262,35 +265,35 @@ namespace Revitalize.Framework.Objects.Machines
if (I.canStackWith(ModCore.ObjectManager.resources.getOre("BauxiteOre")))
{
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("BauxiteSand", 2));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("BauxiteSand", 2));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
}
if (I.canStackWith(ModCore.ObjectManager.resources.getOre("LeadOre")))
{
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("LeadSand", 2));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("LeadSand", 2));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
}
if (I.canStackWith(ModCore.ObjectManager.resources.getOre("SilverOre")))
{
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("SilverSand", 2));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("SilverSand", 2));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
}
if (I.canStackWith(ModCore.ObjectManager.resources.getOre("TinOre")))
{
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("TinSand", 2));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("TinSand", 2));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
}
if (I.canStackWith(ModCore.ObjectManager.resources.getOre("TitaniumOre")))
{
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("TitaniumSand", 2));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("TitaniumSand", 2));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
@ -298,7 +301,7 @@ namespace Revitalize.Framework.Objects.Machines
if (I.canStackWith(new StardewValley.Object((int)Enums.SDVObject.Stone, 1)))
{
this.InventoryManager.bufferItems.Add(ModCore.ObjectManager.resources.getResource("Sand", 1));
this.GetInventoryManager().bufferItems.Add(ModCore.ObjectManager.resources.getResource("Sand", 1));
itemToRemove = I;
this.containerObject.MinutesUntilReady = ModCore.Configs.machinesConfig.grinderTimeToGrind;
break;
@ -313,7 +316,7 @@ namespace Revitalize.Framework.Objects.Machines
}
else if (itemToRemove.Stack == 1)
{
this.InventoryManager.items.Remove(itemToRemove);
this.GetInventoryManager().items.Remove(itemToRemove);
}
return true;

View File

@ -13,6 +13,7 @@ using Revitalize.Framework.Menus.Machines;
using Revitalize.Framework.Objects.InformationFiles;
using Revitalize.Framework.Utilities;
using StardewValley;
using StardewValley.Objects;
using StardustCore.Animations;
using StardustCore.UIUtilities;
using StardustCore.UIUtilities.MenuComponents.ComponentsV2.Buttons;
@ -32,12 +33,29 @@ namespace Revitalize.Framework.Objects.Machines
string pyTkData = ModCore.Serializer.ToJSONString(this.data);
string offsetKey = this.offsetKey != null ? ModCore.Serializer.ToJSONString(this.offsetKey) : "";
string container = this.containerObject != null ? this.containerObject.guid.ToString() : "";
string resources = ModCore.Serializer.ToJSONString(this.producedResources);
string energyRequired = this.energyRequiredPer10Minutes.ToString();
string timeToProduce = this.timeToProduce.ToString();
string updatesContainer = this.updatesContainerObjectForProduction.ToString();
return info + "<" + guidStr + "<" + pyTkData + "<" + offsetKey + "<" + container + "<" + resources + "<" + energyRequired + "<" + timeToProduce + "<" + updatesContainer + "<" + this.craftingRecipeBook;
StringBuilder b = new StringBuilder();
b.Append(info);
b.Append("<");
b.Append(guidStr);
b.Append("<");
b.Append(pyTkData);
b.Append("<");
b.Append(offsetKey);
b.Append("<");
b.Append(container);
b.Append("<");
b.Append(energyRequired);
b.Append("<");
b.Append(timeToProduce);
b.Append("<");
b.Append(updatesContainer);
b.Append("<");
b.Append(this.craftingRecipeBook);
//ModCore.log("Setting info: " + b.ToString());
return b.ToString();
}
set
{
@ -48,16 +66,16 @@ namespace Revitalize.Framework.Objects.Machines
string pyTKData = data[2];
string offsetVec = data[3];
string containerObject = data[4];
string resourcesString = data[5];
string energyRequired = data[6];
string time = data[7];
string updates = data[8];
this.craftingRecipeBook = data[9];
string energyRequired = data[5];
string time = data[6];
string updates = data[7];
this.craftingRecipeBook = data[8];
this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation));
this.data = Revitalize.ModCore.Serializer.DeserializeFromJSONString<CustomObjectData>(pyTKData);
this.energyRequiredPer10Minutes = Convert.ToInt32(energyRequired);
this.timeToProduce = Convert.ToInt32(time);
this.updatesContainerObjectForProduction = Convert.ToBoolean(updates);
if (string.IsNullOrEmpty(offsetVec)) return;
if (string.IsNullOrEmpty(containerObject)) return;
this.offsetKey = ModCore.Serializer.DeserializeFromJSONString<Vector2>(offsetVec);
@ -104,19 +122,26 @@ namespace Revitalize.Framework.Objects.Machines
//ModCore.CustomObjects.Remove(oldGuid);
}
}
if (string.IsNullOrEmpty(resourcesString) == false)
{
this.producedResources = ModCore.Serializer.DeserializeFromJSONString<List<ResourceInformation>>(resourcesString);
}
else
{
if (this.producedResources == null) this.producedResources = new List<ResourceInformation>();
}
}
}
public List<ResourceInformation> producedResources;
[JsonIgnore]
public List<ResourceInformation> producedResources
{
get
{
return MachineUtilities.GetResourcesProducedByThisMachine(this.info.id);
}
set
{
if (MachineUtilities.ResourcesForMachines == null) MachineUtilities.InitializeResourceList();
if (MachineUtilities.ResourcesForMachines.ContainsKey(this.info.id)) return;
MachineUtilities.ResourcesForMachines.Add(this.info.id, value);
Chest c = new Chest();
}
}
public int energyRequiredPer10Minutes;
public int timeToProduce;
public bool updatesContainerObjectForProduction;
@ -140,6 +165,7 @@ namespace Revitalize.Framework.Objects.Machines
{
get
{
this.updateInfo();
if (ModCore.Configs.machinesConfig.doMachinesConsumeEnergy == false)
{
//ModCore.log("Machine config disables energy consumption.");
@ -150,12 +176,12 @@ namespace Revitalize.Framework.Objects.Machines
//ModCore.log("Machine rquires 0 energy to run.");
return false;
}
if (this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Consumes)
if (this.GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Consumes)
{
//ModCore.log("Machine does consume energy.");
return true;
}
if (this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Storage)
if (this.GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Storage)
{
return true;
@ -216,20 +242,17 @@ namespace Revitalize.Framework.Objects.Machines
public override void updateWhenCurrentLocation(GameTime time, GameLocation environment)
{
base.updateWhenCurrentLocation(time, environment);
this.animationManager.prepareForNextUpdateTick();
}
public override bool minutesElapsed(int minutes, GameLocation environment)
{
if (this.info == null)
{
this.updateInfo();
}
ModCore.log(this.info.animationManager.currentAnimationName);
this.updateInfo();
//ModCore.log(this.info.animationManager.currentAnimationName);
if (this.updatesContainerObjectForProduction)
{
@ -238,7 +261,7 @@ namespace Revitalize.Framework.Objects.Machines
int remaining = minutes;
//ModCore.log("Minutes elapsed: " + remaining);
List<MultiTiledObject> energySources = new List<MultiTiledObject>();
if (this.ConsumesEnergy || this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Storage)
if (this.ConsumesEnergy || this.GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Storage)
{
//ModCore.log("This machine drains energy: " + this.info.name);
energySources = this.EnergyGraphSearchSources(); //Only grab the network once.
@ -246,17 +269,16 @@ namespace Revitalize.Framework.Objects.Machines
if (this.ProducesItems)
{
ModCore.log("This machine produces items: " + this.info.name);
while (remaining > 0)
{
if (this.ConsumesEnergy)
{
this.drainEnergyFromNetwork(energySources); //Continually drain from the network.
if (this.EnergyManager.remainingEnergy < this.energyRequiredPer10Minutes) return false;
if (this.GetEnergyManager().remainingEnergy < this.energyRequiredPer10Minutes) return false;
else
{
this.EnergyManager.consumeEnergy(this.energyRequiredPer10Minutes); //Consume the required amount of energy necessary.
this.GetEnergyManager().consumeEnergy(this.energyRequiredPer10Minutes); //Consume the required amount of energy necessary.
}
}
else
@ -266,14 +288,14 @@ namespace Revitalize.Framework.Objects.Machines
remaining -= 10;
this.containerObject.MinutesUntilReady -= 10;
if (this.containerObject.MinutesUntilReady <= 0 && this.InventoryManager.IsFull == false)
if (this.containerObject.MinutesUntilReady <= 0 && this.GetInventoryManager().IsFull == false)
{
this.produceItem();
this.containerObject.MinutesUntilReady = this.timeToProduce;
}
}
}
if (this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Produces)
if (this.GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Produces)
{
while (remaining > 0)
{
@ -286,9 +308,9 @@ namespace Revitalize.Framework.Objects.Machines
{
this.MinutesUntilReady = Math.Max(0, this.MinutesUntilReady - minutes);
if (this.InventoryManager.hasItemsInBuffer && this.MinutesUntilReady == 0)
if (this.GetInventoryManager().hasItemsInBuffer && this.MinutesUntilReady == 0)
{
this.InventoryManager.dumpBufferToItems();
this.GetInventoryManager().dumpBufferToItems();
}
}
@ -298,7 +320,7 @@ namespace Revitalize.Framework.Objects.Machines
else
{
if (this.EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Produces)
if (this.GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Produces)
{
this.storeEnergyToNetwork();
}
@ -330,15 +352,15 @@ namespace Revitalize.Framework.Objects.Machines
MachineSummaryMenu m = new Framework.Menus.Machines.MachineSummaryMenu((Game1.viewport.Width / 2) - 400, 48, 800, 600, Color.White, this.containerObject, this.energyRequiredPer10Minutes);
machineMenu.addInMenuTab("Summary", new AnimatedButton(new StardustCore.Animations.AnimatedSprite("SummaryTab", new Vector2(), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Menus", "MenuTab"), new Animation(0, 0, 24, 24)), Color.White), new Rectangle(0, 0, 24, 24), 2f), m, true);
if (this.InventoryManager.capacity > 0)
if (this.GetInventoryManager().capacity > 0)
{
InventoryTransferMenu transferMenu = new InventoryTransferMenu(100, 150, 500, 600, this.InventoryManager.items, this.InventoryManager.capacity, this.InventoryManager.displayRows, this.InventoryManager.displayColumns);
InventoryTransferMenu transferMenu = new InventoryTransferMenu(100, 150, 500, 600, this.GetInventoryManager().items, this.GetInventoryManager().capacity, this.GetInventoryManager().displayRows, this.GetInventoryManager().displayColumns);
machineMenu.addInMenuTab("Inventory", new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Inventory Tab", new Vector2(), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Menus", "MenuTab"), new Animation(0, 0, 24, 24)), Color.White), new Rectangle(0, 0, 24, 24), 2f), transferMenu, false);
}
if (string.IsNullOrEmpty(this.craftingRecipeBook) == false)
{
CraftingMenuV1 craftingMenu = CraftingRecipeBook.CraftingRecipesByGroup[this.craftingRecipeBook].getCraftingMenuForMachine(100, 100, 400, 700, ref this.InventoryManager.items, ref this.InventoryManager.items, this);
CraftingMenuV1 craftingMenu = CraftingRecipeBook.CraftingRecipesByGroup[this.craftingRecipeBook].getCraftingMenuForMachine(100, 100, 400, 700, ref this.GetInventoryManager().items, ref this.GetInventoryManager().items, this);
machineMenu.addInMenuTab("Crafting", new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Crafting Tab", new Vector2(), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Menus", "MenuTab"), new Animation(0, 0, 24, 24)), Color.White), new Rectangle(0, 0, 24, 24), 2f), craftingMenu, false);
}
@ -384,11 +406,6 @@ namespace Revitalize.Framework.Objects.Machines
public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
{
this.updateInfo();
if (this.info.ignoreBoundingBox == true)
{
x *= -1;
y *= -1;
}
if (this.info == null)
{
@ -428,7 +445,10 @@ namespace Revitalize.Framework.Objects.Machines
try
{
this.animationManager.tickAnimation();
if (this.animationManager.canTickAnimation())
{
this.animationManager.tickAnimation();
}
// Log.AsyncC("Tick animation");
}
catch (Exception err)
@ -448,7 +468,7 @@ namespace Revitalize.Framework.Objects.Machines
if (r.shouldDropResource())
{
Item i = r.getItemDrops();
this.InventoryManager.addItem(i);
this.GetInventoryManager().addItem(i);
//ModCore.log("Produced an item!");
}
}
@ -457,9 +477,9 @@ namespace Revitalize.Framework.Objects.Machines
public virtual void produceEnergy()
{
if (this.EnergyManager.canReceieveEnergy)
if (this.GetEnergyManager().canReceieveEnergy)
{
this.EnergyManager.produceEnergy(this.energyRequiredPer10Minutes);
this.GetEnergyManager().produceEnergy(this.energyRequiredPer10Minutes);
}
}
@ -467,7 +487,10 @@ namespace Revitalize.Framework.Objects.Machines
protected virtual void drawStatusBubble(SpriteBatch b, int x, int y, float Alpha)
{
if (this.updatesContainerObjectForProduction == false) return;
if (this.InventoryManager.IsFull && this.ProducesItems && ModCore.Configs.machinesConfig.showMachineNotificationBubble_InventoryFull)
if (this.machineStatusBubbleBox == null) this.createStatusBubble();
this.updateInfo();
if (this.GetInventoryManager() == null) return;
if (this.GetInventoryManager().IsFull && this.ProducesItems && ModCore.Configs.machinesConfig.showMachineNotificationBubble_InventoryFull)
{
y--;
float num = (float)(4.0 * Math.Round(Math.Sin(DateTime.UtcNow.TimeOfDay.TotalMilliseconds / 250.0), 2));
@ -480,6 +503,26 @@ namespace Revitalize.Framework.Objects.Machines
}
}
public override void updateInfo()
{
if (this.info == null || this.containerObject == null)
{
this.ItemInfo = this.text;
//ModCore.log("Updated item info!");
return;
}
if (this.requiresUpdate())
{
//this.ItemInfo = this.text;
this.text = this.ItemInfo;
this.info.cleanAfterUpdate();
this.containerObject.updateInfo();
//ModCore.log("Force an update for machine: " + this.info.name);
MultiplayerUtilities.RequestUpdateSync(this.guid);
}
}
}
}

View File

@ -33,6 +33,7 @@ namespace Revitalize.Framework.Objects.Machines
public override bool minutesElapsed(int minutes, GameLocation environment)
{
this.updateInfo();
return false;
}

View File

@ -92,52 +92,6 @@ namespace Revitalize.Framework.Objects
public Vector2 offsetKey;
[JsonIgnore]
public override EnergyManager EnergyManager
{
get
{
if (this.info == null || this.containerObject==null)
{
this.updateInfo();
if (this.containerObject == null) return null;
return this.containerObject.info.EnergyManager;
}
else
{
return this.containerObject.info.EnergyManager;
}
}
set
{
this.containerObject.info.EnergyManager = value;
}
}
/// <summary>
/// The inventory for the object.
/// </summary>
[JsonIgnore]
public virtual InventoryManager InventoryManager
{
get
{
if (this.info == null || this.containerObject == null)
{
this.updateInfo();
if (this.containerObject == null) return null;
return this.containerObject.info.inventory;
}
else
{
return this.containerObject.info.inventory;
}
}
set
{
this.containerObject.info.inventory = value;
}
}
public MultiTiledComponent() { }
@ -422,6 +376,7 @@ namespace Revitalize.Framework.Objects
if (this.info == null || this.containerObject==null)
{
this.ItemInfo = this.text;
//ModCore.log("Updated item info!");
return;
}
@ -460,7 +415,7 @@ namespace Revitalize.Framework.Objects
StardewValley.Object obj = this.location.getObjectAtTile((int)neighborTile.X, (int)neighborTile.Y);
if (obj is MultiTiledComponent)
{
if ((obj as MultiTiledComponent).EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Produces || (obj as MultiTiledComponent).EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Transfers || (obj as MultiTiledComponent).EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Storage)
if ((obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Produces || (obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Transfers || (obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Storage)
{
customObjects.Add((MultiTiledComponent)obj);
}
@ -498,7 +453,7 @@ namespace Revitalize.Framework.Objects
StardewValley.Object obj = this.location.getObjectAtTile((int)neighborTile.X, (int)neighborTile.Y);
if (obj is MultiTiledComponent)
{
if ((obj as MultiTiledComponent).EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Consumes || (obj as MultiTiledComponent).EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Transfers || (obj as MultiTiledComponent).EnergyManager.energyInteractionType == Enums.EnergyInteractionType.Storage)
if ((obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Consumes || (obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Transfers || (obj as MultiTiledComponent).GetEnergyManager().energyInteractionType == Enums.EnergyInteractionType.Storage)
{
customObjects.Add((MultiTiledComponent)obj);
}
@ -519,15 +474,15 @@ namespace Revitalize.Framework.Objects
/// <returns></returns>
protected virtual List<MultiTiledComponent> getAppropriateEnergyNeighbors()
{
if (this.EnergyManager.consumesEnergy)
if (this.GetEnergyManager().consumesEnergy)
{
return this.GetNeighboringOutputEnergySources();
}
else if (this.EnergyManager.producesEnergy)
else if (this.GetEnergyManager().producesEnergy)
{
return this.GetNeighboringInputEnergySources();
}
else if (this.EnergyManager.transfersEnergy)
else if (this.GetEnergyManager().transfersEnergy)
{
List<MultiTiledComponent> objs = new List<MultiTiledComponent>();
objs.AddRange(this.GetNeighboringInputEnergySources());
@ -620,8 +575,8 @@ namespace Revitalize.Framework.Objects
for(int i = 0; i < energySources.Count; i++)
{
this.EnergyManager.transferEnergyFromAnother(energySources[i].EnergyManager, this.EnergyManager.capacityRemaining);
if (this.EnergyManager.hasMaxEnergy) break;
this.GetEnergyManager().transferEnergyFromAnother(energySources[i].GetEnergyManager(), this.GetEnergyManager().capacityRemaining);
if (this.GetEnergyManager().hasMaxEnergy) break;
}
}
@ -631,8 +586,8 @@ namespace Revitalize.Framework.Objects
for (int i = 0; i < energySources.Count; i++)
{
this.EnergyManager.transferEnergyFromAnother(energySources[i].EnergyManager, this.EnergyManager.capacityRemaining);
if (this.EnergyManager.hasMaxEnergy) break;
this.GetEnergyManager().transferEnergyFromAnother(energySources[i].GetEnergyManager(), this.GetEnergyManager().capacityRemaining);
if (this.GetEnergyManager().hasMaxEnergy) break;
}
}
@ -647,8 +602,8 @@ namespace Revitalize.Framework.Objects
for (int i = 0; i < energySources.Count; i++)
{
this.EnergyManager.transferEnergyToAnother(energySources[i].EnergyManager, this.EnergyManager.capacityRemaining);
if (this.EnergyManager.hasEnergy==false) break;
this.GetEnergyManager().transferEnergyToAnother(energySources[i].GetEnergyManager(), this.GetEnergyManager().capacityRemaining);
if (this.GetEnergyManager().hasEnergy==false) break;
}
}
@ -659,8 +614,57 @@ namespace Revitalize.Framework.Objects
for (int i = 0; i < energySources.Count; i++)
{
this.EnergyManager.transferEnergyToAnother(energySources[i].EnergyManager, this.EnergyManager.capacityRemaining);
if (this.EnergyManager.hasEnergy==false) break;
this.GetEnergyManager().transferEnergyToAnother(energySources[i].GetEnergyManager(), this.GetEnergyManager().capacityRemaining);
if (this.GetEnergyManager().hasEnergy==false) break;
}
}
public override ref EnergyManager GetEnergyManager()
{
if (this.info == null || this.containerObject == null)
{
this.updateInfo();
if (this.containerObject == null) return ref this.info.EnergyManager;
return ref this.containerObject.info.EnergyManager;
}
return ref this.containerObject.info.EnergyManager;
}
public override void SetEnergyManager(ref EnergyManager Manager)
{
this.info.EnergyManager = Manager;
}
public override ref InventoryManager GetInventoryManager()
{
if (this.info == null || this.containerObject == null)
{
this.updateInfo();
if (this.containerObject == null)
{
return ref this.info.inventory;
}
return ref this.containerObject.info.inventory;
}
return ref this.containerObject.info.inventory;
}
public override void SetInventoryManager(InventoryManager Manager)
{
this.info.inventory = Manager;
this.containerObject.info.inventory = Manager;
}
public override bool requiresUpdate()
{
if (this.info.requiresSyncUpdate() || this.containerObject.info.requiresSyncUpdate())
{
return true;
}
else
{
return false;
}
}
}

View File

@ -183,7 +183,7 @@ namespace Revitalize.Framework.Objects
MultiTiledObject sandBox = new MultiTiledObject(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Sandbox", TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), typeof(MultiTiledObject), Color.White, true), new BasicItemInformation("Sandbox", "Omegasis.Revitalize.Objects.Machines.Sandbox", "A sandbox which slowly produces sand. Unfortunately you can't sit in this one.", "Machine", Color.SteelBlue, -300, 0, false, 750, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), new AnimationManager(), Color.White, true, new InventoryManager(36), null, null));
Machine sandBox_0_0 = new Machine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Sandbox", TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), typeof(Machine), Color.White, true), new BasicItemInformation("Sandbox", "Omegasis.Revitalize.Objects.Machines.Sandbox", "A sandbox which slowly produces sand. Unfortunately you can't sit in this one.", "Machine", Color.SteelBlue, -300, 0, false, 750, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "Sandbox"),new Animation(0,0,16,16)), Color.White, false, new InventoryManager(36), null, null), new List<InformationFiles.ResourceInformation>()
{
//new InformationFiles.ResourceInformation(this.resources.getResource("Sand",1),1,1,1,1,1,1,0,0,0,0)
new InformationFiles.ResourceInformation(this.resources.getResource("Sand",1),1,1,1,1,1,1,0,0,0,0)
}, 0, TimeUtilities.GetMinutesFromTime(0, 1, 0), true,"Workbench");
Machine sandBox_1_0 = new Machine(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Objects.Machines.Sandbox", TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), typeof(Machine), Color.White, true), new BasicItemInformation("Sandbox", "Omegasis.Revitalize.Objects.Machines.Sandbox", "A sandbox which slowly produces sand. Unfortunately you can't sit in this one.", "Machine", Color.SteelBlue, -300, 0, false, 750, true, true, TextureManager.GetTexture(ModCore.Manifest, "Machines", "Sandbox"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Machines", "Sandbox"), new Animation(16, 0, 16, 16)), Color.White, false, new InventoryManager(36), null, null), new List<InformationFiles.ResourceInformation>()

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Revitalize.Framework.Objects.InformationFiles;
namespace Revitalize.Framework.Utilities
{
public class MachineUtilities
{
public static Dictionary<string, List<ResourceInformation>> ResourcesForMachines;
public static List<ResourceInformation> GetResourcesProducedByThisMachine(string ID)
{
if (ResourcesForMachines == null) InitializeResourceList();
if (ResourcesForMachines.ContainsKey(ID))
{
return ResourcesForMachines[ID];
}
else if (ID.Equals("Omegasis.Revitalize.Objects.Machines.MiningDrillV1"))
{
return ModCore.ObjectManager.resources.miningDrillResources.Values.ToList();
}
return new List<ResourceInformation>();
}
public static void InitializeResourceList()
{
ResourcesForMachines = new Dictionary<string, List<ResourceInformation>>()
{
{"Omegasis.Revitalize.Objects.Machines.BatteryBin" ,new List<ResourceInformation>(){
new Objects.InformationFiles.ResourceInformation(new StardewValley.Object((int)Enums.SDVObject.BatteryPack,1),1,1,1,1,1,1,0,0,0,0)
} },
{"Omegasis.Revitalize.Objects.Machines.Sandbox",new List<ResourceInformation>(){
new Objects.InformationFiles.ResourceInformation(ModCore.ObjectManager.resources.getResource("Sand",1),1,1,1,1,1,1,0,0,0,0)
} }
};
}
}
}

View File

@ -335,7 +335,7 @@ namespace Revitalize
*/
if (e.Button == SButton.U)
{
CraftingMenuV1 craft = new CraftingMenuV1(100, 100, 600, 800, Color.White, Game1.player.Items);
CraftingMenuV1 craft = new CraftingMenuV1(100, 100, 600, 800, Color.White, Game1.player.Items.ToList());
craft.addInCraftingPageTab("Default", new AnimatedButton(new StardustCore.Animations.AnimatedSprite("Default Tab", new Vector2(100 + 48, 100 + (24 * 4)), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Menus", "MenuTabHorizontal"), new Animation(0, 0, 24, 24)), Color.White), new Rectangle(0, 0, 24, 24), 2f));
craft.addInCraftingRecipe(new Framework.Menus.MenuComponents.CraftingRecipeButton(new Recipe(new List<CraftingRecipeComponent>()
{

View File

@ -183,6 +183,7 @@
<Compile Include="Framework\Utilities\IntRange.cs" />
<Compile Include="Framework\Utilities\InventoryManager.cs" />
<Compile Include="Framework\Utilities\LocationUtilities.cs" />
<Compile Include="Framework\Utilities\MachineUtilities.cs" />
<Compile Include="Framework\Utilities\MultiplayerUtilities.cs" />
<Compile Include="Framework\Utilities\ObjectUtilities.cs" />
<Compile Include="Framework\Utilities\PlayerUtilities.cs" />

View File

@ -27,6 +27,8 @@ namespace StardustCore.Animations
public bool requiresUpdate;
public bool IsNull => this.defaultDrawFrame == null && this.objectTexture == null;
public bool hasRecievedUpdateTick;
/// <summary>
/// Checks to see if there is an animation playing.
/// </summary>
@ -107,6 +109,7 @@ namespace StardustCore.Animations
this.getNextAnimationFrame();
this.currentAnimation.tickAnimationFrame();
//this.requiresUpdate = true;
this.hasRecievedUpdateTick = true;
}
catch (Exception err)
{
@ -115,6 +118,16 @@ namespace StardustCore.Animations
}
}
public void prepareForNextUpdateTick()
{
this.hasRecievedUpdateTick = false;
}
public bool canTickAnimation()
{
return this.hasRecievedUpdateTick == false;
}
/// <summary>Get the next animation frame in the list of animations.</summary>
private void getNextAnimationFrame()
{