public function getIndex()
 {
     // Get the list
     $list = Session::get('list', []);
     foreach ($list as $k => &$l) {
         // $l starts as the amount integer and we're transforming it to an array
         $l = ['amount' => $l, 'item' => Item::with(array('recipe' => function ($query) {
             $query->limit(1);
         }, 'name'))->find($k)];
         if (count($l['item']->recipe) == 0) {
             unset($list[$k]);
         }
     }
     unset($l);
     $saved_link = [];
     if ($list) {
         foreach ($list as $id => $info) {
             $saved_link[] = $id . ',' . $info['amount'];
         }
     }
     $saved_link = implode(':', $saved_link);
     $job_list = ClassJob::get_name_abbr_list();
     $active = 'list';
     return view('pages.list', compact('active', 'list', 'saved_link', 'job_list'));
 }
 public function getBeasts($id = 0)
 {
     $item = Item::with('name', 'beasts', 'beasts.name', 'beasts.location', 'beasts.location.name')->where('id', $id)->first();
     $beasts = [];
     foreach ($item->beasts as $beast) {
         foreach ($beast->location as $loc) {
             @($beasts[$loc->name->term][ltrim($beast->name->term, '\\x20') . ($loc->pivot->triggered ? '*' : '')][] = $loc->pivot->levels);
         }
     }
     return ['html' => view('partials.beasts-modal', compact('item', 'beasts'))->render()];
 }
 public function getView($id = 0)
 {
     $item = Item::with('name', 'vendors', 'vendors.npc', 'vendors.npc.name', 'vendors.npc.location', 'vendors.npc.location.name')->where('id', $id)->first();
     $vendors = [];
     foreach ($item->vendors as $vendor) {
         $npc = array('id' => $vendor->npc->id, 'name' => $vendor->npc->name->term, 'color' => $vendor->pivot->color);
         foreach ($vendor->npc->location as $loc) {
             if (!isset($vendors[$loc->id])) {
                 $vendors[$loc->id] = array('name' => $loc->name->term, 'npcs' => []);
             }
             $vendors[$loc->id]['npcs'][] = array_merge($npc, $loc->pivot->x ? array('coords' => array('x' => $loc->pivot->x, 'y' => $loc->pivot->y)) : []);
         }
     }
     ksort($vendors);
     return ['html' => view('partials.vendors-modal', compact('item', 'vendors'))->render()];
 }
 public function getIndex()
 {
     // Items that are Materia
     $results = Item::with('name', 'en_name', 'baseparam', 'baseparam.name', 'baseparam.en_name')->where('itemcategory_id', 13)->orderBy('id')->get();
     // Flatten materia list
     $materia_list = array();
     foreach ($results as $row) {
         preg_match('/^(.*)\\sMateria\\s(.*)$/', $row->en_name->term, $matches);
         list($ignore, $name, $power) = $matches;
         if (!isset($materia_list[$name])) {
             $materia_list[$name] = array('icon' => $row->baseparam[0]->en_name->term, 'stat' => $row->baseparam[0]->name->term, 'power' => array());
         }
         $materia_list[$name]['power'][$power] = array('id' => $row->id, 'amount' => $row->baseparam[0]->pivot->nq_amount);
     }
     return view('pages.materia', compact('materia_list'));
 }
 public function postIndex(Request $request)
 {
     $inputs = $request->all();
     $title = preg_replace('/\\s+/m', ' ', preg_replace("/\n/", '', trim($inputs['title'])));
     view()->share('map_title', $title);
     $posted_list = explode('||', $inputs['items']);
     $item_list = array();
     foreach ($posted_list as $row) {
         list($id, $amount) = explode('|', $row);
         $item_list[$id] = $amount;
     }
     view()->share(compact('item_list'));
     if (!empty($item_list)) {
         $items = Item::with('name', 'vendors', 'vendors.npc', 'vendors.npc.name', 'vendors.npc.location', 'vendors.npc.location.name', 'clusters', 'clusters.classjob', 'clusters.classjob.name', 'clusters.classjob.abbr', 'clusters.location', 'clusters.location.name', 'clusters.nodes', 'beasts', 'beasts.name', 'beasts.location')->whereIn('id', array_keys($item_list))->get();
         $map_data = array();
         foreach ($items as $item) {
             foreach ($item->vendors as $v) {
                 foreach ($v->npc->location as $l) {
                     if (!isset($map_data[$l->id])) {
                         $map_data[$l->id] = array('name' => $l->name->term);
                     }
                     if (!isset($map_data[$l->id]['vendors'])) {
                         $map_data[$l->id]['vendors'] = array();
                     }
                     //						// Map ID 			// NPC ID
                     if (!isset($map_data[$l->id]['vendors'][$v->npc->id])) {
                         $map_data[$l->id]['vendors'][$v->npc->id] = array('name' => $v->npc->name->term, 'x' => $l->pivot->x, 'y' => $l->pivot->y, 'items' => array());
                     }
                     $map_data[$l->id]['vendors'][$v->npc->id]['items'][$item->id] = array('needed' => $item_list[$item->id], 'name' => $item->name->term, 'min_price' => $item->min_price, 'max_price' => $item->max_price);
                 }
             }
             foreach ($item->clusters as $c) {
                 if (!isset($map_data[$c->placename_id])) {
                     $map_data[$c->placename_id] = array('name' => is_null($c->location) ? 'unknown' : $c->location->name->term);
                 }
                 if (!isset($map_data[$c->placename_id]['clusters'])) {
                     $map_data[$c->placename_id]['clusters'] = array();
                 }
                 if (!isset($map_data[$c->placename_id]['clusters'][$c->id])) {
                     $map_data[$c->placename_id]['clusters'][$c->id] = array('icon' => $c->icon, 'level' => $c->level, 'classjob' => $c->classjob_id, 'classjob_name' => $c->classjob->name->term, 'classjob_abbr' => $c->classjob->abbr->term, 'x' => $c->x, 'y' => $c->y, 'items' => array());
                 }
                 $map_data[$c->placename_id]['clusters'][$c->id]['items'][$item->id] = array('needed' => $item_list[$item->id], 'name' => $item->name->term, 'min_price' => $item->min_price, 'max_price' => $item->max_price);
             }
             foreach ($item->beasts as $b) {
                 foreach ($b->location as $l) {
                     if (!isset($map_data[$l->id])) {
                         $map_data[$l->id] = array('name' => $b->name->term);
                     }
                     if (!isset($map_data[$l->id]['beasts'])) {
                         $map_data[$l->id]['beasts'] = array();
                     }
                     //						// Map ID 			// NPC ID
                     if (!isset($map_data[$l->id]['beasts'][$b->id])) {
                         $map_data[$l->id]['beasts'][$b->id] = array('name' => $b->name->term, 'levels' => $b->pivot->levels, 'triggered' => $b->pivot->triggered, 'items' => array());
                     }
                     $map_data[$l->id]['beasts'][$b->id]['items'][$item->id] = array('needed' => $item_list[$item->id], 'name' => $item->name->term);
                 }
             }
         }
         view()->share(compact('map_data', 'items'));
     }
     return $this->getIndex();
 }
 public function getIndex()
 {
     list($sections, $translations) = Cache::get('food_sections_' . Config::get('language'), function () {
         $core_crafting_headers = array('CP', 'Control', 'Craftsmanship', 'Careful Desynthesis');
         $core_gathering_headers = array('GP', 'Gathering', 'Perception');
         $core_battle_headers = array('Accuracy', 'Critical Hit Rate', 'Determination', 'Parry', 'Piety', 'Skill Speed', 'Spell Speed', 'Vitality');
         $core_resistances_headers = array('Reduced Durability Loss');
         // Items that are Food
         $results = Item::with('name', 'baseparam', 'baseparam.name', 'baseparam.en_name', 'vendors')->where('itemcategory_id', 5)->orderBy('id')->get();
         // Group the food up
         $food_groups = $translations = [];
         foreach ($results as $item) {
             $stats = $names = $key_name = [];
             foreach ($item->baseparam as $baseparam) {
                 $nq_limit = $baseparam->pivot->nq_limit ?: (int) $baseparam->pivot->nq_amount;
                 $hq_limit = $baseparam->pivot->hq_limit ?: (int) $baseparam->pivot->hq_amount;
                 $translations[$baseparam->en_name->term] = $baseparam->name->term;
                 $stats[$baseparam->en_name->term] = ['name' => $baseparam->name->term, 'nq' => ['amount' => (int) $baseparam->pivot->nq_amount, 'limit' => $nq_limit, 'threshold' => round($nq_limit / ($baseparam->pivot->nq_amount / 100))], 'hq' => ['amount' => (int) $baseparam->pivot->hq_amount, 'limit' => $hq_limit, 'threshold' => $baseparam->pivot->hq_amount == 0 ? 0 : round($hq_limit / ($baseparam->pivot->hq_amount / 100))]];
             }
             if (empty($stats)) {
                 continue;
             }
             // if ($item->id == 10146)
             // 	dd($names, $item);
             // For each combination of two, add a new entry
             foreach ($stats as $i => $i_stats) {
                 foreach ($stats as $j => $j_stats) {
                     // Put stats in alphabetical order
                     $names = [$i, $j];
                     sort($names);
                     $names = implode('|', $names);
                     list($x, $y) = explode('|', $names);
                     $food_groups[$names][$item->id] = ['id' => $item->id, 'has_hq' => $item->has_hq, 'name' => $item->name->term, 'min_price' => $item->min_price, 'vendor_count' => count($item->vendors), 'stats' => [$x => $stats[$x], $y => $stats[$y]]];
                 }
             }
         }
         ksort($food_groups);
         // Break these up into groups
         $sections_base = ['data' => [], 'headers' => [], 'intersections' => []];
         // This order determines how they show up on the page, so it's kind of important to keep it this way
         $sections = ['Crafting' => $sections_base, 'Gathering' => $sections_base, 'Battle' => $sections_base, 'Resistances' => $sections_base];
         foreach ($food_groups as $key => $value) {
             $keys = explode('|', $key);
             $belongs_to = 'Battle';
             // Core tenants of each section
             if (count(array_intersect($core_crafting_headers, $keys)) > 0) {
                 $belongs_to = 'Crafting';
             } elseif (count(array_intersect($core_gathering_headers, $keys)) > 0) {
                 $belongs_to = 'Gathering';
             } elseif (preg_match('/Resistance|Durability/', $key)) {
                 $belongs_to = 'Resistances';
             }
             $sections[$belongs_to]['data'][$key] = $value;
         }
         foreach ($sections as $section_key => $section_array) {
             $single_keys = [];
             foreach (array_keys($section_array['data']) as $keys) {
                 $single_keys = array_merge($single_keys, explode('|', $keys));
             }
             $single_keys = array_unique($single_keys);
             sort($single_keys);
             $sections[$section_key]['headers'] = $single_keys;
             // For Crafting and Gathering, we want the "core tenants" to be first, regardless of the sort().
             if (isset(${'core_' . strtolower($section_key) . '_headers'})) {
                 $sections[$section_key]['headers'] = array_merge(${'core_' . strtolower($section_key) . '_headers'}, array_diff($single_keys, ${'core_' . strtolower($section_key) . '_headers'}));
             }
             // Also get the Intersections
             $intersections = [];
             foreach ($single_keys as $i) {
                 if (!isset($intersections[$i])) {
                     $intersections[$i] = [];
                 }
                 foreach ($single_keys as $j) {
                     if (!isset($intersections[$i][$j])) {
                         $intersections[$i][$j] = 0;
                     }
                     // $looking_for = 2;//$i == $j ? 1 : 2;
                     foreach ($section_array['data'] as $key => $value) {
                         $keys = explode('|', $key);
                         // $matched = 0;
                         // // $bonus = 0;
                         // if (in_array($i, $keys))
                         // 	$matched++;
                         // if (/*$i != $j && */in_array($j, $keys))
                         // 	$matched++;
                         // if (preg_match('/Vitality/', $key))
                         // {
                         // 	$bonus = 1;
                         // 	$matched++;
                         // }
                         // if ($matched == $looking_for + $bonus && count($keys) == $looking_for + $bonus)
                         if ($i == $keys[0] && $j == $keys[1] || $i == $keys[1] && $j == $keys[0]) {
                             // Count base items
                             $intersections[$i][$j] += count($value);
                             // Count HQ items
                             foreach ($value as $x) {
                                 if ($x['has_hq']) {
                                     $intersections[$i][$j]++;
                                 }
                             }
                         }
                     }
                 }
             }
             $sections[$section_key]['intersections'] = $intersections;
         }
         unset($food_groups);
         return array($sections, $translations);
     });
     return view('pages.food', compact('sections', 'translations'));
 }
Exemple #7
0
 public static function get_gear($job_id = 0, $level = 1, $range = 0, $craftable_only = TRUE, $rewardable_too = TRUE)
 {
     // $cache_key = __METHOD__ . '|' . Config::get('language') . '|' . $job_id . ',' . $level . ',' . $range . ($craftable_only ? ('T' . ($rewardable_too ? 'T' : 'F')) : 'F');
     // // Does cache exist?  Return that instead
     // if (Cache::has($cache_key))
     // 	return Cache::get($cache_key);
     // Get the job IDs
     $job = ClassJob::with('en_abbr')->find($job_id);
     $equipment_list = array_flip(Config::get('site.equipment_roles'));
     array_walk($equipment_list, function (&$i) {
         $i = [];
     });
     // Slot data
     $slots = Config::get('site.defined_slots');
     $slot_alias = Config::get('site.slot_alias');
     $slot_cannot_equip = Config::get('site.slot_cannot_equip');
     foreach ($slot_cannot_equip as &$sce) {
         foreach ($sce as &$ce) {
             $ce = $slots[$ce];
         }
     }
     unset($sce, $ce);
     // Make sure the slot avoids pieces with certain stats
     $stat_ids_to_avoid = Stat::get_ids(Stat::avoid($job->en_abbr->term));
     $stat_ids_to_focus = Stat::get_ids(Stat::focus($job->en_abbr->term));
     $boring_stat_ids = Stat::get_ids(Stat::boring());
     $advanced_stat_avoidance = Stat::advanced_avoidance($job->en_abbr->term);
     foreach ($advanced_stat_avoidance as &$ava) {
         // These are in a very specific order.
         // Keep that order in tact.
         list($a, $b) = explode(' w/o ', $ava);
         $ava[0] = Stat::get_ids(array($a))[0];
         $ava[1] = Stat::get_ids(array($b))[0];
     }
     unset($ava);
     // Get all items where:
     // Slot isn't zero
     // It's between the level & level - 10
     // The class can use it
     // craftable only?
     // rewardable?
     foreach ($slots as $slot_identifier => $slot_name) {
         $query = Item::with('name', 'baseparam', 'baseparam.name', 'vendors', 'recipe', 'recipe.classjob', 'recipe.classjob.name')->where('slot', $slot_identifier)->whereBetween('equip_level', array($level - 10, $level + $range))->whereHas('classjob', function ($query) use($job_id) {
             $query->where('classjob.id', $job_id);
         })->whereHas('baseparam', function ($query) use($stat_ids_to_focus) {
             $query->whereIn('baseparam.id', $stat_ids_to_focus);
         })->orderBy('items.equip_level')->orderBy('items.level', 'DESC')->limit(20);
         if ($craftable_only && $rewardable_too) {
             $query->where(function ($query) {
                 $query->whereHas('recipe', function ($query) {
                     $query->where('recipes.item_id', \DB::raw('items.id'));
                 })->orWhere('items.achievable', '1')->orWhere('items.rewarded', '1');
             });
         } elseif ($craftable_only) {
             $query->whereHas('recipe', function ($query) {
                 $query->where('recipes.item_id', \DB::raw('items.id'));
             });
         }
         $items = $query->get();
         $slot = isset($slot_alias[$slot_identifier]) ? $slot_alias[$slot_identifier] : $slot_identifier;
         $role = $slots[$slot];
         foreach ($items as $item) {
             // Kick it to the curb because of attributes?
             // Compare the focused vs the avoids
             $focus = $avoid = 0;
             $param_count = array_fill(1, 100, 0);
             // 73 total stats, 100's pretty safe, not to mention we only really focus on the first dozen
             foreach ($item->baseparam as $param) {
                 $param_count[$param->id]++;
                 if (in_array($param->id, $stat_ids_to_avoid)) {
                     $avoid++;
                 } elseif (in_array($param->id, $stat_ids_to_focus)) {
                     $focus++;
                 }
             }
             if ($advanced_stat_avoidance) {
                 foreach ($advanced_stat_avoidance as $ava) {
                     // If the [0] stat exists, but the [1] stat doesn't, drop the piece completely
                     if ($param_count[$ava[0]] > 0 && $param_count[$ava[1]] == 0) {
                         $avoid += 10;
                     }
                 }
             }
             // Really sell that this should be avoided
             # echo '<strong>' . $item->name->term . ' [' . $item->id . ']</strong> for ' . $role . ' (' . $focus . ',' . $avoid . ')<br>';
             if ($avoid >= $focus || $focus == 0) {
                 continue;
             }
             // if ($item->name->term == 'Linen Cowl')
             // 	dd($item->name->term, $item->slot, $slot, $slot_cannot_equip, $slot_cannot_equip[$item->slot]);
             // Cannot equip attribute?
             if (isset($slot_cannot_equip[$item->slot])) {
                 $item->cannot_equip = implode(',', $slot_cannot_equip[$item->slot]);
             }
             $equipment_list[$role][] = $item;
             # echo '<strong>+ ' . $item->name->term . ' [' . $item->id . ']</strong> for ' . $role . '<br>';
         }
         unset($items);
     }
     $two_handed_weapon_ids = ItemUICategory::two_handed_weapon_ids();
     $leveled_equipment = [];
     // We now have a proper list, but now we need to widdle down further by ilvl
     // foreach (range($level, $level + $range) as $l)
     // {
     foreach ($equipment_list as $role => $items) {
         // Let's find the lowest acceptable level
         // if I'm level 15, and there are level 12 and 17 items, include the level 12 items, but nothing under that
         $lowest_acceptable_level = $level;
         $closest_found = 0;
         // Find max
         foreach ($items as $item) {
             if ($item->equip_level > $closest_found && $item->equip_level <= $level) {
                 $closest_found = $item->equip_level;
             }
         }
         // Drop lesser items
         // OR figure out cannot equip stuff for weapons
         foreach ($items as $key => $item) {
             if ($item->equip_level >= $closest_found) {
                 if (empty($item->cannot_equip) && in_array($item->itemuicategory_id, $two_handed_weapon_ids)) {
                     $item->cannot_equip = 'Off Hand';
                 }
                 //$item->cannot_equip = array_flip(Config::get('site.defined_slots'))['Off Hand'];
                 $leveled_equipment[$role][$item->id] = $item;
             }
         }
     }
     // }
     // Cache the results
     // Cache::put($cache_key, $leveled_equipment, Config::get('site.cache_length'));
     return $leveled_equipment;
 }
 public function postLoad(Request $request)
 {
     $inputs = $request->all();
     $job = $request['job'];
     $level = $request['level'];
     $craftable_only = $request['craftable_only'];
     $rewardable_too = $request['rewardable_too'];
     // All Jobs
     $job_list = ClassJob::get_name_abbr_list();
     // Jobs are capital
     $desired_job = strtoupper($job);
     $job = ClassJob::get_by_abbr($desired_job);
     // What stats do the class like?
     $stat_ids_to_focus = Stat::get_ids(Stat::focus($job->abbr->term));
     view()->share(compact('job_list', 'job', 'stat_ids_to_focus', 'level'));
     $equipment = Item::calculate($job->id, $level, 0, $craftable_only, $rewardable_too);
     return $this->getOutput($equipment);
 }
Exemple #9
0
 /**
  * Get all items matching these parameters
  * @param  [type] $job_id            [description]
  * @param  [type] $level_start       [description]
  * @param  [type] $level_end         [description]
  * @param  [type] $slot_ids          [description]
  * @param  [type] $stat_ids_to_focus [description]
  * @param  [type] $options           [description]
  * @return [type]                    [description]
  */
 private static function items($job_id, $level_start, $level_end, $slot_ids, $stat_ids_to_focus, $options)
 {
     // Get all items where:
     // Slot isn't zero
     // The class can use it
     $query = Item::with('name', 'baseparam', 'baseparam.name', 'vendors', 'recipe', 'recipe.classjob', 'recipe.classjob.name')->whereIn('slot', $slot_ids)->whereBetween('equip_level', [$level_start, $level_end])->whereHas('classjob', function ($query) use($job_id) {
         $query->where('classjob.id', $job_id);
     })->whereHas('baseparam', function ($query) use($stat_ids_to_focus) {
         $query->whereIn('baseparam.id', $stat_ids_to_focus);
     })->orderBy('items.equip_level', 'DESC')->orderBy('items.level', 'DESC');
     if (in_array('craftable', $options)) {
         if (in_array('rewardable', $options)) {
             $query->where(function ($query) {
                 $query->whereHas('recipe', function ($query) {
                     $query->where('recipes.item_id', \DB::raw('items.id'));
                 })->orWhere('items.achievable', '1')->orWhere('items.rewarded', '1');
             });
         } else {
             $query->whereHas('recipe', function ($query) {
                 $query->where('recipes.item_id', \DB::raw('items.id'));
             });
         }
     }
     return $query->get();
 }