Merge pull request #4 from jorenchik/develop

partial validate action implementation
This commit is contained in:
Jorens Shtekels 2024-03-10 20:22:45 +02:00 committed by GitHub
commit 2b6d7dab47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 10 deletions

View File

@ -1,7 +1,18 @@
#include "lib.hh"
#include "prep/prep.hh"
#include <vector>
enum VALIDATION_STATUS {
NO_PLAYER,
ROOM_NOT_IN_PROGRESS,
ACTION_PROHIBITED,
ACTION_NOT_ALLOWED,
NO_ROLE,
ACTION_VALID,
};
void run() {
Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS);
Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED);
@ -10,19 +21,40 @@ void run() {
Role role2(actions);
}
enum VALIDATION_STATUS {
NO_PLAYER,
ROOM_NOT_IN_PROGRESS,
ACTION_PROHIBITED,
ACTION_NOT_ALLOWED,
ACTION_VALID,
};
int validateAction(
Player *actor, Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr) {
if (!actor) {
return NO_PLAYER;
}
// TODO: Check if action has a target
if (room->status != RoomStatus::IN_PROGRESS) {
return ROOM_NOT_IN_PROGRESS;
}
Role *role = &actor->role;
if (!role) {
return NO_ROLE;
}
if (!actionBelongsToRole(role, action)) {
return ACTION_NOT_ALLOWED;
}
if (!isActionAllowed(relatedEvents)) {
return ACTION_PROHIBITED;
}
return ACTION_VALID;
}
bool actionBelongsToRole(Role *role, Action *action) {
// TODO: implement
bool belongs = false;
return belongs;
}
bool isActionAllowed(std::vector<Event> *relevantEvents) {
// TODO: implement
bool allowed = false;
return allowed;
}
int functionToTest(int a) {
return a * 2;
}

View File

@ -1,6 +1,8 @@
#include "prep/prep.hh"
void run();
int validateAction(
Player *actor, Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr);
bool actionBelongsToRole(Role *role, Action *action);
bool isActionAllowed(std::vector<Event> *relevantEvents);
int validateAction(Player *actor, Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target);
int functionToTest(int);