game2005api/webapp/controller/HeroController.class.php
2021-11-26 14:22:38 +08:00

151 lines
4.2 KiB
PHP

<?php
require_once('mt/Shop.php');
require_once('mt/Hero.php');
require_once('mt/Item.php');
require_once('models/Hero.php');
require_once('models/HeroSkin.php');
use phpcommon\SqlHelper;
use models\Hero;
use models\HeroSkin;
class HeroController extends BaseAuthedController {
public function heroList()
{
$heroList = array();
SqlHelper::ormSelect(
$this->_getSelfMysql(),
't_hero',
array(
'accountid' => $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(
'accountid' => $this->_getAccountId()
),
function ($row) use(&$skinList) {
array_push($skinList, HeroSkin::toDto($row));
}
);
$this->_rspData(array(
'skin_list' => $skinList
));
}
public function buyHero()
{
$heroId = getReqVal('hero_id', 0);
$buyType = getReqVal('buy_type', 0);
$heroMeta = mt\Hero::get($heroId);
if ($heroMeta) {
$this->_rspErr(1, 'hero_id参数错误');
return;
}
if (empty($heroMeta['itemid'])) {
$this->_rspErr(2, 'hero.item_id配置错误');
return;
}
if (!in_array($buyType, array(0, 1))) {
$this->_rspErr(1, 'buy_type参数错误');
return;
}
$shopMeta = mt\Shop::get(mt\Shop::HERO_SHOP_ID);
if (!$shopMeta) {
$this->_rspErr(2, '配置表错误');
return;
}
$goodsInfo = mt\Shop::getGoodsInfo($shopMeta, $heroMeta['itemid']);
if (empty($goodsInfo)) {
$this->_rspErr(2, '配置表错误');
return;
}
$costItems = array(
'item_id' => $goodsInfo['costItemId'],
'item_num' => $goodsInfo['costItemNum'],
);
$lackItem = null;
if (!$this->_hasEnoughItemsEx($costItems, $lackItem)) {
$this->_rspErr(3, '道具不足');
return;
}
$this->_decItems($costItems);
Hero::addHero($heroMeta);
}
public function buySkin()
{
$skinId = getReqVal('skin_id', 0);
$skinMeta = mt\Item::get($skinId);
if (!$skinMeta) {
$this->_rspErr(1, 'skin_id参数错误');
return;
}
if (!mt\Item::isType($skinMeta, mt\Item::SKIN_TYPE)){
$this->_rspErr(1, 'skin_id参数错误');
return;
}
HeroSkin::addSkin($skinId);
}
public function takeonSkin()
{
$heroId = getReqVal('hero_id', 0);
$skinId = getReqVal('skin_id', 0);
$heroDb = Hero::find($heroId);
$heroSkinDb = Hero::find($skinId);
if (!$heroDb) {
$this->_rspErr(1, '你还没这个英雄');
return;
}
if (!$heroSkinDb) {
$this->_rspErr(2, '你还没这个皮肤');
return;
}
Hero::takeonSkin($heroId, $skinId);
$this->_rspOk();
}
public function upgradeSkill()
{
$heroId = getReqVal('hero_id', 0);
$skillIdx = getReqVal('skill_idx', 0);
$heroDb = Hero::find($heroId);
if (!$heroDb) {
$this->_rspErr(1, '你还没这个英雄');
return;
}
if (!in_array($skillIdx, array(0, 1))) {
$this->_rspErr(1, 'skill_idx参数必须为0-1');
return;
}
Hero::upgradeSkill($heroId, $skillIdx);
$this->_rspOk();
}
public function useYokeItem()
{
$heroId = getReqVal('hero_id', 0);
$itemId = getReqVal('item_id', 0);
$itemNum = getReqVal('item_num', 0);
$this->_rspOk();
}
}