224 lines
6.9 KiB
PHP
224 lines
6.9 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;
|
|
$paramMeta = mt\Parameter::getByName('chip_upgrade_cost');
|
|
$gold = 0;
|
|
if ($paramMeta){
|
|
$paramValue = explode('|',$paramMeta['param_value']);
|
|
switch ($chipDb['chip_grade']){
|
|
case 1: {
|
|
$gold = $paramValue[0];
|
|
};break;
|
|
case 2: {
|
|
$gold = $paramValue[1];
|
|
};break;
|
|
}
|
|
}
|
|
$chip['cost'] = array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $gold
|
|
);
|
|
$this->_rspData(array(
|
|
'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 = trim(getReqVal('unique_id_param', 0));
|
|
if (!$idxMain || !$idxParam) {
|
|
$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;
|
|
}
|
|
$chipDbParam = Chip::find($idxParam);
|
|
if (!$chipDbParam){
|
|
$this->_rspErr(1,"unique_id_param 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 (count(array_filter(explode("|",$chipDbParam['inlay_state']))) > 0){
|
|
$this->_rspErr(1, "The used chip");
|
|
return;
|
|
}
|
|
if ($chipDbParam['chip_grade'] != $chipDbMain['chip_grade']){
|
|
$this->_rspErr(1, "Material chip grade does not meet");
|
|
return;
|
|
}
|
|
$paramMeta = mt\Parameter::getByName('chip_upgrade_cost');
|
|
$gold = 0;
|
|
if ($paramMeta){
|
|
$paramValue = explode('|',$paramMeta['param_value']);
|
|
switch ($chipDbMain['chip_grade']){
|
|
case 1: {
|
|
$gold = $paramValue[0];
|
|
};break;
|
|
case 2: {
|
|
$gold = $paramValue[1];
|
|
};break;
|
|
}
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $gold
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
|
|
$this->_decItems($costItems);
|
|
Chip::update2($idxParam,
|
|
array(
|
|
'account_id' => myself()->_getAccountId() . '!!!',
|
|
)
|
|
);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addChip();
|
|
$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,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
]);
|
|
}
|
|
|
|
} |