完成战斗逻辑
This commit is contained in:
parent
42d333bd9a
commit
86ad0a3a0d
@ -31,6 +31,8 @@ class Battle(object):
|
|||||||
['map_id', 0, '地图id'],
|
['map_id', 0, '地图id'],
|
||||||
['map_tpl_name', '', '地图模板名'],
|
['map_tpl_name', '', '地图模板名'],
|
||||||
['room_uuid', 0, '房间唯一id'],
|
['room_uuid', 0, '房间唯一id'],
|
||||||
|
['room_mode', 0, '房间模式 0:吃鸡模式 1:匹配赛模式'],
|
||||||
|
['hero_id', 0, '英雄id'],
|
||||||
['map_name', '', '地图名'],
|
['map_name', '', '地图名'],
|
||||||
['team_mode', 0, '队伍模式 0:单人 1:组队'],
|
['team_mode', 0, '队伍模式 0:单人 1:组队'],
|
||||||
['game_time', 0, '游戏时间'],
|
['game_time', 0, '游戏时间'],
|
||||||
@ -56,7 +58,7 @@ class Battle(object):
|
|||||||
|
|
||||||
['rank_score', 0, '排位积分'],
|
['rank_score', 0, '排位积分'],
|
||||||
#['pass_score', 0, '通行证积分'],
|
#['pass_score', 0, '通行证积分'],
|
||||||
['items', 0, '道具|分割'],
|
['items', 0, '道具id:道具数量|'],
|
||||||
],
|
],
|
||||||
'response': [
|
'response': [
|
||||||
_common.RspHead(),
|
_common.RspHead(),
|
||||||
|
@ -6,6 +6,13 @@ use phpcommon\SqlHelper;
|
|||||||
|
|
||||||
class BattleController extends BaseAuthedController {
|
class BattleController extends BaseAuthedController {
|
||||||
|
|
||||||
|
public function preBattleCheck()
|
||||||
|
{
|
||||||
|
$this->_rspData(array(
|
||||||
|
'pre_battle_payload' => ''
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public function battleReport()
|
public function battleReport()
|
||||||
{
|
{
|
||||||
$userInfo = $this->_getOrmUserInfo();
|
$userInfo = $this->_getOrmUserInfo();
|
||||||
|
@ -32,6 +32,9 @@ class GMController extends BaseAuthedController {
|
|||||||
'.additem' => function () use($params) {
|
'.additem' => function () use($params) {
|
||||||
$this->addItem($params);
|
$this->addItem($params);
|
||||||
},
|
},
|
||||||
|
'.addtili' => function () use($params) {
|
||||||
|
$this->addTili($params);
|
||||||
|
},
|
||||||
'.getsystime' => function () use($params) {
|
'.getsystime' => function () use($params) {
|
||||||
$this->getSysTime($params);
|
$this->getSysTime($params);
|
||||||
},
|
},
|
||||||
@ -53,6 +56,7 @@ class GMController extends BaseAuthedController {
|
|||||||
$this->_rspData(array(
|
$this->_rspData(array(
|
||||||
'text' => <<<END
|
'text' => <<<END
|
||||||
.additem 道具id 道具数量 //添加道具
|
.additem 道具id 道具数量 //添加道具
|
||||||
|
.addtili 英雄id 体力值 //添加英雄体力
|
||||||
.getsystime //获取服务器时间
|
.getsystime //获取服务器时间
|
||||||
.setsystime //设置服务器时间,示例:.setsystime 2021-12-08 00:00:00
|
.setsystime //设置服务器时间,示例:.setsystime 2021-12-08 00:00:00
|
||||||
END
|
END
|
||||||
@ -78,6 +82,21 @@ END
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addTili($params)
|
||||||
|
{
|
||||||
|
$heroId = getXVal($params, 0, 0);
|
||||||
|
$tili = getXVal($params, 1, 0);
|
||||||
|
Hero::update($heroId, array(
|
||||||
|
'hero_tili' => "hero_tili + ${tili}"
|
||||||
|
));
|
||||||
|
$propertyChgService->addHeroChg();
|
||||||
|
$this->_rspData(array(
|
||||||
|
'text' => '添加道具成功',
|
||||||
|
'award' => $awardService->toDto(),
|
||||||
|
'property_chg' => $propertyChgService->toDto(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
private function getSysTime($params)
|
private function getSysTime($params)
|
||||||
{
|
{
|
||||||
$sysTime = phpcommon\timestamp_to_datetime(phpcommon\getNowTime());
|
$sysTime = phpcommon\timestamp_to_datetime(phpcommon\getNowTime());
|
||||||
|
@ -102,4 +102,17 @@ class Hero extends BaseModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function update($heroId, $fieldsKv)
|
||||||
|
{
|
||||||
|
SqlHelper::upsert
|
||||||
|
(myself()->_getSelfMysql(),
|
||||||
|
't_hero',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'hero_id' => $heroId,
|
||||||
|
),
|
||||||
|
$fieldsKv
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,17 @@ require_once('mt/Item.php');
|
|||||||
require_once('mt/Equip.php');
|
require_once('mt/Equip.php');
|
||||||
require_once('mt/Season.php');
|
require_once('mt/Season.php');
|
||||||
require_once('mt/Rank.php');
|
require_once('mt/Rank.php');
|
||||||
|
require_once('mt/Param.php');
|
||||||
|
|
||||||
require_once('models/Season.php');
|
require_once('models/Season.php');
|
||||||
require_once('models/Battle.php');
|
require_once('models/Battle.php');
|
||||||
|
require_once('models/Bag.php');
|
||||||
|
|
||||||
use mt;
|
use mt;
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
use models\Season;
|
use models\Season;
|
||||||
use models\Battle;
|
use models\Battle;
|
||||||
|
use models\Bag;
|
||||||
|
|
||||||
class BattleDataService extends BaseService {
|
class BattleDataService extends BaseService {
|
||||||
|
|
||||||
@ -21,6 +24,9 @@ class BattleDataService extends BaseService {
|
|||||||
|
|
||||||
public function updateBattleData()
|
public function updateBattleData()
|
||||||
{
|
{
|
||||||
|
if (!$this->decCost()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->currSeasonMeta = mt\Season::getCurrentSeason();
|
$this->currSeasonMeta = mt\Season::getCurrentSeason();
|
||||||
if (!$this->currSeasonMeta) {
|
if (!$this->currSeasonMeta) {
|
||||||
return;
|
return;
|
||||||
@ -99,6 +105,7 @@ class BattleDataService extends BaseService {
|
|||||||
'battle_data' => json_encode($seasonBattleData),
|
'battle_data' => json_encode($seasonBattleData),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$this->addItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function apply(&$battleData)
|
private function apply(&$battleData)
|
||||||
@ -255,30 +262,66 @@ class BattleDataService extends BaseService {
|
|||||||
|
|
||||||
private function updateScore()
|
private function updateScore()
|
||||||
{
|
{
|
||||||
$userInfo = myself()->_getOrmUserInfo();
|
if (getReqVal('room_mode', 0) == 0) {
|
||||||
$rankScore = getReqVal('rank_score', 0);
|
$userInfo = myself()->_getOrmUserInfo();
|
||||||
if ($rankScore > 0) {
|
$rankScore = getReqVal('rank_score', 0);
|
||||||
$newRank = $userInfo['rank'];
|
if ($rankScore > 0) {
|
||||||
$newScore = $userInfo['score'];
|
$newRank = $userInfo['rank'];
|
||||||
mt\Rank::calcNewRankAndScore($userInfo['rank'], $userInfo['score'], $newRank, $newScore, $rankScore);
|
$newScore = $userInfo['score'];
|
||||||
if ($newRank >= $userInfo['rank'] && $newScore != $userInfo['score']) {
|
mt\Rank::calcNewRankAndScore($userInfo['rank'], $userInfo['score'], $newRank, $newScore, $rankScore);
|
||||||
myself()->_updateUserInfo(array(
|
if ($newRank >= $userInfo['rank'] && $newScore != $userInfo['score']) {
|
||||||
'rank' => $newRank,
|
myself()->_updateUserInfo(array(
|
||||||
'score' => $newScore,
|
'rank' => $newRank,
|
||||||
'history_best_rank' => max($userInfo['rank'], $newRank),
|
'score' => $newScore,
|
||||||
'score_modifytime' => myself()->_getNowTime(),
|
'history_best_rank' => max($userInfo['rank'], $newRank),
|
||||||
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
'score_modifytime' => myself()->_getNowTime(),
|
||||||
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
||||||
));
|
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
||||||
Season::update($this->currSeasonMeta['id'], array(
|
));
|
||||||
'rank' => $newRank,
|
Season::update($this->currSeasonMeta['id'], array(
|
||||||
'score' => $newScore,
|
'rank' => $newRank,
|
||||||
'history_best_rank' => max($userInfo['rank'], $newRank),
|
'score' => $newScore,
|
||||||
'score_modifytime' => myself()->_getNowTime(),
|
'history_best_rank' => max($userInfo['rank'], $newRank),
|
||||||
'score_modifytime' => myself()->_getNowTime(),
|
'score_modifytime' => myself()->_getNowTime(),
|
||||||
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
'score_modifytime' => myself()->_getNowTime(),
|
||||||
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
||||||
));
|
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function decCost()
|
||||||
|
{
|
||||||
|
$heroDb = Hero::find(getReqVal('hero_id', 0));
|
||||||
|
if (!$heroDb) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$costTili = mt\Parameter::getVal('cost_fatigue', 0);
|
||||||
|
if ($heroDB['tili'] < $costTili) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Hero::update($heroDb['hero_id'], array(
|
||||||
|
'hero_tili' => function () use($costTili) {
|
||||||
|
return "GREATEST(0, hero_tili - ${costTili})";
|
||||||
|
}
|
||||||
|
));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addItems()
|
||||||
|
{
|
||||||
|
$tmpStrs1 = explode('|', getReqVal('items', ''));
|
||||||
|
foreach ($tmpStrs1 as $tmpStr) {
|
||||||
|
$tmpStrs2 = explode(':', $tmpStr);
|
||||||
|
if (count($tmpStrs2) >= 2) {
|
||||||
|
$itemId = $tmpStrs2[0];
|
||||||
|
$itemNum = $tmpStrs2[1];
|
||||||
|
$itemMeta = mt\Item::get($itemId);
|
||||||
|
if ($itemMeta) {
|
||||||
|
Bag::addItem($itemId, $itemNum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user