162 lines
5.1 KiB
PHP
162 lines
5.1 KiB
PHP
<?php
|
|
require_once('mt/Item.php');
|
|
require_once('mt/DressAttribute.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/HeroSkin.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/LogService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Hero;
|
|
use models\HeroSkin;
|
|
use services\LogService;
|
|
|
|
class HeroSkinController extends BaseAuthedController {
|
|
|
|
public function skinList()
|
|
{
|
|
$skinId = trim(getReqVal('skin_id', 0));
|
|
$itemMeta = \mt\Item::get($skinId);
|
|
if ($itemMeta['type'] != \mt\Item::HERO_SKIN_TYPE){
|
|
$this->_rspErr(1, 'skin_id error');
|
|
return;
|
|
}
|
|
$skinList = array();
|
|
HeroSkin::getSkinList($skinId,function ($row) use(&$skinList) {
|
|
array_push($skinList, $row);
|
|
});
|
|
$this->_rspData(array(
|
|
'skin_list' => $skinList
|
|
));
|
|
}
|
|
|
|
public function skinDetails()
|
|
{
|
|
$skinUniid = trim(getReqVal('skin_uniid', 0));
|
|
if ( ! $skinUniid) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$heroSkinDb = HeroSkin::find($skinUniid);
|
|
if (! $heroSkinDb){
|
|
$this->_rspErr(1, "You don't have the hero yet");
|
|
return;
|
|
}
|
|
$skin = HeroSkin::toDto($heroSkinDb);
|
|
$this->_rspData(array(
|
|
'data' => $skin
|
|
));
|
|
}
|
|
|
|
public function takeonSkin()
|
|
{
|
|
$heroUniid = getReqVal('hero_uniid', 0);
|
|
$skinUniid = getReqVal('skin_uniid', 0);
|
|
$heroDb = Hero::find($heroUniid);
|
|
$heroSkinDb = HeroSkin::find($skinUniid);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(1, "You don't have the hero yet");
|
|
return;
|
|
}
|
|
if (!$heroSkinDb) {
|
|
$this->_rspErr(1, "You don't have the hero skin yet");
|
|
return;
|
|
}
|
|
if ($heroDb['skin_id']){
|
|
HeroSkin::update($heroDb['skin_id'],array(
|
|
'used'=>HeroSkin::NO_USE,
|
|
'hero_uniid'=>0,
|
|
'modifytime'=>myself()->_getNowTime(),
|
|
));
|
|
}
|
|
if ($heroSkinDb['hero_uniid']){
|
|
Hero::update($heroSkinDb['hero_uniid'],array(
|
|
'skin_id' => 0,
|
|
'modifytime'=>myself()->_getNowTime()
|
|
));
|
|
}
|
|
Hero::update($heroUniid,array(
|
|
'skin_id' => $skinUniid,
|
|
'modifytime'=>myself()->_getNowTime()
|
|
));
|
|
HeroSkin::update($skinUniid,array(
|
|
'used'=>HeroSkin::USED,
|
|
'skin_state'=>HeroSkin::NO_LOCK,
|
|
'hero_uniid'=>$heroUniid,
|
|
'modifytime'=>myself()->_getNowTime(),
|
|
));
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function demountSkin(){
|
|
$heroUniid = getReqVal('hero_uniid', 0);
|
|
$heroDb = Hero::find($heroUniid);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(1, "You don't have the hero yet");
|
|
return;
|
|
}
|
|
if (!$heroDb['skin_id']){
|
|
$this->_rspErr(1, "Useless operation");
|
|
return;
|
|
}
|
|
Hero::update($heroUniid,array(
|
|
'skin_id' => 0,
|
|
'modifytime'=>myself()->_getNowTime()
|
|
));
|
|
HeroSkin::update($heroDb['skin_id'],array(
|
|
'used'=>HeroSkin::NO_USE,
|
|
'skin_state'=>HeroSkin::NO_LOCK,
|
|
'hero_uniid'=>0,
|
|
'modifytime'=>myself()->_getNowTime(),
|
|
));
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function synSkin(){
|
|
$skinId = trim(getReqVal('skin_id', 0));
|
|
$itemMeta = \mt\Item::get($skinId);
|
|
if ($itemMeta['type'] != \mt\Item::HERO_SKIN_TYPE){
|
|
$this->_rspErr(1, 'skin_id error');
|
|
return;
|
|
}
|
|
$dressMeta = mt\DressAttribute::get($skinId);
|
|
if (!$dressMeta){
|
|
$this->_rspErr(1, 'skin_id error');
|
|
return;
|
|
}
|
|
$needItem = explode(':',$dressMeta['needItem']);
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => $needItem[0],
|
|
'item_num' => $needItem[1]
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addBagChg();
|
|
HeroSkin::addSkin($itemMeta);
|
|
$lastIdx = SqlHelper::getLastInsertId( myself()->_getSelfMysql());
|
|
$skinDb = HeroSkin::find($lastIdx);
|
|
$propertyChgService->addHeroSkinChg();
|
|
$event = array(
|
|
'ID' => 'heroSkin',
|
|
'SUB_ID' => 'synthesis',
|
|
'SUB_KEY' => 'heroSkin_synthesis',
|
|
'cost_fragment' => $costItems,
|
|
'result' => 1,
|
|
'outcome_skin' => $skinDb,
|
|
);
|
|
LogService::burialPointEvent($event);
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
}
|