280 lines
9.4 KiB
PHP
280 lines
9.4 KiB
PHP
<?php
|
|
|
|
require_once('models/Hero.php');
|
|
require_once('models/Gun.php');
|
|
require_once('models/Chip.php');
|
|
require_once('models/Bag.php');
|
|
require_once('models/DynData.php');
|
|
require_once('models/BattleSettlement.php');
|
|
require_once('models/BattleHistory.php');
|
|
require_once('services/BattleDataService.php');
|
|
require_once('services/FormulaService.php');
|
|
require_once('mt/RankSeason.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Hero;
|
|
use models\Gun;
|
|
use models\Bag;
|
|
use models\DynData;
|
|
use models\BattleHistory;
|
|
use models\BattleSettlement;
|
|
|
|
class BattleController extends BaseAuthedController {
|
|
|
|
public function preBattleCheck()
|
|
{
|
|
$this->_rspData(array(
|
|
'pre_battle_payload' => ''
|
|
));
|
|
}
|
|
|
|
/*
|
|
http post
|
|
php://input
|
|
{
|
|
"team_list": [
|
|
[
|
|
"team_id": 1,
|
|
"members": [
|
|
"account_id": ""
|
|
]
|
|
],
|
|
]
|
|
}
|
|
|
|
$channelId = phpcommon\extractChannel($account_id);
|
|
if ($chnanelId == SELFSDK_CHANNEL || $account_id == '') {
|
|
//则是机器人
|
|
}
|
|
*/
|
|
|
|
public function battleReport()
|
|
{
|
|
$userInfo = $this->_getOrmUserInfo();
|
|
if (!$userInfo) {
|
|
$this->_rspErr(1, 'Without this player1');
|
|
return;
|
|
}
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
/*error_log(json_encode(array(
|
|
'a' => 'battleReport',
|
|
'post_data' => $data
|
|
)));*/
|
|
|
|
$teamList = array();
|
|
if ($data) {
|
|
$teamList = $data['team_list'];
|
|
}
|
|
error_log(json_encode($teamList));
|
|
$battleDataService = new services\BattleDataService();
|
|
$battleDataService->teamList = $teamList;
|
|
$battleDataService->updateBattleData();
|
|
SqlHelper::insert(
|
|
$this->_getSelfMysql(),
|
|
't_battle_record',
|
|
array(
|
|
'account_id' => $this->_getAccountId(),
|
|
'request' => json_encode($_REQUEST),
|
|
'createtime' => $this->_getNowTime(),
|
|
'modifytime' => $this->_getNowTime(),
|
|
)
|
|
);
|
|
error_log(json_encode($battleDataService->getReward()));
|
|
$data = array(
|
|
'reward' => $battleDataService->getReward()
|
|
);
|
|
if ( getReqVal('match_mode', 0) == services\BattleDataService::MATCH_MODE_PVP
|
|
&& mt\RankSeason::getCurrentSeason()
|
|
&& myself()->_getV(TN_RANK_STATUS, 0 ) == 0 ){
|
|
$newRank = $userInfo['rank'];
|
|
$newScore = $userInfo['score'];
|
|
$winningPro = $battleDataService->celWinningPro();
|
|
if ($winningPro){
|
|
$newScore = \services\FormulaService::calcBattleAfterRankScore($userInfo,$_REQUEST,$winningPro);
|
|
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
|
|
}
|
|
$scoreInfo = array(
|
|
'old_rank' => $userInfo['rank'],
|
|
'old_score' => $userInfo['score'],
|
|
'new_rank' => $newRank,
|
|
'new_score' => $newScore,
|
|
);
|
|
$data['score_info'] = $scoreInfo;
|
|
}
|
|
$this->_rspData($data);
|
|
}
|
|
|
|
/*
|
|
http post
|
|
php://input
|
|
{
|
|
}
|
|
*/
|
|
|
|
public function reportSettlement()
|
|
{
|
|
$battleUuid = getReqVal('battle_uuid', '');
|
|
$data = file_get_contents('php://input');
|
|
BattleSettlement::add($battleUuid, $data);
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
public function getBattleData()
|
|
{
|
|
$mode = getReqVal('mode', '');
|
|
$members = json_decode(getReqVal('members', ''), true);
|
|
|
|
$data = array(
|
|
'members' => array()
|
|
);
|
|
error_log(json_encode($_REQUEST));
|
|
error_log(json_encode($members));
|
|
foreach ($members as $member) {
|
|
$info = array(
|
|
'account_id' => $member['account_id'],
|
|
'session_id' => $member['session_id'],
|
|
'hero_uniid' => $member['hero_uniid'],
|
|
'weapon_uuid1' => $member['weapon_uuid1'],
|
|
'weapon_uuid2' => $member['weapon_uuid2'],
|
|
'battle_uuid' => $member['battle_uuid'],
|
|
'hero_dto' => '',
|
|
'weapon_dto1' => '',
|
|
'weapon_dto2' => '',
|
|
|
|
'is_valid_battle' => 0,
|
|
'payload' => json_encode($member['cmjoin']),
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
);
|
|
if (!phpcommon\isValidSessionId($member['account_id'], $member['session_id'])) {
|
|
$info['errcode'] = 50;
|
|
$info['errmsg'] = 'invalid session_id';
|
|
} else {
|
|
{
|
|
$heroDb = Hero::findByAccountId($member['account_id'],
|
|
$member['hero_uniid']);
|
|
if ($heroDb) {
|
|
$info['is_valid_battle'] = 1;
|
|
$info['hero_dto'] = Hero::toDto($heroDb);
|
|
} else {
|
|
$info['errcode'] = 51;
|
|
$info['errmsg'] = 'paramater error';
|
|
}
|
|
}
|
|
{
|
|
for ($i = 1; $i <= 2; ++$i) {
|
|
$gunDb = Gun::findByAccountId($member['account_id'],
|
|
$member['weapon_uuid' . $i]);
|
|
if ($gunDb) {
|
|
$info['weapon_dto' . $i] = Gun::toDto($gunDb);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
array_push($data['members'], $info);
|
|
}
|
|
error_log(json_encode($data));
|
|
myself()->_rspData($data);
|
|
}
|
|
|
|
public function getBattleDataNew()
|
|
{
|
|
error_log(json_encode($_REQUEST));
|
|
$members = json_decode(getReqVal('members', ''), true);
|
|
$data = array(
|
|
'members' => array()
|
|
);
|
|
$currSeason = mt\RankSeason::getCurrentSeason();
|
|
foreach ($members as $member) {
|
|
$info = array(
|
|
'account_id' => $member['account_id'],
|
|
'session_id' => $member['session_id'],
|
|
'hero_uniid' => $member['hero_uniid'],
|
|
'weapon_uuid1' => $member['weapon_uuid1'],
|
|
'weapon_uuid2' => $member['weapon_uuid2'],
|
|
'battle_uuid' => $member['battle_uuid'],
|
|
'hero_dto' => '',
|
|
'weapon_dto1' => '',
|
|
'weapon_dto2' => '',
|
|
|
|
'is_valid_battle' => 0,
|
|
//'payload' => json_encode($member['cmjoin']),
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
);
|
|
if (!phpcommon\isValidSessionId($member['account_id'], $member['session_id'])) {
|
|
$info['errcode'] = 50;
|
|
$info['errmsg'] = 'invalid session_id';
|
|
}else{
|
|
{
|
|
$heroDb = Hero::findByAccountId($member['account_id'],
|
|
$member['hero_uniid']);
|
|
if ($heroDb) {
|
|
$info['is_valid_battle'] = 1;
|
|
$info['hero_dto'] = Hero::toDto($heroDb);
|
|
} else {
|
|
$info['errcode'] = 51;
|
|
$info['errmsg'] = 'paramater error';
|
|
}
|
|
}
|
|
{
|
|
for ($i = 1; $i <= 2; ++$i) {
|
|
if (isset($member['weapon_uuid' . $i])) {
|
|
$gunDb = Gun::findByAccountId($member['account_id'],
|
|
$member['weapon_uuid' . $i]);
|
|
if ($gunDb) {
|
|
$info['weapon_dto' . $i] = Gun::toDto($gunDb);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
{
|
|
$itemDb = Bag::findEx($member['account_id'], V_ITEM_REVIVE_COIN);
|
|
$info['revive_coin'] = $itemDb && $itemDb['item_num'] > 0 ? $itemDb['item_num'] : 0;
|
|
}
|
|
{
|
|
$info['match_mode'] = 0;
|
|
if ($currSeason && DynData::getVEx($member['account_id'], TN_RANK_STATUS, 0) == 0){
|
|
$info['match_mode'] = 1;
|
|
}
|
|
}
|
|
}
|
|
array_push($data['members'], $info);
|
|
|
|
}
|
|
// $attr = Hero::getChipAttr($info['hero_dto']['chip_ids']);
|
|
myself()->_rspData($data);
|
|
}
|
|
|
|
public function getBattleHistory(){
|
|
$mode = getReqVal('mode', 0);
|
|
$historyList = BattleHistory::orderBy(BattleHistory::getMyBattleHistoryByMode($mode),'desc');
|
|
$data = array();
|
|
foreach ($historyList as $k=>$history){
|
|
if ($k < 20){
|
|
array_push($data,BattleHistory::toDto($history));
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'data' => $data
|
|
));
|
|
}
|
|
|
|
public function decReviveCoin()
|
|
{
|
|
$num = getReqVal('num', 1);
|
|
$itemDb = Bag::find(V_ITEM_REVIVE_COIN);
|
|
if (!$itemDb || $itemDb['item_num'] < $num) {
|
|
myself()->_rspErr(1, 'not enought item');
|
|
return;
|
|
}
|
|
Bag::decItem(V_ITEM_REVIVE_COIN, $num);
|
|
$itemDb = Bag::find(V_ITEM_REVIVE_COIN);
|
|
$reviveCoin = $itemDb && $itemDb['item_num'] > 0 ? $itemDb['item_num'] : 0;
|
|
myself()->_rspData(array(
|
|
'revive_coin' => $reviveCoin
|
|
));
|
|
}
|
|
|
|
}
|