game2004api/webapp/controller/RoleController.class.php
aozhiwei b405645f2e 1
2020-06-04 16:22:56 +08:00

1107 lines
45 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' => 'gamedb2004_' . $mysql_conf['instance_id']
));
return $conn;
}
protected function getRedis($account_id)
{
$redis_conf = getRedisConfig(crc32($account_id));
$r = new phpcommon\Redis(array(
'host' => $redis_conf['host'],
'port' => $redis_conf['port'],
'passwd' => $redis_conf['passwd']
));
return $r;
}
protected function getParameter($para_id)
{
$parameter_meta_cluster = require('../res/parameter@parameter.php');
$parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id);
$p = array(
'id' => $parameter_meta['id'],
'name' => $parameter_meta['param_name'],
'param_value' => $parameter_meta['param_value'],
);
return $p;
}
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 getSeason($season_id)
{
$season_meta_table = require('../res/season@season.php');
$season_meta = getSeasonConfig($season_meta_table, $season_id);
$season = array(
'number' => $season_meta['season_number'],
'open_time' => $season_meta['time1'],
'end_time' => $season_meta['time2'],
'reward' => $season_meta['season_reward'],
'weekreward' => $season_meta['week_reward'],
);
return $season;
}
protected function getSeasonPoint($seaPoint_id)
{
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
$seaPoint_meta = getSeasonPointConfig($seaPoint_meta_table, $seaPoint_id);
$seaPoint = array(
'id' => $seaPoint_meta['id'],
'min' => $seaPoint_meta['min_point'],
'max' => $seaPoint_meta['max_point'],
'des' => $seaPoint_meta['des'],
'topoint' => $seaPoint_meta['topoint'],
//'weekreward' => $seaPoint_meta['week_reward'],
);
return $seaPoint;
}
public function roleInfo()
{
$account_id = $_REQUEST['account_id'];
$user_name = $_REQUEST['name'];
$avatar_url = $_REQUEST['avatar_url'];
$switch_id = $_REQUEST['switch_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;
}
$this->updateSwitch($account_id, $switch_id);
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
//$newInfo = array();
if (!$row) {
$season_time = 0;
$season_meta_table = require('../res/season@season.php');
for ($i = 1; $i <= count($season_meta_table); $i++) {
$season = $this->getSeason($i);
if (time() >= strtotime($season['open_time']) && time() <= strtotime($season['end_time'])) {
$season_time = strtotime($season['end_time']);
break;
}
}
$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, sign_sum, box_num, diamond_num, sum_coin, pass_status, score, season_status, recharge_times_total, first_gift, season_time, free_coin, free_diamond, season_end_score, kill_modifytime, win_modifytime, rank_modifytime, vip_score, first_login, daily_first_login, daily_time, free_box, update_time, season_games, season_win, sea_max_kill, sea_max_hart, sea_avg_kill, free_lot_ticket, free_dou_lot_ticket, daily_order1, daily_order2, daily_order3, first_bee, newhand, coin_times, newInfo) ' .
' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 200, 0, 0, 0, 0, 0, 0, 0, :create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, :season_time, 0, 0, 0, 0, 0, 0, 0, 0, 0, :daily_time, 0,:update_time,0,0,0,0,0,0,0,0,0,0,0,0,0,:newInfo) ' .
' 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, sign_sum=0, box_num=0, diamond_num=0, sum_coin=0, pass_status=0, score=0, season_status=1, recharge_times_total=0, first_gift=0, season_time=:season_time, free_coin=0, free_diamond=0, season_end_score=0, kill_modifytime=0, win_modifytime=0, rank_modifytime=0, vip_score=0, first_login=0, daily_first_login=0, daily_time=:daily_time, free_box=0, update_time=:update_time, season_games=0, season_win=0, sea_max_kill=0, sea_max_hart=0, sea_avg_kill=0, free_lot_ticket=0, free_dou_lot_ticket=0, daily_order1=0, daily_order2=0, daily_order3=0, first_bee=0, newhand=0, coin_times=0, newInfo=:newInfo;',
array(
':accountid' => $account_id,
':user_name' => $user_name,
':avatar_url' => $avatar_url,
':create_time' => time(),
':modify_time' => time(),
':daily_time' => 0,
':update_time' => time(),
':newInfo' => '',
':season_time' => $season_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' => 200,
'first_fight' => 0,
'collect_status' => 0,
'keys_num' => 0,
'kefu_status' => 0,
'box_num' => 0,
'diamond_num' => 0,
'pass_status' => 0,
'season_status' => 1,
'first_gift' => 0,
'sum_coin' => 0,
'recharge_times_total' => 0,
'first_login' => 0,
'daily_first_login' => 0,
'free_box' => 0,
'season_games' => 0,
'season_win' => 0,
'sea_max_kill' => 0,
'sea_max_hart' => 0,
'sea_avg_kill' => 0,
'free_lot_ticket' => 0,
'free_dou_lot_ticket' => 0,
'time' => time(),
'newhand' => 0,
'vip_score' => 0,
'coin_times' => 0,
'newInfo' => ''
));
} else {
if ($avatar_url != '') {
if ($user_name != $row['user_name']) {
$ret = $conn->execScript('UPDATE user SET user_name=:user_name, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':user_name' => $user_name,
':modify_time' => time()
));
}
if ($avatar_url != $row['avatar_url']) {
$ret = $conn->execScript('UPDATE user SET avatar_url=:avatar_url, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':avatar_url' => $avatar_url,
':modify_time' => time()
));
}
}
$nowTime = phpcommon\getdayseconds(time());
$daily_first_login = $row['daily_first_login'];
$coin_times = $row['coin_times'];
$kefu_status = $row['kefu_status'];
if ($row['update_time'] == 0 || ($nowTime - phpcommon\getdayseconds($row['update_time']) > 0)) {
$ret = $conn->execScript('UPDATE user SET daily_first_login=0, kefu_status=0, coin_times=0, ' .
'modify_time=:modify_time WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':modify_time' => time(),
));
if (!$ret) {
die();
return;
}
$daily_first_login = 0;
$kefu_status = 0;
$coin_times = 0;
if (time() > $row['season_time'] && $row['season_time'] != 0) {
$this->updateSeasonStatus($account_id);
}
}
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
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' => $kefu_status,
'box_num' => $row['box_num'],
'diamond_num' => $row['diamond_num'],
'pass_status' => $row['pass_status'],
'season_status' => $row['season_status'],
'first_gift' => $row['first_gift'],
'sum_coin' => $row['sum_coin'],
'recharge_times_total' => $row['recharge_times_total'],
'first_login' => $row['first_login'],
'daily_first_login' =>$daily_first_login,
'vip_score' => $row['vip_score'],
'coin_nums' => $row['coin_num'],
'diamond_nums' => $row['diamond_num'],
'free_box' => $row['free_box'],
'season_games' => $row['season_games'],
'season_win' => $row['season_win'],
'sea_max_kill' => $row['sea_max_kill'],
'sea_max_hart' => $row['sea_max_hart'],
'sea_avg_kill' => $row['sea_avg_kill'],
'free_dou_lot_ticket' => $row['free_dou_lot_ticket'],
'free_lot_ticket' => $row['free_lot_ticket'],
'time' => time(),
'newhand' => $row['newhand'],
'coin_times' => $coin_times,
'newInfo' => $row['newInfo']
));
}
}
protected function updateSeasonStatus($account_id)
{
$conn = $this->getMysql($account_id);
if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
die();
}
//刷新赛季奖励状态
$rowUser = $conn->execQueryOne('SELECT season_time, pass_status, integral ' .
' FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
));
if (time() > $rowUser['season_time'] && $rowUser['season_time'] != 0) {
$season_meta_table = require('../res/season@season.php');
$end_time = 0;
for ($i = 1; $i <= count($season_meta_table); $i++) {
$season = $this->getSeason($i);
if (time() >= strtotime($season['open_time']) && time() <= strtotime($season['end_time'])) {
$end_time = strtotime($season['end_time']);
break;
}
}
$season_point_table = require('../res/seasomPoint@seasomPoint.php');
$integral = 0;
for ($j = 1; $j <= count($season_point_table); $j++) {
$seasonpoint = $this->getSeasonPoint($j);
if ($rowUser['integral'] <= $seasonpoint['max'] ||
$seasonpoint['max'] == -1) {
$integral = $seasonpoint['topoint'];
break;
}
}
$user_ret = $conn->execScript('UPDATE user SET pass_status=0, score=0, season_status=0, integral=:integral, season_end_score=:season_end_score, modify_time=:modify_time, season_games=0, sea_max_kill=0, sea_max_hart=0, sea_avg_kill=0, season_win=0, season_time=:season_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':season_end_score' => $rowUser['integral'],
':modify_time' => time(),
':season_time' => $end_time,
':integral' => $integral
));
if (!$user_ret) {
die();
}
$pass_ret = $conn->execScript('UPDATE passinfo SET active_status=0, honor_status=0, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':modify_time' => time()
));
if (!$pass_ret) {
die();
}
}
}
protected function updateDaily($account_id, $daily_time)
{
$nowTime = phpcommon\getdayseconds(time());
$conn = $this->getMysql($account_id);
$daily_first_login = $daily_first_login + 1;
//更新人物信息
if ($daily_time == 0 || ($nowTime - phpcommon\getdayseconds($daily_time) > 0)) {
$daily_first_login = 0;
}
$ret = $conn->execScript('UPDATE user SET daily_first_login=:daily_first_login, ' .
'modify_time=:modify_time WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':modify_time' => time(),
':daily_first_login' => $daily_first_login,
));
if (!$ret) {
die();
}
return $daily_first_login;
}
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['rank_score']; //排位积分
$score = $_REQUEST['pass_score']; //通行证积分
if ($_REQUEST['items'] != '') {
$item_list = $this->getExplode($_REQUEST['items']);
$addreward = new classes\AddReward();
$addreward->addReward((int)$item_list[0][0], (int)$item_list[0][1], $account_id, 0, 0);
}
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;
}
//更新击杀信息时间
$k = 0;
if ($row['game_times'] != 0) {
$k = $row['kill_his'] / $row['game_times'];
}
if (($row['kill_his'] + $kills) / ($row['game_times'] + 1) != $k) {
$killret = $conn->execScript('UPDATE user SET kill_modifytime=:kill_modifytime ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':kill_modifytime' => time(),
));
if (!$killret) {
die();
return;
}
}
//更新胜场信息时间
if ($rank == 1) {
$winret = $conn->execScript('UPDATE user SET win_times=:win_times, season_win=:season_win, win_modifytime=:win_modifytime ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':win_times' => $row['win_times'] + 1,
':season_win' => $row['season_win'] + 1,
':win_modifytime' => time(),
));
if (!$winret) {
die();
return;
}
}
//更新排位积分信息时间
if ($integral != 0) {
$inret = $conn->execScript('UPDATE user SET integral=:integral, rank_modifytime=:rank_modifytime ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':integral' => $row['integral'] + $integral,
':rank_modifytime' => time(),
));
if (!$inret) {
die();
return;
}
}
//更新历史最高信息
if ($kill_his < $row['kill_his']) {
$kill_his = $row['kill_his'];
}
if ($harm_his < $row['harm_his']) {
$harm_his = $row['harm_his'];
}
$sea_max_hart = $harm;
if ($sea_max_hart < $row['sea_max_hart']) {
$sea_max_hart = $row['sea_max_hart'];
}
$sea_max_kill = $kills;
if ($sea_max_kill < $row['sea_max_kill']) {
$sea_max_kill = $row['sea_max_kill'];
}
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'];
}
//添加空投箱
$box_num = $row['box_num'];
if ($row['box_num'] + 1 <= 20) {
$box_num = $row['box_num'] + 1;
}
$nowTime = phpcommon\getdayseconds(time());
$daily_time = $row['daily_time'];
if ($daily_time == 0 || ($nowTime - phpcommon\getdayseconds($daily_time) > 0)) {
$daily_time = time();
}
$daily_first_login = $row['daily_first_login'];
/* $switch = $this->getSwitch($account_id);
if ($switch == 1) {
$daily_first_login = $daily_first_login + 1;
}*/
$newhand = $row['newhand'];
$p1 = $this->getParameter(NEWHAND_NUM1);
$fight_times = $p1['param_value'];
$p2 = $this->getParameter(NEWHAND_NUM2);
$view_times = $p2['param_value'];
if ($row['game_times'] + 1 == $fight_times && $row['vip_score'] >= $view_times) {
$newhand = 1;
}
$ret = $conn->execScript('UPDATE user SET game_times=:game_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, modify_time=:modify_time, first_fight=1, box_num=:box_num, score=:score, daily_time=:daily_time, season_games=:season_games, sea_max_kill=:sea_max_kill, sea_max_hart=:sea_max_hart, sea_avg_kill=:sea_avg_kill, newhand=:newhand ' .
'WHERE accountid=:accountid;',
array(
':game_times' => $row['game_times'] + 1,
':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,
':modify_time' => time(),
':box_num' => $box_num,
':score' => $row['score'] + $score,
':daily_time' => $daily_time,
':season_games' => $row['season_games'] + 1,
':sea_max_kill' => $sea_max_kill,
':sea_max_hart' => $sea_max_hart,
':sea_avg_kill' => $row['sea_avg_kill'] + $kills,
':newhand' => $newhand,
));
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);
if ($team_status == 1 && $rank <= 5) {
$quest->triggerQuest(QUEST_DAY_RANK, 1, 1, $account_id);
}
if ($team_status == 1) {
$quest->triggerQuest(QUEST_DAY_TEAM, 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'];
//登录校验
$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 order by game_time desc limit 0,10;',
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);
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 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[$i][0];
$item_num = $num_array[$i][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();
$p = $this->getParameter(REWARD_TIMES);
$times = $p['param_value'] - 1;
foreach ($weight_array as $item) {
if ($item[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 * $times, $account_id);
}
$i++;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
));
}
public function getPreSettlementInfo()
{
$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);
$pre_settlement_info = '';
if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'pre_settlement_info' => $pre_settlement_info
));
}
public function getRobotInfo()
{
$account_id = $_REQUEST['account_id'];
//登录校验
$login = loginVerify($account_id, $_REQUEST['session_id']);
if (!$login) {
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$member = array();
$i = Rand(1, 100);
$coin = Rand(1, 100) * 0.01;
$num = 1;
$robot_id = 1000 + $i;
$address = '../res/robot@robot' . $num . '.php';
$robot_meta_cluster = require($address);
$robot_meta = getRobotConfig($robot_meta_cluster, $robot_id);
$rob = array(
'id' => $robot_meta['id'],
'name' => $robot_meta['name'],
'avatar_url' => $robot_meta['avatar_url'],
'sex' => $robot_meta['sex']
);
array_push ($member, array(
'account_id' => $rob['id'],
'name' => $rob['name'],
'avatar_url' => $rob['avatar_url'],
));
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'member_list' => $member,
'sin_member' => $robot_meta_cluster,
'num' => $coin,
));
}
protected function updateSwitch($account_id, $switch_id)
{
$r = $this->getRedis($account_id);
if (!$r) {
die();
return;
}
$switch_uuid = 'game2004api_switch:' . $account_id;
$r -> set($switch_uuid, $switch_id);
$r -> pexpire($switch_uuid, 1000 * 3600 * 24);
}
protected function getSwitch($account_id)
{
$r = $this->getRedis($account_id);
if (!$r) {
die();
return;
}
$switch_uuid = 'game2004api_switch:' . $account_id;
$user_db_str = $r->get($switch_uuid);
$switch = json_decode($user_db_str, true);
return $switch;
}
public function getFightReward()
{
$account_id = $_REQUEST['account_id'];
//登录校验
$login = loginVerify($account_id, $_REQUEST['session_id']);
if (!$login) {
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$coin_num = $_REQUEST['coin_num'];
$reward_id = $_REQUEST['reward_id'];
$reward_num = $_REQUEST['reward_num'];
$addreward = new classes\AddReward();
$p = $this->getParameter(GAMEOVER_REWARD_TIMES);
$times = $p['param_value'] - 1;
$addreward->addReward(10001, $coin_num * $times, $account_id, 0, 0);
if ($reward_id != 0) {
$addreward->addReward($reward_id, $reward_num * $times, $account_id, 0, 0);
}
$coin_num = $addreward->getCoinNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'coin_nums' => $coin_num,
));
}
public function getNewHandReward()
{
$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 newhand FROM user WHERE accountid=:account_id;',
array(
':account_id' => $account_id
));
if (!$row || $row['newhand'] != 1) {
phpcommon\sendError(ERR_USER_BASE + 2, '未达到领取条件');
return;
}
$ret = $conn->execScript('UPDATE user SET newhand=2, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':modify_time' => time(),
':accountid' => $account_id
));
if (!$ret) {
die();
return;
}
$d = $this->getDrop(29001);
if (!$d) {
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
return;
}
$item_list = array();
$all_item_list = array();
$item_id_array = $this->getExplode($d['item_id']);
$item_num_array = $this->getExplode($d['num']);
for ($i = 0; $i < count($item_id_array); $i++) {
$item_id = $item_id_array[$i][0];
$item_num = $item_num_array[$i][0];
array_push($item_list, array(
'item_id' => $item_id,
'item_num' => $item_num,
'time' => 0
));
}
$addreward = new classes\AddReward();
foreach ($item_list as $item) {
$items = $addreward->addReward($item['item_id'], $item['item_num'], $account_id, $item['time'], 0);
foreach($items as $i) {
array_push($all_item_list, array(
'item_id' => $i['item_id'],
'item_num' => $i['item_num'],
'time' => $i['time'],
));
}
}
$coin_num = $addreward->getCoinNum($account_id);
$num = $addreward->getDiamondNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'item_list' => $item_list,
'coin_num' => $coin_num,
'diamond_nums' => $num,
'all_item_list' => $all_item_list
));
}
public function getSessionId()
{
$account_id = $_REQUEST['account_id'];
$registertime = $_REQUEST['registertime'];
$session_key = $_REQUEST['session_key'];
$session_id = $this->createSessionId($account_id, $registertime, $session_key);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'session_id' => $session_id,
));
}
protected function createSessionId($accountid, $registertime, $session_key)
{
$nowtime = time();
// error_log($accountid . 'f3a6a9a5-217a-4079-ab99-b5d69b8212be' . $registertime . $nowtime);
$session_id = $nowtime
. '_'
. $registertime
. '_'
. md5($accountid . 'f3a6a9a5-217a-4079-ab99-b5d69b8212be' . $registertime . $nowtime)
. '_'
. md5('f3a6a9a5-217a-4079-ab99-b5d69b8212be'
. $accountid
. $session_key
. time()
. rand()
);
return $session_id;
}
public function exchangeCoin()
{
$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;
}
$rowUser = $conn->execQueryOne('SELECT coin_times, coin_num FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
));
if (!$rowUser) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$coin_times = $rowUser['coin_times'];
$p1 = $this->getParameter(DAILYCOIN_TIMES);
$max_times = $p1['param_value'];
$p2 = $this->getParameter(DAILYCOIN_DECAY);
$val = $p2['param_value'];
$p3 = $this->getParameter(DAILYCOIN_NUM);
$num = $p3['param_value'];
if ($coin_times >= $max_times) {
phpcommon\sendError(ERR_USER_BASE + 2, '今日次数达到上限');
return;
}
$coin_num = round($num * pow($val, $coin_times));
//error_log($coin_num);
$ret = $conn->execScript('UPDATE user SET coin_times=:coin_times, coin_num=:coin_num, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':coin_times' => $coin_times + 1,
':coin_num' => $coin_num + $rowUser['coin_num'],
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
$coin = $coin_num + $rowUser['coin_num'];
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'coin_nums' => $coin,
'coin_times' => $coin_times + 1
));
}
public function saveNewbie()
{
$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;
}
//$info = array();
$id = $_REQUEST['id'];
$rowUser = $conn->execQueryOne('SELECT newInfo FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
));
if (!$rowUser) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$info = json_decode($rowUser['newInfo']);
if (empty($info)) {
$info = array();
}
array_push($info, (int)$id);
$ret = $conn->execScript('UPDATE user SET newInfo=:newInfo,modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':newInfo' => json_encode($info),
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
));
}
}
?>