From 3711686abfac76f8cd39b1956ea6aa5d13812fee Mon Sep 17 00:00:00 2001 From: wangwei01 Date: Thu, 11 Jul 2019 14:20:06 +0800 Subject: [PATCH] 1 --- sql/gamedb.sql | 79 +-- webapp/bootstrap/config_loader.php | 11 +- webapp/classes/AddReward.php | 8 +- webapp/classes/Quest.php | 2 +- .../controller/CommanderController.class.php | 451 ++++++++++++++++ .../controller/DouRewardController.class.php | 9 +- webapp/controller/EquipController.class.php | 297 ----------- webapp/controller/HangController.class.php | 34 ++ webapp/controller/QuestController.class.php | 260 +++++----- webapp/controller/RoleController.class.php | 43 +- webapp/controller/ShareController.class.php | 63 +-- webapp/controller/SkinController.class.php | 398 +++----------- webapp/controller/TankController.class.php | 491 ++++++++++++++++++ 13 files changed, 1261 insertions(+), 885 deletions(-) create mode 100644 webapp/controller/CommanderController.class.php delete mode 100644 webapp/controller/EquipController.class.php create mode 100644 webapp/controller/TankController.class.php diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 2589f9b..995b265 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -66,6 +66,54 @@ CREATE TABLE `user` ( UNIQUE KEY `accountid` (`accountid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +-- +-- Table structure for table `commander` +-- + +DROP TABLE IF EXISTS `commander`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `commander` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `commander_id` int(11) NOT NULL COMMENT '指挥官id', + `commander_status` int(11) NOT NULL COMMENT '指挥官状态(0:上阵中,1:已获得,2:未获得)', + `fragment_id` int(11) NOT NULL COMMENT '碎片id', + `fragment_num` int(11) NOT NULL COMMENT '碎片数量', + `commander_type` int(11) NOT NULL COMMENT '指挥官类型', + `commander_level` int(11) NOT NULL COMMENT '指挥官等级', + `experience_level` int(11) NOT NULL COMMENT '指挥官体验等级', + `active_time` varchar(50) NOT NULL DEFAULT '有效时间', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `commander_uuid` (`accountid`, `commander_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +-- +-- Table structure for table `tank` +-- + +DROP TABLE IF EXISTS `tank`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `tank` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `tank_id` int(11) NOT NULL COMMENT '坦克id', + `tank_status` int(11) NOT NULL COMMENT '坦克状态(0:上阵中,1:已获得,2:未获得)', + `tank_level` int(11) NOT NULL COMMENT '坦克等级', + `experience_level` int(11) NOT NULL COMMENT '坦克体验等级', + `experience_type` int(11) NOT NULL COMMENT '坦克体验类型', + `active_time` varchar(50) NOT NULL DEFAULT '有效时间', + `create_time` int(11) NOT NULL COMMENT '创建时间', + `modify_time` int(11) NOT NULL COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `tank_uuid` (`accountid`, `tank_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + -- -- Table structure for table `skin` -- @@ -77,15 +125,7 @@ CREATE TABLE `skin` ( `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', `skin_id` int(11) NOT NULL COMMENT '皮肤id', - `skin_status` int(11) NOT NULL COMMENT '皮肤状态(0:上阵中,1:已获得)', - `fragment_id` int(11) NOT NULL COMMENT '碎片id', - `fragment_num` int(11) NOT NULL COMMENT '碎片数量', - `active_time` varchar(50) NOT NULL DEFAULT '有效时间(体验时间)', - `fragment_status` int(11) NOT NULL COMMENT '碎片收集状态(活动相关)', - `skin_type` int(11) NOT NULL COMMENT '皮肤类型', - `skin_level` int(11) NOT NULL COMMENT '皮肤等级', - `skin_experience_level` int(11) NOT NULL COMMENT '皮肤体验等级', - `skin_experience_type` int(11) NOT NULL COMMENT '皮肤试用类型(0:没试用,1:皮肤体验,2:满级体验)', + `skin_status` int(11) NOT NULL COMMENT '皮肤状态(0:上阵中,1:已获得,2:未获得)', `create_time` int(11) NOT NULL COMMENT '创建时间', `modify_time` int(11) NOT NULL COMMENT '修改时间', PRIMARY KEY (`idx`), @@ -93,27 +133,6 @@ CREATE TABLE `skin` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- --- Table structure for table `equip` --- - -DROP TABLE IF EXISTS `equip`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `equip` ( - `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', - `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', - `equip_id` int(11) NOT NULL COMMENT '装备id', - `equip_level` int(11) NOT NULL COMMENT '装备等级', - `equip_experience_level` int(11) NOT NULL COMMENT '装备体验等级', - `active_time` varchar(50) NOT NULL DEFAULT '有效时间', - `create_time` int(11) NOT NULL COMMENT '创建时间', - `modify_time` int(11) NOT NULL COMMENT '修改时间', - PRIMARY KEY (`idx`), - UNIQUE KEY `equip_uuid` (`accountid`, `equip_id`) -) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; - - -- -- Table structure for table `sign` -- diff --git a/webapp/bootstrap/config_loader.php b/webapp/bootstrap/config_loader.php index e0ec3a9..e4c971d 100644 --- a/webapp/bootstrap/config_loader.php +++ b/webapp/bootstrap/config_loader.php @@ -60,9 +60,10 @@ function getSkinConfig($skin_table ,$item_id) return array_key_exists($item_id, $skin_table) ? $skin_table[$item_id] : null; } -function getEquipConfig($equip_table, $item_id) +function getTankConfig($tank_table, $tank_id) { - return array_key_exists($item_id, $equip_table) ? $equip_table[$item_id] : null; + $tank_id = (int)$tank_id; + return array_key_exists($tank_id, $tank_table) ? $tank_table[$tank_id] : null; } function getSupplyConfig($supply_table, $box_id) @@ -140,5 +141,11 @@ function getShareConfig($share_table, $share_id) $share_id = (int)$share_id; return array_key_exists($share_id, $share_table) ? $share_table[$share_id] : null; } + +function getCommanderConfig($commander_table, $commander_id) +{ + $commander_id = (int)$commander_id; + return array_key_exists($commander_id, $commander_table) ? $commander_table[$commander_id] : null; +} checkMysqlConfig(); checkRedisConfig(); diff --git a/webapp/classes/AddReward.php b/webapp/classes/AddReward.php index 32e6d4f..1771753 100644 --- a/webapp/classes/AddReward.php +++ b/webapp/classes/AddReward.php @@ -13,7 +13,7 @@ class AddReward { 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], - 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + 'dbname' => 'gamedb2002_' . $mysql_conf['instance_id'] )); return $conn; } @@ -41,17 +41,17 @@ class AddReward { die(); } } else if ($item_id > 13000 && $item_id < 14000) { - $rowSkin = $conn->execQueryOne('SELECT fragment_num FROM skin WHERE accountid=:accountid AND fragment_id=:fragment_id;', + $rowCommander = $conn->execQueryOne('SELECT fragment_num FROM commander WHERE accountid=:accountid AND fragment_id=:fragment_id;', array( ':accountid' => $account_id, ':fragment_id' => $item_id )); - $ret = $conn->execScript('UPDATE skin SET fragment_num=:fragment_num, modify_time=:modify_time ' . + $ret = $conn->execScript('UPDATE commander SET fragment_num=:fragment_num, modify_time=:modify_time ' . ' WHERE accountid=:accountid AND fragment_id=:fragment_id;', array( ':accountid' => $account_id, ':fragment_id' => $item_id, - ':fragment_num' => $item_num + $rowSkin['fragment_num'], + ':fragment_num' => $item_num + $rowCommander['fragment_num'], ':modify_time' => time() )); if (!$ret) { diff --git a/webapp/classes/Quest.php b/webapp/classes/Quest.php index ec766cd..2fa00c1 100644 --- a/webapp/classes/Quest.php +++ b/webapp/classes/Quest.php @@ -14,7 +14,7 @@ class Quest{ 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], - 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + 'dbname' => 'gamedb2002_' . $mysql_conf['instance_id'] )); return $conn; } diff --git a/webapp/controller/CommanderController.class.php b/webapp/controller/CommanderController.class.php new file mode 100644 index 0000000..63b452d --- /dev/null +++ b/webapp/controller/CommanderController.class.php @@ -0,0 +1,451 @@ + $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 getCommander($commander_id) + { + $commander_meta_table = require('../res/driver@driver.php'); + $commander_meta = getCommanderConfig($commander_meta_table, $commander_id); + $c = array( + 'id' => $commander_meta['id'], + 'name' => $commander_meta['name'], + 'compose' => $commander_meta['compose'], + 'debris_id' => $commander_meta['debris'], + 'g_type' => $commander_meta['g_type'], + 'cost' => $commander_meta['cost'], + 'cost_int' => $commander_meta['cost_int'], + 'gold_cost_int' => $commander_meta['gold_cost_int'], + 'gold_cost' => $commander_meta['gold_cost'], + 'max_lv' => $commander_meta['max_lv'], + ); + return $c; + } + + 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) + { + $parameter_meta_cluster = require('../res/parameter@parameter.php'); + $parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id); + $p = array( + 'id' => $parameter_meta['id'], + 'param_name' => $parameter_meta['param_name'], + 'param_value' => $parameter_meta['param_value'], + ); + return $p; + } + + protected function updateActiveTime($row, $conn) + { + $ret = $conn->execScript('UPDATE commander SET active_time=0,experience_level=0, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND commander_id=:commander_id;', + array( + ':account_id' => $row['accountid'], + ':commander_id' => $row['commander_id'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } + + public function commanderInfo() + { + $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); + $commander_list = array(); + if(!$conn){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); + return; + } + $commander_meta_table = require('../res/driver@driver.php'); + $c = $this->getCommander(14001); + if (!$c) { + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个指挥官'); + return; + } + $rowCount = $conn->execQueryRowCount('SELECT commander_id FROM commander WHERE accountid = :account_id;', + array( + ':account_id' => $account_id + )); + $commander_status = 0; + if ($rowCount == 0) { + for ($i = 14001; $i <= count($commander_meta_table) + 14000; $i++) { + $c = $this->getCommander($i); + if (!$c) { + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个指挥官'); + return; + } + if ($i == 14001) { + $commander_status = 0; + } else { + $commander_status = 2; + } + $ret = $conn->execScript('INSERT INTO commander(accountid, commander_id, commander_status, fragment_id, fragment_num, commander_type, commander_level, experience_level, active_time, create_time, modify_time) ' . + ' VALUES(:account_id, :commander_id, :commander_status, :fragment_id, 0, :commander_type, 1, 0, 0, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:account_id, commander_id=:commander_id, commander_status=:commander_status, fragment_id=:fragment_id, fragment_num=0, commander_type=:commander_type, commander_level=1, experience_level=0, active_time=0, modify_time=:modify_time;', + array( + ':account_id' => $account_id, + ':commander_id' => $i, + ':commander_status' => $commander_status, + ':fragment_id' => $c['debris_id'], + ':commander_type' => $c['g_type'], + ':create_time' => time(), + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + } + } + $rows = $conn->execQuery('SELECT * FROM commander WHERE accountid = :account_id;', + array( + ':account_id' => $account_id, + )); + $commander_id = 0; + $commander_level = 0; + $time = 0; + foreach ($rows as $row) { + $commander_level = $row['commander_level']; + $c = $this->getCommander($row['commander_id']); + if ($commander_id == $row['commander_id']) { + continue; + } + if ($row['active_time'] != 0) { + if(time() >= $row['active_time']){ + $this->updateActiveTime($row, $conn); + $time = 0; + } else { + $commander_level = $row['experience_level']; + $time = $row['active_time']; + } + } + $commander_id = $row['commander_id']; + array_push($commander_list, array( + 'commander_id' => $commander_id, + 'commander_status' => $row['commander_status'], + 'fragment_num' => $row['fragment_num'], + 'commander_level' => $commander_level, + 'time' => $time, + )); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'commander_list' => $commander_list + )); + } + + + public function unlockCommander() + { + $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); + $commander_id = $_REQUEST['commander_id']; + if(!$conn){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); + return; + } + $c = $this->getCommander($commander_id); + if(!$c){ + phpcommon\sendError(ERR_USER_BASE + 2,'没有这个指挥官'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM commander WHERE accountid=:account_id AND commander_id=:commander_id;', + array( + ':account_id' => $account_id, + ':commander_id' => $commander_id + )); + if(!$row){ + phpcommon\sendError(ERR_USER_BASE + 2,'没有这个指挥官'); + return; + } + $fragment_num = 0; + $array = $this->getExplode($c['compose']); + if ($row['fragment_num'] < $array[0][1]) { + phpcommon\sendError(ERR_USER_BASE + 4,'指挥官碎片数量不足'); + return; + } + $fragment_num = $row['fragment_num'] - $array[0][1]; + + $commander_status = 1; + $ret = $conn->execScript('UPDATE commander SET fragment_num=:fragment_num ,commander_status=:commander_status, modify_time=:modify_time ' . + ' WHERE accountid = :account_id AND commander_id = :commander_id;', + array( + ':account_id' => $account_id, + ':commander_id' => $commander_id, + ':fragment_num' => $fragment_num, + ':commander_status' => $commander_status, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + "commander_id" => $commander_id, + "commander_status" => $commander_status, + "fragment_num" => $fragment_num, + "commander_level" => 1, + )); + } + + public function exchangeCommander() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $usingcommander_id = $_REQUEST['usingcommander_id']; + $exchangecommander_id = $_REQUEST['exchangecommander_id']; + $conn = $this->getMysql($account_id); + if(!$conn){ + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + //正在上阵的指挥官 + $row = $conn->execQueryOne('SELECT * FROM commander WHERE accountid=:accountid AND commander_id=:commander_id;', + array( + ':accountid' => $account_id, + ':commander_id' => $usingcommander_id, + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个指挥官'); + return; + } + $commander_status = 1; + $using_ret = $conn->execScript('UPDATE commander SET commander_status=:commander_status, modify_time=:modify_time ' . + ' WHERE accountid = :account_id AND commander_id = :commander_id;', + array( + ':account_id' => $account_id, + ':commander_id' => $usingcommander_id, + ':commander_status' => $commander_status, + ':modify_time' => time() + )); + + if(!$using_ret){ + die(); + return; + } + $commander_list = array(); + array_push($commander_list, array( + 'commander_id' => $usingcommander_id, + 'commander_status' => $commander_status, + )); + //准备上阵的指挥官 + $commander_status = 0; + $row_exchange = $conn->execQueryOne('SELECT * FROM commander WHERE accountid=:accountid AND commander_id=:commander_id;', + array( + ':accountid' => $account_id, + ':commander_id' => $exchangecommander_id, + )); + $exchange_ret = $conn->execScript('UPDATE commander SET commander_status=0, modify_time=:modify_time ' . + ' WHERE accountid = :account_id AND commander_id = :commander_id;', + array( + ':account_id' => $account_id, + ':commander_id' => $exchangecommander_id, + ':modify_time' => time() + )); + if(!$exchange_ret){ + die(); + return; + } + array_push($commander_list, array( + 'commander_id' => $exchangecommander_id, + 'commander_status' => $commander_status, + )); + + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + "commander_list" => $commander_list, + )); + } + + public function updateCommander() + { + $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; + } + $commander_id = $_REQUEST['commander_id']; + $free = $_REQUEST['free']; + $row = $conn->execQueryOne('SELECT * FROM commander WHERE accountid=:account_id AND commander_id=:commander_id;', + array( + ':account_id' => $account_id, + ':commander_id' => $commander_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 1, '指挥官不存在'); + return; + } + $rowCoin = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:account_id;', + array( + ':account_id' => $account_id, + )); + if (!$rowCoin) { + phpcommon\sendError(ERR_USER_BASE + 1, '指挥官不存在'); + return; + } + $c = $this->getCommander($commander_id); + if (!$c) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个指挥官'); + return; + } + if ($row['commander_level'] >= $c['max_lv']) { + phpcommon\sendError(ERR_USER_BASE + 4, '指挥官已到满级'); + return; + } + $debris_num = $c['cost'] * ceil($row['commander_level'] / 5) + $c['cost_int']; + $coin_num = $c['gold_cost'] * ceil($row['commander_level'] / 5) + $c['gold_cost_int']; + if ($free == 1) { + $debris_num = 0; + $coin_num = 0; + } + if ($debris_num > $row['fragment_num']) { + phpcommon\sendError(ERR_USER_BASE + 5, '指挥官碎片数量不足'); + return; + } + if ($coin_num > $rowCoin['coin_num']) { + phpcommon\sendError(ERR_USER_BASE + 6, '金币不足'); + return; + } + $ret = $conn->execScript('UPDATE commander SET commander_level=:commander_level, fragment_num=:fragment_num, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND commander_id=:commander_id;', + array( + ':account_id' => $account_id, + ':commander_id' => $commander_id, + ':commander_level' => $row['commander_level'] + 1, + ':fragment_num' => $row['fragment_num'] - $debris_num, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $retCoin = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:account_id;', + array( + ':account_id' => $account_id, + ':coin_num' => $row['coin_num'] - $coin_num, + ':modify_time' => time() + )); + if (!$retCoin) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'commander_id' => $row['commander_id'], + 'commander_status' => $row['commander_status'], + 'fragment_num' => $row['fragment_num'] - $debris_num, + 'commander_level' => $row['commander_level'] + 1, + )); + } + + public function freetrycommander() + { + $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; + } + $commander_id = $_REQUEST['commander_id']; + $row = $conn->execQueryOne('SELECT * FROM commander WHERE accountid=:accountid AND commander_id=:commander_id;', + array( + ':accountid' => $account_id, + ':commander_id' => $commander_id, + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个指挥官'); + return; + } + $c = $this->getCommander($commander_id); + if(!$c){ + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个指挥官'); + return; + } + $ex_level = $c['max_lv']; + $p = $this->getParameter(SKIN_SKILL_TIME); + $time = $p['param_value']; + $ret = $conn->execScript('UPDATE commander SET active_time=:active_time, experience_level=:experience_level, modify_time=:modify_time ' . + ' WHERE accountid = :account_id AND commander_id = :commander_id;', + array( + ':account_id' => $account_id, + ':commander_id' => $commander_id, + ':active_time' => time() + $time, + ':experience_level' => $ex_level, + ':modify_time' => time() + )); + if(!$ret){ + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'commander_id' => $row['commander_id'], + 'time' => time() + $time, + 'experience_level' => $ex_level, + )); + } +} +?> diff --git a/webapp/controller/DouRewardController.class.php b/webapp/controller/DouRewardController.class.php index 63eb94a..cb76dca 100644 --- a/webapp/controller/DouRewardController.class.php +++ b/webapp/controller/DouRewardController.class.php @@ -13,7 +13,7 @@ class DouRewardController{ 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], - 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + 'dbname' => 'gamedb2002_' . $mysql_conf['instance_id'] )); return $conn; } @@ -98,7 +98,7 @@ class DouRewardController{ return; } $item_id = $row['item_id']; - $num = $row['num']; + $num = $row['item_num']; switch ($_REQUEST['type']) { //签到双倍奖励 @@ -115,8 +115,11 @@ class DouRewardController{ $num = $num * ($times - 1); break; } - //开宝箱双倍奖励 + //开宝箱双倍奖励,收藏双倍奖励,分享好友双倍奖励,客服双倍奖励 case 3: + case 4: + case 5: + case 6: { $p_gold = $this->getParameter(DOUBLE_BOX); $num = $num * ($p_gold['param_value'] - 1); diff --git a/webapp/controller/EquipController.class.php b/webapp/controller/EquipController.class.php deleted file mode 100644 index 1c08865..0000000 --- a/webapp/controller/EquipController.class.php +++ /dev/null @@ -1,297 +0,0 @@ - $mysql_conf['host'], - 'port' => $mysql_conf['port'], - 'user' => $mysql_conf['user'], - 'passwd' => $mysql_conf['passwd'], - 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] - )); - return $conn; - } - - protected function getEquip($equip_id) - { - $g_conf_equip_cluster = require('../res/equipUpgrade@equipUpgrade.php'); - $equip_conf = getEquipConfig($g_conf_equip_cluster, $equip_id); - $e = array( - 'equip_id' => $equip_conf['id'], - 'equip_name' => $equip_conf['name'], - 'equip_type' => $equip_conf['equip_page'], - 'cost_int' => $equip_conf['cost_int'], - 'max_lv' => $equip_conf['max_lv'], - 'equip_cost' => $equip_conf['cost'], - 'equip_attr_type' => $equip_conf['attr_type'], - ); - return $e; - } - - 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 subCoin($account_id, $equip_id, $equip_level, $free) - { - $e = $this->getEquip($equip_id); - if (!$e) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); - die(); - } - if ($e['max_lv'] <= $equip_level) { - phpcommon\sendError(ERR_USER_BASE + 4, '装备已到满级'); - die(); - } - $conn = $this->getMysql($account_id); - if (!$conn) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - die(); - } - $coin_num = $e['equip_cost'] * ceil($equip_level / 5) + $e['cost_int']; - if ($free == 1) { - $coin_num = 0; - } - $rowCoin = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if ($rowCoin['coin_num'] < $coin_num) { - phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); - die(); - } - $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':coin_num' => $rowCoin['coin_num'] - $coin_num, - ':modify_time' => time() - )); - if (!$ret) { - die(); - } - return $e; - } - - public function equipInfo() - { - $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); - $equip_list = array(); - if (!$conn) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $rowCount = $conn->execQueryRowCount('SELECT * FROM equip WHERE accountid=:account_id;', - array( - ':account_id' => $account_id - )); - if ($rowCount != 0) { - $active_time = 0; - $equip_level = 0; - $rows = $conn->execQuery('SELECT * FROM equip WHERE accountid=:account_id;', - array( - ':account_id' => $account_id - )); - foreach ($rows as $row) { - if (time() >= $row['active_time'] && $row['active_time'] != 0) { - $ret = $conn->execScript('UPDATE equip SET active_time=0, equip_experience_level=0, modify_time=:modify_time ' . - ' WHERE accountid=:account_id AND equip_id=:equip_id;', - array( - ':account_id' => $account_id, - ':equip_id' => $row['equip_id'], - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - $equip_level = $row['equip_level']; - $active_time = 0; - } else { - if ($row['active_time'] != 0) { - $active_time = $row['active_time']; - $equip_level = $row['equip_experience_level']; - } else { - $active_time = 0; - $equip_level = $row['equip_level']; - } - } - array_push($equip_list, array( - 'equip_id' => $row['equip_id'], - 'equip_level' => $equip_level, - 'active_time' => $active_time - )); - } - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'equip_list' => $equip_list - )); - } - - - public function updateEquip() - { - $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); - $skin_list = array(); - if (!$conn) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $equip_id = $_REQUEST['equip_id']; - $free = $_REQUEST['free']; - $equip_level = 0; - $row = $conn->execQueryOne('SELECT * FROM equip WHERE accountid=:account_id AND equip_id=:equip_id;', - array( - ':account_id' => $account_id, - ':equip_id' => $equip_id - )); - - if (!$row) { - $e = $this->subCoin($account_id, $equip_id, 1, $free); - $ret = $conn->execScript('INSERT INTO equip(accountid, equip_id, equip_level, equip_experience_level, active_time, create_time, modify_time) ' . - ' VALUES(:accountid, :equip_id, :equip_level, :equip_experience_level, :active_time, :create_time, :modify_time) ' . - ' ON DUPLICATE KEY UPDATE accountid=:accountid, equip_id=:equip_id, equip_level=:equip_level, equip_experience_level=:equip_experience_level, active_time=:active_time, modify_time=:modify_time;', - array( - ':accountid' => $account_id, - ':equip_id' => $equip_id, - ':equip_level' => 2, - ':equip_experience_level' => 0, - ':active_time' => 0, - ':create_time' => time(), - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - $equip_level = 2; - } else { - $e = $this->subCoin($account_id, $equip_id, $row['equip_level'], $free); - $ret = $conn->execScript('UPDATE equip SET equip_level=:equip_level, modify_time=:modify_time ' . - ' WHERE accountid=:account_id AND equip_id=:equip_id;', - array( - ':account_id' => $account_id, - ':equip_id' => $equip_id, - ':equip_level' => $row['equip_level'] + 1, - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - $equip_level = $row['equip_level'] + 1; - } - $quest = new classes\Quest(); - $quest->triggerQuest(QUEST_DAY_UPDATEEQUIP, 1, 1, $account_id); - if ($row['equip_level'] + 1 >= $e['max_lv']) { - $quest->triggerQuest(QUEST_SUM_EQUIPMAX, 2, 1, $account_id); - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - /*'equip_id' => $equip_id, - 'equip_level' => $equip_level, - 'equip_time' => 0, - 'coin_num' => -($e['equip_cost'] * ceil($equip_level / 5) + $e['cost_int'])*/ - )); - } - - - public function freeTryEquip() - { - $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); - $equip_id = $_REQUEST['equip_id']; - $equip_level = $_REQUEST['equip_level']; - if (!$conn) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个角色'); - return; - } - $e = $this->getEquip($equip_id); - if (!$e) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); - return; - } - $p = $this->getParameter(WEAPON_TRIAL); - $time = $p['param_value']; - $row = $conn->execQueryOne('SELECT * FROM equip WHERE accountid=:account_id AND equip_id=:equip_id;', - array( - ':account_id' => $account_id, - ':equip_id' => $equip_id - )); - if (!$row) { - $ret = $conn->execScript('INSERT INTO equip(accountid, equip_id, equip_level, equip_experience_level, active_time, create_time, modify_time) ' . - ' VALUES(:accountid, :equip_id, 1, :equip_experience_level, :active_time, :create_time, :modify_time) ' . - ' ON DUPLICATE KEY UPDATE accountid=:accountid, equip_id=:equip_id, equip_level=1, equip_experience_level=9, active_time=:active_time, modify_time=:modify_time;', - array( - ':accountid' => $account_id, - ':equip_id' => $equip_id, - ':active_time' => time() + $time, - ':create_time' => time(), - ':modify_time' => time(), - ':equip_experience_level' => $e['max_lv'] - )); - if (!$ret) { - die(); - return; - } - } else { - $ret = $conn->execScript('UPDATE equip SET active_time=:active_time, equip_experience_level=:equip_experience_level, modify_time=:modify_time ' . - ' WHERE accountid=:account_id AND equip_id=:equip_id;', - array( - ':account_id' => $account_id, - ':equip_id' => $equip_id, - ':active_time' => time() + $time, - ':modify_time' => time(), - ':equip_experience_level' => $e['max_lv'] - )); - if (!$ret) { - die(); - return; - } - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - /*'equip_id' => $equip_id, - 'equip_level' => $e['max_lv'], - 'equip_time' => time() + $time,*/ - )); - } -} -?> diff --git a/webapp/controller/HangController.class.php b/webapp/controller/HangController.class.php index f9b9ec3..e66d210 100644 --- a/webapp/controller/HangController.class.php +++ b/webapp/controller/HangController.class.php @@ -91,10 +91,44 @@ class HangController{ phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } + $num = 0; + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!$row) { + $ret = $conn->execScript('INSERT INTO hang(accountid, hang_time, create_time, modify_time) ' . + ' VALUES(:accountid, :hang_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, hang_time=:hang_time, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':hang_time' => time(), + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + } else { + $p_num = $this->getParameter(GOLD); + $p_time_limit = $this->getParameter(TIME_LIMIT); + $num = floor((time() - $row['hang_time']) / 5 * $p_num['param_value']); + if ((time() - $row['hang_time']) >= $p_time_limit['param_value']) { + $num = floor($p_time_limit['param_value'] / 5 * $p_num['param_value']); + } + } + echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'time' => time(), + 'num' => $num )); } diff --git a/webapp/controller/QuestController.class.php b/webapp/controller/QuestController.class.php index e3396ed..01bf949 100644 --- a/webapp/controller/QuestController.class.php +++ b/webapp/controller/QuestController.class.php @@ -73,24 +73,22 @@ class QuestController{ return $d; } - protected function insertActive($account_id, $active_id, $task_num) + protected function insertActive($account_id, $active_id) { $conn = $this->getMysql($account_id); - for ($i = $active_id; $i < $active_id + $task_num; $i++) { - $ret = $conn->execScript('INSERT INTO quest(accountid, quest_id, quest_type, quest_state, create_time, modify_time) ' . - ' VALUES(:accountid, :quest_id, :quest_type, :quest_state, :create_time, :modify_time) ' . - ' ON DUPLICATE KEY UPDATE accountid=:accountid, quest_id=:quest_id, quest_type=:quest_type, quest_state=:quest_state, modify_time=:modify_time;', - array( - ':accountid' => $account_id, - ':quest_id' => $i, - ':quest_type' => 0, - ':quest_state'=> 0, - ':create_time' => time(), - ':modify_time' => time() - )); - if (!$ret) { - die(); - } + $ret = $conn->execScript('INSERT INTO quest(accountid, quest_id, quest_type, quest_state, create_time, modify_time) ' . + ' VALUES(:accountid, :quest_id, :quest_type, :quest_state, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, quest_id=:quest_id, quest_type=:quest_type, quest_state=:quest_state, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':quest_id' => $active_id, + ':quest_type' => 0, + ':quest_state'=> 0, + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); } } @@ -104,19 +102,18 @@ class QuestController{ ':quest_id' => $quest_id )); $t = $this->getTaskReward($quest_id); - if ($row['quest_state'] != 0 || $active_num < $t['value']) { - continue; - } - $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, modify_time=:modify_time ' . - ' WHERE accountid=:accountid AND quest_id =:quest_id;', - array( - ':accountid' => $account_id, - ':quest_id' => $quest_id, - ':quest_state' => 1, - ':modify_time' => time() - )); - if (!$ret) { - die(); + if ($row['quest_state'] == 0 && $active_num >= $t['value']) { + $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_id =:quest_id;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_state' => 1, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } } } @@ -265,113 +262,114 @@ class QuestController{ return; } $item_list = array(); - if ($row['quest_state'] == 1) { - $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, modify_time=:modify_time ' . - ' WHERE accountid=:accountid AND quest_id =:quest_id AND quest_type=:quest_type;', - array( - ':accountid' => $account_id, - ':quest_id' => $quest_id, - ':quest_type' => $quest_type, - ':quest_state' => 2, - ':modify_time' => time() - )); - if (!$ret) { - die(); + if ($row['quest_state'] != 1) { + phpcommon\sendError(ERR_USER_BASE + 3, '任务未完成'); + return; + } + $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_id =:quest_id AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_type' => $quest_type, + ':quest_state' => 2, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + //发奖励 + if ($quest_type == 0) { + $t = $this->getTaskReward($quest_id); + if (!$t) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); return; } - - //发奖励 - if ($quest_type == 0) { - $t = $this->getTaskReward($quest_id); - if (!$t) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); - return; - } - $d = $this->getDrop($t['reward']); - if (!$d) { - phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); - return; - } - $weight_sum = 0; - $weight_array = $this->getExplode($d['weight']); - for ($i = 0; $i < count($weight_array); $i++) { - $weight_sum += $weight_array[$i][0]; - } - - $random = Rand(0, $weight_sum); - $weight = 0; - for ($i = 0; $i < count($weight_array); $i++) { - $weight += $weight_array[$i][0]; - if ($weight > $random) { - $key = $i; - break; - } - } - $item_id_array = $this->getExplode($d['item_id']); - $num_array = $this->getExplode($d['num']); - $item_id = $item_id_array[$key][0]; - $item_num = $num_array[$key][0]; - array_push($item_list, array( - 'item_id' => $item_id, - 'item_num' => $item_num, - )); - $addreward = new classes\AddReward(); - $addreward->addReward($item_id, $item_num, $account_id); - } else { - $q = $this->getQuest($quest_id); - if (!$q) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); - return; - } - $array = $this->getExplode($q['reward']); - $reward_id = $array[0][0]; - $reward_num = $array[0][1]; - $addreward = new classes\AddReward(); - $addreward->addReward($reward_id, $reward_num, $account_id); - array_push($item_list, array( - 'item_id' => $reward_id, - 'item_num' => $reward_num, - )); + $d = $this->getDrop($t['reward']); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; } - if ($row['quest_type'] == 1) { - $active = $conn->execQueryOne('SELECT active_num, active_sum FROM active WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - //增加活跃度 - if (!$active) { - $this->insertActive($account_id, 73001); - $ret = $conn->execScript('INSERT INTO active(accountid, active_num, num_time, create_time, modify_time) ' . - ' VALUES(:accountid, :active_num, :num_time, :create_time, :modify_time) ' . - ' ON DUPLICATE KEY UPDATE accountid=:accountid, active_num=:active_num, num_time=:num_time, modify_time=:modify_time;', - array( - ':accountid' => $account_id, - ':active_num' => $q['active_value'], - ':num_time' => time(), - ':create_time' => time(), - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - $this->updateActive($account_id, $q['active_value']); - } else { - $active['active_num'] = $q['active_value'] + $active['active_num']; - $ret = $conn->execScript('UPDATE active SET active_num=:active_num, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':active_num' => $active['active_num'], - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - $this->updateActive($account_id, $active['active_num']); + $weight_sum = 0; + $weight_array = $this->getExplode($d['weight']); + for ($i = 0; $i < count($weight_array); $i++) { + $weight_sum += $weight_array[$i][0]; + } + + $random = Rand(0, $weight_sum); + $weight = 0; + for ($i = 0; $i < count($weight_array); $i++) { + $weight += $weight_array[$i][0]; + if ($weight > $random) { + $key = $i; + break; } } + $item_id_array = $this->getExplode($d['item_id']); + $num_array = $this->getExplode($d['num']); + $item_id = $item_id_array[$key][0]; + $item_num = $num_array[$key][0]; + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + )); + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $item_num, $account_id); + } else { + $q = $this->getQuest($quest_id); + if (!$q) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); + return; + } + $array = $this->getExplode($q['reward']); + $reward_id = $array[0][0]; + $reward_num = $array[0][1]; + $addreward = new classes\AddReward(); + $addreward->addReward($reward_id, $reward_num, $account_id); + array_push($item_list, array( + 'item_id' => $reward_id, + 'item_num' => $reward_num, + )); + } + if ($row['quest_type'] == 1) { + $active = $conn->execQueryOne('SELECT active_num FROM active WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + //增加活跃度 + if (!$active) { + $this->insertActive($account_id, 73001); + $ret = $conn->execScript('INSERT INTO active(accountid, active_num, num_time, create_time, modify_time) ' . + ' VALUES(:accountid, :active_num, :num_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, active_num=:active_num, num_time=:num_time, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':active_num' => $q['active_value'], + ':num_time' => time(), + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $this->updateActive($account_id, $q['active_value']); + } else { + $active['active_num'] = $q['active_value'] + $active['active_num']; + $ret = $conn->execScript('UPDATE active SET active_num=:active_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':active_num' => $active['active_num'], + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $this->updateActive($account_id, $active['active_num']); + } } echo json_encode(array( 'errcode' => 0, diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php index 345a437..763f7d9 100644 --- a/webapp/controller/RoleController.class.php +++ b/webapp/controller/RoleController.class.php @@ -549,7 +549,7 @@ class RoleController{ die(); return; } - $d = $this->getDrop(24003); + $d = $this->getDrop(24006); if (!$d) { phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); return; @@ -565,6 +565,7 @@ class RoleController{ $item_num = $num_array[0]; $addreward = new classes\AddReward(); $addreward->addReward($item_id, $item_num, $account_id); + $addreward->updateReward($item_id, $item_num, $account_id); array_push($item_list, array( 'item_id' => $item_id, 'item_num' => $item_num @@ -578,45 +579,5 @@ class RoleController{ 'item_list' => $item_list )); } - - public function collectDoubleReward() - { - $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); - $record_list = array(); - if (!$conn) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $d = $this->getDrop(24003); - if (!$d) { - phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); - return; - } - $item_id_array = $this->getExplode($d['item_id']); - $num_array = $this->getExplode($d['num']); - $weight_array = $this->getExplode($d['weight']); - $i = 0; - $item_list = array(); - foreach ($weight_array as $item) { - if ($item[$i][0] >= Rand(0, 10000)) { - $item_id = $item_id_array[$i][0]; - $item_num = $num_array[$i][0]; - $addreward = new classes\AddReward(); - $addreward->addReward($item_id, $item_num, $account_id); - } - $i++; - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - )); - } } ?> diff --git a/webapp/controller/ShareController.class.php b/webapp/controller/ShareController.class.php index c2d956c..b2f5d89 100644 --- a/webapp/controller/ShareController.class.php +++ b/webapp/controller/ShareController.class.php @@ -13,7 +13,7 @@ class ShareController{ 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], - 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + 'dbname' => 'gamedb2002_' . $mysql_conf['instance_id'] )); return $conn; } @@ -84,9 +84,7 @@ class ShareController{ phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } - $free = $_REQUEST['free']; $drop_id = 0; - //扣除钥匙 $row = $conn->execQueryOne('SELECT keys_num, coin_num, diamond_num, free_getbox FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id @@ -296,7 +294,6 @@ class ShareController{ return; } $ach_id = $_REQUEST['ach_id']; - $double = $_REQUEST['double']; $row = $conn->execQueryOne('SELECT status FROM share_achievement WHERE accountid=:accountid AND ach_id=:ach_id;', array( ':accountid' => $account_id, @@ -337,12 +334,6 @@ class ShareController{ $ach_list = $data['invitee_nums']; $peo_num = 0; $sh = $this->getShare($ach_id); - $num = 0; - if ($double != 0) { - $num = 2; - } else { - $num = 1; - } foreach($ach_list as $ach){ $ach_id = $ach['achievement_id']; $peo_num = $ach['invitee_num']; @@ -353,7 +344,8 @@ class ShareController{ } $array = $this->getExplode($sh['rewards']); $addreward = new classes\AddReward(); - $addreward->addReward($array[0][0], $array[0][1] * $num, $account_id); + $addreward->addReward($array[0][0], $array[0][1], $account_id); + $addreward->updateReward($array[0][0], $array[0][1], $account_id); //更新状态 $ret = $conn->execScript('UPDATE share_achievement SET status=1, modify_time=:modify_time ' . ' WHERE accountid=:accountid AND ach_id=:ach_id;', @@ -429,6 +421,7 @@ class ShareController{ } $addreward = new classes\AddReward(); $addreward->addReward($item_id, $item_num, $account_id); + $addreward->updateReward($item_id, $item_num, $account_id); array_push($item_list, array( 'item_id' => $item_id, 'item_num' => $item_num, @@ -451,53 +444,5 @@ class ShareController{ 'item_list' => $item_list )); } - - public function kefuDoubleReward() - { - $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 + 2, '没有这个玩家'); - return; - } - $mail_id = $_REQUEST['mail_ids']; - $d = $this->getDrop(24005); - if (!$d) { - phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); - return; - } - $item_id_array = $this->getExplode($d['item_id']); - $weight_sum = 0; - $keys = 0; - $item_num_array = $this->getExplode($d['num']); - $weight_array = $this->getExplode($d['weight']); - for ($i = 0; $i < count($weight_array); $i++) { - $weight_sum += $weight_array[$i][0]; - } - srand(crc32($account_id . $mail_id)); - $random = Rand(0, $weight_sum); - $weight = 0; - for ($i = 0; $i < count($weight_array); $i++) { - $weight += $weight_array[$i][0]; - if ($weight > $random) { - $keys = $i; - break; - } - } - $item_id = $item_id_array[$keys][0]; - $item_num = $item_num_array[$keys][0]; - $addreward = new classes\AddReward(); - $addreward->addReward($item_id, $item_num, $account_id); - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - )); - } } ?> diff --git a/webapp/controller/SkinController.class.php b/webapp/controller/SkinController.class.php index b9b23b1..797ac0e 100644 --- a/webapp/controller/SkinController.class.php +++ b/webapp/controller/SkinController.class.php @@ -10,32 +10,24 @@ class SkinController{ 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], - 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + 'dbname' => 'gamedb2002_' . $mysql_conf['instance_id'] )); return $conn; } - protected function getSkin($skin_id) + protected function getTankSkin($skin_id) { - $g_conf_skin_cluster = require('../res/dress@dress.php'); - $skin_conf = getSkinConfig($g_conf_skin_cluster, $skin_id); + $skin_meta_table = require('../res/tankSkin@tankSkin.php'); + $skin_meta = getCommanderConfig($skin_meta_table, $skin_id); $s = array( - 'skin_id' => $skin_conf['id'], - 'skin_name' => $skin_conf['name'], - 'skin_skillid' => $skin_conf['skill_id'], - 'skin_compose' => $skin_conf['compose'], - 'skin_experience' => $skin_conf['is_experience'], - 'skin_type' => $skin_conf['type'], - 'duration' => $skin_conf['duration'], - 'debris_id' => $skin_conf['debris'], - 'cost' => $skin_conf['cost'], - 'cost_int' => $skin_conf['cost_int'], - 'max_lv' => $skin_conf['max_lv'], + 'id' => $skin_meta['id'], + 'name' => $skin_meta['name'], + 'price' => $skin_meta['pirce'], ); return $s; } - protected function getExplode($string) + protected function getExplode($string) { $delim = "|"; $drop_multiply = explode($delim, $string); @@ -50,60 +42,16 @@ class SkinController{ protected function getParameter($para_id) { - $g_conf_para_cluster = require('../res/parameter@parameter.php'); - $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); + $parameter_meta_cluster = require('../res/parameter@parameter.php'); + $parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id); $p = array( - 'id' => $para_conf['id'], - 'param_name' => $para_conf['param_name'], - 'param_value' => $para_conf['param_value'], + 'id' => $parameter_meta['id'], + 'param_name' => $parameter_meta['param_name'], + 'param_value' => $parameter_meta['param_value'], ); return $p; } - protected function updateActiveTime($row, $conn) - { - $skin_status = 0; - if ($row['skin_type'] == 1) { - $skin_status = 2; - } else if ($row['skin_type'] == 2) { - $skin_status = 3; - } - $ret = $conn->execScript('UPDATE skin SET active_time=0, skin_experience_level=0, skin_experience_type=0, modify_time=:modify_time ' . - ' WHERE accountid=:account_id AND skin_id=:skin_id;', - array( - ':account_id' => $row['accountid'], - ':skin_id' => $row['skin_id'], - ':modify_time' => time() - )); - if(!$ret){ - die(); - return; - } - if ($row['skin_status'] == 0 && $row['skin_experience_type'] == 1) { - $ret = $conn->execScript('UPDATE skin SET skin_status=:skin_status, modify_time=:modify_time ' . - ' WHERE accountid=:account_id AND skin_id=:skin_id;', - array( - ':account_id' => $row['accountid'], - ':skin_id' => $row['skin_id'], - ':skin_status' => $skin_status, - ':modify_time' => time() - )); - if(!$ret){ - die(); - return; - } - $ret = $conn->execScript('UPDATE skin SET skin_status=0, modify_time=:modify_time ' . - ' WHERE accountid = :account_id AND skin_id = 14001;', - array( - ':account_id' => $row['accountid'], - ':modify_time' => time() - )); - if(!$ret){ - die(); - return; - } - } - } public function skinInfo() { $account_id = $_REQUEST['account_id']; @@ -119,39 +67,36 @@ class SkinController{ phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家'); return; } - $g_conf_skin_cluster = require('../res/dress@dress.php'); - $s = $this->getSkin(14001); - if(!$s){ + $skin_meta_table = require('../res/tankSkin@tankSkin.php'); + $s = $this->getSkin(30001); + if (!$s) { phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤'); return; } - $rowCount = $conn->execQueryRowCount('SELECT * FROM skin WHERE accountid = :account_id;', + $rowCount = $conn->execQueryRowCount('SELECT skin_id FROM skin WHERE accountid = :account_id;', array( ':account_id' => $account_id )); + $status = 0; if ($rowCount == 0) { - for ($i = 14001; $i <= count($g_conf_skin_cluster) + 14000; $i++) { + for ($i = 30001; $i <= count($commander_meta_table) + 30000; $i++) { $s = $this->getSkin($i); - if(!$s){ + if (!$s) { phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤'); return; } - if ($i == 14001) { - $skin_status = 0; - } else if ($s['skin_type'] == 2){ - $skin_status = 3; + if ($s['price'] == 0) { + $status = 0; } else { - $skin_status = 2; + $status = 2; } - $ret = $conn->execScript('INSERT INTO skin(accountid, skin_id, skin_status, fragment_id, fragment_num, active_time, fragment_status, skin_type, skin_level, skin_experience_level, skin_experience_type, create_time, modify_time) ' . - ' VALUES(:account_id, :skin_id, :skin_status, :fragment_id, 0, 0, 0, :skin_type, 1, 0, 0, :create_time, :modify_time) ' . - ' ON DUPLICATE KEY UPDATE accountid=:account_id, skin_id=:skin_id, skin_status=:skin_status, fragment_id=:fragment_id, fragment_num=0, active_time=0, fragment_status=0, skin_type=:skin_type, skin_level=1, skin_experience_level=0, skin_experience_type=0, modify_time=:modify_time;', + $ret = $conn->execScript('INSERT INTO skin(accountid, skin_id, status, create_time, modify_time) ' . + ' VALUES(:account_id, :skin_id, :status, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:account_id, skin_id=:skin_id, status=:status, modify_time=:modify_time;', array( ':account_id' => $account_id, ':skin_id' => $i, - ':skin_status' => $skin_status, - ':fragment_id' => $s['debris_id'], - ':skin_type' => $s['skin_type'], + ':status' => $status, ':create_time' => time(), ':modify_time' => time() )); @@ -161,46 +106,19 @@ class SkinController{ } } } - $time = 0; - $skin_level = 0; - $skin_experience_type = 0; - $skin_status = 0; - $rows = $conn->execQuery('SELECT * FROM skin WHERE accountid = :account_id;', + $rows = $conn->execQuery('SELECT skin_id, status FROM skin WHERE accountid = :account_id;', array( ':account_id' => $account_id, )); - - foreach ($rows as $row) { - $s = $this->getSkin($row['skin_id']); - if(time() >= $row['active_time'] && $row['active_time'] != 0){ - $this->updateActiveTime($row, $conn); - } - } - $rowsSkin = $conn->execQuery('SELECT * FROM skin WHERE accountid = :account_id;', - array( - ':account_id' => $account_id, - )); $skin_id = 0; - foreach ($rowsSkin as $rowSkin) { - $s = $this->getSkin($rowSkin['skin_id']); - if ($skin_id == $rowSkin['skin_id']) { + foreach ($rows as $row) { + if ($skin_id == $row['skin_id']) { continue; } - $skin_id = $rowSkin['skin_id']; - if ($rowSkin['active_time'] != 0) { - $skin_level = $s['max_lv']; - $skin_experience_type = 2; - } else { - $skin_level = $rowSkin['skin_level']; - $skin_experience_type = 0; - } + $skin_id = $row['skin_id']; array_push($skin_list, array( - 'skin_id' => $rowSkin['skin_id'], - 'skin_status' => $rowSkin['skin_status'], - 'fragment_num' => $rowSkin['fragment_num'], - 'active_time' => $rowSkin['active_time'], - 'skin_level' => $skin_level, - 'skin_experience_type' => $skin_experience_type + 'skin_id' => $skin_id, + 'skin_status' => $row['status'], )); } echo json_encode(array( @@ -228,49 +146,51 @@ class SkinController{ } $s = $this->getSkin($skin_id); if(!$s){ - phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤1'); + phpcommon\sendError(ERR_USER_BASE + 2,'没有这个皮肤'); return; } - $row = $conn->execQueryOne('SELECT * FROM skin WHERE accountid = :account_id AND skin_id = :skin_id;', + $row = $conn->execQueryOne('SELECT status FROM skin WHERE accountid=:account_id AND skin_id=:skin_id;', array( ':account_id' => $account_id, ':skin_id' => $skin_id )); if(!$row){ - phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤'); + phpcommon\sendError(ERR_USER_BASE + 2,'没有这个皮肤'); return; } - if ($row['skin_type'] != 1) { - phpcommon\sendError(ERR_USER_BASE + 2,'皮肤无法解锁'); + if ($row['status'] == 1) { + phpcommon\sendError(ERR_USER_BASE + 3,'皮肤已解锁'); return; } - $fragment_num = 0; - $array = $this->getExplode($s['skin_compose']); - if ($row['fragment_num'] < $array[0][1]) { - phpcommon\sendError(ERR_USER_BASE + 2,'皮肤碎片数量不足'); + $num = $s['price']; + $rowDiamond = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:account_id;', + array( + ':account_id' => $account_id, + )); + if (!$rowDiamond) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } - $fragment_num = $row['fragment_num'] - $array[0][1]; - - $skin_status = 1; - $active_time = 0; - $skin_experience_type = 0; - if ($row['skin_status'] == 0) { - $skin_status = 0; + if ($num > $rowDiamond['diamond_num']) { + phpcommon\sendError(ERR_USER_BASE + 6, '钻石不足'); + return; } - if ($row['active_time'] != 0) { - $active_time = $row['active_time']; - $skin_experience_type = 2; + $retDiamond = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' . + ' WHERE accountid=:account_id;', + array( + ':account_id' => $account_id, + ':diamond_num' => $row['diamond_num'] - $num, + ':modify_time' => time() + )); + if (!$retDiamond) { + die(); + return; } - $ret = $conn->execScript('UPDATE skin SET fragment_num=:fragment_num ,skin_status=:skin_status, active_time=:active_time, skin_experience_type=:skin_experience_type, modify_time=:modify_time ' . + $ret = $conn->execScript('UPDATE skin SET status=1, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND skin_id = :skin_id;', array( ':account_id' => $account_id, ':skin_id' => $skin_id, - ':fragment_num' => $fragment_num, - ':skin_status' => $skin_status, - ':active_time' => $active_time, - ':skin_experience_type' => $skin_experience_type, ':modify_time' => time() )); if (!$ret) { @@ -280,12 +200,8 @@ class SkinController{ echo json_encode(array( 'errcode' => 0, 'errmsg' => '', - /*"skin_id" => $skin_id, - "skin_status" => $skin_status, - "fragment_num" => $fragment_num, - "time" => $active_time, - "skin_level" => 1, - "skin_experience_type" => $skin_experience_type,*/ + "skin_id" => $skin_id, + "skin_status" => 1, )); } @@ -305,31 +221,22 @@ class SkinController{ phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } - $skin_status = 0; - $row = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:accountid AND skin_id=:skin_id;', + //正在上阵的皮肤 + $row = $conn->execQueryOne('SELECT status FROM skin WHERE accountid=:accountid AND skin_id=:skin_id;', array( ':accountid' => $account_id, ':skin_id' => $usingskin_id, )); if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个皮肤'); + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个指挥官'); return; } - if ($row['skin_experience_type'] == 0 || $row['skin_experience_type'] == 2) { - $skin_status = 1; - } else if ($row['skin_experience_type'] == 1) { - if ($row['skin_type'] == 1) { - $skin_status = 2; - } else if ($row['skin_type'] == 2) { - $skin_status = 3; - } - } - $using_ret = $conn->execScript('UPDATE skin SET skin_status=:skin_status, modify_time=:modify_time ' . + $status = 1; + $using_ret = $conn->execScript('UPDATE skin SET status=:1, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND skin_id = :skin_id;', array( ':account_id' => $account_id, ':skin_id' => $usingskin_id, - ':skin_status' => $skin_status, ':modify_time' => time() )); @@ -337,7 +244,18 @@ class SkinController{ die(); return; } - $exchange_ret = $conn->execScript('UPDATE skin SET skin_status=0, modify_time=:modify_time ' . + $skin_list = array(); + array_push($skin_list, array( + 'skin_id' => $usingskin_id, + 'skin_status' => 1, + )); + //准备上阵的皮肤 + $row_exchange = $conn->execQueryOne('SELECT status FROM commander WHERE accountid=:accountid AND skin_id=:skin_id;', + array( + ':accountid' => $account_id, + ':skin_id' => $exchangeskin_id, + )); + $exchange_ret = $conn->execScript('UPDATE skin SET status=0, modify_time=:modify_time ' . ' WHERE accountid = :account_id AND skin_id = :skin_id;', array( ':account_id' => $account_id, @@ -348,169 +266,15 @@ class SkinController{ die(); return; } - /*$skin_list = array(); array_push($skin_list, array( - 'skin_id' => $row['skin_id'], - 'skin_status' => $skin_status, - 'fragment_num' => $row['fragment_num'], - 'active_time' => $row['active_time'], - 'skin_level' => $row['skin_level'], - 'skin_experience_type' => $row['skin_experience_type'] - )); - $row_exchange = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:accountid AND skin_id=:skin_id;', - array( - ':accountid' => $account_id, - ':skin_id' => $exchangeskin_id, - )); - array_push($skin_list, array( - 'skin_id' => $row_exchange['skin_id'], - 'skin_status' => 0, - 'fragment_num' => $row_exchange['fragment_num'], - 'active_time' => $row_exchange['active_time'], - 'skin_level' => $row_exchange['skin_level'], - 'skin_experience_type' => $row_exchange['skin_experience_type'] - )); - */ - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - //"skin_list" => $skin_list, + 'skin_id' => $exchangeskin_id, + 'skin_status' => 0, )); - } - public function freetryskin() - { - $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); - $skin_id = $_REQUEST['skin_id']; - $row = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:accountid AND skin_id=:skin_id;', - array( - ':accountid' => $account_id, - ':skin_id' => $skin_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1,'没有这个角色'); - return; - } - if(!$conn){ - phpcommon\sendError(ERR_USER_BASE + 1,'没有这个角色'); - return; - } - $s = $this->getSkin($skin_id); - if(!$s){ - phpcommon\sendError(ERR_USER_BASE + 2,'没有这个皮肤'); - return; - } - $time = 0; - $ex_level = 0; - $ex_type = 0; - if ($s['skin_type'] == 2) { - $time = $s['duration']; - } - $ex_level = $s['max_lv']; - $p = $this->getParameter(SKIN_SKILL_TIME); - $time = $p['param_value']; - if ($row['skin_status'] <= 1) { - $ex_type = 2; - } else { - $ex_type = 1; - } - $ret = $conn->execScript('UPDATE skin SET active_time=:active_time, skin_experience_level=:skin_experience_level, skin_experience_type=:skin_experience_type, modify_time=:modify_time ' . - ' WHERE accountid = :account_id AND skin_id = :skin_id;', - array( - ':account_id' => $account_id, - ':skin_id' => $skin_id, - ':active_time' => time() + $time, - ':skin_experience_level' => $ex_level, - ':skin_experience_type' => $ex_type, - ':modify_time' => time() - )); - if(!$ret){ - die(); - return; - } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', - /*'skin_id' => $row['skin_id'], - 'skin_status' => $row['skin_status'], - 'fragment_num' => $row['fragment_num'], - 'active_time' => time() + $time, - 'skin_level' => $ex_level, - 'skin_experience_type' => 2*/ - )); - } - - public function updateSkin() - { - $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; - } - $skin_id = $_REQUEST['skin_id']; - $free = $_REQUEST['free']; - $row = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:account_id AND skin_id=:skin_id;', - array( - ':account_id' => $account_id, - ':skin_id' => $skin_id - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1, '皮肤不存在'); - return; - } - $s = $this->getSkin($skin_id); - if (!$s) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个皮肤'); - return; - } - if ($row['skin_level'] >= $s['max_lv']) { - phpcommon\sendError(ERR_USER_BASE + 3, '皮肤已到满级'); - return; - } - $debris_num = $s['cost'] * ceil($row['skin_level'] / 5) + $s['cost_int']; - if ($free == 1) { - $debris_num = 0; - } - if ($debris_num > $row['fragment_num']) { - phpcommon\sendError(ERR_USER_BASE + 4, '皮肤碎片数量不足'); - return; - } - $ret = $conn->execScript('UPDATE skin SET skin_level=:skin_level, fragment_num=:fragment_num, modify_time=:modify_time ' . - ' WHERE accountid=:account_id AND skin_id=:skin_id;', - array( - ':account_id' => $account_id, - ':skin_id' => $skin_id, - ':skin_level' => $row['skin_level'] + 1, - ':fragment_num' => $row['fragment_num'] - $debris_num, - ':modify_time' => time() - )); - if (!$ret) { - die(); - return; - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - /*'skin_id' => $row['skin_id'], - 'skin_status' => $row['skin_status'], - 'fragment_num' => $row['fragment_num'] - $debris_num, - 'active_time' => $row['active_time'], - 'skin_level' => $row['skin_level'] + 1, - 'skin_experience_type' => $row['skin_experience_type']*/ + "skin_list" => $skin_list, )); } } diff --git a/webapp/controller/TankController.class.php b/webapp/controller/TankController.class.php new file mode 100644 index 0000000..be37ffb --- /dev/null +++ b/webapp/controller/TankController.class.php @@ -0,0 +1,491 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $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'], + 'price' => $tank_meta['price'], + 'cost' => $tank_meta['cost'], + 'cost_int' => $tank_meta['cost_int'], + 'max_lv' => $tank_meta['max_lv'], + ); + 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=20001;', + 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(20001); + 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 = 20001; $i <= count($tank_meta_table) + 20000; $i++) { + $t = $this->getTank($i); + if (!$t) { + phpcommon\sendError(ERR_USER_BASE + 1,'没有这个坦克'); + return; + } + if ($i == 20000) { + $tank_status = 0; + } else { + $tank_status = 2; + } + $ret = $conn->execScript('INSERT INTO tank(accountid, tank_id, tank_status, active_time, tank_level, experience_level, experience_type, create_time, modify_time) ' . + ' VALUES(:account_id, :tank_id, :tank_status, 0, 1, 0, 0, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:account_id, tank_id=:tank_id, tank_status=:tank_status, active_time=0, tank_level=1, experience_level=0, experience_type=0, modify_time=:modify_time;', + array( + ':account_id' => $account_id, + ':tank_id' => $i, + ':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 = $rowSkin['experience_level']; + } else { + $tank_level = $rowSkin['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'], + )); + } + 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 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 = $t['price']; + $rowDiamond = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:account_id;', + array( + ':account_id' => $account_id, + )); + if (!$rowDiamond) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + if ($num > $rowDiamond['diamond_num']) { + phpcommon\sendError(ERR_USER_BASE + 5, '钻石不足'); + return; + } + $retDiamond = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' . + ' WHERE accountid=:account_id;', + array( + ':account_id' => $account_id, + ':diamond_num' => $row['diamond_num'] - $num, + ':modify_time' => time() + )); + if (!$retDiamond) { + die(); + return; + } + + $ret = $conn->execScript('UPDATE tank SET tank_status=1, modify_time=:modify_time ' . + ' WHERE accountid=:account_id AND tank_id=:tank_id;', + array( + ':account_id' => $account_id, + ':tank_id' => $tank_id, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + "tank_id" => $tank_id, + "tank_status" => $tank_status, + )); + } + + 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, + )); + $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 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->getSkin($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; + } + $rowCoin = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:account_id;', + array( + ':account_id' => $account_id, + )); + if (!$rowCoin) { + phpcommon\sendError(ERR_USER_BASE + 1, '指挥官不存在'); + return; + } + $coin_num = $t['cost'] * ceil($row['tank_level'] / 5) + $t['cost_int']; + if ($free == 1) { + $coin_num = 0; + } + if ($coin_num > $rowCoin['coin_num']) { + phpcommon\sendError(ERR_USER_BASE + 6, '金币不足'); + return; + } + $retCoin = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:account_id;', + array( + ':account_id' => $account_id, + ':coin_num' => $row['coin_num'] - $coin_num, + ':modify_time' => time() + )); + if (!$retCoin) { + die(); + return; + } + $ret = $conn->execScript('UPDATE tank SET tank_level=:tank_level, 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, + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'tank_id' => $row['tank_id'], + 'tank_level' => $row['tank_level'] + 1, + )); + } +} +?>