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');
     $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);
 }
 protected function _exec()
 {
     $gameuid = $this->getParam('gameuid', 'int');
     $heroid = $this->getParam('heroid', 'int');
     $name = $this->getParam('name', 'string');
     $user_clan_mgr = new UserClanManager();
     $clanInfo = $user_clan_mgr->getUserClanInfo($heroid);
     if (!empty($clanInfo)) {
         $this->throwException("user {$heroid} already have clan ");
     }
     $account_mgr = new UserAccountManager();
     $account_info = $account_mgr->getUserAccount($gameuid);
     if ($account_info['gem'] < 20) {
         $this->throwException("user {$gameuid} not enough gem to buy Clan ");
     }
     $clan_mgr = new ClanManager();
     $result = $clan_mgr->creatClan($heroid, $name);
     $user_clan_info = $user_clan_mgr->creatUserClan($heroid, $result['data_id']);
     $account_mgr->updateUserMoney($gameuid, 20);
     $hero_mgr = new CharacterAccountManager();
     $result['admin'] = $hero_mgr->getCharacterAccount($heroid);
     $result['membersArr'] = array($user_clan_info);
     return array('clan' => $result);
 }
Пример #7
0
 public function __construct()
 {
     self::$cdir = dirname(__FILE__);
     self::$tfile = self::$cdir . '/' . self::tPage;
 }
 /**
  * @param $params
  */
 public function execute($params = null)
 {
     try {
         if ($this->isServiceClosed($params['gameuid'])) {
             return $this->getReturnArray(GameStatusCode::SYSTEM_MAINTAIN, 'service closed.');
         }
         //				return $this->getReturnArray(0,'ok',"test");
         if (isset($params['gameuid'])) {
             $gameuid = intval($params['gameuid']);
             if ($gameuid <= 0) {
                 $this->throwException("user[{$gameuid}] not exists", GameStatusCode::USER_NOT_EXISTS);
             }
             if (isset($params['friend_gameuid'])) {
                 if (empty($params['friend_gameuid']) || $params['friend_gameuid'] <= 0) {
                     $this->throwException("friend user[" . $params['friend_gameuid'] . "] not exist", GameStatusCode::USER_NOT_EXISTS);
                 }
             }
             $this->action_logger = new UserActionLogManager($gameuid);
             $this->user_account = $this->user_account_mgr->getUserAccount($gameuid);
             if (empty($this->user_account)) {
                 $this->throwException("user[{$gameuid}] not exists", GameStatusCode::USER_NOT_EXISTS);
             }
             //				//是否被禁用
             //				if($this->user_account['disabled'] == "1"){
             //					return $this->getReturnArray(GameStatusCode::USER_NOT_EXISTS,"user[$gameuid] is disbaled.");
             //				}
             //				$this->checkSession($gameuid);
         }
         // 对参数做处理
         $this->params = $params;
         //			if(!$this->isPerfTestMode($params['gameuid'])){
         //				if(!get_app_config()->getGlobalConfig("debug_mode")){
         //					$this->checkSignature($params);
         //				}
         //				$this->validate();
         //			}
         $now = time();
         //调用游戏接口
         $result = $this->_exec();
         //			// 根据动作的定义,获取用户的经验值和金币的修改值
         //			$modify = array_intersect_key($result,array('coin'=>0,'money'=>0,'coupon'=>0,'experience'=>0));
         //			if (isset($this->params['action_id'])) {
         //		       	if (intval($this->action_def['coin']) != 0) $modify['coin'] += intval($this->action_def['coin']);
         //		       	if (intval($this->action_def['experience']) != 0) $modify['experience'] += intval($this->action_def['experience']);
         //			}
         //
         //		    //修改用户的经验值和金币数量
         //		    if (count($modify) > 0) {
         //		       	$this->user_account_mgr->updateUserStatus($gameuid, $modify);
         //		       	$result = array_merge($result, $modify);
         //		    }
         //
         //			//检查action是否要进行计数
         //			if (isset($this->params['action_id'])&&in_array($this->params['action_id'], $this->action_record_count)){
         //				UserActionCountManager::updateActionCount($this->params['gameuid'],$this->params['action_id']);
         //			}
         //			//判断是否要写actionlog日志
         //			if (!empty($modify) && isset($this->params['action_id'])){
         //				$action_log_params=array();
         //				$action_log_params=$modify;
         //				if (isset($result['action_log_params'])){
         //					$action_log_params['content']=$result['action_log_params']['content'];
         //					unset($result['action_log_params']);
         //				}
         //				$this->action_logger->writeLog($this->params['action_id'], $action_log_params);
         //			}
         //如果有eventlog,则写log日志,同时将返回值中的相关信息删除
         if (isset($result['event_log_params']) && is_array($result['event_log_params'])) {
             $event_log_params = $result['event_log_params'];
             $event_gameuid = $event_log_params['gameuid'];
             $event_action_id = $event_log_params['action_id'];
             $event_params = $event_log_params['params'];
             $event_logger = new UserEventLogManager($event_gameuid);
             $event_logger->writeLog($event_action_id, $event_params);
             unset($result['event_log_params']);
         }
         return $this->getReturnArray(0, 'ok', $result);
     } catch (DBException $e) {
         // 数据库类型的错误特殊处理
         $this->logger->writeError("database exception happens while execute sql, error_msg:" . $e->getMessage());
         $this->logger->writeError("and the stack trace is as below:\n" . $e->getTraceAsString());
         if (get_app_config()->getGlobalConfig("debug_mode")) {
             return $this->getReturnArray(GameStatusCode::DATABASE_ERROR, $e->getMessage());
         } else {
             return $this->getReturnArray(GameStatusCode::DATABASE_ERROR, 'database error');
         }
     } catch (GameException $e) {
         $this->logger->writeError("game exception happens while execute action:" . $e);
         //log输出过多,关闭之
         return $this->getReturnArray($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         // 其他的错误
         $this->logger->writeError("unknown exception happens while execute action." . $e->getTraceAsString());
         return $this->getReturnArray(GameStatusCode::UNKNOWN_ERROR, $e->getMessage());
     }
     return $this->getReturnArray(GameStatusCode::UNKNOWN_ERROR, '');
 }
 /**
  *
  * @return int
  */
 private function initSeq()
 {
     $key = $this->getMemKey();
     $seq = $this->cache->get($key);
     if ($seq === FALSE) {
         $sql = sprintf("select LAST_INSERT_ID() from %s", $this->table_name);
         $value = $this->dbhelper->resultFirst($sql);
         if (!empty($value)) {
             $seq = $value['gameuid'];
         }
     }
     if ($seq != FALSE && $seq >= 1) {
         $user_mgr = new UserAccountManager();
         $account = $user_mgr->getUserAccount($seq);
         $nexAccount = $user_mgr->getUserAccount($seq);
     }
     if (empty($account) || !empty($nexAccount)) {
         $sql = sprintf("select ifnull(max(%s),0) max_value from %s", "gameuid", $this->table_name);
         $res = $this->dbhelper->getOne($sql);
         $seq = $res['max_value'];
     }
     return $seq;
 }
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";