예제 #1
0
 public function random()
 {
     $builds = TeamComp::lists('id');
     shuffle($builds);
     $team = TeamComp::find($builds[0]);
     $team->load('itemsets.itemset_blocks.items', 'itemsets.champion');
     foreach ($team->itemsets as $itemset) {
         $items = [];
         foreach ($itemset->itemset_blocks as $block) {
             if ($block->type == 0) {
                 $itemset->items = $block->items;
             }
         }
     }
     return $team;
 }
예제 #2
0
 public function team_comps()
 {
     $path = storage_path() . "/fill/itemsets_teamcomps.json";
     if (!File::exists($path)) {
         throw new Exception("Invalid File");
     }
     $file = File::get($path);
     $obj = json_decode($file);
     $teamcomps = [];
     foreach ($obj as $teamcomp) {
         $teamcomp->name = ucwords(strtolower($teamcomp->name));
         $slug = \Illuminate\Support\Str::slug($teamcomp->name);
         $team = TeamComp::firstOrNew(['name' => $teamcomp->name, 'slug' => $slug]);
         $team->description = $teamcomp->description;
         $video = preg_replace("/(?:https:\\/\\/|http:\\/\\/)?(?:www\\.)?(?:youtube\\.com|youtu\\.be)\\/(?:watch\\?v=)?/", "http://www.youtube.com/embed/", $teamcomp->video);
         $team->video = $video;
         if (isset($teamcomp->author)) {
             $team->author = $teamcomp->author;
         } else {
             $team->author = 'Anverid';
         }
         $team->save();
         foreach ($teamcomp->champions as $champion) {
             $custom = false;
             $customItemset;
             $champ = Champion::where('riot_id', $champion)->first();
             if (isset($teamcomp->itemsets)) {
                 foreach ($teamcomp->itemsets as $itemset) {
                     if ($itemset->champion == $champion) {
                         $custom = true;
                         $customItemset = $itemset;
                     }
                 }
             }
             $name = $custom ? $champ->name . ' - ' . $team->name : 'Frequent ' . $champ->name;
             $itemset = Itemset::firstOrNew(['name' => $name, 'champion_id' => $champion]);
             $frequent_set = WinrateBuild::where(['champion_id' => $champion, 'bestrate' => false, 'order' => 1])->first()->itemsets()->first();
             $frequent_set->load('itemset_blocks', 'itemset_blocks.items');
             // Get the custom itemset - if it was not made, use the frequent set.
             // SPELL ORDER
             if ($custom && isset($customItemset->spell_order) && count($customItemset->spell_order)) {
                 $itemset->point1 = $customItemset->spell_order->point1;
                 $itemset->point2 = $customItemset->spell_order->point2;
                 $itemset->point3 = $customItemset->spell_order->point3;
                 $itemset->max1 = $customItemset->spell_order->max1;
                 $itemset->max2 = $customItemset->spell_order->max2;
                 $itemset->max3 = $customItemset->spell_order->max3;
             } else {
                 $itemset->point1 = $frequent_set->point1;
                 $itemset->point2 = $frequent_set->point2;
                 $itemset->point3 = $frequent_set->point3;
                 $itemset->max1 = $frequent_set->max1;
                 $itemset->max2 = $frequent_set->max2;
                 $itemset->max3 = $frequent_set->max3;
             }
             // SUMMONER SPELLS
             if ($custom && isset($customItemset->summoner_spells) && count($customItemset->summoner_spells)) {
                 $itemset->summoner1 = $customItemset->summoner_spells[0];
                 $itemset->summoner2 = $customItemset->summoner_spells[1];
             } else {
                 $itemset->summoner1 = $frequent_set->summoner1;
                 $itemset->summoner2 = $frequent_set->summoner2;
             }
             $team->itemsets()->save($itemset);
             $blockStarting = ItemsetBlock::firstOrNew(['name' => 'Starting Items', 'type' => 1, 'itemset_id' => $itemset->id]);
             $itemset->itemset_blocks()->save($blockStarting);
             // STARTING ITEMS
             if ($custom && isset($customItemset->starting_items) && count($customItemset->starting_items)) {
                 // Read them from the custom itemset
                 $startings_count = [];
                 foreach ($customItemset->starting_items as $value) {
                     if (isset($startings_count[(string) $value])) {
                         $startings_count[(string) $value] = $startings_count[(string) $value] + 1;
                     } else {
                         $startings_count[(string) $value] = 1;
                     }
                 }
                 $counter = 0;
                 foreach ($startings_count as $key => $value) {
                     $item = Item::where('riot_id', $key)->first();
                     if (!$blockStarting->items->contains($item->id)) {
                         $blockStarting->items()->save($item, ['count' => $value, 'order' => $counter]);
                     }
                     $counter++;
                 }
             } else {
                 $block = $frequent_set->itemset_blocks()->where('type', 1)->first();
                 $items = $block->items()->get();
                 foreach ($items as $item) {
                     if (!$blockStarting->items->contains($item->id)) {
                         $blockStarting->items()->save($item, ['count' => $item->pivot->count, 'order' => $item->pivot->order]);
                     }
                 }
             }
             $blockFinal = ItemsetBlock::firstOrNew(['name' => 'Core Items', 'type' => 0, 'itemset_id' => $itemset->id]);
             $itemset->itemset_blocks()->save($blockFinal);
             // FINAL ITEMS
             if ($custom && isset($customItemset->items) && count($customItemset->items)) {
                 foreach ($customItemset->items as $key) {
                     $item = Item::where('riot_id', $key)->first();
                     if (!$blockFinal->items->contains($item->id)) {
                         $blockFinal->items()->save($item, ['count' => $value, 'order' => $counter]);
                     }
                     $counter++;
                 }
             } else {
                 $block = $frequent_set->itemset_blocks()->where('type', 0)->first();
                 $items = $block->items()->get();
                 foreach ($items as $item) {
                     if (!$blockFinal->items->contains($item->id)) {
                         $blockFinal->items()->save($item, ['count' => $item->pivot->count, 'order' => $item->pivot->order]);
                     }
                 }
             }
         }
         array_push($teamcomps, $team);
     }
     return TeamComp::with('itemsets.itemset_blocks.items')->get();
     return $teamcomps;
 }