game2004api/webapp/controller/GameOverController.class.php
aozhiwei d46e3e7f9a 1
2020-08-14 19:05:01 +08:00

338 lines
11 KiB
PHP

<?php
require 'classes/Quest.php';
require 'classes/AddReward.php';
class GameOverController{
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($shop_uuid)
{
$redis_conf = getRedisConfig(crc32($shop_uuid));
$r = new phpcommon\Redis(array(
'host' => $redis_conf['host'],
'port' => $redis_conf['port'],
'passwd' => $redis_conf['passwd']
));
return $r;
}
protected function getBox($box_id)
{
$box_meta_table = require('../res/box@box.php');
$box_meta = getBoxConfig($box_meta_table, $box_id);
$b = array(
'box_id' => $box_meta['box_type'],
'item_id' => $box_meta['item_id'],
'num' => $box_meta['num'],
'weight' => $box_meta['weight'],
'type' => $box_meta['type'],
'time' => $box_meta['time'],
'count' => $box_meta['count'],
);
return $b;
}
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 getEquip($equip_id)
{
$g_conf_equip_cluster = require('../res/equip@equip.php');
$equip_conf = getEquipConfig($g_conf_equip_cluster, $equip_id);
$e = array(
'id' => $equip_conf['id'],
'upgrade_priority' => $equip_conf['upgrade_priority'],
'equip_upgrade' => $equip_conf['equip_upgrade'],
'level_gold_cost' => $equip_conf['level_gold_cost'],
'max_level' => $equip_conf['max_level'],
'equip_upgradematerial' => $equip_conf['equip_upgradematerial'],
'equip_upgradetime' => $equip_conf['equip_upgradetime'],
'diamond_cost' => $equip_conf['diamond_cost'],
'drop_id' => $equip_conf['drop_id']
);
return $e;
}
protected function getDrop($drop_id)
{
$drop_meta_table = require('../res/drop@drop.php');
$drop_meta = getDropConfig($drop_meta_table, $drop_id);
$d = array(
'drop_id' => $drop_meta['drop_id'],
'item_id' => $drop_meta['item_id'],
'num' => $drop_meta['num'],
'weight' => $drop_meta['weight'],
'type' => $drop_meta['type']
);
return $d;
}
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 getRankReward($rank)
{
$rank_meta_table = require('../res/rankReward@rankReward.php');
$rank_meta = getRankRewardConfig($rank_meta_table, $rank);
$d = array(
'rank' => $rank_meta['rank'],
'parameter' => $rank_meta['parameter'],
'drop' => $rank_meta['drop'],
'ad_drop' => $rank_meta['ad_drop'],
'ad_num' => $rank_meta['ad_num'],
'js_num' => $rank_meta['js_num'],
'js_drop' => $rank_meta['js_drop'],
'zbmode_param' => $rank_meta['zbmode_param'],
);
return $d;
}
public function firstRewardInfo()
{
$account_id = $_REQUEST['account_id'];
//登录校验
$login = loginVerify($account_id, $_REQUEST['session_id']);
if (!$login) {
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$first_uuid = 'game2004api_first_uuid:' . md5($_REQUEST['account_id']);
$r = $this->getRedis($first_uuid);
if (!$r) {
die();
return;
}
$rank = $_REQUEST['rank'];
$type = 0;
$coin = 0;
$score = 0;
$kills = 0;
$normal_coin = 0;
$num = 1;
if (isset($_REQUEST['type'])) {
$type = $_REQUEST['type'];
}
$p = $this->getParameter(EQUIPREWARD_PARAMETER);
$par = $p['param_value'];
if ($type == 1) {
$ar = $this->getRankReward($rank);
$coin = $ar['zbmode_param'];
$num = ceil($ar['zbmode_param'] / $par);
if (isset($_REQUEST['kills'])) {
$score = $_REQUEST['kills'] * 10;
}
} else if ($type == 0) {
if (isset($_REQUEST['coin'])) {
$num = ceil($_REQUEST['coin'] / $par);
}
}
//道具物品
$first_list = array();
if (phpcommon\extractChannel($account_id) == 6000 || phpcommon\extractChannel($account_id) == 6001) {
array_push($first_list, array(
'item_id' => 18006,
'item_num' => $num,
'time' => 0,
));
} else {
$first_list = $this->randomReward($rank, $type);
}
$first_db = array(
'first_uuid' => $first_uuid,
'first_list' => $first_list,
);
$r -> set($first_uuid, json_encode($first_db));
$r -> pexpire($first_uuid, 1000 * 3600 * 2);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'first_uuid' => $first_uuid,
'item_list' => $first_list,
'coin' => $coin,
'score' => $score,
));
}
public function getFirstReward()
{
$account_id = $_REQUEST['account_id'];
//登录校验
$login = loginVerify($account_id, $_REQUEST['session_id']);
if (!$login) {
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$type = $_REQUEST['type'];
$first_uuid = $_REQUEST['first_uuid'];
$item_id = 0;
$item_num = 0;
$flag = 0;
$addreward = new classes\AddReward();
$item_list = array();
$all_item_list = array();
if ($type == 0) {
$item_list = $this->fixReward($item_list);
} else {
$r = $this->getRedis($first_uuid);
$user_db_str = $r->get($first_uuid);
if (empty($user_db_str)) {
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
return;
}
$user_db = json_decode($user_db_str, true);
if (empty($user_db)) {
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
return;
}
$item_list = $user_db['first_list'];
}
foreach($item_list as $it) {
$items = $addreward->addReward($it['item_id'], $it['item_num'], $account_id, $it['time'], 0);
foreach($items as $j) {
array_push($all_item_list, array(
'item_id' => $j['item_id'],
'item_num' => $j['item_num'],
'time' => $j['time'],
));
}
}
$coin_num = $addreward->getCoinNum($account_id);
$diamond_num = $addreward->getDiamondNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'coin_nums' => $coin_num,
'diamond_nums' => $diamond_num,
'item_list' => $item_list,
'all_item_list' => $all_item_list
));
}
protected function fixReward($item_list)
{
$b1 = $this->getbox(5);
if (!$b1) {
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
die();
}
$fixed_id = $this->getExplode($b1['item_id']);
$fixed_time = $this->getExplode($b1['time']);
$fixed_num = $this->getExplode($b1['num']);
$fixed_array = $this->getExplode($b1['weight']);
for($i = 0; $i < count($fixed_id); $i++) {
$random = Rand(0, 10000);
if ($fixed_array[$i][0] >= $random) {
array_push($item_list, array(
'item_id' => $fixed_id[$i][0],
'item_num' => $fixed_num[$i][0],
'time' => $fixed_time[$i][0]
));
}
}
return $item_list;
}
protected function randomReward($rank,$type)
{
//随机奖励
$r = $this->getRankReward($rank);
$b = $this->getDrop($r['ad_drop']);
$count = $r['ad_num'];
if ($type == 1) {
$b = $this->getDrop($r['js_drop']);
$count = $r['js_num'];
}
$item_list = array();
$item_id_array = $this->getExplode($b['item_id']);
$item_num_array = $this->getExplode($b['num']);
$weight_array = $this->getExplode($b['weight']);
$reward_array = array();
for ($c = 0; $c < $count; $c++) {
$weight_sum = 0;
$keys = 0;
for ($ii = 0; $ii < count($weight_array); $ii++) {
$flag = $this->removal($reward_array, $item_id_array[$ii][0]);
if ($flag == 1) {
continue;
}
$weight_sum += $weight_array[$ii][0];
}
$random = Rand(0, $weight_sum);
$weight = 0;
for ($ii = 0; $ii < count($weight_array); $ii++) {
$flag = $this->removal($reward_array, $item_id_array[$ii][0]);
if ($flag == 1) {
continue;
}
$weight += $weight_array[$ii][0];
if ($weight >= $random) {
$keys = $ii;
break;
}
}
$item_id = $item_id_array[$keys][0];
$item_num = $item_num_array[$keys][0];
$time = 0;
array_push($reward_array, array(
'id' => $item_id
));
array_push($item_list, array(
'item_id' => $item_id,
'item_num' => $item_num,
'time' => $time
));
}
return $item_list;
}
protected function removal($reward, $id)
{
$flag = 0;
foreach ($reward as $r) {
if ($id == $r['id']) {
$flag = 1;
break;
}
}
return $flag;
}
}