DarkflameServer/dGame/dUtilities/Preconditions.h

82 lines
1.3 KiB
C
Raw Normal View History

#pragma once
#include <vector>
#include "Entity.h"
enum class PreconditionType
{
2022-07-28 13:39:57 +00:00
ItemEquipped,
ItemNotEquipped,
HasItem,
DoesNotHaveItem,
HasAchievement,
MissionAvailable,
OnMission,
MissionComplete,
PetDeployed,
HasFlag,
WithinShape,
InBuild,
TeamCheck,
IsPetTaming,
HasFaction,
DoesNotHaveFaction,
HasRacingLicence,
DoesNotHaveRacingLicence,
LegoClubMember,
NoInteraction,
HasLevel = 22
};
class Precondition final
{
public:
2022-07-28 13:39:57 +00:00
explicit Precondition(uint32_t condition);
bool Check(Entity* player, bool evaluateCosts = false) const;
private:
2022-07-28 13:39:57 +00:00
bool CheckValue(Entity* player, uint32_t value, bool evaluateCosts = false) const;
PreconditionType type;
2022-07-28 13:39:57 +00:00
std::vector<uint32_t> values;
2022-07-28 13:39:57 +00:00
uint32_t count;
};
class PreconditionExpression final
{
public:
2022-07-28 13:39:57 +00:00
explicit PreconditionExpression(const std::string& conditions);
bool Check(Entity* player, bool evaluateCosts = false) const;
~PreconditionExpression();
private:
2022-07-28 13:39:57 +00:00
uint32_t condition = 0;
2022-07-28 13:39:57 +00:00
bool m_or = false;
2022-07-28 13:39:57 +00:00
bool empty = false;
2022-07-28 13:39:57 +00:00
PreconditionExpression* next = nullptr;
};
class Preconditions final
{
public:
2022-07-28 13:39:57 +00:00
static bool Check(Entity* player, uint32_t condition, bool evaluateCosts = false);
2022-07-28 13:39:57 +00:00
static PreconditionExpression CreateExpression(const std::string& conditions);
~Preconditions();
2022-07-28 13:39:57 +00:00
private:
2022-07-28 13:39:57 +00:00
static std::map<uint32_t, Precondition*> cache;
};