323 lines
12 KiB
PHP
323 lines
12 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('mt/RookieTask.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 upgradeAttrChange(){
|
|
$chipUniId = getReqVal('chip_uniid', 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;
|
|
}
|
|
$randMetas = mt\BattleRandAttribute::getByInvoke($chipAttrMeta['battleAttribute'],$chipDb['quality'] + 1);
|
|
$attrList = array();
|
|
foreach ($randMetas as $meta){
|
|
$strs = explode('|', $meta['attributeRange']);
|
|
foreach ($strs as $str) {
|
|
$attrStr = explode(':', $str);
|
|
if (isset($attrList[$attrStr[0]])){
|
|
if ( $attrList[$attrStr[0]][0] > $attrStr[1]){
|
|
$attrList[$attrStr[0]][0] = $attrStr[1];
|
|
}
|
|
if ($attrList[$attrStr[0]][1] < $attrStr[2]){
|
|
$attrList[$attrStr[0]][1] = $attrStr[2];
|
|
}
|
|
}else{
|
|
$attrList[$attrStr[0]] = array($attrStr[1],$attrStr[2]);
|
|
}
|
|
}
|
|
}
|
|
$data = array();
|
|
foreach ($attrList as $key => $value){
|
|
array_push($data,array(
|
|
'attr_id' => $key,
|
|
'min_val' => $value[0],
|
|
'max_val' => $value[1],
|
|
));
|
|
}
|
|
$this->_rspData(array(
|
|
'data' => $data,
|
|
));
|
|
}
|
|
|
|
public function upgradeQualityS(){
|
|
myself()->_verifySwitch('chipUp');
|
|
$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'] || $consumeChipDb['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;
|
|
}
|
|
|
|
//消耗材料
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$costItems = array();
|
|
if ($manufactureMeta['gold']){
|
|
array_push($costItems, array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $manufactureMeta['gold'],
|
|
));
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
$propertyChgService->addUserChg();
|
|
}
|
|
foreach ($consumeUniIdArr as $uniid){
|
|
$consumeChipDb = Chip::find($uniid);
|
|
array_push($costItems, $consumeChipDb);
|
|
Chip::update2($uniid,array(
|
|
'account_id' => myself()->_getAccountId() . '!!!',
|
|
'modifytime' => myself()->_getNowTime(),
|
|
));
|
|
}
|
|
// $this->_incPeriodV(TN_HASH_RATE_UP_CHIP_TIMES, 0, 1);
|
|
myself()->_fireEvent('Upgrade','onChipUpgrade');
|
|
$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_items' => $costItems,
|
|
'chance' => $weight,
|
|
'result' => $status,
|
|
'outcome_chip' =>$chipDb,
|
|
);
|
|
\services\LogService::burialPointEvent($event);
|
|
$this->_rspData(array(
|
|
'status' => $status,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function synChipS(){
|
|
myself()->_verifySwitch('chipPieceSyn');
|
|
$itemId = getReqVal('item_id',0);
|
|
$itemNum = getReqVal('item_num',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;
|
|
}
|
|
if ($itemNum < $needItemNum){
|
|
$this->_rspErr(1, "item number enough ");
|
|
return;
|
|
}
|
|
$number = floor($itemNum / $needItemNum);
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => $needItemNum * $number
|
|
),
|
|
);
|
|
$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','');
|
|
$outcome_chip = array();
|
|
for ($i=0;$i<$number;$i++){
|
|
$items = \services\LootService::dropOutItem($synLoot);
|
|
array_push($outcome_chip,$items[0]);
|
|
$this->_addItems($items,$awardService,$propertyChgService);
|
|
}
|
|
$propertyChgService->addChip();
|
|
// $this->_incPeriodV(TN_HASH_RATE_SYN_CHIP_TIMES, 0, $number);
|
|
myself()->_fireEvent('Synthesis','onChipSyn',$number);
|
|
$event = array(
|
|
'ID' => 'chip',
|
|
'SUB_ID' => 'synthesis',
|
|
'SUB_KEY' => 'chip_synthesis',
|
|
'cost_item' => $costItems,
|
|
'outcome_chip' => $outcome_chip,
|
|
);
|
|
\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);
|
|
}
|
|
myself()->_callModelStatic('RookieTask','incTaskVal',\mt\RookieTask::SALVAGE_CHIP_TIMES_COND,count($uniidArr));
|
|
$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(),
|
|
));
|
|
}
|
|
|
|
|
|
|
|
}
|