add event conditions in quest visibility

This commit is contained in:
Martin Michelsen
2024-01-30 20:57:09 -08:00
parent 7aa05f39e2
commit 340fbb8ca5
9 changed files with 47 additions and 9 deletions
+4 -2
View File
@@ -334,7 +334,7 @@ shared_ptr<const TeamIndex::Team> Client::team() const {
return team;
}
bool Client::can_see_quest(shared_ptr<const Quest> q, uint8_t difficulty, size_t num_players) const {
bool Client::can_see_quest(shared_ptr<const Quest> q, uint8_t event, uint8_t difficulty, size_t num_players) const {
if (this->license && (this->license->flags & License::Flag::DISABLE_QUEST_REQUIREMENTS)) {
return true;
}
@@ -348,13 +348,14 @@ bool Client::can_see_quest(shared_ptr<const Quest> q, uint8_t difficulty, size_t
.challenge_records = &p->challenge_records,
.team = this->team(),
.num_players = num_players,
.event = event,
};
int64_t ret = q->available_expression->evaluate(env);
this->log.info("Evaluated quest availability expression %s => %s", expr.c_str(), ret ? "TRUE" : "FALSE");
return ret;
}
bool Client::can_play_quest(shared_ptr<const Quest> q, uint8_t difficulty, size_t num_players) const {
bool Client::can_play_quest(shared_ptr<const Quest> q, uint8_t event, uint8_t difficulty, size_t num_players) const {
if (this->license && (this->license->flags & License::Flag::DISABLE_QUEST_REQUIREMENTS)) {
return true;
}
@@ -368,6 +369,7 @@ bool Client::can_play_quest(shared_ptr<const Quest> q, uint8_t difficulty, size_
.challenge_records = &p->challenge_records,
.team = this->team(),
.num_players = num_players,
.event = event,
};
bool ret = q->enabled_expression->evaluate(env);
this->log.info("Evaluating quest enabled expression %s => %s", expr.c_str(), ret ? "TRUE" : "FALSE");
+2 -2
View File
@@ -282,8 +282,8 @@ public:
std::shared_ptr<const TeamIndex::Team> team() const;
bool can_see_quest(std::shared_ptr<const Quest> q, uint8_t difficulty, size_t num_players) const;
bool can_play_quest(std::shared_ptr<const Quest> q, uint8_t difficulty, size_t num_players) const;
bool can_see_quest(std::shared_ptr<const Quest> q, uint8_t event, uint8_t difficulty, size_t num_players) const;
bool can_play_quest(std::shared_ptr<const Quest> q, uint8_t event, uint8_t difficulty, size_t num_players) const;
static void dispatch_save_game_data(evutil_socket_t, short, void* ctx);
void save_game_data();
+4 -4
View File
@@ -729,8 +729,8 @@ Lobby::JoinError Lobby::join_error_for_client(std::shared_ptr<Client> c, const s
}
if (this->quest) {
size_t num_clients = this->count_clients() + 1;
if (!c->can_see_quest(this->quest, this->difficulty, num_clients) ||
!c->can_play_quest(this->quest, this->difficulty, num_clients)) {
if (!c->can_see_quest(this->quest, this->event, this->difficulty, num_clients) ||
!c->can_play_quest(this->quest, this->event, this->difficulty, num_clients)) {
return JoinError::NO_ACCESS_TO_QUEST;
}
}
@@ -855,10 +855,10 @@ QuestIndex::IncludeCondition Lobby::quest_include_condition() const {
return [this, num_players](shared_ptr<const Quest> q) -> QuestIndex::IncludeState {
bool is_enabled = true;
for (const auto& lc : this->clients) {
if (lc && !lc->can_see_quest(q, this->difficulty, num_players)) {
if (lc && !lc->can_see_quest(q, this->event, this->difficulty, num_players)) {
return QuestIndex::IncludeState::HIDDEN;
}
if (lc && !lc->can_play_quest(q, this->difficulty, num_players)) {
if (lc && !lc->can_play_quest(q, this->event, this->difficulty, num_players)) {
is_enabled = false;
}
}
+17
View File
@@ -245,6 +245,20 @@ string QuestAvailabilityExpression::NumPlayersLookupNode::str() const {
return "V_NumPlayers";
}
QuestAvailabilityExpression::EventLookupNode::EventLookupNode() {}
bool QuestAvailabilityExpression::EventLookupNode::operator==(const Node& other) const {
return dynamic_cast<const EventLookupNode*>(&other) != nullptr;
}
int64_t QuestAvailabilityExpression::EventLookupNode::evaluate(const Env& env) const {
return env.num_players;
}
string QuestAvailabilityExpression::EventLookupNode::str() const {
return "V_Event";
}
QuestAvailabilityExpression::ConstantNode::ConstantNode(bool value)
: value(value) {}
@@ -395,6 +409,9 @@ unique_ptr<const QuestAvailabilityExpression::Node> QuestAvailabilityExpression:
if (text == "V_NumPlayers") {
return make_unique<NumPlayersLookupNode>();
}
if (text == "V_Event") {
return make_unique<EventLookupNode>();
}
// Check for constants
if (text == "true") {
+10
View File
@@ -20,6 +20,7 @@ public:
const PlayerRecordsBB_Challenge* challenge_records;
std::shared_ptr<const TeamIndex::Team> team;
size_t num_players;
uint8_t event;
};
QuestAvailabilityExpression(const std::string& text);
@@ -150,6 +151,15 @@ protected:
virtual std::string str() const;
};
class EventLookupNode : public Node {
public:
EventLookupNode();
virtual ~EventLookupNode() = default;
virtual bool operator==(const Node& other) const;
virtual int64_t evaluate(const Env& env) const;
virtual std::string str() const;
};
class ConstantNode : public Node {
public:
ConstantNode(bool value);
+3
View File
@@ -0,0 +1,3 @@
{
"AvailableIf": "V_Event == 3",
}
+3
View File
@@ -0,0 +1,3 @@
{
"AvailableIf": "V_Event == 9",
}
+3
View File
@@ -0,0 +1,3 @@
{
"AvailableIf": "V_Event == 5",
}
+1 -1
View File
@@ -1,3 +1,3 @@
{
"AvailableIf": "V_NumPlayers == 1",
"AvailableIf": "V_NumPlayers == 1 && V_Event == 1",
}