/** * 格式化奖励道具格式 * @Param $prop_list 奖励道具列表 */ public static function format_send_prop($prop_list) { $prop_info = array(); if (Com_Array::is_good_arr($prop_list)) { foreach ($prop_list as $prop) { $type = Cache_Currency::getInstance()->get_key($prop['id']); if ($type) { $prop_info[] = array('type' => $type, 'item_id' => $prop['id'], 'item_num' => $prop['num']); } else { $prop_info[] = array('type' => 'prop', 'item_id' => $prop['id'], 'item_num' => $prop['num']); } } } return $prop_info ? $prop_info : array(); }
public function sync($data) { if (empty($data)) { return; } $data = json_decode($data, true); if (!isset($data['player_id'])) { return; } $player_id = $data['player_id']; $arr_update = $data['arr_update']; $gateway = $data['gateway']; //测试环境 推送到不同的gateway // echo $gateway."\n"; SynPlayer::init($player_id); SynPlayer::set_player($player_id); if (isset($arr_update['load']) && $arr_update['load'] == 1) { #登陆的时候加载下数据 SynPlayer::init_syn_data(null); SynPlayer::set_syn_data($arr_update['init_data']); return; } ######################################################## $objPlayerBase = $this->get_game('PlayerBase'); $objFpowerCalc = $this->get_game('FpowerCalc'); $objPlayer = $this->get_data('Player'); $objDetail = $this->get_data('PlayerDetail'); $objPlayerSkill = $this->get_game('PlayerSkill'); $objPlayerAchieve = $this->get_game('PlayerAchieve'); $objFairy = $this->get_data('Fairy'); $objHero = $this->get_game('Hero'); $objPlayerHero = $this->get_data('PlayerHero'); $objPlayerWing = $this->get_game('PlayerWing'); ######################################################## $player_detail = null; $playerInfo = null; if (isset($arr_update['player_data'])) { $player_detail = $arr_update['player_data']['player_detail']; $playerInfo = $arr_update['player_data']['player']; if (isset($arr_update['player_data']['player_detail']) && empty($player_detail)) { $player_detail = $objDetail->get_player_detail($player_id, Protocol_Player::get_player_attr_detail_key()); } if (isset($arr_update['player_data']['player']) && empty($playerInfo)) { $playerInfo = $objPlayer->get_player_info($player_id); } // Com_Log::write("sync.".$player_id,"player_data".var_export($arr_update['player_data'],true)); } //Com_Log::write("sync.".$player_id,"player_detail".var_export($player_detail,true)); //Com_Log::write("sync.".$player_id,"playerInfo".var_export($playerInfo,true)); $cur_data = SynPlayer::get_uval(); // Com_Log::write('potion_hot_cnt_'.$player_id,var_export($cur_data,true)); if (empty($cur_data)) { SynPlayer::init_syn_data(null); $init_data = $objPlayerBase->get_player_init_info($player_id); SynPlayer::set_syn_data($init_data); $cur_data = SynPlayer::get_uval(); if (isset($arr_update['potion_dh_cnt'])) { $arr_update['potion_dh_cnt'] = 0; } #初次同步 如果有这些同步就置为0 if (isset($arr_update['potion_hot_cnt'])) { $arr_update['potion_hot_cnt'] = 0; } if (isset($arr_update['mp_potion_cnt'])) { $arr_update['mp_potion_cnt'] = 0; } } $syn_item = array(); $player_info = array(); if (isset($arr_update['attr']) || isset($arr_update['fairy_info']) || isset($arr_update['hero_info'])) { //更新人物属性 // Com_Log::write('sync_player',"############################[start]##################################"); // Com_Log::write('sync_player',"cur_data:".var_export($cur_data,true)); $player_info = $this->get_player_info($player_id, $playerInfo, $player_detail); $attr = Cache_AttrConfig::getInstance()->get_attr(); // Com_Log::write('sync_player',"attr:".var_export($attr,true)); $attr_mag = array(); $level = $cur_data[36]; // Com_Log::write("sync_level.".$player_id,"level:{$level}"); foreach ($attr as $key) { $cur_val = $cur_data[SynPlayer::get_attr_inde($key)]; $now_val = intval($player_info[$key]); // Com_Log::write('sync_player.'.$player_id,"key:{$key} cur_val:{$cur_val} now_val:{$now_val}"); // echo "key:{$key} cur_val:{$cur_val} now_val:{$now_val}\n"; if ($cur_val != $now_val) { $diff_val = $now_val - $cur_val; if ($level <= 20 && $diff_val < 0) { // continue; } else { if ($diff_val < 0) { $diff_val = $diff_val * -1; $color = "FC0100"; $symbol = "-"; } else { $color = "66FD34"; $symbol = "+"; } if ($key != 'atk_max') { $param = array(array('rep_type' => 6, 'rep_val' => $key), array('rep_type' => 7, 'rep_val' => $symbol, 'rep_color' => $color), array('rep_type' => 7, 'rep_val' => $diff_val, 'rep_color' => $color)); $attr_mag[] = Language_Message::make_message('10116', $param); } } } $syn_item[$key] = $now_val; // Com_Log::write('sync_player',"############################[end]##################################"); } if (!empty($attr_mag)) { if (isset($arr_update['exp'])) { $msg_out = array(0 => $attr_mag, 1 => 2000); } else { $msg_out = array(0 => $attr_mag, 1 => 0); } Protocol::input($player_id, 8, 7, 742, $msg_out); } } $update_fpower = array(); if (isset($arr_update['wing']) || isset($arr_update['dower_info']) || isset($arr_update['hero_info']) || isset($arr_update['attr']) || isset($arr_update['fairy_info']) || isset($arr_update['skill_infos'])) { if (empty($player_info)) { $player_info = $this->get_player_info($player_id, $playerInfo, $player_detail); } Com_Log::write("player_fpower." . $player_id, "############################[start]#####################################"); Com_Log::write("player_fpower." . $player_id, "player_info:" . var_export($player_info, true)); Com_Log::write("player_fpower." . $player_id, "player_detail:" . var_export($player_detail, true)); // Com_Log::write("sync_player_fpower.".$player_id,"player_info:".var_export($player_info,true)); // Com_Log::write("sync_player_fpower.".$player_id,"player_detail:".var_export($player_detail,true)); $objFpowerCalc->set_player_info($player_info); $objFpowerCalc->set_player_detail($player_detail); $player_fpower = $this->get_game('FpowerCalc')->calc_player_fpower($data['player_id']); $player_info['fpower'] = $update_fpower['fpower'] = $player_fpower['fpower']; $update_fpower['buff_fpower'] = $syn_item['buff_fpower'] = $player_fpower['buff_fpower']; if (isset($arr_update['attr'])) { $update_fpower['equip_fpower'] = $objFpowerCalc->calc_equip_fpower($player_id); $player_info['equip_fpower'] = $syn_item['equip_fpower'] = $update_fpower['equip_fpower']; $update_fpower['sq_fpower'] = $objFpowerCalc->calc_sq_fpower($player_id); $player_info['sq_fpower'] = $syn_item['sq_fpower'] = $update_fpower['sq_fpower']; } if (isset($arr_update['fairy_info'])) { $update_fpower['fairy_fpower'] = $objFpowerCalc->calc_fairy_fpower($player_id); $player_info['fairy_fpower'] = $syn_item['fairy_fpower'] = $update_fpower['fairy_fpower']; } if (isset($arr_update['hero_info'])) { $update_fpower['hero_fpower'] = $objFpowerCalc->calc_hero_fpower($player_id); $player_info['hero_fpower'] = $syn_item['hero_fpower'] = $update_fpower['hero_fpower']; } if (isset($arr_update['skill_infos']) || isset($arr_update['dower_info'])) { $update_fpower['skill_fpower'] = $objFpowerCalc->calc_skill_fpower($player_id); $player_info['skill_fpower'] = $syn_item['skill_fpower'] = $update_fpower['skill_fpower']; } if (isset($arr_update['wing'])) { $update_fpower['wing_fpower'] = $objFpowerCalc->calc_wing_fpower($player_id); $player_info['wing_fpower'] = $syn_item['wing_fpower'] = $update_fpower['wing_fpower']; } if ($update_fpower) { $update_fpower['fpower'] = $player_info['fpower'] + $player_info['sq_fpower'] + $player_info['skill_fpower'] + $player_info['equip_fpower']; Com_Log::write("player_fpower." . $player_id, "fpower:{$player_info['fpower']} sq_fpower:{$player_info['sq_fpower']} skill_fpower:{$player_info['skill_fpower']} equip_fpower:{$player_info['equip_fpower']}"); $sum_fpower = $update_fpower['fpower'] + $player_info['hero_fpower'] + $player_info['fairy_fpower'] + $player_info['wing_fpower'] + $update_fpower['buff_fpower']; Com_Log::write("player_fpower." . $player_id, "hero_fpower:{$player_info['hero_fpower']} fairy_fpower:{$player_info['fairy_fpower']} wing_fpower:{$player_info['wing_fpower']} buff_fpower:{$update_fpower['buff_fpower']}"); $update_fpower['sum_fpower'] = $sum_fpower; if ($sum_fpower > $player_info['max_sum_fpower']) { $update_fpower['max_sum_fpower'] = $sum_fpower; } $yesterday_max_sum_fpower = $this->get_data("PlayerDailyTime")->get_player_used_time($player_id, 'yesterday_max_sum_fpower'); if (intval($yesterday_max_sum_fpower) == 0) { $grab_treasure_info = $this->get_cross("GrabTreasure")->get_grab_treasure($player_id); if (!empty($grab_treasure_info)) { $yesterday_max_sum_fpower = intval($player_info['max_sum_fpower']) ? $player_info['max_sum_fpower'] : $player_info['sum_fpower']; $this->get_data("PlayerDailyTime")->set_used_time($player_id, 'yesterday_max_sum_fpower', $yesterday_max_sum_fpower); } } $objPlayer->update_player_info($player_id, $update_fpower); $syn_item['fpower'] = $update_fpower['fpower']; $syn_item['sum_fpower'] = $sum_fpower; Com_Log::write("player_fpower." . $player_id, "sum_fpower:{$sum_fpower} fpower:{$update_fpower['fpower']}"); $this->get_data("Player")->set_player_sum_fpower($player_id, $sum_fpower); if ($player_info['level'] > 20) { if (!isset($player_info['union_id'])) { $playerInfo = $objPlayer->get_player_info($player_id); } $this->get_data("UnionInfo")->set_union_player_sum_fpower($player_info['union_id'], $player_id, $sum_fpower); } $objPlayerAchieve->async_trigger_achieve_target($player_id, 1, $sum_fpower, 2, $player_info['level']); } $objFpowerCalc->clear_static(); unset($arr_update['attr']); Com_Log::write("player_fpower." . $player_id, "############################[end]#####################################"); } if (isset($arr_update['equip_model']) || isset($arr_update['fashion_fit'])) { if (empty($arr_update['equip_model'])) { $arr_update['equip_model'] = $this->get_equip_views($player_id); } if (!isset($player_detail['fashion_fit']) || !isset($player_detail['player_settings'])) { $player_detail = $objDetail->get_player_detail($player_id, array('fashion_fit', 'player_settings')); } $fashion_fit = $player_detail['fashion_fit']; $meditation_flag = isset($player_detail['player_settings'][34]) ? $player_detail['player_settings'][34] : 0; if ($meditation_flag == 0) { if ($fashion_fit) { $fashions = Cache_Fashion::getInstance()->get_fashion(array_values($fashion_fit)); if ($fashions) { if (isset($fashion_fit[1])) { $arr_update['equip_model'][3] = $fashions[$fashion_fit[1]]['equip_view']; } if (isset($fashion_fit[2])) { $arr_update['equip_model'][0] = $fashions[$fashion_fit[2]]['equip_view']; } } } } $syn_item['equip'] = $arr_update['equip_model']; unset($arr_update['equip_model']); } if (isset($arr_update['meditation'])) { if (!isset($player_detail['player_settings'])) { $player_detail = $objDetail->get_player_detail($player_id, array('player_settings')); } $player_settings = $player_detail['player_settings']; if (isset($player_settings[37]) && $player_settings[37] == 1) { $syn_item['meditation_status'] = 1; } elseif (isset($player_settings[38]) && $player_settings[38] == 1) { $syn_item['meditation_status'] = 2; } else { $syn_item['meditation_status'] = 0; } } # 冥想功能开启状态同步 if (isset($arr_update['meditation_open_status'])) { if (empty($arr_update['meditation_open_status'])) { $player_detail = $objDetail->get_player_detail($player_id, array('func_open')); } else { $player_detail = $arr_update['meditation_open_status']; } if (isset($player_detail['func_open']['44'])) { $syn_item['meditation_open_status'] = 1; } else { $syn_item['meditation_open_status'] = 0; } } if (isset($arr_update['equip_swallow'])) { $syn_item['equip_swallow'] = $arr_update['equip_swallow']; unset($arr_update['equip_swallow']); } if (isset($arr_update['equip_skill'])) { $syn_item['equip_skill'] = $arr_update['equip_skill']; unset($arr_update['equip_skill']); } // $log_skill = false; if (isset($arr_update['skill_infos'])) { //Com_Log::write("skill_infos.".$player_id,"player_info:".var_export($arr_update,true)); //Com_Log::write("skill_infos.".$player_id,"player_info:".var_export($playerInfo,true)); //Com_Log::write("skill_infos.".$player_id,"player_deatail:".var_export($player_detail,true)); $skill_infos = $objPlayerSkill->skill_list($player_id, $playerInfo, $player_detail); // Com_Log::write('sync_skill_infos.'.$player_id,var_export($skill_infos['skill_infos'],true)); $syn_item['skill_infos'] = $skill_infos['skill_infos']; // $log_skill = true; unset($arr_update['skill_infos']); } if (isset($arr_update['fairy_info'])) { $fairy_list = $objFairy->get_player_fairy_list($player_id); $syn_item['fairy_info'] = array(); if (!empty($fairy_list)) { foreach ($fairy_list as $keys => $val) { foreach ($val['combination_list'] as $value) { //获取有镶嵌的属性ID if ($value['state'] > 1) { $val['triggers'][] = $value['state']; } } $syn_item['fairy_info'][] = $val; } } unset($arr_update['fairy_info']); } if (isset($arr_update['hero_info'])) { $hero_list = $this->get_data('PlayerHero')->get_fight_hero($player_id); if ($hero_list) { list($hero_id1, $hero_code1) = each($hero_list); if ($hero_id1) { $hero_info = $this->get_game('Hero')->get_player_hero_attr($player_id, $hero_id1); $syn_item['hero_info'] = $hero_info; $syn_item['hero_code'] = $hero_code1; $syn_item['hero_state'] = 1; $syn_item['hero_level'] = $hero_info['hero_level']; $syn_item['hero_fit_level'] = $hero_info['fit']; } else { $syn_item['hero_code'] = 0; $syn_item['hero_state'] = 0; $syn_item['hero_info'] = array(); $syn_item['hero_fit_level'] = 0; } list($hero_id2, $hero_code2) = each($hero_list); if ($hero_id2) { $after_hero_info = $this->get_game('Hero')->get_player_hero_attr($player_id, $hero_id2); $syn_item['hero2_info'] = $after_hero_info; $syn_item['hero2_code'] = $hero_code2; $syn_item['hero2_state'] = 1; $syn_item['hero2_level'] = $after_hero_info['hero_level']; $syn_item['hero2_fit_level'] = $after_hero_info['fit']; } else { $syn_item['hero2_code'] = 0; $syn_item['hero2_state'] = 0; $syn_item['hero2_info'] = array(); $syn_item['hero2_fit_level'] = 0; } } else { $syn_item['hero_code'] = 0; $syn_item['hero_state'] = 0; $syn_item['hero_info'] = array(); $syn_item['hero_fit_level'] = 0; $syn_item['hero2_code'] = 0; $syn_item['hero2_state'] = 0; $syn_item['hero2_info'] = array(); $syn_item['hero2_fit_level'] = 0; } unset($arr_update['hero_info']); } if (isset($arr_update['dower_info'])) { if (!isset($player_detail['dower_info'])) { $player_detail = $objDetail->get_player_detail($player_id, array('dower_info')); } $syn_item['dower_info'] = $player_detail['dower_info']; unset($arr_update['dower_info']); } if (isset($arr_update['hook_settings'])) { if (empty($arr_update['hook_settings'])) { $player_detail = $objDetail->get_player_detail($player_id, array('hook_settings')); } else { $player_detail = $arr_update['hook_settings']; } $syn_item['hook_settings'] = $player_detail['hook_settings']; unset($arr_update['hook_settings']); } if (isset($arr_update['wing'])) { if (!isset($player_detail['equip_wing']) || !isset($player_detail['wing_info'])) { $player_detail = $objDetail->get_player_detail($player_id, array('equip_wing', 'wing_info')); } if ($player_detail['equip_wing'] && isset($player_detail['wing_info'][$player_detail['equip_wing']])) { $wing_table_task = $objPlayerWing->get_cache_table_data('player_wing_table', array('id' => $player_detail['wing_info'][$player_detail['equip_wing']]['id'], 'level' => $player_detail['wing_info'][$player_detail['equip_wing']]['lvl'])); $syn_item['wing'] = $wing_table_task[0]['avatar']; $syn_item['wing_skill_id'] = intval($player_detail['wing_info'][$player_detail['equip_wing']]['skill_id'][0]); $syn_item['wing_skill_id2'] = intval($player_detail['wing_info'][$player_detail['equip_wing']]['skill_id'][1]); $syn_item['wing_skill_id3'] = intval($player_detail['wing_info'][$player_detail['equip_wing']]['skill_id'][2]); } else { $syn_item['wing'] = ''; $syn_item['wing_skill_id'] = 0; $syn_item['wing_skill_id2'] = 0; $syn_item['wing_skill_id3'] = 0; } unset($arr_update['wing']); } ##################[同步当前任务]##################################### if (isset($arr_update['city_escort_map_sid'])) { $syn_item['city_escort_map_sid'] = $arr_update['city_escort_map_sid']; unset($arr_update['city_escort_map_sid']); } if (isset($arr_update['city_escort_target_x'])) { $syn_item['city_escort_target_x'] = $arr_update['city_escort_target_x']; unset($arr_update['city_escort_target_x']); } if (isset($arr_update['city_escort_target_y'])) { $syn_item['city_escort_target_y'] = $arr_update['city_escort_target_y']; unset($arr_update['city_escort_target_y']); } if (isset($arr_update['city_escort_npc_sid'])) { $syn_item['city_escort_npc_sid'] = $arr_update['city_escort_npc_sid']; unset($arr_update['city_escort_npc_sid']); } if (isset($arr_update['task_id'])) { $syn_item['task_id'] = $arr_update['task_id']; unset($arr_update['task_id']); } if (isset($arr_update['task_step'])) { $syn_item['task_step'] = $arr_update['task_step']; unset($arr_update['task_step']); } if (isset($arr_update['task_start_status'])) { $syn_item['task_start_status'] = $arr_update['task_start_status']; unset($arr_update['task_start_status']); } ##################[同步当前任务]####################################### #########################[竞技场同步]################################## if (isset($arr_update['dw'])) { $syn_item['dw'] = $arr_update['dw']; unset($arr_update['dw']); } if (isset($arr_update['dw_lv'])) { $syn_item['dw_lv'] = $arr_update['dw_lv']; unset($arr_update['dw_lv']); } if (isset($arr_update['score'])) { $syn_item['score'] = $arr_update['score']; unset($arr_update['score']); } if (isset($arr_update['dw_star'])) { $syn_item['dw_star'] = $arr_update['dw_star']; unset($arr_update['dw_star']); } #########################[竞技场同步]################################## if (isset($arr_update['potion_dh_cnt'])) { #修改直接回血药剂数量 $cur_data = SynPlayer::get_uval(); $cur_val = intval($cur_data[SynPlayer::POTION_DH_CNT]); $syn_item['potion_dh_cnt'] = $cur_val + intval($arr_update['potion_dh_cnt']); unset($arr_update['potion_dh_cnt']); } if (isset($arr_update['potion_hot_cnt'])) { #修改缓慢回血药剂数量 $cur_data = SynPlayer::get_uval(); $cur_val = intval($cur_data[SynPlayer::POTION_HOT_CNT]); $syn_item['potion_hot_cnt'] = $cur_val + intval($arr_update['potion_hot_cnt']); unset($arr_update['potion_hot_cnt']); } if (isset($arr_update['mp_potion_cnt'])) { #修改回蓝药剂数量 $cur_data = SynPlayer::get_uval(); $cur_val = intval($cur_data[SynPlayer::MP_POTION_CNT]); $syn_item['mp_potion_cnt'] = $cur_val + intval($arr_update['mp_potion_cnt']); unset($arr_update['mp_potion_cnt']); } if (isset($arr_update['light_fairy_name'])) { #光女神名字 $syn_item['light_fairy_name'] = $arr_update['light_fairy_name']; // Com_Log::write('light_fairy_name_'.$player_id,$arr_update['light_fairy_name']); unset($arr_update['light_fairy_name']); } if (isset($arr_update['dark_fairy_name'])) { #按女神名字 $syn_item['dark_fairy_name'] = $arr_update['dark_fairy_name']; // Com_Log::write('dark_fairy_name'.$player_id,$arr_update['dark_fairy_name']); unset($arr_update['dark_fairy_name']); } if (isset($arr_update['athena_remaining_count'])) { #守护女神次数 $syn_item['athena_remaining_count'] = $arr_update['athena_remaining_count']; unset($arr_update['athena_remaining_count']); } if (isset($arr_update['worldboss_remaining_count'])) { #世界boss次数 $syn_item['worldboss_remaining_count'] = $arr_update['worldboss_remaining_count']; unset($arr_update['worldboss_remaining_count']); } if (isset($arr_update['had_on_swings'])) { #已开启翅膀 $syn_item['had_on_swings'] = $arr_update['had_on_swings']; unset($arr_update['had_on_swings']); } if (isset($arr_update['trial_of_god_remaining_cnt'])) { #神之试炼当前剩余次数 $syn_item['trial_of_god_remaining_cnt'] = $arr_update['trial_of_god_remaining_cnt']; unset($arr_update['trial_of_god_remaining_cnt']); } if (isset($arr_update['is_hidden_vip'])) { #vip显示状态 $syn_item['is_hidden_vip'] = $arr_update['is_hidden_vip']; unset($arr_update['is_hidden_vip']); } if (isset($arr_update['mineral_remaining_count'])) { #抢矿剩余次数 $syn_item['mineral_remaining_count'] = $arr_update['mineral_remaining_count']; unset($arr_update['mineral_remaining_count']); } if (isset($arr_update['privilege_left_time'])) { #vip特权剩余时间 $syn_item['privilege_left_time'] = $arr_update['privilege_left_time']; unset($arr_update['privilege_left_time']); } if (isset($arr_update['kf_3vs3_remaining_count'])) { #跨服切磋次数 $syn_item['kf_3vs3_remaining_count'] = $arr_update['kf_3vs3_remaining_count']; unset($arr_update['kf_3vs3_remaining_count']); } //毁灭奥克兰次数 if (isset($arr_update['count_boss_oakland'])) { $syn_item['count_boss_oakland'] = $arr_update['count_boss_oakland']; unset($arr_update['count_boss_oakland']); } if (isset($arr_update['count_boss_oakland'])) { $syn_item['count_boss_oakland'] = $arr_update['count_boss_oakland']; unset($arr_update['count_boss_oakland']); } if (isset($arr_update['count_chest_oakland'])) { $syn_item['count_chest_oakland'] = $arr_update['count_chest_oakland']; unset($arr_update['count_chest_oakland']); } if (!empty($arr_update)) { // Com_Log::write("sync_publish.".$player_id,var_export($arr_update,true)); #Com_Log::write('nut','---1--'.json_encode($arr_update)); foreach ($arr_update as $key => $val) { $syn_item[$key] = $val; #先临时这样写 #Com_Log::write('nut','---3--'.json_encode($arr_update)); $currency_key = Cache_Currency::get_currency_key(); if (empty($val) && !in_array($key, $currency_key)) { if (!isset($player_info[$key])) { $player_info = $this->get_player_info($player_id); } $syn_item[$key] = $player_info[$key]; } else { $syn_item[$key] = $val; } if ($key == 'silver') { if ($player_id == 1895663) { Com_Log::write('xgame.p2c_part_update_tmp', json_encode($syn_item)); } $objPlayerAchieve->async_trigger_achieve_target($player_id, 23, $syn_item[$key], 2, $player_info['level']); //出发成就 } if ($key == 'gold') { $objPlayerAchieve->async_trigger_achieve_target($player_id, 25, $syn_item[$key], 4, $player_info['level']); } } } #Com_Log::debug_write("sync.".$player_id, "arr_update".json_encode($arr_update)); #Com_Log::debug_write("sync.".$player_id, "player_info".json_encode($player_info)); unset($objPlayerBase, $objFpowerCalc, $objPlayer, $objDetail, $objPlayerSkill, $objPlayerAchieve, $objFairy, $objHero, $objPlayerHero, $objPlayerWing); SynPlayer::set_syn_data($syn_item); $data = SynPlayer::get_data(); // if(isset($data['u'][225])){ // Com_Log::write('silver_'.$player_id,"silver:{$data['u'][225]}"); // } // if($log_skill){ // Com_Log::write('sync_skill_infos.'.$player_id,var_export($data['m'],true)); // Com_Log::write('sync_skill_infos.'.$player_id,var_export($data['u'],true)); // } Protocol::input($player_id, 7, 4, 417, array(0 => $data['m'], 1 => $data['u'])); Protocol::out($gateway); }
/** * @Purpose: * 领取宝箱 * @Param $player_id 玩家ID * @Param $chest_id 宝箱ID */ public function receive_chest($player_id, $chest_id) { $player_id = intval($player_id); #获取玩家公会ID $union_id = $this->get_data('Player')->get_player_info($player_id, 'union_id'); if ($union_id < 1) { $this->throw_error('160002'); #宝箱不可领取 } #获取宝箱信息 $chest_info = $this->get_data('UnionBoonHall')->get_boon_hall_info($union_id, 'ubtc', 'day'); $chest_data = $chest_info['chest_info']; if (!$chest_data) { $this->throw_error('160002'); #宝箱不可领取 } if (!is_array($chest_data)) { //字段格式转换 $chest_data = json_decode($chest_data, true); } $chest_id = intval($chest_id); #宝箱领取验证 if ($chest_data['chest'][$chest_id]['state'] != 1) { $this->throw_error('160002'); #宝箱不可领取 } /* #是否是同一公会的宝箱 if ($chest_data['player'][$player_id]['union_id'] && $chest_data['player'][$player_id]['union_id'] != $union_id) { $this->throw_error('171201'); #不同公会宝箱不可重复领取 } */ #玩家是否已领取过 #获取玩家公会信息 $player_chest = $this->get_data('UnionBoonHall')->get_boon_hall_info($player_id, 'pruc', 'day'); if (!is_array($player_chest['chest_id'])) { $player_chest['chest_id'] = json_decode($player_chest['chest_id'], true); } if (Com_Array::is_good_arr($player_chest['chest_id'])) { if (in_array($chest_id, $player_chest['chest_id'])) { $this->throw_error('160002'); #宝箱不可领取 } } $rtn_list = array(); $prop_info = array(); $prop_list = $this->format_table_field($chest_data['chest'][$chest_id]['prop_info']); if (Com_Array::is_good_arr($prop_list)) { foreach ($prop_list as $id => $num) { $rtn_list[$id][] = $id; $rtn_list[$id][] = $num; $type = Cache_Currency::getInstance()->get_key($id); if ($type) { $prop_info[] = array('type' => $type, 'item_id' => $id, 'item_num' => $num); } else { $prop_info[] = array('type' => 'prop', 'item_id' => $id, 'item_num' => $num); } } } #已领取宝箱 #$chest_data['chest'][$chest_id]['state'] = 2; #$chest_info['chest_info'] = json_encode($chest_data); #玩家领取记录 $player_chest['chest_id'][] = $chest_id; $player_data['chest_id'] = json_encode($player_chest['chest_id']); $this->start_trans(); #道具发送 if (Com_Array::is_good_arr($prop_info)) { $result = $this->get_game('Reward')->send_reward($player_id, $prop_info, array('cmd_id' => '1712'), 1); if ($result !== true) { $this->throw_error('10104'); } } #更新宝箱信息 $this->get_data('UnionBoonHall')->update_boon_hall_data($union_id, 'ubtc', $chest_info); #玩家领取宝箱信息 $this->get_data('UnionBoonHall')->update_boon_hall_data($player_id, 'pruc', $player_data); $this->commit(); $this->get_game('Reward')->add_reward_log(true); $data['player_chest'] = $player_chest['chest_id']; $this->update_temporary_data($data); return array('0' => $rtn_list); }
/** * 领取所有资源 * @param int player_id 玩家id * @param int type 领取类型 1,免费;2,消耗钻石 */ public function get_back_all($player_id, $type) { $player_id = intval($player_id); if (!in_array($type, array(1, 2))) { //参数错误 $this->throw_error(10107, 6010018); } $df = 0; $data = $this->get_data('GetBackCurrency')->get_yesterday_info($player_id, $df); if ($data['reward_num'] < 1) { //无资源可以找回 $this->throw_error(6010109, 6010114); } if ($data['is_vip']) { $type = 2; } $cost_currency_value = 0; $reward_detail = array(); foreach ($data['func_info'] as &$func) { if (1 == $func['reward_status']) { if (!$data['is_vip'] && 2 == $type) { $value = explode(':', $func['cost_num']); $cost_currency_type = $value[0]; $cost_currency_value += $value[1]; } if (!empty($func['reward'])) { $reward_array = explode("|", $func['reward']); foreach ($reward_array as $reward) { list($item_idx, $item_num) = explode(":", $reward); if (empty($item_num)) { continue; } if (1 == $type) { $item_num = ceil($item_num / 2); } $reward_detail[$item_idx] += intval($item_num); } } $func['reward_status'] = 2; } } if (!$reward_detail) { $this->throw_error(6010109, 6010115); } $send_reward = array(); $this->get_game('Reward')->gen_reward_array($reward_detail, $send_reward); if ($cost_currency_value) { $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); $cost_currency_key = Cache_Currency::getInstance()->get_key($cost_currency_type); $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value, $data['reward_num'], $cost_currency_type); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 1, $cost_currency_type); } $arr_up['func_info'] = $data['func_info']; $arr_up['reward_num'] = 0; $this->start_trans(); $result = $this->get_data('GetBackCurrency')->update_player_info($player_id, $data['day'], $arr_up); if ($result) { $result = $this->get_game('Reward')->send_reward($player_id, $send_reward, array('cmd_id' => 2021)); if ($result !== true) { $this->throw_error($result); } } if ($cost_currency_value) { if ($result) { $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 2021, array(), $arr_consume); } } if ($result) { $this->commit(); $this->get_game('Reward')->add_reward_log(true); } else { $this->rollback(); $this->throw_error('10101', 6010116); } $data = $this->get_panel($player_id); Protocol::input($player_id, 8, 20, 2019, $data); //该死的同步次数 $this->get_game('PlayerFunc')->sync_func_tips($player_id, 1130); return array('res' => 1); }
public function compose($player_id, $target_id, $comp_type, $comp_sub_type, $auto_buy, $onekey) { $this->get_game('PlayerFunc')->get_func_is_open($player_id, $this->func_id); # 参数校验,comp_sub_type允许为0 $this->param_check_numeric(array($player_id, $target_id, $comp_type, $comp_sub_type), 0); $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'player_id', 'level', 'vip', 'privilege_level'))); # 一键合成不允许自动购买 if ($onekey) { $auto_buy = 0; } # 获取具体合成信息 $comp_info = Cache_ItemCompose::getInstance()->get_item_compose_info_by_target_id($target_id); if (empty($comp_info)) { $this->throw_error('90002'); # 没有配置该道具的合成信息 } $comp_type = $comp_info['comp_type']; $comp_sub_type = $comp_info['comp_sub_type']; /** 由于前端问题,传参此处可能报异常,反正这两个参数不实用,故忽略 if ($comp_info['comp_type'] != $comp_type || $comp_info['comp_sub_type'] != $comp_sub_type) { $this->throw_error('90003'); # 合成参数异常 } **/ # 检查消耗情况 $cost_material_info_hash = array(); # 消耗材料信息哈希,为了方便一次性查找所有消耗材料的持有数 for ($i = 1; $i <= 5; $i++) { if (!empty($comp_info['m' . $i . '_id']) && !empty($comp_info['m' . $i . '_amount'])) { $cost_material_info_hash[$comp_info['m' . $i . '_id']] = $comp_info['m' . $i . '_amount']; } } # -------------------------------------------------------------------- # 计算可一键合成的产物数量 # -------------------------------------------------------------------- $onekey_num_list = array(); # 每项材料可以满足合成条件几次 if (!empty($cost_material_info_hash)) { $material_hold_nums = $this->get_game('Prop')->get_prop_num_by_prop_id($player_id, array_keys($cost_material_info_hash)); foreach ($cost_material_info_hash as $m_id => $m_amount) { $onekey_num_list[$m_id] = intval($material_hold_nums[$m_id] / $m_amount); } } $onekey_num = min($onekey_num_list); # 木桶原理,能一键合成的产物数由最少材料项决定 if ($onekey) { if (empty($onekey_num)) { $this->throw_error('90004'); # 合成所需材料不足 } $onekey_num = min($onekey_num, intval($player_info['silver'] / $comp_info['cost'])); # 木桶原理,能一键合成的产物数还由玩家持有货币决定 if (empty($onekey_num)) { $this->throw_error('10113'); # 金币不足 } } else { if (empty($onekey_num) && empty($auto_buy)) { $this->throw_error('90004'); # 合成所需材料不足 } $onekey_num = 1; # 非一键合成一次只允许合成一件 } $this->start_trans(); # 消耗虚拟货币 $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', 'silver', $comp_info['cost'] * $onekey_num, 1, 1); # 消耗材料 $arr_logs = array(); $log_param = array('level' => $player_info['level'], 'vip' => $player_info['vip'], 'privilege_level' => $player_info['privilege_level'], 'cmd_id' => 2202); foreach ($cost_material_info_hash as $m_id => $m_amount) { $hold_num = !empty($material_hold_nums[$m_id]) ? $material_hold_nums[$m_id] : 0; if (!empty($auto_buy) && $hold_num < $m_amount) { # 一定是单次合成 # 获取正确的单价 $price_info = $this->get_game('Shop')->shortcut_purchase_interface($m_id, 1); if (empty($price_info['item_price'])) { $this->throw_error('130001'); # 商城没有出售该道具 } # 策划价格配置多项时,选其中一项 list($cur_idx, $cur_val) = each($price_info['item_price']); $price = $cur_val; $cost_currency_key = Cache_Currency::getInstance()->get_key($cur_idx); $cost_currency_value = intval($cur_val * ($m_amount - $hold_num)); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 1, $cur_idx); if ($hold_num > 0) { # 该方法在道具不足时会报错,无需外层再判断是否道具足够 $re = $this->get_game('Prop')->deduct_prop_by_prop_id($player_id, $m_id, $material_hold_nums[$m_id], $arr_logs, 0, $log_param); $this->write_check($re, 3010156); } # 若有购买缺少材料,记录虚假商城购买日志 if ($cost_currency_value > 0) { $this->get_game('Shop')->add_dummy_shop_log($player_id, $player_info, $m_id, intval($m_amount - $hold_num), $cur_idx, $cost_currency_value, 2202); } } else { # 可能单次,可能一键 # 该方法在道具不足时会报错,无需外层再判断是否道具足够 $re = $this->get_game('Prop')->deduct_prop_by_prop_id($player_id, $m_id, $m_amount * $onekey_num, $arr_logs, 0, $log_param); $this->write_check($re, 3010161); } } # TODO: 数据中心推送 $re = $this->get_data('Player')->update_player_resource($player_id, $player_info, '2202'); $this->write_check($re, 3010167); #--------------------------------------------------------------------- # 按概率计算成功次数 #--------------------------------------------------------------------- $success_num = 0; for ($i = 1; $i <= $onekey_num; $i++) { if (Com_Random::probability($comp_info['succ_rate'], 10000)) { # 成功 $success_num += 1; } } if ($success_num) { # 成功 # 发送道具 $reward[] = array('type' => 'prop', 'item_id' => $target_id, 'item_num' => $success_num); $re = $this->get_game('Reward')->send_reward($player_id, $reward, array('cmd_id' => 2202)); #send_reward失败时,会返回各种失败情况的错误码 $this->write_check_strict($re, 3010173); } # 记录合成日志 $this->commit(); # -------------------------------------------------------------------- # 通知道具变更,粘包806 # -------------------------------------------------------------------- $this->get_game('Reward')->add_reward_log(); # 调用add_reward_log,触发806协议通知道具变更,并记录道具获取日志 if (!empty($arr_logs) && is_array($arr_logs)) { $ndata = array(); foreach ($arr_logs as $key => $val) { $ndata[] = $val; } Protocol_Prop::prop_806($player_id, $ndata); } # -------------------------------------------------------------------- # 刷新2201协议 # -------------------------------------------------------------------- $data_2201 = $this->get_compose_info($player_id, $comp_type, $comp_sub_type); Protocol::input($player_id, 3, 22, 2201, $data_2201); # 记录行为 Com_Log::write('xgame.compose', "{$player_id}\t" . "{$target_id}\t" . "{$auto_buy}\t" . "{$onekey}\t" . "{$onekey_num}\t" . "{$success_num}\t"); # 日常任务埋点,宝石合成才触发,考虑宝石种类可能包含多种,不方便使用$arr_logs[0]['type'] == 3 && $arr_logs[0]['sub_type'] == 6类似条件 #if ($comp_type == $this->comp_type_for_gem) { # 改为任意合成都算 $this->get_game('TaskTrigger')->async_trigger_task($player_id, 109, 109, $onekey_num); #} #引导任务 $this->get_game('TaskTrigger')->async_trigger_guide_task($player_id, 12, $onekey_num); # -------------------------------------------------------------------- # 公告 # -------------------------------------------------------------------- $replace_info = array(array('rep_type' => 0, 'rep_val' => $player_id), array('rep_type' => 1, 'rep_val' => 70), array('rep_type' => 2, 'rep_val' => $target_id)); $prop_info = Cache_Prop::getInstance()->get_prop_info($target_id); $this->get_game('SystemNotice')->push_sys_notice($player_id, 70, 0, $replace_info, 0, $prop_info['need_broad_cast']); $out_2202 = array('result' => 1); return $out_2202; }
/** * @Purpose: * 购买金蛋活动挑战次数 * @param $player_id 玩家ID */ public function buy_egg_active_times($player_id) { $player_id = intval($player_id); $buy_times_table = Cache_BuyTimes::getInstance()->get_buy_times_info(9); if (!$buy_times_table) { $this->throw_error('113602'); #buy_times配置表读取错误 } else { if (!isset($buy_times_table['max_times']) || $buy_times_table['max_times'] < 1) { $this->throw_error('113701'); #buy_times配置表的max_times字段配置错误 } else { if (!isset($buy_times_table['cost_num']) || empty($buy_times_table['cost_num'])) { $this->throw_error('113702'); #buy_times配置表的cost_num字段配置错误 } else { if (!isset($buy_times_table['cost_type']) || $buy_times_table['cost_type'] < 1) { $this->throw_error('113704'); #buy_times配置表的cost_type配置错误 } else { if (!isset($buy_times_table['per_num']) || $buy_times_table['per_num'] < 1) { $this->throw_error('113705'); #buy_times配置表的per_num配置错误 } } } } } #获取玩家已购买的次数 $player_times = $this->get_data('PlayerDailyTime')->get_player_used_time($player_id, 'buy_egg_active_times'); #$player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'vip', 'ticket', 'gold', 'privilege_level')); $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'ticket', 'gold', 'silver', 'privilege_level'))); if ($player_times >= $buy_times_table['max_times']) { $this->throw_error('10225'); #购买次数已满 } $cost_num = explode("|", $buy_times_table['cost_num']); $expend_coin = $cost_num[$player_times]; if ($expend_coin < 1) { $this->throw_error('113703'); #buy_times配置表的cost_num字段配置消耗不足 } $cost_currency_key = Cache_Currency::getInstance()->get_key($buy_times_table['cost_type']); if (empty($cost_currency_key)) { $this->throw_error('113704'); #buy_times配置表的cost_type配置错误 } # 消耗货币 /***************/ $ticket = 0; $gold = $expend_coin; if ($player_info['ticket'] > 0) { if ($player_info['ticket'] >= $expend_coin) { $ticket = $expend_coin; $gold = 0; } else { $ticket = $player_info['ticket']; $gold = $expend_coin - $player_info['ticket']; } } $arr_consume = array('price' => $expend_coin, 'gold' => $gold, 'ticket' => $ticket, 'count' => 1); #数据中心推送 /***************/ $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $expend_coin, 1, $buy_times_table['cost_type']); $this->start_trans(); #增加挑战次数 $add_res = $this->get_data('PlayerDailyTime')->pre_add_used_time($player_id, 'add_egg_active_times', $buy_times_table['per_num']); if (!$add_res) { $this->throw_error('10104'); } #增加购买次数 $add_buy_res = $this->get_data('PlayerDailyTime')->pre_add_used_time($player_id, 'buy_egg_active_times'); if (!$add_buy_res) { $this->throw_error('10104'); } #扣货币 $update_res = $this->get_data('Player')->update_player_resource($player_id, $player_info, 758, array(), $arr_consume); if (!$update_res) { $this->throw_error('10104'); } $this->commit(); $cost_type = 0; $cost_num = 0; $add_times = 0; if ($player_times + 1 < $buy_times_table['max_times']) { $num = explode("|", $buy_times_table['cost_num']); $cost_num = $num[$player_times + 1]; $cost_type = $buy_times_table['cost_type']; $add_times = $buy_times_table['per_num']; } return array('id' => intval($cost_type), 'num' => intval($cost_num), 'add_times' => intval($add_times)); }
/** * @Purpose: * 提升英雄成长值 * @Param $player_id * @Param $hero_id * @Param $state 0普通提升 1批量提升 * @Param $auto 为1时表示道具不足时从上次自动购买道具 */ public function player_hero_grow_upgrade($player_id, $hero_id, $state, $auto = 0) { $player_id = intval($player_id); $hero_id = strval($hero_id); $obj_player_hero_data = $this->get_data('PlayerHero'); $hero_data = $obj_player_hero_data->get_player_hero_info($player_id, $hero_id); if (empty($hero_data)) { $this->throw_error('10102'); #英雄不存在 } $hero_conf = Cache_HeroAttr::getInstance()->get_hero_attr_info($hero_data['hero_code']); if (empty($hero_conf)) { $this->throw_error('50120'); #英雄配置错误 } if ($hero_data['grow_rate'] >= $hero_conf['grow_limit']) { $this->throw_error('50121'); #成长值已达上限 } $obj_hero_grow = $this->get_data('PlayerHeroGrow'); $hero_grow_id = $obj_hero_grow->get_player_hero_grow_data($hero_id); $hero_grow_conf = array(); $findFlag = false; if (!$hero_grow_id) { $findFlag = true; } else { $hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($hero_grow_id); if (empty($hero_grow_conf)) { $findFlag = true; } else { if ($hero_data['grow_rate'] < $hero_grow_conf['grow_left'] || $hero_data['grow_rate'] >= $hero_grow_conf['grow_right']) { #区间错误 $findFlag = true; } } } if ($findFlag) { #启动自动纠错 $hero_grow_id = $this->find_hero_grow_id($hero_data['grow_rate'], $hero_grow_conf); if (!$hero_grow_id) { $this->throw_error('10111'); #配置错误 } } if (empty($hero_grow_conf)) { $this->throw_error('10111'); } $obj_prop_game = $this->get_game('Prop'); $obj_shop_game = $this->get_game('Shop'); $consume_props = $last_props = $arr_consume = $arr_shop_log = array(); $last_props[$hero_grow_conf['item_id']] = intval($obj_prop_game->get_prop_num_by_prop_id($player_id, $hero_grow_conf['item_id'])); if (empty($auto) && $last_props[$hero_grow_conf['item_id']] < $hero_grow_conf['item_nums']) { $this->throw_error('50107'); } $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); $crit_counter = 0; #暴击计数 $counter = 10; #while执行计数 $sum_rand_grow_val = 0; #总提升数量 $new_hero_grow_val = 0; #新的成长值 $upgrade_times = $counter; $error_code = 0; $update_gold = false; #是否更新彩钻或钻石资源 do { $need_buy_prop_nums = 0; #每次执行所需要的材料需在商城购买的数量 if ($last_props[$hero_grow_conf['item_id']] < $hero_grow_conf['item_nums']) { $last_props[$hero_grow_conf['item_id']] = 0; $need_buy_prop_nums = $hero_grow_conf['item_nums'] - $last_props[$hero_grow_conf['item_id']]; if ($last_props[$hero_grow_conf['item_id']] > 0) { $consume_props[$hero_grow_conf['item_id']] += $last_props[$hero_grow_conf['item_id']]; } } else { $last_props[$hero_grow_conf['item_id']] -= $hero_grow_conf['item_nums']; #剩余数量 $consume_props[$hero_grow_conf['item_id']] += $hero_grow_conf['item_nums']; #消耗数量 } if ($need_buy_prop_nums > 0) { #材料不足需要在商城购买 $update_gold = true; $buy_prop_info = $obj_shop_game->shortcut_purchase_interface($hero_grow_conf['item_id'], 1); if (empty($buy_prop_info['item_price'])) { $this->throw_error('130001'); #商城没有出售该道具 } list($cost_currency_type, $cost_currency_value) = each($buy_prop_info['item_price']); $cost_currency_value *= $need_buy_prop_nums; $cost_currency_key = Cache_Currency::getInstance()->get_key($cost_currency_type); $arr_tmp_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value, $need_buy_prop_nums); if (!empty($arr_tmp_consume)) { $arr_consume['price'] += $arr_tmp_consume['price']; $arr_consume['gold'] += $arr_tmp_consume['gold']; $arr_consume['ticket'] += $arr_tmp_consume['ticket']; $arr_consume['count'] += $arr_tmp_consume['count']; } #虚拟商城记录日志 if (!isset($arr_shop_log[$hero_grow_conf['item_id']])) { $arr_shop_log[$hero_grow_conf['item_id']]['cost_resource_id'] = $cost_currency_type; } $arr_shop_log[$hero_grow_conf['item_id']]['item_num'] += $need_buy_prop_nums; $arr_shop_log[$hero_grow_conf['item_id']]['cost_resource_num'] += $cost_currency_value; $error_code = $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 0, $cost_currency_type); if ($error_code !== true) { if ($counter == 10) { #首次执行如果资源不足则退出 $this->throw_error($error_code); } break; } } $counter--; $rand_val = 0; $is_crit = Com_Random::probability($hero_grow_conf['crit_rate']); if ($is_crit) { $crit_counter++; $rand_val = $this->parse_data($hero_grow_conf['val_crit']); } else { $rand_val = $this->parse_data($hero_grow_conf['val_nor']); } if (!$rand_val) { $this->throw_error('50122'); #英雄成长配置表解析错误 } #单次随机值 $real_rand_val = Com_Random::get_probability_key($rand_val); #批量随机值之和 $sum_rand_grow_val += $real_rand_val; #英雄的新成长值 $new_hero_grow_val = $hero_data['grow_rate'] + $sum_rand_grow_val; if ($new_hero_grow_val >= $hero_conf['grow_limit']) { #超过英雄成长值上限 $new_hero_grow_val = $hero_conf['grow_limit']; $sum_rand_grow_val = $hero_conf['grow_limit'] - $hero_data['grow_rate']; break; } #移动至下一个成长值区间 if ($new_hero_grow_val > $hero_grow_conf['grow_right']) { $hero_grow_id++; $hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($hero_grow_id); if (empty($hero_grow_conf)) { break; } if (!isset($last_props[$hero_grow_conf['item_id']])) { $last_props[$hero_grow_conf['item_id']] = intval($obj_prop_game->get_prop_num_by_prop_id($player_id, $hero_grow_conf['item_id'])); } } if (empty($auto) && $last_props[$hero_grow_conf['item_id']] < $hero_grow_conf['item_nums']) { #道具不足 break; } } while ($counter > 0 && $state > 0); #控制循环数量防止进入死循环 $this->start_trans(); $result = true; if ($update_gold) { $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 557, array(), $arr_consume); $this->write_check($result, 3010476); } if (!empty($consume_props)) { $log_param = array('cmd_id' => 557, 'level' => $player_info['level'], 'vip' => $player_info['vip']); $logs = array(); foreach ($consume_props as $prop_id => $prop_nums) { #批量扣除多个道具如果可能 $result = $obj_prop_game->deduct_prop_by_prop_id($player_id, $prop_id, $prop_nums, $logs, 1, $log_param); if (!$result) { $this->throw_error('10101'); } } } if ($result) { $hero_data['grow_rate'] = $new_hero_grow_val; $hero_data['fight'] = $this->calc_fight($player_id, $hero_data, $hero_data['fit'], $hero_data['rune_hole_list'], $hero_data['star_add_attr_per'], $hero_data['skill_list']); $update_field['grow_rate'] = $hero_data['grow_rate']; $update_field['fight'] = $hero_data['fight']; $result = $this->update_db($player_id, $update_field, $hero_data, 557); $this->get_data('RankList')->update_hero_rank($hero_id, $hero_data['fight']); } if ($result) { $this->commit(); $obj_hero_grow->set_player_hero_grow_data($hero_id, $hero_grow_id); $n_hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($hero_grow_id); #引导任务 $this->get_game('TaskTrigger')->async_trigger_guide_task($player_id, 26, $upgrade_times - $counter); $this->get_game('PlayerAchieve')->async_trigger_achieve_target($player_id, 37, $hero_data['grow_rate'] + $hero_data['fit_grow'], 8); if (!empty($arr_shop_log)) { foreach ($arr_shop_log as $item_id => $item_info) { $obj_shop_game->add_dummy_shop_log($player_id, $player_info, $item_id, $item_info['item_num'], $item_info['cost_resource_id'], $item_info['cost_resource_num'], 557); } } return array('res' => $crit_counter, 'rand_val' => $sum_rand_grow_val, 'cur_grow_val' => $new_hero_grow_val, 'effect' => 10000 * round($this->calc_grow_attar($new_hero_grow_val, $hero_conf['grow']), 4), 'prop_id' => $n_hero_grow_conf['item_id'], 'prop_nums' => $n_hero_grow_conf['item_nums'], 'nor_desc' => $n_hero_grow_conf['nor_desc'], 'crit_desc' => $n_hero_grow_conf['crit_desc']); } else { $this->throw_error('10101'); } }
/** * 添加多种资源 资源是指 黄金 钻石 等这些资源 * @param $player_id 用户id * @param $level 用户等级 * @param $vip_level vip等级 * @param $cmd_id cmd2 指令 * @param $data array('type',item_id,item_num,amount) 具体含义 参照 add_resource_log 里的 $item * @param $arr_consume array('price',gold,ticket,count) or array() 同 Data/Player.php update_player_resource 里的 $arr_consume * @return bool */ public function add_multi_resource_log($player_id, $level, $vip_level, $vip_special_level, $cmd_id, $data, $arr_consume = array()) { $arr_async = array(); if (Com_Array::is_arr2($data)) { foreach ($data as $param) { if ($param['item_num'] > 0) { $this->add_resource_log($player_id, $level, $vip_level, $vip_special_level, $cmd_id, $param['type'], $param['item_id'], $param['item_num'], $param['amount'], $param['front_attr'], $param['after_attr']); } $key = Cache_Currency::getInstance()->get_key($param['item_id']); if (isset($param['is_async']) && $param['is_async'] == 0) { #这时候是不推送的 做不推送的操作 具体啥操作 待定 } else { if ($param['type'] == 1) { $arr_async[$key] = $param['amount'] + $param['item_num']; } elseif ($param['type'] == 2) { $arr_async[$key] = $param['amount'] - $param['item_num']; ############################################################################### # 道具消费,上报数据 if (OPERATOR_ID == 82) { $playerData = TenYear::getInstance("Data_player")->get_player_info($player_id, array("session_id")); $arrUpload = TenYear::getInstance("Game_online")->get_session($playerData['session_id']); $platform = $arrUpload['platform']; $serverId = $arrUpload['server_id']; $openid = $arrUpload['openid']; Com_TencentDataUpload::getInstance()->init($platform, $serverId, $player_id, $openid); $arr_consume_upload = array("level" => $level, "itemid" => $data['item_id'], "itemtype" => $data['type'], "itemcnt" => $data['item_num']); if (!($res = Com_TencentDataUpload::getInstance()->consume_data_upload($arr_consume_upload))) { Com_Log::write("uploadDataError", "consume_data_upload failed!"); } } ############################################################################### } } } } else { if ($data['item_num'] > 0) { $this->add_resource_log($player_id, $level, $vip_level, $vip_special_level, $cmd_id, $data['type'], $data['item_id'], $data['item_num'], $data['amount'], $data['front_attr'], $data['after_attr']); } $key = Cache_Currency::getInstance()->get_key($data['item_id']); if (isset($data['is_async']) && $data['is_async'] == 0) { #检查否同步前端 #这时候是不推送的 做不推送的操作 具体啥操作 待定 } else { if ($data['type'] == 1) { $arr_async[$key] = $data['amount'] + $data['item_num']; } elseif ($data['type'] == 2) { $arr_async[$key] = $data['amount'] - $data['item_num']; } } } if ($arr_consume) { $params['act'] = $cmd_id; $params['level'] = $level; $params['price'] = $arr_consume['price']; $params['gold'] = $arr_consume['gold']; $params['black_gold'] = $arr_consume['ticket']; $params['count'] = $arr_consume['count']; $params['time'] = time(); Com_DataCenter::getInstance()->publish_data($player_id, 'prop', $params); } # 先注释了 if ($arr_async) { Protocol_Player::p2c_part_update($player_id, $arr_async); #同步资 } return true; }
public function get_reward($player_id, $sid, $wave, $time, $friend) { $player_id = intval($player_id); $sid = intval($sid); $wave = intval($wave); $time = intval($time); if (!$sid || !$player_id) { $this->throw_error(10107, 2010009); } #判断次数 $set = Cache_ActivityHall::getInstance()->get_Activity_set(4001); if (!empty($set)) { $max_time = $set[0]['max_times']; } $used = $this->get_athena_remaining_count($player_id, $sid); if ($used > $max_time) { #次数超过不发奖励 $res = array(); $res['sid'] = $sid; $res['wave'] = $wave; $res['time'] = $time; $res['reward'] = array(); $res['new'] = 0; #是否创记录 $res['old_wave'] = 0; $res['old_time'] = 0; Protocol::input($player_id, 8, 11, 1111, $res); } #添加好友亲密度 $this->add_firend_point($player_id, $friend); $new = 1; $p_info = $this->get_data('Player')->get_player_info($player_id, array('gm')); #只记录普通账号记录 if ($p_info['gm'] == 0 || $p_info['gm'] == 3) { #保存记录------- $insert_data = array('sid' => $sid, 'player_id' => $player_id, 'waves' => $wave, 'times' => $time, 'add_time' => time()); $player_info = $this->get_data('Athena')->get_player_info($player_id, $sid); if (!empty($player_info) && isset($player_info['player_id'])) { #更新记录 if ($player_info['waves'] < $wave || $player_info['waves'] == $wave && $time > $player_info['times']) { $this->get_data('Athena')->update_player_info($player_id, $sid, $insert_data); $new = 1; } else { $new = 0; } } else { #添加记录 if ($insert_data['waves'] > 0) { $this->get_data('Athena')->update_player_info($player_id, $sid, $insert_data); } $player_info['waves'] = 0; $player_info['times'] = 0; } } else { $player_info['waves'] = 0; $player_info['times'] = 0; } #----------- $res = array(); $res['sid'] = $sid; $res['wave'] = $wave; $res['time'] = $time; $res['reward'] = array(); $res['new'] = $new; #是否创记录 $res['old_wave'] = $player_info['waves']; $res['old_time'] = $player_info['times']; $rewards = Cache_Athena::getInstance()->get_athena_reward($sid); if ($rewards && $wave > 0) { $reward_ids = array(); foreach ($rewards as $val) { if ($val['sid'] == $sid && $wave == $val['waves']) { $reward_ids = explode('|', $val['rewards']); } } if (!empty($reward_ids)) { foreach ($reward_ids as $v) { $temp = explode(':', $v); if (count($temp) > 1) { // $temp_reward= Cache_FbLoot::getInstance()->get_loot($temp[0]); $temp_reward = array('type' => Cache_Currency::getInstance()->get_key($temp[0]), 'item_id' => $temp[0], 'item_num' => $temp[1]); $vip_exp = $this->get_vip_add_exp($player_id); #vip 增加经验收益 if ($temp[0] == 1) { $temp_reward['item_num'] *= 1 + $vip_exp; } #vip 增加金币收益 if ($temp[0] == 3) { $temp_reward['item_num'] *= 1 + $vip_exp; } array_push($res['reward'], $temp_reward); } else { $this->throw_error(10222, 2010010); } } } else { $this->throw_error(10222, 2010012); } $_event_log = array('player_id' => $player_id, 'reg_time' => time(), 'map_id' => $sid, 'against_npc_num' => $wave); $this->get_game('Event')->async_deal_event_log($_event_log); } else { //$this->throw_error(10222);#配置表错误 $res['reward'] = array(); } $reward_log = array('sid' => $sid, 'player_id' => $player_id, 'rewards' => json_encode($res['reward']), 'static' => 0, 'waves' => $wave, 'times' => $time, 'add_time' => time()); $res['reward_id'] = $this->get_data('Athena')->add_player_reward_log($reward_log); if ($res['reward_id'] > 0) { Protocol::input($player_id, 8, 11, 1111, $res); if ($wave > 0) { #公告广播 $arr_replace = array(); $arr_replace[] = array('rep_type' => 0, 'rep_val' => $player_id); $arr_replace[] = array('rep_type' => 7, 'txt' => $wave); $this->get_game('SystemNotice')->push_sys_notice($player_id, 4001, 0, $arr_replace, $wave); } } else { $this->throw_error(10110, 2010013); } #任务埋点 $this->get_game('TaskTrigger')->async_trigger_guide_task($player_id, 24, 1); }
public function clear_challenge_battle_cd($player_id) { $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); # 获取挑战剩余cd时间 $remain_cd = $this->get_data('Challenge')->get_challenge_remain_cd($player_id); $this->start_trans(); # 消耗虚拟货币 $cost_currency_key = Cache_Currency::getInstance()->get_key($this->clear_cd_cost_currency_type); $cost_currency_value = Formula_Ladder::challenge_cd_prize($remain_cd); $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 1, 1); $re = $this->get_data('Player')->update_player_resource($player_id, $player_info, '1207', array(), $arr_consume); $this->write_check($re, 3011487); # 清除天梯挑战cd时间 $re = $this->get_data('Challenge')->clear_remain_cd($player_id); $this->write_check($re, 3011491); $this->commit(); $out = array('result' => 1); # 记录行为 Com_Log::write('xgame.challenge', "{$player_id}\t" . "clear_challenge_battle_cd\t"); return $out; }
/** * @Purpose: * 领取宝箱 * @Param $player_id 玩家ID * @Param $chest_id 宝箱ID */ public function Receive_chest($player_id, $chest_id) { $player_id = intval($player_id); $chest_id = intval($chest_id); #获取兑换次数信息 $exchange_data = $this->get_data('PlayerCoinExchange')->get_gold_exchange_info($player_id, 'day'); if (!$exchange_data || !$exchange_data['chest_info']) { $this->throw_error('160002'); #宝箱不可领取 } //字段格式转换 $exchange_data['chest_info'] = json_decode($exchange_data['chest_info'], true); #宝箱领取验证 if ($exchange_data['chest_info'][$chest_id]['state'] != 1) { $this->throw_error('160002'); #宝箱不可领取 } #获取宝箱配置表 $chest_table = $this->get_cache_table_data('gold_chest_award_table', array('sid' => $chest_id)); $prop_info = array(); $rtn_list = array(); $prop_list = $this->format_table_field($chest_table[0]['loot']); if (Com_Array::is_good_arr($prop_list)) { foreach ($prop_list as $id => $num) { $rtn_list[$id][] = $id; $rtn_list[$id][] = $num; $type = Cache_Currency::getInstance()->get_key($id); if ($type) { $prop_info[] = array('type' => $type, 'item_id' => $id, 'item_num' => $num); } else { $prop_info[] = array('type' => 'prop', 'item_id' => $id, 'item_num' => $num); } } } #已领取宝箱 $exchange_data['chest_info'][$chest_id]['state'] = 2; $exchange_data['chest_info'] = json_encode($exchange_data['chest_info']); $this->start_trans(); #道具发送 if (Com_Array::is_good_arr($prop_info)) { $result = $this->get_game('Reward')->send_reward($player_id, $prop_info, array('cmd_id' => '1603'), 1); if ($result !== true) { $this->throw_error('10104'); } } #更新兑换记录 $this->get_data('PlayerCoinExchange')->update_exchange_data($player_id, array('chest_info' => $exchange_data['chest_info'])); $this->commit(); $this->get_game('Reward')->add_reward_log(true); return array('0' => $rtn_list); }
/** * 更新人物资源的 统一接口 此方法配合check_player_resource使用 更新 $_resource_field 里要更新资源 * @param $player_id * @param $player_info player表里的信息 里面至少包含 player_id level vip $cur_key对应的字段 * @param $cmd_id cmd2 * @param array $other_update 其他一起更新的字段 * @param array $arr_consume array(price,gold,ticket,count) or array() 数据中心 prop数据(gold and ticket消耗) * @return bool */ public function update_player_resource($player_id, $player_info, $cmd_id, $other_update = array(), $arr_consume = array()) { if (empty($this->_resource_update_field)) { return false; } $update = array(); $logs = array(); // foreach($this->_resource_update_field as $cur_key=>$val){ // if ($cur_key == 'exp') { # 跳过经验 // # do nothing // } else { // $update[$cur_key] = $val; // } // } foreach ($this->_resource_update_field as $cur_key => $resources) { if ($cur_key == 'exp') { continue; } # 跳过经验 if ($resources) { $num = 0; foreach ($resources as $val) { $num += $val; } if ($num > 0) { $update[$cur_key] = "+" . abs($num); } else { $update[$cur_key] = "-" . abs($num); } } } // var_dump($update);exit; if (!empty($other_update)) { $update = array_merge($update, $other_update); } foreach ($this->_resource_log_field as $val) { if ($val['cur_key'] == 'exp') { # 补发经验 $re = $this->get_game('Reward')->send_reward($player_id, array(array('type' => 'exp', 'item_id' => 1, 'item_num' => $val['item_num'])), array('cmd_id' => $cmd_id)); } else { $item_id = Cache_Currency::getInstance()->get_index($val['cur_key']); $logs[] = array('type' => $val['type'] == "+" ? 1 : 2, 'item_id' => $item_id, 'item_num' => $val['item_num'], 'amount' => $val['amount']); } } $res = $this->update_player_info($player_id, $update); if ($res) { if ($this->is_trans()) { $obj = Log_Common::getInstance(); $this->set_redis_pre_action(null, array($obj, 'add_multi_resource_log'), array($player_id, $player_info['level'], $player_info['vip'], $player_info['privilege_level'], $cmd_id, $logs, $arr_consume)); } else { // Com_Log::write('log_log',json_encode($logs)); Log_Common::getInstance()->add_multi_resource_log($player_id, $player_info['level'], $player_info['vip'], $player_info['privilege_level'], $cmd_id, $logs, $arr_consume); } } $this->_resource_log_field = array(); $this->_resource_update_field = array(); return $res; }
public function fund_invest($player_id, $fund_id) { $this->param_check_numeric(array($player_id, $fund_id)); $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); # 获取基金配置信息 $fund_conf = Cache_Finance::getInstance()->get_fund_conf($fund_id); if (empty($fund_conf)) { $this->throw_error(110001); # 获取基金信息失败 } # 判断活动时间 $remain_time = $this->_cal_invest_remain_time(); if ($remain_time <= 0) { $this->throw_error(110004); # 不在基金投资有效期内,不能投资 } # 获取玩家某种类型基金的投资情况 list($invest_acc, $invest_lvl, $invest_time) = $this->get_data('Finance')->get_player_fund_invest_log_by_type($player_id, $fund_conf['fund_type']); # 计算投资差额 if ($fund_conf['fund_price'] <= $invest_acc) { $this->throw_error(110005); # 不能减少基金已投资金额 } else { $delta = $fund_conf['fund_price'] - $invest_acc; } $this->start_trans(); # 资源消耗 $cost_cur_key = Cache_Currency::getInstance()->get_key($this->fund_invest_cur_id); $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_cur_key, $delta); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_cur_key, $delta, 1, 0); $re = $this->get_data('Player')->update_player_resource($player_id, $player_info, '2703', array(), $arr_consume); $this->write_check($re, 3010225); # 更新投资记录 $invest_log = array('player_id' => $player_id, 'fund_type' => $fund_conf['fund_type'], 'invest_time' => $this->current_time, 'invest_num' => $delta, 'invest_level' => $player_info['level']); $re = $this->get_data('Finance')->insert_fund_invest_log($invest_log); $this->write_check($re, 3010227); $this->commit(); # 刷新基金列表 $out_2701 = $this->get_fund_list($player_id, $fund_conf['fund_type']); Protocol::input($player_id, 3, 27, 2701, $out_2701); # 记录行为 Com_Log::debug_write('xgame.finance', "{$player_id}\t" . "fund_invest\t" . "{$fund_id}\t"); $out_2703 = array('fund_type' => $fund_conf['fund_type']); return $out_2703; }
/** * 购买次数 * @param $player_id * @return array */ public function add_fight_times($player_id) { $p_num = $this->get_data('PlayerDailyTime')->get_player_used_time($player_id, 'union_grab_domain_add_times'); $p_num = $p_num ? $p_num : 0; $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); $vip_level = $player_info['vip'] ? $player_info['vip'] : 0; //获取购买消耗信息 $buy_times_info = Cache_UnionGrabDomain::getInstance()->get_buy_times_info($vip_level); //获取购买次数上限 $times_limit = $this->get_buy_max_times($player_id, $buy_times_info); if ($p_num >= $times_limit) { // 你不能再增加进攻次数了 if (10 > $vip_level) { $this->throw_error(6010121); } else { $this->throw_error(6010146); } } $purchase_times_cost = explode("|", $buy_times_info['cost_num']); $cost_currency_value = intval($purchase_times_cost[$p_num]); $cost_currency_type = $buy_times_info['cost_type']; $cost_currency_key = Cache_Currency::getInstance()->get_key($cost_currency_type); $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value, 1, $cost_currency_type); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 1, $cost_currency_type); $this->start_trans(); $result = $this->get_data('PlayerDailyTime')->add_used_time($player_id, 'union_grab_domain_add_times'); if ($result) { $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 2602, array(), $arr_consume); } if ($result) { $this->commit(); $max_time = $p_num + 1; $grab_domain_conf = Cache_UnionGrabDomain::getInstance()->get_base_conf(); $max_fight_times = $grab_domain_conf['times']; $cur_num = intval($this->get_data('PlayerDailyTime')->get_player_used_time($player_id, 'union_grab_domain_use_times')); if ($max_time >= $times_limit) { //到了最大次数 前端不弹提示框 这里约定传 null $next_cost = ''; } else { $p_num = $p_num + 1; $next_cost = intval($purchase_times_cost[$p_num]); $next_cost = $cost_currency_type . ':' . $next_cost; } Protocol_Msg::msg($player_id, 12017); //给前端提示 购买成功 return array('cur_num' => $cur_num, 'max_time' => $max_time + $max_fight_times, 'next_cost' => $next_cost); } else { $this->rollback(); $this->throw_error('10110', 6010122); } }
/** * 复活 * @param int $player_id 玩家id * @return array */ public function relive($player_id) { $res = array(); $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); //配置 $kf_duel_conf = Cache_CrossDuel::getInstance()->get_battle_conf(41001); if (!$kf_duel_conf) { $this->throw_error(10222, 6010106); } $purchase_relive_cost = explode(":", $kf_duel_conf['relive_price']); $cost_currency_value = $purchase_relive_cost[1]; $cost_currency_type = $purchase_relive_cost[0]; $cost_currency_key = Cache_Currency::getInstance()->get_key($cost_currency_type); $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value, 1, $cost_currency_type); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 1, $cost_currency_type); $this->start_trans(); $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 1237, array(), $arr_consume); if (true === $result) { $this->commit(); Protocol::input($player_id, 7, 4, 559, 0); //成功通知C++ } else { $this->rollback(); $this->throw_error(10110, 6010107); } $res['res'] = 1; return $res; }
/** * 购买道具 * @param $player_id * @param $auction_id * @return array */ public function buy_item($player_id, $auction_id, $buy_num) { $auction_data = $this->get_data('Auction')->get_auction($auction_id); if (empty($auction_data)) { $this->throw_error('80920'); //道具不存在 } $prop = json_decode($auction_data['prop_info'], true); if ($buy_num > $prop['item_num'] || $buy_num <= 0) { $this->throw_error('80914'); //购买数量不正确 } if ($prop['player_id'] == $player_id) { $this->throw_error('80915'); //购买数量不正确 } $player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'vip', 'gold', 'name', 'player_id', 'privilege_level')); $has_gold = $player_info['gold']; $price = $auction_data['sell_price'] / $prop['item_num']; $need_gold = ceil($price * $buy_num); $this->get_data('Player')->check_player_resource($player_id, $player_info, "-", 'gold', $need_gold); $this->start_trans(); $reward[] = array('type' => 'prop', 'item_id' => $prop['prop_id'], 'item_num' => $buy_num); $result = $this->get_game('Reward')->send_reward($player_id, $reward, array('cmd_id' => '774')); if ($result !== true) { $this->throw_error($result); } if ($result) { // $result = $this->get_data('Player')->update_player_info($player_id,array('gold'=>"-".$need_gold)); $arr_consume = array('price' => $price, 'gold' => $need_gold, 'ticket' => 0, 'count' => $buy_num); #数据中心推送 $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 774, array(), $arr_consume); } if ($result) { if ($buy_num < $prop['item_num']) { $prop['item_num'] = $prop['item_num'] - $buy_num; $sell_price = $auction_data['sell_price'] - $need_gold; $this->get_data('Auction')->set_auction($auction_id, array('prop_info' => $prop, 'sell_price' => $sell_price)); } else { $prop['item_num'] = 0; $this->get_data('Auction')->del_auction($auction_id); } } $prop_config = Cache_Prop::getInstance()->get_prop_info($prop['prop_id']); $attachment_gold = 0; $objApi = TenYear::getInstance('Com_Uzapi'); $ip = $this->get_cross('Base')->get_server_ip($auction_data['server_id']); $objApi->setServerUrl($ip); if ($result) { $factorage = $need_gold * ($this->_factorage / 100); $factorage = ceil($factorage); $attachment_gold = $need_gold - $factorage; $attachment = array(array("prop_id" => Cache_Currency::getInstance()->get_index('ticket'), "prop_num" => $attachment_gold)); $phrase_config = Cache_FuncPhraseConfig::getInstance()->get_phrase_config_info(7); $content = sprintf($phrase_config['content'], $player_info['name'], $prop_config['name'] . '*' . $buy_num, $factorage, $attachment_gold); //"{$player_info['name']} 购买了你出售的 {$prop_config['name']}*{$buy_num} ,扣除手续费{$factorage}钻,你获得了 {$need_gold}钻。"; if ($auction_data['server_id'] == SERVER_ID) { $result = $this->get_game('Mail')->async_trigger_mail($auction_data['player_id'], $phrase_config['title'], $content, $attachment, $phrase_config['sender'], 1, 774); } else { $objApi->setReqData(array("action" => "PlayerInfo", "command" => "send_mail", "player_id" => $auction_data['player_id'], 'title' => $phrase_config['title'], 'content' => $content, 'attachment' => json_encode($attachment), 'sender' => $phrase_config['sender'])); $response = $objApi->sendRequest(); if (!empty($response['return']) && $response['return'] != 1) { $result = false; } } } if ($result) { $this->commit(); #数据中心推送 // if($need_gold > 0){ // $params['act'] = 774; // $params['price'] = $price; // $params['gold'] = $need_gold; // $params['black_gold'] = 0; // $params['count'] = $buy_num; // $params['time'] = time(); // Com_DataCenter::getInstance()->publish_data($player_id,'prop',$params); // } $this->get_game('Reward')->add_reward_log(); //购买日志 Log_Trade::getInstance()->add_trade_log($player_id, $player_info['level'], $player_info['vip'], $player_info['privilege_level'], 2, $prop['prop_id'], $prop_config['name'], $prop['quality'], $buy_num, $prop['item_num'], $prop['level'], $prop, 2, $need_gold); //被购买日志 $prop['buyer_id'] = $player_id; $seller_info = array(); if ($auction_data['server_id'] == SERVER_ID) { $seller_info = $this->get_data('Player')->get_player_info($auction_data['player_id'], array('level', 'vip', 'privilege_level')); } else { $objApi->setReqData(array("action" => "PlayerInfo", "command" => "get_player_info", "player_id" => $auction_data['player_id'])); $response = $objApi->sendRequest(); if (!empty($response['return'])) { $seller_info = $response['return']; } } Log_Trade::getInstance()->add_trade_log($auction_data['player_id'], $seller_info['level'], $seller_info['vip'], $seller_info['privilege_level'], 3, $prop['prop_id'], $prop_config['name'], $prop['quality'], $buy_num, $prop['item_num'], $prop['level'], $prop, 4, $attachment_gold); return array('result' => 1, 'auction_id' => $auction_id); } else { $this->rollback(); } return array('result' => 0, 'auction_id' => $auction_id); }
public function CMD2_557() { # 消耗虚拟货币 $player_id = $this->_authuser['player_id']; $out = array('player_id' => $player_id, "code" => 0); $cost_currency_key = Cache_Currency::getInstance()->get_key(20); $cost_currency_value = 1; $player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'gold', 'silver', 'ticket', 'privilege_level', 'vip')); $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value); $re = $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 0, 20); if ($re !== true) { $out['code'] = 1; } else { $re = $this->get_data('Player')->update_player_resource($player_id, $player_info, '557', array(), $arr_consume); if (!$re) { $out['code'] = 1; } } Protocol::input($this->_authuser['player_id'], 5, 4, 557, $out); }
public function get_item_key($key) { if ($key < 30) { return Cache_Currency::getInstance()->get_key($key); } else { return 'prop'; } }
public static function get_player_fields($fields) { if (empty($fields) || !is_array($fields)) { return false; } $player_fields = array(); foreach ($fields as $field) { if ($field == 'currency') { $currency_fields = Cache_Currency::getInstance()->get_currency_key(); $player_fields = array_merge($player_fields, $currency_fields); } else { $player_fields[] = $field; } } return $player_fields; }
public function enhanced_refine($player_id, $player_prop_id, $refine_attr_seq, $add_success_rate) { #$this->get_game('PlayerFunc')->get_func_is_open($player_id, $this->func_id_enhanced_refine); $this->param_check_numeric(array($player_id, $refine_attr_seq)); $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); $player_equip_info = $this->get_data('PlayerProp')->get_player_prop_detail($player_id, $player_prop_id); if (!$player_equip_info) { $this->throw_error('80013'); # 玩家没有该装备! } if (Com_Util::is_first_charge_item($player_equip_info['prop_id'])) { $this->throw_error('81105'); # 首充装备不允许精练 } $out_850 = array('player_prop_id' => $player_prop_id, 'result' => 0); # 洗练属性检查 if (empty($player_equip_info['refine_info'])) { $this->throw_error('81008'); # 洗练属性为空,不能精炼 } # 获取洗练属性key /** foreach ($player_equip_info['refine_info']['attr_info'] as $attr_seq => $attr_info) { if ($attr_info['attr_seq'] == $refine_attr_seq) { $en_refine_attr_key = $attr_info['attr_key']; break; } } **/ if (!isset($player_equip_info['refine_info']['attr_info'][$refine_attr_seq])) { $this->throw_error('81009'); # 精炼属性异常,选择的精炼属性不存在 } $refine_info = $player_equip_info['refine_info']; $refine_attr = $player_equip_info['refine_attr']; $en_refine_attr_value_current_lv = $refine_info['attr_info'][$refine_attr_seq]['en_refine_success_num'] * ceil($refine_info['attr_info'][$refine_attr_seq]['attr_limit'] / $refine_info['attr_info'][$refine_attr_seq]['attr_section']); if ($refine_info['attr_info'][$refine_attr_seq]['en_refine_lv'] >= $player_equip_info['level'] && $en_refine_attr_value_current_lv >= $refine_info['attr_info'][$refine_attr_seq]['attr_limit']) { $this->throw_error('81010'); # 精炼属性已满 } # 计算成功率 + 货币消耗 $refine_info_mod = $this->get_en_refine_success_rate_and_cost_currency($refine_info); list($cost_currency_type, $cost_currency_value) = explode(":", $refine_info_mod['attr_info'][$refine_attr_seq]['en_refine_cost_currency']); if ($add_success_rate) { $refine_info_mod['en_refine_success_rate'] += $this->add_success_rate; } $before_refine_attr = isset($player_equip_info['refine_attr']) ? $player_equip_info['refine_attr'] : array(); $before_refine_info = isset($player_equip_info['refine_info']) ? $player_equip_info['refine_info'] : array(); # 更新洗练属性 + 消耗货币 $this->start_trans(); $success_flag = false; if (Com_Random::probability($refine_info_mod['attr_info'][$refine_attr_seq]['en_refine_success_rate'], 10000)) { if ($refine_info_mod['attr_info'][$refine_attr_seq]['attr_section']) { $delta = ceil($refine_info_mod['attr_info'][$refine_attr_seq]['attr_limit'] / $refine_info_mod['attr_info'][$refine_attr_seq]['attr_section']); } else { $delta = 0; } $refine_info['attr_info'][$refine_attr_seq]['en_refine_attr_value'] += $delta; if ($refine_info['attr_info'][$refine_attr_seq]['en_refine_attr_value'] > $refine_info['attr_info'][$refine_attr_seq]['attr_stint']) { $refine_info['attr_info'][$refine_attr_seq]['en_refine_attr_value'] = $refine_info['attr_info'][$refine_attr_seq]['attr_stint']; } $refine_info['attr_info'][$refine_attr_seq]['en_refine_success_num'] += 1; $refine_info['attr_info'][$refine_attr_seq]['en_refine_failed_cont'] = 0; $refine_info['attr_info'][$refine_attr_seq]['attr_value'] = $refine_info['attr_info'][$refine_attr_seq]['refine_attr_value'] + $refine_info['attr_info'][$refine_attr_seq]['en_refine_attr_value']; # 升级 $en_refine_lv_stint = $this->get_en_refine_lv_stint($player_equip_info['level']); $en_refine_attr_value_current_lv = $refine_info['attr_info'][$refine_attr_seq]['en_refine_success_num'] * ceil($refine_info['attr_info'][$refine_attr_seq]['attr_limit'] / $refine_info['attr_info'][$refine_attr_seq]['attr_section']); if ($refine_info['attr_info'][$refine_attr_seq]['en_refine_lv'] < $en_refine_lv_stint && $en_refine_attr_value_current_lv >= $refine_info['attr_info'][$refine_attr_seq]['attr_limit']) { # 获取精练属性基础值 $attr_value_info_en_refine_old = Cache_Refine::getInstance()->get_attr_value_info($refine_info['attr_info'][$refine_attr_seq]['en_refine_lv']); $refine_info['attr_info'][$refine_attr_seq]['en_refine_lv'] += $this->en_refine_lv_delta; $attr_value_info_en_refine = Cache_Refine::getInstance()->get_attr_value_info($refine_info['attr_info'][$refine_attr_seq]['en_refine_lv']); if (empty($attr_value_info_en_refine)) { $this->throw_error('81011'); # 获取洗练属性值配置失败 } $attr_key = $refine_info['attr_info'][$refine_attr_seq]['attr_key']; $attr_ratio = $refine_info['attr_info'][$refine_attr_seq]['attr_ratio']; $refine_info['attr_info'][$refine_attr_seq]['attr_limit'] = ceil(($attr_value_info_en_refine[$attr_key] - $attr_value_info_en_refine_old[$attr_key]) * ($attr_ratio / 10000)); $en_refine_conf = Cache_Refine::getInstance()->get_equip_enhanced_refine_base_info($refine_info['attr_info'][$refine_attr_seq]['en_refine_lv']); $refine_info['attr_info'][$refine_attr_seq]['attr_section'] = $en_refine_conf['section']; $refine_info['attr_info'][$refine_attr_seq]['en_refine_success_num'] = 0; } $refine_attr[$refine_attr_seq] = array($refine_info['attr_info'][$refine_attr_seq]['attr_key'] => $refine_info['attr_info'][$refine_attr_seq]['attr_value']); $out_850['result'] = 1; $success_flag = true; } else { $refine_info['attr_info'][$refine_attr_seq]['en_refine_failed_cont'] += 1; # 连续失败精炼次数 } $cost_currency_key = Cache_Currency::getInstance()->get_key($cost_currency_type); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 1, 1); if ($add_success_rate) { $cost_currency_key_other = Cache_Currency::getInstance()->get_key($this->add_success_rate_cost_cur_type); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key_other, $this->add_success_rate_cost_cur_value, 1, 0); } $re = $this->get_data('Player')->update_player_resource($player_id, $player_info, '850'); $this->write_check($re, 3010132); $update_field = array('refine_attr' => $refine_attr, 'refine_info' => $refine_info); $re = $this->get_data('PlayerProp')->update_player_prop($player_equip_info, $update_field); $this->write_check($re, 3010414); $this->commit(); # 提示购买成功消息 if ($success_flag) { $message = array('texts' => array(array('code' => 81014, 'content' => array(), 'params' => array(array(array('txt' => '', 'type' => 6, 'value' => $refine_info['attr_info'][$refine_attr_seq]['attr_key'], 'param' => '')), array(array('txt' => '', 'type' => 7, 'value' => $refine_info['attr_info'][$refine_attr_seq]['attr_value'] - $before_refine_info['attr_info'][$refine_attr_seq]['attr_value'], 'param' => ''))))), 'delay' => 0); } else { $message = array('texts' => array(array('code' => 81015, 'content' => array(), 'params' => array())), 'delay' => 0); } Protocol::input($player_id, 3, 7, 742, $message); # -------------------------------------------------------------------- # 游戏日志记录 # -------------------------------------------------------------------- $log_info = array('player_id' => $player_id, 'player_level' => $player_info['level'], 'vip_level' => $player_info['vip'], 'vip_special_level' => $player_info['privilege_level'], 'add_time' => $this->current_time, 'player_prop_id_master' => $player_prop_id, 'item_id_master' => $player_equip_info['prop_id'], 'item_type' => $player_equip_info['type'], 'item_sub_type' => $player_equip_info['sub_type'], 'item_quality' => $player_equip_info['quality'], 'item_level' => $player_equip_info['level'], 'item_star_level' => $player_equip_info['star_level'], 'item_position' => $player_equip_info['item_position'], 'action_type' => 2, 'before_refine_attr' => $before_refine_attr, 'after_refine_attr' => $player_equip_info['refine_attr'], 'before_refine_info' => $before_refine_info, 'after_refine_info' => $player_equip_info['refine_info']); Log_Forge::getInstance()->add_log($log_info, 'refine'); # 刷新玩家属性 if ($player_equip_info['item_position'] == 3) { $this->get_game('EquipAttr')->equip_attr($player_id); } # 粘806 + 通知道具变更信息 $player_equip_info['refine_attr'] = $update_field['refine_attr']; $player_equip_info['refine_info'] = $update_field['refine_info']; $ndata = array($player_equip_info); Protocol_Prop::prop_806($player_id, $ndata); $out_849 = $this->get_enhanced_refine_info($player_id, $player_prop_id, $refine_attr_seq); Protocol::input($player_id, 3, 8, 849, $out_849); return $out_850; }
/** * 购买挑战次数 * @param unknown $player_id */ public function buy_grab_treasure_times($player_id) { $player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'gold', 'silver', 'ticket', 'privilege_level', 'vip')); # 获取当日已挑战次数及其购买次数 $battle_buy_num = $this->get_data('PlayerDailyTime')->get_player_used_time($player_id, 'grab_treasure_battle_buy_times'); if (empty($battle_buy_num)) { $battle_buy_num = 0; } # 获取购买消耗信息 $buy_times_info = Cache_BuyTimes::getInstance()->get_buy_times_info($this->grab_treasure_battle_buy_type, 1); # 获取购买次数上限 $buy_stint = $this->get_grab_treasure_num_buy_stint($player_id, $this->grab_treasure_battle_buy_type, $buy_times_info); # 购买次数上限检查 if ($battle_buy_num >= $buy_stint) { $this->throw_error('10225'); # 已达到最大购买次数 } # 获取消耗资源类型与值 $cost_currency_type = $buy_times_info['cost_type']; $cost_currency_value = Cache_BuyTimes::getInstance()->cal_buy_price($battle_buy_num, $buy_times_info['cost_num'], "|", 1); $this->start_trans(); # 消耗虚拟货币 $cost_currency_key = Cache_Currency::getInstance()->get_key($cost_currency_type); $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 1, 1); $re = $this->get_data('Player')->update_player_resource($player_id, $player_info, '1223', array(), $arr_consume); $this->write_check($re, 5010391); # 更新当日挑战次数及挑战次数购买次数 $re = $this->get_data('PlayerDailyTime')->add_used_time($player_id, 'grab_treasure_battle_buy_times', 1); $this->write_check($re, 5010395); $this->commit(); # 当前挑战次数上限 $current_battle_num_max = ($battle_buy_num + 1) * $buy_times_info['per_num'] + $this->grab_treasure_max_times; # 剩余挑战次数可购买次数 $battle_num_buy_remain = $buy_stint - $battle_buy_num - 1 > 0 ? $buy_stint - $battle_buy_num - 1 : 0; list($cost_currency_type, $cost_currency_value) = $this->get_grab_treasure_battle_next_buy_price($player_id, $buy_times_info); $battle_num_next_buy_price = "{$cost_currency_type}:{$cost_currency_value}"; $out = array('current_battle_num_max' => $current_battle_num_max, 'battle_num_buy_remain' => $battle_num_buy_remain, 'battle_num_next_buy_price' => $battle_num_next_buy_price); # 提示购买成功消息 $message = array('texts' => array(), 'delay' => 0); $message['texts'][] = array('code' => 10237, 'content' => array(), 'params' => array()); Protocol::input($player_id, 3, 7, 742, $message); $this->get_game('PlayerFunc')->sync_func_tips($player_id, 1040); return $out; }
/** * 领取排名奖励 * @param int player_id 玩家id * @param int type 类型 1 等级,2战力 3公会等级 * @return array */ public function get_rank_reward($player_id, $type) { $player_id = intval($player_id); $type = intval($type); if (!in_array($type, array(1, 2, 3))) { $this->throw_error(10107, 6010086); } $activity_player_rank = $this->get_data('NewServerActivity')->get_player_rank($player_id, $type); if (!$activity_player_rank) { $this->throw_error(6010062, 6010065); } if ($activity_player_rank['flag'] > 1) { //已领取 $this->throw_error(6010063, 6010066); } //获取奖励配置 if (!($set_rank = Cache_NewServerActivity::getInstance()->get_rank_reward($type))) { $this->throw_error(10222, 6010067); } $set = array(); foreach ($set_rank as $rank) { if ($activity_player_rank['rank'] <= $rank['rank']) { $set = $rank; break; } } if (!$set) { $this->throw_error(10222, 6010068); } $up_arr = array('flag' => 2); $config = Cache_AchieveConfig::getInstance()->get_achieve_config($set['rewards']); $item_id = $config['reward']; $reward = array(); $reward[] = array('type' => Cache_Currency::getInstance()->get_key($item_id), 'item_id' => $item_id, 'item_num' => 1); switch ($type) { case 1: $cmd_id = 2316; break; case 2: $cmd_id = 23161; break; case 3: $cmd_id = 23162; break; } $this->start_trans(); $re = $this->get_data('NewServerActivity')->update_player_rank($player_id, $type, $up_arr); $this->write_check($re, 6010070); $re = $this->get_game('Reward')->send_reward($player_id, $reward, array('cmd_id' => $cmd_id, 'bind_flag' => 0)); $this->write_check_strict($re, 6010071); $this->commit(); $this->get_game('Reward')->add_reward_log(true); $data = $this->get_rank_panel($player_id, $type); Protocol::input($player_id, 8, 23, 2314, $data); # 新服活动,蛋疼的数字埋点 $this->get_game('PlayerFunc')->sync_func_tips($player_id, 1250); return array('res' => 1, 'type' => $type); }
public function buy($player_id, $shop_tag_id, $shop_sub_tag_id, $item_id, $item_num, $currency_type) { $this->get_game('PlayerFunc')->get_func_is_open($player_id, $this->func_id); $this->param_check_numeric(array($player_id, $shop_tag_id, $shop_sub_tag_id, $item_id, $item_num, $currency_type)); # 加锁失败 if (!Com_Lock::lock("lock|shop_buy|player_id={$player_id}")) { $this->throw_error('170501'); # 系统繁忙 } # 获取商城道具信息 $item_info = Cache_Shop::getInstance()->get_shop_item_info($shop_tag_id, $shop_sub_tag_id, $item_id); if (empty($item_info)) { $this->throw_error('130001'); # 商城没有出售该道具 } # 限时校验 if (!empty($item_info['sell_start_time']) && $item_info['sell_start_time'] > $this->current_time || !empty($item_info['sell_end_time']) && $item_info['sell_end_time'] < $this->current_time) { $this->throw_error('130002'); # 商城道具限时售卖尚未开始或已经结束 } # 限量校验 if (!empty($item_info['personal_deal_limit'])) { # 获取当日个人累计交易数量 $daily_start_time = mktime(0, 0, 0); $daily_end_time = mktime(23, 59, 59); $already_deal_num = $this->get_data('Shop')->get_daily_personal_deal_num($daily_start_time, $daily_end_time, $item_id, $player_id); if ($already_deal_num + $item_num > $item_info['personal_deal_limit']) { $this->throw_error('130003'); # 商城道具个人购买数量超过限额 } } if (!empty($item_info['whole_deal_limit'])) { # 获取当日全服累计交易数量 $daily_start_time = mktime(0, 0, 0); $daily_end_time = mktime(23, 59, 59); $already_deal_num = $this->get_data('Shop')->get_daily_whole_deal_num($daily_start_time, $daily_end_time, $item_id); if ($already_deal_num + $item_num > $item_info['whole_deal_limit']) { $this->throw_error('130004'); # 商城道具全服购买数量超过限额 } } # 获取消耗资源类型与值 $cost_currency_value = 0; if (!empty($item_info['item_price'])) { $item_price = explode("|", $item_info['item_price']); foreach ($item_price as $price_string) { list($cur_type, $cur_value) = explode(":", $price_string); if ($cur_type == $currency_type) { $cost_currency_value = $cur_value; break; } } } if (empty($cost_currency_value)) { $this->throw_error('130005'); # 商城道具购买价格为零 } $price = 0; # 计算价格与折扣,对于限时折扣,可能存在临界情况,玩家看到限时折扣尚未结束,实际服务端已经结束限时折扣的情况 if (!empty($item_info['discount'])) { $item_info = $this->flush_time_limit_discount($item_info); # 刷新后折扣可能变为0 if (!empty($item_info['discount'])) { $price = ceil($cost_currency_value * $item_info['discount'] / 10000); $cost_currency_value = $price * $item_num; } else { $price = $cost_currency_value; $cost_currency_value = $cost_currency_value * $item_num; } } else { $price = $cost_currency_value; $cost_currency_value = $cost_currency_value * $item_num; } # 消耗虚拟货币校验 $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); $cost_currency_key = Cache_Currency::getInstance()->get_key($currency_type); $this->start_trans(); # 消耗虚拟货币 $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value, $item_num); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 1, $currency_type); $re = $this->get_data('Player')->update_player_resource($player_id, $player_info, '1302', array(), $arr_consume); $this->write_check($re, 3010162); # 发送道具 $reward = array(); $reward[] = array('type' => 'prop', 'item_id' => $item_id, 'item_num' => $item_num); $re = $this->get_game('Reward')->send_reward($player_id, $reward, array('cmd_id' => '1302')); #send_reward失败时,会返回各种失败情况的错误码 $this->write_check_strict($re, 3010168); $sendarrLogs = $this->get_game('Reward')->get_prop_log(); # 记录商城交易日志 $deal_log = array('player_id' => $player_id, 'deal_time' => $this->current_time, 'item_id' => $item_id, 'item_num' => $item_num, 'item_status' => $item_info['item_status'], 'cost_currency_type' => $currency_type, 'cost_currency_value' => $cost_currency_value, 'discount' => $item_info['discount']); $re = $this->get_data('Shop')->record_shop_deal_log($deal_log); $this->write_check($re, 3010183); $this->commit(); # 该方法会自动推送843协议告知前端显示奖励信息,会调用prop_806协议通知道具变更,调用p2c_part_update通知人物信息变更 $this->get_game('Reward')->add_reward_log(); # 通知玩家信息变更[必须放在commit之后] // Protocol_Player::p2c_part_update($player_id, array($cost_currency_key => '')); $this->get_game('TaskTrigger')->async_trigger_task($player_id, 11, $item_id, $item_num); //收集道具任务触发 $out = array('result' => 1); # 日常活跃度处理 $this->get_game('DailyBoon')->async_trigger_daily_boon_task($player_id, 4000); $prop_info = Cache_Prop::getInstance()->get_prop_info($item_id); # -------------------------------------------------------------------- # 公告 # -------------------------------------------------------------------- $replace_info = array(array('rep_type' => 0, 'rep_val' => $player_id), array('rep_type' => 1, 'rep_val' => 100), array('rep_type' => 2, 'rep_val' => $item_id, 'rep_player_id' => $player_id, 'rep_pid' => $sendarrLogs[0]['player_prop_id'])); $this->get_game('SystemNotice')->push_sys_notice($player_id, 100, 0, $replace_info, 0, $prop_info['need_broad_cast']); # -------------------------------------------------------------------- # 活动日志记录 # -------------------------------------------------------------------- $event_log_info = array('log_type' => 'shop', 'player_id' => $player_id, 'reg_time' => $this->current_time, 'item_id' => $item_id, 'item_num' => $item_num); $this->get_game('Event')->async_deal_event_log($event_log_info); # -------------------------------------------------------------------- # 游戏日志记录 # -------------------------------------------------------------------- $log_info = array('player_id' => $player_id, 'player_level' => $player_info['level'], 'vip_level' => $player_info['vip'], 'vip_special_level' => $player_info['privilege_level'], 'add_time' => $this->current_time, 'item_id' => $item_id, 'item_name' => $prop_info['name'], 'item_quality' => $prop_info['quality'], 'item_num' => $item_num, 'resource_id' => $currency_type, 'resource_num' => $cost_currency_value, 'cmd2_id' => 1302); Log_Shop::getInstance()->add_log($log_info); return $out; }
/** * 检查道具数量,配合使用 deduct_player_prop * @param $player_id * @param $player_info player表里的信息 里面至少包含 player_id level vip $cur_key对应的字段 * @param $prop_id 道具ID * @param $prop_num 道具数量 * @param &$arr_consume 数据中心数据 * @param $auto_buy 是否商城购买 0不自动1自动 * @param $is_throw_error 1 直接throw_error 0 返回错误码 */ public function check_player_prop($player_id, &$player_info, $prop_id, $prop_num, &$arr_consume, $auto_buy = 0, $is_throw_error = 1) { if (empty($prop_id) || empty($prop_num)) { if (!$is_throw_error) { return '150016'; } $this->throw_error('150016'); #道具不足 } $this->_deduct_prop_list[$prop_id] = $prop_num; $player_prop_num = $this->get_prop_num_by_prop_id($player_id, $prop_id); if ($player_prop_num < $prop_num) { $this->_deduct_prop_list[$prop_id] = $player_prop_num; if ($auto_buy) { #获取商城表道具元宝价格 $obj_shop_game = $this->get_game('Shop'); $drop_info = $obj_shop_game->shortcut_purchase_interface($prop_id, 1); if (empty($drop_info['item_price'])) { if (!$is_throw_error) { return '130001'; } $this->throw_error('130001'); # 商城没有出售该道具 } list($cur_idx, $cur_val) = each($drop_info['item_price']); $cost_currency_key = Cache_Currency::getInstance()->get_key($cur_idx); $deduct_gold_num = intval($cur_val * ($prop_num - $player_prop_num)); if ('gold' == $cost_currency_key) { if (20 == $cur_idx) { if ($player_info['ticket'] < $deduct_gold_num) { $ticket = $player_info['ticket']; $gold = $deduct_gold_num - $ticket; } else { $ticket = $deduct_gold_num; $gold = 0; } } else { $gold = $deduct_gold_num; $ticket = 0; } $arr_consume = array('price' => $cur_val, 'gold' => $gold, 'ticket' => $ticket, 'count' => $fit_table['prop_num'] - $player_prop_num); #数据中心推送 } $check_res = $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $deduct_gold_num, 1, $cur_idx); if ($is_throw_error) { return $check_res; } } else { if (!$is_throw_error) { return '150016'; } $this->throw_error('150016'); #道具不足 } } }
/** * * @param $player_id * @param $item_unique_id 0缓慢回血药剂 或者 1直接回血药剂 */ public function prop_use_by_drug($player_id, $item_unique_id) { if ($item_unique_id == 'hot') { $props = $this->get_game('Prop')->get_prop_list_by_type($player_id, 2, 1); } elseif ($item_unique_id == 'dh') { $props = $this->get_game('Prop')->get_prop_list_by_type($player_id, 2, 6); } elseif ($item_unique_id == 'mp') { $props = $this->get_game('Prop')->get_prop_list_by_type($player_id, 2, 11); } $player_info = $this->get_data('Player')->get_player_info($player_id, array('name', 'career_type', 'level', 'exp', 'level_exp', 'silver', 'gold', 'ticket', 'chips', 'honor', 'kf_coin', 'vip', 'crystal', 'fame', 'fame_level', 'fame_level_exp', 'kf_score', 'privilege_level')); if (empty($props)) { $player_detail = $this->get_data('PlayerDetail')->get_player_detail($player_id, array('hook_settings', 'hook_status')); if ($player_detail['hook_settings']['onhook_drug_option'] & 1) { #开启自动选项 $ttl = $this->exist_drgu_lock($player_id); if ($ttl) { return array('error_code' => 4, 'cooldown_msec' => intval($ttl)); //还在冷却中 } if ($item_unique_id == 'hot') { $prop_configs = Cache_Prop::getInstance()->get_prop_by_type(2, 1); } elseif ($item_unique_id == 'dh') { $prop_configs = Cache_Prop::getInstance()->get_prop_by_type(2, 6); } elseif ($item_unique_id == 'mp') { $prop_configs = Cache_Prop::getInstance()->get_prop_by_type(2, 11); } if (!empty($prop_configs)) { if ($player_detail['hook_settings']['onhook_hp_order'] == 0) { $prop_configs = Com_Array::multisort($prop_configs, array('level' => 'desc')); #按等级排序 从小到大 } else { $prop_configs = Com_Array::multisort($prop_configs, array('level' => 'asc')); #按等级排序 从小到大 } $prop_info = array(); foreach ($prop_configs as $val) { if ($val['prop_id'] == '50074' || $val['prop_id'] == '50004') { continue; } #策划要把这两种药先去了 if ($player_info['level'] >= $val['level']) { $prop_info[] = $val; break; } } if (!empty($prop_info)) { $prop_info = reset($prop_info); } else { return array('error_code' => 2, 'cooldown_msec' => 0); //没有这个道具 } if ($prop_info['buy_type'] == 0) { $cur_key = 'silver'; } else { $cur_key = Cache_Currency::getInstance()->get_key($prop_info['buy_type']); if (is_array($cur_key)) { #如果没有类型默认金币 $cur_key = 'silver'; } } $arr_consume = array(); if ('gold' == $cur_key) { $arr_consume = array('price' => $prop_info['buy_price'], 'gold' => $prop_info['buy_price'], 'ticket' => 0, 'count' => 1); #数据中心推送 } elseif ('ticket' == $cur_key) { $arr_consume = array('price' => $prop_info['buy_price'], 'gold' => 0, 'ticket' => $prop_info['buy_price'], 'count' => 1); #数据中心推送 } $result = $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cur_key, $prop_info['buy_price'], 0); if ($result === true) { #这地方相当于购买并使用功能 $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 409, array(), $arr_consume); $this->add_drug_lock($player_id); if ($result) { return array('error_code' => 0, 'cooldown_msec' => 0, 'item_sid' => intval($prop_info['prop_id'])); } } else { return array('error_code' => 6, 'cooldown_msec' => 0); //服务器内部错误 } } else { return array('error_code' => 2, 'cooldown_msec' => 0); //没有这个道具 } } else { #没有勾选自动购买选项 return array('error_code' => 2, 'cooldown_msec' => 0); //没有这个道具 } } $player_prop = reset($props); $result = $this->get_game('Prop')->deduct_prop_by_ppid($player_id, $player_prop['player_prop_id'], 1, array('cmd_id' => 409, 'level' => $player_info['level'], 'vip' => $player_info['vip']), $player_prop); if (!$result) { return array('error_code' => 6, 'cooldown_msec' => 0); //服务器内部错误 } return array('error_code' => 0, 'cooldown_msec' => 0, 'item_sid' => $player_prop['prop_id']); }
private function get_common_depletion_detail($common_depletion_string) { $cost_currency = array(); # 消耗的货币 $cost_prop = array(); # 消耗的道具 if (!empty($common_depletion_string)) { $cost_entry_array = explode("|", $common_depletion_string); # 消耗项数组 foreach ($cost_entry_array as $cost_entry) { list($cost_type, $cost_num) = explode(":", $cost_entry); $cost_key = Cache_Currency::getInstance()->get_key($cost_type); if ($cost_key == 'prop') { $cost_prop[$cost_type] = $cost_num; } else { $cost_currency[$cost_key] = $cost_num; } } } # 函数不能返回多个值,但可以通过返回一个数组来得到类似的效果 return array($cost_currency, $cost_prop); }
public function use_privilege($player_id, $plm_id) { $this->param_check_numeric(array($player_id, $plm_id)); $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); # 获取议会配置信息 $plm_conf = Cache_MagicParliament::getInstance()->get_parliament_conf($plm_id); if (empty($plm_conf) || empty($plm_conf['use_privilege_cost_res'])) { $this->throw_error('100002'); # 获取魔法议会配置失败 } # 获取玩家当日行使特权次数 $use_privilege_num = $this->get_data('PlayerDailyTime')->get_player_used_time($player_id, $this->get_redis_key($this->daily_use_privilege_num_prefix, $plm_conf['plm_id'])); # 判断上限 if ($use_privilege_num >= $plm_conf['use_privilege_stint']) { $this->throw_error('100006'); # 魔法议会占星|秘典|提案|试炼次数超过当日上限 } # 判断权限 $title_info_hash = $this->get_title_info_hash(); if (!isset($title_info_hash[$plm_conf['use_privilege_req_title_id']]['title_holder'][$player_id])) { $this->throw_error('100007'); # 未达到称号要求 } # 获取议会人气值 if ($plm_conf['plm_id'] == $this->sage_plm_id) { $popularity = $this->get_cross('PlayerDailyTime')->get_any_used_time($this->get_redis_key($this->daily_popularity_prefix, $plm_conf['plm_id'])); } else { $popularity = $this->get_data('PlayerDailyTime')->get_any_used_time($this->get_redis_key($this->daily_popularity_prefix, $plm_conf['plm_id'])); } # 获取人气值修正信息 && 等级修正信息 && 合并两个修正为一个 $revise_info_1 = Cache_MagicParliament::getInstance()->get_revise_1($plm_conf['plm_id'], $popularity); $revise_info_2 = Cache_MagicParliament::getInstance()->get_revise_2($plm_conf['plm_id'], $player_info['level']); if (empty($revise_info_1)) { $this->throw_error('100003'); # 获取人气值修正信息配置失败 } if (empty($revise_info_2)) { $this->throw_error('100004'); # 获取等级修正信息配置失败 } $this->start_trans(); # 资源消耗 $cost_revise_array = $this->get_game('Reward')->merge_revise_info(array($revise_info_1['privilege_cost_revise'], $revise_info_2['privilege_cost_revise']), 1); $res_cost_list = explode("|", $plm_conf['use_privilege_cost_res']); foreach ($res_cost_list as $res_cost_string) { list($cost_cur_id, $cost_cur_val) = explode(":", $res_cost_string); if (!empty($cost_revise_array[$cost_cur_id])) { $cost_cur_val = intval($cost_cur_val * $cost_revise_array[$cost_cur_id] / 10000); } $cost_cur_key = Cache_Currency::getInstance()->get_key($cost_cur_id); $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_cur_key, $cost_cur_val); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_cur_key, $cost_cur_val, 1, 1); } $re = $this->get_data('Player')->update_player_resource($player_id, $player_info, '2505', array(), $arr_consume); $this->write_check($re, 3010225); # 更新特权使用次数 $re = $this->get_data('PlayerDailyTime')->add_used_time($player_id, $this->get_redis_key($this->daily_use_privilege_num_prefix, $plm_conf['plm_id'])); $this->write_check($re, 3010223); # 发放特权奖励 $reward = array(); $reward_revise_string = $this->get_game('Reward')->merge_revise_info(array($revise_info_1['privilege_reward_revise'], $revise_info_2['privilege_reward_revise'])); $reward_detail = $this->get_game('Reward')->get_reward_detail_other_way($plm_conf['use_privilege_reward'], $reward_revise_string, 1); $this->get_game('Reward')->gen_reward_array($reward_detail, $reward); if (!empty($reward)) { $re = $this->get_game('Reward')->send_reward($player_id, $reward, array('cmd_id' => '2505'), 1); $this->write_check_strict($re, 3010274); } # 清空人气值 && 增加免费奖励累计次数 if ($plm_conf['plm_id'] == $this->sage_plm_id) { $re = $this->get_cross('PlayerDailyTime')->set_any_used_time($this->get_redis_key($this->daily_popularity_prefix, $plm_conf['plm_id']), 0); $this->write_check_strict($re, 3010335); $re = $this->get_cross('PlayerDailyTime')->add_global_used_time($this->get_redis_key($this->daily_free_reward_num_acc_prefix, $plm_conf['plm_id'])); $this->write_check_strict($re, 3010339); } else { $re = $this->get_data('PlayerDailyTime')->set_any_used_time($this->get_redis_key($this->daily_popularity_prefix, $plm_conf['plm_id']), 0); $this->write_check_strict($re, 3010345); $re = $this->get_data('PlayerDailyTime')->add_global_used_time($this->get_redis_key($this->daily_free_reward_num_acc_prefix, $plm_conf['plm_id'])); $this->write_check_strict($re, 3010349); } # 记录行为日志 $action_log = array('player_id' => $player_id, 'reg_time' => $this->current_time, 'plm_id' => $plm_id, 'action_type' => 2, 'reward_info' => json_encode($reward_detail)); $re = $this->get_data('MagicParliament')->record_action_log($action_log); $this->write_check_strict($re, 3010369); $this->commit(); # 该方法会自动推送843协议告知前端显示奖励信息,会调用prop_806协议通知道具变更,调用p2c_part_update通知人物信息变更 $ret = $this->get_game('Reward')->add_reward_log(true); # 刷新议会信息 $out_2503 = $this->init_magic_parliament_deatil($player_id, $plm_id); Protocol::input($player_id, 3, 25, 2503, $out_2503); # 记录行为 Com_Log::debug_write('xgame.magic_parliament', "{$player_id}\t" . "use_privilege\t" . "{$plm_id}\t" . json_encode($cost_revise_array) . "\t" . "{$reward_revise_string}\t"); $out_2505 = array(); return $out_2505; }
/** * 全服邀请 */ public function all_service_invite_union($player_id) { $player_id = intval($player_id); $playerInfo = $this->get_data('Player')->get_player_info($player_id, array("union_id", "silver", "union_name", "gold", "ticket", "level", "vip", "name", "union_job", "privilege_level")); if (!$playerInfo['union_id']) { $this->throw_error('171101'); //没有加入公会 } $union_conf = Cache_UnionBase::getInstance()->get_union_conf(); if (empty($union_conf)) { $this->throw_error(10222, 5011990); } if (!isset($union_conf['world_invite'])) { $this->throw_error(10222, 5011993); } list($cost_currency_type, $cost_currency_value) = explode(":", $union_conf['world_invite']); # 消耗虚拟货币 $cost_currency_key = Cache_Currency::getInstance()->get_key($cost_currency_type); $arr_consume = Com_Util::get_consume_info_for_data_center($playerInfo, $cost_currency_key, $cost_currency_value); $this->get_data('Player')->check_player_resource($player_id, $playerInfo, '-', $cost_currency_key, $cost_currency_value, 1, 1); $re = $this->get_data('Player')->update_player_resource($player_id, $playerInfo, '1789', array(), $arr_consume); $this->write_check($re, 5012009); $arr_replace = array(); $arr_replace[] = array('rep_type' => 7, 'txt' => $playerInfo['union_name']); $arr_replace[] = array('rep_type' => 10, 'txt' => "#1", 'rep_val' => 1703, 'rep_param' => array($playerInfo['union_id'])); $msg = Language_Message::make_message(178901, $arr_replace, 0, '', true); $this->get_game('SystemNotice')->send_system_msg($player_id, $msg, 1, 1); }
/** * 一键出售道具 * @param $player_id * @return array * @throws Exception] */ public function batch_sell_prop($player_id) { $sell_id = array(); $objPlayerPropData = $this->get_data('PlayerProp'); $prop_list = $objPlayerPropData->get_player_prop_by_item_position($player_id); //冲从包裹取出道具 if ($prop_list) { $props = array(); foreach ($prop_list as $prop) { $props[] = $prop['prop_id']; } $prop_configs = Cache_Prop::getInstance()->get_prop_info($props); foreach ($prop_list as $key => $prop) { if ($prop_configs[$prop['prop_id']]['type'] == 3 && $prop_configs[$prop['prop_id']]['sub_type'] == 21 && $prop_configs[$prop['prop_id']]['quality'] <= 4) { $sell_id[$prop['player_prop_id']] = $prop; } elseif ($prop_configs[$prop['prop_id']]['type'] == 1 && $prop_configs[$prop['prop_id']]['sub_type'] <= 12 && $prop_configs[$prop['prop_id']]['quality'] <= 2) { $sell_id[$prop['player_prop_id']] = $prop; } } } if ($sell_id) { $get_silver = 0; foreach ($sell_id as $prop) { if ($prop_configs[$prop['prop_id']]['sale_price'] > 0) { $get_silver += $prop_configs[$prop['prop_id']]['sale_price'] * $prop['item_num']; } } if ($get_silver) { $player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'vip', 'silver', 'privilege_level')); $this->get_data('Player')->check_player_resource($player_id, $player_info, "+", 'silver', $get_silver); $result = true; $objPlayerPropData->start_watch($player_id); $this->start_trans(); $log_param = array('level' => $player_info['level'], 'vip' => $player_info['vip'], 'cmd_id' => 804); foreach ($sell_id as $player_prop_id => $val) { $result = $objPlayerPropData->update_prop_num($player_id, $val, $val['item_num'], "-", $log_param); $sell_id[$player_prop_id] = 0; if (!$result) { $this->throw_error(80003, '10180062601'); } } if ($result) { $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 804); } if ($result) { Com_AdCache::set_pipe(false); $this->commit(); $out['result'] = 1; $out['item'] = array('pos' => 1, 'index' => array()); $asyData = array(); foreach ($sell_id as $arr_prop_detail) { $out['item']['index'][] = $arr_prop_detail['grid']; } $out['silver'] = Cache_Currency::getInstance()->get_index('silver') . ":" . $get_silver; Protocol_Prop::prop_806($player_id, $sell_id); return $out; } } } return array('result' => 1, array()); }
/** * 毁灭奥克兰副本复活 * @param unknown $player_id * $type 1消耗 2不消耗 */ public function destroy_akland_relive($player_id, $type) { $type = intval($type); if ($type == 1) { $player_info = $this->get_data('Player')->get_player_info($player_id, array("privilege_level", "ticket", "level", "vip", "map_id", "gold", 'player_id')); # 消耗虚拟货币 $cost_currency_type = 2; $cost_currency_value = 5; $cost_currency_key = Cache_Currency::getInstance()->get_key($cost_currency_type); $arr_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value); $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 1, 1); $re = $this->get_data('Player')->update_player_resource($player_id, $player_info, '748', array(), $arr_consume); $this->write_check($re, 5010174); $this->start_trans(); $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 748, array(), $arr_consume); $this->write_check($re, 5010177); } $this->commit(); Protocol::input($player_id, 7, 4, 560, array($type)); }