From aef6bf5da4d048f59c4d883fa69e208ee84784c7 Mon Sep 17 00:00:00 2001 From: wangwei01 Date: Thu, 4 Apr 2019 15:15:51 +0800 Subject: [PATCH] 1 --- webapp/controller/EquipController.class.php | 190 ++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 webapp/controller/EquipController.class.php diff --git a/webapp/controller/EquipController.class.php b/webapp/controller/EquipController.class.php new file mode 100644 index 0000000..104c967 --- /dev/null +++ b/webapp/controller/EquipController.class.php @@ -0,0 +1,190 @@ + $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('../config/game2001api.equip.cluster.php'); + $equip_conf = getEquipConfig($g_conf_equip_cluster, $equip_id); + $e = array( + 'equip_number' => $equip_conf['equip_number'], + 'equip_id' => $equip_conf['equip_id'], + 'equip_name' => $equip_conf['equip_name'], + 'equip_type' => $equip_conf['equip_type'], + 'equip_level' => $equip_conf['equip_level'], + 'equip_nextlevel' => $equip_conf['equip_nextlevel'], + 'equip_cost' => $equip_conf['equip_cost'], + 'equip_attr_type' => $equip_conf['equip_attr_type'], + 'equip_atrr_value' => $equip_conf['equip_atrr_value'], + 'equip_experience' => $equip_conf['equip_experience'], + ); + return $e; + } + + public function equipInfo() + { + $account_id = $_REQUEST['account_id']; + $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'] >= 7200 && $row['active_time'] != 0) { + $ret = $conn->execScript('UPDATE equip SET active_time=0 ' . + ' WHERE accountid=:account_id AND equip_id=:equip_id;', + array( + ':account_id' => $account_id, + ':equip_id' => $row['equip_id'] + )); + if (!$ret) { + die(); + return; + } + $equip_level = $row['equip_level']; + } else { + if ($row['active_time'] != 0) { + $active_time = 2; + $equip_level = 8; + } 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']; + $conn = $this->getMysql($account_id); + $skin_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $equip_id = $_REQUEST['equip_id']; + $coin_num = $_REQUEST['coin_num']; + $equip_level = $_REQUEST['equip_level']; + $e = $this->getEquip($equip_id * 10 + $equip_level); + if (!$e) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); + return; + } + if ($e['equip_cost'] > $coin_num) { + phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); + return; + } + $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) ' . + ' VALUES(:accountid, :equip_id, :equip_level, :equip_experience_level, :active_time);', + array( + ':accountid' => $account_id, + ':equip_id' => $equip_id, + ':equip_level' => $e['equip_nextlevel'], + ':equip_experience_level' => 8, + ':active_time' => 0, + )); + if (!$ret) { + die(); + return; + } + } else { + $ret = $conn->execScript('UPDATE equip SET equip_level=:equip_level ' . + ' WHERE accountid=:account_id AND equip_id=:equip_id;', + array( + ':account_id' => $account_id, + ':equip_id' => $equip_id, + ':equip_level' => $e['equip_nextlevel'] + )); + if (!$ret) { + die(); + return; + } + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + + public function freeTryEquip() + { + $account_id = $_REQUEST['account_id']; + $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 * 10 + $equip_level); + if (!$e) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); + return; + } + if ($e['equip_experience'] == 0) { + phpcommon\sendError(ERR_USER_BASE + 3, '装备不可以体验'); + return; + } + $ret = $conn->execScript('UPDATE equip SET active_time=:active_time, equip_experience_level=8 ' . + ' WHERE accountid=:account_id AND equip_id=:equip_id;', + array( + ':account_id' => $account_id, + ':equip_id' => $equip_id, + ':active_time' => time() + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } +} +?>