Skip to content

Commit

Permalink
2.0.0 マップのメモ欄に対応
Browse files Browse the repository at this point in the history
  • Loading branch information
elleonard committed May 27, 2023
1 parent 8db6339 commit 6e3a0c7
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 59 deletions.
44 changes: 0 additions & 44 deletions src/codes/SealItem/DarkPlasma_SealItem.js

This file was deleted.

117 changes: 117 additions & 0 deletions src/codes/SealItem/DarkPlasma_SealItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/// <reference path="./SealItem.d.ts" />

import { pluginName } from '../../common/pluginName';
import { hasTraits } from '../../common/data/hasTraits';

const localTraitId = 1;
const sealAllItemTraitId = uniqueTraitIdCache.allocate(pluginName, localTraitId, '全アイテム禁止');
const sealItemByIdTraitId = uniqueTraitIdCache.allocate(pluginName, localTraitId + 1, 'アイテム禁止');
const sealHealItemTraitId = uniqueTraitIdCache.allocate(pluginName, localTraitId + 2, '回復アイテム禁止');
const sealResurrectionItemTraitId = uniqueTraitIdCache.allocate(pluginName, localTraitId + 3, '蘇生アイテム禁止');

function DataManager_SealItemMixIn(dataManager: typeof DataManager) {
const _extractMetadata = dataManager.extractMetadata;
dataManager.extractMetadata = function (data) {
_extractMetadata.call(this, data);
if (hasTraits(data)) {
data.traits.push(...extractSealItemTraits(data));
}
};

function extractSealItemTraits(data: MZ.Actor | MZ.Class | MZ.Weapon | MZ.Armor | MZ.State | MZ.Enemy) {
const result: MZ.Trait[] = [];
if (data.meta.sealAllItem) {
result.push({
code: sealAllItemTraitId.id,
dataId: 0,
value: 0,
});
}
if (data.meta.sealItems) {
const itemIds = String(data.meta.sealItems).split(",").map(id => Number(id));
result.push(...itemIds.map(itemId => {
return {
code: sealItemByIdTraitId.id,
dataId: itemId,
value: 0
};
}));
}
if (data.meta.sealHealItem) {
result.push({
code: sealHealItemTraitId.id,
dataId: 0,
value: 0,
});
}
if (data.meta.sealResurrectionItem) {
result.push({
code: sealResurrectionItemTraitId.id,
dataId: 0,
value: 0,
});
}
return result;
}

/**
* 特徴を持つオブジェクトから、封印アイテムID一覧を取得する
*/
dataManager.sealItems = function (object) {
return object.meta.sealItems ? String(object.meta.sealItems).split(',').map((itemId) => Number(itemId)) : [];
};

/**
* ダメージタイプが回復であるようなアイテムか
*/
dataManager.isHealItem = function (item) {
return [3, 4].includes(item.damage.type);
};

/**
* 戦闘不能を解除する効果を持つアイテムか
*/
dataManager.isResurrectionItem = function (item) {
return item.effects.some(
(effect) =>
effect.code === Game_Action.EFFECT_REMOVE_STATE && effect.dataId === Game_BattlerBase.prototype.deathStateId()
);
};
}

DataManager_SealItemMixIn(DataManager);

function Game_Map_SealItemMixIn(gameMap: Game_Map) {
gameMap.isItemSealed = function (item) {
if (!$dataMap) {
return false;
}
if ($dataMap.meta.sealItems) {
if (String($dataMap.meta.sealItems).split(",").map(id => Number(id)).includes(item.id)) {
return true;
}
}
return !!$dataMap.meta.sealAllItem
|| !!$dataMap.meta.sealHealItem && DataManager.isHealItem(item)
|| !!$dataMap.meta.sealResurrectionItem && DataManager.isResurrectionItem(item);
};
}

Game_Map_SealItemMixIn(Game_Map.prototype);

function Game_Actor_SealItemMixIn(gameActor: Game_Actor) {
const _meetsItemConditions = gameActor.meetsItemConditions;
gameActor.meetsItemConditions = function (item) {
return _meetsItemConditions.call(this, item) && !this.isItemSealed(item);
};

gameActor.isItemSealed = function (item) {
return this.traits(sealAllItemTraitId.id).length > 0
|| this.traitsSet(sealItemByIdTraitId.id).includes(item.id)
|| this.traits(sealHealItemTraitId.id).length > 0 && DataManager.isHealItem(item)
|| this.traits(sealResurrectionItemTraitId.id).length > 0 && DataManager.isResurrectionItem(item)
|| !!$gameMap && $gameMap.isItemSealed(item)
};
}

Game_Actor_SealItemMixIn(Game_Actor.prototype);
16 changes: 16 additions & 0 deletions src/codes/SealItem/SealItem.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="../../typings/rmmz.d.ts" />
/// <reference path="../AllocateUniqueTraitId/AllocateUniqueTraitId.d.ts" />

declare namespace DataManager {
function sealItems(object: DataManager.NoteHolder): number[];
function isHealItem(item: MZ.Item): boolean;
function isResurrectionItem(item: MZ.Item): boolean;
}

declare interface Game_Map {
isItemSealed(item: MZ.Item): boolean;
}

declare interface Game_Actor {
isItemSealed(item: MZ.Item): boolean;
}
39 changes: 24 additions & 15 deletions src/codes/SealItem/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ DarkPlasma_SealItem:
year: 2021
license: MIT
histories:
- date: '2021/07/05'
version: '1.0.2'
- date: 2023/05/27
version: 2.0.0
description: 'TypeScript移行'
- description: '特徴の制御をAllocateUniqueTraitIdに任せる'
- description: 'マップのメモ欄に対応'
- date: 2021/07/05
version: 1.0.2
description: 'MZ 1.3.2に対応'
- date: '2021/06/22'
version: '1.0.1'
- date: 2021/06/22
version: 1.0.1
description: 'サブフォルダからの読み込みに対応'
- date: '2021/03/13'
version: '1.0.0'
- date: 2021/03/13
version: 1.0.0
description: '公開'

locates:
Expand All @@ -22,19 +27,23 @@ DarkPlasma_SealItem:
structures:
dependencies:
base:
- name: DarkPlasma_AllocateUniqueTraitId
version: 1.0.1
orderAfter:
orderBefore:
- name: DarkPlasma_AllocateUniqueTraitId
orderBefore: []
help:
ja: |
メモ欄に特定の書式で記述することにより、特定のアイテムを使用不能にします。
メモ欄に特定の書式で記述することにより、
特定のアイテムが使用不能になる特徴を追加します。
<sealAllItem>
全てのアイテムが使用できなくなります。
<sealItems:1,2>
アイテムID1及び2のアイテムが使用できなくなります。
アイテムID1及び2のアイテムが使用できなくなります。
<sealHealItem>
HPまたはMP回復アイテムが使用不能になります
HPまたはMP回復アイテムが使用できなくなります
<sealResurrectionItem>
戦闘不能解除の効果を持つアイテムが使用不能になります
戦闘不能解除の効果を持つアイテムが使用できなくなります
アクターのメモ欄: 対象のアクターは使用不能
職業のメモ欄: 対象の職業のアクターは使用不能
武器・防具のメモ欄: 対象を装備したアクターは使用不能
ステート: 対象ステートにかかったアクターは使用不能
同様のタグをマップのメモ欄に記述することにより、
対象マップ内では特定のアイテムが使用不能になります。

0 comments on commit 6e3a0c7

Please sign in to comment.