134 lines
4.2 KiB
PHP
134 lines
4.2 KiB
PHP
<?php
|
|
|
|
require_once('models/Chip.php');
|
|
|
|
require_once('mt/QualityUpMapRule.php');
|
|
require_once('mt/ChipAttribute.php');
|
|
require_once('mt/EconomyAttribute.php');
|
|
require_once('mt/Manufacture.php');
|
|
|
|
require_once('services/PropertyChgService.php');
|
|
|
|
|
|
use models\Chip;
|
|
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 mallChipInfo(){
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
if (! $unique_id){
|
|
$this->_rspErr(1, 'Please enter parameter unique_id');
|
|
return ;
|
|
}
|
|
$chipDb = Chip::findEx($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 upgradeQuality(){
|
|
return ;
|
|
$chipUniId = getReqVal('chip_uniid', 0);
|
|
$itemId = getReqVal('item_id',0);
|
|
$itemNum = getReqVal('item_num',0);
|
|
if ($itemNum < 1){
|
|
$this->_rspErr(1, "item_num not enough");
|
|
return;
|
|
}
|
|
$chipDb = Chip::find($chipUniId);
|
|
if (!$chipDb) {
|
|
$this->_rspErr(100, 'param hero_uniid error ');
|
|
return;
|
|
}
|
|
if ($chipDb['quality'] == \mt\QualityUpMapRule::MAX_QUALITY){
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
return;
|
|
}
|
|
$heroQualityMeta = \mt\QualityUpMapRule::getByQuality($chipDb['item_id'],$chipDb['quality']+1);
|
|
if (!$heroQualityMeta || $heroQualityMeta['needItem'] != $itemId){
|
|
$this->_rspErr(100, 'param item_id error ');
|
|
return;
|
|
}
|
|
$manufactureMeta = \mt\Manufacture::findChipAction(\mt\Manufacture::UP_ACTION,$chipDb['quality']+1);
|
|
if (!$manufactureMeta){
|
|
$this->_rspErr(1, "Error operation");
|
|
return;
|
|
}
|
|
$itemNum = min($itemNum,$manufactureMeta['numTop']);
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $manufactureMeta['gold']
|
|
),
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => $itemNum
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
//消耗材料
|
|
$this->_decItems($costItems);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addBagChg();
|
|
$hashChance = \mt\Manufacture::hashChance($manufactureMeta['chance']);
|
|
$weight = isset($hashChance[$itemNum]) ? $hashChance[$itemNum] : 0;
|
|
$rnd = rand(1,100);
|
|
$status = 0;
|
|
if ($rnd <= $weight*100){
|
|
$status = 1;
|
|
$chipAttrMeta = \mt\ChipAttribute::get($chipDb['item_id']);
|
|
$attribute = \mt\EconomyAttribute::getAttribute($chipAttrMeta['economyAttribute'],$chipDb['quality'] + 1);
|
|
Chip::update2($chipUniId, array(
|
|
'quality' => $chipDb['quality'] + 1,
|
|
'wealth_attr' => json_encode($attribute),
|
|
));
|
|
$propertyChgService->addHeroChg();
|
|
}
|
|
$this->_rspData(array(
|
|
'status' => $status,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
}
|