Skip to content

Commit

Permalink
fall tile and game event
Browse files Browse the repository at this point in the history
  • Loading branch information
jjppof committed Nov 27, 2023
1 parent 8226efd commit 744ffd3
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 4 deletions.
11 changes: 8 additions & 3 deletions base/ControllableChar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1832,12 +1832,14 @@ export abstract class ControllableChar {
/** The destination collision layer index in the dest map. */
dest_collision_layer: number;
/** If true, the char sprite will be brought to the top on z-index while falling. */
send_to_front_on_teleport: boolean;
send_to_front_on_teleport?: boolean;
/** If true, the char will diminish instead of fall before teleport. */
diminish_on_transition: boolean;
diminish_on_transition?: boolean;
/** Callback to be called before teleport begin. */
on_before_teleport?: () => void;
};
/** Callback to be called after hitting the ground. */
on_fall_finish_callback: () => void;
on_fall_finish_callback?: () => void;
}) {
const prev_misc_busy = this.misc_busy;
this.misc_busy = true;
Expand Down Expand Up @@ -1959,6 +1961,9 @@ export abstract class ControllableChar {
fall_tween.stop(false);
scale_tween?.stop(false);
this.reset_scale();
if (options.teleport.on_before_teleport) {
options.teleport.on_before_teleport();
}
});
event.set_finish_callback(() => {
event.destroy();
Expand Down
2 changes: 1 addition & 1 deletion base/game_events/CharBlendModeEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class CharBlendModeEvent extends GameEvent {
npc_label: this.npc_label,
}) ?? this.origin_npc;

if (target_char.sprite) {
if (target_char?.sprite) {
switch (this.blend_mode) {
case "normal":
target_char.sprite.blendMode = PIXI.blendModes.NORMAL;
Expand Down
77 changes: 77 additions & 0 deletions base/game_events/CharFallEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {ControllableChar} from "../ControllableChar";
import {GameEvent, event_types} from "./GameEvent";

export class CharFallEvent extends GameEvent {
private is_npc: boolean;
private npc_label: string;
private options: Parameters<ControllableChar["fall"]>[0];
private finish_events: GameEvent[];

constructor(
game,
data,
active,
key_name,
keep_reveal,
is_npc,
npc_label,
y_destination_position,
dest_collision_layer,
show_exclamation_emoticon,
splash_sweat_drops,
walking_in_the_air,
ground_hit_animation,
teleport,
finish_events
) {
super(game, data, event_types.CHAR_FALL, active, key_name, keep_reveal);
this.is_npc = is_npc;
this.npc_label = npc_label;
this.options = {
y_destination_position: y_destination_position,
dest_collision_layer: dest_collision_layer,
show_exclamation_emoticon: show_exclamation_emoticon,
splash_sweat_drops: splash_sweat_drops,
walking_in_the_air: walking_in_the_air,
ground_hit_animation: ground_hit_animation,
teleport: teleport,
};
this.finish_events = [];
if (finish_events !== undefined) {
finish_events.forEach(event_info => {
const event = this.data.game_event_manager.get_event_instance(event_info, this.type, this.origin_npc);
this.finish_events.push(event);
});
}
}

async _fire() {
const target_char =
GameEvent.get_char(this.data, {
is_npc: this.is_npc,
npc_label: this.npc_label,
}) ?? this.origin_npc;

if (target_char) {
++this.data.game_event_manager.events_running_count;
const target_obj = Object.assign({}, this.options, {
on_fall_finish_callback: () => {
if (!this.options.teleport) {
--this.data.game_event_manager.events_running_count;
this.finish_events.forEach(event => event.fire(this.origin_npc));
}
},
});
if (target_obj.teleport) {
target_obj.teleport.on_before_teleport = () => {
this.data.game_event_manager.events_running_count = 0;
};
}
target_char.fall(target_obj);
}
}

_destroy() {
this.finish_events.forEach(event => event?.destroy());
}
}
1 change: 1 addition & 0 deletions base/game_events/GameEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export enum event_types {
CHAR_SHADOW_VISIBILITY = "char_shadow_visibility",
IO_TWEEN_POSITION = "io_tween_position",
EXIT_SAND_MODE = "exit_sand_mode",
CHAR_FALL = "char_fall",
}

export enum game_event_misc_origin {
Expand Down
19 changes: 19 additions & 0 deletions base/game_events/GameEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import {CharTweenPositionEvent} from "./CharTweenPositionEvent";
import {CharShadowVisibilityEvent} from "./CharShadowVisibilityEvent";
import {IOTweenPositionEvent} from "./IOTweenPositionEvent";
import {ExitSandModeEvent} from "./ExitSandModeEvent";
import {CharFallEvent} from "./CharFallEvent";

export enum interaction_patterns {
NO_INTERACTION = "no_interaction",
Expand Down Expand Up @@ -1226,6 +1227,24 @@ export class GameEventManager {
info.keep_reveal,
info.finish_events
);
case event_types.CHAR_FALL:
return new CharFallEvent(
this.game,
this.data,
info.active,
info.key_name,
info.keep_reveal,
info.is_npc,
info.npc_label,
info.y_destination_position,
info.dest_collision_layer,
info.show_exclamation_emoticon,
info.splash_sweat_drops,
info.walking_in_the_air,
info.ground_hit_animation,
info.teleport,
info.finish_events
);
default:
const origin = `Event origin: ${event_origin}. ${
entity_origin?.label
Expand Down
62 changes: 62 additions & 0 deletions base/tile_events/FallEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {ControllableChar} from "../ControllableChar";
import {event_types, TileEvent} from "./TileEvent";

export class FallEvent extends TileEvent {
private options: Parameters<ControllableChar["fall"]>[0];

constructor(
game,
data,
x,
y,
activation_directions,
initial_disabled_directions,
activation_collision_layers,
active_storage_key,
affected_by_reveal,
key_name: string,
y_destination_position,
dest_collision_layer,
show_exclamation_emoticon,
splash_sweat_drops,
walking_in_the_air,
ground_hit_animation,
teleport
) {
super(
game,
data,
event_types.FALL,
x,
y,
activation_directions,
initial_disabled_directions,
activation_collision_layers,
active_storage_key,
null,
affected_by_reveal,
key_name
);
this.options = {
y_destination_position: y_destination_position,
dest_collision_layer: dest_collision_layer,
show_exclamation_emoticon: show_exclamation_emoticon,
splash_sweat_drops: splash_sweat_drops,
walking_in_the_air: walking_in_the_air,
ground_hit_animation: ground_hit_animation,
teleport: teleport,
};
}

fire() {
if (!this.check_position() || !this.data.hero_movement_allowed()) {
return;
}
this.data.hero.fall(this.options);
}

destroy() {
this.deactivate();
this._origin_interactable_object = null;
}
}
1 change: 1 addition & 0 deletions base/tile_events/TileEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum event_types {
EVENT_TRIGGER = "event_trigger",
ICE_SLIDE = "ice_slide",
ROPE = "rope",
FALL = "fall",
}

export abstract class IntegerPairKey {
Expand Down
21 changes: 21 additions & 0 deletions base/tile_events/TileEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {base_actions, directions} from "../utils";
import {ClimbEvent} from "./ClimbEvent";
import {CollisionEvent} from "./CollisionEvent";
import {EventTriggerEvent} from "./EventTriggerEvent";
import {FallEvent} from "./FallEvent";
import {IceSlideEvent} from "./IceSlideEvent";
import {JumpEvent} from "./JumpEvent";
import {RopeEvent} from "./RopeEvent";
Expand Down Expand Up @@ -454,6 +455,26 @@ export class TileEventManager {
info.dock_exit_collision_layer,
info.rope_collision_layer
);
} else if (info.type === event_types.FALL) {
return new FallEvent(
this.game,
this.data,
info.x,
info.y,
info.activation_directions,
info.initial_disabled_directions,
info.activation_collision_layers,
info.active_storage_key,
info.affected_by_reveal,
info.key_name,
info.y_destination_position,
info.dest_collision_layer,
info.show_exclamation_emoticon,
info.splash_sweat_drops,
info.walking_in_the_air,
info.ground_hit_animation,
info.teleport
);
} else {
if (info.type) {
this.data.logger.log_message(`Tile event type '${info.type}' not found.`);
Expand Down

0 comments on commit 744ffd3

Please sign in to comment.