1
This commit is contained in:
parent
9432aa8235
commit
a37bcd8ac6
@ -2,6 +2,7 @@
|
||||
|
||||
require_once('mt/Parameter.php');
|
||||
require_once('mt/Item.php');
|
||||
require_once('mt/Drop.php');
|
||||
|
||||
require_once('models/Bag.php');
|
||||
|
||||
@ -54,22 +55,24 @@ class BagController extends BaseAuthedController {
|
||||
$this->_rspErr(2, '配置表错误');
|
||||
return;
|
||||
}
|
||||
if ($itemMeta['type'] != mt\Item::FUNC_TYPE) {
|
||||
$this->_rspErr(3, '该道具为不可使用道具');
|
||||
return;
|
||||
}
|
||||
switch ($itemMeta['sub_type']) {
|
||||
case mt\Item::FUNC_RENAME_CARD_SUBTYPE:
|
||||
{
|
||||
$this->renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if ($itemMeta['type'] == mt\Item::FUNC_TYPE) {
|
||||
switch ($itemMeta['sub_type']) {
|
||||
case mt\Item::FUNC_RENAME_CARD_SUBTYPE:
|
||||
{
|
||||
$this->renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
$this->_rspErr(4, '该道具功能暂未实现');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if ($itemMeta['type'] == mt\Item::GIFT_PACKAGE_TYPE) {
|
||||
$this->openGiftPackage($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3);
|
||||
} else {
|
||||
$this->_rspErr(4, '该道具功能暂未实现');
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,4 +177,36 @@ class BagController extends BaseAuthedController {
|
||||
));
|
||||
}
|
||||
|
||||
private function openGiftPackage($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3)
|
||||
{
|
||||
$dropMeta = mt\Drop::get($itemMeta['drop']);
|
||||
if (!$dropMeta) {
|
||||
$this->_rspErr(1, '配置表错误');
|
||||
return;
|
||||
}
|
||||
$costItems = mt\Item::getUseCostItems($itemMeta);
|
||||
error_log(json_encode($costItems));
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||
return;
|
||||
}
|
||||
$this->_decItems($costItems);
|
||||
$this->_decItems(array(
|
||||
array(
|
||||
'item_id' => $itemMeta['id'],
|
||||
'item_num' => 1
|
||||
)
|
||||
));
|
||||
$this->_scatterDrop('gift_package:' . $itemMeta['id'],
|
||||
$dropMeta,
|
||||
$this->awardService,
|
||||
$this->propertyChgService);
|
||||
$this->propertyChgService->addBagChg();
|
||||
$this->_rspData(array(
|
||||
'award' => $this->awardService->toDto(),
|
||||
'property_chg' => $this->propertyChgService->toDto(),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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());
|
||||
|
@ -43,7 +43,7 @@ class Battle extends BaseModel {
|
||||
|
||||
public static function update($fieldsKv)
|
||||
{
|
||||
SqlHelper::upsert
|
||||
SqlHelper::update
|
||||
(myself()->_getSelfMysql(),
|
||||
't_battle',
|
||||
array(
|
||||
|
@ -28,6 +28,7 @@ class Hero extends BaseModel {
|
||||
return array(
|
||||
'hero_id' => $row['hero_id'],
|
||||
'hero_lv' => $row['hero_lv'],
|
||||
'hero_tili' => $row['hero_tili'],
|
||||
'skin_id' => $row['skin_id'],
|
||||
'skill_lv1' => $row['skill_lv1'],
|
||||
'skill_lv2' => $row['skill_lv2'],
|
||||
@ -102,4 +103,17 @@ class Hero extends BaseModel {
|
||||
);
|
||||
}
|
||||
|
||||
public static function update($heroId, $fieldsKv)
|
||||
{
|
||||
SqlHelper::update
|
||||
(myself()->_getSelfMysql(),
|
||||
't_hero',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'hero_id' => $heroId,
|
||||
),
|
||||
$fieldsKv
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -169,6 +169,20 @@ class Item {
|
||||
return $costItems;
|
||||
}
|
||||
|
||||
public static function getUseCostItems($itemMeta)
|
||||
{
|
||||
$costItems = array();
|
||||
foreach (splitStr2($itemMeta['use_cost']) as $arr) {
|
||||
if (count($arr) >= 2) {
|
||||
array_push($costItems, array(
|
||||
'item_id' => $arr[0],
|
||||
'item_num' => $arr[1]
|
||||
));
|
||||
}
|
||||
}
|
||||
return $costItems;
|
||||
}
|
||||
|
||||
public static function isBagItem($type, $subType)
|
||||
{
|
||||
return in_array($type, array(
|
||||
|
@ -6,14 +6,19 @@ require_once('mt/Item.php');
|
||||
require_once('mt/Equip.php');
|
||||
require_once('mt/Season.php');
|
||||
require_once('mt/Rank.php');
|
||||
require_once('mt/Parameter.php');
|
||||
|
||||
require_once('models/Season.php');
|
||||
require_once('models/Battle.php');
|
||||
require_once('models/Bag.php');
|
||||
require_once('models/Hero.php');
|
||||
|
||||
use mt;
|
||||
use phpcommon\SqlHelper;
|
||||
use models\Season;
|
||||
use models\Battle;
|
||||
use models\Bag;
|
||||
use models\Hero;
|
||||
|
||||
class BattleDataService extends BaseService {
|
||||
|
||||
@ -21,10 +26,17 @@ class BattleDataService extends BaseService {
|
||||
|
||||
public function updateBattleData()
|
||||
{
|
||||
error_log(json_encode($_REQUEST));
|
||||
error_log('updateBattleData1');
|
||||
if (!$this->decCost()) {
|
||||
return;
|
||||
}
|
||||
error_log('updateBattleData2');
|
||||
$this->currSeasonMeta = mt\Season::getCurrentSeason();
|
||||
if (!$this->currSeasonMeta) {
|
||||
return;
|
||||
}
|
||||
error_log('updateBattleData3');
|
||||
$this->seasonDb = Season::find($this->currSeasonMeta['id']);
|
||||
if (!$this->seasonDb) {
|
||||
Season::add($this->currSeasonMeta['id']);
|
||||
@ -33,6 +45,7 @@ class BattleDataService extends BaseService {
|
||||
if (!$this->seasonDb) {
|
||||
return;
|
||||
}
|
||||
error_log('updateBattleData4');
|
||||
$this->updateScore();
|
||||
$hisBattleData = Battle::getMyBattleData();
|
||||
if (!isset($hisBattleData)) {
|
||||
@ -99,6 +112,7 @@ class BattleDataService extends BaseService {
|
||||
'battle_data' => json_encode($seasonBattleData),
|
||||
)
|
||||
);
|
||||
$this->addItems();
|
||||
}
|
||||
|
||||
private function apply(&$battleData)
|
||||
@ -255,30 +269,67 @@ class BattleDataService extends BaseService {
|
||||
|
||||
private function updateScore()
|
||||
{
|
||||
$userInfo = myself()->_getOrmUserInfo();
|
||||
$rankScore = getReqVal('rank_score', 0);
|
||||
if ($rankScore > 0) {
|
||||
$newRank = $userInfo['rank'];
|
||||
$newScore = $userInfo['score'];
|
||||
mt\Rank::calcNewRankAndScore($userInfo['rank'], $userInfo['score'], $newRank, $newScore, $rankScore);
|
||||
if ($newRank >= $userInfo['rank'] && $newScore != $userInfo['score']) {
|
||||
myself()->_updateUserInfo(array(
|
||||
'rank' => $newRank,
|
||||
'score' => $newScore,
|
||||
'history_best_rank' => max($userInfo['rank'], $newRank),
|
||||
'score_modifytime' => myself()->_getNowTime(),
|
||||
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
||||
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
||||
));
|
||||
Season::update($this->currSeasonMeta['id'], array(
|
||||
'rank' => $newRank,
|
||||
'score' => $newScore,
|
||||
'history_best_rank' => max($userInfo['rank'], $newRank),
|
||||
'score_modifytime' => myself()->_getNowTime(),
|
||||
'score_modifytime' => myself()->_getNowTime(),
|
||||
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
||||
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
||||
));
|
||||
if (getReqVal('room_mode', 0) == 0) {
|
||||
$userInfo = myself()->_getOrmUserInfo();
|
||||
$rankScore = getReqVal('rank_score', 0);
|
||||
if ($rankScore > 0) {
|
||||
$newRank = $userInfo['rank'];
|
||||
$newScore = $userInfo['score'];
|
||||
mt\Rank::calcNewRankAndScore($userInfo['rank'], $userInfo['score'], $newRank, $newScore, $rankScore);
|
||||
if ($newRank >= $userInfo['rank'] && $newScore != $userInfo['score']) {
|
||||
myself()->_updateUserInfo(array(
|
||||
'rank' => $newRank,
|
||||
'score' => $newScore,
|
||||
'history_best_rank' => max($userInfo['rank'], $newRank),
|
||||
'score_modifytime' => myself()->_getNowTime(),
|
||||
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
||||
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
||||
));
|
||||
Season::update($this->currSeasonMeta['id'], array(
|
||||
'rank' => $newRank,
|
||||
'score' => $newScore,
|
||||
'history_best_rank' => max($userInfo['rank'], $newRank),
|
||||
'score_modifytime' => myself()->_getNowTime(),
|
||||
'score_modifytime' => myself()->_getNowTime(),
|
||||
'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['hero_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', ''));
|
||||
error_log('addItems ' . 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