Skip to content

Commit 9e5f1d7

Browse files
committed
custom field abilities better support
1 parent 46334c1 commit 9e5f1d7

File tree

8 files changed

+74
-24
lines changed

8 files changed

+74
-24
lines changed

base/ControllableChar.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export abstract class ControllableChar {
8787
public casting_psynergy: boolean;
8888
/** Whether this char is under Reveal psynergy effect. */
8989
public on_reveal: boolean;
90+
/** Whether this char is under custom psynergy effect. */
91+
public on_custom_psynergy_effect: boolean;
9092
/** Whether this char is teleporting by the teleport TileEvent. */
9193
public teleporting: boolean;
9294
/** Whether this char is idle during climbing state. */
@@ -227,6 +229,7 @@ export abstract class ControllableChar {
227229
this.misc_busy = false;
228230
this.casting_psynergy = false;
229231
this.on_reveal = false;
232+
this.on_custom_psynergy_effect = false;
230233
this.teleporting = false;
231234
this.idle_climbing = false;
232235
this.ice_sliding_active = false;

base/Map.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class Map {
114114
id: number;
115115
rect: Phaser.Rectangle;
116116
}[];
117-
private current_bounding_box_id: number;
117+
private _current_bounding_box_id: number;
118118
private game_events: GameEvent[];
119119
private before_config_game_events: GameEvent[];
120120
private before_camera_fade_game_events: GameEvent[];
@@ -213,7 +213,7 @@ export class Map {
213213
this._background_key = background_key;
214214
this.polygons_processed = new Set();
215215
this.bounding_boxes = [];
216-
this.current_bounding_box_id = null;
216+
this._current_bounding_box_id = null;
217217
this.game_events = [];
218218
this.before_config_game_events = [];
219219
this.before_camera_fade_game_events = [];
@@ -345,7 +345,6 @@ export class Map {
345345
get active_filters() {
346346
return this._active_filters;
347347
}
348-
349348
/** Gets the window object that shows this map's name. */
350349
get map_name_window() {
351350
return this._map_name_window;
@@ -354,21 +353,22 @@ export class Map {
354353
get show_map_name() {
355354
return this._show_map_name;
356355
}
357-
358356
/** The internal storage keys created for objects of this map. */
359357
get internal_map_objs_storage_keys() {
360358
return this._internal_map_objs_storage_keys;
361359
}
362-
363360
/** Gets Retreat psynergy info. Returns the x and y tile posoition to retreat and the destination collision index and direction. */
364361
get retreat_data() {
365362
return this._retreat_data;
366363
}
367-
368364
/** Gets the collision layer index that sand psynergy will use. */
369365
get sand_collision_layer() {
370366
return this._sand_collision_layer;
371367
}
368+
/** Gets the current bounding box object ID. */
369+
get current_bounding_box_id() {
370+
return this._current_bounding_box_id;
371+
}
372372

373373
/**
374374
* Sorts the sprites in the GoldenSun.middlelayer_group by y position and base_collision_layer
@@ -1440,7 +1440,7 @@ export class Map {
14401440
for (let i = 0; i < this.bounding_boxes.length; ++i) {
14411441
const bounding_box = this.bounding_boxes[i].rect;
14421442
if (bounding_box.contains(x, y)) {
1443-
this.current_bounding_box_id = this.bounding_boxes[i].id;
1443+
this._current_bounding_box_id = this.bounding_boxes[i].id;
14441444
break;
14451445
}
14461446
}
@@ -2397,7 +2397,7 @@ export class Map {
23972397
this.data.middlelayer_group.removeAll();
23982398
this.encounter_zones = [];
23992399
this.bounding_boxes = [];
2400-
this.current_bounding_box_id = null;
2400+
this._current_bounding_box_id = null;
24012401
this.game_events = [];
24022402
this.before_config_game_events = [];
24032403
this.before_camera_fade_game_events = [];

base/Snapshot.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {Button} from "./XGamepad";
1212
import {reverse_directions, engine_filters} from "./utils";
1313
import {Breakable} from "./interactable_objects/Breakable";
1414
import {RollablePillar} from "./interactable_objects/RollingPillar";
15-
import {RevealFieldPsynergy} from "./field_abilities/RevealFieldPsynergy";
1615
import {RopeDock} from "./interactable_objects/RopeDock";
1716
import {Map} from "Map";
1817
import {Pushable} from "interactable_objects/Pushable";
@@ -507,7 +506,14 @@ export class Snapshot {
507506
mute: this.game.sound.mute,
508507
};
509508
if (this.data.hero.on_reveal) {
510-
(this.data.info.field_abilities_list.reveal as RevealFieldPsynergy).finish(false, false);
509+
this.data.info.field_abilities_list.reveal.finish_psynergy(false, false);
510+
}
511+
if (this.data.hero.on_custom_psynergy_effect) {
512+
_.forEach(this.data.info.field_abilities_list, ability => {
513+
if (ability.is_custom_psynergy) {
514+
ability.finish_psynergy(false, false);
515+
}
516+
});
511517
}
512518
Snapshot.download_json(snapshot, Snapshot.SNAPSHOT_FILENAME);
513519
}

base/field_abilities/FieldAbilities.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {Button} from "../XGamepad";
1111
import {DialogManager} from "../utils/DialogManager";
1212
import {degree360} from "../magic_numbers";
1313
import {Pushable} from "../interactable_objects/Pushable";
14+
import {MainChar} from "../MainChar";
1415

1516
/**
1617
* Defines and manages the usage of field psynergy.
@@ -31,6 +32,8 @@ export abstract class FieldAbilities {
3132
protected data: GoldenSun;
3233
/** The controllable char that's casting this psynergy. */
3334
protected controllable_char: ControllableChar;
35+
/** The main char that it casting the psynergy. */
36+
protected caster: MainChar;
3437
/** The target object of this psynergy. Might not be necessary depending on the psynergy. */
3538
protected target_object: InteractableObjects | NPC;
3639
/** If called, the casting aura is destroyed. */
@@ -57,6 +60,7 @@ export abstract class FieldAbilities {
5760
private extra_cast_check: () => boolean;
5861
private target_is_npc: boolean;
5962
private map_colors_sequence: boolean;
63+
public is_custom_psynergy: boolean;
6064
private previous_collision_status: {
6165
char: boolean;
6266
target?: boolean;
@@ -80,6 +84,7 @@ export abstract class FieldAbilities {
8084
* @param ask_before_cast If true, it opens an YesNo menu asking if the char really wants to cast this ability.
8185
* @param target_is_npc If true, the target is a NPC instead of an IO.
8286
* @param map_colors_sequence If true, the map will be tinted sequentially with random colors.
87+
* @param is_custom_psynergy Set this to true, if it's a custom psynergy.
8388
*/
8489
constructor(
8590
game: Phaser.Game,
@@ -95,7 +100,8 @@ export abstract class FieldAbilities {
95100
target_found_extra_check?: (target: FieldAbilities["target_object"]) => boolean,
96101
ask_before_cast?: boolean,
97102
target_is_npc?: boolean,
98-
map_colors_sequence?: boolean
103+
map_colors_sequence?: boolean,
104+
is_custom_psynergy?: boolean
99105
) {
100106
this.game = game;
101107
this.ability_key_name = ability_key_name;
@@ -118,6 +124,7 @@ export abstract class FieldAbilities {
118124
this.ask_before_cast_yes_no_menu = new YesNoMenu(this.game, this.data);
119125
this.target_is_npc = target_is_npc ?? false;
120126
this.map_colors_sequence = map_colors_sequence ?? false;
127+
this.is_custom_psynergy = is_custom_psynergy ?? false;
121128
}
122129

123130
/**
@@ -185,6 +192,14 @@ export abstract class FieldAbilities {
185192
this.cast_finisher = method;
186193
}
187194

195+
/**
196+
* Generic funcion that can be overriden. When calling this, the psynergy effect should be finished.
197+
* @param force for the psynergy to finish.
198+
* @param stop_char stops the char current animation.
199+
* @param finish_callback the callback method to be called on psynergy end finish.
200+
*/
201+
finish_psynergy(force: boolean = false, stop_char: boolean = true, finish_callback?: () => void) {}
202+
188203
/**
189204
* Searches for target, NPC or IO, if this psynergy requests a target.
190205
*/
@@ -433,6 +448,7 @@ export abstract class FieldAbilities {
433448
cast(controllable_char: ControllableChar, caster_key_name: string) {
434449
this.controllable_char = controllable_char;
435450
const caster = this.data.info.main_char_list[caster_key_name];
451+
this.caster = caster;
436452
if (
437453
this.controllable_char.casting_psynergy ||
438454
this.controllable_char.sand_mode ||

base/field_abilities/RevealFieldPsynergy.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export class RevealFieldPsynergy extends FieldAbilities {
4747
update() {
4848
if (this.controllable_char?.on_reveal) {
4949
if (this.should_finish_reveal(this.controllable_char.x, this.controllable_char.y)) {
50-
this.finish();
50+
this.finish_psynergy();
5151
}
5252
}
5353
}
5454

55-
toggle_reveal() {
55+
private toggle_reveal() {
5656
this.data.map.layers.forEach(layer => {
5757
if (layer.properties?.reveal_layer) {
5858
layer.sprite.visible = !layer.sprite.visible;
@@ -93,7 +93,7 @@ export class RevealFieldPsynergy extends FieldAbilities {
9393
}
9494
}
9595

96-
finish(force: boolean = false, stop_char: boolean = true, finish_callback?: () => void) {
96+
finish_psynergy(force: boolean = false, stop_char: boolean = true, finish_callback?: () => void) {
9797
this.controllable_char.on_reveal = false;
9898
const previous_psynergy_state = this.controllable_char.casting_psynergy;
9999
this.controllable_char.casting_psynergy = true;
@@ -126,11 +126,11 @@ export class RevealFieldPsynergy extends FieldAbilities {
126126
}
127127
}
128128

129-
show_wave() {
129+
private show_wave() {
130130
this.close_field_psynergy_window();
131131

132132
if (this.controllable_char.on_reveal) {
133-
this.finish(true);
133+
this.finish_psynergy(true);
134134
this.controllable_char.casting_psynergy = true;
135135
}
136136
this.casting_point = {
@@ -216,7 +216,7 @@ export class RevealFieldPsynergy extends FieldAbilities {
216216
}
217217
}
218218
}
219-
this.finish();
219+
this.finish_psynergy();
220220
});
221221
this.end_timer.start();
222222
};

base/game_events/GameEvent.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {StoragePosition} from "Storage";
2-
import {RevealFieldPsynergy} from "../field_abilities/RevealFieldPsynergy";
32
import {GoldenSun} from "../GoldenSun";
43
import {NPC} from "../NPC";
4+
import * as _ from "lodash";
55

66
type BasicValues = string | number | boolean;
77

@@ -209,9 +209,20 @@ export abstract class GameEvent {
209209
}
210210

211211
/** Check if "Reveal" is currently active. If yes, then cancel it. */
212-
check_reveal() {
212+
private check_reveal() {
213213
if (this.data.hero?.on_reveal && !this.keep_reveal) {
214-
(this.data.info.field_abilities_list.reveal as RevealFieldPsynergy).finish(false, false);
214+
this.data.info.field_abilities_list.reveal.finish_psynergy(false, false);
215+
}
216+
}
217+
218+
/** Check if a custom psynergy is currently active. If yes, then cancel it. */
219+
private check_custom_psynergy() {
220+
if (this.data?.hero.on_custom_psynergy_effect) {
221+
_.forEach(this.data.info.field_abilities_list, ability => {
222+
if (ability.is_custom_psynergy) {
223+
ability.finish_psynergy(false, false);
224+
}
225+
});
215226
}
216227
}
217228

@@ -228,6 +239,7 @@ export abstract class GameEvent {
228239
return;
229240
}
230241
this.check_reveal();
242+
this.check_custom_psynergy();
231243
this._origin_npc = origin_npc;
232244
this._fire();
233245
}

base/tile_events/ClimbEvent.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {base_actions, directions, reverse_directions} from "../utils";
22
import {TileEvent, event_types} from "./TileEvent";
33
import * as numbers from "../magic_numbers";
44
import {InteractableObjects, interactable_object_event_types} from "../interactable_objects/InteractableObjects";
5-
import {RevealFieldPsynergy} from "../field_abilities/RevealFieldPsynergy";
65
import {GoldenSun} from "../GoldenSun";
6+
import * as _ from "lodash";
77

88
export enum climb_actions {
99
IDLE = "idle",
@@ -66,7 +66,14 @@ export class ClimbEvent extends TileEvent {
6666
return;
6767
}
6868
if (this.data.hero.on_reveal) {
69-
(this.data.info.field_abilities_list.reveal as RevealFieldPsynergy).finish(false, false);
69+
this.data.info.field_abilities_list.reveal.finish_psynergy(false, false);
70+
}
71+
if (this.data.hero.on_custom_psynergy_effect) {
72+
_.forEach(this.data.info.field_abilities_list, ability => {
73+
if (ability.is_custom_psynergy) {
74+
ability.finish_psynergy(false, false);
75+
}
76+
});
7077
}
7178
if (
7279
this.current_activation_direction !== directions.up &&

base/tile_events/TeleportEvent.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {base_actions, directions, get_centered_pos_in_px, reverse_directions} from "../utils";
22
import {event_types, TileEvent} from "./TileEvent";
33
import * as _ from "lodash";
4-
import {RevealFieldPsynergy} from "../field_abilities/RevealFieldPsynergy";
54
import {climb_actions} from "./ClimbEvent";
65
import {ParticlesInfo, ParticlesWrapper} from "../ParticlesWrapper";
76

@@ -366,7 +365,14 @@ export class TeleportEvent extends TileEvent {
366365
}
367366
}
368367
if (this.data.hero.on_reveal) {
369-
(this.data.info.field_abilities_list.reveal as RevealFieldPsynergy).finish(true);
368+
this.data.info.field_abilities_list.reveal.finish_psynergy(true);
369+
}
370+
if (this.data.hero.on_custom_psynergy_effect) {
371+
_.forEach(this.data.info.field_abilities_list, ability => {
372+
if (ability.is_custom_psynergy) {
373+
ability.finish_psynergy(true);
374+
}
375+
});
370376
}
371377
const destination_direction =
372378
directions[this.destination_direction] !== undefined

0 commit comments

Comments
 (0)