Last active
January 13, 2018 11:15
-
-
Save Tsumio/7a114deb873397fc79c86d73453b8a93 to your computer and use it in GitHub Desktop.
ArraySample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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