From b97aaa81a957c57497ff61e585d8f4176c501e57 Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Thu, 3 Dec 2020 20:52:43 -0700 Subject: [PATCH] Slime doesn't kill blobs; implement bribe; fix player size on level restart --- js/game.js | 28 ++++++++++++++++++++++------ js/tiletypes.js | 22 +++++++++++++++++----- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/js/game.js b/js/game.js index 45a37f5..cd86460 100644 --- a/js/game.js +++ b/js/game.js @@ -223,10 +223,6 @@ const UNDO_BUFFER_SIZE = TICS_PER_SECOND * 30; export class Level { constructor(stored_level, compat = {}) { this.stored_level = stored_level; - this.width = stored_level.size_x; - this.height = stored_level.size_y; - this.size_x = stored_level.size_x; - this.size_y = stored_level.size_y; this.restart(compat); } @@ -240,6 +236,11 @@ export class Level { // event loop! this.state = 'playing'; + this.width = this.stored_level.size_x; + this.height = this.stored_level.size_y; + this.size_x = this.stored_level.size_x; + this.size_y = this.stored_level.size_y; + this.cells = []; this.player = null; this.actors = []; @@ -1749,19 +1750,34 @@ export class Level { return false; } + take_tool_from_actor(actor, name) { + if (actor.toolbelt) { + let index = actor.toolbelt.indexOf(name); + if (index >= 0) { + actor.toolbelt.splice(index, 1); + this.pending_undo.push(() => actor.toolbelt.splice(index, 0, name)); + return true; + } + } + + return false; + } + take_all_keys_from_actor(actor) { - if (actor.keyring) { + if (actor.keyring && Object.values(actor.keyring).some(n => n > 0)) { let keyring = actor.keyring; this.pending_undo.push(() => actor.keyring = keyring); actor.keyring = {}; + return true; } } take_all_tools_from_actor(actor) { - if (actor.toolbelt) { + if (actor.toolbelt && actor.toolbelt.length > 0) { let toolbelt = actor.toolbelt; this.pending_undo.push(() => actor.toolbelt = toolbelt); actor.toolbelt = []; + return true; } } diff --git a/js/tiletypes.js b/js/tiletypes.js index 0a72d3d..fbf441b 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -695,7 +695,7 @@ const TILE_TYPES = { if (other.type.name === 'dirt_block' || other.type.name === 'ice_block') { level.transmute_tile(me, 'floor'); } - else if (other.type.name === 'ghost') { + else if (other.type.name === 'ghost' || other.type.name === 'blob') { // No effect } else if (other.type.is_player) { @@ -725,8 +725,14 @@ const TILE_TYPES = { draw_layer: DRAW_LAYERS.terrain, blocks_collision: COLLISION.block_cc1 | COLLISION.monster_solid, on_arrive(me, level, other) { - level.sfx.play_once('thief', me.cell); - level.take_all_tools_from_actor(other); + if (level.take_tool_from_actor(other, 'bribe')) { + // TODO bribe sound + return; + } + + if (level.take_all_tools_from_actor(other) && other === level.player) { + level.sfx.play_once('thief', me.cell); + } if (other.type.is_player) { level.adjust_bonus(0, 0.5); } @@ -736,8 +742,14 @@ const TILE_TYPES = { draw_layer: DRAW_LAYERS.terrain, blocks_collision: COLLISION.block_cc1 | COLLISION.monster_solid, on_arrive(me, level, other) { - level.sfx.play_once('thief', me.cell); - level.take_all_keys_from_actor(other); + if (level.take_tool_from_actor(other, 'bribe')) { + // TODO bribe sound + return; + } + + if (level.take_all_keys_from_actor(other) && other === level.player) { + level.sfx.play_once('thief', me.cell); + } if (other.type.is_player) { level.adjust_bonus(0, 0.5); }