Skip to content

Commit

Permalink
Command 9996 ( TODO ) : calling common event to check if skill is usable
Browse files Browse the repository at this point in the history
Params :
isVariable? ; eventID ; isVariable? ; resultVar ( -1 no change, 0 unusable, 1 usable ) ; isVariable? ; actorID ; isVariable? ; skillID

Command 9995 ( TODO ) : store MP cost of a skill in variable
Params :
isVariable? ; skillID ; isVariable? ; variable ID
  • Loading branch information
MackValentine committed May 4, 2024
1 parent b313163 commit 34a0f56
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/game_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include "attribute.h"
#include "rand.h"
#include "algo.h"
#include "scene_battle.h"
#include "game_variables.h"
#include "game_map.h"

constexpr int max_level_2k = 50;
constexpr int max_level_2k3 = 99;
Expand Down Expand Up @@ -230,6 +233,40 @@ bool Game_Actor::IsSkillUsable(int skill_id) const {
Output::Warning("IsSkillUsable: Invalid skill ID {}", skill_id);
return false;
}
if (CustomCheckSkill::used) {

int eventID = CustomCheckSkill::eventID;
int actorID = CustomCheckSkill::actorID;
int skillID = CustomCheckSkill::skillID;
int resultVar = CustomCheckSkill::result;


Game_CommonEvent* common_event = lcf::ReaderUtil::GetElement(Game_Map::GetCommonEvents(), eventID);
if (!common_event) {
Output::Warning("CallEvent: Can't call invalid common event {}", eventID);
}
else {

Main_Data::game_variables->Set(actorID, GetId());
Main_Data::game_variables->Set(skillID, skill_id);

if (Scene::instance->type == Scene::Battle)
Game_Battle::GetInterpreter().Push(common_event);
else
Game_Map::GetInterpreter().Push(common_event);

common_event->ForceCreate(eventID);
common_event->ForceUpdate(false);

}

int result = Main_Data::game_variables->Get(resultVar);

if (result == 0)
return false;
if (result == 1)
return true;
}

if (!skill->affect_attr_defence) {
// Actor must have all attributes of the skill equipped as weapons
Expand Down
25 changes: 25 additions & 0 deletions src/game_commonevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ AsyncOp Game_CommonEvent::Update(bool resume_async) {
return {};
}

void Game_CommonEvent::ForceCreate(int ce_ID) {
auto* ce = lcf::ReaderUtil::GetElement(lcf::Data::commonevents, ce_ID);

{
if (!interpreter)
interpreter.reset(new Game_Interpreter_Map());
interpreter->Push(this);
}
}

AsyncOp Game_CommonEvent::ForceUpdate(bool resume_async) {
if (interpreter) {
assert(interpreter->IsRunning());
interpreter->Update(!resume_async);

// Suspend due to async op ...
if (interpreter->IsAsyncPending()) {
return interpreter->GetAsyncOp();
}
}

return {};
}


int Game_CommonEvent::GetIndex() const {
return common_event_id;
}
Expand Down
9 changes: 9 additions & 0 deletions src/game_commonevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ class Game_CommonEvent {
*/
AsyncOp Update(bool resume_async);

/**
* Force updates common event parallel interpreter.
*
* @param resume_async If we're resuming from an async operation.
* @return async operation if we should suspend, otherwise returns AsyncOp::eNone
*/
AsyncOp ForceUpdate(bool resume_async);
void ForceCreate(int ce_ID);

/**
* Gets common event index.
*
Expand Down
46 changes: 46 additions & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "baseui.h"
#include "algo.h"
#include "rand.h"
#include "scene_battle.h"

enum BranchSubcommand {
eOptionBranchElse = 1
Expand Down Expand Up @@ -826,6 +827,10 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) {
return CommandManiacControlStrings(com);
case Cmd::Maniac_CallCommand:
return CommandManiacCallCommand(com);
case 9996:
return CommandSetCustomIsSkillUsable(com);
case 9995:
return CommandGetSkillMPCost(com);
default:
return true;
}
Expand Down Expand Up @@ -5161,3 +5166,44 @@ int Game_Interpreter::ManiacBitmask(int value, int mask) const {

return value;
}

bool Game_Interpreter::CommandSetCustomIsSkillUsable(lcf::rpg::EventCommand const& com) {

int eventID = ValueOrVariable(com.parameters[0], com.parameters[1]);
int result = ValueOrVariable(com.parameters[2], com.parameters[3]);
int actorID = ValueOrVariable(com.parameters[4], com.parameters[5]);
int skillID = ValueOrVariable(com.parameters[6], com.parameters[7]);

CustomCheckSkill::eventID = eventID;
CustomCheckSkill::actorID = actorID;
CustomCheckSkill::skillID = skillID;
CustomCheckSkill::result = result;
CustomCheckSkill::used = true;

// Output::Debug("CustomSkillUsable {} {} {} {}", eventID, actorID, skillID, result);

return true;
}

bool Game_Interpreter::CommandGetSkillMPCost(lcf::rpg::EventCommand const& com) {

int skillID = ValueOrVariable(com.parameters[0], com.parameters[1]);
int result = ValueOrVariable(com.parameters[2], com.parameters[3]);



const lcf::rpg::Skill* skill = lcf::ReaderUtil::GetElement(lcf::Data::skills, skillID);

if (!skill) {
Output::Warning("IsSkillUsable: Invalid skill ID {}", skillID);
return true;
}

int mpCost = skill->sp_cost;
// Output::Debug("CommandGetSkillMPCost {} {} {}", skillID, result, mpCost);

Main_Data::game_variables->Set(result, mpCost);


return true;
}
2 changes: 2 additions & 0 deletions src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ class Game_Interpreter
bool CommandManiacSetGameOption(lcf::rpg::EventCommand const& com);
bool CommandManiacControlStrings(lcf::rpg::EventCommand const& com);
bool CommandManiacCallCommand(lcf::rpg::EventCommand const& com);
bool CommandSetCustomIsSkillUsable(lcf::rpg::EventCommand const& com);
bool CommandGetSkillMPCost(lcf::rpg::EventCommand const& com);

int DecodeInt(lcf::DBArray<int32_t>::const_iterator& it);
const std::string DecodeString(lcf::DBArray<int32_t>::const_iterator& it);
Expand Down
9 changes: 9 additions & 0 deletions src/scene_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
#include "enemyai.h"
#include "feature.h"

namespace CustomCheckSkill {
bool used = false;

int eventID = 0;
int actorID = 0;
int skillID = 0;
int result = 0;
}

Scene_Battle::Scene_Battle(const BattleArgs& args)
: troop_id(args.troop_id),
allow_escape(args.allow_escape),
Expand Down
10 changes: 10 additions & 0 deletions src/scene_battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
#include "window_message.h"
#include "game_battle.h"


namespace CustomCheckSkill {
extern bool used;

extern int eventID;
extern int actorID;
extern int skillID;
extern int result;
}

namespace AutoBattle {
class AlgorithmBase;
}
Expand Down

0 comments on commit 34a0f56

Please sign in to comment.