public function __isset($var) { if (!character::selected()) { return null; } return (bool) script_variable::get($this->script_name, $var, character::current()->id, false); }
public static function create($name, $type = inventory::TYPE_GENERAL, $character = null) { $char = null; if ($character instanceof character) { $char = $character; } else { if (is_numeric($char)) { $char = character::load_one($character); } else { if (is_string($char)) { $char = character::load_one($character, 'name'); } else { if (!character::selected()) { return false; } else { $char = character::current(); } } } } $inv = new static(); $inv->char_id = $char->id; $inv->type = $type; $inv->name = $name; $inv->save(); return $inv; }
public function log_out_action() { account::log_out(); //is the character still logged in? if yes, log it out if (character::selected()) { character::unselect(); } page::redirect(); }
public function __construct() { //the whole world needs both, valid account and character if (!account::logged_in()) { page::redirect('/account/not-logged-in'); } if (!character::selected()) { page::redirect('/character/select'); } }
public static function format($string, $character = null) { if (!$character) { if (!character::selected()) { return $string; } $character = character::current(); } static $tokens = null; if (!$tokens) { $tokens = static::format_tokens(); } $text = preg_replace_callback('#\\{(?<token>[^\\}]+)\\}#', function ($result) use($tokens, $character) { $token = $result['token']; if (isset($tokens[$token])) { $func = $tokens[$token]; return call_user_func($func, $character); } return 'undefined'; }, $string); return $text; }
public function inventory_action($type) { $type = page::arg('type', $type, 'character'); $charId = page::arg('character_id'); $charName = page::arg('name'); $itemType = page::arg('item_type', null, 'all'); $char = null; if ($charId) { $char = character::load_one($charId); } else { if ($charName) { $char = character::load_one($charName, 'name'); } else { if (!character::selected()) { return api::result(false, array('message' => 'No_character_selected')); } else { $char = character::current(); } } } if (!$type) { $type = 'character'; } $types = array('character' => inventory::TYPE_CHARACTER, 'vault' => inventory::TYPE_VAULT); $itemTypes = array('all' => null, 'usable' => item::TYPE_USABLE, 'enchantable' => item::TYPE_ENCHANTABLE, 'destroyable' => item::TYPE_DESTROYABLE, 'loot' => item::TYPE_LOOT, 'equippable' => item::TYPE_EQUIPPABLE, 'material' => item::TYPE_MATERIAL); if (!isset($types[$type])) { $itemType = (int) $type; } if (!array_key_exists($itemType, $itemTypes)) { return api::result(false, array('message' => 'Invalid_item_type')); } return api::result(true, array($char->inventory($types[$type])->items($itemTypes[$itemType], true))); }
public static function get($value, $field = 'name') { $result = null; if ($value instanceof static) { $result = $value; } else { if (is_numeric($value)) { $result = static::load_one($value); } else { if (is_string($value)) { $result = static::load_one($value, $field); } else { if (character::selected()) { $result = static::current(); } } } } return $result; }