307 lines
13 KiB
PHP
307 lines
13 KiB
PHP
<?php
|
|
|
|
require 'classes/Quest.php';
|
|
|
|
class RoleController{
|
|
|
|
protected function getMysql($account_id)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($account_id));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => 'gamedb2001_' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
public function roleInfo()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$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) {
|
|
$ret = $conn->execScript('INSERT INTO user(accountid, rank, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his) ' .
|
|
' VALUES(:accountid, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
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' => 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'],
|
|
'add_HP' => $row['add_HP'],
|
|
'alive_time' => $row['alive_time'],
|
|
'coin_num' => $row['coin_num']
|
|
));
|
|
}
|
|
}
|
|
|
|
public function battleReport()
|
|
{
|
|
$account_id = $_REQUEST['account_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']; //救起队友次数
|
|
$conn = $this->getMysql($account_id);
|
|
$kill_his = $kills;
|
|
$harm_his = $harm;
|
|
$alive_time_his = $alive_time;
|
|
$add_HP_his = $add_HP;
|
|
$coin_num = $_REQUEST['coin_num']; //金币
|
|
$integral = $_REQUEST['score']; //积分
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
if ($rank == 1) {
|
|
$win_times = 1;
|
|
} else {
|
|
$win_times = 0;
|
|
}
|
|
$ret = $conn->execScript('INSERT INTO user(accountid, game_times, win_times, kills, harm, add_HP, alive_time, kill_his, alive_time_his, harm_his, add_HP_his, coin_num, integral) ' .
|
|
' VALUES(:accountid, :game_times, :win_times, :kills, :harm, :add_HP, :alive_time, :kill_his, :alive_time_his, :harm_his, :add_HP_his, :coin_num, :integral);',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':game_times' => 1,
|
|
':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
|
|
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
} else {
|
|
if ($kills < $row['kill_his']) {
|
|
$high_kill = $row['kill_his'];
|
|
}
|
|
if ($harm < $row['harm_his']) {
|
|
$high_harm = $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']++,
|
|
':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, map_name, game_time, rank, kills, harms, hurts, alive_time) ' .
|
|
' VALUES(:accountid, :map_name, :game_time, :rank, :kills, :harms, :hurts, :alive_time);',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':map_name' => $map_name,
|
|
':game_time' => $game_time,
|
|
':rank' => $rank,
|
|
':kills' => $kills,
|
|
':harms' => $harm,
|
|
':hurts' => $hurt,
|
|
':alive_time' => $alive_time,
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
//刷新任务
|
|
$quest = new classes\Quest();
|
|
$quest->triggerQuest(QUEST_DAY_FIGHT, 1, 1, $account_id);
|
|
$quest->triggerQuest(QUEST_DAY_ALIVE, 1, $alive_time, $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, 1, 1, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_ALIVE, 1, $alive_time, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_HARM, 1, $harm, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_KILL, 1, $kills, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_GAME, 1, 1, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_HELP, 1, $rescue_member, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_SNIPEKILL, 1, $snipe_kill, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_RIFLEKILL, 1, $rifle_kill, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_PISTOLKILL, 1, $pistol_kill, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_SUBMACKILL, 1, $submachine_kill, $account_id);
|
|
if ($team_status != 0 && $rank <= 5) {
|
|
$quest->triggerQuest(QUEST_DAY_RANK, 1, 1, $account_id);
|
|
}
|
|
if ($team_status == 1 && $rank == 1) {
|
|
$quest->triggerQuest(QUEST_SUM_TEAMWIM, 1, 1, $account_id);
|
|
}
|
|
if ($team_status == 2) {
|
|
$quest->triggerQuest(QUEST_DAY_TEAM, 1, 1, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_TEAM, 1, 1, $account_id);
|
|
if ($rank == 1) {
|
|
$quest->triggerQuest(QUEST_SUM_FRITEAMWIN, 1, 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'];
|
|
$conn = $this->getMysql($account_id);
|
|
$record_list = array();
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_BASE_USER + 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'];
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_BASE_USER + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$quest = new classes\Quest();
|
|
$quest->triggerQuest(QUEST_DAY_SHARE, 1, 1, $account_id);
|
|
$quest->triggerQuest(QUEST_SUM_SHARE, 1, 1, $account_id);
|
|
}
|
|
|
|
public function historyInfo()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_BASE_USER + 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']
|
|
));
|
|
}
|
|
}
|
|
|
|
|
|
?>
|