242 lines
8.1 KiB
PHP
242 lines
8.1 KiB
PHP
<?php
|
|
|
|
require_once('models/Chip.php');
|
|
require_once('models/ChipPage.php');
|
|
require_once('models/Hero.php');
|
|
require_once('mt/EconomyAttribute.php');
|
|
require_once('mt/RookieTask.php');
|
|
require_once('services/ChipPageService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
|
|
use models\Chip;
|
|
use models\ChipPage;
|
|
use models\Hero;
|
|
use mt\EconomyAttribute;
|
|
use services\ChipPageService;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class ChipPageController extends BaseAuthedController
|
|
{
|
|
|
|
public function showChipPage(){
|
|
$heroUid = getReqVal('hero_unnid',0);
|
|
$heroDb = Hero::find($heroUid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1,'param error');
|
|
return ;
|
|
}
|
|
$chipPageDb = ChipPage::find($heroUid);
|
|
if (!$chipPageDb){
|
|
ChipPage::addChipPage($heroUid);
|
|
$chipPageDb = ChipPage::find($heroUid);
|
|
}
|
|
$chipPageDto = ChipPage::toDtoInfo($chipPageDb);
|
|
$this->_rspData(array(
|
|
'data' => $chipPageDto,
|
|
));
|
|
}
|
|
|
|
public function unlockSlot(){
|
|
myself()->_verifySwitch('openChipSlot');
|
|
$heroUid = getReqVal('hero_unnid',0);
|
|
$slotId = getReqVal('slot_id',0);
|
|
if ($slotId < 1 || $slotId > ChipPage::MAX_CHIP_SLOT_NUM){
|
|
$this->_rspErr(1,'param slot_id error');
|
|
return ;
|
|
}
|
|
$heroDb = Hero::find($heroUid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1,'param error');
|
|
return ;
|
|
}
|
|
$heroMeta = \mt\Hero::get($heroDb['hero_id']);
|
|
$economyAttrMeta = EconomyAttribute::findByGrade($heroMeta['economyAttribute'],$heroDb['quality']);
|
|
if (!$economyAttrMeta){
|
|
$this->_rspErr(1,'mt error');
|
|
return ;
|
|
}
|
|
$chipSlot = explode("|",$economyAttrMeta['chipSlot']);
|
|
$chipPageDb = ChipPage::find($heroUid);
|
|
$pageHashData = ChipPage::dataToHash($chipPageDb);
|
|
$slotInfo = $pageHashData[$slotId];
|
|
if ($slotInfo['state'] == 1){
|
|
$this->_rspErr(1,'The slot has been unlocked');
|
|
return ;
|
|
}
|
|
$unlockCount = ChipPage::getUnlockCount($chipPageDb,$slotInfo['slot_type']);
|
|
if ($chipSlot[$slotInfo['slot_type']-1] <= $unlockCount){
|
|
$this->_rspErr(1,'The unlock condition was not met');
|
|
return ;
|
|
}
|
|
$totalUnlockCount = ChipPage::getUnlockCount($chipPageDb);
|
|
$priceArr = explode('|',\mt\Parameter::getVal('hero_solt_unlock_price',0));
|
|
if (! isset($priceArr[$totalUnlockCount])){
|
|
$this->_rspErr(1,'mt No price found');
|
|
return ;
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $priceArr[$totalUnlockCount]
|
|
)
|
|
);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
$propertyChgService->addUserChg();
|
|
ChipPage::unlockSlot($chipPageDb,$slotId);
|
|
myself()->_callModelStatic('RookieTask','incTaskVal',\mt\RookieTask::OPEN_CHIP_SLOT_TIMES_COND,1);
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function useChip(){
|
|
$hero_unnid = getReqVal('hero_unnid',0);
|
|
$slotId = getReqVal('slot_id',0);
|
|
$chip_unnid = getReqVal('chip_unnid',0);
|
|
if (!$hero_unnid || !$slotId || !$chip_unnid){
|
|
$this->_rspErr(1, 'Missing parameter');
|
|
return ;
|
|
}
|
|
$heroDb = Hero::find($hero_unnid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1,'param error');
|
|
return ;
|
|
}
|
|
$chipPageDb = ChipPage::find($hero_unnid);
|
|
if (!$chipPageDb){
|
|
$this->_rspErr(1,'page parameter error');
|
|
return ;
|
|
}
|
|
if ($slotId > ChipPage::MAX_CHIP_SLOT_NUM || $slotId < 0 ){
|
|
$this->_rspErr(1,'No card slot exists');
|
|
return ;
|
|
}
|
|
$data = emptyReplace(json_decode($chipPageDb['data'], true), array());
|
|
$pageHashData = ChipPage::dataToHash($chipPageDb);
|
|
$slotInfo = $pageHashData[$slotId];
|
|
if ( $slotInfo['state'] != 1){
|
|
$this->_rspErr(1,'Unlocked state');
|
|
return ;
|
|
}
|
|
$chipDb = Chip::find($chip_unnid);
|
|
if (! $chipDb){
|
|
$this->_rspErr(1, "You don't have the chip yet");
|
|
return;
|
|
}
|
|
|
|
if ($chipDb['inlay_state'] == 1){
|
|
$this->_rspErr(1, "The used chip");
|
|
return;
|
|
}
|
|
if ($chipDb['chip_type'] != $slotInfo['slot_type']){
|
|
$this->_rspErr(1, "Type mismatch");
|
|
return;
|
|
}
|
|
if ( $slotInfo['chip_id'] ){
|
|
Chip::updateInlayState($slotInfo['chip_id'],0);
|
|
}
|
|
$data[$slotId-1]['chip_id'] = $chip_unnid;
|
|
Chip::updateInlayState($chip_unnid,1);
|
|
ChipPage::update($hero_unnid,array(
|
|
'data' => json_encode($data)
|
|
));
|
|
myself()->_callModelStatic('RookieTask','incTaskVal',\mt\RookieTask::EMBED_CHIP_COND,1);
|
|
$newChipPageDb = ChipPage::find($hero_unnid);
|
|
$chipPageDto = ChipPage::toDtoInfo($newChipPageDb);
|
|
$this->_rspData(array(
|
|
'data' => $chipPageDto,
|
|
));
|
|
}
|
|
|
|
public function removeChip(){
|
|
$hero_unnid = getReqVal('hero_unnid',0);
|
|
$slotId = getReqVal('slot_id',0);
|
|
if (!$hero_unnid || !$slotId){
|
|
$this->_rspErr(1, 'Missing parameter');
|
|
return ;
|
|
}
|
|
$heroDb = Hero::find($hero_unnid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1,'param error');
|
|
return ;
|
|
}
|
|
$chipPageDb = ChipPage::find($hero_unnid);
|
|
if (!$chipPageDb){
|
|
$this->_rspErr(1,'page parameter error');
|
|
return ;
|
|
}
|
|
$price = \mt\Parameter::getVal('hero_chip_remove_price',0);
|
|
if ($price == 0){
|
|
$this->_rspErr(1,'mt price error');
|
|
return ;
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $price
|
|
)
|
|
);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
$propertyChgService->addUserChg();
|
|
$data = emptyReplace(json_decode($chipPageDb['data'], true), array());
|
|
foreach ($data as &$value){
|
|
if ($value['slot_id'] == $slotId){
|
|
Chip::updateInlayState($value['chip_id'],0);
|
|
$value['chip_id'] = 0;
|
|
}
|
|
}
|
|
ChipPage::update($hero_unnid,array(
|
|
'data' => json_encode($data)
|
|
));
|
|
$newChipPageDb = ChipPage::find($hero_unnid);
|
|
$chipPageDto = ChipPage::toDtoInfo($newChipPageDb);
|
|
$this->_rspData(array(
|
|
'data' => $chipPageDto,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function removeChipAll(){
|
|
return
|
|
$hero_unnid = getReqVal('hero_unnid',0);
|
|
$heroDb = Hero::find($hero_unnid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1,'param error');
|
|
return ;
|
|
}
|
|
$chipPageDb = ChipPage::find($hero_unnid);
|
|
if (!$chipPageDb){
|
|
$this->_rspErr(1,'page parameter error');
|
|
return ;
|
|
}
|
|
$data = emptyReplace(json_decode($chipPageDb['data'], true), array());
|
|
foreach ($data as &$value){
|
|
if ($value['chip_id']){
|
|
Chip::updateInlayState($value['chip_id'],0);
|
|
$value['chip_id'] = 0;
|
|
}
|
|
}
|
|
ChipPage::update($hero_unnid,array(
|
|
'data' => json_encode($data)
|
|
));
|
|
$newChipPageDb = ChipPage::find($hero_unnid);
|
|
$chipPageDto = ChipPage::toDtoInfo($newChipPageDb);
|
|
$this->_rspData(array(
|
|
'data' => $chipPageDto,
|
|
));
|
|
}
|
|
|
|
|
|
} |