game2006api/webapp/controller/FragmentController.class.php
2022-09-26 21:08:55 +08:00

486 lines
20 KiB
PHP

<?php
require_once('models/Fragment.php');
require_once('models/Nft.php');
require_once('services/PropertyChgService.php');
require_once('services/LogService.php');
use models\Fragment;
use models\Nft;
use services\FormulaService;
use services\LogService;
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());
$meta = mt\Parameter::getByName('jigsaw_merge_h_price');
$mint = $meta ? $meta['param_value'] : 100;
$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());
$meta = mt\Parameter::getByName('jigsaw_merge_w_price');
$mint = $meta ? $meta['param_value'] : 30;
$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;
// }
//销毁碎片
$params =array();
foreach ($token_id_arr as $val){
array_push($params,array(
'unique_id'=>null,
'token_id'=>$val,
));
Fragment::deleteFragment(['token_id'=>$val]);
}
{
//埋点
$event = [
'name' => LogService::FRAGMENT_SYNTH_MATERIAL,
];
LogService::ConsumableMaterial($event,$params);
}
// $this->_decItems($costItems);
//生成NFT英雄
$tokenid = Nft::addNft($itemMeta);
{
//埋点
$nftDb = Nft::getNft($tokenid);
$event = array(
'name' => LogService::HERO_FRAGMENT,
'val' => mt\Parameter::getByName('jigsaw_merge_h_price')['param_value']
);
LogService::fragmentSynth($event,$nftDb);
}
$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;
// }
//销毁碎片
$params =array();
foreach ($token_id_arr as $val){
array_push($params,array(
'unique_id'=>null,
'token_id'=>$val,
));
Fragment::deleteFragment(['token_id'=>$val]);
}
{
//埋点
$event = [
'name' => LogService::FRAGMENT_SYNTH_MATERIAL,
];
LogService::ConsumableMaterial($event,$params);
}
// $this->_decItems($costItems);
$itemMetaList = mt\Item::getMetaListByType(mt\Item::HERO_TYPE);
$key = rand(0,count($itemMetaList)-1);
$itemMeta = $itemMetaList[$key];
//生成NFT英雄
$tokenid = Nft::addNft($itemMeta);
{
//埋点
$nftDb = Nft::getNft($tokenid);
$event = array(
'name' => LogService::HERO_FRAGMENT,
'val' => mt\Parameter::getByName('jigsaw_merge_h_price')['param_value']
);
LogService::fragmentSynth($event,$nftDb);
}
$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;
// }
//销毁碎片
$params = array();
foreach ($token_id_arr as $val){
array_push($params,array(
'unique_id'=>null,
'token_id'=>$val,
));
Fragment::deleteFragment(['token_id'=>$val]);
}
{
//埋点
$event = [
'name' => LogService::FRAGMENT_SYNTH_MATERIAL,
];
LogService::ConsumableMaterial($event,$params);
}
// $this->_decItems($costItems);
//生成NFT英雄
$tokenid = Nft::addNft($itemMeta);
{
//埋点
$nftDb = Nft::getNft($tokenid);
$event = array(
'name' => LogService::GUN_FRAGMENT,
'val' => mt\Parameter::getByName('jigsaw_merge_w_price')['param_value']
);
LogService::fragmentSynth($event,$nftDb);
}
$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;
// }
//销毁碎片
$params = array();
foreach ($token_id_arr as $val){
array_push($params,array(
'unique_id'=>null,
'token_id'=>$val,
));
Fragment::deleteFragment(['token_id'=>$val]);
}
{
//埋点
$event = [
'name' => LogService::FRAGMENT_SYNTH_MATERIAL,
];
LogService::ConsumableMaterial($event,$params);
}
// $this->_decItems($costItems);
$itemMetaList = mt\Item::getMetaListByType(mt\Item::GUN_TYPE);
$key = rand(0,count($itemMetaList)-1);
$itemMeta = $itemMetaList[$key];
//生成NFT英雄
$tokenid = Nft::addNft($itemMeta);
{
//埋点
$nftDb = Nft::getNft($tokenid);
$event = array(
'name' => LogService::GUN_FRAGMENT,
'val' => mt\Parameter::getByName('jigsaw_merge_w_price')['param_value']
);
LogService::fragmentSynth($event,$nftDb);
}
$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;
}