$mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => 'gamedb2002_' . $mysql_conf['instance_id'] )); return $conn; } protected function getTank($tank_id) { $tank_meta_table = require('../res/tank@tank.php'); $tank_meta = getTankConfig($tank_meta_table, $tank_id); $t = array( 'id' => $tank_meta['id'], 'name' => $tank_meta['name'], 'cost' => $tank_meta['cost'], 'cost_int' => $tank_meta['cost_int'], 'max_lv' => $tank_meta['max_lv'], 'compose' => $tank_meta['compose'], 'debris' => $tank_meta['debris'], ); return $t; } protected function getExplode($string) { $delim = "|"; $drop_multiply = explode($delim, $string); $delim1 = ":"; $arr = array(); for ($i = 0; $i < count($drop_multiply); $i++) { $mul = explode($delim1, $drop_multiply[$i]); array_push($arr, $mul); } return $arr; } protected function getParameter($para_id) { $g_conf_para_cluster = require('../res/parameter@parameter.php'); $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); $p = array( 'id' => $para_conf['id'], 'param_name' => $para_conf['param_name'], 'param_value' => $para_conf['param_value'], ); return $p; } protected function updateActiveTime($row, $conn) { $ret = $conn->execScript('UPDATE tank SET active_time=0, experience_level=0, experience_type=0, modify_time=:modify_time ' . ' WHERE accountid=:account_id AND tank_id=:tank_id;', array( ':account_id' => $row['accountid'], ':tank_id' => $row['tank_id'], ':modify_time' => time() )); if (!$ret) { die(); } if ($row['tank_status'] == 0 && $row['experience_type'] == 1) { $ret = $conn->execScript('UPDATE tank SET tank_status=2, modify_time=:modify_time ' . ' WHERE accountid=:account_id AND tank_id=:tank_id;', array( ':account_id' => $row['accountid'], ':tank_id' => $row['tank_id'], ':modify_time' => time() )); if (!$ret) { die(); } $ret = $conn->execScript('UPDATE tank SET skin_status=0, modify_time=:modify_time ' . ' WHERE accountid=:account_id AND tank_id=15001;', array( ':account_id' => $row['accountid'], ':modify_time' => time() )); if (!$ret) { die(); } } } public function tankInfo() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); $tank_list = array(); if(!$conn){ phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); return; } $tank_meta_table = require('../res/tank@tank.php'); $t = $this->getTank(15001); if(!$t){ phpcommon\sendError(ERR_USER_BASE + 1,'没有这个坦克'); return; } $tank_status = 0; $rowCount = $conn->execQueryRowCount('SELECT tank_id FROM tank WHERE accountid = :account_id;', array( ':account_id' => $account_id )); if ($rowCount == 0) { for ($i = 15001; $i <= count($tank_meta_table) + 15000; $i++) { $t = $this->getTank($i); if (!$t) { phpcommon\sendError(ERR_USER_BASE + 1,'没有这个坦克'); return; } if ($i == 15001) { $tank_status = 0; } else { $tank_status = 2; } $ret = $conn->execScript('INSERT INTO tank(accountid, tank_id, tank_status, fragment_id, fragment_num, active_time, tank_level, experience_level, experience_type, create_time, modify_time) ' . ' VALUES(:account_id, :tank_id, :tank_status, :fragment_id, 0, 0, 1, 0, 0, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:account_id, tank_id=:tank_id, tank_status=:tank_status, fragment_id=:fragment_id, fragment_num=0, active_time=0, tank_level=1, experience_level=0, experience_type=0, modify_time=:modify_time;', array( ':account_id' => $account_id, ':tank_id' => $i, ':fragment_id' => $t['debris'], ':tank_status' => $tank_status, ':create_time' => time(), ':modify_time' => time() )); if(!$ret){ die(); return; } } } $tank_level = 0; $tank_status = 0; $rows = $conn->execQuery('SELECT * FROM tank WHERE accountid = :account_id;', array( ':account_id' => $account_id, )); foreach ($rows as $row) { $t = $this->getTank($row['tank_id']); if(time() >= $row['active_time'] && $row['active_time'] != 0){ $this->updateActiveTime($row, $conn); } } $rowsTank = $conn->execQuery('SELECT * FROM tank WHERE accountid = :account_id;', array( ':account_id' => $account_id, )); $tank_id = 0; foreach ($rowsTank as $rowTank) { if ($tank_id == $rowTank['tank_id']) { continue; } $tank_id = $rowTank['tank_id']; if ($rowTank['active_time'] != 0) { $tank_level = $rowTank['experience_level']; } else { $tank_level = $rowTank['tank_level']; } array_push($tank_list, array( 'tank_id' => $rowTank['tank_id'], 'tank_level' => $tank_level, 'active_time' => $rowTank['active_time'], 'tank_status' => $rowTank['tank_status'], 'fragment_id' => $rowTank['fragment_id'], 'fragment_num' => $rowTank['fragment_num'], )); } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'tank_list' => $tank_list )); } public function unlockTank() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); $tank_id = $_REQUEST['tank_id']; if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); return; } $t = $this->getTank($tank_id); if (!$t) { phpcommon\sendError(ERR_USER_BASE + 2,'没有这个坦克'); return; } $row = $conn->execQueryOne('SELECT tank_status, fragment_num, fragment_id FROM tank WHERE accountid=:account_id AND tank_id=:tank_id;', array( ':account_id' => $account_id, ':tank_id' => $tank_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 3,'没有这个坦克'); return; } if ($row['tank_status'] == 1) { phpcommon\sendError(ERR_USER_BASE + 4,'坦克已解锁'); return; } $num = 0; $array = $this->getExplode($t['compose']); if ($row['fragment_num'] < $array[0][1]) { phpcommon\sendError(ERR_USER_BASE + 2,'坦克碎片数量不足'); return; } $fragment_num = $row['fragment_num'] - $array[0][1]; $ret = $conn->execScript('UPDATE tank SET tank_status=1, fragment_num=:fragment_num, modify_time=:modify_time ' . ' WHERE accountid=:account_id AND tank_id=:tank_id;', array( ':account_id' => $account_id, ':tank_id' => $tank_id, ':fragment_num' => $fragment_num, ':modify_time' => time() )); if (!$ret) { die(); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', "tank_id" => $tank_id, "tank_status" => 1, "fragment_id" => $row['fragment_id'], "fragment_num" => $fragment_num, )); } public function exchangeTank() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $usingtank_id = $_REQUEST['usingtank_id']; $exchangetank_id = $_REQUEST['exchangetank_id']; $conn = $this->getMysql($account_id); if(!$conn){ phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $tank_status = 0; $tank_list = array(); $row = $conn->execQueryOne('SELECT * FROM tank WHERE accountid=:accountid AND tank_id=:tank_id;', array( ':accountid' => $account_id, ':tank_id' => $usingtank_id, )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个皮肤'); return; } if ($row['experience_type'] == 0 || $row['experience_type'] == 2) { $tank_status = 1; } else if ($row['experience_type'] == 1) { $skin_status = 2; } //正在使用的坦克 $using_ret = $conn->execScript('UPDATE tank SET tank_status=:tank_status, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND tank_id = :tank_id;', array( ':account_id' => $account_id, ':tank_id' => $usingtank_id, ':tank_status' => $tank_status, ':modify_time' => time() )); if(!$using_ret){ die(); return; } $tank_list = array(); array_push($tank_list, array( 'tank_id' => $usingtank_id, 'tank_status' => $tank_status, )); //准备上阵的坦克 $tank_status = 0; $row_exchange = $conn->execQueryOne('SELECT tank_status FROM tank WHERE accountid=:accountid AND tank_id=:tank_id;', array( ':accountid' => $account_id, ':tank_id' => $exchangetank_id, )); if (!$row_exchange) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个皮肤'); return; } $exchange_ret = $conn->execScript('UPDATE tank SET tank_status=0, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND tank_id = :tank_id;', array( ':account_id' => $account_id, ':tank_id' => $exchangetank_id, ':modify_time' => time() )); if(!$exchange_ret){ die(); return; } array_push($tank_list, array( 'tank_id' => $exchangetank_id, 'tank_status' => $tank_status, )); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', "tank_list" => $tank_list, )); } public function freeTryTank() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1,'没有这个角色'); return; } $tank_id = $_REQUEST['tank_id']; $row = $conn->execQueryOne('SELECT tank_status FROM tank WHERE accountid=:accountid AND tank_id=:tank_id;', array( ':accountid' => $account_id, ':tank_id' => $tank_id, )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 1,'没有这个角色'); return; } $t = $this->getTank($tank_id); if(!$t){ phpcommon\sendError(ERR_USER_BASE + 2,'没有这个坦克'); return; } $time = 0; $ex_level = 0; $ex_type = 0; $ex_level = $t['max_lv']; $p = $this->getParameter(SKIN_SKILL_TIME); $time = $p['param_value']; if ($row['tank_status'] <= 1) { $ex_type = 2; } else { $ex_type = 1; } $ret = $conn->execScript('UPDATE tank SET active_time=:active_time, experience_level=:experience_level, experience_type=:experience_type, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND tank_id = :tank_id;', array( ':account_id' => $account_id, ':tank_id' => $tank_id, ':active_time' => time() + $time, ':experience_level' => $ex_level, ':experience_type' => $ex_type, ':modify_time' => time() )); if (!$ret) { die(); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'tank_id' => $tank_id, 'active_time' => time() + $time, 'tank_level' => $ex_level, )); } public function updateTank() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个角色'); return; } $tank_id = $_REQUEST['tank_id']; $free = $_REQUEST['free']; $row = $conn->execQueryOne('SELECT tank_level, fragment_num, fragment_id FROM tank WHERE accountid=:account_id AND tank_id=:tank_id;', array( ':account_id' => $account_id, ':tank_id' => $tank_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 1, '坦克不存在'); return; } $t = $this->getTank($tank_id); if (!$t) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个坦克'); return; } if ($row['tank_level'] >= $t['max_lv']) { phpcommon\sendError(ERR_USER_BASE + 3, '坦克已到满级'); return; } $coin_num = $t['cost'] * ceil($row['tank_level'] / 5) + $t['cost_int']; if ($free == 1) { $coin_num = 0; } if ($coin_num > $row['fragment_num'] ){ phpcommon\sendError(ERR_USER_BASE + 4, '坦克碎片数量不足'); return; } $ret = $conn->execScript('UPDATE tank SET tank_level=:tank_level, fragment_num=:fragment_num, modify_time=:modify_time ' . ' WHERE accountid=:account_id AND tank_id=:tank_id;', array( ':account_id' => $account_id, ':tank_id' => $tank_id, ':tank_level' => $row['tank_level'] + 1, ':fragment_num' => $row['fragment_num'] - $coin_num, ':modify_time' => time() )); if (!$ret) { die(); return; } $quest = new classes\Quest(); $quest->triggerQuest(QUEST_DAY_UPDATETANK, 1, 1, $account_id); if ($row['tank_level'] + 1 >= $t['max_lv']) { $quest->triggerQuest(QUEST_SUM_TANKMAX, 2, 1, $account_id); } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'tank_id' => $tank_id, 'tank_level' => $row['tank_level'] + 1, "fragment_id" => $row['fragment_id'], "fragment_num" => $row['fragment_num'] - $coin_num, )); } } ?>