_getSelfMysql(), 't_hero', array( 'account_id' => $this->_getAccountId() ), function ($row) use(&$heroList) { array_push($heroList, Hero::toDto($row)); } ); $this->_rspData(array( 'hero_list' => $heroList )); } public function skinList() { $skinList = array(); SqlHelper::ormSelect( $this->_getSelfMysql(), 't_hero_skin', array( 'account_id' => $this->_getAccountId() ), function ($row) use(&$skinList) { array_push($skinList, HeroSkin::toDto($row)); } ); $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, '你还没这个英雄'); return; } if (!$heroSkinDb) { $this->_rspErr(2, '你还没这个皮肤'); return; } Hero::takeonSkin($heroUniId, $skinId); $this->_rspOk(); } public function upgradeSkill() { $heroUniId = getReqVal('hero_uniid', 0); $skillIdx = getReqVal('skill_idx', 0); $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, '你还没这个英雄'); return; } if (!in_array($skillIdx, array(0, 1))) { $this->_rspErr(1, 'skill_idx参数必须为0-1'); return; } Hero::upgradeSkill($heroUniId, $skillIdx); $this->_rspOk(); } public function upgradeLevel() { $costItemId = getReqVal('cost_item_id', 0); $heroUniId = getReqVal('hero_uniid', 0); $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, '英雄不存在'); return; } if ($heroDb['state'] != Hero::GETED_STATE) { $this->_rspErr(3, '试用英雄不能操作'); return; } if ($heroDb['unlock_time'] > $this->_getNowTime()) { $this->_rspErr(2, '锁定期间不能操作'); return; } if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) { $this->_rspErr(2, '锁定期间不能操作'); return; } $currLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'], $heroDb['hero_lv']); if (!$currLevelMeta) { $this->_rspErr(100, '服务器内部错误'); return; } $nextLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'], $heroDb['hero_lv'] + 1); if (!$nextLevelMeta) { $this->_rspErr(5, '已满级'); return; } $costItems = array(); switch ($costItemId) { case V_ITEM_GOLD: { $costItems = array( array( 'item_id' => $costItemId, 'item_num' => $currLevelMeta['gold'] ) ); } Break; case V_ITEM_DIAMOND: { $costItems = array( array( 'item_id' => $costItemId, 'item_num' => $currLevelMeta['diamond'] ) ); } break; default: { $this->_rspErr(2, '支付方式不支持'); return; } break; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); $ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $attrs); if (!$ret) { $this->_rspErr(2, '服务器内部错误'); return; } $this->_decItems($costItems); Hero::update($heroUniId, array( 'hero_lv' => $heroDb['hero_lv'] + 1, 'rand_attr' => json_encode($attrs), 'lock_type' => Hero::LEVEL_LOCK, 'unlock_time' => $this->_getNowTime() + $currLevelMeta['time'] ) ); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } public function upgradeQuality() { $costItemId = getReqVal('cost_item_id', 0); $heroUniId = getReqVal('hero_uniid', 0); $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, '英雄不存在'); return; } if ($heroDb['state'] != Hero::GETED_STATE) { $this->_rspErr(3, '试用英雄不能操作'); return; } if ($heroDb['unlock_time'] > $this->_getNowTime()) { $this->_rspErr(2, '锁定期间不能操作'); return; } if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) { $this->_rspErr(2, '锁定期间不能操作'); return; } $currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']); if (!$currQualityMeta) { $this->_rspErr(100, '服务器内部错误'); return; } $nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1); if (!$nextQualityMeta) { $this->_rspErr(5, '已满级1'); return; } $nextLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'] + 1, $heroDb['hero_lv']); if (!$nextLevelMeta) { $this->_rspErr(5, '已满级2'); return; } $costItems = array(); switch ($costItemId) { case V_ITEM_GOLD: { $costItems = array( array( 'item_id' => $costItemId, 'item_num' => $currQualityMeta['gold'] ) ); } break; case V_ITEM_DIAMOND: { $costItems = array( array( 'item_id' => $costItemId, 'item_num' => $currQualityMeta['diamond'] ) ); } break; default: { $this->_rspErr(2, '支付方式不支持'); return; } break; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); { $obtainAttrs = mt\HeroQuality::getRandAttr($nextQualityMeta); mt\AttrHelper::mergeAttr($attrs, $obtainAttrs); } { $ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $attrs); if (!$ret) { $this->_rspErr(2, '服务器内部错误'); return; } } $this->_decItems($costItems); Hero::update($heroUniId, array( 'hero_lv' => $heroDb['hero_lv'], 'quality' => $heroDb['quality'] + 1, 'rand_attr' => json_encode($attrs), 'lock_type' => Gun::QUALITY_LOCK, 'unlock_time' => $this->_getNowTime() + $currQualityMeta['time'] ) ); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto(), )); } }