Skip to content

Commit

Permalink
feat: 違うマップにいるキャラクターがぶつかってくるバグを修正 (#184)
Browse files Browse the repository at this point in the history
* プレイヤーと同じマップにいるオブジェクトだけ「つねに」を呼ぶ
* プレイヤーと同じマップにいるオブジェクトだけ「じかんがすすんだとき」を呼ぶ
* 別のマップにいるオブジェクトにはぶつからない
* https://scrapbox.io/hackforplay-inc/別のマップにいるキャラクターにぶつかられるバグ
  • Loading branch information
teramotodaiki committed Mar 10, 2023
1 parent a246d4a commit d8a8ef8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/hackforplay/object/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,16 @@ export default class RPGObject extends enchant.Sprite implements N.INumbers {
nextMapY < 0 ||
nextMapY >= ty; // 画面外にいこうとしている

// 同じマップにいるオブジェクト
const currentMap = this.map;
const objectsInSameMap = RPGObject.collection.filter(
obj => obj.map === currentMap
);

// プレイヤーだけは例外的に仲間のいるマスをすり抜けられる
const mayCollideItems = this.isPlayer
? objectsInDefaultMap().filter(item => this.family !== item.family)
: objectsInDefaultMap();
? objectsInSameMap.filter(item => this.family !== item.family)
: objectsInSameMap;

// 歩く先にあるオブジェクト
const hits = mayCollideItems.filter(obj => {
Expand Down
9 changes: 6 additions & 3 deletions src/hackforplay/rule.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { log } from '@hackforplay/log';
import { objectsInDefaultMap } from './cache';
import { IDir } from './dir';
import { Direction } from './direction';
import { hasContract, isOpposite } from './family';
import { install } from './feeles';
import { getHack } from './get-hack';
import { emitGlobalsChangedIfNeeded } from './globals';
import { loadMaps } from './load-maps';
import RPGObject from './object/object';
import { errorInEvent, logFromAsset } from './stdlog';
import { synonyms } from './synonyms/rule';
import { PropertyMissing, synonymizeClass } from './synonyms/synonymize';
import talk from './talk';
import { loadMaps } from './load-maps';

interface IEvent {
target: RPGObject;
Expand Down Expand Up @@ -314,8 +315,7 @@ export class Rule {
if (!Hack.isPlaying) return; // ゲームが終了した

// つねに をコールする
// this._collections を使うべきか?(へんしんしたときちゃんと動くか?)
for (const object of Array.from(RPGObject.collection)) {
for (const object of objectsInDefaultMap()) {
if (!this.enabledUpdate.get(object)) {
continue; // まだ途中になっているものがある => スキップ
}
Expand Down Expand Up @@ -385,6 +385,9 @@ export class Rule {
if (!listeners) return;
for (const name of Object.keys(listeners)) {
for (const item of this.getCollection(name)) {
const map = 'map' in Hack ? Hack.map : undefined;
if (item.map !== map) continue; // プレイヤーと同じマップにいるものだけが対象

this.scheduleEventEmit({
eventName: 'じかんがすすんだとき',
args: [item]
Expand Down

0 comments on commit d8a8ef8

Please sign in to comment.