/** * 公会建筑升级 */ public function build_upgrade($player_id, $union_id, $npc_sid) { $npc_sid = intval($npc_sid); $union_id = intval($union_id); $objUnionInfoData = $this->get_data('UnionInfo'); $unionInfo = $objUnionInfoData->get_union_info($union_id); $objUnionPlayerData = $this->get_data('UnionPlayer'); $unionPlayerInfo = $objUnionPlayerData->get_union_player_info($union_id, $player_id); if (empty($unionPlayerInfo)) { $this->throw_error('171001'); //该玩家未加入该公会 } if ($unionPlayerInfo["job_id"] > 2) { $this->throw_error('170701'); //无权操作 } $build_type = $this->get_game('Union')->get_build_type($npc_sid); if (!$build_type) { $this->throw_error('173601'); //不存在该建筑 } //当前建筑ID对应的Redis字段 $redisLevelField = $build_type . "_level"; //当前建筑等级,默认等级为1级 $unionInfo[$redisLevelField] = intval($unionInfo[$redisLevelField]) ? $unionInfo[$redisLevelField] : 1; $front_upgrade_level = $unionInfo[$redisLevelField]; $objUnionBuildConfig = Cache_UnionBuild::getInstance(); $unionBuildLevelConfig = $objUnionBuildConfig->get_union_build_info($npc_sid, $unionInfo[$redisLevelField]); //1.公会资金2.经验 if ($unionBuildLevelConfig['lvl_up_cost_type'] != 1) { $this->throw_error('173603'); //该建筑不能升级 } $max_level = $objUnionBuildConfig->get_union_build_max_level($build_type); if ($unionInfo[$redisLevelField] >= $max_level) { $this->throw_error('173602'); //建筑已升级到最大等级 } if (empty($unionBuildLevelConfig)) { $this->throw_error('10222'); //配置错误 } $unionInfo[$redisLevelField] += 1; if ($unionInfo[$redisLevelField] > $unionInfo['union_level']) { $this->throw_error('173504'); //该建筑等级不能大于公会大厅等级 } //1.公会资金2.经验 if ($unionInfo['fund'] < $unionBuildLevelConfig['lvl_up_cost_num']) { $this->throw_error('173503'); } $unionInfo['fund'] = "-" . $unionBuildLevelConfig['lvl_up_cost_num']; //更改升级后的npc_sid $npc_sid = $this->get_game('Union')->get_build_sid($build_type, $unionInfo[$redisLevelField]); $unionInfo[$build_type . '_sid'] = $npc_sid; $this->start_trans(); Com_Log::debug_write('update_union_info', "build_upgrade|unoin_id={$union_id}" . json_encode($unionInfo)); $retUnionInfo = $objUnionInfoData->update_union_info($union_id, $unionInfo); if ($retUnionInfo) { $this->commit(); $this->get_game('Union')->Sync_Union_msg($union_id); } else { $this->rollback(); $this->throw_error('10101'); } if ($build_type == "shop") { $this->get_game('UnionShop')->union_shop_upgrade($union_id, $unionInfo[$redisLevelField]); //公会成就商店升级 $this->get_game('UnionAchieve')->async_trigger_union_achieve($player_id, 20, $unionInfo[$redisLevelField], 2); } else { if ($build_type == "hall") { //福利大厅 $this->get_game('UnionAchieve')->async_trigger_union_achieve($player_id, 21, $unionInfo[$redisLevelField], 2); } else { if ($build_type == "wanted") { //通缉 $this->get_game('UnionAchieve')->async_trigger_union_achieve($player_id, 14, $unionInfo[$redisLevelField], 2); } else { if ($build_type == "tech") { //魔法科技 $this->get_game('UnionAchieve')->async_trigger_union_achieve($player_id, 22, $unionInfo[$redisLevelField], 2); //魔法科技-流水日志 $log_data = array('player_id' => $player_id, 'channel' => 54, 'type' => 6, 'item_id' => 0, 'item_num' => $unionInfo[$redisLevelField] - $front_upgrade_level, 'amount' => $front_upgrade_level, 'after_amount' => $unionInfo[$redisLevelField], 'cmd_id' => 1732); Log_Common::getInstance()->add_log($log_data); } } } } //发邮件 /* $phrase_id = 1000 + $unionInfo[$redisLevelField]; $phrase_config = Cache_FuncPhraseConfig::getInstance()->get_phrase_config_info($phrase_id); $this->get_game('UnionPlayer')->send_mail($player_id,$union_id, $phrase_config['title'], $phrase_config['content'],false); */ //添加日志 //%player_name% 消耗了 %s 公会资金升级了公会建筑 %d //广播建筑升级 $arr_replace = array(); $arr_replace[] = array('rep_type' => 7, 'txt' => $unionBuildLevelConfig['build_name']); $arr_replace[] = array('rep_type' => 7, 'txt' => $unionInfo[$redisLevelField]); $msg = Language_Message::make_message(171015, $arr_replace); $this->get_game('SystemNotice')->send_system_msg($player_id, $msg, 7, 7); $arr_replace = array(); $arr_replace[] = array('rep_type' => 0, 'rep_val' => $player_id); $arr_replace[] = array('rep_type' => 7, 'txt' => $unionBuildLevelConfig['lvl_up_cost_num']); $arr_replace[] = array('rep_type' => 7, 'txt' => $unionBuildLevelConfig['build_name']); $objUnionBaseGame = $this->get_game('UnionBase'); $objUnionBaseGame->sys_add_union_log($player_id, $union_id, 173604, $arr_replace); return array($union_id, $npc_sid, $unionInfo[$redisLevelField]); }
/** * @Purpose: * 公会商店购买 * @Param $player_id 玩家ID * @Param $shop_id 商品ID * @Param $type 商品类型 * @Param $num 购买数量 */ public function union_shop_buy($player_id, $shop_id, $type, $num) { $player_id = intval($player_id); if ($num < 1) { $this->throw_error('10107'); #参数错误 } #获取玩家公会ID,验证公会信息 $union_id = $this->get_data('Player')->get_player_info($player_id, 'union_id'); if ($union_id < 1) { $this->throw_error('171101'); #未加入公会 } #获取商店数据 $data = $this->get_data('UnionShop')->get_union_shop_info($union_id); if (!$data) { $this->throw_error('10110'); #数据错误 } $shop_type = ''; $type = intval($type); if ($type == 1) { $shop_type = 'prop_info'; $data['player_buy_info'] = Com_FmtData::cus_json_decode($data['player_buy_info']); } else { if ($type == 2) { $shop_type = 'buff_info'; } else { $this->throw_error('1715001'); #购买失败 } } if ($data[$shop_type] && !is_array($data[$shop_type])) { $data[$shop_type] = json_decode($data[$shop_type], true); } $shop_id = intval($shop_id); #BUFF存在 if ($type == 2 && $data[$shop_type][$shop_id]['record'][$player_id]) { $this->throw_error('1715001'); #购买失败 } #商品验证 if (!$data[$shop_type][$shop_id]) { $this->throw_error('1715005'); #道具不足 } #商品是否解锁 if ($data[$shop_type][$shop_id]['state'] != 1) { $this->throw_error('1715004'); #道具未解锁 } #购买职务验证 #获取玩家公会职务 $player_data = $this->get_data('UnionPlayer')->get_union_player_info($union_id, $player_id); $job = $player_data['job_id']; if ($job > $data[$shop_type][$shop_id]['job_level']) { $this->throw_error('1715003'); #职务过低 } #获取公会商店等级 $shop_level = $this->get_data('UnionInfo')->get_union_info($union_id, 'shop_level'); #本次更新每个玩家可以购买的道具上限验证 $union_build_table = Cache_UnionBuild::getInstance()->get_union_build_info_two(array('build_type' => 'shop', 'build_lvl' => $shop_level)); if ($union_build_table['buy_limit'] > 0 && $data['player_buy_info'][$player_id] + $num > $union_build_table['buy_limit']) { $this->throw_error('1715009'); #本次刷新购买次数已满 } $time = time(); #道具数量验证 if ($data[$shop_type][$shop_id]['num'] < $num) { #刷新时间验证 if ($type == 1) { $next_refresh = 0; $update_prop_res = $this->check_shop_refresh($data['refresh_time'], $data[$shop_type], $next_refresh, $shop_level); if ($update_prop_res) { $update_data['refresh_time'] = $data['refresh_time']; #更新玩家购买次数 $data['player_buy_info'] = array(); } else { $this->throw_error('1715005'); #道具不足 } } else { if ($type == 2) { $record = $data[$shop_type][$shop_id]['record']; if (Com_Array::is_good_arr($record)) { foreach ($record as $pid => $re) { if ($time >= $re['expired_time']) { #增加商品数量 if ($data[$shop_type][$shop_id]['num'] + 1 < $data[$shop_type][$shop_id]['num_max']) { $data[$shop_type][$shop_id]['num']++; } else { $data[$shop_type][$shop_id]['num'] = $data[$shop_type][$shop_id]['num_max']; } #清除玩家购买记录 unset($data[$shop_type][$shop_id]['record'][$pid]); } } } #道具数量验证 if ($data[$shop_type][$shop_id]['num'] < $num) { $this->throw_error('1715005'); #道具不足 } /* #获取公会商店等级 $shop_level = $this->get_data('UnionInfo')->get_union_info($union_id, 'shop_level'); #获取商店配置表 $shop_table = $this->get_cache_table_data('shop_table', array('level' => $shop_level, 'type' => $type)); if (!$shop_table || !$shop_table[0]['refresh_time']) { $this->throw_error('10109'); //配置表读取错误 } $next_time = $data[$shop_type][$shop_id]['next_refresh_time']; $refresh_time = $shop_table[0]['refresh_time'] * 3600; #更新下次刷新时间 $data[$shop_type][$shop_id]['next_refresh_time'] = $time + ($refresh_time - intval(($time - $next_time) % $refresh_time)); */ } else { $this->throw_error('1715005'); #道具不足 } } } #玩家贡献度验证 #获取玩家贡献度 $player_data = $this->get_data('UnionPlayer')->get_union_player_info($union_id, $player_id); if ($data[$shop_type][$shop_id]['contribution'] * $num > $player_data['total_dedicate']) { $this->throw_error('1715006'); #贡献度不足 } $player_name = $this->get_data('Player')->get_player_info($player_id, "name"); if ($type == 2) { #获取商店配置表 $shop_table = $this->get_cache_table_data('shop_table', array('level' => $shop_level, 'type' => $type)); if (!$shop_table || !$shop_table[0]['refresh_time']) { $this->throw_error('10109'); //配置表读取错误 } $refresh_time = $time + $shop_table[0]['refresh_time'] * 3600; #更新购买记录 $data[$shop_type][$shop_id]['record'][$player_id]['player_name'] = $player_name; $data[$shop_type][$shop_id]['record'][$player_id]['job'] = $job; $data[$shop_type][$shop_id]['record'][$player_id]['buy_time'] = $time; $data[$shop_type][$shop_id]['record'][$player_id]['expired_time'] = $refresh_time; } #扣除商品数量 $data[$shop_type][$shop_id]['num'] -= $num; #扣除贡献度 $front_amount_dedicate = $player_data['total_dedicate']; $dedicate = $data[$shop_type][$shop_id]['contribution'] * $num; $player_data['total_dedicate'] -= $dedicate; #增加公会记录 $arr_replace = array(); $arr_replace[] = array('rep_type' => 0, 'rep_val' => $player_id); $arr_replace[] = array('rep_type' => 7, 'txt' => $data[$shop_type][$shop_id]['name'], 'rep_color' => "ffb901"); $this->get_game('UnionBase')->sys_add_union_log($player_id, $union_id, 1715007, $arr_replace); $this->start_trans(); if ($type == 1) { #发道具 $prop_info[] = array('type' => 'prop', 'item_id' => $data[$shop_type][$shop_id]['prop_id'], 'item_num' => $num); if (Com_Array::is_good_arr($prop_info)) { $result = $this->get_game('Reward')->send_reward($player_id, $prop_info, array('cmd_id' => '1715'), 1); if ($result !== true) { $this->throw_error('10104'); } } #记录玩家购买次数 $data['player_buy_info'][$player_id] += $num; $update_data['player_buy_info'] = json_encode($data['player_buy_info']); } $update_data[$shop_type] = json_encode($data[$shop_type]); #更新商店 $this->get_data('UnionShop')->update_union_shop($union_id, $update_data); #更新玩家贡献度 $this->get_data('UnionPlayer')->update_union_player_info($union_id, $player_id, $player_data); //公会贡献-流水日志 $log_data = array('player_id' => $player_id, 'channel' => 16, 'type' => 2, 'item_id' => 11, 'item_num' => $dedicate, 'amount' => $front_amount_dedicate, 'after_amount' => $player_data['total_dedicate'], 'cmd_id' => 1715); Log_Common::getInstance()->add_log($log_data); $this->commit(); if ($type == 1) { $this->get_game('Reward')->add_reward_log(); } else { if ($type == 2) { #通知C++给玩家增加BUFF Protocol::input($player_id, 7, 4, 490, array('0' => $player_id, '1' => $data[$shop_type][$shop_id]['prop_id'])); } } $this->update_temporary_data($data); return array('0' => 1, '1' => $data[$shop_type][$shop_id]['prop_id']); }