$redis_conf['host'], 'port' => $redis_conf['port'], 'passwd' => $redis_conf['passwd'] )); return $r; } 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' => DBNAME_PREFIX . $mysql_conf['instance_id'] )); return $conn; } protected function getGameLevelInfo($level) { $conf = require('../res/gamelevel@gamelevel.php'); return array_key_exists($level, $conf) ? $conf[$level] : null; } protected function getPlayerLevelInfo($level) { $conf = require('../res/playerlevel@playerlevel.php'); 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']; //登录校验 $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; } $solorow = $conn->execQueryOne( 'SELECT * FROM solo WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); $medals = 0; $privilege = new classes\Privilege(); $medalsgrowlimit = intval(metatable\getParameterById(MEDAL_LIMIT)['param_value']) + $privilege->getMedalLimitPlus($account_id); $nowtime = time(); $lastredeem = $nowtime; $level = 1; $exp = 0; $gamelevel = array( 'curlevel' => 1, '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, 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 ) ); } else { $medalsecs = intval(metatable\getParameterById(MEDAL_SECONDS)['param_value']); $lastredeem = $solorow['lastredeem']; $medals = $solorow['medals']; $lastoffline = $solorow['lastoffline']; $updatedb = false; $offlinehours = $solorow['offline']; if ($solorow['medals'] < $medalsgrowlimit && $medalsecs + $solorow['lastredeem'] <= $nowtime) { //结算体力自然增长 $addmedals = ($nowtime - $solorow['lastredeem']) / $medalsecs; $lastredeem = $solorow['lastredeem'] + $addmedals * $medalsecs; $medals = $addmedals + $solorow['medals']; $updatedb = true; } else { $medals = $solorow['medals']; $lastredeem = $solorow['lastredeem']; } if ($lastoffline + 3600 <= $nowtime) { $offlinehours += ($nowtime - $lastoffline) / 3600; $offlinelimit = intval(metatable\getParameterById(OFFLINE_LIMIT)['param_value']) + $privilege->getOfflineLimitPlus($account_id); if ($offlinehours > $offlinelimit) { $offlinehours = $offlinelimit; } $updatedb = true; } else if ($lastoffline + 1800 >= $nowtime) { $updatedb = true; } if ($updatedb) { $ret = $conn->execScript( 'UPDATE solo SET medals=:medals, lastredeem=:lastredeem, lastoffline=:lastoffline, offline=:offline, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':medals' => $medals, ':lastredeem' => $lastredeem, ':lastoffline' => $nowtime, ':offline' => $offlinehours, ':modify_time' => $nowtime ) ); } $level = $solorow['level']; $exp = $solorow['exp']; 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; $lvinfo = $this->getPlayerLevelInfo($level); if ($lvinfo) { $upexp = $lvinfo['experience']; } echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'level' => $level, 'exp' => $exp, 'upexp' => $upexp, 'medals' => $medals, 'medal_limit' => $medalsgrowlimit, 'lastredeem' => $lastredeem, 'offlinehours' => $offlinehours, 'gamelevel' => $gamelevel, 'funds' => $funds, )); } public function offlineAward() { $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; } $solorow = $conn->execQueryOne( 'SELECT offline, gamelevel FROM solo WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); if (!$solorow || $solorow['offline'] < 1 || is_null($solorow['gamelevel']) || $solorow['gamelevel'] == '') { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 2'); return; } $gamelevelinfo = json_decode($solorow['gamelevel'], true); if ($gamelevelinfo['curlevel'] < 1) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 3'); return; } $levelcfg = $this->getGameLevelInfo($gamelevelinfo['curlevel']); if (!$levelcfg) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 4'); return; } $offlinehours = $solorow['offline']; $fixawards = explode('|', $levelcfg['offlineitem_id']); $item_list = array(); $all_item_list = array(); foreach ($fixawards as $fixitemstr) { $itemstrs = explode(':', $fixitemstr); if (count($itemstrs) < 2) { continue; } $item_list[] = array( 'item_id' => $itemstrs[0], 'item_num' => $itemstrs[1] * $offlinehours, 'time' => 0 ); } $droplist = explode('|', $levelcfg['offlineitem_id2']); $dropawards = array(); for ($i = 0; $i < $offlinehours; $i++) { foreach ($droplist as $dropid) { $dropitems = array(); $dropitems = metatable\getDropAllListById($dropid, $dropitems); foreach ($dropitems as $dropitem) { $itemid = $dropitem['item_id']; $itemnum = $dropitem['item_num']; if ($itemid == 0 || $itemnum == 0) { continue; } $dropawards[$itemid] += $itemnum; } } } foreach ($dropawards as $itemid => $itemnum) { $item_list[] = array( 'item_id' => $itemid, 'item_num' => $itemnum, 'time' => 0 ); } $addreward = new classes\AddReward(); 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); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'offlinehours' => $offlinehours, 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'adfree' => $adfree, 'medals' => $medals, 'item_list' => $item_list, 'all_item_list' => $all_item_list, )); } // consume medals public function consume() { $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; } $key = 'game2004api-cost-medals:' . $account_id; $r = $this->getRedis($key); if (!$r) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 1'); return; } $level = $_REQUEST['level']; $reqlevelcfg = $this->getGameLevelInfo($level); if (!$reqlevelcfg) { phpcommon\sendError(ERR_USER_BASE + 1, '体力不足'); return; } $solorow = $conn->execQueryOne( 'SELECT medals FROM solo WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); $medalcost = $reqlevelcfg['medal_cost']; if ($medalcost > $solorow['medals']) { phpcommon\sendError(ERR_USER_BASE + 1, '体力不足 1'); return; } $ret = $conn->execScript( 'UPDATE solo SET medals=:medals, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':medals' => $solorow['medals'] - $medalcost, ':modify_time' => time() ) ); if (!$ret) { phpcommon\sendError(ERR_RETRY + 1, '系统繁忙'); return; } $infoobj = array( 'level' => $level, ); $infostr = json_encode($infoobj); $r->set($key, $infostr); $r->pexpire($key, 1000 * 86400); error_log($key . ':' . $infostr); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'level' => $level, 'medals' => $solorow['medals'] - $medalcost, )); } // 战斗结算 public function settle() { $this->levelaward(true); } public function vidsettle() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $key = 'game2004api-vidsettle:' . $account_id; $r = $this->getRedis($key); if (!$r) { phpcommon\sendError(ERR_USER_BASE + 1, '奖励不存在'); return; } $infostr = $r->get($key); if (empty($infostr)) { phpcommon\sendError(ERR_USER_BASE + 1, '奖励不存在 1'); return; } $infoobj = json_decode($infostr, true); if ($infoobj['level'] != $_REQUEST['level'] || $infoobj['wave'] != $_REQUEST['wave']) { phpcommon\sendError(ERR_USER_BASE + 1, '奖励不存在 2'); return; } $r->del($key); $item_list = $infoobj['item_list']; $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); echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'level' => $_REQUEST['level'], 'wave' => $_REQUEST['wave'], 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'adfree' => $adfree, 'medals' => $medals, 'item_list' => $item_list, 'all_item_list' => $all_item_list, )); } // 领取关卡宝箱 public function complete() { $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; } $solorow = $conn->execQueryOne( 'SELECT * FROM solo WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); if (!$solorow) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 1'); return; } $gamelevel = array( 'curlevel' => 1, 'curwave' => 0, 'levelinfo' => array(), ); if (!is_null($solorow['gamelevel']) && !empty($solorow['gamelevel'])) { $gamelevel = json_decode($solorow['gamelevel'], true); } $level = $_REQUEST['level']; $wave = $_REQUEST['wave']; if (!array_key_exists($level, $gamelevel['levelinfo'])) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个奖励'); return; } $foundwave = false; $newlist = array(); foreach ($gamelevel['levelinfo'][$level] as $waveitem) { if ($wave == $waveitem) { $foundwave = true; } else { $newlist[] = $waveitem; } } if (!$foundwave) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个奖励 1'); return; } $levelcfg = $this->getGameLevelInfo($level); if (!$levelcfg) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个奖励 2'); return; } if (count($newlist) == 0) { unset($gamelevel['levelinfo'][$level]); } else { $gamelevel['levelinfo'][$level] = $newlist; } $wavearr = explode('|', $levelcfg['completionwave']); $foundwave = false; $item_list = array(); foreach ($wavearr as $key => $waveitem) { if ($wave != $waveitem) { continue; } $waveawardarr = explode('|', $levelcfg['completionreward']); if (!array_key_exists($key, $waveawardarr)) { break; } $awardarr = explode(';', $waveawardarr[$key]); foreach ($awardarr as $awarditem) { $strs = explode(':', $awarditem); if (count($strs) < 2) { continue; } $item_list[] = array( 'item_id' => $strs[0], 'item_num' => $strs[1], "time" => 0, ); } $foundwave = true; } if (!$foundwave) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个奖励 3'); return; } $ret = $conn->execScript( 'UPDATE solo SET gamelevel=:gamelevel, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':gamelevel' => json_encode($gamelevel), ':modify_time' => time() ) ); if (!$ret) { phpcommon\sendError(ERR_RETRY + 1, '系统繁忙'); return; } $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' => '', 'level' => $level, 'wave' => $wave, '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); } // 扫荡结算 public function sweep() { $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) { $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; } $solorow = $conn->execQueryOne( 'SELECT * FROM solo WHERE accountid=:accountid;', array( ':accountid' => $account_id ) ); if (!$solorow) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 1'); return; } $gamelevel = array( 'curlevel' => 1, 'curwave' => 0, 'levelinfo' => array(), ); if (!is_null($solorow['gamelevel']) && !empty($solorow['gamelevel'])) { $gamelevel = json_decode($solorow['gamelevel'], true); } $curlevelcfg = $this->getGameLevelInfo($gamelevel['curlevel']); if (!$curlevelcfg) { phpcommon\sendError(ERR_USER_BASE + 1, '关卡未通过'); return; } $curmonsterwaves = explode('|', $curlevelcfg['monsterlist_id']); $curfinished = $gamelevel['curwave'] > 0 && $gamelevel['curwave'] == count($curmonsterwaves); $level = $_REQUEST['level']; if ($isbattle) { if ((!$curfinished && $level > $gamelevel['curlevel']) || ($curfinished && $level > $gamelevel['curlevel'] + 1) ) { phpcommon\sendError(ERR_USER_BASE + 1, '关卡未通过 1'); return; } } else { if ((!$curfinished && $level >= $gamelevel['curlevel']) || ($curfinished && $level > $gamelevel['curlevel']) ) { phpcommon\sendError(ERR_USER_BASE + 1, '关卡未通过 2'); return; } } $reqlevelcfg = $this->getGameLevelInfo($level); if (!$reqlevelcfg) { phpcommon\sendError(ERR_USER_BASE + 1, '关卡未通过 3'); return; } $medalcost = $reqlevelcfg['medal_cost']; if ($isbattle) { $key = 'game2004api-cost-medals:' . $account_id; $r = $this->getRedis($key); if (!$r) { phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 1'); return; } $infostr = $r->get($key); if (empty($infostr)) { phpcommon\sendError(ERR_USER_BASE + 1, '奖励不存在 1'); return; } $infoobj = json_decode($infostr, true); if ($infoobj['level'] != $level) { phpcommon\sendError(ERR_USER_BASE + 1, '奖励不存在 2'); return; } $r->del($key); } else if ($medalcost > $solorow['medals']) { phpcommon\sendError(ERR_USER_BASE + 2, '体力不足'); return; } $reqmonsterwaves = explode('|', $reqlevelcfg['monsterlist_id']); $reqfinished = $isbattle ? ($_REQUEST['wave'] > 0 && $_REQUEST['wave'] == count($reqmonsterwaves)) : true; $item_list = array(); // fixed award $fixedawards = explode('|', $reqlevelcfg['fixedreward']); $addexp = $medalcost * 10; //1点体力=10点经验 foreach ($fixedawards as $fixitem) { $itemstrs = explode(':', $fixitem); if (count($itemstrs) < 2) { continue; } if ($itemstrs[0] == 10013) { $addexp += $itemstrs[1]; continue; } $item_list[] = array( "item_id" => $itemstrs[0], "item_num" => $itemstrs[1], "time" => 0, ); } // level finished award if ($reqfinished) { $finishedawards = explode('|', $reqlevelcfg['winreward']); foreach ($finishedawards as $finishitem) { $itemstrs = explode(':', $finishitem); if (count($itemstrs) < 2) { continue; } if ($itemstrs[0] == 10013) { $addexp += $itemstrs[1]; continue; } $item_list[] = array( "item_id" => $itemstrs[0], "item_num" => $itemstrs[1], "time" => 0, ); } } if ($isbattle) { // level box award $wave = $_REQUEST['wave']; if ($curfinished && $level == $gamelevel['curlevel'] + 1) { $newwaves = array(); $completewaves = explode('|', $reqlevelcfg['completionwave']); foreach ($completewaves as $waveitem) { if ($wave >= $waveitem) { $newwaves[] = $waveitem; } } $gamelevel['levelinfo'][$level] = $newwaves; $gamelevel['curlevel'] = $level; $gamelevel['curwave'] = $wave; } else if (!$curfinished && $level == $gamelevel['curlevel'] && $wave > $gamelevel['curwave']) { if ($gamelevel['curwave'] == 0) { $gamelevel['levelinfo'][$level] = array(); } $completewaves = explode('|', $reqlevelcfg['completionwave']); foreach ($completewaves as $waveitem) { if ($wave >= $waveitem && $waveitem > $gamelevel['curwave']) { $gamelevel['levelinfo'][$level][] = $waveitem; } } $gamelevel['curwave'] = $wave; } } // cost medals, add exp $curexp = $solorow['exp'] + $addexp; $curlv = $solorow['level']; $curlvcfg = $this->getPlayerLevelInfo($curlv); $uplv_item_list = array(); while ($curlvcfg && $curlvcfg['experience'] > 0 && $curexp >= $curlvcfg['experience']) { $curexp -= $curlvcfg['experience']; $curlv++; $curlvcfg = $this->getPlayerLevelInfo($curlv); if ($curlvcfg) { $uplvawards = explode('|', $curlvcfg['level_reward']); foreach ($uplvawards as $uplvitem) { $itemstrs = explode(':', $uplvitem); if (count($itemstrs) < 2) { continue; } $uplv_item_list[] = array( "item_id" => $itemstrs[0], "item_num" => $itemstrs[1], "time" => 0, ); } } } $curmedals = $isbattle ? $solorow['medals'] : ($solorow['medals'] - $medalcost); $lastredeem = $solorow['lastredeem']; $privilege = new classes\Privilege(); $medalsgrowlimit = intval(metatable\getParameterById(MEDAL_LIMIT)['param_value']) + $privilege->getMedalLimitPlus($account_id); if ($solorow['medals'] >= $medalsgrowlimit && $curmedals < $medalsgrowlimit) { $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, funds=:funds, modify_time=:modify_time' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, ':medals' => $curmedals, ':lastredeem' => $lastredeem, ':level' => $curlv, ':exp' => $curexp, ':gamelevel' => json_encode($gamelevel), ':funds' => json_encode($funds), ':modify_time' => time() ) ); if (!$ret) { phpcommon\sendError(ERR_RETRY + 1, '系统繁忙'); return; } $addreward = new classes\AddReward(); $all_item_list = array(); foreach ($item_list as $itemaward) { if ($itemaward['item_id'] == 10013) { //经验值奖励已处理 $all_item_list[] = $itemaward; continue; } $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, )); } } if ($isbattle) { $key = 'game2004api-vidsettle:' . $account_id; $r = $this->getRedis($key); if ($r) { $infoobj = array( 'level' => $level, 'wave' => $_REQUEST['wave'], 'item_list' => $item_list, ); $infostr = json_encode($infoobj); $r->set($key, $infostr); $r->pexpire($key, 1000 * 86400); error_log($key . ':' . $infostr); } } $uplv_all_item_list = array(); foreach ($uplv_item_list as $itemaward) { $items = $addreward->addReward($itemaward['item_id'], $itemaward['item_num'], $account_id, 0, 0); foreach ($items as $i) { array_push($uplv_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' => '', 'level' => $level, 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'adfree' => $adfree, 'medals' => $medals, 'item_list' => $item_list, 'all_item_list' => $all_item_list, 'playerlvup' => array( 'item_list' => $uplv_item_list, 'all_item_list' => $uplv_all_item_list, ) ); if ($isbattle) { $response['wave'] = $_REQUEST['wave']; } 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; } } } }