game2002api/webapp/controller/RoleController.class.php
wangwei01 0bd95356b7 1
2019-07-08 15:01:32 +08:00

646 lines
27 KiB
PHP

<?php
require 'classes/Quest.php';
require 'classes/AddReward.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;
}
protected function getActivityRewardConfig($activityReward_id)
{
$g_conf_activityReward_cluster = require('../res/activityReward@activityReward.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 getDrop($drop_id)
{
$g_conf_drop_cluster = require('../res/drop@drop.php');
$drop_conf = getDropConfig($g_conf_drop_cluster, $drop_id);
$d = array(
'drop_id' => $drop_conf['drop_id'],
'item_id' => $drop_conf['item_id'],
'num' => $drop_conf['num'],
'weight' => $drop_conf['weight'],
'type' => $drop_conf['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)
{
$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;
}
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, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his, act_share_time, act_share_status, create_time, modify_time, first_fight, collect_status, keys_num, battle_re_times, shop_flush_times, kefu_status) ' .
' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, create_time, :modify_time, 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, add_HP=0, alive_time=0, coin_num=0, integral=0, kill_his=0, alive_time_his=0, harm_his=0, add_HP_his=0, act_share_time=0, act_share_status=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;',
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,
'add_HP' => 0,
'alive_time' => 0,
'coin_num' => 0,
'first_fight' => 0,
'collect_status' => 0,
'keys_num' => 0,
'kefu_status' => 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'],
'first_fight' => $row['first_fight'],
'collect_status' => $row['collect_status'],
'keys_num' => $row['keys_num'],
'kefu_status' => $row['kefu_status'],
));
}
}
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']; //伤害
$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']; //积分
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'];
}
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, 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,
':add_HP_his' => $add_HP_his,
':accountid' => $account_id,
':coin_num' => $row['coin_num'] + $coin_num,
':integral' => $row['integral'] + $integral,
':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_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_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);
}*/
//额外奖励
$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,
'add_HP_his' => $add_HP_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(24003);
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);
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
));
}
public function collectDoubleReward()
{
$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;
}
$d = $this->getDrop(24003);
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[$i][0] >= Rand(0, 10000)) {
$item_id = $item_id_array[$i][0];
$item_num = $num_array[$i][0];
$addreward = new classes\AddReward();
$addreward->addReward($item_id, $item_num, $account_id);
}
$i++;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
));
}
}
?>