From 604fb32de43734627709af705cf89557fa6e8a54 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 29 May 2020 11:32:43 +0800 Subject: [PATCH] 1 --- webapp/controller/EquipController.class.php | 389 ++++++++++++++++++ .../controller/GameOverController.class.php | 291 +++++++++++++ 2 files changed, 680 insertions(+) create mode 100644 webapp/controller/EquipController.class.php create mode 100644 webapp/controller/GameOverController.class.php diff --git a/webapp/controller/EquipController.class.php b/webapp/controller/EquipController.class.php new file mode 100644 index 0000000..cb87d70 --- /dev/null +++ b/webapp/controller/EquipController.class.php @@ -0,0 +1,389 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2004_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getItem($item_id) + { + $g_conf_item_cluster = require('../res/item@item.php'); + $item_conf = getItemConfig($g_conf_item_cluster, $item_id); + $it = array( + 'id' => $item_conf['id'], + 'diamond' => $item_conf['diamond'], + 'dprice' => $item_conf['dprice'], + 'type' => $item_conf['fuction'], + 'diamond_hour' => $item_conf['diamond_hour'] + ); + return $it; + } + + 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 getEquip($equip_id) + { + $g_conf_equip_cluster = require('../res/equip@equip.php'); + $equip_conf = getEquipConfig($g_conf_equip_cluster, $equip_id); + $e = array( + 'id' => $equip_conf['id'], + 'upgrade_priority' => $equip_conf['upgrade_priority'], + 'equip_upgrade' => $equip_conf['equip_upgrade'], + 'level_gold_cost' => $equip_conf['level_gold_cost'], + 'max_level' => $equip_conf['max_level'], + 'equip_upgradematerial' => $equip_conf['equip_upgradematerial'], + 'equip_upgradetime' => $equip_conf['equip_upgradetime'], + 'diamond_cost' => $equip_conf['diamond_cost'], + 'reduce_time' => $equip_conf['reduce_time'], + 'diamond_time' => $equip_conf['diamond_time'], + ); + return $e; + } + + 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; + } + + public function getEquipInfo() + { + $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; + } + $equip_list = array(); + $row = $conn->execQueryOne('SELECT * FROM equip WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + if (!$row) { + $id = 0; + $g_conf_lot_cluster = require('../res/equip@equip.php'); + for ($i = 0; $i < count($g_conf_lot_cluster); $i++) { + $e = $this->getEquip(12100 + $i); + if (!$e) { + continue; + } + if ($e['upgrade_priority'] == 1) { + $id = $e['id']; + break; + } + } + $ret = $conn->execScript('INSERT INTO equip(accountid, id, lv, active_time, sub_time, create_time, modify_time) ' . + ' VALUES(:account_id, :id, 0, :active_time, :sub_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:account_id, id=:id, lv=0, active_time=:active_time, sub_time=:sub_time, modify_time=:modify_time;', + array( + ':account_id' => $account_id, + ':id' => $id, + ':active_time' => 0, + ':create_time' => time(), + ':modify_time' => time(), + ':sub_time' => 0, + )); + if(!$ret){ + die(); + return; + } + array_push($equip_list, array( + 'id' => $id, + 'lv' => 0, + 'active_time' => 0, + )); + } else { + $time = $row['active_time'] + $row['sub_time']; + if (time() >= $row['active_time'] + $row['sub_time']) { + $ret1 = $conn->execScript('UPDATE equip SET active_time=0, sub_time=0, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => time() + )); + if (!$ret1) { + die(); + return; + } + $time = 0; + } + array_push($equip_list, array( + 'id' => $row['id'], + 'lv' => $row['lv'], + 'active_time' => $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); + $equip_list = array(); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $row = $conn->execQueryOne('SELECT * FROM equip WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + $rowUser = $conn->execQueryOne('SELECT coin_num, diamond_num FROM user WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + if (!$row || !$rowUser) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $e = $this->getEquip($row['id']); + if (!$e) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); + return; + } + $flag = 0; + if ($row['lv'] < $e['max_level']) { + //金币升级 + $coin_array = $this->getExplode($e['level_gold_cost']); + $coin_num = $coin_array[$row['lv']][0]; + if ($rowUser['coin_num'] < $coin_num) { + phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); + return; + } + $retuser = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $rowUser['coin_num'] - $coin_num, + ':modify_time' => time() + )); + $ret = $conn->execScript('UPDATE equip SET lv=:lv, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':lv' => $row['lv'] + 1, + ':modify_time' => time() + )); + if (!$ret || !$retuser) { + die(); + return; + } + } else { + //装备进阶 + $rowBag = $conn->execQuery('SELECT * FROM bag WHERE accountid=:account_id AND id>18000 AND id<19000;', + array( + ':account_id' => $account_id + )); + $max_p = $e['upgrade_priority']; + $id = 0; + $g_conf_lot_cluster = require('../res/equip@equip.php'); + for ($i = 0; $i < count($g_conf_lot_cluster); $i++) { + $ec = $this->getEquip(12100 + $i); + if (!$ec) { + continue; + } + if ($ec['upgrade_priority'] == $max_p + 1) { + $id = $ec['id']; + break; + } + } + if ($id == 0) { + phpcommon\sendError(ERR_USER_BASE + 4, '装备已达满级'); + return; + } + $mar_array = $this->getExplode($e['equip_upgradematerial']); + $mflag = 0; + for ($m = 0; $m < count($mar_array); $m++) { + foreach ($rowBag as $rb) { + if ($rb['id'] == $mar_array[$m][0]) { + if ($rb['num'] >= $mar_array[$m][1]) { + $mflag++; + } + } + } + } + if ($mflag < count($mar_array)) { + phpcommon\sendError(ERR_USER_BASE + 5, '材料不足'); + return; + } + //扣除材料 + for ($m = 0; $m < count($mar_array); $m++) { + foreach ($rowBag as $rb) { + if ($rb['id'] != $mar_array[$m][0]) { + continue; + } + $retbag = $conn->execScript('UPDATE bag SET num=:num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND id=:id;', + array( + ':accountid' => $account_id, + ':num' => $rb['num'] - $mar_array[$m][1], + ':id' => $rb['id'], + ':modify_time' => time() + )); + if (!$retbag) { + die(); + return; + } + break; + } + } + $active_time = time(); + $sub_time = $e['equip_upgradetime']; + if ($e['equip_upgradetime'] == 0) { + $active_time = 0; + $flag = 1; + } + $retEquip = $conn->execScript('UPDATE equip SET id=:id, lv=0, active_time=:active_time, sub_time=:sub_time, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':id' => $id, + ':modify_time' => time(), + ':active_time' => $active_time, + ':sub_time' => $sub_time + )); + if (!$retEquip) { + die(); + return; + } + } + $addreward = new classes\AddReward(); + $coin_num = $addreward->getCoinNum($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'coin_nums' => $coin_num, + 'flag' => $flag, + )); + } + + public function speedUpTime() + { + $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; + } + $type = $_REQUEST['type']; + $row = $conn->execQueryOne('SELECT * FROM equip WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + if (!$row) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $e = $this->getEquip($row['id']); + if (!$e) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); + return; + } + $sub_time = $row['sub_time'] - $row['sub_time'] * $e['reduce_time'] * 0.01; + //error_log($sub_time); + if ($type == 1) { + $rowUser = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + if (!$rowUser) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + if ($rowUser['diamond_num'] < $e['diamond_cost']) { + phpcommon\sendError(ERR_USER_BASE + 3, '钻石不足'); + return; + } + $sub_time = $row['sub_time'] - $row['sub_time'] * $e['diamond_time'] * 0.01; + $retUser = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':diamond_num' => $rowUser['diamond_num'] - $e['diamond_cost'], + ':modify_time' => time() + )); + if (!$retUser) { + die(); + return; + } + } + $active_time = $row['active_time']; + if ($sub_time == 0) { + $active_time = 0; + } + $retEquip = $conn->execScript('UPDATE equip SET active_time=:active_time, sub_time=:sub_time, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':active_time' => $active_time, + ':sub_time' => $sub_time, + ':modify_time' => time(), + )); + if (!$retEquip) { + die(); + return; + } + $addreward = new classes\AddReward(); + $num = $addreward->getDiamondNum($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'diamond_nums' => $num, + )); + } + +} +?> diff --git a/webapp/controller/GameOverController.class.php b/webapp/controller/GameOverController.class.php new file mode 100644 index 0000000..4d03b4e --- /dev/null +++ b/webapp/controller/GameOverController.class.php @@ -0,0 +1,291 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2004_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getRedis($shop_uuid) + { + $redis_conf = getRedisConfig(crc32($shop_uuid)); + $r = new phpcommon\Redis(array( + 'host' => $redis_conf['host'], + 'port' => $redis_conf['port'], + 'passwd' => $redis_conf['passwd'] + + )); + return $r; + } + + + protected function getBox($box_id) + { + $box_meta_table = require('../res/box@box.php'); + $box_meta = getBoxConfig($box_meta_table, $box_id); + $b = array( + 'box_id' => $box_meta['box_type'], + 'item_id' => $box_meta['item_id'], + 'num' => $box_meta['num'], + 'weight' => $box_meta['weight'], + 'type' => $box_meta['type'], + 'time' => $box_meta['time'], + 'count' => $box_meta['count'], + ); + return $b; + } + + 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 getEquip($equip_id) + { + $g_conf_equip_cluster = require('../res/equip@equip.php'); + $equip_conf = getEquipConfig($g_conf_equip_cluster, $equip_id); + $e = array( + 'id' => $equip_conf['id'], + 'upgrade_priority' => $equip_conf['upgrade_priority'], + 'equip_upgrade' => $equip_conf['equip_upgrade'], + 'level_gold_cost' => $equip_conf['level_gold_cost'], + 'max_level' => $equip_conf['max_level'], + 'equip_upgradematerial' => $equip_conf['equip_upgradematerial'], + 'equip_upgradetime' => $equip_conf['equip_upgradetime'], + 'diamond_cost' => $equip_conf['diamond_cost'], + 'drop_id' => $equip_conf['drop_id'] + ); + return $e; + } + + protected function getDrop($drop_id) + { + $drop_meta_table = require('../res/drop@drop.php'); + $drop_meta = getDropConfig($drop_meta_table, $drop_id); + $d = array( + 'drop_id' => $drop_meta['drop_id'], + 'item_id' => $drop_meta['item_id'], + 'num' => $drop_meta['num'], + 'weight' => $drop_meta['weight'], + 'type' => $drop_meta['type'] + ); + return $d; + } + + + public function firstRewardInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + + $first_uuid = 'game2004api_first_uuid:' . md5($_REQUEST['account_id']); + $r = $this->getRedis($first_uuid); + if (!$r) { + die(); + return; + } + $id = 12121; + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + die(); + } + $row = $conn->execQueryOne('SELECT id FROM equip WHERE accountid=:account_id;', + array( + ':account_id' => $account_id + )); + if ($row) { + $id = $row['id']; + } + //道具物品 + $first_list = array(); + $first_list = $this->fixReward($first_list); + $first_list = $this->randomReward($first_list, $id); + $first_db = array( + 'first_uuid' => $first_uuid, + 'first_list' => $first_list, + ); + $r -> set($first_uuid, json_encode($first_db)); + $r -> pexpire($first_uuid, 1000 * 3600 * 2); + + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'first_uuid' => $first_uuid, + 'item_list' => $first_list, + )); + } + + public function getFirstReward() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $type = $_REQUEST['type']; + $first_uuid = $_REQUEST['first_uuid']; + $item_id = 0; + $item_num = 0; + $flag = 0; + $addreward = new classes\AddReward(); + $item_list = array(); + $all_item_list = array(); + if ($type == 0) { + $item_list = $this->fixReward($item_list); + } else { + $r = $this->getRedis($first_uuid); + $user_db_str = $r->get($first_uuid); + if (empty($user_db_str)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); + return; + } + $user_db = json_decode($user_db_str, true); + if (empty($user_db)) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); + return; + } + $item_list = $user_db['first_list']; + } + foreach($item_list as $it) { + $items = $addreward->addReward($it['item_id'], $it['item_num'], $account_id, $it['time'], 0); + foreach($items as $j) { + array_push($all_item_list, array( + 'item_id' => $j['item_id'], + 'item_num' => $j['item_num'], + 'time' => $j['time'], + )); + } + } + $coin_num = $addreward->getCoinNum($account_id); + $diamond_num = $addreward->getDiamondNum($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'coin_nums' => $coin_num, + 'diamond_nums' => $diamond_num, + 'item_list' => $item_list, + 'all_item_list' => $all_item_list + )); + } + + protected function fixReward($item_list) + { + $b1 = $this->getbox(5); + if (!$b1) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + die(); + } + $fixed_id = $this->getExplode($b1['item_id']); + $fixed_time = $this->getExplode($b1['time']); + $fixed_num = $this->getExplode($b1['num']); + $fixed_array = $this->getExplode($b1['weight']); + + for($i = 0; $i < count($fixed_id); $i++) { + $random = Rand(0, 10000); + if ($fixed_array[$i][0] >= $random) { + array_push($item_list, array( + 'item_id' => $fixed_id[$i][0], + 'item_num' => $fixed_num[$i][0], + 'time' => $fixed_time[$i][0] + )); + } + } + return $item_list; + } + + protected function randomReward($item_list, $id) + { + //随机奖励 + //$e = $this->getEquip($id); + //$d = $this->getDrop($e['drop_id']); + + + $b = $this->getbox(6); + $count = 3; + $item_id_array = $this->getExplode($b['item_id']); + $item_num_array = $this->getExplode($b['num']); + $weight_array = $this->getExplode($b['weight']); + $time_array = $this->getExplode($b['time']); + $reward_array = array(); + for ($c = 0; $c < $count; $c++) { + $weight_sum = 0; + $keys = 0; + for ($ii = 0; $ii < count($weight_array); $ii++) { + $flag = $this->removal($reward_array, $item_id_array[$ii][0]); + if ($flag == 1) { + //error_log(222222222); + continue; + } + $weight_sum += $weight_array[$ii][0]; + } + $random = Rand(0, $weight_sum); + $weight = 0; + //error_log(json_encode($weight_array)); + for ($ii = 0; $ii < count($weight_array); $ii++) { + $flag = $this->removal($reward_array, $item_id_array[$ii][0]); + if ($flag == 1) { + //error_log(1111111); + continue; + } + $weight += $weight_array[$ii][0]; + if ($weight >= $random) { + $keys = $ii; + break; + } + } + $item_id = $item_id_array[$keys][0]; + $item_num = $item_num_array[$keys][0]; + $time = $time_array[$keys][0]; + array_push($reward_array, array( + 'id' => $item_id + )); + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + 'time' => $time + )); + } + //error_log(json_encode($item_list)); + return $item_list; + } + + protected function removal($reward, $id) + { + $flag = 0; + foreach ($reward as $r) { + if ($id == $r['id']) { + $flag = 1; + break; + } + } + return $flag; + } +}