Skip to content

Commit

Permalink
Merge pull request #3 from mksudo/fix-auto-uncomplete-point-if-regene…
Browse files Browse the repository at this point in the history
…rates

add functionalities to automatically discard completed points
  • Loading branch information
360NENZ authored Dec 17, 2022
2 parents d826673 + 55b9c54 commit 153b37b
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 1 deletion.
26 changes: 26 additions & 0 deletions cheat-library/res/map_enkanomiya.json
Original file line number Diff line number Diff line change
Expand Up @@ -9151,5 +9151,31 @@
424
]
}
],
"regenerates": [
{
"hours": 12,
"categories": [ "Animals", "Materials", "Enemies (Common)" ],
"exclude": [ "61", "62", "63" ],
"include": []
},
{
"hours": 24,
"categories": [ "Enemies (Elite)", "Investigation" ],
"exclude": [],
"include": [ "172" ]
},
{
"hours": 48,
"categories": [ "Local Specialties" ],
"exclude": [],
"include": [ "61", "62", "63", "15", "139" ]
},
{
"hours": 72,
"categories": [ "Fishing" ],
"exclude": [],
"include": [ "16", "80", "202" ]
}
]
}
26 changes: 26 additions & 0 deletions cheat-library/res/map_golden_apple_archipelago.json
Original file line number Diff line number Diff line change
Expand Up @@ -2047,5 +2047,31 @@
351
]
}
],
"regenerates": [
{
"hours": 12,
"categories": [ "Animals", "Materials", "Enemies (Common)" ],
"exclude": [ "61", "62", "63" ],
"include": []
},
{
"hours": 24,
"categories": [ "Enemies (Elite)", "Investigation" ],
"exclude": [],
"include": [ "172" ]
},
{
"hours": 48,
"categories": [ "Local Specialties" ],
"exclude": [],
"include": [ "61", "62", "63", "15", "139" ]
},
{
"hours": 72,
"categories": [ "Fishing" ],
"exclude": [],
"include": [ "16", "80", "202" ]
}
]
}
26 changes: 26 additions & 0 deletions cheat-library/res/map_teyvat.json
Original file line number Diff line number Diff line change
Expand Up @@ -135764,5 +135764,31 @@
424
]
}
],
"regenerates": [
{
"hours": 12,
"categories": [ "Animals", "Materials", "Enemies (Common)" ],
"exclude": [ "61", "62", "63" ],
"include": []
},
{
"hours": 24,
"categories": [ "Enemies (Elite)", "Investigation" ],
"exclude": [],
"include": [ "172" ]
},
{
"hours": 48,
"categories": [ "Local Specialties" ],
"exclude": [],
"include": [ "61", "62", "63", "15", "139" ]
},
{
"hours": 72,
"categories": [ "Fishing" ],
"exclude": [],
"include": [ "16", "80", "202" ]
}
]
}
26 changes: 26 additions & 0 deletions cheat-library/res/map_undeground_mines.json
Original file line number Diff line number Diff line change
Expand Up @@ -5896,5 +5896,31 @@
424
]
}
],
"regenerates": [
{
"hours": 12,
"categories": [ "Animals", "Materials", "Enemies (Common)" ],
"exclude": [ "61", "62", "63" ],
"include": []
},
{
"hours": 24,
"categories": [ "Enemies (Elite)", "Investigation" ],
"exclude": [],
"include": [ "172" ]
},
{
"hours": 48,
"categories": [ "Local Specialties" ],
"exclude": [],
"include": [ "61", "62", "63", "15", "139" ]
},
{
"hours": 72,
"categories": [ "Fishing" ],
"exclude": [],
"include": [ "16", "80", "202" ]
}
]
}
61 changes: 60 additions & 1 deletion cheat-library/src/user/cheat/imap/InteractiveMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,23 @@ namespace cheat::feature
return;
}

auto complete_timestamp = data["complete_timestamp"].get<int64_t>();

auto current_timestamp = util::GetCurrentTimeMillisec();

auto& scene = m_ScenesData[labelData->sceneID];
if (scene.regenerateTime.count(labelData->id) > 0)
{
auto regenerateTime = scene.regenerateTime[labelData->id];

// do not load complete point if resource is regenerated
if (complete_timestamp + regenerateTime <= current_timestamp) {
return;
}
}

point.completed = true;
point.completeTimestamp = data["complete_timestamp"];
point.completeTimestamp = complete_timestamp;
labelData->completedCount++;

m_CompletedPoints.push_back(&point);
Expand Down Expand Up @@ -1366,6 +1381,48 @@ namespace cheat::feature
newCategory.name = data["name"];
}

void InteractiveMap::LoadRegenrateTimeData(const nlohmann::json& data, uint32_t sceneID)
{
auto& sceneData = m_ScenesData[sceneID];
auto& labels = sceneData.labels;
auto& categories = sceneData.categories;

auto& regenerateTime = sceneData.regenerateTime;

for (auto& regenerateData : data) {
int64_t regenerateTimeInMS = regenerateData["hours"] * 60 * 60 * 1000;

auto& regenerateCatogories = regenerateData["categories"];
auto& regenerateInclude = regenerateData["include"];
auto& regenerateExclude = regenerateData["exclude"];

for (auto& regenerateCategory : regenerateCatogories)
{
for (auto& category : categories)
{
if (category.name != regenerateCategory.get<std::string>())
continue;

auto& categoryChildren = category.children;

for (auto& childLable : categoryChildren)
{
if (!regenerateExclude.contains(std::to_string(childLable->id)))
{
regenerateTime[childLable->id] = regenerateTimeInMS;
}
}

break;
}
}

for (auto& includeLabelID : regenerateInclude) {
regenerateTime[std::stoi(includeLabelID.get<std::string>())] = regenerateTimeInMS;
}
}
}

void InteractiveMap::LoadSceneData(const nlohmann::json& data, uint32_t sceneID)
{
for (auto& [labelID, labelData] : data["labels"].items())
Expand All @@ -1377,6 +1434,8 @@ namespace cheat::feature
{
LoadCategoriaData(categorie, sceneID);
}

LoadRegenrateTimeData(data["regenerates"], sceneID);
}

void InteractiveMap::LoadScenesData()
Expand Down
2 changes: 2 additions & 0 deletions cheat-library/src/user/cheat/imap/InteractiveMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace cheat::feature
std::map<uint32_t, LabelData> labels;
std::map<std::string, LabelData*> nameToLabel;
std::vector<CategoryData> categories;
std::map<uint32_t, int64_t> regenerateTime;
};

struct MaterialData
Expand Down Expand Up @@ -183,6 +184,7 @@ namespace cheat::feature
void LoadLabelData(const nlohmann::json& data, uint32_t sceneID, uint32_t labelID);
void LoadCategoriaData(const nlohmann::json& data, uint32_t sceneID);
void LoadSceneData(const nlohmann::json& data, uint32_t sceneID);
void LoadRegenrateTimeData(const nlohmann::json& data, uint32_t sceneID);
void LoadScenesData();

// Parsing ascension materials data
Expand Down

0 comments on commit 153b37b

Please sign in to comment.