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;
 }
 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');
     $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);
 }
 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);
 }
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";