public function validateGameMode($attr, $params) { $value = substr($this->{$attr}, 1); $isExist = !!GameMode::findOne(['key' => $value]); if (!$isExist) { $this->addError($attr, Yii::t('yii', '{attribute} is invalid.', ['attribute' => $this->getAttributeLabel($attr)])); } }
public function up() { $this->createTable('game_mode', ['id' => $this->primaryKey(), 'key' => $this->string(16)->notNull()->unique(), 'name' => $this->string(32)->notNull()->unique()]); $this->createTable('rule', ['id' => $this->primarykey(), 'mode_id' => $this->integer()->notNull(), 'key' => $this->string(16)->notNull()->unique(), 'name' => $this->string(32)->notNull()->unique()]); $this->addForeignKey('fk_rule_1', 'rule', 'mode_id', 'game_mode', 'id'); $this->batchInsert('game_mode', ['key', 'name'], [['regular', 'Regular Battle'], ['gachi', 'Ranked Battle']]); $modeRegular = GameMode::findOne(['key' => 'regular'])->id; $modeGachi = GameMode::findOne(['key' => 'gachi'])->id; $this->batchInsert('rule', ['key', 'mode_id', 'name'], [['nawabari', $modeRegular, 'Turf War'], ['area', $modeGachi, 'Splat Zones'], ['yagura', $modeGachi, 'Tower Control'], ['hoko', $modeGachi, 'Rainmaker']]); }
private function makeRules() { $ret = ['' => Yii::t('app', 'Unknown')]; $gameModes = GameMode::find()->orderBy('[[id]] ASC')->all(); foreach ($gameModes as $gameMode) { $gameModeText = Yii::t('app-rule', $gameMode->name); // "ナワバリバトル" $rules = Rule::find()->andWhere(['mode_id' => $gameMode->id])->orderBy('[[id]] ASC')->all(); $mode = []; foreach ($rules as $rule) { $mode[$rule->id] = Yii::t('app-rule', $rule->name); } asort($mode); $ret[$gameModeText] = $mode; } return $ret; }
public function getEntireWeapons() { $rules = []; foreach (GameMode::find()->orderBy('id ASC')->all() as $mode) { $tmp = []; foreach ($mode->rules as $rule) { $weapons = $this->getEntireWeaponsByRule($rule); $tmp[] = (object) ['key' => $rule->key, 'name' => Yii::t('app-rule', $rule->name), 'data' => $weapons, 'sub' => $this->convertWeapons2Sub($weapons), 'special' => $this->convertWeapons2Special($weapons)]; } usort($tmp, function ($a, $b) { return strnatcasecmp($a->name, $b->name); }); while (!empty($tmp)) { $rules[] = array_shift($tmp); } } return $rules; }
public function run() { $filter = new BattleFilterForm(); $filter->load($_GET); $filter->validate(); $data = []; $modes = GameMode::find()->orderBy('id')->all(); foreach ($modes as $mode) { $tmpData = []; foreach ($mode->rules as $rule) { $tmpData[] = (object) ['key' => $rule->key, 'name' => Yii::t('app-rule', $rule->name), 'data' => $this->makeData($rule, $filter)]; } usort($tmpData, function ($a, $b) { return strcmp($a->name, $b->name); }); $data = array_merge($data, $tmpData); } return $this->controller->render('kd-win.tpl', ['rules' => $data, 'maps' => $this->maps, 'weapons' => $this->weapons, 'filter' => $filter]); }
private function makeRulesList() { $ret = ['' => Yii::t('app-rule', 'Any Mode')]; $gameModes = GameMode::find()->orderBy('[[id]] ASC')->all(); foreach ($gameModes as $gameMode) { $gameModeText = Yii::t('app-rule', $gameMode->name); // "ナワバリバトル" $rules = Rule::find()->andWhere(['mode_id' => $gameMode->id])->orderBy('[[id]] ASC')->all(); $mode = []; if (count($rules) > 1) { $mode['@' . $gameMode->key] = Yii::t('app-rule', 'All of {0}', $gameModeText); } foreach ($rules as $rule) { $mode[$rule->key] = Yii::t('app-rule', $rule->name); } $ret[$gameModeText] = $mode; } return $ret; }
private function mapUpdateGachi() { echo "gachi...\n"; $gameMode = GameMode::findOne(['key' => 'gachi']); $latestPeriod = $this->getLatestPeriod($gameMode); $currntPeriod = \app\components\helpers\Battle::calcPeriod(time()); $futureOnly = $latestPeriod >= $currntPeriod; $json = array_filter(array_map(function ($item) { $item->period = \app\components\helpers\Battle::calcPeriod(strtotime($item->start)); return $item; }, $this->queryJson($futureOnly ? 'http://splapi.retrorocket.biz/gachi/next_all' : 'http://splapi.retrorocket.biz/gachi')->result), function ($item) use($latestPeriod) { return $item->period > $latestPeriod; }); if (empty($json)) { echo "no data updated.\n"; return; } printf("count(new_data) = %d\n", count($json)); usort($json, function ($a, $b) { return $a->period - $b->period; }); echo "Converting to insert data...\n"; $map = $this->getMapTable(); $rule = $this->getRuleTable($gameMode); $insert = []; foreach ($json as $item) { if (!isset($rule[$item->rule])) { echo "Unknown rule name: {$item->rule}\n"; continue; } foreach ($item->maps as $mapName) { if (isset($map[$mapName])) { $insert[] = [$item->period, $rule[$item->rule], $map[$mapName]]; } else { echo "Unknown map name: {$mapName}\n"; } } } echo "inserting...\n"; Yii::$app->db->createCommand()->batchInsert(PeriodMap::tableName(), ['period', 'rule_id', 'map_id'], $insert)->execute(); echo "done.\n"; }
/** * @return \yii\db\ActiveQuery */ public function getMode() { return $this->hasOne(GameMode::className(), ['id' => 'mode_id']); }