本文整理汇总了PHP中Stat::advanced_avoidance方法的典型用法代码示例。如果您正苦于以下问题:PHP Stat::advanced_avoidance方法的具体用法?PHP Stat::advanced_avoidance怎么用?PHP Stat::advanced_avoidance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stat
的用法示例。
在下文中一共展示了Stat::advanced_avoidance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculate
public static function calculate($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 = array();
});
// 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', 'DESC')->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->remember(Config::get('site.cache_length'))->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);
}
//.........这里部分代码省略.........