Advertisement
Nicklaj

Condition Factory

Aug 3rd, 2024
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.99 KB | None | 0 0
  1. // Condition.h
  2. #pragma once
  3.  
  4. #include <string>
  5.  
  6. enum ConditionType {
  7.     QuestStageDone,
  8.     PlayerLevel,
  9.     SkillLevel,
  10.     DungeonCleared,
  11.     ItemInInventory,
  12.     FindMapLocation,
  13.     ItemActivation,
  14.     NotSet
  15. };
  16.  
  17. class Condition : public RE::BSTEventSink<RE::TESQuestStageEvent> {
  18. public:
  19.     ConditionType type;
  20.     virtual ~Condition() {};
  21.     virtual void EnableListener(void);
  22.     virtual void OnDataLoaded(void);
  23.  
  24.     Condition(ConditionType type) : type(type) {};
  25.  
  26. };
  27.  
  28. class ConditionFactory {
  29. public:
  30.     virtual Condition* createCondition() = 0;
  31.     virtual ~ConditionFactory() {};
  32. };
  33.  
  34. class QuestStageDoneCondition : public Condition {
  35. public:
  36.     std::string questId;
  37.     int stage = 200;
  38.  
  39.     void OnDataLoaded(void) override;
  40.     void EnableListener(void) override;
  41.     void SetCondition(std::string questId, int stage);
  42. private:
  43.     RE::BSEventNotifyControl ProcessEvent(const RE::TESQuestStageEvent* a_event, RE::BSTEventSource<RE::TESQuestStageEvent>*) override;
  44. };
  45.  
  46. class QuestStageDoneConditionFactory : public ConditionFactory {
  47. public:
  48.     Condition* createCondition() override;
  49. };
  50.  
  51. // Condition.cpp
  52. #include "Condition.h"
  53. #include "log.h"
  54. #include "CommonFunctions.h"
  55. #include <SKSE/SKSE.h>
  56. #include <RE/Skyrim.h>
  57. #include <functional>
  58.  
  59. extern void RegisterPostLoadFunction(Condition* condition);
  60.  
  61. class Condition : public RE::BSTEventSink<RE::TESQuestStageEvent> {
  62. public:
  63.     void EnableListener() {
  64.         // Provide a default implementation or leave it empty if it's meant to be overridden
  65.     }
  66.  
  67.     void OnDataLoaded() {
  68.         // Provide a default implementation or leave it empty if it's meant to be overridden
  69.     }
  70. };
  71.  
  72. class QuestStageDoneCondition : public Condition {
  73. public:
  74.     std::string questId;
  75.     int stage = 200;
  76.  
  77.     void SetCondition(std::string questId, int stage) {
  78.         this->questId = questId;
  79.         this->stage = stage;
  80.     }
  81.  
  82.     void OnDataLoaded(void){
  83.         std::string questId = this->questId;
  84.         logger::info("{}", questId);
  85.         return;
  86.         // Check that quest hasn't been completed already
  87.         if (CheckQuestStage(this->questId, "Skyrim.esm") >= stage) {
  88.             return;
  89.         }
  90.  
  91.         // Bind sink for quest stage change event
  92.     }
  93.  
  94.     void EnableListener(void)
  95.     {
  96.         RegisterPostLoadFunction(this);
  97.  
  98.         auto* eventSourceHolder = RE::ScriptEventSourceHolder::GetSingleton();
  99.         eventSourceHolder->AddEventSink(this);
  100.     }
  101.  
  102.     RE::BSEventNotifyControl ProcessEvent(const RE::TESQuestStageEvent* event, RE::BSTEventSource<RE::TESQuestStageEvent>*) override {
  103.         const auto quest = RE::TESForm::LookupByEditorID<RE::TESQuest>(this->questId);
  104.         if (event->formID == quest->formID) {
  105.             logger::debug("si");
  106.         }
  107.         logger::debug("Ciaone.");
  108.  
  109.         return RE::BSEventNotifyControl::kContinue;
  110.     }
  111. };
  112.  
  113. class QuestStageDoneConditionFactory : ConditionFactory {
  114. public:
  115.     Condition* createCondition() override {
  116.         return new QuestStageDoneCondition();
  117.     };
  118. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement