ChestTrap.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. // instantiates one inner layer to the top layer of chest trap lists
  65. if (parentClass)
  66. InstantiateLists(false);
  67. ListLoaded = false;
  68. }
  69. ~ChestTrapList() {
  70. Clear();
  71. }
  72. int32 Size();
  73. void AddChestTrap(ChestTrap* trap);
  74. ChestTrap::ChestTrapInfo GetChestTrap(int32 id);
  75. ChestTrap::ChestTrapInfo GetNextTrap(int32 zoneid, int32 chest_difficulty);
  76. void Clear();
  77. private:
  78. // randomized maps so we just iterate the map for our next 'random' result
  79. ChestTrap::ChestTrapInfo GetNextChestTrap();
  80. ChestTrapList* GetChestListByDifficulty(int32 difficulty);
  81. ChestTrapList* GetChestListByZone(int32 zoneid);
  82. map<int32, ChestTrap*>* GetAllChestTraps();
  83. bool IsListLoaded();
  84. void SetListLoaded(bool val);
  85. void SetCycleIterator(map<int32, ChestTrap*>::iterator itr);
  86. ChestTrapList* GetChestTrapList(ChestTrapBaseList listName);
  87. void ClearTraps();
  88. void ClearTrapList();
  89. void SetupMutexes();
  90. void InstantiateLists(bool parent);
  91. void shuffleMap(ChestTrapList* list);
  92. bool ChestTrapParent;
  93. bool ListLoaded;
  94. map<int32, ChestTrap*> chesttrap_list;
  95. map<int32, ChestTrapList*> chesttrap_innerlist;
  96. ChestTrapList* difficultyList;
  97. ChestTrapList* zoneList;
  98. map<int32, ChestTrap*>::iterator cycleItr;
  99. Mutex MChestTrapList;
  100. Mutex MChestTrapInnerList;
  101. Mutex MChestListsInUse;
  102. };