250 lines
8.1 KiB
PHP
250 lines
8.1 KiB
PHP
<?php
|
|
require_once('mt/Item.php');
|
|
require_once('mt/Parameter.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 skinAll()
|
|
{
|
|
$skinList = array();
|
|
HeroSkin::allSkinList(function ($row) use(&$skinList) {
|
|
array_push($skinList, HeroSkin::toDto($row));
|
|
});
|
|
$this->_rspData(array(
|
|
'skin_list' => $skinList
|
|
));
|
|
}
|
|
|
|
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 mallSkinDetails()
|
|
{
|
|
$skinUniid = trim(getReqVal('skin_uniid', 0));
|
|
if ( ! $skinUniid) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$heroSkinDb = HeroSkin::findEx($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 takeonSkinS()
|
|
{
|
|
$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;
|
|
}
|
|
$removeNum = 0;
|
|
if ($heroDb['skin_id']){
|
|
$removeNum += 1;
|
|
}
|
|
if ($heroSkinDb['hero_uniid']){
|
|
$removeNum += 1;
|
|
}
|
|
$propertyChgService = new services\PropertyChgService();
|
|
if ($removeNum > 0){
|
|
$goldNum = \mt\Parameter::getVal('hero_dress_remove_price',200);
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $goldNum * $removeNum
|
|
)
|
|
);
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
$propertyChgService->addUserChg();
|
|
}
|
|
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(),
|
|
));
|
|
|
|
$propertyChgService->addHeroChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function demountSkinS(){
|
|
$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;
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => \mt\Parameter::getVal('hero_dress_remove_price',200)
|
|
),
|
|
);
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
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(),
|
|
));
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addHeroChg();
|
|
$propertyChgService->addUserChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function synSkinS(){
|
|
myself()->_verifySwitch('skinSyn');
|
|
$itemId = getReqVal('item_id',0);
|
|
$itemNum = getReqVal('item_num',0);
|
|
$itemMeta = \mt\Item::get($itemId);
|
|
if (!$itemMeta || $itemMeta['type'] != \mt\Item::FRAGMENT_TYPE){
|
|
$this->_rspErr(1, 'param error');
|
|
return;
|
|
}
|
|
$skinId = $itemMeta['relationship'];
|
|
$dressMeta = mt\DressAttribute::get($skinId);
|
|
if (!$dressMeta){
|
|
$this->_rspErr(1, 'skin_id error');
|
|
return;
|
|
}
|
|
$needItem = explode(':',$dressMeta['needItem']);
|
|
if ($itemId !=$needItem[0] || $itemNum < $needItem[1]){
|
|
$this->_rspErr(1, "item number enough ");
|
|
return;
|
|
}
|
|
$number = floor($itemNum / $needItem[1]);
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => $needItem[0],
|
|
'item_num' => $needItem[1] * $number
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addBagChg();
|
|
$skinMeta = \mt\Item::get($skinId);
|
|
for ($i=0; $i<$number; $i++){
|
|
HeroSkin::addSkin($skinMeta);
|
|
}
|
|
$propertyChgService->addHeroSkinChg();
|
|
// $this->_incPeriodV(TN_HASH_RATE_SYN_SKIN_TIMES, 0, $number);
|
|
myself()->_fireEvent('Synthesis','onSkinSyn',$number);
|
|
$event = array(
|
|
'ID' => 'heroSkin',
|
|
'SUB_ID' => 'synthesis',
|
|
'SUB_KEY' => 'heroSkin_synthesis',
|
|
'cost_fragment' => $costItems,
|
|
'result' => 1,
|
|
'outcome_skin' => array(
|
|
'item_id' => $skinId,
|
|
'item_num' => $number
|
|
),
|
|
);
|
|
LogService::burialPointEvent($event);
|
|
$this->_rspData(array(
|
|
'item_id' => $skinId,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
}
|