Skip to content

Commit

Permalink
Debug: Add possibility to specify amount of gold in TakeGold cmd
Browse files Browse the repository at this point in the history
Currently in GiveGold and TakeGold commands in debug.cpp we only have
a possibility to flood our inventory with gold, this patch adds a
possibility to either specify amount of gold to be added or just
write "max" which will preserve native functionality of those commands,
by clearing all gold or giving max gold possible (depending on the
amount of free slots in inventory).
  • Loading branch information
tetektoza committed Oct 14, 2023
1 parent 4e64418 commit 0933d1a
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions Source/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,38 @@ std::string DebugCmdTakeGoldCheat(const std::string_view parameter)
Player &myPlayer = *MyPlayer;
std::string cmdLabel = "[takegold] ";

int goldToRemove = 0;

if (parameter == "max")
goldToRemove = GOLD_MAX_LIMIT * InventoryGridCells;
else
goldToRemove = ParseInt<int>(parameter, /*min=*/1).value_or(1);

const int goldAmountBefore = myPlayer._pGold;
for (auto itemIndex : myPlayer.InvGrid) {
itemIndex -= 1;

if (itemIndex < 0)
continue;
if (myPlayer.InvList[itemIndex]._itype != ItemType::Gold)

Item &item = myPlayer.InvList[itemIndex];
if (!item.isGold())
continue;

if (item._ivalue >= goldToRemove) {
myPlayer._pGold -= goldToRemove;
item._ivalue -= goldToRemove;
if (item._ivalue == 0)
myPlayer.RemoveInvItem(itemIndex);
break;
}

myPlayer._pGold -= item._ivalue;
goldToRemove -= item._ivalue;
myPlayer.RemoveInvItem(itemIndex);
}

myPlayer._pGold = 0;

return StrCat(cmdLabel, "Set your gold to", myPlayer._pGold, ".");
return StrCat(cmdLabel, "Set your gold to ", myPlayer._pGold, ", removed ", goldAmountBefore - myPlayer._pGold, ".");
}

std::string DebugCmdWarpToLevel(const std::string_view parameter)
Expand Down Expand Up @@ -1221,7 +1239,7 @@ std::vector<DebugCmdItem> DebugCmdList = {
{ "maxstats", "Sets all stat values to maximum.", "", &DebugCmdMaxStats },
{ "minstats", "Sets all stat values to minimum.", "", &DebugCmdMinStats },
{ "setspells", "Set spell level to {level} for all spells.", "{level}", &DebugCmdSetSpellsLevel },
{ "takegold", "Removes all gold from inventory.", "", &DebugCmdTakeGoldCheat },
{ "takegold", "Removes {amount} or {max} gold from inventory.", "{amount/max}", &DebugCmdTakeGoldCheat },
{ "givequest", "Enable a given quest.", "({id})", &DebugCmdQuest },
{ "givemap", "Reveal the map.", "", &DebugCmdMapReveal },
{ "takemap", "Hide the map.", "", &DebugCmdMapHide },
Expand Down

0 comments on commit 0933d1a

Please sign in to comment.