This commit is contained in:
yangduo 2025-03-20 13:40:43 +08:00
parent 53ea4022c7
commit 880662aeee
3 changed files with 378 additions and 11 deletions

View File

@ -456,6 +456,7 @@ CREATE TABLE `solo` (
`lastoffline` int(11) NOT NULL DEFAULT '0' COMMENT '上次计算离线收益时间戳',
`offline` int(11) NOT NULL DEFAULT '0' COMMENT '已计算离线时长(小时)',
`gamelevel` mediumblob NOT NULL COMMENT '关卡信息',
`funds` mediumblob NOT NULL COMMENT '基金',
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),

View File

@ -852,6 +852,105 @@ class RechargeController
)
);
}
} else {
//等级基金,关卡基金,体力基金
$solorow = $conn->execQueryOne(
'SELECT funds FROM solo WHERE accountid=:accountid;',
array(
':accountid' => $account_id
)
);
$funds = array();
$fundsname = 'shop_' . $goodsid;
if (!$solorow || is_null($solorow['funds']) || empty($solorow['funds'])) {
$funds = array(
"playerlevel" => array(
"hit" => 0,
"details" => array(
"free" => array(),
),
),
"gamelevel" => array(
"hit" => 0,
"details" => array(
"free" => array(),
),
),
"medalcost" => array(
"hit" => 0,
"sum" => 0,
"details" => array(
"free" => array(),
),
),
);
switch ($shopgoods['type']) {
case 5;
$funds['playerlevel']['details'][$fundsname] = array();
break;
case 7;
$funds['gamelevel']['details'][$fundsname] = array();
break;
case 8;
$funds['medalcost']['details'][$fundsname] = array();
break;
}
} else {
$funds = json_decode($solorow['funds'], true);
switch ($shopgoods['type']) {
case 5;
for ($id = 1; $id <= $funds['playerlevel']['hit']; $id++) {
$funds['playerlevel']['details'][$fundsname][] = $id;
}
break;
case 7;
for ($id = 1; $id <= $funds['gamelevel']['hit']; $id++) {
$funds['gamelevel']['details'][$fundsname][] = $id;
}
break;
case 8;
for ($id = 1; $id <= $funds['medalcost']['hit']; $id++) {
$funds['medalcost']['details'][$fundsname][] = $id;
}
break;
}
}
if (!$solorow) {
$privilege = new classes\Privilege();
$medals = metatable\getParameterById(MEDAL_LIMIT) + $privilege->getMedalLimitPlus($account_id);
$gamelevel = array(
'curlevel' => 1,
'curwave' => 0,
'levelinfo' => array(),
);
$ret = $conn->execScript(
'INSERT INTO solo(accountid, level, exp, medals, lastredeem, lastoffline, gamelevel, funds, create_time, modify_time) ' .
' VALUES(:account_id, 1, 0, :medals, :lastredeem, :lastoffline, :gamelevel, :funds, :create_time, :modify_time) ' .
' ON DUPLICATE KEY UPDATE accountid=:account_id, level=1, exp=0, medals=:medals, lastredeem=:lastredeem, lastoffline=:lastoffline, gamelevel=:gamelevel, funds=:funds, modify_time=:modify_time;',
array(
':account_id' => $account_id,
':medals' => $medals,
':lastredeem' => $nowtime,
':lastoffline' => $nowtime,
':gamelevel' => json_encode($gamelevel),
':funds' => json_encode($funds),
':create_time' => $nowtime,
':modify_time' => $nowtime
)
);
} else {
$ret = $conn->execScript(
'UPDATE solo SET funds=:funds, modify_time=:modify_time' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':funds' => json_encode($funds),
':modify_time' => time()
)
);
}
}
echo json_encode(array(

View File

@ -44,6 +44,24 @@ class SoloController
return array_key_exists($level, $conf) ? $conf[$level] : null;
}
protected function getPlayerLevelFundInfo()
{
$conf = require('../res/levelfund@levelfundaccount.php');
return $conf;
}
protected function getGameLevelFundInfo()
{
$conf = require('../res/levelfund@levelfundgame.php');
return $conf;
}
protected function getMedalCostFundInfo()
{
$conf = require('../res/levelfund@levelfundstamina.php');
return $conf;
}
public function soloInfo()
{
$account_id = $_REQUEST['account_id'];
@ -78,18 +96,41 @@ class SoloController
'curwave' => 0,
'levelinfo' => array(),
);
$funds = array(
"playerlevel" => array(
"hit" => 0,
"details" => array(
"free" => array(),
),
),
"gamelevel" => array(
"hit" => 0,
"details" => array(
"free" => array(),
),
),
"medalcost" => array(
"hit" => 0,
"sum" => 0,
"details" => array(
"free" => array(),
),
),
);
$offlinehours = 0;
if (!$solorow) {
$medals = $medalsgrowlimit;
$ret = $conn->execScript(
'INSERT INTO solo(accountid, level, exp, medals, lastredeem, lastoffline, create_time, modify_time) ' .
' VALUES(:account_id, 1, 0, :medals, :lastredeem, :lastoffline, :create_time, :modify_time) ' .
' ON DUPLICATE KEY UPDATE accountid=:account_id, level=:level, exp=:exp, medals=:medals, lastredeem=:lastredeem, lastoffline=:lastoffline, modify_time=:modify_time;',
'INSERT INTO solo(accountid, level, exp, medals, lastredeem, lastoffline, gamelevel, funds, create_time, modify_time) ' .
' VALUES(:account_id, 1, 0, :medals, :lastredeem, :lastoffline, :gamelevel, :funds, :create_time, :modify_time) ' .
' ON DUPLICATE KEY UPDATE accountid=:account_id, level=1, exp=0, medals=:medals, lastredeem=:lastredeem, lastoffline=:lastoffline, gamelevel=:gamelevel, funds=:funds, modify_time=:modify_time;',
array(
':account_id' => $account_id,
':medals' => $medals,
':lastredeem' => $lastredeem,
':lastoffline' => $nowtime,
':gamelevel' => json_encode($gamelevel),
':funds' => json_encode($funds),
':create_time' => $nowtime,
':modify_time' => $nowtime
)
@ -143,6 +184,10 @@ class SoloController
if (!is_null($solorow['gamelevel']) && !empty($solorow['gamelevel'])) {
$gamelevel = json_decode($solorow['gamelevel']);
}
if (!is_null($solorow['funds']) && !empty($solorow['funds'])) {
$funds = json_decode($solorow['funds']);
}
}
$upexp = 0;
@ -161,7 +206,8 @@ class SoloController
'medal_limit' => $medalsgrowlimit,
'lastredeem' => $lastredeem,
'offlinehours' => $offlinehours,
'gamelevel' => $gamelevel
'gamelevel' => $gamelevel,
'funds' => $funds,
));
}
@ -362,16 +408,16 @@ class SoloController
}
$awardarr = explode($waveawardarr[$key], ';');
foreach($awardarr as $awarditem) {
foreach ($awardarr as $awarditem) {
$strs = explode($awarditem, ':');
if (count($strs) < 2) {
continue;
}
$item_list[]=array(
$item_list[] = array(
'item_id' => $strs[0],
'item_num' => $strs[1],
"time" => 0,
"time" => 0,
);
}
@ -437,6 +483,158 @@ class SoloController
{
$this->levelaward(false);
}
// 基金奖励
public function fundsAward()
{
$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;
}
$fundstype = $_REQUEST['type'];
$fundsname = $_REQUEST['name'];
$fundsid = $_REQUEST['id'];
if ($fundstype < 1 || $fundstype > 3) {
phpcommon\sendError(ERR_USER_BASE + 1, '基金不存在');
return;
}
$solorow = $conn->execQueryOne(
'SELECT * FROM solo WHERE accountid=:accountid;',
array(
':accountid' => $account_id
)
);
if (!$solorow) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 1');
return;
}
if (is_null($solorow['funds']) || empty($solorow['funds'])) {
phpcommon\sendError(ERR_USER_BASE + 1, '基金不存在 1');
return;
}
$funds = json_decode($solorow['funds'], true);
$details = array();
$fundscfg = array();
switch ($fundstype) {
case 1:
$details = &$funds['playerlevel']['details'];
$fundscfg = $this->getPlayerLevelFundInfo();
break;
case 2:
$details = &$funds['gamelevel']['details'];
$fundscfg = $this->getGameLevelFundInfo();
break;
case 3:
$details = &$funds['medalcost']['details'];
$fundscfg = $this->getMedalCostFundInfo();
break;
}
if (!array_key_exists($fundsname, $details)) {
phpcommon\sendError(ERR_USER_BASE + 1, '基金不存在 2');
return;
}
$found = false;
foreach ($details[$fundsname] as &$id) {
if ($id == $fundsid) {
$found = true;
unset($id);
break;
}
}
if (!$found) {
phpcommon\sendError(ERR_USER_BASE + 1, '基金不存在 3');
return;
}
if (!array_key_exists($fundsid, $fundscfg)) {
phpcommon\sendError(ERR_USER_BASE + 1, '基金不存在 4');
return;
}
if (!array_key_exists($fundsname, $fundscfg[$fundsid])) {
phpcommon\sendError(ERR_USER_BASE + 1, '基金不存在 5');
return;
}
$ret = $conn->execScript(
'UPDATE solo SET funds=:funds, modify_time=:modify_time' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':funds' => json_encode($funds),
':modify_time' => time()
)
);
if (!$ret) {
phpcommon\sendError(ERR_RETRY + 1, '系统繁忙');
return;
}
$awardstrs = explode($fundscfg[$fundsid][$fundsname], '|');
$item_list = array();
foreach($awardstrs as $awarditem) {
$strs = explode($awarditem, ':');
if (count($strs) < 2) {
continue;
}
$item_list[] = array(
'item_id' => $strs[0],
'item_num' => $strs[1],
"time" => 0,
);
}
$addreward = new classes\AddReward();
$all_item_list = array();
foreach ($item_list as $itemaward) {
$items = $addreward->addReward($itemaward['item_id'], $itemaward['item_num'], $account_id, 0, 0);
foreach ($items as $i) {
array_push($all_item_list, array(
'item_id' => $i['item_id'],
'item_num' => $i['item_num'],
'time' => 0,
));
}
}
$coin_num = $addreward->getCoinNum($account_id);
$diamond_num = $addreward->getDiamondNum($account_id);
$adfree = $addreward->getAdfree($account_id);
$medals = $addreward->getMedals($account_id);
$response = array(
'errcode' => 0,
'errmsg' => '',
'type' => $fundstype,
'name' => $fundsname,
'id' => $fundsid,
'coin_nums' => $coin_num,
'diamond_nums' => $diamond_num,
'adfree' => $adfree,
'medals' => $medals,
'item_list' => $item_list,
'all_item_list' => $all_item_list,
);
echo json_encode($response);
}
protected function levelaward($isbattle)
{
@ -508,7 +706,8 @@ class SoloController
return;
}
if ($reqlevelcfg['medal_cost'] > $solorow['medals']) {
$medalcost = $reqlevelcfg['medal_cost'];
if ($medalcost > $solorow['medals']) {
phpcommon\sendError(ERR_USER_BASE + 2, '体力不足');
return;
}
@ -577,7 +776,7 @@ class SoloController
}
// cost medals, add exp
$curexp = $solorow['exp'] + $reqlevelcfg['medal_cost'];
$curexp = $solorow['exp'] + $medalcost;
$curlv = $solorow['level'];
$curlvcfg = $this->getPlayerLevelInfo($curlv);
$uplv_item_list = array();
@ -601,7 +800,7 @@ class SoloController
}
}
$curmedals = $solorow['medals'] - $reqlevelcfg['medal_cost'];
$curmedals = $solorow['medals'] - $medalcost;
$lastredeem = $solorow['lastredeem'];
$privilege = new classes\Privilege();
$medalsgrowlimit = metatable\getParameterById(MEDAL_LIMIT) + $privilege->getMedalLimitPlus($account_id);
@ -609,8 +808,10 @@ class SoloController
$lastredeem = time();
}
$funds = json_decode($solorow['funds'], true);
$this->updateFunds($curlv, $level, $medalcost, $funds);
$ret = $conn->execScript(
'UPDATE solo SET medals=:medals, lastredeem=:lastredeem, level=:level, exp=:exp, gamelevel=:gamelevel, modify_time=:modify_time' .
'UPDATE solo SET medals=:medals, lastredeem=:lastredeem, level=:level, exp=:exp, gamelevel=:gamelevel, funds=:funds, modify_time=:modify_time' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
@ -619,6 +820,7 @@ class SoloController
':level' => $curlv,
':exp' => $curexp,
':gamelevel' => json_encode($gamelevel),
':funds' => $funds,
':modify_time' => time()
)
);
@ -678,4 +880,69 @@ class SoloController
}
echo json_encode($response);
}
protected function updateFunds($playerlevel, $gamelevel, $medalcost, &$funds)
{
$accountfundcfg = $this->getPlayerLevelFundInfo();
foreach ($accountfundcfg as $cfgitem) {
$newhit = $cfgitem['id'];
if ($newhit <= $funds['playerlevel']['hit']) {
continue;
}
if ($cfgitem['level'] > $playerlevel) {
break;
}
if ($newhit > $funds['playerlevel']['hit']) {
$funds['playerlevel']['hit'] = $newhit;
}
foreach ($funds['playerlevel']['details'] as $key => $fundsitem) {
$funds['playerlevel']['details'][$key][] = $newhit;
}
}
$gamefundcfg = $this->getGameLevelFundInfo();
foreach ($gamefundcfg as $cfgitem) {
$newhit = $cfgitem['id'];
if ($newhit <= $funds['gamelevel']['hit']) {
continue;
}
if ($cfgitem['level'] > $gamelevel) {
break;
}
if ($newhit > $funds['gamelevel']['hit']) {
$funds['gamelevel']['hit'] = $newhit;
}
foreach ($funds['gamelevel']['details'] as $key => $fundsitem) {
$funds['gamelevel']['details'][$key][] = $newhit;
}
}
$medalcostfundcfg = $this->getMedalCostFundInfo();
$cursum = $funds['medalcost']['sum'] + $medalcost;
$funds['medalcost']['sum'] = $cursum;
foreach ($medalcostfundcfg as $cfgitem) {
$newhit = $cfgitem['id'];
if ($newhit <= $funds['medalcost']['hit']) {
continue;
}
if ($cfgitem['stamina'] > $cursum) {
break;
}
if ($newhit > $funds['medalcost']['hit']) {
$funds['medalcost']['hit'] = $newhit;
}
foreach ($funds['medalcost']['details'] as $key => $fundsitem) {
$funds['medalcost']['details'][$key][] = $newhit;
}
}
}
}