完成战斗逻辑

This commit is contained in:
aozhiwei 2021-12-22 16:58:58 +08:00
parent 42d333bd9a
commit 86ad0a3a0d
5 changed files with 109 additions and 25 deletions

View File

@ -31,6 +31,8 @@ class Battle(object):
['map_id', 0, '地图id'],
['map_tpl_name', '', '地图模板名'],
['room_uuid', 0, '房间唯一id'],
['room_mode', 0, '房间模式 0:吃鸡模式 1:匹配赛模式'],
['hero_id', 0, '英雄id'],
['map_name', '', '地图名'],
['team_mode', 0, '队伍模式 0:单人 1组队'],
['game_time', 0, '游戏时间'],
@ -56,7 +58,7 @@ class Battle(object):
['rank_score', 0, '排位积分'],
#['pass_score', 0, '通行证积分'],
['items', 0, '道具|分割'],
['items', 0, '道具id:道具数量|'],
],
'response': [
_common.RspHead(),

View File

@ -6,6 +6,13 @@ use phpcommon\SqlHelper;
class BattleController extends BaseAuthedController {
public function preBattleCheck()
{
$this->_rspData(array(
'pre_battle_payload' => ''
));
}
public function battleReport()
{
$userInfo = $this->_getOrmUserInfo();

View File

@ -32,6 +32,9 @@ class GMController extends BaseAuthedController {
'.additem' => function () use($params) {
$this->addItem($params);
},
'.addtili' => function () use($params) {
$this->addTili($params);
},
'.getsystime' => function () use($params) {
$this->getSysTime($params);
},
@ -53,6 +56,7 @@ class GMController extends BaseAuthedController {
$this->_rspData(array(
'text' => <<<END
.additem 道具id 道具数量 //添加道具
.addtili 英雄id 体力值 //添加英雄体力
.getsystime //获取服务器时间
.setsystime //设置服务器时间,示例:.setsystime 2021-12-08 00:00:00
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)
{
$sysTime = phpcommon\timestamp_to_datetime(phpcommon\getNowTime());

View File

@ -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
);
}
}

View File

@ -6,14 +6,17 @@ require_once('mt/Item.php');
require_once('mt/Equip.php');
require_once('mt/Season.php');
require_once('mt/Rank.php');
require_once('mt/Param.php');
require_once('models/Season.php');
require_once('models/Battle.php');
require_once('models/Bag.php');
use mt;
use phpcommon\SqlHelper;
use models\Season;
use models\Battle;
use models\Bag;
class BattleDataService extends BaseService {
@ -21,6 +24,9 @@ class BattleDataService extends BaseService {
public function updateBattleData()
{
if (!$this->decCost()) {
return;
}
$this->currSeasonMeta = mt\Season::getCurrentSeason();
if (!$this->currSeasonMeta) {
return;
@ -99,6 +105,7 @@ class BattleDataService extends BaseService {
'battle_data' => json_encode($seasonBattleData),
)
);
$this->addItems();
}
private function apply(&$battleData)
@ -255,6 +262,7 @@ class BattleDataService extends BaseService {
private function updateScore()
{
if (getReqVal('room_mode', 0) == 0) {
$userInfo = myself()->_getOrmUserInfo();
$rankScore = getReqVal('rank_score', 0);
if ($rankScore > 0) {
@ -282,5 +290,40 @@ class BattleDataService extends BaseService {
}
}
}
}
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);
}
}
}
}
}