248 lines
8.5 KiB
PHP
248 lines
8.5 KiB
PHP
<?php
|
|
|
|
require_once('models/Chip.php');
|
|
|
|
|
|
require_once('mt/ChipAttribute.php');
|
|
require_once('mt/BattleRandAttribute.php');
|
|
require_once('mt/EconomyAttribute.php');
|
|
require_once('mt/Manufacture.php');
|
|
require_once('mt/Parameter.php');
|
|
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/AwardService.php');
|
|
require_once('services/LootService.php');
|
|
require_once('services/LogService.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(){
|
|
$chipUniId = getReqVal('chip_uniid', 0);
|
|
$consumeUniIds = getReqVal('consume_uniids',0);
|
|
$chipDb = Chip::find($chipUniId);
|
|
if (!$chipDb) {
|
|
$this->_rspErr(100, 'param chip_uniid error ');
|
|
return;
|
|
}
|
|
if ($chipDb['quality'] == Chip::CHIP_QUALITY_MAX){
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
return;
|
|
}
|
|
$chipAttrMeta = \mt\ChipAttribute::get($chipDb['item_id']);
|
|
if (!$chipAttrMeta){
|
|
$this->_rspErr(100, 'mt error ');
|
|
return;
|
|
}
|
|
$consumeUniIdArr = explode("|",$consumeUniIds);
|
|
foreach ($consumeUniIdArr as $uniid){
|
|
$consumeChipDb = Chip::find($uniid);
|
|
if (!$consumeChipDb || $consumeChipDb['quality'] != $chipDb['quality'] || $chipDb['inlay_state'] == 1) {
|
|
$this->_rspErr(100, 'param consume error ');
|
|
return;
|
|
}
|
|
}
|
|
$manufactureMeta = \mt\Manufacture::getByInvoke($chipAttrMeta['manufacture'],$chipDb['quality']+1);
|
|
if (!$manufactureMeta){
|
|
$this->_rspErr(1, "mt error");
|
|
return;
|
|
}
|
|
if (count($consumeUniIdArr) != $manufactureMeta['needItem']){
|
|
$this->_rspErr(100, ' consume number error ');
|
|
return;
|
|
}
|
|
|
|
//消耗材料
|
|
$costItems = array();
|
|
foreach ($consumeUniIdArr as $uniid){
|
|
$consumeChipDb = Chip::find($uniid);
|
|
array_push($costItems, $consumeChipDb);
|
|
Chip::update2($uniid,array(
|
|
'account_id' => myself()->_getAccountId() . '!!!',
|
|
'modifytime' => myself()->_getNowTime(),
|
|
));
|
|
}
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addChip();
|
|
$hashChance = \mt\Manufacture::hashChance($manufactureMeta['chance']);
|
|
$weight = $hashChance[0];
|
|
$rnd = rand(1,100);
|
|
$status = 0;
|
|
if ($rnd <= $weight*100){
|
|
$status = 1;
|
|
$attr = emptyReplace(json_decode($chipDb['rand_attr'], true), array());
|
|
$attribute = \mt\EconomyAttribute::getAttribute($chipAttrMeta['economyAttribute'],$chipDb['quality'] + 1);
|
|
$randMeta = mt\BattleRandAttribute::getByWeight($chipAttrMeta['battleAttribute'],$chipDb['quality'] + 1);
|
|
$randAttr = mt\BattleRandAttribute::getRandAttr($randMeta);
|
|
$newAttr = mt\BattleRandAttribute::mergeAttr($attr,$randAttr);
|
|
Chip::update2($chipUniId, array(
|
|
'quality' => $chipDb['quality'] + 1,
|
|
'rand_attr' => json_encode($newAttr),
|
|
'wealth_attr' => json_encode($attribute),
|
|
'modifytime' => myself()->_getNowTime()
|
|
));
|
|
$chipDb['quality'] += 1;
|
|
$chipDb['rand_attr'] = $newAttr;
|
|
$chipDb['wealth_attr'] = $attribute;
|
|
}
|
|
$event = array(
|
|
'ID' => 'chip',
|
|
'SUB_ID' => 'advanced',
|
|
'SUB_KEY' => 'chip_advanced',
|
|
'cost_chip' => $costItems,
|
|
'chance' => $weight,
|
|
'result' => $status,
|
|
'outcome_chip' =>$chipDb,
|
|
);
|
|
\services\LogService::burialPointEvent($event);
|
|
$this->_rspData(array(
|
|
'status' => $status,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function synChip(){
|
|
$itemId = getReqVal('item_id',0);
|
|
$needItem = \mt\Parameter::getVal('chip_craft_need_item',0);
|
|
$needItemNum = \mt\Parameter::getVal('chip_craft_need_item_number',50);
|
|
if ($itemId != $needItem){
|
|
$this->_rspErr(1, "item_id error");
|
|
return;
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => $needItemNum
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
// 消耗材料
|
|
$this->_decItems($costItems);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
$propertyChgService->addBagChg();
|
|
|
|
$synLoot = \mt\Parameter::getVal('chip_craft_product_loot','');
|
|
$items = \services\LootService::dropOutItem($synLoot);
|
|
$this->_addItems($items,$awardService,$propertyChgService);
|
|
$propertyChgService->addChip();
|
|
$event = array(
|
|
'ID' => 'chip',
|
|
'SUB_ID' => 'synthesis',
|
|
'SUB_KEY' => 'chip_synthesis',
|
|
'cost_item' => array(
|
|
'item_id' => $itemId,
|
|
'item_num' => $needItemNum
|
|
),
|
|
'outcome_chip' => $items[0],
|
|
);
|
|
\services\LogService::burialPointEvent($event);
|
|
$this->_rspData(array(
|
|
'award' => $awardService->toDto(),
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
|
|
}
|
|
|
|
public function resolveChip(){
|
|
$chip_uniids = getReqVal('chip_uniids',0);
|
|
$uniidArr = explode('|',$chip_uniids);
|
|
foreach ($uniidArr as $uniid){
|
|
$chipDb = Chip::find($uniid);
|
|
if (!$chipDb || $chipDb['inlay_state'] == 1){
|
|
$this->_rspErr(1, "the chip don't operation");
|
|
return;
|
|
}
|
|
}
|
|
$decLoot = \mt\Parameter::getVal('chip_craft_decompose_loot',0);
|
|
$lootArr = explode("|",$decLoot);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
$cost_item = array();
|
|
$outcome_item = array();
|
|
foreach ($uniidArr as $uniid){
|
|
$chipDb = Chip::find($uniid);
|
|
array_push($cost_item,$chipDb['item_id']);
|
|
$lootId = $lootArr[$chipDb['quality'] - 1 ];
|
|
$items = \services\LootService::dropOutItem($lootId);
|
|
array_push($outcome_item,$items[0]);
|
|
Chip::update2($uniid,array(
|
|
'account_id' => myself()->_getAccountId() . '!!!',
|
|
'modifytime' => myself()->_getNowTime(),
|
|
));
|
|
$this->_addItems($items,$awardService,$propertyChgService);
|
|
}
|
|
$propertyChgService->addChip();
|
|
$propertyChgService->addBagChg();
|
|
$event = array(
|
|
'ID' => 'chip',
|
|
'SUB_ID' => 'resolve',
|
|
'SUB_KEY' => 'chip_resolve',
|
|
'cost_item' => $cost_item,
|
|
'outcome_item' => $outcome_item,
|
|
);
|
|
\services\LogService::burialPointEvent($event);
|
|
$this->_rspData(array(
|
|
'award' => $awardService->toDto(),
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
|
|
|
|
}
|