Skip to content

Instantly share code, notes, and snippets.

@Tsumio
Last active January 13, 2018 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tsumio/7a114deb873397fc79c86d73453b8a93 to your computer and use it in GitHub Desktop.
Save Tsumio/7a114deb873397fc79c86d73453b8a93 to your computer and use it in GitHub Desktop.
ArraySample
'use strict';
class Predicates {
static hpLessThanHalf(value, index) {
return value.mhp/2 > value.hp;
}
static isMaxHP(value, index) {
return value.mhp === value.hp;
}
}
class TrapAction {
static fire(actionName, predicate) {
const actionMembers = $gameParty.members().filter(predicate);
this[actionName](actionMembers);
}
//private
static killMembers(actionMembers) {
actionMembers.forEach(function(value, index) {
value.addState(value.deathStateId());
});
}
//private
static addPoisonState(actionMembers) {
actionMembers.forEach(function(value, index) {
value.addState(4);//Poison
});
}
}
class RewardAction {
static tryFire(actionName, predicate) {
const canFire = $gameParty.members().every(predicate);
if(canFire) {
this[actionName]();
}
}
//private
static upToLevelFifty() {
$gameParty.members().forEach(function(value, index) {
value.changeLevel(50, true);
});
}
}
/*以下はスクリプトコマンドから実行する*/
/*
//HP全快のメンバーに毒を付与
TrapAction.fire('addPoisonState', Predicates.isMaxHP);
//HP半分未満のメンバーは死亡
TrapAction.fire('killMembers', Predicates.hpLessThanHalf);
//全メンバーがレベル50以下なら、全メンバー50まで上げる
RewardAction.tryFire('upToLevelFifty', function(value, index) {
return value.level <= 50;
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment