From d5f00c38cf45acceb15d67f3dc9cf09ffd85392f Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Fri, 22 Dec 2023 16:51:16 -0300 Subject: [PATCH] New Command: 2099 - StoreCommands Store commands inside a Stringvariable. //$storeCommands "preffix",[evtType_isVar, evtType, evtId_isVar, evtId, evtPage_isVar, evtPage, targetStrVar_isVar, targetStrVar] // 2099, "@easyrpg_raw", [1,4, 1,5, 1,6, 1,7], 0; --- src/dynrpg_easyrpg.h | 1 - src/game_interpreter.cpp | 72 ++++++++++++++++++++++++++++++++++++++++ src/game_interpreter.h | 3 ++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/dynrpg_easyrpg.h b/src/dynrpg_easyrpg.h index 4499df98951..0f9e41e446f 100644 --- a/src/dynrpg_easyrpg.h +++ b/src/dynrpg_easyrpg.h @@ -21,7 +21,6 @@ #include "game_dynrpg.h" #include "game_battle.h" #include "game_map.h" -#include "constants.h" namespace DynRpg { /** diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index ab1d780cde0..315eb35b9cb 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -825,6 +825,8 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) { return CommandManiacControlStrings(com); case Cmd::Maniac_CallCommand: return CommandManiacCallCommand(com); + case static_cast (2099): //easyrpg_storeCommands + return CommandStoreCommands(com); default: return true; } @@ -5061,6 +5063,76 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const& co return true; } +bool Game_Interpreter::CommandStoreCommands(lcf::rpg::EventCommand const& com) { + //$storeCommands "preffix",[evtType_isVar, evtType, evtId_isVar, evtId, evtPage_isVar, evtPage, targetStrVar_isVar, targetStrVar] + // 2099, "@easyrpg_raw", [1,4, 1,5, 1,6, 1,7], 0; + + int evtType = ValueOrVariable(com.parameters[0], com.parameters[1]); + int evtId = ValueOrVariable(com.parameters[2], com.parameters[3]); + int evtPage = ValueOrVariable(com.parameters[4], com.parameters[5]); + int targetStrVar = ValueOrVariable(com.parameters[6], com.parameters[7]); // target string variable + + std::string textPreffix = com.string.empty() ? "" : ToString(com.string) + " "; + + Game_Event* event; + const lcf::rpg::EventPage* page; + Game_CommonEvent* common_event; + + if (evtType == 0) { // Map Event + event = static_cast(GetCharacter(evtId)); + if (!event || evtId == 10001) { + Output::Warning("StoreCommands: Can't read non-existent event {}", evtId); + return true; + } + page = event->GetPage(evtPage); + if (!page) { + Output::Warning("StoreCommands: Can't read non-existent page {} of event {}", evtPage, evtId); + return true; + } + } + else if (evtType == 1) { // Common Event + common_event = lcf::ReaderUtil::GetElement(Game_Map::GetCommonEvents(), evtId); + if (!common_event) { + Output::Warning("StoreCommands: Can't read invalid common event {}", evtId); + return true; + } + } + + std::string rawCommand = " "; + Constants constList; + + const auto& list = evtType == 1 ? common_event->GetList() : page->event_commands; + int index = 0; + + for (size_t i = index; i < list.size(); ++i) { + std::stringstream ss; + + for (size_t j = 0; j < list[i].parameters.size(); ++j) { + ss << std::to_string(list[i].parameters[j]); + if (j < list[i].parameters.size() - 1) ss << ", "; + } + + std::string inputString = ToString(list[i].string); + for (size_t j = 0; j < inputString.length(); ++j) + if (inputString[j] == '"') { + inputString.insert(j, 1, '"'); + ++j; + } + + std::string preffix(list[i].indent, ' '); + std::string suffix = i < list.size() - 1 ? "\n" : ""; + + rawCommand += fmt::format("{}${}, \"{}\", [{}], {};{}", + preffix, constList.get("EventCode", std::to_string(list[i].code), 1), inputString, ss.str(), list[i].indent, suffix); + } + + Game_Strings::Str_Params str_params = { targetStrVar,0, 0 }; + Main_Data::game_strings->Asg(str_params, textPreffix + rawCommand); + //fmt::print(rawCommand); + + return true; +} + Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() { return Game_Battle::IsBattleRunning() ? Game_Battle::GetInterpreter() diff --git a/src/game_interpreter.h b/src/game_interpreter.h index 8d0e44625a3..6d0fdc5893b 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -32,6 +32,7 @@ #include #include #include "async_op.h" +#include "constants.h" class Game_Event; class Game_CommonEvent; @@ -289,6 +290,8 @@ class Game_Interpreter bool CommandManiacControlStrings(lcf::rpg::EventCommand const& com); bool CommandManiacCallCommand(lcf::rpg::EventCommand const& com); + bool CommandStoreCommands(lcf::rpg::EventCommand const& com); + int DecodeInt(lcf::DBArray::const_iterator& it); const std::string DecodeString(lcf::DBArray::const_iterator& it); lcf::rpg::MoveCommand DecodeMove(lcf::DBArray::const_iterator& it);