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()
 {
     $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()
 {
     $characterId = $this->getParam('heroid', 'int');
     $clanID = $this->getParam('clanId', 'int');
     $userClanMgr = new UserClanManager();
     $userclaninfo = $userClanMgr->getUserClanInfo($characterId);
     if (empty($userclaninfo) || $userclaninfo['bossTime'] > time()) {
         $this->throwException("hero has attack boss today ");
     }
     $bossMgr = new ClanBossManager();
     $boosInfo = $bossMgr->getCurClanBoss();
     $curTime = $boosInfo['Date'];
     //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']);
         $rateMgr = new RatingClanManager();
         $clanRateInfo = $rateMgr->getClanRate($clanID);
         if (empty($clanRateInfo)) {
             $newclanRate = array('id' => $clanID, 'date' => $curTime, 'level' => 1, 'kills' => 0);
             $rateMgr->addNewClanRate($clanID, $newclanRate);
         } else {
             if ($clanRateInfo['date'] == $curTime) {
                 $newclanRate = $clanRateInfo;
             } else {
                 $newclanRate = array('id' => $clanID, 'date' => $curTime, 'level' => 1, 'kills' => 0);
                 $rateMgr->updateClanRate($clanID, $newclanRate);
             }
         }
         $battleMgr = new BattleManager();
         $battleMgr->setBattleCache($characterId, $curTime, 1, 0);
         $hero_mgr->updateUserStatus($characterId, $heroChange);
         //bossTime
         $userclaninfo['bossTime'] = strtotime("next day");
         $userClanMgr->updateUserClan($userclaninfo);
         $heroChange['clanRateInfo'] = $newclanRate;
         $heroChange['bossData'] = $boosInfo;
         return $heroChange;
     }
 }
 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()
 {
     $enemyId = $this->getParam('enemyId', 'string');
     $characterId = $this->getParam('heroid', 'int');
     $hero_mgr = new CharacterAccountManager();
     $hero_info = $hero_mgr->getCharacterAccount($characterId);
     $vipLevel = StaticFunction::expToVip($hero_info['vip']);
     $vipDATA = StaticFunction::$VipList[$vipLevel];
     $maxPkCOUNT = $vipDATA['pkAddCount'];
     $cacheInfo = $hero_mgr->getVipCache($characterId);
     $usedCount = 0;
     if (!empty($cacheInfo) && $cacheInfo['time'] > time()) {
         $usedCount = $cacheInfo['pkAddCount'];
         $newCacheInfo = $cacheInfo;
     } else {
         $newCacheInfo['time'] = strtotime(date("Y-m-d", strtotime("+1 day")));
     }
     $newCacheInfo['pkAddCount'] = $usedCount + 1;
     if ($maxPkCOUNT <= $usedCount) {
         $this->throwException("pk too much used {$usedCount} , total = {$maxPkCOUNT}");
     } else {
         $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);
             $hero_mgr->setVipCache($characterId, $newCacheInfo);
             $battleMgr = new BattleManager();
             $battleMgr->setBattleCache($characterId, $enemyId, 2, 0);
             $heroChange['vipCache'] = $newCacheInfo;
             return $heroChange;
         }
     }
 }
 public static function getCharacterLevel($exp)
 {
     return StaticFunction::expToGrade($exp);
 }
Exemplo n.º 8
0
<?php

class StaticFunction
{
    static function not_dead()
    {
        echo "not dead\n";
    }
    static function is_dead()
    {
        echo "dead\n";
    }
}
StaticFunction::not_dead();
 public static function resetCurPower($hero_info)
 {
     $power = $hero_info['power'];
     $powertime = $hero_info['powertime'];
     $totalPower = StaticFunction::getTotalPower(StaticFunction::expToGrade($hero_info['exp']), StaticFunction::expToVip($hero_info['vip']));
     $curpower = 0;
     if ($power >= $totalPower) {
         $curpower = $power;
     } else {
         $curpower = $power + floor((time() - $powertime) / StaticFunction::$POWER_CYCLE);
         $curpower = min($curpower, $totalPower);
     }
     $hero_info['power'] = $curpower;
     $hero_info['powertime'] = time();
     return $hero_info;
 }
function additems($gameuid, $item_id, $uid, $name)
{
    $item_def = get_xml_def($item_id, XmlDbType::XMLDB_ITEM);
    if (empty($item_def['matchPoint'])) {
        return 0;
    } else {
        include_once GAMELIB . '/model/activity/UserMedalManager.class.php';
        include_once GAMELIB . '/model/UserPickUpBonusManager.class.php';
        //每次新大赛都要会实例化第几个表
        $user_medal = new UserMedalManager(8);
        $user_pick = new UserPickUpBonusManager();
        $item = explode("|", $item_def['matchPoint']);
        $rand_arr = array();
        foreach ($item as $v) {
            $add_item = explode(":", $v);
            $rand_arr[$add_item[0]] = $add_item[1];
        }
        $count = StaticFunction::getOneByRate($rand_arr);
        if ($count > 0) {
            $user_medal->addMedal($gameuid, $uid, $name, $count);
            $user_pick->setPickUpCache($gameuid, 'special', $count);
        }
        return $count;
    }
}