From 1f6c86c146f0748d5399beb3e5056b819244e0a1 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Sun, 14 Feb 2021 14:22:28 +1100 Subject: [PATCH] Implement Electrified Floor Conducts power (like a blue teleporter). While powered, destroys anything not wearing lightning boots (except dirt blocks). --- js/format-c2g.js | 4 ++++ js/main-editor.js | 5 +++++ js/main.js | 6 ++++++ js/tileset.js | 5 +++++ js/tiletypes.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/js/format-c2g.js b/js/format-c2g.js index df22a14..a321486 100644 --- a/js/format-c2g.js +++ b/js/format-c2g.js @@ -787,6 +787,10 @@ const TILE_ENCODING = { }, // LL-specific tiles + 0xd0: { + name: 'electrified_floor', + is_extension: true, + }, 0xe0: { name: 'gift_bow', has_next: true, diff --git a/js/main-editor.js b/js/main-editor.js index 0ebc377..0ca6d33 100644 --- a/js/main-editor.js +++ b/js/main-editor.js @@ -1604,6 +1604,7 @@ const EDITOR_PALETTE = [{ 'fire_sticks', 'turntable_cw', 'turntable_ccw', + 'electrified_floor', ], }]; @@ -2202,6 +2203,10 @@ const EDITOR_TILE_DESCRIPTIONS = { name: "Turntable (Counterclockwise)", desc: "Rotates anything entering this tile counterclockwise. Frame blocks are rotated too. If connected to wire, only functions while receiving power.", }, + electrified_floor: { + name: "Electrified Floor", + desc: "Conducts power (like a blue teleporter). While powered, destroys anything not wearing lightning boots (except dirt blocks).", + }, }; const SPECIAL_PALETTE_ENTRIES = { diff --git a/js/main.js b/js/main.js index 1d978a5..482be0f 100644 --- a/js/main.js +++ b/js/main.js @@ -91,6 +91,12 @@ const OBITUARIES = { "no place to be", "on a trip to nowhere", ], + electrocuted: [ + "a shocking revelation", + "danger: high voltage", + "inadequate insulation", + "rode the lightning", + ], generic: [ "you had a bad time", ], diff --git a/js/tileset.js b/js/tileset.js index 7a63b9c..c9e6631 100644 --- a/js/tileset.js +++ b/js/tileset.js @@ -1048,6 +1048,11 @@ export const LL_TILESET_LAYOUT = Object.assign({}, CC2_TILESET_LAYOUT, { active: [8, 43], inactive: [10, 43], }, + electrified_floor: { + __special__: 'visual-state', + active: [[5, 41], [6, 41], [7, 41]], + inactive: [4, 41], + }, }); export const TILESET_LAYOUTS = { diff --git a/js/tiletypes.js b/js/tiletypes.js index 135b9e4..0a7b07f 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -169,6 +169,9 @@ function player_visual_state(me) { else if (me.fail_reason === 'slimed') { return 'slimed'; } + else if (me.fail_reason === 'electrocuted') { + return 'burned'; //same gfx for now + } else if (me.fail_reason) { return 'failed'; } @@ -1108,7 +1111,7 @@ const TILE_TYPES = { blocks_collision: COLLISION.all, is_actor: true, is_block: true, - ignores: new Set(['fire', 'flame_jet_on']), + ignores: new Set(['fire', 'flame_jet_on', 'electrified_floor']), can_reverse_on_railroad: true, movement_speed: 4, }, @@ -1885,6 +1888,44 @@ const TILE_TYPES = { me.type.activate(me, level); }, }, + electrified_floor: { + layer: LAYERS.terrain, + wire_propagation_mode: 'all', + on_begin(me, level) { + // TODO if wire destruction is ever allowed, this will need to update somehow + me.is_wired = level.is_tile_wired(me, false); + me.is_active = ! me.is_wired; + }, + on_tic(me, level) { + if (me.is_active) + { + let actor = me.cell.get_actor(); + if (actor && actor.movement_cooldown <= 0 && ! actor.ignores(me.type.name)) { + if (actor.type.is_real_player) { + level.fail('electrocuted', me, actor); + } + else { + level.sfx.play_once('bomb', me.cell); + level.transmute_tile(actor, 'explosion'); + } + } + } + }, + on_power(me, level) { + if (me.is_wired) { + level._set_tile_prop(me, 'is_active', true); + } + }, + on_depower(me, level) { + if (me.is_wired) { + level._set_tile_prop(me, 'is_active', false); + } + }, + visual_state(me) { + return ! me || me.is_active ? 'active' : 'inactive'; + }, + }, + // Buttons button_blue: { layer: LAYERS.terrain, @@ -2855,6 +2896,7 @@ const TILE_TYPES = { is_item: true, is_tool: true, blocks_collision: COLLISION.block_cc1 | (COLLISION.monster_solid & ~COLLISION.rover), + item_ignores: new Set(['electrified_floor']), }, speed_boots: { layer: LAYERS.item,