Ejemplo n.º 1
0
 private function makeLobbies()
 {
     $ret = ['' => Yii::t('app', 'Unknown')];
     foreach (Lobby::find()->orderBy('[[id]] ASC')->all() as $model) {
         $ret[$model->id] = Yii::t('app-rule', $model->name);
     }
     return $ret;
 }
Ejemplo n.º 2
0
 private function makeLobbiesList()
 {
     $ret = ['' => Yii::t('app-rule', 'Any Lobby')];
     $tmpList = Lobby::find()->orderBy('[[id]] ASC')->all();
     foreach ($tmpList as $lobby) {
         $ret[$lobby->key] = Yii::t('app-rule', $lobby->name);
     }
     return $ret;
 }
Ejemplo n.º 3
0
 public function rules()
 {
     return [[['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['lobby'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'key'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key', 'when' => function () {
         return substr($this->rule, 0, 1) !== '@';
     }], [['rule'], 'validateGameMode', 'when' => function () {
         return substr($this->rule, 0, 1) === '@';
     }], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key', 'when' => function () {
         return !in_array(substr($this->weapon, 0, 1), ['@', '+', '*'], true);
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => WeaponType::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '@';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Subweapon::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '+';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Special::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '*';
     }], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose'], [['term'], 'in', 'range' => ['this-period', 'last-period', '24h', 'today', 'yesterday', 'term']], [['term_from', 'term_to'], 'date', 'format' => 'yyyy-M-d H:m:s']];
 }
Ejemplo n.º 4
0
 public function createCurrentData()
 {
     $db = Yii::$app->db;
     static $nawabari = null;
     if ($nawabari === null) {
         $nawabari = Rule::findOne(['key' => 'nawabari'])->id;
     }
     $condIsNawabari = sprintf('({{battle}}.[[rule_id]] = %s)', $db->quoteValue($nawabari));
     $condIsGachi = sprintf('({{battle}}.[[rule_id]] <> %s)', $db->quoteValue($nawabari));
     static $private = null;
     if ($private === null) {
         $private = Lobby::findOne(['key' => 'private'])->id;
     }
     $condIsNotPrivate = sprintf('({{battle}}.[[lobby_id]] IS NULL OR {{battle}}.[[lobby_id]] <> %s)', $db->quoteValue($private));
     $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time();
     $cond24Hours = sprintf('(({{battle}}.[[end_at]] IS NOT NULL) AND ({{battle}}.[[end_at]] BETWEEN %s AND %s))', $db->quoteValue(gmdate('Y-m-d H:i:sO', $now - 86400 + 1)), $db->quoteValue(gmdate('Y-m-d H:i:sO', $now)));
     $condKDPresent = sprintf('(%s)', implode(' AND ', ['{{battle}}.[[kill]] IS NOT NULL', '{{battle}}.[[death]] IS NOT NULL']));
     $column_battle_count = "COUNT(*)";
     $column_wp = sprintf('(%s * 100.0 / NULLIF(%s, 0))', sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, '{{battle}}.[[is_win]] IS NOT NULL'])));
     $column_wp_short = sprintf("(%s * 100.0 / NULLIF(%s, 0))", sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $cond24Hours, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $cond24Hours, '{{battle}}.[[is_win]] IS NOT NULL'])));
     $column_total_kd_battle_count = sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condKDPresent]));
     $column_total_kill = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[kill]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condKDPresent]));
     $column_total_death = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[death]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condKDPresent]));
     $column_nawabari_count = sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari]));
     $column_nawabari_wp = sprintf('(%s * 100.0 / NULLIF(%s, 0))', sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, '{{battle}}.[[is_win]] IS NOT NULL'])));
     $column_nawabari_kill = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[kill]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, $condKDPresent]));
     $column_nawabari_death = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[death]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, $condKDPresent]));
     $column_gachi_count = sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi]));
     $column_gachi_wp = sprintf('(%s * 100.0 / NULLIF(%s, 0))', sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, '{{battle}}.[[is_win]] IS NOT NULL'])));
     $column_gachi_kill = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[kill]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, $condKDPresent]));
     $column_gachi_death = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[death]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, $condKDPresent]));
     $query = (new \yii\db\Query())->select(['battle_count' => $column_battle_count, 'wp' => $column_wp, 'wp_short' => $column_wp_short, 'total_kill' => $column_total_kill, 'total_death' => $column_total_death, 'total_kd_battle_count' => $column_total_kd_battle_count, 'nawabari_count' => $column_nawabari_count, 'nawabari_wp' => $column_nawabari_wp, 'nawabari_kill' => $column_nawabari_kill, 'nawabari_death' => $column_nawabari_death, 'gachi_count' => $column_gachi_count, 'gachi_wp' => $column_gachi_wp, 'gachi_kill' => $column_gachi_kill, 'gachi_death' => $column_gachi_death])->from('battle')->andWhere(['{{battle}}.[[user_id]]' => $this->user_id]);
     $this->attributes = $query->createCommand()->queryOne();
     $keys = ['battle_count', 'total_kill', 'total_death', 'total_kd_battle_count', 'nawabari_count', 'nawabari_kill', 'nawabari_death', 'gachi_count', 'gachi_kill', 'gachi_death'];
     foreach ($keys as $key) {
         $this->{$key} = (int) $this->{$key};
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLobby()
 {
     return $this->hasOne(Lobby::className(), ['id' => 'lobby_id']);
 }
Ejemplo n.º 6
0
 public function toBattle()
 {
     $user = $this->getUser();
     $o = new Battle();
     $o->user_id = $user->id;
     $o->env_id = $user->env_id;
     $o->lobby_id = $this->lobby ? Lobby::findOne(['key' => $this->lobby])->id : null;
     $o->rule_id = $this->rule ? Rule::findOne(['key' => $this->rule])->id : null;
     $o->map_id = $this->map ? Map::findOne(['key' => $this->map])->id : null;
     $o->weapon_id = $this->weapon ? Weapon::findOne(['key' => $this->weapon])->id : null;
     $o->level = $this->level ? (int) $this->level : null;
     $o->level_after = $this->level_after ? (int) $this->level_after : null;
     $o->rank_id = $this->rank ? Rank::findOne(['key' => $this->rank])->id : null;
     $o->rank_after_id = $this->rank_after ? Rank::findOne(['key' => $this->rank_after])->id : null;
     $o->rank_exp = (string) $this->rank_exp != '' ? (int) $this->rank_exp : null;
     $o->rank_exp_after = (string) $this->rank_exp_after != '' ? (int) $this->rank_exp_after : null;
     $o->cash = (string) $this->cash != '' ? (int) $this->cash : null;
     $o->cash_after = (string) $this->cash_after != '' ? (int) $this->cash_after : null;
     $o->is_win = $this->result === 'win' ? true : ($this->result === 'lose' ? false : null);
     $o->rank_in_team = $this->rank_in_team ? (int) $this->rank_in_team : null;
     $o->kill = (string) $this->kill != '' ? (int) $this->kill : null;
     $o->death = (string) $this->death != '' ? (int) $this->death : null;
     $o->gender_id = $this->gender === 'boy' ? 1 : ($this->gender === 'girl' ? 2 : null);
     $o->fest_title_id = $this->fest_title ? FestTitle::findOne(['key' => $this->fest_title])->id : null;
     $o->fest_title_after_id = $this->fest_title_after ? FestTitle::findOne(['key' => $this->fest_title_after])->id : null;
     $o->fest_exp = (string) $this->fest_exp != '' ? (int) $this->fest_exp : null;
     $o->fest_exp_after = (string) $this->fest_exp_after != '' ? (int) $this->fest_exp_after : null;
     $o->my_team_color_hue = $this->my_team_color ? $this->my_team_color['hue'] : null;
     $o->my_team_color_rgb = $this->my_team_color ? vsprintf('%02x%02x%02x', $this->my_team_color['rgb']) : null;
     $o->his_team_color_hue = $this->his_team_color ? $this->his_team_color['hue'] : null;
     $o->his_team_color_rgb = $this->his_team_color ? vsprintf('%02x%02x%02x', $this->his_team_color['rgb']) : null;
     $o->start_at = $this->start_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->start_at) : null;
     $o->end_at = $this->end_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->end_at) : new Now();
     $o->agent_id = null;
     $o->ua_custom = (string) $this->agent_custom == '' ? null : (string) $this->agent_custom;
     $o->at = new Now();
     $o->is_automated = $this->automated === 'yes';
     $o->my_point = (string) $this->my_point != '' ? (int) $this->my_point : null;
     $o->my_team_final_point = (string) $this->my_team_final_point != '' ? (int) $this->my_team_final_point : null;
     $o->his_team_final_point = (string) $this->his_team_final_point != '' ? (int) $this->his_team_final_point : null;
     $o->my_team_final_percent = (string) $this->my_team_final_percent != '' ? sprintf('%.1f', (double) $this->my_team_final_percent) : null;
     $o->his_team_final_percent = (string) $this->his_team_final_percent != '' ? sprintf('%.1f', (double) $this->his_team_final_percent) : null;
     $o->is_knock_out = $this->knock_out === 'yes' ? true : ($this->knock_out === 'no' ? false : null);
     $o->my_team_count = (string) $this->my_team_count != '' ? (int) $this->my_team_count : null;
     $o->his_team_count = (string) $this->his_team_count != '' ? (int) $this->his_team_count : null;
     $o->events = null;
     if ($this->events) {
         $o->events = json_encode($this->events, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     }
     if ($this->gears) {
         $o->headgear_id = $this->processGear('headgear');
         $o->clothing_id = $this->processGear('clothing');
         $o->shoes_id = $this->processGear('shoes');
     }
     if ($this->isTest) {
         $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time();
         $o->id = 0;
         foreach ($o->attributes as $k => $v) {
             if ($v instanceof Now) {
                 $o->{$k} = gmdate('Y-m-d H:i:sP', $now);
             }
         }
     }
     return $o;
 }
Ejemplo n.º 7
0
 public function rules()
 {
     return [[['lobby_id'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'id'], [['rule_id'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'id'], [['map_id'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'id'], [['weapon_id'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'id']];
 }
 public function safeUp()
 {
     $lobbyStandard = Lobby::findOne(['key' => 'standard'])->id;
     $lobbyFest = Lobby::findOne(['key' => 'fest'])->id;
     $this->update('battle', ['lobby_id' => $lobbyFest], implode(' AND ', ["lobby_id = {$lobbyStandard}", 'gender_id IS NOT NULL', 'fest_title_id IS NOT NULL']));
 }
Ejemplo n.º 9
0
 public function toBattle()
 {
     $o = new Battle();
     $o->user_id = $this->getUser()->id;
     $o->lobby_id = $this->lobby ? Lobby::findOne(['key' => $this->lobby])->id : null;
     $o->rule_id = $this->rule ? Rule::findOne(['key' => $this->rule])->id : null;
     $o->map_id = $this->map ? Map::findOne(['key' => $this->map])->id : null;
     $o->weapon_id = $this->weapon ? Weapon::findOne(['key' => $this->weapon])->id : null;
     $o->level = $this->level ? (int) $this->level : null;
     $o->level_after = $this->level_after ? (int) $this->level_after : null;
     $o->rank_id = $this->rank ? Rank::findOne(['key' => $this->rank])->id : null;
     $o->rank_after_id = $this->rank_after ? Rank::findOne(['key' => $this->rank_after])->id : null;
     $o->rank_exp = (string) $this->rank_exp != '' ? (int) $this->rank_exp : null;
     $o->rank_exp_after = (string) $this->rank_exp_after != '' ? (int) $this->rank_exp_after : null;
     $o->cash = (string) $this->cash != '' ? (int) $this->cash : null;
     $o->cash_after = (string) $this->cash_after != '' ? (int) $this->cash_after : null;
     $o->is_win = $this->result === 'win' ? true : ($this->result === 'lose' ? false : null);
     $o->rank_in_team = $this->rank_in_team ? (int) $this->rank_in_team : null;
     $o->kill = (string) $this->kill != '' ? (int) $this->kill : null;
     $o->death = (string) $this->death != '' ? (int) $this->death : null;
     $o->gender_id = $this->fest_gender === 'boy' ? 1 : ($this->fest_gender === 'girl' ? 2 : null);
     $o->fest_title_id = $this->fest_rank ? FestTitle::findOne(['key' => $this->fest_rank])->id : null;
     $o->my_team_color_hue = $this->my_team_color ? $this->my_team_color['hue'] : null;
     $o->my_team_color_rgb = $this->my_team_color ? vsprintf('%02x%02x%02x', $this->my_team_color['rgb']) : null;
     $o->his_team_color_hue = $this->his_team_color ? $this->his_team_color['hue'] : null;
     $o->his_team_color_rgb = $this->his_team_color ? vsprintf('%02x%02x%02x', $this->his_team_color['rgb']) : null;
     $o->start_at = $this->start_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->start_at) : null;
     $o->end_at = $this->end_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->end_at) : new Now();
     $o->agent_id = null;
     $o->at = new Now();
     return $o;
 }
 public function safeUp()
 {
     $lobbyStandard = Lobby::findOne(['key' => 'standard'])->id;
     $lobbyFest = Lobby::findOne(['key' => 'fest'])->id;
     $this->update('battle', ['lobby_id' => $lobbyStandard], ['lobby_id' => $lobbyFest, 'gender_id' => null, 'fest_title_id' => null]);
 }