feat: target player bool for action

Added validation logic that checks for target player if needed.
This commit is contained in:
Jorens Shtekels 2024-03-10 20:42:35 +02:00
parent ee12e48a86
commit 9a7bc42db6
3 changed files with 20 additions and 12 deletions

View File

@ -16,9 +16,11 @@ enum VALIDATION_STATUS {
void run() {
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS);
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED);
Role role1({Action::KILL, Action::HEAL});
std::vector<Action> actions = {Action::HEAL};
Role role2(actions);
const Action kill = Action("kill", true);
const Action heal = Action("heal", true);
const Action vote = Action("vote", true);
Role role1({vote, kill, heal});
Role role2({heal});
}
int validateAction(
@ -26,7 +28,9 @@ int validateAction(
if (!actor) {
return NO_PLAYER;
}
// TODO: Check if action has a target
if (action->hasTarget && !target) {
return NO_PLAYER;
}
if (room->status != RoomStatus::IN_PROGRESS) {
return ROOM_NOT_IN_PROGRESS;
}

View File

@ -8,6 +8,11 @@ int add(int a, int b) {
return a + b;
}
Action::Action(std::string name, bool hasTarget) {
this->name = name;
this->hasTarget = hasTarget;
}
Role::Role(std::initializer_list<Action> actions) {
for (auto &a : actions) {
this->actions.push_back(a);

View File

@ -18,14 +18,6 @@ enum EventType {
PLAYER_STATE_CHANGE,
};
enum Action {
KILL,
VOTE,
INVESTIGATE,
HEAL,
PROTECT,
};
enum RoomStatus {
AWAITING_START,
IN_PROGRESS,
@ -45,6 +37,13 @@ struct Player;
struct Room;
struct Event;
struct Action {
std::string name;
bool hasTarget;
Action(std::string name, bool hasTarget);
};
struct Role {
std::vector<Action> actions;