$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 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; } 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) { $para_meta_table = require('../res/parameter@parameter.php'); $para_meta = getParameterConfig($para_meta_table, $para_id); $p = array( 'id' => $para_conf['id'], 'param_name' => $para_conf['param_name'], 'param_value' => $para_conf['param_value'], ); return $p; } public function roleInfo() { $account_id = $_REQUEST['account_id']; $user_name = $_REQUEST['name']; $avatar_url = $_REQUEST['avatar_url']; //登录校验 $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; } if (empty($_REQUEST['account_id'])) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { $ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, game_times, win_times, kills, harm, score, alive_time, coin_num, diamond_num, kill_his, alive_time_his, harm_his, create_time, modify_time, first_fight, collect_status, keys_num, battle_re_times, shop_flush_times, kefu_status, free_getbox) ' . ' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0) ' . ' ON DUPLICATE KEY UPDATE accountid=:accountid, user_name=:user_name, avatar_url=:avatar_url, game_times=0, win_times=0, kills=0, harm=0, score=0, alive_time=0, coin_num=0, diamond_num=0, kill_his=0, alive_time_his=0, harm_his=0, modify_time=:modify_time, first_fight=0, collect_status=0, keys_num=0, battle_re_times=0, shop_flush_times=0, kefu_status=0, free_getbox=0;', array( ':accountid' => $account_id, ':user_name' => $user_name, ':avatar_url' => $avatar_url, ':create_time' => time(), ':modify_time' => time() )); if (!$ret) { die(); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'game_times' => 0, 'win_times' => 0, 'high_kill' => 0, 'kills' => 0, 'high_harm' => 0, 'harm' => 0, 'score' => 0, 'alive_time' => 0, 'coin_num' => 0, 'first_fight' => 0, 'collect_status' => 0, 'keys_num' => 0, 'kefu_status' => 0, 'diamond_num' => 0, 'free_getbox' => 0, )); } else { echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'game_times' => $row['game_times'], 'win_times' => $row['win_times'], 'high_kill' => $row['kill_his'], 'kills' => $row['kills'], 'high_harm' => $row['harm_his'], 'harm' => $row['harm'], 'score' => $row['score'], 'alive_time' => $row['alive_time'], 'coin_num' => $row['coin_num'], 'first_fight' => $row['first_fight'], 'collect_status' => $row['collect_status'], 'keys_num' => $row['keys_num'], 'kefu_status' => $row['kefu_status'], 'diamond_num' => $row['diamond_num'], 'free_getbox' => $row['free_getbox'] )); } } public function battleReport() { $account_id = $_REQUEST['account_id']; //账号 $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } $map_id = $_REQUEST['map_id']; $map_tpl_name = $_REQUEST['map_tpl_name']; $room_uuid = $_REQUEST['room_uuid']; //战斗id $map_name = $_REQUEST['map_name']; //地图名 $game_time = $_REQUEST['game_time']; //游戏结束时间 $hurt = $_REQUEST['hurt']; //承受伤害 $rank = $_REQUEST['rank']; //排名 $kills = $_REQUEST['kills']; //击杀数 $harm = $_REQUEST['harm']; //伤害 $alive_time = $_REQUEST['alive_time']; //存活时间 $skill = $_REQUEST['skill']; //技能释放数 $tank1_kill = $_REQUEST['tank1_kill']; //坦克1击杀数 $tank2_kill = $_REQUEST['tank2_kill']; //坦克2击杀数 $tank3_kill = $_REQUEST['tank3_kill'];//坦克3击杀数 $rescue_member = $_REQUEST['rescue_member']; //救起队友次数 $kill_his = $kills; $harm_his = $harm; $alive_time_his = $alive_time; $coin_num = $_REQUEST['coin_num']; //金币 $score = $_REQUEST['score']; //积分 if (!$map_id) { $map_id = 0; } if (!$map_tpl_name) { $map_tpl_name = ''; } $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家1'); return; } if ($kill_his < $row['kill_his']) { $kill_his = $row['kill_his']; } if ($harm_his < $row['harm_his']) { $harm_his = $row['harm_his']; } if ($rank == 1) { $row['win_times']++; } if ($alive_time_his < $row['alive_time_his']) { $alive_time_his = $row['alive_time_his']; } $ret = $conn->execScript('UPDATE user SET game_times=:game_times, win_times=:win_times, kills=:kills, harm=:harm, add_HP=:add_HP, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, score=:score, coin_num=:coin_num, modify_time=:modify_time, first_fight=1 ' . ' WHERE accountid=:accountid;', array( ':game_times' => $row['game_times'] + 1, ':win_times' => $row['win_times'], ':kill_his' => $kill_his, ':kills' => $row['kills'] + $kills, ':harm_his' => $harm_his, ':harm' => $row['harm'] + $harm, ':add_HP' => $row['add_HP'] + $add_HP, ':alive_time' => $row['alive_time'] + $alive_time, ':alive_time_his' => $alive_time_his, ':accountid' => $account_id, ':coin_num' => $row['coin_num'] + $coin_num, ':score' => $row['score'] + $score, ':modify_time' => time() )); if (!$ret) { die(); return; } //插入历史记录 $ret = $conn->execScript('INSERT INTO history_record(accountid, room_uuid, map_id, map_tpl_name, map_name, game_time, rank, kills, harms, hurts, alive_time, coin, status, create_time, modify_time) ' . ' VALUES(:accountid, :room_uuid, :map_id, :map_tpl_name, :map_name, :game_time, :rank, :kills, :harms, :hurts, :alive_time, :coin, 0, :create_time, :modify_time) ' . ' ON DUPLICATE KEY UPDATE accountid=:accountid, room_uuid=:room_uuid, map_id=:map_id, map_tpl_name=:map_tpl_name, map_name=:map_name, game_time=:game_time, rank=:rank, kills=:kills, harms=:harms, hurts=:hurts, alive_time=:alive_time, coin=:coin, status=0, modify_time=:modify_time;', array( ':accountid' => $account_id, ':room_uuid' => $room_uuid, ':map_id' => $map_id, ':map_tpl_name' => $map_tpl_name, ':map_name' => $map_name, ':game_time' => $game_time, ':rank' => $rank, ':kills' => $kills, ':harms' => $harm, ':hurts' => $hurt, ':alive_time' => $alive_time, ':coin' => $coin_num, ':create_time' => time(), ':modify_time' => time() )); if (!$ret) { die(); return; } //刷新任务 $quest = new classes\Quest(); $quest->triggerQuest(QUEST_DAY_FIGHT, 1, 1, $account_id); $quest->triggerQuest(QUEST_DAY_ALIVE, 1, (int)($alive_time / 1000 / 60), $account_id); $quest->triggerQuest(QUEST_DAY_HARM, 1, $harm, $account_id); $quest->triggerQuest(QUEST_DAY_KILL, 1, $kills, $account_id); $quest->triggerQuest(QUEST_SUM_FIGHT, 2, 1, $account_id); $quest->triggerQuest(QUEST_SUM_ALIVE, 2, (int)($alive_time / 1000 / 60), $account_id); $quest->triggerQuest(QUEST_SUM_HARM, 2, $harm, $account_id); $quest->triggerQuest(QUEST_SUM_KILL, 2, $kills, $account_id); $quest->triggerQuest(QUEST_SUM_SKILL, 2, $skill, $account_id); $quest->triggerQuest(QUEST_SUM_TANK1KILL, 2, $tank1_kill, $account_id); $quest->triggerQuest(QUEST_SUM_TANK2KILL, 2, $tank2_kill, $account_id); $quest->triggerQuest(QUEST_SUM_TANK3KILL, 2, $tank3_kill, $account_id); if ($rank <= 5) { $quest->triggerQuest(QUEST_DAY_RANK, 1, 1, $account_id); } if ($rank == 1) { $quest->triggerQuest(QUEST_SUM_WIM, 2, 1, $account_id); } //额外奖励 $times = $this->getRewardTimes($coin_num); $extra_coin = $coin_num * ($times - 1); $d = $this->getDrop(24004); if (!$d) { phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); return; } $skin_id_array = $this->getExplode($d['item_id']); $weight_sum = 0; $keys = 0; $skin_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($room_uuid); $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; } } $extra_drop = ""; $skin_id = $skin_id_array[$keys][0]; $skin_num = $skin_num_array[$keys][0]; $p_battle_reward = $this->getParameter(MAX_BATTLE_REWARD); if ($row['battle_re_times'] >= $p_battle_reward['param_value']) { $extra_drop = '10001:' . $extra_coin; } else { $extra_drop = '10001:' . $extra_coin . '|10002:1' . '|' . $skin_id . ':' . $skin_num; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'kill_his' => $kill_his, 'alive_time_his' => $alive_time_his, 'harm_his' => $harm_his, 'extra_drop' => $extra_drop )); } public function historyRecord() { $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; } $rowCount = $conn->execQueryRowCount('SELECT * FROM history_record WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if ($rowCount != 0) { $rows = $conn->execQuery('SELECT * FROM history_record WHERE accountid=:account_id;', array( ':account_id' => $account_id )); foreach ($rows as $row) { array_push($record_list, array( 'map_name' => $row['map_name'], 'game_time' => $row['game_time'], 'rank' => $row['rank'], 'kills' => $row['kills'], 'harms' => $row['harms'], 'hurts' => $row['hurts'], 'alive_time' => $row['alive_time'] )); } } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'record_list' => $record_list )); } public function shareGame() { $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; } $quest = new classes\Quest(); $quest->triggerQuest(QUEST_DAY_SHARE, 1, 1, $account_id); $quest->triggerQuest(QUEST_SUM_SHARE, 2, 1, $account_id); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } public function historyInfo() { $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; } $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'kill_his' => $row['kill_his'], 'alive_time_his' => $row['alive_time_his'], 'harm_his' => $row['harm_his'], 'add_HP_his' => $row['add_HP_his'] )); } public function fightReward() { $account_id = $_REQUEST['account_id']; $room_uuid = $_REQUEST['room_uuid']; //登录校验 $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; } $row = $conn->execQueryOne('SELECT * FROM history_record WHERE accountid=:accountid AND room_uuid=:room_uuid;', array( ':accountid' => $account_id, ':room_uuid' => $room_uuid )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这场战斗记录'); return; } if ($row['status'] == 1) { phpcommon\sendError(ERR_USER_BASE + 3, '战斗奖励已领取'); return; } $coin_num = $row['coin']; $times = $this->getRewardTimes($coin_num); $coin_num = $row['coin'] * ($times - 1); $d = $this->getDrop(24004); if (!$d) { phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); return; } $skin_id_array = $this->getExplode($d['item_id']); $weight_sum = 0; $keys = 0; $skin_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($room_uuid); $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; } } $skin_id = $skin_id_array[$keys][0]; $skin_num = $skin_num_array[$keys][0]; $p_battle_reward = $this->getParameter(MAX_BATTLE_REWARD); $addreward = new classes\AddReward(); $addreward->addReward(10001, $coin_num, $account_id); $rowUser = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if ($rowUser['battle_re_times'] < $p_battle_reward['param_value']) { $keys_num = $rowUser['keys_num'] + 1; $battle_re_times = $rowUser['battle_re_times'] + 1; $addreward->addReward($skin_id, $skin_num, $account_id); $ret = $conn->execScript('UPDATE user SET battle_re_times=:battle_re_times, keys_num=:keys_num, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':keys_num' => $keys_num, ':battle_re_times' => $battle_re_times, ':modify_time' => time(), ':accountid' => $account_id )); if (!$ret) { die(); return; } } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } protected function getRewardTimes($coin_num) { $g_conf_reward_cluster = require('../res/rewardTimes@rewardTimes.php'); $times = 1; $reward_conf = array(); for ($i = 0; $i < 4; $i++) { $reward_id = $i + 91100; $reward_conf = getRewardTimesConfig($g_conf_reward_cluster, $reward_id); if ((int)$coin_num >= $reward_conf['minGold'] && (int)$coin_num <= $reward_conf['maxGold']) { $times = $reward_conf['times']; break; } } return $times; } public function collectReward() { $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; } $ret = $conn->execScript('UPDATE user SET collect_status=1, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', array( ':modify_time' => time(), ':accountid' => $account_id )); if (!$ret) { die(); return; } $d = $this->getDrop(24006); 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[0] >= Rand(0, 10000)) { $item_id = $item_id_array[0]; $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 )); } $i++; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'item_list' => $item_list )); } } ?>