199 lines
6.4 KiB
PHP
199 lines
6.4 KiB
PHP
<?php
|
|
|
|
require_once('models/Chip.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/Gun.php');
|
|
require_once('models/User.php');
|
|
|
|
require_once('mt/ChipAttr.php');
|
|
|
|
require_once('services/FormulaService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/LogService.php');
|
|
|
|
|
|
|
|
|
|
|
|
use models\Chip;
|
|
use models\Hero;
|
|
use models\Gun;
|
|
use models\User;
|
|
use services\FormulaService;
|
|
use services\LogService;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class ChipController extends BaseAuthedController
|
|
{
|
|
public function chipList()
|
|
{
|
|
$chipList = array();
|
|
Chip::getChipList(function ($row) use(&$chipList){
|
|
if ($row['inlay_state'] != 1){
|
|
array_push($chipList, Chip::toDto($row));
|
|
}
|
|
});
|
|
$this->_rspData(array(
|
|
'data' => $chipList,
|
|
));
|
|
}
|
|
|
|
public function chipDetails(){
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
if (! $unique_id){
|
|
$this->_rspErr(1, 'Please enter parameter unique_id');
|
|
return ;
|
|
}
|
|
$chipDb = Chip::find($unique_id);
|
|
if (! $chipDb){
|
|
$this->_rspErr(1, "You don't have the chip yet");
|
|
return;
|
|
}
|
|
$chip = Chip::toDto($chipDb);
|
|
$this->_rspData(array(
|
|
'data' => $chip,
|
|
));
|
|
}
|
|
|
|
public function upgradeLevelPreview(){
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
if (! $unique_id) {
|
|
$this->_rspErr(1, 'Please enter parameter unique_id');
|
|
return;
|
|
}
|
|
$chipDb = Chip::find($unique_id);
|
|
if (!$chipDb){
|
|
$this->_rspErr(1,'unique_id parameter error');
|
|
return;
|
|
}
|
|
if ($chipDb['chip_grade'] == Chip::CHIP_LV_MAX){
|
|
$this->_rspErr(1,' Level upper limit');
|
|
return;
|
|
}
|
|
$chip = Chip::toDto($chipDb);
|
|
$rand_attr = emptyReplace(json_decode($chipDb['rand_attr'], true), array());
|
|
$chipMeta = mt\ChipAttr::getAttrByItemId($chipDb['item_id']);
|
|
if ($chipMeta){
|
|
array_push($rand_attr,array(
|
|
'attr_id'=>$chipMeta['attr_id'],
|
|
'val' => $chipMeta['lv'.($chipDb['chip_grade']+1)]
|
|
));
|
|
}
|
|
$chip['rand_attr_after'] = $rand_attr;
|
|
$chip['upgrade_cost']=\services\FormulaService::getChipUpgradeCost($chip['chip_grade']+1);
|
|
$this->_rspData(['data'=>$chip]);
|
|
}
|
|
|
|
public function selectChip(){
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
$idxArr = explode(' ',$unique_id);
|
|
if (count($idxArr)<0){
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$chipDbMain = Chip::find($idxArr[0]);
|
|
$chipDbParam = Chip::find($idxArr[1]);
|
|
if (!$chipDbMain || !$chipDbParam){
|
|
$this->_rspErr(1,'unique_id parameter error');
|
|
return;
|
|
}
|
|
if ($chipDbParam['token_id']) {
|
|
$this->_rspErr(1, "Unable to use nft chip");
|
|
return;
|
|
}
|
|
if (!$chipDbParam['state']) {
|
|
$this->_rspErr(1, "Unable to use free chip");
|
|
return;
|
|
}
|
|
if ($chipDbParam['chip_grade']>$chipDbMain['chip_grade']){
|
|
$this->_rspErr(1, "The selected material is too high grade");
|
|
return;
|
|
}
|
|
$cost = \services\FormulaService::getChipCumulativeCost($chipDbParam['chip_grade']);
|
|
$this->_rspData(['cost'=>$cost]);
|
|
}
|
|
|
|
public function upgradeLevel(){
|
|
$idxMain = trim(getReqVal('unique_id_main', 0));
|
|
$idxParam = array_filter(explode(' ',getReqVal('unique_id_param', 0)));
|
|
if (! $idxMain || count($idxParam)<=0 ) {
|
|
$this->_rspErr(1, 'Please enter parameter');
|
|
return;
|
|
}
|
|
$chipDbMain = Chip::find($idxMain);
|
|
if (!$chipDbMain){
|
|
$this->_rspErr(1,'unique_id_main parameter error');
|
|
return;
|
|
}
|
|
if ($chipDbMain['chip_grade'] == Chip::CHIP_LV_MAX){
|
|
$this->_rspErr(1,' Level upper limit');
|
|
return;
|
|
}
|
|
$upgrade_cost = \services\FormulaService::getChipUpgradeCost($chipDbMain['chip_grade']+1);
|
|
if ( $upgrade_cost == 0 ){
|
|
$this->_rspErr(1, 'Error in calculation formula');
|
|
return;
|
|
}
|
|
$cumulative_cost = 0;
|
|
|
|
foreach ($idxParam as $val){
|
|
$chipDbParam = Chip::find($val);
|
|
if (!$chipDbParam){
|
|
$this->_rspErr(1,"unique_id_param:{$val} parameter error");
|
|
return;
|
|
}
|
|
if ($chipDbParam['token_id']) {
|
|
$this->_rspErr(1, "Unable to use nft chip");
|
|
return;
|
|
}
|
|
if ($chipDbParam['state'] == Chip::FREE_STATE) {
|
|
$this->_rspErr(1, "Unable to use free chip");
|
|
return;
|
|
}
|
|
if ($chipDbParam['chip_grade']>$chipDbMain['chip_grade']){
|
|
$this->_rspErr(1, "The selected material is too high grade");
|
|
return;
|
|
}
|
|
$cumulative_cost += \services\FormulaService::getChipCumulativeCost($chipDbParam['chip_grade']);
|
|
}
|
|
//清除材料芯片
|
|
foreach ($idxParam as $idx){
|
|
Chip::update2($idx,
|
|
array(
|
|
'account_id' => myself()->_getAccountId() . '!!!',
|
|
)
|
|
);
|
|
}
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addChip();
|
|
if (round(1,100) > ($cumulative_cost/$upgrade_cost)*100){
|
|
//合成失败
|
|
$this->_rspData([
|
|
'state' => 0,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
]);
|
|
return ;
|
|
}
|
|
|
|
$rand_attr = emptyReplace(json_decode($chipDbMain['rand_attr'], true), array());
|
|
$attrProMeta = \mt\ChipAttr::getAttrPool($chipDbMain);
|
|
array_push($rand_attr,array(
|
|
'attr_id'=>$attrProMeta['attr_id'],
|
|
'val'=>$attrProMeta['val'],
|
|
));
|
|
Chip::update2($idxMain,
|
|
array(
|
|
'chip_grade' => $chipDbMain['chip_grade']+1,
|
|
'state' => Chip::GETED_STATE,
|
|
'rand_attr' => json_encode($rand_attr),
|
|
)
|
|
);
|
|
$chipDbNew = Chip::toDto(Chip::find($idxMain));
|
|
$this->_rspData([
|
|
'data'=>$chipDbNew,
|
|
'state' => 1,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
]);
|
|
}
|
|
|
|
} |