fixed player not picking up dragon hoard when standing on top of it and killing the dragon
This commit is contained in:
@ -101,6 +101,30 @@ long_result player_base::move(level *lvl,
|
||||
return {result::NOTHING, "PC tried to move into non-existent space. "};
|
||||
}
|
||||
|
||||
void player_base::pickup_gold(level *lvl, std::string &msg) {
|
||||
gold g{{0, 0}, 0};
|
||||
int gold_tmp = 0;
|
||||
|
||||
while ((g = get_gold_at(pos, lvl->get_glist())).get_amount() != 0)
|
||||
gold_tmp += g.get_amount();
|
||||
|
||||
if (gold_tmp)
|
||||
msg += "PC picked up " + std::to_string(gold_tmp) +
|
||||
" pieces of gold. ";
|
||||
|
||||
bool locked = false;
|
||||
|
||||
for (auto g : lvl->get_glist())
|
||||
if (g.is_locked() && g.get_pos() == pos)
|
||||
locked = true;
|
||||
|
||||
if (locked)
|
||||
msg += "There's a pile of gold here that PC cannot pick up. ";
|
||||
|
||||
gold_cnt += gold_tmp;
|
||||
|
||||
}
|
||||
|
||||
long_result player_base::get_hit(character *ch, const int tATK,
|
||||
const fraction &hit_rate) {
|
||||
if (rng->trial(hit_rate)) {
|
||||
@ -190,27 +214,7 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) {
|
||||
} else if (cmd >= MOVE_NORTH && cmd <= MOVE_SOUTHWEST) {
|
||||
auto res = move(lvl, pos + MOVE[cmd - MOVE_NORTH]);
|
||||
|
||||
gold g{{0, 0}, 0};
|
||||
int gold_tmp = 0;
|
||||
|
||||
while ((g = get_gold_at(pos, lvl->get_glist())).get_amount() != 0)
|
||||
gold_tmp += g.get_amount();
|
||||
|
||||
if (gold_tmp)
|
||||
res.msg += "PC picked up " + std::to_string(gold_tmp) +
|
||||
" pieces of gold. ";
|
||||
|
||||
bool locked = false;
|
||||
|
||||
for (auto g : lvl->get_glist())
|
||||
if (g.is_locked() && g.get_pos() == pos)
|
||||
locked = true;
|
||||
|
||||
if (locked)
|
||||
res.msg += "There's a pile of gold here that PC cannot pick up. ";
|
||||
|
||||
gold_cnt += gold_tmp;
|
||||
|
||||
pickup_gold(lvl, res.msg);
|
||||
|
||||
if (enabled_features & FEATURE_INVENTORY) {
|
||||
size_t idx = get_potion_at(pos, lvl->get_plist());
|
||||
@ -252,6 +256,8 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) {
|
||||
gold_cnt += g;
|
||||
}
|
||||
|
||||
pickup_gold(lvl, res.msg);
|
||||
|
||||
return res;
|
||||
} else if (cmd == UP_STAIRS) {
|
||||
if (lvl->get_up_stairs() == pos &&
|
||||
|
@ -15,6 +15,8 @@ class player_base: public character {
|
||||
static const int INV_CURSOR_OFFSET = 2;
|
||||
static const int INV_POTION_OFFSET = 5;
|
||||
static const int INV_MAX_CNT = 10;
|
||||
|
||||
void pickup_gold(level *lvl, std::string &msg);
|
||||
protected:
|
||||
int gold_cnt;
|
||||
|
||||
|
Reference in New Issue
Block a user