This commit is contained in:
aozhiwei 2019-04-09 16:08:08 +08:00
parent 5466fdc96b
commit 26786fbf2f
4 changed files with 52 additions and 40 deletions

View File

@ -57,19 +57,36 @@ namespace MetaData
total_weight = 0;
for (size_t i = 0; i < item_list.size(); ++i) {
total_weight += a8::XValue(weight_list[i]).GetInt();
std::vector<int> itemids;
{
std::vector<std::string> strings;
a8::Split(item_list[i], strings, ':');
for (auto& str : strings) {
itemids.push_back(a8::XValue(str).GetInt());
}
}
std::vector<int> nums;
{
std::vector<std::string> strings;
a8::Split(num_list[i], strings, ':');
for (auto& str : strings) {
nums.push_back(a8::XValue(str).GetInt());
}
}
assert(itemids.size() == nums.size());
if (this->i->type() == 1) {
std::tuple<int, int, int> item_tuple = std::make_tuple(
a8::XValue(item_list[i]),
a8::XValue(num_list[i]),
a8::XValue(weight_list[i])
);
auto item_tuple = std::make_tuple(
itemids,
nums,
a8::XValue(weight_list[i]).GetInt()
);
items.push_back(item_tuple);
} else {
std::tuple<int, int, int> item_tuple = std::make_tuple(
a8::XValue(item_list[i]),
a8::XValue(num_list[i]),
total_weight
);
auto item_tuple = std::make_tuple(
itemids,
nums,
total_weight
);
items.push_back(item_tuple);
}
}
@ -81,20 +98,24 @@ namespace MetaData
if (i->type() == 1) {
for (auto& item : items) {
if ((rand() % 10000) <= std::get<2>(item)) {
drop_items.push_back(std::make_tuple(
std::get<0>(item),
std::get<1>(item)
));
for (size_t i = 0; i < std::get<0>(item).size(); ++i) {
drop_items.push_back(std::make_tuple(
std::get<0>(item)[i],
std::get<1>(item)[i]
));
}
}
}
} else if (total_weight > 0) {
int rnd = rand() % total_weight;
for (auto& item : items) {
if (std::get<2>(item) >= rnd) {
drop_items.push_back(std::make_tuple(
std::get<0>(item),
std::get<1>(item)
));
for (size_t i = 0; i < std::get<0>(item).size(); ++i) {
drop_items.push_back(std::make_tuple(
std::get<0>(item)[i],
std::get<1>(item)[i]
));
}
break;
}
}

View File

@ -72,7 +72,7 @@ namespace MetaData
void RandItems(std::vector<std::tuple<int, int>>& drop_items);
private:
std::vector<std::tuple<int, int, int>> items;
std::vector<std::tuple<std::vector<int>, std::vector<int>, int>> items;
int total_weight = 0;
};

View File

@ -424,7 +424,7 @@ void Player::LootInteraction(Loot* entity)
weapons[0].weapon_idx = 0;
weapons[0].weapon_id = entity->item_id;
weapons[0].weapon_lv = 1;
weapons[0].ammo = entity->count;
weapons[0].ammo = 0;
need_sync_active_player = true;
}
need_sync_active_player = true;
@ -454,7 +454,7 @@ void Player::LootInteraction(Loot* entity)
}
weapon->weapon_id = entity->item_id;
weapon->weapon_lv = 1;
weapon->ammo = entity->count;
weapon->ammo = 0;
weapon->meta = item_meta;
AutoLoadingBullet();
need_sync_active_player = true;
@ -811,27 +811,18 @@ void Player::MakeUpdateMsg()
}
}
}
if (updated_times == 0) {
for (auto& pair : room->uniid_hash_) {
if (pair.second->entity_type == ET_Building) {
new_objects.insert(pair.second);
}
}
}
for (auto& itr : new_objects) {
itr->FillMFObjectFull(update_msg->add_full_objects());
#if 0
if (itr->frame_data.bullets.size() > 0) {
update_msg->mutable_bullets()->MergeFrom(itr->frame_data.bullets);
}
if (itr->frame_data.shots.size() > 0) {
update_msg->mutable_shots()->MergeFrom(itr->frame_data.shots);
}
#endif
}
for (auto& itr : part_objects) {
itr->FillMFObjectPart(update_msg->add_part_objects());
#if 0
if (itr->frame_data.bullets.size() > 0) {
update_msg->mutable_bullets()->MergeFrom(itr->frame_data.bullets);
}
if (itr->frame_data.shots.size() > 0) {
update_msg->mutable_shots()->MergeFrom(itr->frame_data.shots);
}
#endif
}
if (updated_times == 0 || need_sync_active_player) {
update_msg->set_active_player_id(entity_uniid);

View File

@ -98,8 +98,8 @@ int Room::AliveCount()
void Room::AddPlayer(Player* hum)
{
{
hum->pos.x = 1000 + rand() % 100;
hum->pos.y = 2000 + rand() % 200;
hum->pos.x = 3000 + rand() % 100;
hum->pos.y = 3000 + rand() % 200;
hum->attack_dir = hum->pos;
hum->attack_dir.Normalize();
hum->attack_dir.Rotate(a8::RandAngle());
@ -406,7 +406,7 @@ void Room::CreateThings()
MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(thing_id);
if (thing_meta) {
if (thing_meta->i->is_house()) {
MetaData::Building* building_meta = MetaMgr::Instance()->GetBuilding(1);
MetaData::Building* building_meta = MetaMgr::Instance()->GetBuilding(thing_meta->i->house_id());
if (building_meta) {
Building* entity = new Building();
entity->room = this;