碎片合成

This commit is contained in:
hujiabin 2023-03-30 15:40:39 +08:00
parent 58b5d71d0b
commit a93f8e9fdb
3 changed files with 151 additions and 232 deletions

View File

@ -41,9 +41,9 @@ class Fragment(object):
'params': [
_common.ReqHead(),
['type', '', '类型1 英雄2 枪械'],
['unique_ids', '', '普通碎片unique id,用“|”分开id1|id2|id3...'],
['unique_id_special', '', '特殊碎片unique id'],
['item_id', '', '英雄或枪械的道具id'],
['params', '', '普通碎片 item id,用“|”分开item id1|item id2|item id3...'],
['param', '', '特殊碎片 item id'],
['item_id', '', '英雄或枪械 item id'],
],
'response': [
_common.RspHead(),

View File

@ -2,12 +2,18 @@
require_once('models/Fragment.php');
require_once('models/Nft.php');
require_once('models/Bag.php');
require_once('models/Hero.php');
require_once('models/Gun.php');
require_once('services/PropertyChgService.php');
require_once('services/LogService.php');
use models\Fragment;
use models\Nft;
use models\Bag;
use models\Hero;
use models\Gun;
use services\FormulaService;
use services\LogService;
@ -81,94 +87,95 @@ class FragmentController extends BaseAuthedController
}
}
private function _verificationFragment($itemId,$type,$sub_type){
$itemMetaParam = mt\Item::get($itemId);
if (!$itemMetaParam){
$this->_rspErr(1,'param error ' .$itemId);
die;
}
if ($itemMetaParam['type'] != $type||
$itemMetaParam['sub_type'] != $sub_type){
$this->_rspErr(1,'param error (type) '.$itemId);
die;
}
$itemNum = Bag::getItemCount($itemId);
if ($itemNum < 1){
$this->_rspErr(1,'Insufficient quantity '.$itemId.' Number:'.$itemNum);
die;
}
}
public function syntheticFragment(){
$this->_rspOk();return;
// $this->_rspOk();return;
$type = getReqVal('type', 0);
$unique_ids = getReqVal('unique_ids','');
$unique_id_special = getReqVal('unique_id_special','');
$params = getReqVal('params','');
$param = getReqVal('param','');
$item_id = getReqVal('item_id','');
$unique_id_arr = explode('|',$unique_ids);
if (count($unique_id_arr) != 8){
$paramArr = explode('|',$params);
if (count($paramArr) != 8){
$this->_rspErr(1,'Insufficient number of parameters');
return ;
}
switch ($type) {
case 1:
{
if ($unique_id_special){
$meta = mt\Parameter::getByName('jigsaw_merge_h_price');
$mint = $meta ? $meta['param_value'] : 100;
if ($param){
//指定合成英雄
$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');
if (!$itemMeta['type'] != \mt\Item::HERO_TYPE){
$this->_rspErr(1,'item_id param error (type)');
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;
$this->_verificationFragment($param,\mt\Item::FRAGMENT_TYPE,\mt\Item::HERO_FRAGMENT_SUBTYPE_PRO);
// $itemMetaParam = mt\Item::get($param);
// if (!$itemMetaParam){
// $this->_rspErr(1,'param error');
// return ;
// }
// if ($itemMetaParam['type'] != \mt\Item::FRAGMENT_TYPE ||
// $itemMetaParam['sub_type'] != \mt\Item::HERO_FRAGMENT_SUBTYPE_PRO){
// $this->_rspErr(1,'param error (type)');
// return ;
// }
// $itemNum = Bag::getItemCount($param);
// if ($itemNum < 1){
// $this->_rspErr(1,'Insufficient quantity '.$param);
// return ;
// }
$decItems = array();
array_push($decItems,$param);
foreach ($paramArr as $val){
$this->_verificationFragment($val,\mt\Item::FRAGMENT_TYPE,\mt\Item::HERO_FRAGMENT_SUBTYPE);
array_push($decItems,$val);
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $mint
)
);
$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);
foreach ($decItems as $item){
Bag::decItem($item,1);
}
$this->_decItems($costItems);
//生成英雄
Hero::addHero($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addFragment();
$propertyChgService->addBagChg();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
@ -176,65 +183,35 @@ class FragmentController extends BaseAuthedController
));
}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']);
$decItems = array();
foreach ($paramArr as $val){
$this->_verificationFragment($val,\mt\Item::FRAGMENT_TYPE,\mt\Item::HERO_FRAGMENT_SUBTYPE);
array_push($decItems,$val);
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $mint
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
// $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]);
foreach ($decItems as $item){
Bag::decItem($item,1);
}
{
//埋点
$event = [
'name' => LogService::FRAGMENT_SYNTH_MATERIAL,
];
LogService::ConsumableMaterial($event,$params);
}
// $this->_decItems($costItems);
$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);
}
//生成英雄
Hero::addHero($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addFragment();
$propertyChgService->addBagChg();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
@ -245,146 +222,84 @@ class FragmentController extends BaseAuthedController
break;
case 2:
{
if ($unique_id_special){
$meta = mt\Parameter::getByName('jigsaw_merge_w_price');
$mint = $meta ? $meta['param_value'] : 30;
if ($param){
//指定合成枪械
$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');
if ($itemMeta['type'] != \mt\Item::GUN_TYPE){
$this->_rspErr(1,'item_id param error (type)');
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->_verificationFragment($param,\mt\Item::FRAGMENT_TYPE,\mt\Item::GUN_FRAGMENT_SUBTYPE_PRO);
$decItems = array();
array_push($decItems,$param);
foreach ($paramArr as $val){
$this->_verificationFragment($val,\mt\Item::FRAGMENT_TYPE,\mt\Item::GUN_FRAGMENT_SUBTYPE);
array_push($decItems,$val);
}
// $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);
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $mint
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
//销毁碎片
foreach ($decItems as $item){
Bag::decItem($item,1);
}
$this->_decItems($costItems);
//生成武器
Gun::addGun($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addFragment();
$propertyChgService->addBagChg();
$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']);
$decItems = array();
foreach ($paramArr as $val){
$this->_verificationFragment($val,\mt\Item::FRAGMENT_TYPE,\mt\Item::GUN_FRAGMENT_SUBTYPE);
array_push($decItems,$val);
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $mint
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
// $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]);
foreach ($decItems as $item){
Bag::decItem($item,1);
}
{
//埋点
$event = [
'name' => LogService::FRAGMENT_SYNTH_MATERIAL,
];
LogService::ConsumableMaterial($event,$params);
}
// $this->_decItems($costItems);
$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);
}
//生成枪械
Gun::addGun($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addFragment();
$propertyChgService->addBagChg();
$propertyChgService->addGunChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),

View File

@ -104,10 +104,14 @@ class Item {
const WEEKLY_BUY_LIMIT = 2;
const TOTAL_BUY_LIMIT = 3;
const ROLE_CHIP_SUBTYPE = 1;
const GUN_CHIP_SUBTYPE = 2;
const HERO_FRAGMENT_SUBTYPE = 1;
const HERO_FRAGMENT_SUBTYPE_PRO = 3;
const GUN_FRAGMENT_SUBTYPE = 2;
const GUN_FRAGMENT_SUBTYPE_PRO = 4;
public static function get($id)
{