601 lines
19 KiB
PHP
601 lines
19 KiB
PHP
<?php
|
|
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/Item.php');
|
|
require_once('mt/HeroLevel.php');
|
|
require_once('mt/Skill.php');
|
|
|
|
require_once('models/Hero.php');
|
|
require_once('models/HeroSkin.php');
|
|
require_once('models/Nft.php');
|
|
require_once('models/ChipPage.php');
|
|
require_once('models/Gun.php');
|
|
require_once('models/HeroPreset.php');
|
|
require_once('models/Bag.php');
|
|
require_once('models/Transaction.php');
|
|
require_once('models/BcOrder.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/LogService.php');
|
|
require_once('services/BlockChainService.php');
|
|
|
|
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Hero;
|
|
use models\HeroSkin;
|
|
use models\ChipPage;
|
|
use models\Gun;
|
|
use models\Nft;
|
|
use models\HeroPreset;
|
|
use models\Bag;
|
|
use models\Transaction;
|
|
use models\BcOrder;
|
|
use services\LogService;
|
|
|
|
class HeroController extends BaseAuthedController {
|
|
|
|
// public function test(){
|
|
// $heroUniId = getReqVal('hero_uniid', 0);
|
|
// $heroDb = Hero::find($heroUniId);
|
|
// if (!$heroDb) {
|
|
// $this->_rspErr(100, 'param error or null');
|
|
// return;
|
|
// }
|
|
// if ($heroDb['hero_lv'] == 15){
|
|
// $this->_rspErr(100, 'param error or null');
|
|
// return;
|
|
// }
|
|
// $attrs = Hero::LvUpAddAttr($heroDb);
|
|
// Hero::update($heroUniId, array(
|
|
// 'hero_lv' => $heroDb['hero_lv'] + 1,
|
|
// 'rand_attr' => json_encode($attrs['rand_attr']),
|
|
// 'base_attr' => json_encode($attrs['base_attr']),
|
|
// ));
|
|
// }
|
|
|
|
public function heroList()
|
|
{
|
|
$heroList = array();
|
|
Hero::getHeroList(function ($row) use(&$heroList) {
|
|
// if(!in_array($row['hero_id'],array(30200,30700,31000))){
|
|
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'];
|
|
}
|
|
$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 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 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_HERO_META,
|
|
'item_num' => $nextLevelMeta['serum']
|
|
)
|
|
);
|
|
// $metaList = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE);
|
|
// foreach ($metaList as $meta){
|
|
// if ($meta['relationship'] == $heroDb['hero_id']) {
|
|
// array_push($costItems,array(
|
|
// 'item_id' => $meta['id'],
|
|
// 'item_num' => $nextLevelMeta['piece'],
|
|
// ));
|
|
// }
|
|
// }
|
|
$heroDto = Hero::toDto($heroDb);
|
|
$newHeroDto = $heroDto;
|
|
$newHeroDto['hero_lv'] += 1;
|
|
$attrs_new = Hero::nextLvAttr($heroDb);
|
|
$newHeroDto['rand_attr'] = $attrs_new;
|
|
$this->_rspData(array(
|
|
|
|
'old_hero' => $heroDto,
|
|
'new_hero' => $newHeroDto,
|
|
'cost' => $costItems
|
|
));
|
|
}
|
|
|
|
/*
|
|
英雄升级
|
|
*/
|
|
public function upgradeLv()
|
|
{
|
|
return;
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$heroDb = Hero::find($heroUniId);
|
|
$oldHero = Hero::toDto($heroDb);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(100, 'param error or null');
|
|
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;
|
|
}
|
|
|
|
//校验英雄碎片数量
|
|
$piece_item_id = 0;
|
|
$metaList = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE);
|
|
foreach ($metaList as $meta){
|
|
if ($meta['relationship'] == $heroDb['hero_id']) {
|
|
$piece_item_id = $meta['id'];
|
|
break;
|
|
}
|
|
}
|
|
$piece_num = Bag::getItemCount($piece_item_id);
|
|
if ($piece_num < $nextLevelMeta['piece']){
|
|
$this->_rspErr(3, "Lack of hero piece");
|
|
return;
|
|
}
|
|
|
|
//校验英雄水晶数量
|
|
$num = Bag::getItemCount(V_ITEM_HERO_META);
|
|
if ($num < $nextLevelMeta['serum']){
|
|
$this->_rspErr(3, "Lack of hero crystal");
|
|
return;
|
|
}
|
|
|
|
//校验用户gold数量
|
|
$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);
|
|
Bag::decItem($piece_item_id,$nextLevelMeta['piece']);
|
|
Bag::decItem(V_ITEM_HERO_META,$nextLevelMeta['serum']);
|
|
{
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::HERO_LEVEL_UP,
|
|
'val' => $nextLevelMeta['gold']
|
|
];
|
|
LogService::consumeGold($event);
|
|
}
|
|
|
|
$attrs = Hero::LvUpAddAttr($heroDb);
|
|
Hero::update($heroUniId, array(
|
|
'hero_lv' => $heroDb['hero_lv'] + 1,
|
|
'rand_attr' => json_encode($attrs['rand_attr']),
|
|
'base_attr' => json_encode($attrs['base_attr']),
|
|
// 'state' => Hero::GETED_STATE,
|
|
));
|
|
|
|
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();
|
|
$propertyChgService->addBagChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
'old_hero' => $oldHero,
|
|
'new_hero' => $newHero,
|
|
));
|
|
}
|
|
|
|
|
|
/*
|
|
英雄升级
|
|
*/
|
|
public function upgradeLvNew()
|
|
{
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$heroDb = Hero::find($heroUniId);
|
|
$oldHero = Hero::toDto($heroDb);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(100, 'param error or null');
|
|
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_HERO_META,
|
|
'item_num' => $nextLevelMeta['serum']
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
// Bag::decItem(V_ITEM_HERO_META,$nextLevelMeta['serum']);
|
|
{
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::HERO_LEVEL_UP,
|
|
'val' => $nextLevelMeta['gold']
|
|
];
|
|
LogService::consumeGold($event);
|
|
}
|
|
|
|
$attrs = Hero::LvUpAddAttr($heroDb);
|
|
Hero::update($heroUniId, array(
|
|
'hero_lv' => $heroDb['hero_lv'] + 1,
|
|
'rand_attr' => json_encode($attrs['rand_attr']),
|
|
'base_attr' => json_encode($attrs['base_attr']),
|
|
//'state' => Hero::GETED_STATE,
|
|
));
|
|
|
|
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();
|
|
$propertyChgService->addBagChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
'old_hero' => $oldHero,
|
|
'new_hero' => $newHero,
|
|
));
|
|
}
|
|
|
|
/*
|
|
英雄预设
|
|
*/
|
|
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;
|
|
}
|
|
$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 ;
|
|
}
|
|
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();
|
|
}
|
|
|
|
/*
|
|
英雄碎片合成
|
|
*/
|
|
public function heroPieceSys(){
|
|
error_log("HERO PRICE : " . json_encode($_REQUEST));
|
|
$itemId = getReqVal('item_id',0);
|
|
$pieceNum = \mt\Parameter::getVal('hero_piece_synthesis_num',0);
|
|
$itemMeta = \mt\Item::get($itemId);
|
|
if (!$itemMeta || $itemMeta['type'] != \mt\Item::FRAGMENT_TYPE){
|
|
$this->_rspErr(1, "param item_id error");
|
|
return;
|
|
}
|
|
$bagDb = Bag::find($itemId);
|
|
if (!$bagDb || $bagDb['item_num'] < $pieceNum){
|
|
$this->_rspErr(1, "Insufficient material");
|
|
return;
|
|
}
|
|
|
|
$heroMeta = \mt\Item::get($itemMeta['relationship']);
|
|
Bag::decItem($itemId,$pieceNum);
|
|
Hero::addFreeHero($heroMeta);
|
|
$heroIdx = SqlHelper::getLastInsertId($this->_getSelfMysql());
|
|
$heroInfo = Hero::toDto(Hero::find($heroIdx));
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addHeroChg();
|
|
$propertyChgService->addBagChg();
|
|
$this->_rspData(array(
|
|
'hero' => $heroInfo,
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function beforeHeroReset(){
|
|
return;
|
|
$hero_unnid = getReqVal('hero_unnid',0);
|
|
$heroDb = Hero::find($hero_unnid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1, "param hero_unnid error");
|
|
return;
|
|
}
|
|
if ($heroDb['hero_lv'] == 1){
|
|
$this->_rspErr(1, "Level 1 hero cannot operate");
|
|
return;
|
|
}
|
|
$paramMeta = \mt\Parameter::getListValue('hero_reset_cost');
|
|
if (!$paramMeta){
|
|
$this->_rspErr(1, "parameter hero_reset_cost is null ");
|
|
return;
|
|
}
|
|
$actual_price = 0;
|
|
foreach ($paramMeta as $value){
|
|
$temp = explode(":",$value);
|
|
if ($heroDb['hero_lv'] == $temp[0]){
|
|
$actual_price = $temp[1];
|
|
}
|
|
}
|
|
$piece = 0;
|
|
$serum = 0;
|
|
$gold = 0;
|
|
for ($i=1;$i<=$heroDb['hero_lv'];$i++){
|
|
$heroLevelMeta = mt\HeroLevel::getByLevel($i);
|
|
$piece += $heroLevelMeta['piece'];
|
|
$serum += $heroLevelMeta['serum'];
|
|
$gold += $heroLevelMeta['gold'];
|
|
}
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $gold,
|
|
),
|
|
array(
|
|
'item_id' => V_ITEM_HERO_META,
|
|
'item_num' => $serum,
|
|
),
|
|
|
|
);
|
|
$metaList = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE);
|
|
foreach ($metaList as $meta){
|
|
if ($meta['relationship'] == $heroDb['hero_id']) {
|
|
array_push($costItems,array(
|
|
'item_id' => $meta['id'],
|
|
'item_num' => $piece,
|
|
));
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'ceg' => $actual_price,
|
|
"cost" => $costItems
|
|
));
|
|
}
|
|
/*
|
|
英雄重置 2:5|3:10|4:15|5:20|6:25|7:30|8:35|9:40|10:45|11:50|12:55|13:60|14:65|15:70
|
|
*/
|
|
public function heroResetLevel(){
|
|
return;
|
|
error_log("heroResetLevel : " . json_encode($_REQUEST));
|
|
if (!$this->_isValidAddress()) {
|
|
$this->_rspErr(1, 'address is empty');
|
|
return;
|
|
}
|
|
$hero_unnid = getReqVal('hero_unnid',0);
|
|
$price = getReqVal('price', 0);
|
|
$heroDb = Hero::find($hero_unnid);
|
|
if (!$heroDb){
|
|
$this->_rspErr(1, "param hero_unnid error");
|
|
return;
|
|
}
|
|
if ($heroDb['hero_lv'] <= 1){
|
|
$this->_rspErr(1, "This is the lowest level of hero");
|
|
return;
|
|
}
|
|
$paramMeta = \mt\Parameter::getListValue('hero_reset_cost');
|
|
if (!$paramMeta){
|
|
$this->_rspErr(1, "parameter hero_reset_cost is null ");
|
|
return;
|
|
}
|
|
$actual_price = 0;
|
|
foreach ($paramMeta as $value){
|
|
$temp = explode(":",$value);
|
|
if ($heroDb['hero_lv'] == $temp[0]){
|
|
$actual_price = $temp[1];
|
|
}
|
|
}
|
|
if($price != $actual_price){
|
|
$this->_rspErr(1, "The number of CEGs is incorrect ");
|
|
return;
|
|
}
|
|
$response = services\BlockChainService::gameItemMallBuy(
|
|
Transaction::RESET_HERO_LEVEL_TYPE, services\BlockChainService::CURRENCY_CEG, services\BlockChainService::formatCurrency($price), V_ITEM_RESET_CARD, 1);
|
|
$this->_setV(TN_DAILY_RESET_HERO_LEVEL_STATE, intval($hero_unnid), 1);
|
|
BcOrder::upsert($response['trans_id'], array(
|
|
'item_id' => V_ITEM_RESET_CARD,
|
|
'item_num' => 1,
|
|
'price' => $price,
|
|
'ext_data' => json_encode($hero_unnid),
|
|
));
|
|
$this->_rspData($response);
|
|
}
|
|
|
|
/*
|
|
英雄分解
|
|
*/
|
|
public function heroSalvage(){
|
|
|
|
}
|
|
|
|
/*
|
|
英雄融合
|
|
*/
|
|
public function heroMerge(){
|
|
|
|
}
|
|
|
|
}
|