currSeasonMeta = mt\Season::getCurrentSeason(); if (!$this->currSeasonMeta) { $this->_rspErr(10, 'server internal error'); die(); } $this->propertyChgService = new services\PropertyChgService(); $this->awardService = new services\AwardService(); $this->userInfo = $this->_safeGetOrmUserInfo(); $this->seasonService = new services\SeasonService(); if (!$this->seasonService->checkSeason($this->userInfo)) { $this->userInfo = $this->_safeGetOrmUserInfo(); $this->propertyChgService->addUserChg(); } $this->seasonDb = Season::find($this->currSeasonMeta['id']); if (!$this->seasonDb) { Season::add($this->currSeasonMeta['id']); $this->seasonDb = Season::find($this->currSeasonMeta['id']); } if (!$this->seasonDb) { $this->_rspErr(10, 'server internal error'); die(); } $this->seasonCardDb = array( SeasonCard::NORMAL_PACKAGE_ID => SeasonCard::allHash($this->currSeasonMeta['id'], SeasonCard::NORMAL_PACKAGE_ID), SeasonCard::VIP_PACKAGE_ID => SeasonCard::allHash($this->currSeasonMeta['id'], SeasonCard::VIP_PACKAGE_ID), ); } public function info() { $seasonCardMeta = mt\SeasonCard::get($this->seasonDb['card_lv']); $this->_rspData(array( 'info' => array( 'season_id' => $this->currSeasonMeta['id'], 'season_begin_time' => strtotime($this->currSeasonMeta['begin_time']), 'season_end_time' => strtotime($this->currSeasonMeta['end_time']), 'card_lv' => $this->seasonDb ? $this->seasonDb['card_lv'] : 1, 'card_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 0, 'card_max_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 1, 'gift_packages' => $this->getGiftPackages(), 'buy_level_price' => $seasonCardMeta ? $seasonCardMeta['cost'] : 0, 'received_level_rewards1' => $this->getReceivedLevelRewards(SeasonCard::NORMAL_PACKAGE_ID), 'received_level_rewards2' => $this->getReceivedLevelRewards(SeasonCard::VIP_PACKAGE_ID), ) )); } public function getReward() { $type = getReqVal('type', 0); $level = getReqVal('level', 0); $cardMeta = mt\SeasonCard::get($level); if (!$level) { $this->_rspErr(1, 'level parameter error'); return; } if (!in_array($type, array( SeasonCard::NORMAL_PACKAGE_ID, SeasonCard::VIP_PACKAGE_ID ))) { $this->_rspErr(1, 'type parameter error'); return; } if ($level > $this->seasonDb['card_lv']) { $this->_rspErr(2, 'Level not unlocked can not receive'); return; } $cardDb = getXVal($this->seasonCardDb[$type], $level); if ($cardDb) { $this->_rspErr(3, "Can't get it again"); return; } $dropMeta = mt\Drop::get($type == SeasonCard::NORMAL_PACKAGE_ID ? $cardMeta['reward'] : $cardMeta['advanced_reward']); if (!$dropMeta){ $this->_rspErr(4, 'config error'); return; } $this->_scatterDrop('season:level_reward:' . $type . ':' . $level, $dropMeta, $this->awardService, $this->propertyChgService); SeasonCard::add($this->currSeasonMeta['id'], $type, $level); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } public function getAllReward() { $seasonCardMeta = mt\SeasonCard::get($this->seasonDb['card_lv']); $info = array( 'season_id' => $this->currSeasonMeta['id'], 'season_begin_time' => strtotime($this->currSeasonMeta['begin_time']), 'season_end_time' => strtotime($this->currSeasonMeta['end_time']), 'card_lv' => $this->seasonDb ? $this->seasonDb['card_lv'] : 1, 'card_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 0, 'card_max_exp' => $this->seasonDb ? $this->seasonDb['card_exp'] : 1, 'gift_packages' => $this->getGiftPackages(), 'buy_level_price' => $seasonCardMeta ? $seasonCardMeta['cost'] : 0, 'received_level_rewards1' => $this->getReceivedLevelRewards(SeasonCard::NORMAL_PACKAGE_ID), 'received_level_rewards2' => $this->getReceivedLevelRewards(SeasonCard::VIP_PACKAGE_ID), ); $vipPackageBuyed = false; foreach ($info['gift_packages'] as $package) { if ($package['package_id'] == SeasonCard::VIP_PACKAGE_ITEM_ID) { if ($package['state'] == 1) { $vipPackageBuyed = true; } break; } } $cardMeta = $seasonCardMeta; for ($i = 1; $i <= $info['card_lv']; ++$i) { $level = $i; $type = SeasonCard::NORMAL_PACKAGE_ID; { $received1 = array_find($info['received_level_rewards1'], function ($val) use($i) { return $val == $i; }); if (!$received1) { $dropMeta = mt\Drop::get($type == SeasonCard::NORMAL_PACKAGE_ID ? $cardMeta['reward'] : $cardMeta['advanced_reward']); if ($dropMeta){ $this->_scatterDrop('season:level_reward:' . $type . ':' . $level, $dropMeta, $this->awardService, $this->propertyChgService); SeasonCard::add($this->currSeasonMeta['id'], $type, $level); } } } $type = SeasonCard::VIP_PACKAGE_ID; if ($vipPackageBuyed) { $received2 = array_find($info['received_level_rewards2'], function ($val) use($i) { return $val == $i; }); if (!$received2) { $dropMeta = mt\Drop::get($type == SeasonCard::NORMAL_PACKAGE_ID ? $cardMeta['reward'] : $cardMeta['advanced_reward']); if ($dropMeta){ $this->_scatterDrop('season:level_reward:' . $type . ':' . $level, $dropMeta, $this->awardService, $this->propertyChgService); SeasonCard::add($this->currSeasonMeta['id'], $type, $level); } } } } $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } public function buyLevel() { $addLevel = (int)getReqVal('add_level', 0); if ($addLevel < 0) { $this->_rspErr(1, 'add_level parameter error'); return; } $newLevel = $this->seasonDb['card_lv'] + $addLevel; $currCardMeta = mt\SeasonCard::get($this->seasonDb['card_lv']); $newCardMeta = mt\SeasonCard::get($newLevel); if (!$currCardMeta || !$newCardMeta) { $this->_rspErr(2, 'add_level parameter error'); return; } $costItemId = V_ITEM_DIAMOND; $costItemNum = mt\SeasonCard::calcCost($currCardMeta, $newCardMeta); $itemNum = $this->_getItemCount($costItemId, $this->userInfo); if ($itemNum < $costItemNum) { $this->_rspErr(3, 'Diamond shortage'); return; } $this->_decItems(array( array( 'item_id' => $costItemId, 'item_num' => $costItemNum ) )); Season::updateCardLv($this->currSeasonMeta['id'], $newLevel); $this->propertyChgService->addUserChg(); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } public function buyGiftPackage() { $packageId = getReqVal('package_id', 0); $costItemId = getReqVal('cost_item_id', 0); $giftPackage = array_find($this->getGiftPackages(), function ($val) use($packageId) { if ($val['package_id'] == $packageId) { return true; } return false; }); if (!$giftPackage) { $this->_rspErr(1, 'pacakge_id parameter error'); return; } if ($giftPackage['state'] == 1) { $this->_rspErr(2, 'Cannot repeat purchase'); return; } $priceInfo = $giftPackage['price_info']; if (empty($priceInfo)) { $this->_rspErr(3, 'config error'); return; } $itemMeta = mt\Item::get($giftPackage['item_id']); if (empty($itemMeta)) { $this->_rspErr(3, 'config error1'); return; } $dropMeta = mt\Drop::get($itemMeta['drop']); if (empty($dropMeta)) { $this->_rspErr(3, 'config error3'); return; } $costItems = mt\Item::getCostItems($priceInfo, $costItemId); if (empty($costItems)) { $this->_rspErr(3, 'config error2'); return; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(4, $this->_getLackItemErrMsg($lackItem)); return; } Season::updateGiftPackageState($this->currSeasonMeta['id'], $packageId); $this->_decItems($costItems); $this->_scatterDrop('season:gift_package:' . $packageId, $dropMeta, $this->awardService, $this->propertyChgService); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } private function getGiftPackages() { $itemMeta = mt\Item::get(SeasonCard::VIP_PACKAGE_ITEM_ID); $priceInfo = $itemMeta ? mt\Item::getPriceInfo($itemMeta) : null; $giftPackages = array( array( 'package_id' => SeasonCard::VIP_PACKAGE_ID, 'item_id' => SeasonCard::VIP_PACKAGE_ITEM_ID, 'state' => $this->seasonDb['gift_state2'], 'price_info' => $priceInfo ? $priceInfo['price_info'] : null ) ); return $giftPackages; } private function getReceivedLevelRewards($type) { $levels = array(); foreach (getXVal($this->seasonCardDb, $type, array()) as $val) { array_push($levels, $val['card_lv']); } return $levels; } }