$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 getActivityRewardConfig($activityReward_id) { $g_conf_activityReward_cluster = require('../config/game2001api.activityReward.cluster.php'); $activityReward_conf = getActivityRewardConfig($g_conf_activityReward_cluster, $activityReward_id); $act = array( 'id' => $activityReward_conf['id'], 'activity_id' => $activityReward_conf['activity_id'], 'condition' => $activityReward_conf['condition'], 'parameter' => $activityReward_conf['parameter'], 'start_end_time' => $activityReward_conf['start_end_time'], 'activity_reward' => $activityReward_conf['activity_reward'], 'exchange_num' => $activityReward_conf['exchange_num'], 'exchange_item' => $activityReward_conf['exchange_item'] ); return $act; } 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('../config/game2001api.parameter.cluster.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; } public function roleInfo() { $account_id = $_REQUEST['account_id']; $user_name = $_REQUEST['name']; $avatar_url = $_REQUEST['avatar_url']; $login = loginVerify($account_id, $_REQUEST['session_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; } 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, rank, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his, act_share_time, act_share_status) ' . ' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 0, 100000, 0, 0, 0, 0, 0, 0, 0);', array( ':accountid' => $account_id, ':user_name' => $user_name, ':avatar_url' => $avatar_url )); 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, 'add_HP' => 0, 'alive_time' => 0, 'coin_num' => 100000, )); } 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'], 'add_HP' => $row['add_HP'], 'alive_time' => $row['alive_time'], 'coin_num' => $row['coin_num'] )); } } public function battleReport() { $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; } $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']; //伤害 $add_HP = $_REQUEST['add_HP']; //治疗量 $alive_time = $_REQUEST['alive_time']; //存活时间 $team_status = $_REQUEST['team_status']; //是否是组队状态 $snipe_kill = $_REQUEST['snipe_kill']; //狙击枪击杀数 $rifle_kill = $_REQUEST['rifle_kill']; //步枪击杀数 $pistol_kill = $_REQUEST['pistol_kill']; //手枪击杀数 $submachine_kill = $_REQUEST['submachine_kill'];//冲锋枪击杀数 $rescue_member = $_REQUEST['rescue_member']; //救起队友次数 $kill_his = $kills; $harm_his = $harm; $alive_time_his = $alive_time; $add_HP_his = $add_HP; $coin_num = $_REQUEST['coin_num']; //金币 $integral = $_REQUEST['score']; //积分 $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); if (!$row) { phpcommon\sendError(ERR_USER_BASE + 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']; } if ($add_HP_his < $row['add_HP_his']) { $add_HP_his = $row['add_HP_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, add_HP_his=:add_HP_his, coin_num=:coin_num, integral=:integral ' . ' 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, ':add_HP_his' => $add_HP_his, ':accountid' => $account_id, ':coin_num' => $row['coin_num'] + $coin_num, ':integral' => $row['integral'] + $integral )); if (!$ret) { die(); return; } //插入历史记录 $ret = $conn->execScript('INSERT INTO history_record(accountid, room_uuid, map_name, game_time, rank, kills, harms, hurts, alive_time, coin, status) ' . ' VALUES(:accountid, :room_uuid, :map_name, :game_time, :rank, :kills, :harms, :hurts, :alive_time, :coin, 0);', array( ':accountid' => $account_id, ':room_uuid' => $room_uuid, ':map_name' => $map_name, ':game_time' => $game_time, ':rank' => $rank, ':kills' => $kills, ':harms' => $harm, ':hurts' => $hurt, ':alive_time' => $alive_time, ':coin' => $coin_num )); 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_DAY_GAME, 1, 1, $account_id); $quest->triggerQuest(QUEST_DAY_HELP, 1, $rescue_member, $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_GAME, 2, 1, $account_id); $quest->triggerQuest(QUEST_SUM_HELP, 2, $rescue_member, $account_id); $quest->triggerQuest(QUEST_SUM_SNIPEKILL, 2, $snipe_kill, $account_id); $quest->triggerQuest(QUEST_SUM_RIFLEKILL, 2, $rifle_kill, $account_id); $quest->triggerQuest(QUEST_SUM_PISTOLKILL, 2, $pistol_kill, $account_id); $quest->triggerQuest(QUEST_SUM_SUBMACKILL, 2, $submachine_kill, $account_id); if ($team_status == 1 && $rank <= 5) { $quest->triggerQuest(QUEST_DAY_RANK, 1, 1, $account_id); } if ($team_status == 0 && $rank == 1) { $quest->triggerQuest(QUEST_SUM_WIM, 2, 1, $account_id); } if ($team_status == 1) { $quest->triggerQuest(QUEST_DAY_TEAM, 1, 1, $account_id); $quest->triggerQuest(QUEST_SUM_TEAM, 2, 1, $account_id); if ($rank == 1) { $quest->triggerQuest(QUEST_SUM_TEAMWIN, 2, 1, $account_id); } } //触发活动任务 $act = $this->getActivityRewardConfig(QUEST_ACTIVITY_LOGIN); $array = $this->getExplode($act['start_end_time']); $nowTime = phpcommon\getdayseconds(time()); $start_time = $array[0][0] * 3600 + $array[0][1] * 60 + $nowTime; $end_time = $array[1][0] * 3600 + $array[1][1] * 60 + $nowTime; if (time() >= $start_time && time() < $start_time) { $quest->triggerQuest(QUEST_ACTIVITY_GAME, 3, 1, $account_id); } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'kill_his' => $kill_his, 'alive_time_his' => $alive_time_his, 'harm_his' => $harm_his, 'add_HP_his' => $add_HP_his )); } 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); } 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']; $p_gold = $this->getParameter(DOUBLE_END_WAR); $coin_num = $row['coin'] * ($p_gold['param_value'] - 1); $rowUser = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':coin_num' => $coin_num + $rowUser['coin_num'] )); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', )); } } ?>