Beispiel #1
0
 public static function flipMogs($match_id, $active_player_id, $count)
 {
     //arrays for id's to be flipped and active ids for owner update
     $flip_ids = [];
     $active_ids = [];
     //Get the mogs
     $mogs = PlayField::getActiveMogs($match_id);
     //Build array of random indexes for flip
     for ($i = 0; $i < $count; $i++) {
         $flipIdx = rand(0, count((array) $mogs) - 1);
         $flip_ids[] = $mogs[$flipIdx]->id;
         array_splice($mogs, $flipIdx, 1);
     }
     //flip them
     DB::table('PlayField')->where('match_id', '=', $match_id)->where('flipped', '=', 0)->whereIn('id', $flip_ids)->update(['flipped' => 1, 'new_owner_id' => $active_player_id, 'show_animation' => 1]);
     //Get flipped Mogs active id for update
     $flipped_mogs = DB::table('PlayField')->whereIn('id', $flip_ids)->get();
     //build array of active ids from flipped mogs
     foreach ($flipped_mogs as $mog) {
         $active_ids[] = $mog->mog_id;
     }
     //update Activated Mog's owner
     ActivatedMogs::updateOwner($active_ids, $active_player_id);
 }
Beispiel #2
0
 public function calcRoundOutcome($slam_time)
 {
     //determine round_bias from given slam time
     if ($slam_time == 0) {
         $round_bias = 0;
     } else {
         if ($slam_time > 1 && $slam_time <= 200) {
             $round_bias = 1;
         } else {
             if ($slam_time > 200 && $slam_time <= 300) {
                 $round_bias = 0.9;
             } else {
                 if ($slam_time > 300 && $slam_time <= 600) {
                     $round_bias = 0.8;
                 } else {
                     if ($slam_time > 600 && $slam_time <= 700) {
                         $round_bias = 0.7;
                     } else {
                         if ($slam_time > 700 && $slam_time <= 900) {
                             $round_bias = 0.6;
                         } else {
                             if ($slam_time > 900 && $slam_time <= 1200) {
                                 $round_bias = 0.5;
                             } else {
                                 if ($slam_time > 1200 && $slam_time <= 1600) {
                                     $round_bias = 0.4;
                                 } else {
                                     if ($slam_time > 1600 && $slam_time <= 2100) {
                                         $round_bias = 0.3;
                                     } else {
                                         if ($slam_time > 2100 && $slam_time <= 4000) {
                                             $round_bias = 0.2;
                                         } else {
                                             $round_bias = 0.1;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     //get count of available mogs for this match
     $available_mog_count = PlayField::getActiveMogs($this->id);
     $available_mog_count = count((array) $available_mog_count);
     //get number to be flipped
     $flip_count = 40 * $round_bias;
     //make sure number to be flipped doesn't exceed available
     if ($flip_count > $available_mog_count) {
         $flip_count = $available_mog_count;
     }
     //Flip the mogs
     PlayField::flipMogs($this->id, $this->active_player_id, $flip_count);
     //update count of mogs for player
     if ($this->active_player_id == $this->p1_id) {
         $this->p1_mog_count += $flip_count;
     } else {
         $this->p2_mog_count += $flip_count;
     }
     $this->save();
 }