392 lines
16 KiB
PHP
392 lines
16 KiB
PHP
<?php
|
|
|
|
require_once('models/Fragment.php');
|
|
require_once('models/Nft.php');
|
|
|
|
require_once('services/PropertyChgService.php');
|
|
|
|
use models\Fragment;
|
|
use models\Nft;
|
|
use services\FormulaService;
|
|
|
|
class FragmentController extends BaseAuthedController
|
|
{
|
|
private $hero_count = 9;
|
|
private $gun_count = 9;
|
|
|
|
public function fragmentList()
|
|
{
|
|
$type = getReqVal('type','');
|
|
if (! $type || !in_array($type,[1,2])){
|
|
$this->_rspErr(1,'type parameter error');
|
|
return ;
|
|
}
|
|
$fragmentList = [];
|
|
Fragment::getFragmentList(function ($row) use(&$fragmentList,$type) {
|
|
switch ($type){
|
|
case 1:
|
|
{
|
|
if ( $row['type'] == 1 || $row['type'] == 3){
|
|
array_push($fragmentList, $row);
|
|
}
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
if ( $row['type'] == 2 || $row['type'] == 4){
|
|
array_push($fragmentList, $row);
|
|
};
|
|
}
|
|
}
|
|
});
|
|
$this->_rspData(array(
|
|
'fragment_list' => $fragmentList
|
|
));
|
|
}
|
|
|
|
public function syntheticFragmentPreview()
|
|
{
|
|
$type = getReqVal('type', 0);
|
|
switch ($type) {
|
|
case 1:
|
|
{
|
|
$itemMetaList = mt\Item::getMetaListByType(mt\Item::HERO_TYPE);
|
|
$hero = array();
|
|
foreach ($itemMetaList as $meta){
|
|
array_push($hero,$meta['id']);
|
|
}
|
|
$mint = strval(\services\FormulaService::Hero_Parts_Synthetic_Cost());
|
|
$this->_rspData(array(
|
|
'list' => $hero,
|
|
'mint' => $mint
|
|
));
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
$itemMetaList = mt\Item::getMetaListByType(mt\Item::GUN_TYPE);
|
|
$gun = array();
|
|
foreach ($itemMetaList as $meta){
|
|
array_push($gun,$meta['id']);
|
|
}
|
|
$mint = strval(\services\FormulaService::Weapon_Parts_Synthetic_Cost());
|
|
$this->_rspData(array(
|
|
'list' => $gun,
|
|
'mint' => $mint
|
|
));
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
$this->_rspErr(1, 'type parameter error');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function syntheticFragment(){
|
|
$type = getReqVal('type', 0);
|
|
$unique_ids = getReqVal('unique_ids','');
|
|
$unique_id_special = getReqVal('unique_id_special','');
|
|
$item_id = getReqVal('item_id','');
|
|
$unique_id_arr = explode('|',$unique_ids);
|
|
if (count($unique_id_arr) != 8){
|
|
$this->_rspErr(1,'Insufficient number of parameters');
|
|
return ;
|
|
}
|
|
switch ($type) {
|
|
case 1:
|
|
{
|
|
if ($unique_id_special){
|
|
//指定合成英雄
|
|
$itemMeta = mt\Item::get($item_id);
|
|
if (!$itemMeta){
|
|
$this->_rspErr(1,'item_id param error');
|
|
return ;
|
|
}
|
|
$fragmentDbSpecial = Fragment::getFragmentByIdx($unique_id_special);
|
|
if (!$fragmentDbSpecial){
|
|
$this->_rspErr(1,'unique_id_special param error');
|
|
return ;
|
|
}
|
|
if ($fragmentDbSpecial['type'] != 3){
|
|
$this->_rspErr(1,'unique_id_special param error(type)');
|
|
return ;
|
|
}
|
|
$token_id_arr = array();
|
|
array_push($token_id_arr,$fragmentDbSpecial['token_id']);
|
|
foreach ($unique_id_arr as $val){
|
|
$fragmentDb = Fragment::getFragmentByIdx($val);
|
|
if (!$fragmentDb){
|
|
$this->_rspErr(1,'unique_ids param error');
|
|
return ;
|
|
}
|
|
if ($fragmentDb['type'] != 1){
|
|
$this->_rspErr(1,'unique_ids param error(type)');
|
|
return ;
|
|
}
|
|
array_push($token_id_arr,$fragmentDb['token_id']);
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => \services\FormulaService::Hero_Parts_Synthetic_Cost()
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
//销毁碎片
|
|
foreach ($token_id_arr as $val){
|
|
Fragment::deleteFragment(['token_id'=>$val]);
|
|
}
|
|
$this->_decItems($costItems);
|
|
//生成NFT英雄
|
|
Nft::addNft($itemMeta);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
$propertyChgService->addFragment();
|
|
$propertyChgService->addHeroChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
'item_id' => $itemMeta['id']
|
|
));
|
|
}else{
|
|
//随机合成英雄
|
|
$token_id_arr = array();
|
|
foreach ($unique_id_arr as $val){
|
|
$fragmentDb = Fragment::getFragmentByIdx($val);
|
|
if (!$fragmentDb){
|
|
$this->_rspErr(1,'unique_id param error');
|
|
return ;
|
|
}
|
|
if ($fragmentDb['type'] != 1){
|
|
$this->_rspErr(1,'unique_id param error(type)');
|
|
return ;
|
|
}
|
|
array_push($token_id_arr,$fragmentDb['token_id']);
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => \services\FormulaService::Hero_Parts_Synthetic_Cost()
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
//销毁碎片
|
|
foreach ($token_id_arr as $val){
|
|
Fragment::deleteFragment(['token_id'=>$val]);
|
|
}
|
|
$this->_decItems($costItems);
|
|
$itemMetaList = mt\Item::getMetaListByType(mt\Item::HERO_TYPE);
|
|
$key = rand(0,count($itemMetaList)-1);
|
|
$itemMeta = $itemMetaList[$key];
|
|
//生成NFT英雄
|
|
Nft::addNft($itemMeta);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
$propertyChgService->addFragment();
|
|
$propertyChgService->addHeroChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
'item_id' => $itemMeta['id']
|
|
));
|
|
}
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
if ($unique_id_special){
|
|
//指定合成枪械
|
|
$itemMeta = mt\Item::get($item_id);
|
|
if (!$itemMeta){
|
|
$this->_rspErr(1,'item_id param error');
|
|
return ;
|
|
}
|
|
$fragmentDbSpecial = Fragment::getFragmentByIdx($unique_id_special);
|
|
if (!$fragmentDbSpecial){
|
|
$this->_rspErr(1,'unique_id_special param error');
|
|
return ;
|
|
}
|
|
if ($fragmentDbSpecial['type'] != 4){
|
|
$this->_rspErr(1,'unique_id_special param error(type)');
|
|
return ;
|
|
}
|
|
$token_id_arr = array();
|
|
array_push($token_id_arr,$fragmentDbSpecial['token_id']);
|
|
foreach ($unique_id_arr as $val){
|
|
$fragmentDb = Fragment::getFragmentByIdx($val);
|
|
if (!$fragmentDb){
|
|
$this->_rspErr(1,'unique_ids param error');
|
|
return ;
|
|
}
|
|
if ($fragmentDb['type'] != 2){
|
|
$this->_rspErr(1,'unique_ids param error(type)');
|
|
return ;
|
|
}
|
|
array_push($token_id_arr,$fragmentDb['token_id']);
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => \services\FormulaService::Weapon_Parts_Synthetic_Cost()
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
//销毁碎片
|
|
foreach ($token_id_arr as $val){
|
|
Fragment::deleteFragment(['token_id'=>$val]);
|
|
}
|
|
$this->_decItems($costItems);
|
|
//生成NFT英雄
|
|
Nft::addNft($itemMeta);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
$propertyChgService->addFragment();
|
|
$propertyChgService->addGunChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
'item_id' => $itemMeta['id']
|
|
));
|
|
|
|
}else{
|
|
//随机合成枪械
|
|
$token_id_arr = array();
|
|
foreach ($unique_id_arr as $val){
|
|
$fragmentDb = Fragment::getFragmentByIdx($val);
|
|
if (!$fragmentDb){
|
|
$this->_rspErr(1,'unique_id param error');
|
|
return ;
|
|
}
|
|
if ($fragmentDb['type'] != 2){
|
|
$this->_rspErr(1,'unique_id param error(type)');
|
|
return ;
|
|
}
|
|
array_push($token_id_arr,$fragmentDb['token_id']);
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => \services\FormulaService::Weapon_Parts_Synthetic_Cost()
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
//销毁碎片
|
|
foreach ($token_id_arr as $val){
|
|
Fragment::deleteFragment(['token_id'=>$val]);
|
|
}
|
|
$this->_decItems($costItems);
|
|
$itemMetaList = mt\Item::getMetaListByType(mt\Item::GUN_TYPE);
|
|
$key = rand(0,count($itemMetaList)-1);
|
|
$itemMeta = $itemMetaList[$key];
|
|
//生成NFT英雄
|
|
Nft::addNft($itemMeta);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
$propertyChgService->addFragment();
|
|
$propertyChgService->addGunChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
'item_id' => $itemMeta['id']
|
|
));
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
$this->_rspErr(1, 'type parameter error');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function showBaseByItemId(){
|
|
$item_id = getReqVal('item_id','');
|
|
$itemMeta = mt\Item::get($item_id);
|
|
if (! $itemMeta){
|
|
$this->_rspErr(1, 'item_id parameter error');
|
|
return;
|
|
}
|
|
if ($itemMeta['type'] == self::HERO_TYPE){
|
|
$heroMeta = mt\Hero::get($itemMeta['id']);
|
|
$baseAttr =[];
|
|
if ($heroMeta) {
|
|
$baseAttr = mt\Hero::getHeroAttr($heroMeta);
|
|
}
|
|
$heroLucky = FormulaService::Hero_Advanced_Lucky_Value(1);
|
|
$hero = array(
|
|
'hero_id' => $itemMeta['id'],
|
|
'hero_lv' => 1,
|
|
'quality' => 1,
|
|
'skill_lv1' => 1,
|
|
'skill_lv2' => 1,
|
|
'attr_base' => $baseAttr,
|
|
'lucky' => strval($heroLucky),
|
|
'skill_points' => 0,
|
|
'skill_common' => [
|
|
"100100",
|
|
"100120",
|
|
"100140",
|
|
"100160",
|
|
"100180",
|
|
"100200",
|
|
"100220",
|
|
"100240",
|
|
"100260",
|
|
"100280"
|
|
],
|
|
'hero_tili' => strval(round(FormulaService::Hero_NFT_Maximum_Physical_Strength(1,$heroLucky),3)),
|
|
'hero_tili_max' => strval(round(FormulaService::Hero_NFT_Maximum_Physical_Strength(1,$heroLucky),3)),
|
|
'chip_strength_sum' =>0,
|
|
);
|
|
$hero['current_pvp_get_ceg'] = strval(round(FormulaService::getHeroPvpDailyCegUpLimit($hero),2));
|
|
$hero['pvp_ceg_uplimit'] = strval(round(FormulaService::getHeroPvpDailyCegUpLimit($hero),2));
|
|
$hero['current_pve_get_ceg'] = strval(round(FormulaService::getHeroPveDailyCegUpLimit($hero),2));
|
|
$hero['pve_ceg_uplimit'] = strval(round(FormulaService::getHeroPveDailyCegUpLimit($hero),2));
|
|
$this->_rspData(array(
|
|
'data' => $hero
|
|
));
|
|
}else if ($itemMeta['type'] == self::GUN_TYPE){
|
|
$baseAttr = mt\Equip::getGunBaseAttrs($itemMeta['relationship']);
|
|
$gunLucky = FormulaService::Weapon_Advanced_Lucky_Value(1);
|
|
$gun = array(
|
|
'gun_id' => $itemMeta['id'],
|
|
'gun_lv' => 1,
|
|
'quality' => 1,
|
|
'attr_base' => $baseAttr,
|
|
'lucky' => strval($gunLucky),
|
|
'durability' => strval(round(FormulaService::Weapon_NFT_Maximum_Durability(1,$gunLucky),3)),
|
|
'durability_max' => strval(round(FormulaService::Weapon_NFT_Maximum_Durability(1,$gunLucky),3)),
|
|
'chip_strength_sum' =>0,
|
|
);
|
|
$gun['current_pvp_get_ceg'] = strval(round(FormulaService::getWeaponPvpDailyCegUpLimit($gun),2)) ;
|
|
$gun['pvp_ceg_uplimit'] = strval(round(FormulaService::getWeaponPvpDailyCegUpLimit($gun),2)) ;
|
|
$gun['current_pve_get_ceg'] = strval(round(FormulaService::getWeaponPveDailyCegUpLimit($gun),2)) ;
|
|
$gun['pve_ceg_uplimit'] = strval(round(FormulaService::getWeaponPveDailyCegUpLimit($gun),2)) ;
|
|
$this->_rspData(array(
|
|
'data' => $gun
|
|
));
|
|
}else{
|
|
$this->_rspErr(1, 'item_id parameter error');
|
|
return;
|
|
}
|
|
}
|
|
|
|
const HERO_TYPE = 3;
|
|
const GUN_TYPE = 7;
|
|
|
|
} |