Skip to content

Commit

Permalink
Modular Recipe Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
NeDether committed Nov 28, 2023
1 parent 1f71ae6 commit bdac5b9
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 13 deletions.
98 changes: 91 additions & 7 deletions Craft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,102 @@ bool Craft::HandleUIMessage(IWindow* window, const Message& message)
{
if (message.eventType == MessageType::kMsgButtonClick)
{
App::ConsolePrintF("energy");
cSpaceToolDataPtr tool;
ToolManager.LoadTool({ id("energypotion"), 0, 0 }, tool);
tool->mCurrentAmmoCount = 2;
auto inventory = SimulatorSpaceGame.GetPlayerInventory();
inventory->AddItem(tool.get());
SpaceTrading.ObtainTradingObject({ id("spice_drt_ice"), 0, 0 }, -5);
if (!HasMaterial(id("spice_drt_ice"), 20) || !HasMaterial(id("spice_mat_copper"), 5)) {

return true;
}
if (!UseMaterial(id("spice_drt_ice"), 20) || !UseMaterial(id("spice_mat_copper"), 5)) {

return true;
}
if (GiveItem(id("energypotion"), 1)) {

return true;
//Run if happen.
}
return true;

}
// Return true if the message was handled, and therefore no other window procedure should receive it.
return false;

// Return true if the message was handled, and therefore no other window procedure should receive it.

}
bool Craft::UseMaterial(uint32_t WareID, int neededAmount)
{//Returns True if Has Material. Returns False if Does not.
auto inventory = SimulatorSpaceGame.GetPlayerInventory();
auto X = inventory->IndexOf(Simulator::SpaceInventoryItemType(4), { WareID, 0, 0 });
auto H = inventory->GetItem(X);
if (H == nullptr) {
App::ConsolePrintF("Does not have Any Resources...");
return false;
}
size_t itemCount;
if (H->GetItemCount(itemCount))
{

if (itemCount >= neededAmount) {

App::ConsolePrintF("The total ''Count'' in the inv: %d", H);

SpaceTrading.ObtainTradingObject({ WareID, 0, 0 }, (neededAmount*-1));
if (itemCount == neededAmount) {
auto D = inventory->RemoveItem(H);

}
return true;
//do stuff
}
if (itemCount == 0) {
//Deletes the cargo if reaches 0 because spore is ok with having '0' of a cargo slot.
auto D = inventory->RemoveItem(H);
}
App::ConsolePrintF("Insufficient Resources...");
}
App::ConsolePrintF("I had a bruh moment.");
return false;
}


bool Craft::GiveItem(uint32_t WareID, int givenAmount)
{ //Returns true if Gives Item, returns false if does not.
//Gives energy potion.
auto inventory = SimulatorSpaceGame.GetPlayerInventory();
cSpaceToolDataPtr tool;
ToolManager.LoadTool({ WareID, 0, 0 }, tool);
tool->mCurrentAmmoCount = givenAmount;

inventory->AddItem(tool.get());

if (inventory->mbHasAddedItem) {
return true;

}
return false;
}
bool Craft::HasMaterial(uint32_t WareID, int neededAmount)
{ //Checks if has the materials in the first place before using them up.
auto inventory = SimulatorSpaceGame.GetPlayerInventory();
auto X = inventory->IndexOf(Simulator::SpaceInventoryItemType(4), { WareID, 0, 0 });
auto H = inventory->GetItem(X);
if (H == nullptr) {
App::ConsolePrintF("Does not have Any Resources...");
return false;
}
size_t itemCount;
if (H->GetItemCount(itemCount))
{

if (itemCount >= neededAmount) {

return true;
//do stuff
}

App::ConsolePrintF("Insufficient Resources...");
}
App::ConsolePrintF("I had a bruh moment.");
return false;
}
//
9 changes: 7 additions & 2 deletions Craft.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include "Spore/Simulator/SubSystem/SpaceTrading.h"
#include <Spore/CommonIDs.h>
#include <Spore/Simulator/cSpaceToolData.h>

#include <Spore/Simulator/SimulatorEnums.h>
#include <Spore/Simulator/cSimulatorSpaceGame.h>
#include <Spore/Simulator/cPlayerInventory.h>
#include <Spore/ResourceKey.h>
#define CraftPtr intrusive_ptr<Craft>

// To avoid repeating UTFWin:: all the time.
Expand All @@ -15,7 +18,6 @@ class Craft
, public DefaultRefCounted
{
public:
static const uint32_t TYPE = id("Craft");

Craft();
~Craft();
Expand All @@ -27,5 +29,8 @@ class Craft
int GetEventFlags() const override;
// This is the function you have to implement, called when a window you added this winproc to received an event
bool HandleUIMessage(IWindow* pWindow, const Message& message) override;
bool UseMaterial(uint32_t WareID, int neededAmount);
bool GiveItem(uint32_t WareID, int givenAmount);
bool HasMaterial(uint32_t WareID, int neededAmount);

};
4 changes: 2 additions & 2 deletions SMFX/RattlerSpore/config.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Tue Nov 28 11:58:57 EST 2023
lastTimeUsed=1701190737036
#Tue Nov 28 13:32:46 EST 2023
lastTimeUsed=1701195134231
isReadOnly=false
sources="Spore (Game & Graphics)"
fixedTabPaths="animations~\\en-us.package.unpacked\\locale~\\rattlerforge.locale"
Expand Down
4 changes: 2 additions & 2 deletions SdkPathConfig.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<SporeSdkPath>D:\Spore ModAPI SDK\</SporeSdkPath>
<SporeLauncherPath>D:\SteamLibrary\GOG\Spore\MODAPI\Spore ModAPI Launcher Kit\</SporeLauncherPath>
<SporeSdkPath>F:\Spore ModAPI SDK\</SporeSdkPath>
<SporeLauncherPath>F:\SPORE ModAPI Launcher Kit\</SporeLauncherPath>
</PropertyGroup>
<PropertyGroup />
<ItemDefinitionGroup />
Expand Down

0 comments on commit bdac5b9

Please sign in to comment.