Prevent pickup up a fifth tool when unable to drop one (because it's a yellow teleport and you're not on floor)

This commit is contained in:
Eevee (Evelyn Woods) 2020-12-27 08:05:38 -07:00
parent f30b9b34dd
commit 66ca5f5fff

View File

@ -1591,18 +1591,22 @@ export class Level extends LevelInterface {
drop_item(actor, force = false) { drop_item(actor, force = false) {
if (this.stored_level.use_cc1_boots) if (this.stored_level.use_cc1_boots)
return; return false;
if (actor.movement_cooldown > 0) if (actor.movement_cooldown > 0)
return; return false;
if (! actor.toolbelt || actor.toolbelt.length === 0)
return false;
if (actor.cell.get_item() && ! force)
return false;
// Drop the oldest item, i.e. the first one // Drop the oldest item, i.e. the first one
if (actor.toolbelt && actor.toolbelt.length > 0 && (force || ! actor.cell.get_item())) {
let name = actor.toolbelt[0]; let name = actor.toolbelt[0];
if (name === 'teleport_yellow') { if (name === 'teleport_yellow') {
// We can only be dropped on regular floor // We can only be dropped on regular floor
let terrain = actor.cell.get_terrain(); let terrain = actor.cell.get_terrain();
if (terrain.type.name !== 'floor') if (terrain.type.name !== 'floor')
return; return false;
this.transmute_tile(terrain, 'teleport_yellow'); this.transmute_tile(terrain, 'teleport_yellow');
} }
@ -1624,7 +1628,8 @@ export class Level extends LevelInterface {
actor.toolbelt.shift(); actor.toolbelt.shift();
this._push_pending_undo(() => actor.toolbelt.unshift(name)); this._push_pending_undo(() => actor.toolbelt.unshift(name));
}
return true;
} }
_do_wire_phase() { _do_wire_phase() {
@ -2131,13 +2136,18 @@ export class Level extends LevelInterface {
if (! actor.toolbelt) { if (! actor.toolbelt) {
actor.toolbelt = []; actor.toolbelt = [];
} }
// Nothing can hold more than four items, so try to drop one first. Note that this may
// temporarily cause there to be two items in the cell if we're in the middle of picking
// one up, and it means we can't pick up a yellow teleport and swap out another for it
// FIXME two items at once is bad, please fix caller somehow
if (actor.toolbelt.length === 4) {
if (! this.drop_item(actor, true))
return false;
}
actor.toolbelt.push(name); actor.toolbelt.push(name);
this._push_pending_undo(() => actor.toolbelt.pop()); this._push_pending_undo(() => actor.toolbelt.pop());
// Nothing can hold more than four items
if (actor.toolbelt.length > 4) {
this.drop_item(actor, true);
}
} }
return true; return true;
} }