295 lines
9.4 KiB
PHP
295 lines
9.4 KiB
PHP
<?php
|
|
|
|
require_once('phpcommon/tglog.php');
|
|
|
|
require_once('mt/Item.php');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/LootConfig.php');
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/LootService.php');
|
|
require_once('services/MailApiService.php');
|
|
require_once('models/Nft.php');
|
|
require_once('models/Hero.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Nft;
|
|
use models\Hero;
|
|
use phpcommon\TGLog;
|
|
|
|
class GMController extends BaseAuthedController {
|
|
|
|
public function _handlePre()
|
|
{
|
|
parent::_handlePre();
|
|
if (SERVER_ENV == _ONLINE) {
|
|
die("can't create GMController");
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function execCmd()
|
|
{
|
|
$cmds = explode(' ', getReqVal('cmd', ''));
|
|
if (count($cmds) < 0) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$cmd = $cmds[0];
|
|
$params = count($cmds) > 1 ? array_slice($cmds, 1) : array();
|
|
$cmdHash = array(
|
|
'.help' => function () use($params) {
|
|
$this->help($params);
|
|
},
|
|
'.additem' => function () use($params) {
|
|
$this->addItem($params);
|
|
},
|
|
'.getsystime' => function () use($params) {
|
|
$this->getSysTime($params);
|
|
},
|
|
'.setsystime' => function () use($params) {
|
|
$this->setSysTime($params);
|
|
},
|
|
'.reset_mission' => function () use($params) {
|
|
$this->resetMission($params);
|
|
},
|
|
'.addhero' => function () use($params) {
|
|
$this->addHero($params);
|
|
},
|
|
'.decgold' => function () use($params) {
|
|
$this->decGold($params);
|
|
},
|
|
'.loot' => function () use($params) {
|
|
$this->lootTest($params);
|
|
},
|
|
'.clear_big_wheel' => function () use($params) {
|
|
$this->clearBigWheel($params);
|
|
}
|
|
);
|
|
$func = getXVal($cmdHash, $cmd);
|
|
if ($func) {
|
|
$func($params);
|
|
} else {
|
|
$this->_rspErr(2, 'Unrecognized instruction');
|
|
return;
|
|
}
|
|
}
|
|
|
|
private function help($params)
|
|
{
|
|
$this->_rspData(array(
|
|
'text' => <<<END
|
|
.additem 道具id 道具数量 //添加道具
|
|
.getsystime //获取服务器时间
|
|
.setsystime //设置服务器时间,示例:.setsystime 2021-12-08 00:00:00
|
|
.reset_mission //重置任务
|
|
.loot 索引ID 次数 //测试掉落系统数据,示例:.loot 1030 10
|
|
.clear_big_wheel clear big wheel data
|
|
END
|
|
));
|
|
}
|
|
|
|
private function addItem($params)
|
|
{
|
|
$itemId = getXVal($params, 0, 0);
|
|
$itemNum = getXVal($params, 1, 0);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
$this->_addItems(array(
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => $itemNum
|
|
)
|
|
), $awardService, $propertyChgService);
|
|
$this->_rspData(array(
|
|
'text' => 'add item success',
|
|
'award' => $awardService->toDto(),
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
private function addHero($params)
|
|
{
|
|
$itemId = getXVal($params, 0, 0);
|
|
$quality = getXVal($params, 1, 1);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
$itemMeta = mt\Item::get($itemId);
|
|
if (!$itemMeta){
|
|
myself()->_rspErr(1, 'param item_id error');
|
|
return;
|
|
}
|
|
if ($quality > 6){
|
|
myself()->_rspErr(1, 'param quality error');
|
|
return;
|
|
}
|
|
if ($itemMeta['type'] != \mt\Item::HERO_TYPE){
|
|
myself()->_rspErr(1, 'param item_id error');
|
|
return;
|
|
}
|
|
$heroMeta = \mt\Hero::get($itemMeta['id']);
|
|
Hero::addSyntheticHero($heroMeta,$quality);
|
|
$propertyChgService->addHeroChg();
|
|
$this->_rspData(array(
|
|
'text' => 'add item success',
|
|
'award' => $awardService->toDto(),
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
private function getSysTime($params)
|
|
{
|
|
$sysTime = phpcommon\timestamp_to_datetime(phpcommon\getNowTime());
|
|
$this->_rspData(array(
|
|
'text' => $sysTime,
|
|
));
|
|
}
|
|
|
|
private function setSysTime($params)
|
|
{
|
|
if (!defined('GLOBAL_TIME_OFFSET_KEY')) {
|
|
die('不支持设置系统时间');
|
|
return;
|
|
}
|
|
$newtime = strtotime($_REQUEST['newtime']);
|
|
if ($newtime <= 0) {
|
|
die('时间格式错误');
|
|
return;
|
|
}
|
|
$time_offset = $newtime - phpcommon\getRealTime();
|
|
$r = new phpcommon\Redis(array(
|
|
'host' => '127.0.0.1',
|
|
'port' => 6379,
|
|
'passwd' => ''
|
|
|
|
));
|
|
$r->set(GLOBAL_TIME_OFFSET_KEY, $time_offset);
|
|
}
|
|
|
|
private function resetMission($params)
|
|
{
|
|
myself()->_getSelfMysql()->execScript('DELETE FROM t_mission;');
|
|
myself()->_getSelfMysql()->execScript('DELETE FROM t_bigdata;');
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
|
|
private function lootTest($params){
|
|
|
|
$lucky = getXVal($params, 0, 0);
|
|
$itemId = getXVal($params, 1, 0);
|
|
$itemNum = getXVal($params, 2, 0);
|
|
$itemMeta = mt\Item::get($itemId);
|
|
if (!$itemMeta || $itemMeta['type'] != mt\Item::BATTLE_REWARD_BOX) {
|
|
$this->_rspErr(2, 'config error');
|
|
return;
|
|
}
|
|
$lootMeta = mt\LootConfig::find($itemMeta['loot']);
|
|
if ($lootMeta['isAffected']){
|
|
$luckyParam = \mt\Parameter::getVal('economy_account_luck_K',0);
|
|
$rangeArr = explode("|",\mt\Parameter::getVal('economy_account_luck_range',0));
|
|
$rate = ($rangeArr[1]-$rangeArr[0]) * $lucky/($lucky+$luckyParam) + $rangeArr[0];
|
|
$rnd = rand() / (mt_getrandmax() + 1);
|
|
for ($i=0; $i<$itemNum; $i++){
|
|
if ($rnd <= $rate){
|
|
$items = \services\LootService::dropOutItem($itemMeta['loot']);
|
|
}
|
|
array_unshift($items,array(
|
|
'rnd' => $rnd,
|
|
'rate' => $rate,
|
|
));
|
|
TGLog::writeToLog("game_2006_api","loot",array(
|
|
$itemId => $items
|
|
));
|
|
}
|
|
}else{
|
|
for ($i=0; $i<$itemNum; $i++){
|
|
$items = \services\LootService::dropOutItem($itemMeta['loot']);
|
|
TGLog::writeToLog("game_2006_api","loot",array(
|
|
$itemId => $items
|
|
));
|
|
}
|
|
}
|
|
}
|
|
|
|
private function proEffect($p,$b){
|
|
if ($p * $b > -1 && $b != 0) {
|
|
$x = floor($p) * $b;
|
|
$y = max($x+$b,-1);
|
|
$q = ($p * $b - $y) / ($x - $y);
|
|
$rnd = rand(1,100);
|
|
return $rnd < $q*100 ? $x : $y;
|
|
}else{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public function sendMail()
|
|
{
|
|
$to = getReqVal('to', '');
|
|
$subject = getReqVal('subject', '');
|
|
$content = getReqVal('content', '');
|
|
$attachments = getReqVal('attachments', '');
|
|
$unikey = 'test:' . uniqid();
|
|
SqlHelper::upsert
|
|
(myself()->_getMailMysql(),
|
|
't_sys_mail',
|
|
array(
|
|
'unikey' => $unikey
|
|
),
|
|
array(
|
|
),
|
|
array(
|
|
'unikey' => $unikey,
|
|
'subject' => $subject,
|
|
'content' => $content,
|
|
'recipients' => json_encode(array(
|
|
$to,
|
|
)),
|
|
'attachments' => $attachments,
|
|
'tag1' => 1,
|
|
'tag2' => 100,
|
|
'sendtime' => myself()->_getNowTime(),
|
|
'expiretime' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
|
|
'user_reg_start_time' => 0,
|
|
'user_reg_end_time' => myself()->_getNowTime() + 3600 * 24 * 365 * 10,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
)
|
|
);
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
private function decGold($params)
|
|
{
|
|
$itemNum = getXVal($params, 0, 0);
|
|
$userInfo = myself()->_getUserInfo(array('gold'));
|
|
$oldGold = myself()->_getItemCount(V_ITEM_GOLD, $userInfo);
|
|
$decItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $itemNum
|
|
)
|
|
);
|
|
myself()->_decItems($decItems);
|
|
$newUserInfo = myself()->_getUserInfo(array('gold'));
|
|
$newGold = myself()->_getItemCount(V_ITEM_GOLD, $newUserInfo);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
|
|
myself()->_rspData(array(
|
|
'oldGold' => $oldGold,
|
|
'newGold' => $newGold,
|
|
'itemNum' => $itemNum,
|
|
'property_chg' => $propertyChgService->toDto()
|
|
));
|
|
}
|
|
|
|
private function clearBigWheel($params){
|
|
$key = myself()->_getModelConstant('MidData', 'BIG_WHEEL_TYPE');
|
|
myself()->_callModelStatic('MidData', 'setData', $key, json_encode(array()));
|
|
myself()->_rspOk();
|
|
}
|
|
}
|