game2006api/webapp/controller/GMController.class.php
hujiabin 2d26b1b957 1
2024-07-04 16:57:16 +08:00

346 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once('phpcommon/tglog.php');
require_once('mt/Item.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);
},
'.addnft' => function () use($params) {
$this->addNft($params);
},
'.addtili' => function () use($params) {
$this->addTili($params);
},
'.getsystime' => function () use($params) {
$this->getSysTime($params);
},
'.setsystime' => function () use($params) {
$this->setSysTime($params);
},
'.reset_mission' => function () use($params) {
$this->resetMission($params);
},
'.addtest' => function () use($params) {
$this->addDyndata($params);
},
'.addhero' => function () use($params) {
$this->addHero($params);
},
'.loot' => function () use($params) {
$this->lootTest($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 道具数量 //添加道具
.addtili 英雄id 体力值 //添加英雄体力
.getsystime //获取服务器时间
.setsystime //设置服务器时间,示例:.setsystime 2021-12-08 00:00:00
.reset_mission //重置任务
.addtest //添加测试数据 1击杀数 2星星数 3升段数
.loot 索引ID 次数 //测试掉落系统数据,示例:.loot 1030 10
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;
}
Hero::addSyntheticHero($itemMeta,$quality);
$propertyChgService->addHeroChg();
$this->_rspData(array(
'text' => 'add item success',
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
));
}
private function addNft($params)
{
$itemId = getXVal($params, 0, 0);
$propertyChgService = new services\PropertyChgService();
$awardService = new services\AwardService();
$itemMeta = mt\Item::get($itemId);
if ($itemMeta) {
$tokenType = Nft::getTokenType($itemMeta);
if ($tokenType == Nft::NONE_TYPE) {
myself()->_rspErr(1, 'param item_id error');
return;
} else {
SqlHelper::insert(
myself()->_getMarketMysql(),
't_nft',
array(
'token_id' => Nft::genTempTokenId(),
'token_type' => $tokenType,
'game_id' => 2006,
'item_id' => $itemId,
'owner_address' => myself()->_getAddress(),
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
}
} else {
myself()->_rspErr(1, 'param item_id error');
return;
}
$this->_rspData(array(
'text' => 'add nft success',
'award' => $awardService->toDto(),
'property_chg' => $propertyChgService->toDto(),
));
}
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' => '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 addDyndata($params){
$type = getXVal($params, 0, 0);
$num = getXVal($params, 1, 0);
switch ($type){
case 1 : {
myself()->_incV(TN_TOTAL_KILLS_NUM,0,$num);
}
break;
case 2 : {
myself()->_incV(TN_TOTAL_STAR_NUM,0,$num);
}
break;
case 3 : {
myself()->_incV(TN_TOTAL_DIAMOND_CONSUME,0,$num);
}
break;
case 4 : {
myself()->_incV(TN_TOTAL_CEG_CONSUME,0,$num);
}
}
}
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);
$luckyMaxPro = \mt\Parameter::getVal('economy_account_luck_E',0);
$prob = $luckyMaxPro * ($lucky / ($lucky+$luckyParam));
for ($i=0; $i<$itemNum; $i++){
$times = $this->proEffect($prob,1);
$temp = array(
"prob" => $prob,
"times" => $times
);
$items = \services\LootService::dropOutItem($itemMeta['loot']);
if ($times > 0){
foreach ($items as &$item){
$item['item_num'] += $item['item_num']*$times;
}
}
array_unshift($items,$temp);
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();
}
}