game2001api/webapp/controller/RoleController.class.php
aozhiwei e073dabedf 1
2020-09-25 16:14:23 +08:00

1175 lines
50 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 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 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'];
$switch_id = isset($_REQUEST['switch_id']) ? $_REQUEST['switch_id'] : 0;
$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
));
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, 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, chapingcount, aderrormaxcount, share_video_times, daily_skin_times, share_equip_times, daily_diamond_times, newhand, game_times2, view_times2, daily_ad_times, mid_aut_adtimes, mid_aut_status, daily_draw_status, daily_box_times, daily_box_status, daily_box2_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, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :daily_time, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 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=0, 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, chapingcount=0, aderrormaxcount=0, share_video_times=0, daily_skin_times=0, share_equip_times=0, daily_diamond_times=0, newhand=0, game_times2=0, view_times2=0, daily_ad_times=0, mid_aut_adtimes=0, mid_aut_status=0, daily_draw_status=0, daily_box_times=0, daily_box_status=0, daily_box2_status=0;',
array(
':accountid' => $account_id,
':user_name' => $user_name,
':avatar_url' => $avatar_url,
':create_time' => time(),
':modify_time' => time(),
':daily_time' => 0
));
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,
'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,
'chapingcount' => 0,
'aderrormaxcount' => 0,
'share_video_times' => 0,
'daily_skin_times' => 0,
'share_equip_times' => 0,
'daily_diamond_times' => 0,
'newhand' => 0,
'game_times2' => 0,
'view_times2' => 0,
'daily_ad_times' => 0,
'mid_aut_adtimes' => 0,
'mid_aut_status' => 0,
'daily_draw_status' => 0,
'daily_box_times' => 0,
'daily_box_status' => 0,
'daily_box2_status' => 0,
));
} else {
$ret = $conn->execScript('UPDATE user SET first_login=1 ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
));
if (!$ret) {
die();
return;
}
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'];
$chapingcount = $row['chapingcount'];
$aderrormaxcount = $row['aderrormaxcount'];
$share_video_times = $row['share_video_times'];
$daily_skin_times = $row['daily_skin_times'];
$box_num = $row['box_num'];
$share_equip_times = $row['share_equip_times'];
$daily_diamond_times = $row['daily_diamond_times'];
$daily_ad_times = $row['daily_ad_times'];
$daily_draw_status = $row['daily_draw_status'];
$daily_box_times = $row['daily_box_times'];
$daily_box_status = $row['daily_box_status'];
$daily_box2_status = $row['daily_box2_status'];
if ($row['daily_time'] == 0 || ($nowTime - phpcommon\getdayseconds($row['daily_time']) > 0)) {
$ret = $conn->execScript('UPDATE user SET daily_first_login=0, share_video_times=0, daily_skin_times=0, box_num=0, daily_time=:daily_time, share_equip_times=0, daily_diamond_times=0,' .
'modify_time=:modify_time, daily_ad_times=0, daily_draw_status=0, daily_box_times=0, daily_box_status=0, daily_box2_status=0 WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':modify_time' => time(),
':daily_time' => time(),
));
if (!$ret) {
die();
return;
}
$daily_first_login = 0;
$share_video_times = 0;
$daily_skin_times = 0;
$box_num = 0;
$share_equip_times = 0;
$daily_diamond_times = 0;
$daily_ad_times = 0;
$daily_draw_status = 0;
$daily_box_times = 0;
$daily_box_status = 0;
$daily_box2_status = 0;
}
//更新新手礼
$newhand = $this->getnewhandinfo($row['newhand'], $row['game_times2'], $row['view_times2'], $account_id);
//更新中秋活动礼
$mid_aut_status = $this->getmidautinfo($row['mid_aut_status'], $row['mid_aut_adtimes'], $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' => $row['kefu_status'],
'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' => 1,
'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'],
'chapingcount' => $chapingcount,
'aderrormaxcount' => $aderrormaxcount,
'share_video_times' => $share_video_times,
'daily_skin_times' => $daily_skin_times,
'box_num' => $box_num,
'share_equip_times' => $share_equip_times,
'daily_diamond_times' => $daily_diamond_times,
'newhand' => $newhand,
'game_times2' => $row['game_times2'],
'view_times2' => $row['view_times2'],
'daily_ad_times' => $daily_ad_times,
'mid_aut_adtimes' => $row['mid_aut_adtimes'],
'mid_aut_status' => $row['mid_aut_status'],
'daily_draw_status' => $daily_draw_status,
'daily_box_times' => $daily_box_times,
'daily_box_status' => $daily_box_status,
'daily_box2_status' => $daily_box2_status,
));
}
}
protected function getnewhandinfo($status, $num1, $num2, $account_id)
{
$p3 = $this->getParameter(ZIJIE_ACTIVITY_FIGHT);
$fight_times2 = $p3['param_value'];
$p4 = $this->getParameter(ZIJIE_ACTIVITY_ADS);
$view_times2 = $p4['param_value'];
$conn = $this->getMysql($account_id);
if ($num1 >= $fight_times2 && $num2 >= $view_times2 && $status == 0) {
$ret = $conn->execScript('UPDATE user SET newhand=1, ' .
'modify_time=:modify_time WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':modify_time' => time(),
));
if (!$ret) {
die();
}
return 1;
}
return $status;
}
protected function getmidautinfo($status, $num, $account_id)
{
$p3 = $this->getParameter(ZIJIE_ACTIVITY2_ADS);
$fight_times2 = $p3['param_value'];
$conn = $this->getMysql($account_id);
if ($num >= $fight_times2 && $status == 0) {
$ret = $conn->execScript('UPDATE user SET mid_aut_status=1, ' .
'modify_time=:modify_time WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':modify_time' => time(),
));
if (!$ret) {
die();
}
return 1;
}
return $status;
}
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 (!$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, win_modifytime=:win_modifytime ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':win_times' => $row['win_times'] + 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'];
}
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'];
$game_times2 = $row['game_times2'];
$p3 = $this->getParameter(ZIJIE_ACTIVITY_FIGHT);
$fight_times2 = $p3['param_value'];
$p4 = $this->getParameter(ZIJIE_ACTIVITY_ADS);
$view_times2 = $p4['param_value'];
if ($row['game_times2'] + 1 == $fight_times2 && $row['view_times2'] >= $view_times2) {
$newhand = 1;
}
$game_times2++;
$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, score=:score, daily_first_login=:daily_first_login, newhand=:newhand, game_times2=:game_times2 ' .
'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(),
':score' => $row['score'] + $score,
':daily_first_login' => $daily_first_login,
':game_times2' => $game_times2,
':newhand' => $newhand,
));
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);
}
}
//额外奖励
$p = $this->getParameter(REWARD_TIMES);
$times = $p['param_value'] - 1;
$extra_coin = $coin_num * $times;
$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 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);
$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'];
$coin_num = $_REQUEST['coin'];
//登录校验
$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 = $this->getParameter(REWARD_TIMES);
// //$times = $p['param_value'] - 1;
// $times = 1;
// $coin_num = $row['coin'] * $times;
// $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;
// }
// }
$coin_nums = $addreward->getCoinNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'coin_nums' => $coin_nums,
));
}
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 = 'game2001api_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 = 'game2001api_switch:' . $account_id;
$user_db_str = $r->get($switch_uuid);
$switch = json_decode($user_db_str, true);
return $switch;
}
public function addChapingCount()
{
$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 chapingcount FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$chapingcount = $row['chapingcount'] + 1;
$ret = $conn->execScript('UPDATE user SET chapingcount=:chapingcount, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':modify_time' => time(),
':accountid' => $account_id,
':chapingcount' => $chapingcount
));
if (!$ret) {
die();
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'chapingcount' => $chapingcount,
));
}
public function updateadErrorMaxCount()
{
$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 aderrormaxcount FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$aderrormaxcount = $row['aderrormaxcount'] + 1;
$ret = $conn->execScript('UPDATE user SET aderrormaxcount=:aderrormaxcount, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':modify_time' => time(),
':accountid' => $account_id,
':aderrormaxcount' => $aderrormaxcount
));
if (!$ret) {
die();
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'aderrormaxcount' => $aderrormaxcount
));
}
public function getVideoReward()
{
$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 diamond_num, share_video_times, share_equip_times FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
));
if (!$rowUser) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$type = 0;
if (isset($_REQUEST['type'])) {
$type = $_REQUEST['type'];
}
$lv = 0;
if ($type == 0) {
if ($rowUser['share_video_times'] >= 3) {
phpcommon\sendError(ERR_USER_BASE + 2, '今日领取奖励次数已达上限');
return;
}
$num = 100;
$ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, share_video_times=:share_video_times, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':diamond_num' => $rowUser['diamond_num'] + $num,
':share_video_times' => $rowUser['share_video_times'] + 1,
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
} else if ($type == 1) {
$row = $conn->execQueryOne('SELECT equip_level FROM equip WHERE accountid=:account_id AND equip_id=:equip_id;',
array(
':account_id' => $account_id,
':equip_id' => $type
));
if (!$row) {
return;
}
$lv = $row['equip_level'] + 1;
$ret = $conn->execScript('UPDATE equip SET equip_level=:equip_level, modify_time=:modify_time ' .
' WHERE accountid=:account_id AND equip_id=:equip_id;',
array(
':account_id' => $account_id,
':equip_id' => $type,
':equip_level' => $lv,
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
$p = $this->getParameter(SHAREWUQILV);
$ret2 = $conn->execScript('UPDATE user SET share_equip_times=:share_equip_times, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':share_equip_times' => $rowUser['share_equip_times'] + $p['param_value'],
':modify_time' => time()
));
if (!$ret2) {
die();
return;
}
}
$addreward = new classes\AddReward();
$diamond_num = $addreward->getDiamondNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'diamond_nums' => $diamond_num,
'lv' => $lv,
));
}
}
?>