ChestTrap.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <string>
  2. #include <map>
  3. #include <list>
  4. #include "../../common/Mutex.h"
  5. #include "../../common/types.h"
  6. #pragma once
  7. using namespace std;
  8. enum ChestTrapBaseList {
  9. DIFFICULTY = 0,
  10. ZONE = 1
  11. };
  12. class ChestTrap {
  13. public:
  14. struct ChestTrapInfo {
  15. int32 id;
  16. int32 applicable_zone_id;
  17. int32 min_chest_difficulty;
  18. int32 max_chest_difficulty;
  19. int32 spell_id;
  20. int32 spell_tier;
  21. };
  22. //Constructors **must** always set all ChestTrapInfo as we don't memset so a data value will be wack if not set!
  23. ChestTrap(int32 dbid, sint32 zoneid, int32 mindifficulty, int32 maxdifficulty, int32 spellid, int32 tier)
  24. {
  25. s_ChestTrapInfo.id = dbid;
  26. s_ChestTrapInfo.applicable_zone_id = zoneid;
  27. s_ChestTrapInfo.min_chest_difficulty = mindifficulty;
  28. s_ChestTrapInfo.max_chest_difficulty = maxdifficulty;
  29. s_ChestTrapInfo.spell_id = spellid;
  30. s_ChestTrapInfo.spell_tier = tier;
  31. }
  32. ChestTrap(ChestTrap* parent)
  33. {
  34. s_ChestTrapInfo.id = parent->GetDBID();
  35. s_ChestTrapInfo.applicable_zone_id = parent->GetApplicableZoneID();
  36. s_ChestTrapInfo.min_chest_difficulty = parent->GetMinChestDifficulty();
  37. s_ChestTrapInfo.max_chest_difficulty = parent->GetMaxChestDifficulty();
  38. s_ChestTrapInfo.spell_id = parent->GetSpellID();
  39. s_ChestTrapInfo.spell_tier = parent->GetSpellTier();
  40. }
  41. int32 GetDBID() { return s_ChestTrapInfo.id; }
  42. sint32 GetApplicableZoneID() { return s_ChestTrapInfo.applicable_zone_id; }
  43. int32 GetMinChestDifficulty() { return s_ChestTrapInfo.min_chest_difficulty; }
  44. int32 GetMaxChestDifficulty() { return s_ChestTrapInfo.max_chest_difficulty; }
  45. int32 GetSpellID() { return s_ChestTrapInfo.spell_id; }
  46. int32 GetSpellTier() { return s_ChestTrapInfo.spell_tier; }
  47. ChestTrapInfo* GetChestTrapInfo() { return &s_ChestTrapInfo; }
  48. private:
  49. ChestTrapInfo s_ChestTrapInfo;
  50. };
  51. class ChestTrapList {
  52. public:
  53. ChestTrapList() {
  54. SetupMutexes();
  55. ChestTrapParent = true;
  56. // instantiate the parent lists for zone/difficulty/etc, later on we will do the inverse of each map, zone->difficulty and difficulty->zone
  57. InstantiateLists(true);
  58. ListLoaded = true;
  59. }
  60. // not to be called externally from ChestTrapList/ChestTrap
  61. ChestTrapList(bool parentClass) {
  62. SetupMutexes();
  63. ChestTrapParent = parentClass;
  64. ListLoaded = false;
  65. }
  66. ~ChestTrapList() {
  67. Clear();
  68. }
  69. int32 Size();
  70. void AddChestTrap(ChestTrap* trap);
  71. bool GetChestTrap(int32 id, ChestTrap::ChestTrapInfo* cti);
  72. bool GetNextTrap(int32 zoneid, int32 chest_difficulty, ChestTrap::ChestTrapInfo* cti);
  73. void Clear();
  74. private:
  75. // randomized maps so we just iterate the map for our next 'random' result
  76. bool GetNextChestTrap(ChestTrap::ChestTrapInfo* cti);
  77. ChestTrapList* GetChestListByDifficulty(int32 difficulty);
  78. ChestTrapList* GetChestListByZone(int32 zoneid);
  79. map<int32, ChestTrap*>* GetAllChestTraps();
  80. bool IsListLoaded();
  81. void SetListLoaded(bool val);
  82. void AddChestTrapList(ChestTrapList* trap, int32 id);
  83. void SetCycleIterator(map<int32, ChestTrap*>::iterator itr);
  84. ChestTrapList* GetChestTrapList(ChestTrapBaseList listName);
  85. ChestTrapList* GetChestTrapListByID(int32 id);
  86. void ClearTraps();
  87. void ClearTrapList();
  88. void SetupMutexes();
  89. void InstantiateLists(bool parent);
  90. void shuffleMap(ChestTrapList* list);
  91. bool ChestTrapParent;
  92. bool ListLoaded;
  93. map<int32, ChestTrap*> chesttrap_list;
  94. map<int32, ChestTrapList*> chesttrap_innerlist;
  95. ChestTrapList* difficultyList;
  96. ChestTrapList* zoneList;
  97. map<int32, ChestTrap*>::iterator cycleItr;
  98. Mutex MChestTrapList;
  99. Mutex MChestTrapInnerList;
  100. Mutex MChestListsInUse;
  101. };