Skip to content

Commit a2b3f47

Browse files
Added support for find item.
1 parent 460288d commit a2b3f47

1 file changed

Lines changed: 43 additions & 14 deletions

File tree

dropsim.cpp

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ namespace std {
102102

103103
std::unordered_map<std::string, AtomicTC> atomic;
104104
std::unordered_map<std::string, TC> treasureClasses;
105-
int playermod = 1;
105+
106+
long playermod = 1;
107+
int finditem = 0;
108+
106109
std::random_device rd;
107110
std::mt19937 gen(rd());
108111

@@ -161,6 +164,10 @@ void pickAtomic(std::string tcname, int magic, int rare, int set, int unique, st
161164
}
162165

163166
long calcNodrop(long e, long nd, long d) {
167+
if (e < 1) {
168+
return 0;
169+
}
170+
164171
double _e = (double)e, _nd = (double)nd, _d = (double)d;
165172
if (nd < 1) {
166173
return 0;
@@ -173,7 +180,7 @@ long calcNodrop(long e, long nd, long d) {
173180
return (long)(_d / (pow((_nd + _d) / nd, _e) - 1));
174181
}
175182

176-
void pick(std::string tcname, int magic, int rare, int set, int unique, std::vector<Drop>& drops) {
183+
void pick(std::string tcname, int magic, int rare, int set, int unique, std::vector<Drop>& drops, int depth = 0) {
177184
if (drops.size() >= 6) {
178185
return;
179186
}
@@ -206,8 +213,27 @@ void pick(std::string tcname, int magic, int rare, int set, int unique, std::vec
206213
return;
207214
}
208215

216+
long nodrop = tc.nodrop;
217+
218+
if (depth == 0 && finditem > 0) {
219+
std::uniform_int_distribution<long> dis(0, 100);
220+
long finditemnum = dis(gen);
221+
222+
if (finditemnum >= finditem) {
223+
#ifdef DEBUG
224+
std::cout << "Find item failed" << std::endl;
225+
wait();
226+
#endif
227+
return;
228+
}
229+
230+
nodrop = 0;
231+
}
232+
else {
233+
nodrop = calcNodrop(playermod, nodrop, tc.total);
234+
}
235+
209236
int picks = tc.picks > 0 ? tc.picks : -tc.picks;
210-
long nodrop = calcNodrop(playermod, tc.nodrop, tc.total);
211237

212238
#ifdef DEBUG
213239
std::cout << tc.name << " with " << picks << " " << (tc.picks > 0 ? "random" : "sequential") << " picks " << std::endl;
@@ -243,7 +269,7 @@ void pick(std::string tcname, int magic, int rare, int set, int unique, std::vec
243269
std::cout << item.name << " picked" << std::endl;
244270
wait();
245271
#endif
246-
pick(item.name, magic, rare, set, unique, drops);
272+
pick(item.name, magic, rare, set, unique, drops, depth + 1);
247273
break;
248274
}
249275

@@ -267,7 +293,7 @@ void pick(std::string tcname, int magic, int rare, int set, int unique, std::vec
267293
std::cout << tc.name << " picked" << std::endl;
268294
wait();
269295
#endif
270-
pick(item.name, magic, rare, set, unique, drops);
296+
pick(item.name, magic, rare, set, unique, drops, depth + 1);
271297
picks--;
272298
}
273299
}
@@ -357,7 +383,7 @@ std::string trim(const std::string& str) {
357383
// Main takes first parameter as treasure class name
358384
int main(int argc, char* argv[]) {
359385
if (argc < 2) {
360-
std::cout << "Usage: " << argv[0] << " <treasure_class_name> <player_mod> <drop_cycles>\n";
386+
std::cout << "Usage: " << argv[0] << " <treasure_class_name> <player_mod> <find_item_percent>\n";
361387
return 1;
362388
}
363389

@@ -374,23 +400,26 @@ int main(int argc, char* argv[]) {
374400
std::string simulationsPath = realpath(path + "simulations") + DIRECTORY_SEPARATOR_STRING;
375401

376402
std::string tcname = argv[1];
377-
int dropcycles = 300000;
378403

379404
if (argc >= 3) {
380405
playermod = atoi(argv[2]);
381406
}
382407

383-
playermod = std::max(1, playermod);
384-
playermod = std::min(8, playermod);
408+
playermod = std::max(0L, playermod);
409+
playermod = std::min(8L, playermod);
385410

386-
if (argc >= 4) {
387-
dropcycles = atoi(argv[3]);
411+
if (playermod) {
412+
std::cout << tcname << " [" << playermod << "]" << std::endl;
413+
}
414+
else {
415+
std::cout << tcname << " [No NoDrop]" << std::endl;
388416
}
389417

390-
dropcycles = std::max(1, dropcycles);
391-
dropcycles = std::min(20000000, dropcycles);
418+
if (argc >= 4) {
419+
finditem = atoi(argv[3]);
420+
}
392421

393-
std::cout << tcname << " [" << playermod << "]" << std::endl;
422+
int dropcycles = 300000;
394423

395424
// Open the treasure class file at: txt/treasureclassex.txt
396425
FILE* tex = fopen((txtDir + (BASETC ? "base/treasureclassex.txt" : "treasureclassex.txt")).c_str(), "r");

0 commit comments

Comments
 (0)