空投指定品阶英雄
This commit is contained in:
parent
8f6b20aff6
commit
5b3a849467
@ -32,6 +32,7 @@ class Rankings {
|
||||
}
|
||||
if (await Redis.exists(RANKING_KEY + "account")){
|
||||
await Redis.del(RANKING_KEY + 'account')
|
||||
await Redis.del(RANKING_KEY + 'ranking')
|
||||
await this.calcRanking();
|
||||
console.log("跟新rank榜单")
|
||||
}else {
|
||||
|
@ -8,6 +8,7 @@
|
||||
class CallbackController extends BaseController {
|
||||
|
||||
private $handlers = array(
|
||||
'mintNftHero' => 'MintNftHero' ,
|
||||
'gameItemMallBuyOk' => 'GameItemMallBuyOk',
|
||||
'gameItemMarketBuyOk' => 'GameItemMarketBuyOk',
|
||||
'MarketSellOrderOk' => 'MarketSellOrderOk',
|
||||
|
138
webapp/services/callback/MintNftHero.php
Normal file
138
webapp/services/callback/MintNftHero.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace services;
|
||||
|
||||
require_once ('services/callback/common/SignatureService.php');
|
||||
require_once('mt/Item.php');
|
||||
require_once('mt/Hero.php');
|
||||
require_once('mt/Parameter.php');
|
||||
|
||||
|
||||
use mt\Item;
|
||||
use mt\Hero;
|
||||
use mt\Parameter;
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
class MintNftHero
|
||||
{
|
||||
const TYPE_1 = 1; //D
|
||||
const TYPE_2 = 2; //C
|
||||
const TYPE_3 = 3; //B
|
||||
const TYPE_4 = 4; //A
|
||||
const TYPE_5 = 5; //S
|
||||
public function process()
|
||||
{
|
||||
SignatureService::web3ServiceCheck();
|
||||
$address = getReqVal('address', '');
|
||||
$tokenId = getReqVal('tokenId', '');
|
||||
if (!$tokenId){
|
||||
echo json_encode(array(
|
||||
'errcode' => 1,
|
||||
'errmsg' => "tokenId empty",
|
||||
));
|
||||
die;
|
||||
}
|
||||
$itemId = getReqVal('itemId', '');
|
||||
$itemMeta = Item::get($itemId);
|
||||
if (!$itemMeta || $itemMeta['type'] != Item::HERO_TYPE){
|
||||
echo json_encode(array(
|
||||
'errcode' => 1,
|
||||
'errmsg' => "itemId error",
|
||||
));
|
||||
die;
|
||||
}
|
||||
$quality = getReqVal('quality', 0);
|
||||
if (!in_array($quality,array(
|
||||
self::TYPE_1,
|
||||
self::TYPE_2,
|
||||
self::TYPE_3,
|
||||
self::TYPE_4,
|
||||
self::TYPE_5,
|
||||
))){
|
||||
echo json_encode(array(
|
||||
'errcode' => 1,
|
||||
'errmsg' => "quality error",
|
||||
));
|
||||
die;
|
||||
}
|
||||
error_log("MintNftHero-------------------".json_encode($_REQUEST));
|
||||
$this->internalAddHero($tokenId,$itemId,$quality);
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => "callback success",
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
private function internalAddHero($tokenId,$itemId,$quality)
|
||||
{
|
||||
$randAttr = $this->_getRandAttr($itemId,$quality) ;
|
||||
$fieldsKv = array(
|
||||
'hero_id' => $itemId,
|
||||
'token_id' => $tokenId,
|
||||
'hero_lv' => 1,
|
||||
'quality' => 1,
|
||||
'state' => 0,
|
||||
'skill_lv1' => 1,
|
||||
'skill_lv2' => 1,
|
||||
'rand_attr' => json_encode($randAttr),
|
||||
'lock_type' => 0,
|
||||
'unlock_time' => 0,
|
||||
'unlock_trade_time' => 0,
|
||||
'activate' => 1,
|
||||
'base_attr' => json_encode($randAttr),
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime()
|
||||
);
|
||||
|
||||
SqlHelper::insert(
|
||||
myself()->_getMysql(''),
|
||||
't_hero',
|
||||
$fieldsKv
|
||||
);
|
||||
}
|
||||
|
||||
private function _getRandAttr($heroId,$quality){
|
||||
$heroMeta = Hero::get($heroId);
|
||||
$baseAttr = Hero::getHeroAttr($heroMeta);
|
||||
$paramMeta = Parameter::getVal('quality',0);
|
||||
$attr = array();
|
||||
if ($paramMeta){
|
||||
$rate = explode('|',$paramMeta);
|
||||
foreach ($baseAttr as $value){
|
||||
if (in_array($value['attr_id'],array(kHAT_Hp,kHAT_Atk,kHAT_Def))){
|
||||
// $quality = self::_getAttrQuality($type);
|
||||
$minRate = $rate[$quality-1] * 100;
|
||||
$maxRate = $rate[$quality] * 100 - 1;
|
||||
if ($quality == 5){
|
||||
$maxRate = $rate[$quality] * 100;
|
||||
}
|
||||
$finalRate = rand($minRate,$maxRate) / 100;
|
||||
if ( $value['attr_id'] == kHAT_Hp){
|
||||
$attr_val = round($value['val'] * $finalRate,0);
|
||||
}else{
|
||||
$attr_val = round($value['val'] * $finalRate,2);
|
||||
}
|
||||
|
||||
array_push($attr,array(
|
||||
'attr_id' => $value['attr_id'],
|
||||
'val' => $attr_val,
|
||||
'quality' => $quality,
|
||||
// 'rate' => $finalRate,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
array_push($attr,array(
|
||||
'attr_id' => $value['attr_id'],
|
||||
'val' => $value['val'] ,
|
||||
'quality' => 0,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $attr;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user