game2006api/webapp/controller/FragmentController.class.php
hujiabin fdaf16e172 2
2023-04-07 15:16:27 +08:00

370 lines
15 KiB
PHP

<?php
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;
class FragmentController extends BaseAuthedController
{
private $hero_count = 9;
private $gun_count = 9;
public function fragmentList()
{
$fragmentList = array();
foreach (Fragment::getFragmentList() as $val){
array_push($fragmentList,Fragment::ToDto($val));
}
$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']);
}
$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']);
}
$meta = mt\Parameter::getByName('jigsaw_merge_w_price');
$mint = $meta ? $meta['param_value'] : 20;
$this->_rspData(array(
'list' => $gun,
'mint' => $mint
));
}
break;
default:
{
$this->_rspErr(1, 'type parameter error');
return;
}
}
}
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(){
$type = getReqVal('type', 0);
$params = getReqVal('params','');
$param = getReqVal('param','');
$item_id = getReqVal('item_id','');
$paramArr = explode('|',$params);
if (count($paramArr) != 8){
$this->_rspErr(1,'Insufficient number of parameters');
return ;
}
switch ($type) {
case 1:
{
$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 ' . $item_id);
return ;
}
if ($itemMeta['type'] != \mt\Item::HERO_TYPE){
$this->_rspErr(1,'item_id param error (type)' . $item_id);
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;
}
//销毁碎片
foreach ($decItems as $item){
Bag::decItem($item,1);
}
$this->_decItems($costItems);
//生成英雄
Hero::addHero($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addBagChg();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'item_id' => $itemMeta['id']
));
}else{
//随机合成英雄
$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;
}
//销毁碎片
foreach ($decItems as $item){
Bag::decItem($item,1);
}
$this->_decItems($costItems);
$itemMetaList = mt\Item::getMetaListByType(mt\Item::HERO_TYPE);
$key = rand(0,count($itemMetaList)-1);
$itemMeta = $itemMetaList[$key];
//生成英雄
Hero::addHero($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addBagChg();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'item_id' => $itemMeta['id']
));
}
}
break;
case 2:
{
$meta = mt\Parameter::getByName('jigsaw_merge_w_price');
$mint = $meta ? $meta['param_value'] : 20;
if ($param){
//指定合成枪械
$itemMeta = mt\Item::get($item_id);
if (!$itemMeta){
$this->_rspErr(1,'item_id param error '. $item_id);
return ;
}
if ($itemMeta['type'] != \mt\Item::GUN_TYPE){
$this->_rspErr(1,'item_id param error (type) ' . $item_id);
return ;
}
$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);
}
$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->addBagChg();
$propertyChgService->addGunChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'item_id' => $itemMeta['id']
));
}else{
//随机合成枪械
$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;
}
//销毁碎片
foreach ($decItems as $item){
Bag::decItem($item,1);
}
$this->_decItems($costItems);
$itemMetaList = mt\Item::getMetaListByType(mt\Item::GUN_TYPE);
$key = rand(0,count($itemMetaList)-1);
$itemMeta = $itemMetaList[$key];
//生成枪械
Gun::addGun($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addBagChg();
$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,
'rand_attr' => $baseAttr,
'lucky' => strval($heroLucky),
'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,
'labour'=>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,
'rand_attr' => $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,
'labour'=>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;
}