Esempio n. 1
0
void Map_Team::deserialize(Block_Buffer &buf) {
	buf.read_int8(type_);
	buf.read_string(words_);
	buf.read_int32(scene_id_);
	buf.read_int8(degree_);
	buf.read_uint32(team_index_);
	buf.read_int64(team_id_);
	buf.read_int64(team_id_for_scene_);
	buf.read_int64(leader_role_id_);
	uint16_t len = 0;
	buf.read_uint16(len);
	int64_t role_id = 0;
	for (uint16_t i = 0; i < len; ++i) {
		buf.read_int64(role_id);
		team_member_set_.insert(role_id);
	}
	buf.read_uint16(len);
	for (uint16_t i = 0; i < len; ++i) {
		buf.read_int64(role_id);
		offline_teamer_map_.insert(std::make_pair(role_id, Online_Teamer_Info()));
	}
	buf.read_int8(in_battle_);
	buf.read_uint16(len);
	Int_Role_Id int_role_id;
	Int_Role_Id_Vec lineup;
	for (uint16_t i = 0; i < len; ++i) {
		int_role_id.deserialize(buf);
		lineup.push_back(int_role_id);
	}
	this->lineup_replace(lineup);
	buf.read_int32(enter_level_);
	buf.read_int16(fail_times_);
	buf.read_int16(match_fail_);
	buf.read_bool(is_not_first_team_fb_);
}
int Hero_Info_Detail::deserialize(Block_Buffer &r) {
	if( r.read_int32(hero_id)  ||  r.read_int32(hero_index)  ||  r.read_int32(hero_facade_id)  ||
			r.read_string(hero_name)  ||  r.read_int8(is_outer) ||  r.read_int8(is_fighter)  ||
			r.read_int32(level)  ||  r.read_int32(formation)  || r.read_int32(awake_lvl) ||
			r.read_double(exp)	)
			return -1;

	uint16_t __prop_value_vec_size;
	if(r.read_uint16(__prop_value_vec_size) )
			return -1;
	prop_value.reserve(__prop_value_vec_size);
	for(uint16_t i = 0; i < __prop_value_vec_size; ++i) {
			Int_Double v;
			if(v.deserialize(r))
					return -1;
			prop_value.push_back(v);
	}

	uint16_t size = 0;
	Artifact_Detail artifact_detail;
	r.read_uint16(size);
	for(uint16_t i = 0; i < size; ++i) {
		artifact_detail.reset();
		if (artifact_detail.deserialize(r)) {
			continue;
		};
		artifacts.insert(std::make_pair(artifact_detail.artifact_id, artifact_detail));
	}
	hero_fighter_detail.deserialize(r);
	return 0;
}
int Anci_Artifact_Detail::deserialize(Block_Buffer &buffer) {
	buffer.read_int64(role_id);
//	buffer.read_int64(perfectPoint);
	uint16_t len = 0;
	buffer.read_uint16(len);
	aa_info_map.clear();
	Anci_Artifact_Cond_Info info;
	for (uint16_t i = 0; i < len; ++i) {
		info.reset();
		buffer.read_int32(info.id);
		buffer.read_int8(info.state_count);
		buffer.read_int32(info.data);
		aa_info_map.insert(std::make_pair(info.id, info));
	}
	buffer.read_uint16(len);
	complete_ids.clear();
	int32_t complete_id = 0;
	for (uint16_t i = 0; i < len; ++i) {
		buffer.read_int32(complete_id);
		complete_ids.insert(complete_id);
	}
	aa_unban_info.clear();
	Anci_Artifact_Unban_Info aa_ui;
	for (uint16_t i = 0; i < len; ++i) {
		aa_ui.reset();
		buffer.read_int32(aa_ui.id);
		buffer.read_int8(aa_ui.state);
		buffer.read_int8(aa_ui.box_state);
		aa_unban_info.insert(std::make_pair(aa_ui.id, aa_ui));
	}
	return 0;
}
int Smelter_Detail::deserialize(Block_Buffer & r) {
	if(r.read_int8(smelter_idx) ||
			r.read_int8(is_open)) {
		return -1;
	}
 	return 0;
}
int Scene_Gang_Manager::gang_war_load_source_gangs_from_logic(Block_Buffer &buf) {
	int8_t type = 0;
	buf.read_int8(type);
	if (type == 1) {
		int64_t server_id = 0;
		std::string zone;
		uint16_t len = 0;
		int8_t stage = 0;

		buf.read_int64(server_id);
		buf.read_string(zone);
		buf.read_int8(stage);
		if (stage != stage_
				|| load_source_ < Time_Value::gettimeofday()) {
			gang_map_.clear();
			gangid_serverid_map_.clear();
			gangid_zone_map_.clear();
			server_ids_.clear();
			stage_ = stage;
			load_source_ = Time_Value::gettimeofday() + Time_Value(Time_Value::ONE_MINUTE_IN_SECS * 5);
			MSG_USER("GANG_WAR: source_gangs server_id(%d) clear data",server_id);
		}
		server_ids_.insert(server_id);
		buf.read_uint16(len);
		Gang_War_Spot spot;
		std::map<int8_t, Gang_War_Spot> gang_war_result_map;
		for (uint16_t i = 0; i < len; ++i) {
			spot.reset();
			spot.deserialize(buf);
			gang_war_result_map.insert(std::make_pair(spot.index, spot));
		}
		if (!gang_war_result_map.empty()) {
			gang_war_result_map_.clear();
			gang_war_result_map_ = gang_war_result_map;
		}
		buf.read_uint16(len);
		Gang_DB_View info;
		for (uint16_t i = 0; i < len; ++i) {
			info.reset();
			info.gang_war_deserialize(buf);
			gang_map_.insert(std::make_pair(info.gang_id, info));
			gangid_serverid_map_.insert(std::make_pair(info.gang_id, server_id));
			gangid_zone_map_.insert(std::make_pair(info.gang_id, zone));
			SCENE_GANG_GLOBAL_MANAGER->add_gang(info.gang_id, this);
		}
		MSG_USER("GANG_WAR: source_gangs server_id(%d)",server_id);
	} else {
		role_id_t gang_id = 0;
		buf.read_int64(gang_id);
		gang_map_.erase(gang_id);
		gangid_serverid_map_.erase(gang_id);
		gangid_zone_map_.erase(gang_id);
		SCENE_GANG_GLOBAL_MANAGER->erase_gang(gang_id);
	}
	return 0;
}
int Scene_Server_Request::process_20100503(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf) {
	JUDGE_PLAYER_NULL(player, role_id);
	int8_t type = 0;
	uint16_t len = 0;
	buf.read_int8(type);
	buf.read_uint16(len);
	if (len <= 0) {
		return 0;
	}
//	player
	Hero *hero = SCENE_PUBLIC->find_fight_hero(role_id);
	if (!hero) {
		return 0;
	}
	if (type == 1) { // add
		for (uint16_t i = 0; i < len; ++i) {
			hero->inner_status_insert(buf);
		}
	} else {
		Int_Hash_Set is;
		int status_id = 0;
		for (uint16_t i = 0; i < len; ++i) {
			buf.read_int32(status_id);
			is.insert(status_id);
		}
		hero->erase_status_in_set(is);
	}
	return 0;
}
int Scene_Server_Request::process_20100403(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf) {
	JUDGE_PLAYER_NULL(player, role_id);
	int8_t type = 0;
	buf.read_int8(type);
	uint16_t vec_size = 0;
	if (buf.read_uint16(vec_size)) {
		return -1;
	}

	Int_Double_Map force_map;
	player->get_all_pre_force(force_map);
	int old_val = player->fighter_detail().force;

	Skill_Info skill_info;
	for (uint16_t i = 0; i < vec_size; ++i) {
		skill_info.reset();
		skill_info.deserialize(buf);
		if (type == NPT_ADD) {
			player->add_skill_extra(skill_info.skill_id, skill_info.skill_lv);
		} else if (type == NPT_REMOVE) {
			player->remove_skill_extra(skill_info.skill_id, skill_info.skill_lv);
		}
	}

	if (vec_size > 0) {
		player->sync_force_to_client();
	}

	int new_val = player->fighter_detail().force;
	player->print_all_part_force(100, new_val-old_val, force_map);

	return 0;
}
int Scene_Gang_Manager::set_activity_state(Block_Buffer &buf) {
	int8_t swit = 0;
	buf.read_int8(swit);
	MSG_USER("GANG_WAR: state(%d)",swit);
	switch(swit) {
	case ACTIVITY_OPEN: {
		open_activity();
		break;
	}
	case ACTIVITY_CLOSE: {
		Role_Hash_Set scene_ids;
		for (SceneIndex_GangWarMatchedGangsPair_Map::const_iterator it = scene_index_gang_map_.begin();
				it != scene_index_gang_map_.end(); ++it) {
			scene_ids.insert(it->first);
		}
		GANG_WAR_SCENE_MANAGER->close_all_gang_war_scene(scene_ids);
		close_activity();
		break;
	}
	case GANG_WAR_CREATE_16: {
		gang_war_create_16();
		break;
	}
	case ACTIVITY_READY: {
		ready_activity();
		break;
	}
	default:
		break;
	}
	return 0;
}
int Scene_Server_Request::process_20300100(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf) {
	Monitor_Unique_ID logic_muid;
	role_id_t player_role_id = 0;
	int level = 0;
	int force = 0;
	role_id_t gang_id = 0;
	int8_t remain_income_num = 0;
	int16_t income_rate = 0;
	int total_merit = 0;
	int remain_time = 0;
	int act_time = 0;
	std::string server_name;
	logic_muid.deserialize(buf);
	buf.read_int64(player_role_id);
	buf.read_int32(level);
	buf.read_int32(force);
	buf.read_int64(gang_id);
	buf.read_int8(remain_income_num);
	buf.read_int16(income_rate);
	buf.read_int32(total_merit);
	buf.read_int32(remain_time);
	buf.read_int32(act_time);
	buf.read_string(server_name);
	SCENE_WAR_MANAGER->req_enter_war_scene(logic_muid, player_role_id, level,
			force, gang_id, remain_income_num, income_rate, total_merit, remain_time, act_time, server_name);
	return 0;
}
int Stronghold::deserialize(Block_Buffer &r) {
	r.read_uint32(point_id);
	int8_t tp = 0;
	r.read_int8(tp);
	type = (Expedition_Build_Type)tp;

	info.deserialize(r);
	return 0;
}
int Scene_Server_Request::process_20300101(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf) {
	int8_t sync_type = 0;
	buf.read_int8(sync_type);
	switch(sync_type){
		case 3:{// 单人副本付费复活消耗钻石返回
			if(player && player->move_scene() && player->move_scene()->scene_type() == FuBen_Scene_Type){
				int8_t revive_result = 0;
				buf.read_int8(revive_result);
				if(revive_result == 1){
					int param1 = 0;
					int param2 = 0;
					int param3 = 0;
					player->move_scene()->get_scene_param(param1, param2, param3);
					param1 = 0;
					player->move_scene()->set_scene_param(param1, param2, param3, true);
					player->reset_revive_info();
					{
						MSG_81000026 msg;
						msg.role_id = player->role_id();
						msg.state = 0;
						OBJ_SEND_TO_CLIENT(msg, (*player));
					}
					{
						MSG_50200215 msg;
						msg.result = 1;
						OBJ_SEND_TO_CLIENT(msg, (*player));
					}
				}else{
					MSG_50200215 msg;
					msg.result = 0;
					OBJ_SEND_TO_CLIENT(msg, (*player));
				}
			}
			break;
		}
		default:{
			break;
		}
	}
	return 0;
}
int Scene_Server_Request::process_20100306(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf) {
	int8_t switch_ = 0;
	buf.read_int8(switch_);
	if (switch_ == 0) {
		TEAM_ARENA_CONTROLER->team_sports_test() = false;
		TEAM_ARENA_CONTROLER->close_sports_activity();
	} else {
		TEAM_ARENA_CONTROLER->team_sports_test() = true;
		TEAM_ARENA_CONTROLER->open_sports_activity();
	}
	return 0;
}
int Heroer_Detail::deserialize_fighter(Block_Buffer &buffer){
	this->hero_base_detail_.deserialize(buffer);
	buffer.read_int32(this->fighter_index);
	int8_t has_hero = 0;
	buffer.read_int8(has_hero);
	if(has_hero != 0){
		Hero_Info_Detail info;
		info.deserialize(buffer);
		this->hero_map[this->fighter_index] = info;
	}
	return 0;
}
int Scene_Server_Request::process_20100051(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &inner_buf) {
	JUDGE_PLAYER_NULL(player, role_id);
	MSG_81000067 active_msg;
	inner_buf.read_int64(active_msg.role_id);
	inner_buf.read_int8(active_msg.int_type);
	switch (active_msg.int_type) {
	case 32: {
		uint16_t change_info_size = 0;
		inner_buf.read_uint16(change_info_size);
		if (change_info_size == 0) {
			return -1;
		}
		Int32_Info_Change int32_info_change;
		bool is_hero_awake = false;
		for (uint16_t i = 0; i < change_info_size; ++i) {
			int32_info_change.reset();
			if (int32_info_change.deserialize(inner_buf)) {
				return -1;
			}
			if (int32_info_change.type == IICT_HERO_AWAKE_LVL) {
				is_hero_awake = true;
			}
			active_msg.vec_32_change_info.push_back(int32_info_change);
		}

		// 英雄觉醒等级更新
		if (is_hero_awake) {
			Hero *hero = SCENE_PUBLIC->find_mover_hero(player->role_id());
			if (hero) {
				active_msg.role_id = hero->role_id();
				Block_Buffer active_buf;
				MAKE_MSG_BUF(active_msg, active_buf);
				hero->scene_broad_around(active_buf,Mover::SCENE_MOVE);
			}
		}

		break;
	}
	case 8:
	case 16:
	case 64:
		break;
	default:
		break;
	}

	return 0;
}
Esempio n. 15
0
v8::Local<v8::Value> Msg_Struct::build_object_arg(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate) {
    EscapableHandleScope handle_scope(isolate);

    Local<Value> value;
    if(field_info.field_type == "int8") {
        int8_t val = 0;
        buffer.read_int8(val);
        value = Int32::New(isolate, val);
    }
    else if(field_info.field_type == "int16") {
        int16_t val = 0;
        buffer.read_int16(val);
        value = Int32::New(isolate, val);
    }
    else if(field_info.field_type == "int32") {
        int32_t val = 0;
        buffer.read_int32(val);
        value = Int32::New(isolate, val);
    }
    else if(field_info.field_type == "int64") {
        int64_t val = 0;
        buffer.read_int64(val);
        value = Number::New(isolate, val);
    }
    else if(field_info.field_type == "double") {
        double val = 0;
        buffer.read_double(val);
        value = Number::New(isolate, val);
    }
    else if(field_info.field_type == "bool") {
        bool val = false;
        buffer.read_bool(val);
        value = Boolean::New(isolate, val);
    }
    else if(field_info.field_type == "string") {
        std::string val = "";
        buffer.read_string(val);
        value = String::NewFromUtf8(isolate, val.c_str(), NewStringType::kNormal).ToLocalChecked();
    }
    else {
        LOG_ERROR("Can not find the field_type:%s, struct_name:%s", field_info.field_type.c_str(), struct_name().c_str());
        return handle_scope.Escape(Local<Value>());
    }
    return handle_scope.Escape(value);
}
Esempio n. 16
0
int Player_Monster::hero_battle_birth(Block_Buffer& buf, Battle_Scene* scene) {
    int8_t has_fight_hero = 0;
    buf.read_int8(has_fight_hero);
    if (has_fight_hero) {
        Hero_Base_Detail base_detail;
        base_detail.reset();
        base_detail.deserialize(buf);

        Hero *hero = NPC_MANAGER->create_hero_in_battle_scene(scene, Coord(0,0));
        if (hero) {
            base_detail.hero_role_id = hero->role_id();
            //SCENE_PUBLIC->bind_master_id_hero(detail.master_role_id, *hero);

            hero->refresh_hero_base_detail(base_detail);

            Fighter_Detail fighter_detail;
            fighter_detail.reset();
            fighter_detail.deserialize(buf);
            hero->refresh_hero_fighter_detail(fighter_detail);

            Position_Key player_pos_key = mover_detail().battle_position;
            Position_Key hero_pos_key(player_pos_key.pos, hero->hero_const_base_detail().hero_formation);

            player_pos_key_fit_hero(player_pos_key, hero_pos_key);
            this->set_battle_position(player_pos_key.pos, player_pos_key.idx, scene);
            hero->set_pos_key(hero_pos_key.pos, hero_pos_key.idx);
            // birth
            const Coord &player_coord = mover_detail().grid_coord;
            hero->set_battle_ai();
            if (0 != hero->battle_birth(hero->hero_const_base_detail().hero_role_id, scene,	player_coord)) {
                NPC_MANAGER->destroy_npc(hero);
                return -1;
            }
            hero_role_id_ = hero->role_id();
            hero->hero_base_detail().master_role_id = role_id();
            NPC_MANAGER->battle_scene_npc_map()[hero->role_id()] = hero;
        } else {
            return -1;
        }
    }

    return 0;
}
int Scene_Server_Request::process_20100200(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf) {
	JUDGE_PLAYER_NULL(player, role_id);
	role_id_t role_id_2 = 0;
	int8_t open_type = 0;
	buf.read_int64(role_id_2);
	buf.read_int8(open_type);

	MSG_50100032 res_msg;
	res_msg.role_id = role_id_2;
	res_msg.open_type = open_type;

	player->fighter_detail().property_list(res_msg.prop_value);
	Hero *hero = SCENE_PUBLIC->find_fight_hero(player->role_id());
	if (hero) {
		int hero_init_morale_type = hero->fighter_detail().init_morale.type;
		double hero_init_morale_val = hero->fighter_detail().init_morale.total();
		for (uint16_t i = 0; i < res_msg.prop_value.size(); ++i) {
			if (res_msg.prop_value[i].type == hero_init_morale_type) {
				res_msg.prop_value[i].value += hero_init_morale_val;
			}
		}
	}
	res_msg.prop_value.push_back(Property(PT_CAREER, player->career()));
	res_msg.prop_value.push_back(Property(PT_CHARM, player->base_detail().charm)); /*魅力值*/

	res_msg.role_name = player->role_name();/*人物姓名*/
	res_msg.gang_name = player->base_detail().gang_name;/*人物id*/
	res_msg.gender = player->base_detail().gender;/*性别(1男,2女)*/
	res_msg.gang_id = player->base_detail().gang_id;/*职业*/
	res_msg.headship = player->ganger_detail().headship;
	res_msg.avatar_vec = player->base_detail().avatar_vec;
	res_msg.vip = player->vip();

//    OBJ_SEND_TO_CLIENT(res_msg, (*player));

	Block_Buffer inner_buf;
	inner_buf.make_message(INNER_REQ_OPEN_PANEL);
	res_msg.serialize(inner_buf);
	inner_buf.finish_message();
	player->send_to_logic(inner_buf);
	return 0;
}
Esempio n. 18
0
int Public_Detail::deserialize(Block_Buffer &buffer) {
	buffer.read_string(plot_id);
	buffer.read_int32(plot_step);
	buffer.read_bool(plot_switch);

	uint16_t size = 0;
	buffer.read_uint16(size);
	std::string str = "";
	int num = 0;
	for (uint16_t i = 0; i < size; ++i) {
		buffer.read_string(str);
		buffer.read_int32(num);
		plot_info.insert(String_Int_Map::value_type(str, num));
	}

	buffer.read_int32(awake_lvl);

	Artifact_Detail artifact_detail;
	buffer.read_uint16(size);
	for(uint16_t i = 0; i < size; ++i) {
		artifact_detail.reset();
		if (artifact_detail.deserialize(buffer)) {
			continue;
		};
		artifacts.insert(std::make_pair(artifact_detail.artifact_id, artifact_detail));
	}

	int32_t gift_lvl = 0;
	int8_t status = 0;
	buffer.read_uint16(size);
	for(uint16_t i = 0; i < size; ++i) {
		buffer.read_int32(gift_lvl);
		buffer.read_int8(status);
		fornotice_gifts_status.insert(std::make_pair(gift_lvl, status));
	}

	buffer.read_int32(exploit_val);
	buffer.read_int32(exploit_lvl);

	return 0;
}
int Scene_Server_Request::process_20400000(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf) {
	JUDGE_PLAYER_NULL(player, role_id);
	int8_t detail_type = 0;
	buf.read_int8(detail_type);
	if (detail_type != OUTER_HERO_ONLY && detail_type != FIGHT_HERO_ONLY && detail_type != OUTER_FIGHT_HERO) {
		return -1;
	}
	switch (detail_type) {
	case OUTER_HERO_ONLY:
		process_20400000_1(buf, player);
		break;
	case FIGHT_HERO_ONLY:
		process_20400000_2(buf, player);
		break;
	case OUTER_FIGHT_HERO:
		process_20400000_3(buf, player);
		break;
	default:
		break;
	}

	return 0;
}
int Honor_Arena_Manager::inner_sync_info(Scene_Player* player, Block_Buffer& buf){
	int8_t sync_type = 0;
	buf.read_int8(sync_type);
	switch(sync_type){
		case 99:{
			role_id_t role_id = 0;
			std::string role_name = "";
			uint8_t gender = 0;
			buf.read_int64(role_id);
			buf.read_string(role_name);
			buf.read_uint8(gender);
			Honor_Arena_Player_Info_Map::iterator it = player_info_map_.find(role_id);
			if(it != player_info_map_.end()){
				it->second.rank_info.role_name = role_name;
			}
			break;
		}
		default:{
			break;
		}
	}
	return 0;
}
int Scene_Outpost_Manager::inner_sync_info(Scene_Player* player, Block_Buffer& buf){
	int8_t sync_type = 0;
	buf.read_int8(sync_type);
		switch(sync_type){
		case 10:{// 购买流浪商人物品返回
			if(!player){
				return 0;
			}
			int scene_id = 0;
			int64_t monster_role_id = 0;
			int item_index = 0;
			int8_t result = 0;

			buf.read_int32(scene_id);
			buf.read_int64(monster_role_id);
			buf.read_int32(item_index);
			buf.read_int8(result);
			if(result == 1){
				Vagrant_Item_Info* item_info = get_vagrant_item_info(scene_id, monster_role_id, item_index);
				if(item_info){
					item_info->buy_item(player->role_id());
				}
				MSG_50211301 msg;
				msg.item_index = item_index;
				msg.result = 1;
				OBJ_SEND_TO_CLIENT(msg, (*player));
				req_vagrant_item_info(player, monster_role_id);
			}else{
				MSG_50211301 msg;
				msg.item_index = item_index;
				msg.result = 0;
				OBJ_SEND_TO_CLIENT(msg, (*player));
			}
			return 0;
			break;
		}
		case 20:{
			if(!player){
				return 0;
			}
			int8_t bless_index = 0;
			int8_t result = 0;
			buf.read_int8(bless_index);
			buf.read_int8(result);
			if(result == 1){
				Move_Scene* scene = player->move_scene();
				if(scene){
					Tbay_Scene* tbay_scene = dynamic_cast<Tbay_Scene*>(scene);
					if(tbay_scene){
						tbay_scene->inner_tbay_bless(player, bless_index);
					}
				}
				MSG_50211312 msg;
				msg.bless_index = bless_index;
				msg.result = 1;
				OBJ_SEND_TO_CLIENT(msg, (*player));
			}else{
				MSG_50211312 msg;
				msg.bless_index = bless_index;
				msg.result = 0;
				OBJ_SEND_TO_CLIENT(msg, (*player));
			}
			return 0;
			break;
		}
		default:{
			return 0;
			break;
		}
	}
	return 0;
}
int Logic_Outpost_Manager::inner_sync_info(Logic_Player* player, Block_Buffer& buf){
	int8_t sync_type = 0;
	buf.read_int8(sync_type);
	switch(sync_type){
		case 10:{//购买流浪商人物品
			if(!player){
				return 0;
			}
			int scene_id = 0;
			int64_t monster_role_id = 0;
			int item_index = 0;
			int item_id = 0;
			int item_amount = 0;
			int8_t cost_type = 0;
			int cost_num  = 0;

			buf.read_int32(scene_id);
			buf.read_int64(monster_role_id);
			buf.read_int32(item_index);
			buf.read_int32(item_id);
			buf.read_int32(item_amount);
			buf.read_int8(cost_type);
			buf.read_int32(cost_num);

			int buy_result = 0;
			Money_Sub_Info m_s_info((Pack::Money_Sub_Type)cost_type, cost_num, MONEY_SUB_VAGRANT_STORE);
			if(cost_num > 0){
				buy_result = player->pack_try_sub_money(m_s_info);
			}
			if(buy_result != 0){
				player->send_err_to_client(buy_result, REQ_VAGRANT_BUY_ITEM);
				{
					Block_Buffer buf;
					buf.make_message(INNER_SYNC_SCENE_OUTPOST);
					buf.write_int8(sync_type);
					buf.write_int32(scene_id);
					buf.write_int64(monster_role_id);
					buf.write_int32(item_index);
					buf.write_int8(0);
					buf.finish_message();
					player->send_to_scene(buf);
				}
				return 0;
			}
			// 背包检测
			Item_Detail item = Item_Detail(item_id, item_amount, (Item_Detail::Bind_Type)0);
			buy_result = player->pack_try_insert_item(Pack::PACK_T_PACKAGE_INDEX, item);
			if( buy_result != 0){
				player->send_err_to_client(buy_result, REQ_VAGRANT_BUY_ITEM);
				{
					Block_Buffer buf;
					buf.make_message(INNER_SYNC_SCENE_OUTPOST);
					buf.write_int8(sync_type);
					buf.write_int32(scene_id);
					buf.write_int64(monster_role_id);
					buf.write_int32(item_index);
					buf.write_int8(0);
					buf.finish_message();
					player->send_to_scene(buf);
				}
				return 0;
			}
			// 添加到背包
			player->pack_insert_item(Pack::PACK_T_PACKAGE_INDEX, item,Gain_Item_DM_Info(Pack::ITEM_GAIN_VAGRANT_STORE));
			// 扣钱
			if(cost_num > 0){
				player->pack_sub_money(m_s_info);
			}
			{
				MSG_81000102 acv_msg;
				acv_msg.type = 0;
				Item_Basic_Info ibi;
				item.set_item_basic_info(ibi);
				acv_msg.item_info.push_back(ibi);
				OBJ_SEND_TO_CLIENT(acv_msg, (*player));
			}
			Block_Buffer buf;
			buf.make_message(INNER_SYNC_SCENE_OUTPOST);
			buf.write_int8(sync_type);
			buf.write_int32(scene_id);
			buf.write_int64(monster_role_id);
			buf.write_int32(item_index);
			buf.write_int8(1);
			buf.finish_message();
			player->send_to_scene(buf);
			return 0;
			break;
		}
		case 20:{// 宝藏海湾神秘祝福
			int8_t bless_index;
			int cost_type = 0;
			int cost_num = 0;
			buf.read_int8(bless_index);
			buf.read_int32(cost_type);
			buf.read_int32(cost_num);
			int buy_result = 0;
			Money_Sub_Info m_s_info((Pack::Money_Sub_Type)cost_type, cost_num, MONEY_SUB_TBAY_BLESS);
			if(cost_num > 0){
				buy_result = player->pack_try_sub_money(m_s_info);
			}
			if(buy_result != 0){
				player->send_err_to_client(buy_result, REQ_TBAY_BLESS);
				{
					Block_Buffer buf;
					buf.make_message(INNER_SYNC_SCENE_OUTPOST);
					buf.write_int8(sync_type);
					buf.write_int8(bless_index);
					buf.write_int8(0);
					buf.finish_message();
					player->send_to_scene(buf);
				}
				return 0;
			}
			// 扣钱
			if(cost_num > 0){
				player->pack_sub_money(m_s_info);
			}
			Block_Buffer buf;
			buf.make_message(INNER_SYNC_SCENE_OUTPOST);
			buf.write_int8(sync_type);
			buf.write_int8(bless_index);
			buf.write_int8(1);
			buf.finish_message();
			player->send_to_scene(buf);
			return 0;
			break;
		}
		default:{
			break;
		}
	}
	return 0;
}
Esempio n. 23
0
// 解Tasker::serialize发过来的数据
void Scene_Tasker::load_scene_detail(Block_Buffer &buf) {
	int8_t flag = 0;
	TaskIdSet task_id_set;
//	Int_Int_Vec item_to_source; //val_1:npc_id   val_2:item_id

	Npc_Item_Chance_Map npc_item_chance_map;
	uint16_t size = 0;
	int32_t task_id = 0;

	buf.read_int8(flag);//1 flag
	buf.read_uint16(size);//2  : task_id的个数
	for (uint16_t i = 0; i < size; ++i) {
		buf.read_int32(task_id); //3...  task_id
		task_id_set.insert(task_id);
	}
	switch(flag) {
	case SYNC_TASK_SOURCE_DEL:
	case SYNC_TASK_SOURCE_ADD: {
		buf.read_uint16(size); //4  npc_id的个数
		for (uint16_t i = 0; i < size; ++i) {
			int npc_id = 0;
			Item_Chance item_chance;
			item_chance.reset();

			buf.read_int32(npc_id); //5...  npc_id
			buf.read_int32(item_chance.val_1); //6...  item_id
			buf.read_int32(item_chance.val_2); //7...  chance
//			item_to_source.push_back(i_t_s);
			npc_item_chance_map.insert(std::make_pair(npc_id, item_chance));
		}
		break;
	}
	case SYNC_TASK_SOURCE_TRANSMIT: {
		buf.read_uint16(size);//4     npc_id的个数
//		Int_Int i_t_s;

		uint16_t size2 = 0;
		for (uint16_t i = 0; i < size; ++i) {
			int npc_id = 0;
//			i_t_s.reset();
			buf.read_int32(npc_id);//5... npc_id

			buf.read_uint16(size2); //6...  item_id 的个数
			for (uint16_t j = 0; j < size2; ++j) {
				Item_Chance item_chance;
				item_chance.reset();
				buf.read_int32(item_chance.val_1); //7... item_id
				buf.read_int32(item_chance.val_2); //8... chance
				npc_item_chance_map.insert(std::make_pair(npc_id, item_chance));
			}
		}
		break;
	}
	}

	switch(flag) {
	case SYNC_TASK_SOURCE_ADD:
		for (TaskIdSet::const_iterator it = task_id_set.begin(); it != task_id_set.end(); ++it) {
			this->__task_id_set.insert(*it);
		}
		for (Npc_Item_Chance_Map::const_iterator it = npc_item_chance_map.begin(); it != npc_item_chance_map.end(); ++it ) {
			add_source_to_item(it->first, it->second);
		}
		break;
	case SYNC_TASK_SOURCE_TRANSMIT:
		__task_id_set.clear();
		__npc_ItemIdSet_map.clear();

		for (TaskIdSet::const_iterator it = task_id_set.begin(); it != task_id_set.end(); ++it) {
			this->__task_id_set.insert(*it);
		}
		for (Npc_Item_Chance_Map::const_iterator it = npc_item_chance_map.begin(); it != npc_item_chance_map.end(); ++it ) {
			add_source_to_item(it->first, it->second);
		}
		break;
	case SYNC_TASK_SOURCE_DEL:
		for (TaskIdSet::const_iterator it = task_id_set.begin(); it != task_id_set.end(); ++it) {
			this->__task_id_set.erase(*it);
		}
		for (Npc_Item_Chance_Map::const_iterator it = npc_item_chance_map.begin(); it != npc_item_chance_map.end(); ++it ) {
			erase_source_to_item(it->first, it->second);
		}
		break;
	default:
		break;
	}
}
int Scene_Knight_Trials_Manager::scene_knight_trials_enter_fighter(Scene_Player *player, Block_Buffer& buf) {
	if(player == NULL){
		return -1;
	}
	if(player->battle_scene()) { //正在战斗中
		MSG_DEBUG("knight trials enter fighter is on fighter role_id:%ld, battle_status_:%d, battle_type_:%d",
				player->role_id(), player->battle_scene()->battle_status() , player->battle_scene()->get_battle_type());
		//MSG_DEBUG("knight trials enter fighter is on fighter role_id:%ld", 	player->role_id());
		return -1;
	}
	Battle_Scene *scene = GLOBAL_SCENE_MANAGER->create_battle_scene(player->move_scene());
	if(!scene){
		return -1;
	}
	scene->set_battle_type(Battle_Scene::BATTLE_TYPE_KNIGHT_TRIALS);
	scene->set_map_id(KNIGHT_TRIALS_FIGHTER_SCENE_MAP_ID);

	std::string role_name;
	role_name.clear();
	int8_t career = 0;
	int8_t gender = 0;
	buf.read_int8(career);
	buf.read_int8(gender);
	buf.read_string(role_name);
	int8_t size = 0;
	buf.read_int8(size);
	Int_Vec avatar_vec;
	for (int8_t i=0; i<size; ++i) {
		int avatar_id = 0;
		buf.read_int32(avatar_id);
		avatar_vec.push_back(avatar_id);
	}

	NPC_Addition_Info add_info;
	add_info.birth_coord.x = 1;
	add_info.birth_coord.y = 5;
	add_info.ex_val1 = career;
	add_info.ex_val2 = gender;
	add_info.name = role_name;
	int monster_type = 63800108;
	Player_Monster* player_monster;
	player_monster = NPC_MANAGER->create_player_monster(monster_type, NULL, add_info, scene, buf);
	if(player_monster == NULL){
		return -1;
	}

	player_monster->set_player_monster_avatar(avatar_vec);
	player_monster->hero_battle_birth(buf, scene);
	player_monster->battle_enter_appaer(scene);
	double morale_init = player_monster->fighter_detail().fetch_fight_property(Property_Type::PT_INIT_MORALE, Prop_Value::ELEM_NORMAL);
	Hero* hero = player_monster->find_hero();
	if(0 != hero) {
		morale_init += hero->fighter_detail().fetch_fight_property(Property_Type::PT_INIT_MORALE, Prop_Value::ELEM_NORMAL);
	}
	player_monster->reset_morale_and_hp(morale_init, player_monster->blood_max(), false);

	if(player->set_battle_position(0, Position_Key::LINE_TWO_FRONT, scene) == 0){
		player->enter_battle_scene(scene);
	}
	return 0;
}
int Scene_Server_Request::process_20300030(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf){
	JUDGE_PLAYER_NULL(player, role_id);

	if (player->is_in_battle()) {
		MSG_DEBUG("creat arena fail player in battle");
		return ERROR_PLAYER_IN_BATTLE;
	}
	if (player->dead_status()) {
		MSG_DEBUG("creat arena fail player dead");
		return ERROR_PLAYER_DIE;
	}

	Battle_Scene *scene = GLOBAL_SCENE_MANAGER->create_battle_scene(player->move_scene());
	if(!scene){
		return -1;
	}
	scene->set_battle_type(Battle_Scene::BATTLE_TYPE_ARENA);
	int fight_map_id = CONFIG_CACHE_ARENA->get_arena_fight_map_id();
	scene->set_map_id(fight_map_id);
//	role_id_t match_role_id = 0;
//	buf.read_int64(match_role_id);
//	if(match_role_id == 0){
//
//	}else{
//
//	}
	int32_t inner_area = 0;
	int8_t career = 0;
	int8_t gender = 0;
	std::string role_name;
	buf.read_int32(inner_area);
	buf.read_int8(career);
	buf.read_int8(gender);
	buf.read_string(role_name);
	int8_t size = 0;
	buf.read_int8(size);
	Int_Vec avatar_vec;
	for (int8_t i=0; i<size; ++i) {
		int avatar_id = 0;
		buf.read_int32(avatar_id);
		avatar_vec.push_back(avatar_id);
	}

	NPC_Addition_Info add_info;
	add_info.birth_coord.x = 1;
	add_info.birth_coord.y = 5;
	add_info.ex_val1 = career;
	add_info.ex_val2 = gender;
	add_info.name = role_name;
	int monster_type = 63800108;
	Player_Monster* player_monster;
	player_monster = NPC_MANAGER->create_player_monster(monster_type, NULL, add_info, scene, buf);
	if(player_monster == NULL){
		MSG_DEBUG("creat arena monster fail");
		return -1;
	}

	player_monster->set_player_monster_avatar(avatar_vec);

	player_monster->hero_battle_birth(buf, scene);
	player_monster->battle_enter_appaer(scene);
	double morale_init = player_monster->fighter_detail().fetch_fight_property(Property_Type::PT_INIT_MORALE, Prop_Value::ELEM_NORMAL);
	Hero* hero = player_monster->find_hero();
	if(0 != hero) {
		morale_init += hero->fighter_detail().fetch_fight_property(Property_Type::PT_INIT_MORALE, Prop_Value::ELEM_NORMAL);
	}
	player_monster->reset_morale_and_hp(morale_init, player_monster->blood_max(), false);

	if(player->set_battle_position(0, Position_Key::LINE_TWO_FRONT, scene) == 0){
		player->enter_battle_scene(scene);
	}

	return 0;
}