Skip to content

Commit

Permalink
TILE_EVENT_MANAGE: allow IO events manipulation. SET_VALUE: new dismi…
Browse files Browse the repository at this point in the history
…ss_checks prop
  • Loading branch information
jjppof committed Dec 29, 2023
1 parent 73cb88c commit 46db345
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 36 deletions.
4 changes: 3 additions & 1 deletion base/game_events/GameEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ export class GameEventManager {
info.check_layers_visibility,
info.npc_label,
info.npc_index,
info.increment
info.increment,
info.dismiss_checks
);
case event_types.MOVE:
return new MoveEvent(
Expand Down Expand Up @@ -575,6 +576,7 @@ export class GameEventManager {
info.key_name,
info.keep_reveal,
info.tile_event_key,
info.io_label,
info.activate_at,
info.pos,
info.collision_layers
Expand Down
15 changes: 9 additions & 6 deletions base/game_events/SetValueEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class SetValueEvent extends GameEvent {
private npc_label: string;
private npc_index: number;
private increment: boolean;
private dismiss_checks: boolean;

constructor(
game,
Expand All @@ -25,7 +26,8 @@ export class SetValueEvent extends GameEvent {
check_layers_visibility,
npc_label,
npc_index,
increment
increment,
dismiss_checks
) {
super(game, data, event_types.SET_VALUE, active, key_name, keep_reveal);
this.event_value = event_value;
Expand All @@ -35,6 +37,7 @@ export class SetValueEvent extends GameEvent {
this.npc_label = npc_label;
this.npc_index = npc_index;
this.increment = increment ?? false;
this.dismiss_checks = dismiss_checks ?? false;
}

_fire() {
Expand All @@ -58,7 +61,7 @@ export class SetValueEvent extends GameEvent {
break;
}
const char = this.data.info.main_char_list[detailed_value.key_name];
if (_.hasIn(char, detailed_value.property)) {
if (_.hasIn(char, detailed_value.property) || this.dismiss_checks) {
if (this.increment) {
value_to_be_set += _.get(char, detailed_value.property);
}
Expand All @@ -68,7 +71,7 @@ export class SetValueEvent extends GameEvent {
}
break;
case game_info_types.HERO:
if (_.hasIn(this.data.hero, detailed_value.property)) {
if (_.hasIn(this.data.hero, detailed_value.property) || this.dismiss_checks) {
if (this.increment) {
value_to_be_set += _.get(this.data.hero, detailed_value.property);
}
Expand All @@ -83,7 +86,7 @@ export class SetValueEvent extends GameEvent {
npc_label: detailed_value.label,
npc_index: detailed_value.index,
});
if (npc && _.hasIn(npc, detailed_value.property)) {
if (npc && (_.hasIn(npc, detailed_value.property) || this.dismiss_checks)) {
if (this.increment) {
value_to_be_set += _.get(npc, detailed_value.property);
}
Expand All @@ -108,7 +111,7 @@ export class SetValueEvent extends GameEvent {
}
break;
}
if (_.hasIn(interactable_object, detailed_value.property)) {
if (_.hasIn(interactable_object, detailed_value.property) || this.dismiss_checks) {
if (this.increment) {
value_to_be_set += _.get(interactable_object, detailed_value.property);
}
Expand All @@ -135,7 +138,7 @@ export class SetValueEvent extends GameEvent {
}
break;
}
if (_.hasIn(event, detailed_value.property)) {
if (_.hasIn(event, detailed_value.property) || this.dismiss_checks) {
if (this.increment) {
value_to_be_set += _.get(event, detailed_value.property);
}
Expand Down
86 changes: 62 additions & 24 deletions base/game_events/TileEventManageEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ import {GameEvent, event_types} from "./GameEvent";

export class TileEventManageEvent extends GameEvent {
private tile_event_key: string;
private io_label: string;
private activate_at: {[direction: string]: boolean};
private pos: {x: number; y: number};
private collision_layers: number[];

constructor(game, data, active, key_name, keep_reveal, tile_event_key, activate_at, pos, collision_layers) {
constructor(
game,
data,
active,
key_name,
keep_reveal,
tile_event_key,
io_label,
activate_at,
pos,
collision_layers
) {
super(game, data, event_types.TILE_EVENT_MANAGE, active, key_name, keep_reveal);
this.tile_event_key = tile_event_key;
this.io_label = io_label;
this.activate_at = activate_at;
this.pos = pos;
if (collision_layers !== undefined) {
Expand All @@ -19,36 +32,61 @@ export class TileEventManageEvent extends GameEvent {
}

_fire() {
if (!this.tile_event_key) return;
const event = TileEvent.get_labeled_event(this.tile_event_key);
if (!event) return;

if (this.activate_at) {
if (this.activate_at.hasOwnProperty("all")) {
if (this.activate_at.all) {
event.activate();
} else {
event.deactivate();
}
let events = [];
if (this.tile_event_key) {
const event = TileEvent.get_labeled_event(this.tile_event_key);
if (event) {
events.push(event);
} else {
for (let direction in this.activate_at) {
const dir = directions[direction];
const active = this.activate_at[direction] as boolean;
if (active) {
event.activate_at(dir);
this.data.logger.log_message(
`Game Event [${this.type}]: Event with ley "${this.tile_event_key}" doesn't exist.`
);
return;
}
} else if (this.io_label) {
const interactable_object = this.data.map.interactable_objects_label_map[this.io_label];
if (!(this.io_label in this.data.map.interactable_objects_label_map)) {
this.data.logger.log_message(
`Game Event [${this.type}]: IO with label "${this.io_label}" doesn't exist.`
);
return;
}
events = interactable_object.get_events();
} else {
return;
}

for (let event of events) {
if (!event) {
continue;
}
if (this.activate_at) {
if (this.activate_at.hasOwnProperty("all")) {
if (this.activate_at.all) {
event.activate();
} else {
event.deactivate_at(dir);
event.deactivate();
}
} else {
for (let direction in this.activate_at) {
const dir = directions[direction];
const active = this.activate_at[direction] as boolean;
if (active) {
event.activate_at(dir);
} else {
event.deactivate_at(dir);
}
}
}
}
}

if (this.collision_layers) {
event.set_activation_collision_layers(...this.collision_layers);
}
if (this.collision_layers) {
event.set_activation_collision_layers(...this.collision_layers);
}

if (this.pos) {
event.set_position(this.pos.x, this.pos.y, true);
if (this.pos) {
event.set_position(this.pos.x, this.pos.y, true);
}
}
}

Expand Down
7 changes: 2 additions & 5 deletions base/interactable_objects/InteractableObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class InteractableObjects {
private _flame_filter: Phaser.Filter.Flame;
private _enable: boolean;
private _entangled_by_bush: boolean;
private _sprite: Phaser.Sprite;
public sprite: Phaser.Sprite;
private _psynergy_casted: {[field_psynergy_key: string]: boolean};
private _blocking_stair_block: Phaser.Physics.P2.Body;
private _active: boolean;
Expand Down Expand Up @@ -354,9 +354,6 @@ export class InteractableObjects {
get base_collision_layer() {
return this._base_collision_layer;
}
get sprite() {
return this._sprite;
}
get sprite_info() {
return this._sprite_info;
}
Expand Down Expand Up @@ -701,7 +698,7 @@ export class InteractableObjects {
const interactable_object_db = this.data.dbs.interactable_objects_db[this.key_name];
const interactable_object_key = this.sprite_info.getSpriteKey(this.current_action);
const interactable_object_sprite = this.data.middlelayer_group.create(0, 0, interactable_object_key);
this._sprite = interactable_object_sprite;
this.sprite = interactable_object_sprite;
this.sprite.is_interactable_object = true;
this.sprite.roundPx = true;
this.sprite.base_collision_layer = this.base_collision_layer;
Expand Down

0 comments on commit 46db345

Please sign in to comment.