381 lines
12 KiB
PHP
381 lines
12 KiB
PHP
<?php
|
|
|
|
require_once('mt/Shop.php');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Item.php');
|
|
require_once('mt/HeroLevel.php');
|
|
require_once('mt/HeroLevelAttr.php');
|
|
require_once('mt/HeroQuality.php');
|
|
require_once('mt/AttrHelper.php');
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/SkillCommon.php');
|
|
require_once('mt/Skill.php');
|
|
|
|
require_once('models/Hero.php');
|
|
require_once('models/Bag.php');
|
|
require_once('models/HeroSkin.php');
|
|
require_once('models/Nft.php');
|
|
require_once('models/NftUpReceive.php');
|
|
require_once('models/Transaction.php');
|
|
require_once('models/ChipPage.php');
|
|
require_once('models/Gun.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/RankActivityService.php');
|
|
require_once('services/LogService.php');
|
|
|
|
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Hero;
|
|
use models\Bag;
|
|
use models\HeroSkin;
|
|
use models\ChipPage;
|
|
use models\Gun;
|
|
use models\Nft;
|
|
use models\NftUpReceive;
|
|
use models\Transaction;
|
|
use services\LogService;
|
|
|
|
class HeroController extends BaseAuthedController {
|
|
|
|
public function heroList()
|
|
{
|
|
$heroList = array();
|
|
Hero::getHeroList(function ($row) use(&$heroList) {
|
|
array_push($heroList, Hero::toDto($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;
|
|
}
|
|
$heroDb['tags'] = '';
|
|
if ($heroDb['token_id']){
|
|
$nftDb = Nft::getNft($heroDb['token_id']);
|
|
$heroDb['tags'] = $nftDb['tags'];
|
|
}
|
|
|
|
$hero = Hero::toDto($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;
|
|
}
|
|
if (!$heroSkinDb) {
|
|
$this->_rspErr(2, "You don't have the skin yet");
|
|
return;
|
|
}
|
|
HeroSkin::takeonSkin( $skinId,$heroDb['hero_id']);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function upgradeLevelPreview(){
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$heroDb = Hero::find($heroUniId);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(1, 'hero does not exist');
|
|
return;
|
|
}
|
|
$heroMeta = mt\Hero::get($heroDb['hero_id']);
|
|
if (!$heroMeta) {
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv'] + 1);
|
|
if (!$nextLevelMeta) {
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
return;
|
|
}
|
|
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $nextLevelMeta['gold']
|
|
),
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => $nextLevelMeta['diamond']
|
|
)
|
|
);
|
|
|
|
$newHeroDb = $heroDb;
|
|
$newHeroDb['hero_lv'] += 1;
|
|
$attrs = Hero::LvUpAddAttr($heroDb,0);
|
|
$newHeroDb['rand_attr'] = json_encode($attrs);
|
|
|
|
$heroDto = Hero::toDto($heroDb);
|
|
$newHeroDto = Hero::toDto($newHeroDb);
|
|
$this->_rspData(array(
|
|
|
|
'old_hero' => $heroDto,
|
|
'new_hero' => $newHeroDto,
|
|
'cost' => $costItems
|
|
));
|
|
}
|
|
|
|
public function upgradeLv()
|
|
{
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$costHeroUniId = getReqVal('cost_hero_uniid', 0);
|
|
$heroDb = Hero::find($heroUniId);
|
|
$oldHero = Hero::toDto($heroDb);
|
|
$costHeroDb = Hero::findEx($costHeroUniId);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(100, 'param error or null');
|
|
return;
|
|
}
|
|
if ($heroDb['hero_lv'] == Hero::LV_1 ||
|
|
$heroDb['hero_lv'] == Hero::LV_2 ||
|
|
$heroDb['hero_lv'] == Hero::LV_3 ){
|
|
if (! $costHeroDb){
|
|
$this->_rspErr(100, 'material param error or null');
|
|
return;
|
|
}
|
|
if ($costHeroDb['token_id']){
|
|
$this->_rspErr(100, 'NFT cannot be a material');
|
|
return;
|
|
}
|
|
// if ($costHeroDb['state'] == Hero::FREE_STATE){
|
|
// $this->_rspErr(100, 'Unable to use free hero');
|
|
// return;
|
|
// }
|
|
switch ($heroDb['hero_lv']){
|
|
case Hero::LV_1:{
|
|
if ($heroDb['hero_lv'] < $costHeroDb['hero_lv']){
|
|
$this->_rspErr(100, 'Grade discrepancy');
|
|
return;
|
|
}
|
|
};break;
|
|
case Hero::LV_2:{
|
|
if ($heroDb['hero_lv'] < $costHeroDb['hero_lv'] && $costHeroDb['hero_lv'] <= Hero::LV_1){
|
|
$this->_rspErr(100, 'Grade discrepancy');
|
|
return;
|
|
}
|
|
};break;
|
|
case Hero::LV_3:{
|
|
if ($heroDb['hero_lv'] < $costHeroDb['hero_lv'] && $costHeroDb['hero_lv'] <= Hero::LV_2){
|
|
$this->_rspErr(100, 'Grade discrepancy');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$heroMeta = mt\Hero::get($heroDb['hero_id']);
|
|
if (!$heroMeta) {
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv'] + 1);
|
|
if (!$nextLevelMeta) {
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
return;
|
|
}
|
|
|
|
//升级所需消耗
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $nextLevelMeta['gold']
|
|
),
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => $nextLevelMeta['diamond']
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
|
|
$attrs = Hero::LvUpAddAttr($heroDb,1);
|
|
Hero::update($heroUniId, array(
|
|
'hero_lv' => $heroDb['hero_lv'] + 1,
|
|
'rand_attr' => json_encode($attrs),
|
|
'state' => Hero::GETED_STATE,
|
|
));
|
|
if ($costHeroDb){
|
|
Hero::update($costHeroUniId, array(
|
|
'account_id' => myself()->_getAccountId() . '!!!',
|
|
));
|
|
}
|
|
if ($heroDb['hero_lv'] + 1 > myself()->_getV(TN_HERO_MAX_LEVEL, 0)) {
|
|
myself()->_setV(TN_HERO_MAX_LEVEL, 0, $heroDb['hero_lv'] + 1);
|
|
}
|
|
$newHero = Hero::toDto(Hero::find($heroUniId));
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addHeroChg();
|
|
$propertyChgService->addUserChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
'old_hero' => $oldHero,
|
|
'new_hero' => $newHero,
|
|
));
|
|
}
|
|
|
|
public function presetHero(){
|
|
$heroId = getReqVal('hero_uid',0);
|
|
$heroDb = Hero::find($heroId);
|
|
if (! $heroDb){
|
|
$this->_rspErr(1, "You don't have the hero yet");
|
|
return;
|
|
}
|
|
$row = SqlHelper::ormSelectOne(
|
|
$this->_getSelfMysql(),
|
|
't_hero_preset',
|
|
array(
|
|
'account_id' => $this->_getAccountId(),
|
|
'hero_uid' => $heroId,
|
|
)
|
|
);
|
|
if ($row){
|
|
|
|
$data = array(
|
|
'skill_id' => $row['skill_id'],
|
|
'weapon_uid1' => $row['weapon_uid1'],
|
|
'weapon_uid2' => $row['weapon_uid2'],
|
|
'chip_page' => $row['chip_page'],
|
|
'gun_id1'=>0,
|
|
'gun_id2'=>0,
|
|
);
|
|
$gunDb1 = Gun::find($row['weapon_uid1']);
|
|
$gunDb2 = Gun::find($row['weapon_uid2']);
|
|
if ($gunDb1){
|
|
$data['gun_id1'] = $gunDb1['gun_id'];
|
|
}
|
|
if ($gunDb1){
|
|
$data['gun_id2'] = $gunDb2['gun_id'];
|
|
}
|
|
}else{
|
|
$data = array(
|
|
'skill_id' => \mt\Skill::DEFAULT_SKILL,
|
|
'weapon_uid1' => 0,
|
|
'weapon_uid2' => 0,
|
|
'gun_id1'=>0,
|
|
'gun_id2'=>0,
|
|
'chip_page' => 1,
|
|
);
|
|
}
|
|
$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;
|
|
}
|
|
$chipPageDb = ChipPage::find($chipPageId);
|
|
if (! $chipPageDb){
|
|
$this->_rspErr(1, "You don't have the chip page");
|
|
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 ;
|
|
}
|
|
SqlHelper::upsert
|
|
($this->_getSelfMysql(),
|
|
't_hero_preset',
|
|
array(
|
|
'account_id' => $this->_getAccountId(),
|
|
'hero_uid' => $heroId,
|
|
),
|
|
array(
|
|
'skill_id' => $skillId,
|
|
'weapon_uid1' => $weaponUid1,
|
|
'weapon_uid2' => $weaponUid2,
|
|
'chip_page' => $chipPageId,
|
|
'modifytime' => $this->_getNowTime(),
|
|
),
|
|
array(
|
|
'account_id' => $this->_getAccountId(),
|
|
'hero_uid' => $heroId,
|
|
'skill_id' => $skillId,
|
|
'weapon_uid1' => $weaponUid1,
|
|
'weapon_uid2' => $weaponUid2,
|
|
'chip_page' => $chipPageId,
|
|
'createtime' => $this->_getNowTime(),
|
|
'modifytime' => $this->_getNowTime(),
|
|
|
|
)
|
|
);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
|
|
}
|