From 7ea8b2014598266248cd838817ead0f28c836ed7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 16 Mar 2023 10:41:19 +0800 Subject: [PATCH] 1 --- server/gameserver/mt/MapThing.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/gameserver/mt/MapThing.cc b/server/gameserver/mt/MapThing.cc index 68171b95..02833dcb 100644 --- a/server/gameserver/mt/MapThing.cc +++ b/server/gameserver/mt/MapThing.cc @@ -39,7 +39,7 @@ namespace mt std::vector strings2; a8::Split(str, strings2, ':'); int drop_id = a8::XValue(strings2[0]); - int weight = strings2.size() > 1 ? a8::XValue(strings2[1]).GetInt() : 10000; + int weight = strings2.size() > 1 ? a8::XValue(strings2[1]).GetInt() : -1; total_weight += weight; _drop.push_back (std::make_tuple( @@ -48,6 +48,7 @@ namespace mt ) ); } + total_weight = std::max(total_weight, 1); } { std::vector strings; @@ -122,20 +123,21 @@ namespace mt std::vector MapThing::RandDrop() const { + std::vector drops; if (HasDrop()) { int total_weight = std::get<1>(_drop[_drop.size() - 1]); int rnd = rand() % total_weight; for (auto& tuple : _drop) { - if (rnd < std::get<1>(tuple)) { -#if 0 - return std::get<0>(tuple); -#endif + if (std::get<1>(tuple) < 0){ + drops.push_back(std::get<0>(tuple)); + } else { + if (rnd < std::get<1>(tuple)) { + drops.push_back(std::get<0>(tuple)); + } } } } -#if 0 - return 0; -#endif + return drops; } }