You have a modulo bias in your code which should be addressed (See Here: https://stackoverflow.com/a/46991999/3985011 ) But that is not "game-breaking" per-se, but usually you would want to have an unbiased chance of something and control it by adding your own weighting.
Also, since you have static Items you want to assign, you could create Variables with IDs for each of them to make this process a little better.
I really love the Idea of Creating a game in CMD, if you would like to
Collaborate Further I woudl love to trade code back ad forth.
I did this for a few hours of fun while between other work, Let's take some time to chat over thins as it's a bit much to write up everything so if you like the code let me know what portions you woudl like to know more about.
Here is your code re-written to make use of a basic inventory system, and to remove the Modulo bias.
@(
SETLOCAL EnableDelayedExpansion
ECHO OFF
SET "_PCInv_Plant.Slots=11"
SET "_PCInv_Armor.Slots=13"
SET "_PCInv_Key.Slots=42"
SET "ECHO_RW=Call :Echo_Color CF "
SET "ECHO_GB=Call :Echo_Color 20 "
SET "ECHO_AB=Call :Echo_Color B0 "
SET "ECHO_LY=Call :Echo_Color 1E "
SET "ECHO_YL=Call :Echo_Color E1 "
SET "ECHO_YR=Call :Echo_Color EC "
SET "ECHO_YB=Call :Echo_Color E0 "
SET "ECHO_RY=Call :Echo_Color CE "
SET "ECHO_BY=Call :Echo_Color 1E "
SET "_Pad=000"
SET "_eLvl=0"
)
CALL :Main
(
Endlocal
COLOR
EXIT /B %eLvl%
)
:Echo_Color
ECHO.>"%~2"
FINDStr /A:%~1 /I ".*" "%~2" NUL
DEL /F /Q "%~2" >nul 2>nul
GOTO :EOF
:Main
CALL :Initialize_Inventory_Items
REM Lets Get 5 Random Items added to the Inevntory from the shop by calling the Test Function 5 times
COLOR 1E
CLS
ECHO.
FOR /L %%L IN (1,1,5) DO (
CALL :Test
)
CLS
COLOR 0E
ECHO.
SET "_PCInv_"
ECHO.
%ECHO_AB% "============================================="
%ECHO_AB% "== Results of Player Inventory Shown Above =="
%ECHO_AB% "============================================="
Pause
GOTO :EOF
:Test
REM cls
CALL :Random _# %_InvItem.count%
REM ECHO. # %_#%
ECHO.
FOR /F "Tokens=1-2* Delims==" %%A IN ('
SET "_InvItem_!_#!"
') DO (
SET "_TType=%%B"
SET "_TDesc=%%C"
)
ECHO(
ECHO(
%ECHO_AB% "You Recievded a !_TType!, It appears to be a '!_TDesc!'"
REM SET Default Value = 0
SET "_TSlot=0"
REM Find First Inventory Slot available.
FOR /F "Tokens=3 Delims=_=" %%A IN ('
SET "_PCInv_!_TType!" ^| FIND /I /V "NONE"
') DO ('
SET /A "_TSlot+=1"
) 2>NUL
REM Place into the First Inventory Slot available.
IF /I !_TSlot! GTR !_PCInv_%_TType%.Slots! (
COLOR CE
ECHO.No Room!
) ELSE (
SET "_Tmp#=%_Pad%!_TSlot!"
SET "_Tmp#=!_Tmp#:~-2!"
REM Add The Item to the Inventory Slot.
SET "_PCInv_!_TType!_!_Tmp#!=!_TDesc!"
%ECHO_YB% " == The !_TType! has been added to Your inventory"
PAUSE
)
GOTO :EOF
:Random
SETLOCAL DisableDelayedExpansion
REM Loops until a valid result is obtained.
SET /A "_Rnd=%Random%"
SET /A "_Max_Valid=( 32767 - ( ( ( 32767 %% %~2 ) + 1 ) %% %~2 ) )"
REM ECHO. "_Rnd" = "%_Rnd%"
REM ECHO. "_Max_Valid" = "%_Max_Valid%"
IF /I "%_Rnd%" GTR "%_Max_Valid%" (
GOTO :Random
)
(
ENDLOCAL
SET /A "%~1=%_Rnd% %% %~2"
)
REM ECHO. # %_#%
GOTO :EOF
:Initialize_Inventory_Items
REM Set up Inventory Items.
SET "_InvItem_0=Plant=Red Spotted Mushroom"
SET "_InvItem_1=Key=Key to Nowhere"
SET "_InvItem_2=Key=Key to Somewhere"
SET "_InvItem_3=Armor=Nordic Berserker Helmet"
SET "_InvItem_4=Plant=Blue Orchid"
REM Store count of Inventory Items
FOR /F %%A IN ('
SET "_InvItem_"
') DO (
CALL SET /A "_InvItem.count+=1"
)
REM Set all Player Inventory Slots to "None"
FOR %%A IN (
Plant
Armor
Key
) DO (
REM ECHO _PCInv_%%A.Slots = !_PCInv_%%A.Slots!
FOR /L %%L IN (1,1,!_PCInv_%%A.Slots!) DO (
SET "_Tmp#=%_Pad%%%L"
SET "_Tmp#=!_Tmp#:~-2!"
REM ECHO SET "_PCInv_!_Tmp#!_%%L=None"
SET "_PCInv_%%A_!_Tmp#!=None"
)
)
GOTO :EOF