Moved effects stuff to json

This commit is contained in:
Dylan K. Taylor 2017-03-12 19:52:57 +00:00
parent 90abc28c29
commit f58ee2028e
3 changed files with 149 additions and 28 deletions

View File

@ -28,6 +28,7 @@ use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\player\PlayerExhaustEvent; use pocketmine\event\player\PlayerExhaustEvent;
use pocketmine\network\mcpe\protocol\MobEffectPacket; use pocketmine\network\mcpe\protocol\MobEffectPacket;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\Config;
class Effect{ class Effect{
const SPEED = 1; const SPEED = 1;
@ -58,34 +59,23 @@ class Effect{
const SATURATION = 23; const SATURATION = 23;
/** @var Effect[] */ /** @var Effect[] */
protected static $effects; protected static $effects = [];
public static function init(){ public static function init(){
self::$effects = new \SplFixedArray(256); $config = new Config(\pocketmine\PATH . "src/pocketmine/resources/effects.json", Config::JSON, []);
self::$effects[Effect::SPEED] = new Effect(Effect::SPEED, "%potion.moveSpeed", 124, 175, 198); foreach($config->getAll() as $name => $data){
self::$effects[Effect::SLOWNESS] = new Effect(Effect::SLOWNESS, "%potion.moveSlowdown", 90, 108, 129, true); $color = hexdec($data["color"]);
self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "%potion.digSpeed", 217, 192, 67); $r = ($color >> 16) & 0xff;
self::$effects[Effect::FATIGUE] = new Effect(Effect::FATIGUE, "%potion.digSlowDown", 74, 66, 23, true); $g = ($color >> 8) & 0xff;
self::$effects[Effect::STRENGTH] = new Effect(Effect::STRENGTH, "%potion.damageBoost", 147, 36, 35); $b = $color & 0xff;
//self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "%potion.heal", 248, 36, 35); self::registerEffect($name, new Effect($data["id"], "%" . $data["name"], $r, $g, $b, $data["isBad"] ?? false));
//self::$effects[Effect::HARMING] = new InstantEffect(Effect::HARMING, "%potion.harm", 67, 10, 9, true); }
self::$effects[Effect::JUMP] = new Effect(Effect::JUMP, "%potion.jump", 34, 255, 76); }
self::$effects[Effect::NAUSEA] = new Effect(Effect::NAUSEA, "%potion.confusion", 85, 29, 74, true);
self::$effects[Effect::REGENERATION] = new Effect(Effect::REGENERATION, "%potion.regeneration", 205, 92, 171); public static function registerEffect(string $internalName, Effect $effect){
self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "%potion.resistance", 153, 69, 58); self::$effects[$effect->getId()] = $effect;
self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "%potion.fireResistance", 228, 154, 58); self::$effects[$internalName] = $effect;
self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "%potion.waterBreathing", 46, 82, 153);
self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "%potion.invisibility", 127, 131, 146);
self::$effects[Effect::BLINDNESS] = new Effect(Effect::BLINDNESS, "%potion.blindness", 191, 192, 192);
self::$effects[Effect::NIGHT_VISION] = new Effect(Effect::NIGHT_VISION, "%potion.nightVision", 0, 0, 139);
self::$effects[Effect::HUNGER] = new Effect(Effect::HUNGER, "%potion.hunger", 46, 139, 87);
self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "%potion.weakness", 72, 77, 72, true);
self::$effects[Effect::POISON] = new Effect(Effect::POISON, "%potion.poison", 78, 147, 49, true);
self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "%potion.wither", 53, 42, 39, true);
self::$effects[Effect::HEALTH_BOOST] = new Effect(Effect::HEALTH_BOOST, "%potion.healthBoost", 248, 125, 35);
self::$effects[Effect::ABSORPTION] = new Effect(Effect::ABSORPTION, "%potion.absorption", 36, 107, 251);
self::$effects[Effect::SATURATION] = new Effect(Effect::SATURATION, "%potion.saturation", 255, 0, 255);
} }
/** /**
@ -101,8 +91,8 @@ class Effect{
} }
public static function getEffectByName($name){ public static function getEffectByName($name){
if(defined(Effect::class . "::" . strtoupper($name))){ if(isset(self::$effects[$name])){
return self::getEffect(constant(Effect::class . "::" . strtoupper($name))); return clone self::$effects[$name];
} }
return null; return null;
} }

@ -1 +1 @@
Subproject commit 8d56e216be03710208800ba31aa3b63612742623 Subproject commit a1c4d8f117f27b7da42a9db644e3c252c1fc033a

View File

@ -0,0 +1,131 @@
{
"speed": {
"id": 1,
"color": "7cafc6",
"name": "potion.moveSpeed"
},
"slowness": {
"id": 2,
"color": "5a6c81",
"name": "potion.moveSlowdown",
"isBad": true
},
"haste": {
"id": 3,
"color": "d9c043",
"name": "potion.digSpeed"
},
"mining_fatigue": {
"id": 4,
"color": "4a4217",
"name": "potion.digSlowDown",
"isBad": true
},
"strength": {
"id": 5,
"color": "932423",
"name": "potion.damageBoost"
},
"instant_health": {
"id": 6,
"color": "f82423",
"name": "potion.heal"
},
"instant_damage": {
"id": 7,
"color": "430a09",
"name": "potion.harm",
"isBad": true
},
"jump_boost": {
"id": 8,
"color": "22ff4c",
"name": "potion.jump"
},
"nausea": {
"id": 9,
"color": "551d4a",
"name": "potion.confusion",
"isBad": true
},
"regeneration": {
"id": 10,
"color": "cd5cab",
"name": "potion.regeneration"
},
"resistance": {
"id": 11,
"color": "99453a",
"name": "potion.resistance"
},
"fire_resistance": {
"id": 12,
"color": "e49a3a",
"name": "potion.fireResistance"
},
"water_breathing": {
"id": 13,
"color": "2e5299",
"name": "potion.waterBreathing"
},
"invisibility": {
"id": 14,
"color": "7f8392",
"name": "potion.invisibility"
},
"blindness": {
"id": 15,
"color": "1f1f23",
"name": "potion.blindness",
"isBad": true
},
"night_vision": {
"id": 16,
"color": "1f1fa1",
"name": "potion.nightVision"
},
"hunger": {
"id": 17,
"color": "587653",
"name": "potion.hunger",
"isBad": true
},
"weakness": {
"id": 18,
"color": "484d48",
"name": "potion.weakness",
"isBad": true
},
"poison": {
"id": 19,
"color": "4e9331",
"name": "potion.poison",
"isBad": true
},
"wither": {
"id": 20,
"color": "352a27",
"name": "potion.wither",
"isBad": true
},
"health_boost": {
"id": 21,
"color": "f87d23",
"name": "potion.healthBoost"
},
"absorption": {
"id": 22,
"color": "2552a5",
"name": "potion.absorption"
},
"saturation": {
"id": 23,
"color": "f82423",
"name": "potion.saturation"
},
"levitation": {
"id": 24,
"color": "ceffff",
"name": "potion.levitation"
}
}