Skip to content

Commit 744ffd3

Browse files
committed
fall tile and game event
1 parent 8226efd commit 744ffd3

File tree

8 files changed

+190
-4
lines changed

8 files changed

+190
-4
lines changed

base/ControllableChar.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,12 +1832,14 @@ export abstract class ControllableChar {
18321832
/** The destination collision layer index in the dest map. */
18331833
dest_collision_layer: number;
18341834
/** If true, the char sprite will be brought to the top on z-index while falling. */
1835-
send_to_front_on_teleport: boolean;
1835+
send_to_front_on_teleport?: boolean;
18361836
/** If true, the char will diminish instead of fall before teleport. */
1837-
diminish_on_transition: boolean;
1837+
diminish_on_transition?: boolean;
1838+
/** Callback to be called before teleport begin. */
1839+
on_before_teleport?: () => void;
18381840
};
18391841
/** Callback to be called after hitting the ground. */
1840-
on_fall_finish_callback: () => void;
1842+
on_fall_finish_callback?: () => void;
18411843
}) {
18421844
const prev_misc_busy = this.misc_busy;
18431845
this.misc_busy = true;
@@ -1959,6 +1961,9 @@ export abstract class ControllableChar {
19591961
fall_tween.stop(false);
19601962
scale_tween?.stop(false);
19611963
this.reset_scale();
1964+
if (options.teleport.on_before_teleport) {
1965+
options.teleport.on_before_teleport();
1966+
}
19621967
});
19631968
event.set_finish_callback(() => {
19641969
event.destroy();

base/game_events/CharBlendModeEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class CharBlendModeEvent extends GameEvent {
1919
npc_label: this.npc_label,
2020
}) ?? this.origin_npc;
2121

22-
if (target_char.sprite) {
22+
if (target_char?.sprite) {
2323
switch (this.blend_mode) {
2424
case "normal":
2525
target_char.sprite.blendMode = PIXI.blendModes.NORMAL;

base/game_events/CharFallEvent.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import {ControllableChar} from "../ControllableChar";
2+
import {GameEvent, event_types} from "./GameEvent";
3+
4+
export class CharFallEvent extends GameEvent {
5+
private is_npc: boolean;
6+
private npc_label: string;
7+
private options: Parameters<ControllableChar["fall"]>[0];
8+
private finish_events: GameEvent[];
9+
10+
constructor(
11+
game,
12+
data,
13+
active,
14+
key_name,
15+
keep_reveal,
16+
is_npc,
17+
npc_label,
18+
y_destination_position,
19+
dest_collision_layer,
20+
show_exclamation_emoticon,
21+
splash_sweat_drops,
22+
walking_in_the_air,
23+
ground_hit_animation,
24+
teleport,
25+
finish_events
26+
) {
27+
super(game, data, event_types.CHAR_FALL, active, key_name, keep_reveal);
28+
this.is_npc = is_npc;
29+
this.npc_label = npc_label;
30+
this.options = {
31+
y_destination_position: y_destination_position,
32+
dest_collision_layer: dest_collision_layer,
33+
show_exclamation_emoticon: show_exclamation_emoticon,
34+
splash_sweat_drops: splash_sweat_drops,
35+
walking_in_the_air: walking_in_the_air,
36+
ground_hit_animation: ground_hit_animation,
37+
teleport: teleport,
38+
};
39+
this.finish_events = [];
40+
if (finish_events !== undefined) {
41+
finish_events.forEach(event_info => {
42+
const event = this.data.game_event_manager.get_event_instance(event_info, this.type, this.origin_npc);
43+
this.finish_events.push(event);
44+
});
45+
}
46+
}
47+
48+
async _fire() {
49+
const target_char =
50+
GameEvent.get_char(this.data, {
51+
is_npc: this.is_npc,
52+
npc_label: this.npc_label,
53+
}) ?? this.origin_npc;
54+
55+
if (target_char) {
56+
++this.data.game_event_manager.events_running_count;
57+
const target_obj = Object.assign({}, this.options, {
58+
on_fall_finish_callback: () => {
59+
if (!this.options.teleport) {
60+
--this.data.game_event_manager.events_running_count;
61+
this.finish_events.forEach(event => event.fire(this.origin_npc));
62+
}
63+
},
64+
});
65+
if (target_obj.teleport) {
66+
target_obj.teleport.on_before_teleport = () => {
67+
this.data.game_event_manager.events_running_count = 0;
68+
};
69+
}
70+
target_char.fall(target_obj);
71+
}
72+
}
73+
74+
_destroy() {
75+
this.finish_events.forEach(event => event?.destroy());
76+
}
77+
}

base/game_events/GameEvent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export enum event_types {
111111
CHAR_SHADOW_VISIBILITY = "char_shadow_visibility",
112112
IO_TWEEN_POSITION = "io_tween_position",
113113
EXIT_SAND_MODE = "exit_sand_mode",
114+
CHAR_FALL = "char_fall",
114115
}
115116

116117
export enum game_event_misc_origin {

base/game_events/GameEventManager.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import {CharTweenPositionEvent} from "./CharTweenPositionEvent";
8585
import {CharShadowVisibilityEvent} from "./CharShadowVisibilityEvent";
8686
import {IOTweenPositionEvent} from "./IOTweenPositionEvent";
8787
import {ExitSandModeEvent} from "./ExitSandModeEvent";
88+
import {CharFallEvent} from "./CharFallEvent";
8889

8990
export enum interaction_patterns {
9091
NO_INTERACTION = "no_interaction",
@@ -1226,6 +1227,24 @@ export class GameEventManager {
12261227
info.keep_reveal,
12271228
info.finish_events
12281229
);
1230+
case event_types.CHAR_FALL:
1231+
return new CharFallEvent(
1232+
this.game,
1233+
this.data,
1234+
info.active,
1235+
info.key_name,
1236+
info.keep_reveal,
1237+
info.is_npc,
1238+
info.npc_label,
1239+
info.y_destination_position,
1240+
info.dest_collision_layer,
1241+
info.show_exclamation_emoticon,
1242+
info.splash_sweat_drops,
1243+
info.walking_in_the_air,
1244+
info.ground_hit_animation,
1245+
info.teleport,
1246+
info.finish_events
1247+
);
12291248
default:
12301249
const origin = `Event origin: ${event_origin}. ${
12311250
entity_origin?.label

base/tile_events/FallEvent.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {ControllableChar} from "../ControllableChar";
2+
import {event_types, TileEvent} from "./TileEvent";
3+
4+
export class FallEvent extends TileEvent {
5+
private options: Parameters<ControllableChar["fall"]>[0];
6+
7+
constructor(
8+
game,
9+
data,
10+
x,
11+
y,
12+
activation_directions,
13+
initial_disabled_directions,
14+
activation_collision_layers,
15+
active_storage_key,
16+
affected_by_reveal,
17+
key_name: string,
18+
y_destination_position,
19+
dest_collision_layer,
20+
show_exclamation_emoticon,
21+
splash_sweat_drops,
22+
walking_in_the_air,
23+
ground_hit_animation,
24+
teleport
25+
) {
26+
super(
27+
game,
28+
data,
29+
event_types.FALL,
30+
x,
31+
y,
32+
activation_directions,
33+
initial_disabled_directions,
34+
activation_collision_layers,
35+
active_storage_key,
36+
null,
37+
affected_by_reveal,
38+
key_name
39+
);
40+
this.options = {
41+
y_destination_position: y_destination_position,
42+
dest_collision_layer: dest_collision_layer,
43+
show_exclamation_emoticon: show_exclamation_emoticon,
44+
splash_sweat_drops: splash_sweat_drops,
45+
walking_in_the_air: walking_in_the_air,
46+
ground_hit_animation: ground_hit_animation,
47+
teleport: teleport,
48+
};
49+
}
50+
51+
fire() {
52+
if (!this.check_position() || !this.data.hero_movement_allowed()) {
53+
return;
54+
}
55+
this.data.hero.fall(this.options);
56+
}
57+
58+
destroy() {
59+
this.deactivate();
60+
this._origin_interactable_object = null;
61+
}
62+
}

base/tile_events/TileEvent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum event_types {
1414
EVENT_TRIGGER = "event_trigger",
1515
ICE_SLIDE = "ice_slide",
1616
ROPE = "rope",
17+
FALL = "fall",
1718
}
1819

1920
export abstract class IntegerPairKey {

base/tile_events/TileEventManager.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {base_actions, directions} from "../utils";
33
import {ClimbEvent} from "./ClimbEvent";
44
import {CollisionEvent} from "./CollisionEvent";
55
import {EventTriggerEvent} from "./EventTriggerEvent";
6+
import {FallEvent} from "./FallEvent";
67
import {IceSlideEvent} from "./IceSlideEvent";
78
import {JumpEvent} from "./JumpEvent";
89
import {RopeEvent} from "./RopeEvent";
@@ -454,6 +455,26 @@ export class TileEventManager {
454455
info.dock_exit_collision_layer,
455456
info.rope_collision_layer
456457
);
458+
} else if (info.type === event_types.FALL) {
459+
return new FallEvent(
460+
this.game,
461+
this.data,
462+
info.x,
463+
info.y,
464+
info.activation_directions,
465+
info.initial_disabled_directions,
466+
info.activation_collision_layers,
467+
info.active_storage_key,
468+
info.affected_by_reveal,
469+
info.key_name,
470+
info.y_destination_position,
471+
info.dest_collision_layer,
472+
info.show_exclamation_emoticon,
473+
info.splash_sweat_drops,
474+
info.walking_in_the_air,
475+
info.ground_hit_animation,
476+
info.teleport
477+
);
457478
} else {
458479
if (info.type) {
459480
this.data.logger.log_message(`Tile event type '${info.type}' not found.`);

0 commit comments

Comments
 (0)