423 lines
14 KiB
PHP
423 lines
14 KiB
PHP
<?php
|
|
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Item.php');
|
|
require_once('mt/Skill.php');
|
|
require_once('mt/QualityUpMapRule.php');
|
|
require_once('mt/ChipAttribute.php');
|
|
require_once('mt/EconomyAttribute.php');
|
|
require_once('mt/Manufacture.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/HeroSkin.php');
|
|
require_once('models/Nft.php');
|
|
require_once('models/Gun.php');
|
|
require_once('models/HeroPreset.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 models\Gun;
|
|
use models\Nft;
|
|
use models\HeroPreset;
|
|
|
|
use services\LogService;
|
|
|
|
class HeroController extends BaseAuthedController {
|
|
|
|
|
|
public function heroList()
|
|
{
|
|
$heroList = array();
|
|
Hero::getHeroList(function ($row) use(&$heroList) {
|
|
array_push($heroList, Hero::listDto($row));
|
|
});
|
|
$this->_rspData(array(
|
|
'hero_list' => $heroList
|
|
));
|
|
}
|
|
|
|
public function heroDetails()
|
|
{
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
if ( ! $unique_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$heroDb = Hero::find($unique_id);
|
|
if (! $heroDb){
|
|
$this->_rspErr(1, "You don't have the hero yet");
|
|
return;
|
|
}
|
|
|
|
$resetLv_state = $this->_getDailyV(TN_DAILY_RESET_HERO_LEVEL_STATE, $unique_id);
|
|
|
|
$hero = Hero::toDto($heroDb);
|
|
$hero['avatarInfo'] = Hero::avatarInfo($heroDb);
|
|
$hero['resetLv_state'] = $resetLv_state;
|
|
$this->_rspData(array(
|
|
'data' => $hero
|
|
));
|
|
}
|
|
|
|
public function mallHeroInfo(){
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
if ( ! $unique_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$heroDb = Hero::findEx($unique_id);
|
|
if (! $heroDb){
|
|
$this->_rspErr(1, "You don't have the hero yet");
|
|
return;
|
|
}
|
|
$hero = Hero::mallInfo($heroDb);
|
|
$this->_rspData(array(
|
|
'data' => $hero
|
|
));
|
|
}
|
|
|
|
public function skinList()
|
|
{
|
|
$heroId = getReqVal('hero_id',0);
|
|
if (!$heroId){
|
|
$this->_rspErr(1, "param null");
|
|
return;
|
|
}
|
|
$itemMeta = \mt\Item::get($heroId);
|
|
if (!$itemMeta || $itemMeta['type']!=\mt\Item::HERO_TYPE){
|
|
$this->_rspErr(1, "param error");
|
|
return;
|
|
}
|
|
$skinList = array();
|
|
$skinMeta = \mt\Item::getMetaListByType(\mt\Item::HERO_SKIN_TYPE);
|
|
if ($skinMeta){
|
|
foreach ($skinMeta as $value){
|
|
if ($value['playerid'] == $heroId){
|
|
array_push($skinList,HeroSkin::toDto($value));
|
|
}
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'skin_list' => $skinList
|
|
));
|
|
}
|
|
|
|
public function takeonSkin()
|
|
{
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$skinId = getReqVal('skin_id', 0);
|
|
$heroDb = Hero::find($heroUniId);
|
|
$heroSkinDb = HeroSkin::find($skinId);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(1, "You don't have the hero yet");
|
|
return;
|
|
}
|
|
$itemMeta = \mt\Item::get($skinId);
|
|
if ($itemMeta['isdefaultskin'] != 1 && !$heroSkinDb) {
|
|
$this->_rspErr(2, "You don't have the skin yet");
|
|
return;
|
|
}
|
|
HeroSkin::takeonSkin( $skinId,$heroDb['hero_id']);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
/*
|
|
升阶预览
|
|
*/
|
|
public function upgradeQualityPreview(){
|
|
return;
|
|
$itemId = getReqVal('itemId', 0);
|
|
$quality = getReqVal('quality', 0);
|
|
|
|
if ($quality == \mt\QualityUpMapRule::MAX_QUALITY){
|
|
$this->_rspErr(5, "It's already the highest quality");
|
|
return;
|
|
}
|
|
$heroQualityMeta = \mt\QualityUpMapRule::getByQuality($itemId,$quality+1);
|
|
if (!$heroQualityMeta){
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $heroQualityMeta['gold']
|
|
),
|
|
array(
|
|
'item_id' => $heroQualityMeta['item'],
|
|
'item_num' => $heroQualityMeta['item_num']
|
|
),
|
|
);
|
|
$this->_rspData(array(
|
|
'cost' => $costItems
|
|
));
|
|
}
|
|
|
|
/*
|
|
英雄升阶
|
|
*/
|
|
public function upgradeQualityOld(){
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$heroDb = Hero::find($heroUniId);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(100, 'param error or null');
|
|
return;
|
|
}
|
|
if ($heroDb['quality'] == \mt\QualityUpMapRule::MAX_QUALITY){
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
return;
|
|
}
|
|
$heroQualityMeta = \mt\QualityUpMapRule::getByQuality($heroDb['hero_id'],$heroDb['quality']+1);
|
|
if (!$heroQualityMeta){
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $heroQualityMeta['gold']
|
|
),
|
|
array(
|
|
'item_id' => $heroQualityMeta['item'],
|
|
'item_num' => $heroQualityMeta['item_num']
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
$heroMeta = \mt\Item::get($heroDb['hero_id']);
|
|
$attribute = \mt\EconomyAttribute::getAttribute($heroMeta['relationship'], $heroDb['quality'] + 1);
|
|
Hero::update($heroUniId, array(
|
|
'quality' => $heroDb['quality'] + 1,
|
|
'wealth_attr' => json_encode($attribute),
|
|
));
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addHeroChg();
|
|
$propertyChgService->addUserChg();
|
|
$propertyChgService->addBagChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function upgradeQuality(){
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$itemId = getReqVal('item_id',0);
|
|
$itemNum = getReqVal('item_num',0);
|
|
if ($itemNum < 1){
|
|
$this->_rspErr(1, "item_num not enough");
|
|
return;
|
|
}
|
|
$heroDb = Hero::find($heroUniId);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(100, 'param hero_uniid error ');
|
|
return;
|
|
}
|
|
if ($heroDb['quality'] == \mt\QualityUpMapRule::MAX_QUALITY){
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
return;
|
|
}
|
|
$heroQualityMeta = \mt\QualityUpMapRule::getByQuality($heroDb['hero_id'],$heroDb['quality']+1);
|
|
if (!$heroQualityMeta || $heroQualityMeta['needItem'] != $itemId){
|
|
$this->_rspErr(100, 'param item_id error ');
|
|
return;
|
|
}
|
|
|
|
$manufactureMeta = \mt\Manufacture::findHeroAction(\mt\Manufacture::UP_ACTION,$heroDb['quality']+1);
|
|
if (!$manufactureMeta){
|
|
$this->_rspErr(1, "Error operation");
|
|
return;
|
|
}
|
|
$itemNum = min($itemNum,$manufactureMeta['numTop']);
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $manufactureMeta['gold']
|
|
),
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => $itemNum
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
//消耗材料
|
|
$this->_decItems($costItems);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addBagChg();
|
|
$propertyChgService->addUserChg();
|
|
$hashChance = \mt\Manufacture::hashChance($manufactureMeta['chance']);
|
|
$weight = isset($hashChance[$itemNum]) ? $hashChance[$itemNum] : 0;
|
|
$rnd = rand(1,100);
|
|
$status = 0;
|
|
if ($rnd <= $weight*100){
|
|
$status = 1;
|
|
$heroMeta = \mt\Item::get($heroDb['hero_id']);
|
|
$heroAtteMeta = \mt\EconomyAttribute::findByGrade($heroMeta['relationship'],$heroDb['quality']);
|
|
$heroNextQualityAtteMeta = \mt\EconomyAttribute::findByGrade($heroMeta['relationship'],$heroDb['quality'] + 1);
|
|
$unsealTime = $heroDb['unseal_time'] ? $heroDb['unseal_time'] : $heroDb['activate_time'];
|
|
$validTime = $unsealTime + 86400 * $heroAtteMeta['validTime'] ;
|
|
$valid_lefttime = max(0, $validTime - myself()->_getNowTime()) + ($heroNextQualityAtteMeta['validTime'] - $heroAtteMeta['validTime']) * 86400;
|
|
$attribute = \mt\EconomyAttribute::getAttribute($heroMeta['relationship'], $heroDb['quality'] + 1);
|
|
$unseal_time_new = $valid_lefttime + myself()->_getNowTime() - 86400 * $heroNextQualityAtteMeta['validTime'];
|
|
Hero::update($heroUniId, array(
|
|
'quality' => $heroDb['quality'] + 1,
|
|
'unseal_time' => $unseal_time_new,
|
|
'wealth_attr' => json_encode($attribute),
|
|
));
|
|
$heroNew = Hero::toDto(Hero::find($heroUniId));
|
|
$propertyChgService->addHeroChg();
|
|
|
|
$event = array(
|
|
'ID' => 'luck',
|
|
'SUB_ID' => 'change',
|
|
'SUB_KEY' => 'luck_change',
|
|
'change' => Hero::getAccountLuckyTemp(),
|
|
'reason' => 'hero_advanced',
|
|
);
|
|
LogService::burialPointEvent($event);
|
|
}
|
|
$itemMeta = \mt\Item::get($itemId);
|
|
$event = array(
|
|
'ID' => 'hero',
|
|
'SUB_ID' => 'advanced',
|
|
'SUB_KEY' => 'hero_advanced',
|
|
'cost_hero' => $heroDb,
|
|
'cost_fragment' => array(
|
|
'item_id' => $itemId,
|
|
'item_num' => $itemNum,
|
|
'item_quality' => $itemMeta['quality'],
|
|
),
|
|
'cost_gold' => array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $manufactureMeta['gold']
|
|
),
|
|
'chance' => $weight,
|
|
'result' => $status,
|
|
'outcome_hero' => isset($heroNew) ? $heroNew : array(),
|
|
);
|
|
LogService::burialPointEvent($event);
|
|
$this->_rspData(array(
|
|
'status' => $status,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function unSealHero(){
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$heroDb = Hero::find($heroUniId);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(100, 'param error or null');
|
|
return;
|
|
}
|
|
// if (!$heroDb['token_id']){
|
|
// $this->_rspErr(1, "this hero is not NFT");
|
|
// return;
|
|
// }
|
|
Hero::update($heroUniId,array(
|
|
'seal_type' => Hero::UNSEAL_STATE,
|
|
"unseal_time" => myself()->_getNowTime()
|
|
));
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addHeroChg();
|
|
$event = array(
|
|
'ID' => 'hero',
|
|
'SUB_ID' => 'unlock',
|
|
'SUB_KEY' => 'hero_unlock',
|
|
'before' => $heroDb,
|
|
'result' => 1,
|
|
'after' => Hero::find($heroUniId),
|
|
);
|
|
LogService::burialPointEvent($event);
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
/*
|
|
英雄预设
|
|
*/
|
|
public function presetHero(){
|
|
$heroUid = getReqVal('hero_uid',0);
|
|
$heroDb = Hero::find($heroUid);
|
|
if (! $heroDb){
|
|
$this->_rspErr(1, "You don't have the hero yet");
|
|
return;
|
|
}
|
|
$data = HeroPreset::getHeroPreset($heroUid);
|
|
$this->_rspData(array(
|
|
'data' => $data,
|
|
));
|
|
}
|
|
|
|
/*
|
|
应用预设
|
|
*/
|
|
public function applyHero(){
|
|
$heroId = getReqVal('hero_uid',0);
|
|
$chipPageId = getReqVal('chip_page',0);
|
|
$weaponUid1 = getReqVal('weapon_uid1',0);
|
|
$weaponUid2 = getReqVal('weapon_uid2',0);
|
|
$skillId = getReqVal('skill_id',0);
|
|
$heroDb = Hero::find($heroId);
|
|
if (! $heroDb){
|
|
$this->_rspErr(1, "You don't have the hero yet");
|
|
return;
|
|
}
|
|
if ($weaponUid1){
|
|
$gunDb1 = Gun::find($weaponUid1);
|
|
if (!$gunDb1){
|
|
$this->_rspErr(1, "You don't have the gun1 yet");
|
|
return;
|
|
}
|
|
}
|
|
if ($weaponUid2){
|
|
$gunDb2 = Gun::find($weaponUid2);
|
|
if (!$gunDb2){
|
|
$this->_rspErr(1, "You don't have the gun2 yet");
|
|
return;
|
|
}
|
|
}
|
|
$skillMeta = \mt\Skill::get($skillId);
|
|
if (! $skillMeta){
|
|
$this->_rspErr(1,'skill_id parameter error');
|
|
return ;
|
|
}
|
|
HeroPreset::upsertPreset($heroId,$skillId,$chipPageId,$weaponUid1,$weaponUid2);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addGunChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
/*
|
|
* 设置通用技能
|
|
*/
|
|
public function setHeroSkill(){
|
|
$skillId = getReqVal('skill_id',0);
|
|
$skillMeta = \mt\Skill::get($skillId);
|
|
if (! $skillMeta){
|
|
$this->_rspErr(1,'skill_id parameter error');
|
|
return ;
|
|
}
|
|
$userDb = $this->_getOrmUserInfo();
|
|
$hero_uid = $userDb['hero_id'];
|
|
$preset = HeroPreset::getHeroPreset($hero_uid);
|
|
HeroPreset::upsertPreset($hero_uid,$skillId,$preset['chip_page'],0,0);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
|
|
|
|
}
|