protected function _exec()
 {
     $heros = $this->getParam('heros', 'array');
     $needMore = $this->getParam('more', 'bool');
     $characterMgr = new CharacterAccountManager();
     $user_clan_mgr = new UserClanManager();
     $clan_mgr = new ClanManager();
     $result = array();
     foreach ($heros as $heroId) {
         $heroInfo = $characterMgr->getCharacterAccount($heroId);
         //item 信息
         if ($needMore === TRUE) {
             $item_mgr = new UserGameItemManager($heroId);
             $items = $item_mgr->getItemList();
             $heroInfo['items'] = $items;
         }
         if (!empty($heroInfo)) {
             $user_clan_info = $user_clan_mgr->getUserClanInfo($heroId);
             if (!empty($user_clan_info)) {
                 $clanInfo = $clan_mgr->getClanInfo($user_clan_info['clan_id']);
                 $clanInfo['clanUser'] = $user_clan_info;
                 $heroInfo['clan'] = $clanInfo;
             }
             array_push($result, $heroInfo);
         }
     }
     return array("heros" => $result);
 }
 protected function _exec()
 {
     $specId = $this->getParam('specId', 'string');
     $battletype = $this->getParam('battletype', 'string');
     $characterId = $this->getParam('heroid', 'int');
     $isHelp = $this->getParam('isHelp', 'bool');
     //power
     $hero_mgr = new CharacterAccountManager();
     $hero_info = $hero_mgr->getCharacterAccount($characterId);
     $new_hero_info = StaticFunction::resetCurPower($hero_info);
     $cur_power = $new_hero_info['power'];
     if ($cur_power < StaticFunction::$power_battle_cost) {
         $this->throwException("power is not enough ,cur power = {$cur_power} ");
     } else {
         $heroChange = array('power' => $cur_power - StaticFunction::$power_battle_cost, 'powertime' => $new_hero_info['powertime']);
         $hero_mgr->updateUserStatus($characterId, $heroChange);
         $battleMgr = new BattleManager();
         $battleMgr->setBattleCache($characterId, $specId, $battletype, 0);
         if ($isHelp === TRUE) {
             $item_mgr = new UserGameItemManager($characterId);
             $item_mgr->subItem("80002", 1);
             $item_mgr->checkReduceItemCount();
             $item_mgr->commitToDB();
         }
         return $heroChange;
     }
 }
 protected function _exec()
 {
     $itemId = $this->getParam('itemId', 'int');
     $characterId = $this->getParam('heroid', 'int');
     $itemDef = get_xml_def($itemId);
     if (empty($itemDef)) {
         $this->throwException("itemId is not item {$itemId}");
     }
     $itemMgr = new UserGameItemManager($characterId);
     $itemMgr->subItem($itemId, 1);
     $hero_mgr = new CharacterAccountManager();
     $hero_account = $hero_mgr->getCharacterAccount($characterId);
     $new_hero_info = StaticFunction::resetCurPower($hero_account);
     $cur_power = $new_hero_info['power'];
     if ($itemId == "80000") {
         $heroChange = array('power' => $cur_power + 50, 'powertime' => $new_hero_info['powertime']);
     } else {
         if ($itemId == "80001") {
             $heroChange = array('power' => StaticFunction::getTotalPower(StaticFunction::expToGrade($new_hero_info['exp']), StaticFunction::expToVip($new_hero_info['vip'])), 'powertime' => $new_hero_info['powertime']);
         }
     }
     $hero_mgr->updateUserStatus($characterId, $heroChange);
     $itemMgr->commitToDB();
     $heroChange['item_id'] = $itemId;
     return $heroChange;
 }
 protected function _exec()
 {
     $characteruid = $this->getParam('characteruid', 'string');
     $result = array();
     //item 信息
     $item_mgr = new UserGameItemManager($characteruid);
     $items = $item_mgr->getItemList();
     $heroInfo['items'] = $items;
     //vip
     $vip_mgr = new CharacterAccountManager();
     $vipInfo = $vip_mgr->getVipCache($characteruid);
     $heroInfo['vipData'] = $vipInfo;
     //rate
     $rate_mgr = new RatingHeroManager();
     $heroInfo['heroRate'] = $rate_mgr->getHeroRate($characteruid);
     $result['topHeroRate'] = $rate_mgr->getTop();
     $heroInfo['heroRateTime'] = $rate_mgr->getRatingRewardTime($characteruid);
     $clan_rate_mgr = new RatingClanManager();
     $result['topClanRate'] = $clan_rate_mgr->getTop();
     $heroInfo['clanRateTime'] = $clan_rate_mgr->getRatingRewardTime($characteruid);
     $bossMgr = new ClanBossManager();
     $heroInfo['bossData'] = $bossMgr->getCurClanBoss();
     //clan
     $user_clan_mgr = new UserClanManager();
     $user_clan_info = $user_clan_mgr->getUserClanInfo($characteruid);
     if (!empty($user_clan_info)) {
         require_once GAMELIB . '/model/ClanManager.class.php';
         $clan_mgr = new ClanManager();
         $clan_info = $clan_mgr->getClanInfo($user_clan_info['clan_id']);
         $membersArr = array();
         $clanmembers = explode(",", $clan_info['members']);
         foreach ($clanmembers as $memberId) {
             $simclaninfo = $user_clan_mgr->getUserClanInfo($memberId);
             if (!empty($simclaninfo)) {
                 array_push($membersArr, $simclaninfo);
             }
         }
         array_push($membersArr, $user_clan_mgr->getUserClanInfo($clan_info['adminId']));
         $clan_info['membersArr'] = $membersArr;
         $clanTalk = $clan_mgr->getClanTalk($user_clan_info['clan_id']);
         if (!empty($clanTalk)) {
             $clan_info['talk'] = $clanTalk;
         }
         $heroInfo['clanRate'] = $clan_rate_mgr->getClanRate($user_clan_info['clan_id']);
         $clan_info['clanUser'] = $user_clan_info;
         $heroInfo['clan'] = $clan_info;
     }
     $result['hero_info'] = $heroInfo;
     return $result;
 }
 protected function _exec()
 {
     $characterId = $this->getParam('heroid', 'int');
     $skillArr = $this->getParam('skill', 'array');
     $itemMgr = new UserGameItemManager($characterId);
     foreach ($skillArr as $skillId) {
         $skill = $itemMgr->getItem($skillId);
         if (empty($skill) || $skill['count'] <= 0) {
             $this->throwException("hero {$characterId} do not have the skill {$skillId}");
         }
     }
     $new_skill_str = implode(":", $skillArr);
     $characterMgr = new CharacterAccountManager();
     $characterMgr->updateUserStatus($characterId, array("skills" => $new_skill_str));
     return array("stats" => TRUE);
 }
 private function addReward($gameuid, $rewards)
 {
     $item_mgr = new UserGameItemManager($gameuid);
     foreach ($rewards as $value) {
         if ($value['id'] == 'coin') {
             $this->user_account_mgr->updateUserCoin($gameuid, $value['count']);
         } else {
             if ($value['id'] == 'exp') {
                 $this->user_account_mgr->updateUserExperience($gameuid, $value['count']);
             } else {
                 $item_mgr->addItem($value['id'], $value['count']);
             }
         }
     }
     $item_mgr->commitToDB();
     return $rewards;
 }
 protected function _exec()
 {
     $gameuid = $this->getParam('gameuid', 'int');
     $specId = $this->getParam('specId', 'string');
     $battletype = $this->getParam('battletype', 'string');
     $heroId = $this->getParam('heroid', 'int');
     $rewards = $this->getParam('battlerewards', 'array');
     $itemMgr = new UserGameItemManager($heroId);
     $hero_mgr = new CharacterAccountManager();
     $hero_info = $hero_mgr->getCharacterAccount($heroId);
     $new_hero_info = StaticFunction::resetCurPower($hero_info);
     $totalPower = StaticFunction::getTotalPower(StaticFunction::expToGrade($hero_info['exp']), StaticFunction::expToVip($hero_info['vip']));
     $cur_power = $new_hero_info['power'];
     if ($cur_power < StaticFunction::$power_battle_cost) {
         $this->throwException("power is not enough ,cur power = {$cur_power} , totalpower = {$totalPower} , oldpower = {$heroId}");
     } else {
         $heroChange = array('power' => $cur_power - StaticFunction::$power_battle_cost, 'powertime' => $new_hero_info['powertime']);
         if ($battletype == "Ordinary") {
             $newItemId = $specId;
         } else {
             $newItemId = 100000 + intval($specId);
         }
         $itemInfo = $itemMgr->getItem($newItemId);
         if ($itemInfo['count'] < 3) {
             $this->throwException("this battle spec id {$newItemId} do not have 3 star");
         }
         $itemMgr->subItem("80003", 1);
         foreach ($rewards as $oneReward) {
             if ($oneReward['item_id'] == 'coin') {
                 $userMgr = new UserAccountManager();
                 $userMgr->updateUserCoin($gameuid, $oneReward['count']);
             } else {
                 if ($oneReward['item_id'] == 'exp') {
                     $heroChange['exp'] = $oneReward['count'];
                 } else {
                     $itemMgr->addItem($oneReward['item_id'], $oneReward['count']);
                 }
             }
         }
         $itemMgr->commitToDB();
         $hero_mgr->updateUserStatus($heroId, $heroChange);
         return TRUE;
     }
     return FALSE;
 }
 protected function _exec()
 {
     $gameuid = $this->getParam('gameuid', 'int');
     $name = $this->getParam('name', 'string');
     $itemId = $this->getParam('itemId', 'int');
     $characterId = $this->getParam('characterId', 'int');
     $characterDef = get_xml_def($itemId);
     if (empty($characterDef) || intval($itemId / 10000) != 1) {
         $this->throwException("itemId is not character {$itemId}", GameStatusCode::DATA_ERROR);
     }
     $HeroCost = StaticFunction::$heroCost;
     $user_mgr = new UserAccountManager();
     $user_account = $user_mgr->getUserAccount($gameuid);
     if ($characterId >= count($HeroCost)) {
         $this->throwException("character id not enough characterId: {$characterId} ", GameStatusCode::DATA_ERROR);
     }
     $costcoin = $HeroCost[$characterId]["coin"];
     if ($costcoin > $user_account["coin"]) {
         $this->throwException("user  not enough coin: {$costcoin} ", GameStatusCode::DATA_ERROR);
     }
     $change = array('coin' => -$costcoin);
     $costgem = $HeroCost[$characterId]["gem"];
     if ($costgem > $user_account["gem"]) {
         $this->throwException("user  not enough gem: {$costgem} ", GameStatusCode::DATA_ERROR);
     }
     $change['gem'] = -$costgem;
     $new_CharacterId = intval($gameuid * 10 + $characterId);
     $character_mgr = new CharacterAccountManager();
     $character_info = $character_mgr->getCharacterAccount($new_CharacterId);
     if (!empty($character_info)) {
         $this->throwException("character id is exist characterId: {$new_CharacterId} ", GameStatusCode::DATA_ERROR);
     }
     $character_info = $character_mgr->createCharacterAccount($new_CharacterId, $name, $itemId);
     $itemMgr = new UserGameItemManager($new_CharacterId);
     $initItems = InitUser::$item_arr[$itemId];
     foreach ($initItems as $v) {
         $itemMgr->addItem($v['item_id'], $v['count']);
     }
     $itemMgr->commitToDB();
     $user_mgr->updateUserStatus($gameuid, $change);
     return array("character" => $character_info, "change" => $change);
 }
 protected function _exec()
 {
     $gameuid = $this->getParam('gameuid', 'int');
     $itemId = $this->getParam('itemId', 'int');
     $count = $this->getParam('count', 'int');
     $useGem = $this->getParam('useGem', 'bool');
     $characterId = $this->getParam('heroid', 'int');
     $itemDef = get_xml_def($itemId);
     if (empty($itemDef)) {
         $this->throwException("itemId is not item {$itemId}");
     }
     $cost = 0;
     if ($useGem) {
         $cost = $itemDef['gem'] * $count;
     } else {
         $cost = $itemDef['coin'] * $count;
     }
     if ($cost <= 0) {
         $this->throwException("itemId is no cost  useGem {$useGem} : {$cost}");
     }
     $itemMgr = new UserGameItemManager($characterId);
     $itemMgr->addItem($itemId, $count);
     $user_mgr = new UserAccountManager();
     $user_account = $user_mgr->getUserAccount($gameuid);
     if ($useGem) {
         if ($user_account['gem'] < $cost) {
             $this->throwException("character {$gameuid} not enough gem {$cost}");
         }
         $user_mgr->updateUserMoney($gameuid, -$cost);
     } else {
         if ($user_account['coin'] < $cost) {
             $this->throwException("character {$gameuid} not enough coin {$cost}");
         }
         $user_mgr->updateUserCoin($gameuid, -$cost);
     }
     $itemMgr->commitToDB();
     return array("state" => TRUE);
 }
 protected function _exec()
 {
     $gameuid = $this->getParam('gameuid', 'int');
     $specId = $this->getParam('specId', 'string');
     $battletype = $this->getParam('battletype', 'string');
     $heroId = $this->getParam('heroid', 'int');
     $rewards = $this->getParam('battlerewards', 'array');
     $battleStar = $this->getParam('battleStar', 'int');
     $battleMgr = new BattleManager();
     $cacheInfo = $battleMgr->getBattleCache($heroId);
     if (!empty($cacheInfo)) {
         $cacheInfoArr = explode(":", $cacheInfo);
         if ($cacheInfoArr[2] == 1) {
             $this->throwException("battle has get rewards");
         }
     }
     $battleMgr->setBattleCache($heroId, $specId, $battletype, 1);
     $heroMgr = new CharacterAccountManager();
     $itemMgr = new UserGameItemManager($heroId);
     foreach ($rewards as $oneReward) {
         if ($oneReward['item_id'] == 'coin') {
             $userMgr = new UserAccountManager();
             $userMgr->updateUserCoin($gameuid, $oneReward['count']);
         } else {
             if ($oneReward['item_id'] == 'exp') {
                 $heroMgr->updateUserExperience($heroId, $oneReward['count']);
             } else {
                 $itemMgr->addItem($oneReward['item_id'], $oneReward['count']);
                 $itemMgr->commitToDB();
             }
         }
     }
     //Elite Ordinary
     if ($battleStar > 0 && $battleStar <= 3) {
         if ($battletype == "Ordinary") {
             $newItemId = $specId;
         } else {
             $newItemId = 100000 + intval($specId);
         }
         $itemInfo = $itemMgr->getItem($newItemId);
         if (empty($itemInfo)) {
             $itemMgr->addItem($newItemId, $battleStar);
         } else {
             $oldC = $itemInfo['count'];
             if ($oldC < $battleStar) {
                 $itemMgr->addItem($newItemId, $battleStar - $oldC);
             }
         }
         $itemMgr->commitToDB();
     }
     return TRUE;
 }
 protected function _exec()
 {
     $gameuid = $this->getParam('gameuid', 'int');
     $characterId = $this->getParam('heroid', 'int');
     $pieceItemId = $this->getParam('pieceItemId', 'int');
     $pieceitemDef = get_xml_def($pieceItemId);
     if (empty($pieceitemDef)) {
         $this->throwException("itemId is not item {$pieceItemId}");
     }
     $composeId = $pieceitemDef['boundItem'];
     $composeDef = get_xml_def($composeId);
     if (empty($composeDef)) {
         $this->throwException("composeitemId is not item {$composeId}");
     }
     $itemMgr = new UserGameItemManager($characterId);
     $composeOwnItem = $itemMgr->getItem($composeId);
     $pieceOwnItem = $itemMgr->getItem($pieceItemId);
     $curLevel = 0;
     if (!empty($composeOwnItem)) {
         $curLevel = $composeOwnItem['count'];
     }
     $pieceArr = explode(",", $composeDef['upCount']);
     $needPiece = $pieceArr[$curLevel];
     if ($pieceitemDef['type'] == "skill") {
         $needCoin = StaticFunction::getUpSkillCoin($curLevel);
     } else {
         if ($pieceitemDef['type'] == "soldier") {
             $needCoin = StaticFunction::getUpSoldierCoin($curLevel);
         }
     }
     if (empty($pieceOwnItem) || $pieceOwnItem['count'] < $needPiece) {
         $this->throwException("composeitemId piece is not enough {$pieceItemId}");
     }
     $user_mgr = new UserAccountManager();
     $user_account = $user_mgr->getUserAccount($gameuid);
     if ($user_account['coin'] < $needCoin) {
         $this->throwException("character {$gameuid} not enough coin {$needCoin} ");
     }
     $itemMgr->addItem($composeId, 1);
     $itemMgr->subItem($pieceItemId, $needPiece);
     $user_mgr->updateUserCoin($gameuid, -$needCoin);
     $itemMgr->commitToDB();
     return array("state" => TRUE);
 }
if (!defined('APP_ROOT')) {
    define('APP_ROOT', realpath(dirname(__FILE__)));
}
if (!defined('GAMELIB')) {
    define('GAMELIB', APP_ROOT . '/libgame');
}
if (!defined('FRAMEWORK')) {
    define('FRAMEWORK', APP_ROOT . '/framework');
}
require_once GAMELIB . '/config/GameConfig.class.php';
require_once FRAMEWORK . '/log/LogFactory.class.php';
require_once FRAMEWORK . '/db/RequestFactory.class.php';
require_once GAMELIB . '/GameConstants.php';
require_once GAMELIB . '/model/ManagerBase.class.php';
require_once GAMELIB . '/model/UserAccountManager.class.php';
require_once GAMELIB . '/model/UidGameuidMapManager.class.php';
require_once GAMELIB . '/model/XmlManager.class.php';
require_once GAMELIB . '/model/UserGameItemManager.class.php';
//$gameuid = $_GET['gameuid'];
$gameuid = "151156";
//$change = array("gem"=>1500,"coin"=>5000);
$change = array("gem" => 250, "coin" => 1000);
$user_account_mgr = new UserAccountManager();
$user_account_mgr->updateUserStatus($gameuid, $change);
$item_mgr = new UserGameItemManager($gameuid);
//$item_mgr->addItem("20001","150");
//$item_mgr->addItem("14005","1");
$item_mgr->addItem("20001", "30");
$item_mgr->addItem("14001", "1");
$item_mgr->commitToDB();
echo "ok";