Fix a crash when trying to drop from an empty inventory

This commit is contained in:
Eevee (Evelyn Woods) 2020-12-03 22:21:44 -07:00
parent 564d247657
commit caf4906176

View File

@ -1209,7 +1209,7 @@ export class Level {
return;
// Cycle leftwards, i.e., the oldest item moves to the end of the list
if (actor.toolbelt) {
if (actor.toolbelt && actor.toolbelt.length > 1) {
actor.toolbelt.push(actor.toolbelt.shift());
this.pending_undo.push(() => actor.toolbelt.unshift(actor.toolbelt.pop()));
}
@ -1222,7 +1222,7 @@ export class Level {
return;
// Drop the oldest item, i.e. the first one
if (actor.toolbelt && (force || ! actor.cell.get_item())) {
if (actor.toolbelt && actor.toolbelt.length > 0 && (force || ! actor.cell.get_item())) {
let name = actor.toolbelt[0];
if (name === 'teleport_yellow') {
// We can only be dropped on regular floor