/** * 创建公会 */ public function create_union($player_id, $name, $introduce) { $unionCreatConfig = Cache_UnionCreat::getInstance()->get_union_creat(1); $field = Cache_FbLoot::getInstance()->get_item_key($unionCreatConfig['cost_type']); $this->start_trans(); $objUnionInfoData = $this->get_data('UnionInfo'); $objPlayerData = $this->get_data('Player'); $playerInfo = $objPlayerData->get_player_info($player_id, array('career_type', "ticket", "union_id", "level", "vip", "privilege_level", "union_id", "name", "sum_fpower", $field)); $arr_consume = array(); // 检查是否满足创建公会 $this->check_create_union($player_id, $name, $introduce, $playerInfo, $unionCreatConfig, $arr_consume); //添加公会信息 $union = array(); $union_id = $this->get_data('Account')->get_new_union_id(); $union = $objUnionInfoData->get_upgrade_level_by_exp(1, 0); $union['union_id'] = $union_id; $union['union_name'] = $name; $union['union_introduce'] = $introduce; $union['create_player_id'] = $player_id; $union['create_player_name'] = $playerInfo['name']; $union['player_num'] = 1; $union['fund'] = 0; $union['add_time'] = time(); if (!$union_id) { $this->get_data('UnionInfo')->delete_union_info($union_id); $this->throw_error('10101'); } foreach ($this->_build_redis_prefix as $build_type) { $union[$build_type . '_level'] = 1; } foreach ($this->_build_redis_prefix as $build_type) { $union[$build_type . '_sid'] = $this->get_game('Union')->get_build_sid($build_type, 1); } $quit_time = 0; $objUnionPlayerHisData = $this->get_data('UnionPlayerHis'); $playerHisData = $objUnionPlayerHisData->get_union_player_info($player_id); if ($playerHisData) { $quit_time = $playerHisData['quit_time']; $retUnionPlayerHisInfo = $objUnionPlayerHisData->del_union_player($player_id); } Com_Log::debug_write('update_union_info', "create_union|unoin_id={$union_id}" . json_encode($union)); //添加公会信息 $retUnionInfo = $objUnionInfoData->update_union_info($union_id, $union); //添加公会成员信息 $unionPlayer = array(); $unionPlayer['player_id'] = $player_id; $unionPlayer['job_id'] = 1; $unionPlayer['total_dedicate'] = 0; //总贡献 $unionPlayer['rep_time'] = time(); $unionPlayer['add_time'] = time(); $unionPlayer['quit_time'] = $quit_time; $objUnionPlayerData = $this->get_data('UnionPlayer'); $retUnionPlayerInfo = $objUnionPlayerData->update_union_player_info($union_id, $player_id, $unionPlayer); $setPlayerInfo = array("union_id" => $union_id, "union_name" => $name, "union_job" => $unionPlayer['job_id']); $retPlayerInfo = $this->get_data('Player')->update_player_resource($player_id, $playerInfo, 1701, $setPlayerInfo, $arr_consume); if ($retUnionPlayerInfo && $retUnionInfo && $retPlayerInfo) { $this->commit(); Protocol_Player::p2c_part_update($player_id, array('union_id' => $union_id, 'union_name' => $name, 'union_job' => $unionPlayer['job_id'], 'attr' => array(), 'player_data' => array('player' => array('career_type' => $playerInfo['career_type'], 'level' => $playerInfo['level'])))); $objUnionInfoData->add_union_base_todb($union); $this->get_data('UnionInfo')->set_union_weight($union_id, $union); $this->get_game('Union')->Sync_Union_msg($union_id); $this->get_game('UnionBoonHall')->init_union_boon_hall($union_id); $this->get_game('UnionShop')->init_union_shop($union_id); $this->get_game('UnionWanted')->init_player_union_wanted($player_id, $union_id); //个人通缉榜数据 $this->get_game('UnionActivities')->init_union_activities_info($union_id); $this->get_game('UnionGuide')->active_push_union_guide_info($player_id); } else { $this->rollback(); $this->throw_error('10101'); } //玩家今日贡献 $this->get_data("PlayerDailyTime")->set_used_time($player_id, "union_player_contribute", 0); //公会成就任务 $challenge_rank = $this->get_game('Challenge')->get_challenge_real_rank($player_id); $this->get_game('UnionAchieve')->async_trigger_union_achieve($player_id, 5, $challenge_rank, 3); $this->get_game('UnionAchieve')->async_trigger_union_achieve($player_id, 1, 1, 2); $this->get_game('UnionAchieve')->async_trigger_union_achieve($player_id, 7, $playerInfo['level'], 2); #引导任务 $this->get_game('TaskTrigger')->async_trigger_guide_task($player_id, 8, 1); $this->get_data("Player")->del_no_union_player($player_id); #公会成员战力 $this->get_data("UnionInfo")->set_union_player_sum_fpower($union_id, $player_id, $playerInfo['sum_fpower']); return array(1, $union_id); }
/** * 邀请加入公会 * @param unknown $player_id * @param unknown $invite_id */ public function send_invite_union_notice($player_id, $invite_id, $keyword) { $player_id = intval($player_id); $invite_id = intval($invite_id); if ($invite_id == 0) { $keyword = addslashes(trim($keyword)); $invite_id = $this->get_data("Account")->get_pid_byname($keyword); if (empty($invite_id)) { $this->throw_error('70118'); //未查找到该用户 } } //加锁 if (!Com_Lock::lock('lock|union_invite|invite_id=' . $invite_id)) { //系统繁忙 //$this->throw_error('170501'); } $objPlayerData = $this->get_data('Player'); $player_info = $objPlayerData->get_player_info($player_id, array("union_id", "name", "union_name", "level")); if (!$player_info['union_id']) { $this->throw_error('171101'); //没有加入公会 } $objUnionPlayerData = $this->get_data('UnionPlayer'); $unionPlayeInfo = $objUnionPlayerData->get_union_player_info($player_info['union_id'], $player_id); if ($unionPlayeInfo['job_id'] > 2) { $this->throw_error('178501'); //没有加入公会 } $objPlayerData = $this->get_data('Player'); $invite_info = $objPlayerData->get_player_info($invite_id, array("union_id", "level", "is_online")); if (empty($invite_info['level'])) { $this->throw_error('70110'); //不存在该用户 } $unionCreatConfig = Cache_UnionCreat::getInstance()->get_union_creat(2); if ($invite_info['level'] < $unionCreatConfig['level_need']) { $this->throw_error('170110'); //level等级不足 } if (intval($invite_info['union_id']) > 0) { $this->throw_error('178502'); //已加入公会 } $unionInfo = $this->get_data('UnionInfo')->get_union_info($player_info['union_id'], array("union_level")); $arr_replace = array(array('rep_type' => 0, 'txt' => $player_info['name'], 'rep_val' => $player_id), array('rep_type' => 7, 'txt' => $player_info['level']), array('rep_type' => 7, 'txt' => $unionInfo['union_level']), array('rep_type' => 7, 'txt' => $player_info['union_name'])); #某玩家(LV.8)邀请你加入8 级公会[公会第一] $msg = Language_Message::make_message(178505, $arr_replace); $add_data = array(); $add_data['union_id'] = $player_info['union_id']; $add_data['rep_content'] = $msg; $add_data['add_time'] = time(); $this->get_data("UnionInvite")->add_union_invite($invite_id, $add_data); $this->get_data('NewsTips')->update_player_tips($invite_id, 12, array("num" => 1)); /* if(intval($invite_info['is_online'])==0){ $this->throw_error('178503'); //对方离线 } Protocol::input($invite_id,8,17,1786,array($player_info['name'],$player_id,$player_info['union_name'],$player_info['union_id'])); */ return array('result' => 1); }