/** * 出售道具 * @param $player_id * @param $player_prop_ids 用户道具的id 多个用:号隔开 * @return array|string */ public function item_sell($player_id, $player_prop_ids) { if (empty($player_prop_ids)) { $this->throw_error('10107', '101800243'); } $arr_player_prop_id = array(); foreach ($player_prop_ids as $val) { if ($val[1] <= 0) { $this->throw_error('10107', "101800242{$val[0]}"); } $arr_player_prop_id[$val[0]] = $val[1]; } if (empty($arr_player_prop_id)) { $this->throw_error('10107', '101800243'); } $objPlayerPropGame = $this->get_game('Prop'); $objPlayerPropData = $this->get_data('PlayerProp'); //获取所有出售道具 $arrPlayerPropList = $objPlayerPropData->get_player_prop_detail_multi($player_id, array_keys($arr_player_prop_id)); if (empty($arrPlayerPropList)) { $this->throw_error('10107', '101800244'); } $arr_prop_id = array(); foreach ($arrPlayerPropList as $key => $value) { $arr_prop_id[] = $value['prop_id']; } $arrPropConfigList = Cache_Prop::getInstance()->get_prop_info(array_values($arr_prop_id)); $msg_param = array(); //提示参数 $get_silver = 0; foreach ($arrPlayerPropList as $key => $value) { // if(intval($arrPropConfigList[$value['prop_id']]['can_sell']) == 0){ // $this->throw_error('ERROR_PROP_8'); // } if ($arrPropConfigList[$value['prop_id']]['sale_price'] <= 0) { $this->throw_error('80003', "101800244{$value['prop_id']}"); //游戏配置出错,请联系客服! } if ($arr_player_prop_id[$key] > $value['item_num']) { $arr_player_prop_id[$key] = $value['item_num']; } $msg_param[$value['prop_id']] += $arr_player_prop_id[$key]; $get_silver += $arrPropConfigList[$value['prop_id']]['sale_price'] * $arr_player_prop_id[$key]; } if (!$get_silver) { $this->throw_error('80003', "101800244{$value['prop_id']}"); } $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(); if ($result) { // $result = $objPlayerPropData->delete_player_prop($player_id, $arrPlayerPropList,false); $log_param = array('level' => $player_info['level'], 'vip' => $player_info['vip'], 'cmd_id' => 804); foreach ($arr_player_prop_id as $key => $val) { $result = $objPlayerPropData->update_prop_num($player_id, $arrPlayerPropList[$key], $val, "-", $log_param); $arrPlayerPropList[$key]['item_num'] -= $val; if (!$result) { $this->throw_error('80003', "101800245 {$arrPlayerPropList[$key]} {$val}"); } } } if ($result) { // $result = $this->get_data('Player')->update_player_silver($player_id, '+'.$get_silver); $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 804); } if ($result) { Com_AdCache::set_pipe(false); $this->commit(); if (!empty($msg_param)) { $param = array(); foreach ($msg_param as $prop_id => $num) { // $param[0][] = array( // 'rep_type'=>2, // 'rep_val'=>$prop_id, // 'rep_num'=>$num // ); // Game_GainMsg::add($player_id,1,$prop_id,$num,2); 道具消失不提示 } $param[0] = array('rep_type' => 2, 'rep_val' => Cache_Currency::getInstance()->get_index('silver'), 'rep_num' => $get_silver); Game_GainMsg::add($player_id, 1, Cache_Currency::getInstance()->get_index('silver'), $get_silver); Game_GainMsg::out($player_id); $this->out_error($player_id, '80020', $param); } // Protocol_Player::p2c_part_update($player_id,array('silver'=>'')); $out['result'] = 1; $out['item'] = array('pos' => 1, 'index' => array()); $asyData = array(); foreach ($arrPlayerPropList as $arr_prop_detail) { $out['item']['index'][] = $arr_prop_detail['grid']; // $box = array(); // $box['pos'] = $arr_prop_detail['item_position']; // $box['from_grid'] = $arr_prop_detail['grid']; // $box['item_position'] = $arr_prop_detail['item_position']; // $box['grid'] = $arr_prop_detail['grid']; // $out[2][] = Struct_Prop::get_item_box_operate_struct($box); } $out['silver'] = Cache_Currency::getInstance()->get_index('silver') . ":" . $get_silver; Protocol_Prop::prop_806($player_id, $arrPlayerPropList); return $out; } else { $this->throw_error('80003', '101800246'); //数据库更新失败 } }
protected function add_player_reward_log($upgrade_async = true) { if (!empty($this->arrPlayerReward)) { $arr_async = array(); $logs = array(); #日志数组 $upgrade_fame_logs = array(); #日志数组 foreach ($this->arrPlayerReward as $key => $reward) { switch ($key) { case 'exp': $this->arrParams['exp'] += $reward; Game_GainMsg::add($this->player_id, 1, 1, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 1, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $this->_out_reward[1] += $reward; // Com_Log::write("player_upgrade.".$this->player_id,"exp:{$this->arrParams['exp']} level_exp:{$this->arrParams['level_exp']} level:{$this->arrParams['level']}"); if ($this->arrParams['exp'] >= $this->arrParams['level_exp'] && $this->arrParams['level'] < 79) { // Com_Log::write("player_upgrade.".$this->player_id,"exp:{$this->arrParams['exp']}"); $this->player_upgrade($this->arrParams['exp'], $upgrade_async); $logs[] = array('type' => 1, 'item_id' => 1, 'item_num' => $reward, 'amount' => $this->arrParams['exp'] - $reward, 'is_async' => 0); } else { $arr_async['exp'] = $this->arrParams['exp']; $logs[] = array('type' => 1, 'item_id' => 1, 'item_num' => $reward, 'amount' => $this->arrParams['exp'] - $reward); } break; case 'gold': // $arr_async['gold'] = $this->arrParams['gold']+$reward; Game_GainMsg::add($this->player_id, 1, 2, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 2, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $logs[] = array('type' => 1, 'item_id' => 2, 'item_num' => $reward, 'amount' => $this->arrParams['gold']); $this->_out_reward[2] += $reward; break; case 'silver': // $arr_async['silver'] = $this->arrParams['silver']+$reward; Game_GainMsg::add($this->player_id, 1, 3, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 3, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $logs[] = array('type' => 1, 'item_id' => 3, 'item_num' => $reward, 'amount' => $this->arrParams['silver']); $this->_out_reward[3] += $reward; break; case 'ticket': // $arr_async['ticket'] = $this->arrParams['ticket']+$reward; Game_GainMsg::add($this->player_id, 1, 4, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 4, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $logs[] = array('type' => 1, 'item_id' => 4, 'item_num' => $reward, 'amount' => $this->arrParams['ticket']); $this->_out_reward[4] += $reward; break; case 'chips': // $arr_async['chips'] = $this->arrParams['chips']+$reward; Game_GainMsg::add($this->player_id, 1, 5, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 5, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $logs[] = array('type' => 1, 'item_id' => 5, 'item_num' => $reward, 'amount' => $this->arrParams['chips']); $this->_out_reward[5] += $reward; break; case 'kf_coin': // $arr_async['kf_coin'] = $this->arrParams['kf_coin']+$reward; Game_GainMsg::add($this->player_id, 1, 6, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 6, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $logs[] = array('type' => 1, 'item_id' => 6, 'item_num' => $reward, 'amount' => $this->arrParams['kf_coin']); $this->_out_reward[6] += $reward; break; case 'honor': // $arr_async['honor'] = $this->arrParams['honor']+$reward; Game_GainMsg::add($this->player_id, 1, 7, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 7, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $logs[] = array('type' => 1, 'item_id' => 7, 'item_num' => $reward, 'amount' => $this->arrParams['honor']); $this->_out_reward[7] += $reward; break; case 'crystal': // $arr_async['crystal'] = $this->arrParams['crystal']+$reward; Game_GainMsg::add($this->player_id, 1, 13, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 13, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $logs[] = array('type' => 1, 'item_id' => 13, 'item_num' => $reward, 'amount' => $this->arrParams['crystal']); $this->_out_reward[13] += $reward; break; case 'fame': $this->arrParams['fame'] += $reward; Game_GainMsg::add($this->player_id, 1, 14, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 14, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $this->_out_reward[14] += $reward; if ($this->arrParams['fame'] >= $this->arrParams['fame_level_exp']) { $upgrade_fame_logs[] = array('type' => 1, 'item_id' => 14, 'item_num' => $reward, 'amount' => $this->arrParams['fame'] - $reward, 'is_async' => 0, 'front_attr' => $this->arrParams['fame_level'], 'after_attr' => $this->arrParams['fame_level']); $this->player_fame_upgrade($this->arrParams['fame'], $upgrade_fame_logs); } else { $arr_async['fame'] = $this->arrParams['fame']; $logs[] = array('type' => 1, 'item_id' => 14, 'item_num' => $reward, 'amount' => $this->arrParams['fame'] - $reward, 'front_attr' => $this->arrParams['fame_level'], 'after_attr' => $this->arrParams['fame_level']); } # ---------------------------------------------------- # 魔法议会周声望排行榜 # ---------------------------------------------------- $this->get_data('MagicParliament')->update_fame_sorted_sort($this->player_id, $reward); break; case 'feather_unicorn': Game_GainMsg::add($this->player_id, 1, 15, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 13, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $this->_out_reward[15] += $reward; $logs[] = array('type' => 1, 'item_id' => 15, 'item_num' => $reward, 'amount' => $this->arrParams['feather_unicorn']); break; case 'kf_score': Game_GainMsg::add($this->player_id, 1, 16, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 16, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $this->_out_reward[16] += $reward; $logs[] = array('type' => 1, 'item_id' => 16, 'item_num' => $reward, 'amount' => $this->arrParams['kf_score']); break; case 'battle_score': Game_GainMsg::add($this->player_id, 1, 17, $reward); Protocol_Reward::add($this->player_id, array('prop_id' => 17, 'item_num' => $reward, 'item_position' => 1, 'grid' => 0)); $this->_out_reward[17] += $reward; $logs[] = array('type' => 1, 'item_id' => 17, 'item_num' => $reward, 'amount' => $this->arrParams['kf_score']); break; } } if ($logs) { Log_Common::getInstance()->add_multi_resource_log($this->player_id, $this->arrParams['level'], $this->arrParams['vip'], $this->arrParams['privilege_level'], $this->arrParams['cmd_id'], $logs); } // if($arr_async){ // Protocol_Player::p2c_part_update($this->player_id,$arr_async); // } } }