1
This commit is contained in:
parent
5466fdc96b
commit
26786fbf2f
@ -57,17 +57,34 @@ namespace MetaData
|
|||||||
total_weight = 0;
|
total_weight = 0;
|
||||||
for (size_t i = 0; i < item_list.size(); ++i) {
|
for (size_t i = 0; i < item_list.size(); ++i) {
|
||||||
total_weight += a8::XValue(weight_list[i]).GetInt();
|
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) {
|
if (this->i->type() == 1) {
|
||||||
std::tuple<int, int, int> item_tuple = std::make_tuple(
|
auto item_tuple = std::make_tuple(
|
||||||
a8::XValue(item_list[i]),
|
itemids,
|
||||||
a8::XValue(num_list[i]),
|
nums,
|
||||||
a8::XValue(weight_list[i])
|
a8::XValue(weight_list[i]).GetInt()
|
||||||
);
|
);
|
||||||
items.push_back(item_tuple);
|
items.push_back(item_tuple);
|
||||||
} else {
|
} else {
|
||||||
std::tuple<int, int, int> item_tuple = std::make_tuple(
|
auto item_tuple = std::make_tuple(
|
||||||
a8::XValue(item_list[i]),
|
itemids,
|
||||||
a8::XValue(num_list[i]),
|
nums,
|
||||||
total_weight
|
total_weight
|
||||||
);
|
);
|
||||||
items.push_back(item_tuple);
|
items.push_back(item_tuple);
|
||||||
@ -81,20 +98,24 @@ namespace MetaData
|
|||||||
if (i->type() == 1) {
|
if (i->type() == 1) {
|
||||||
for (auto& item : items) {
|
for (auto& item : items) {
|
||||||
if ((rand() % 10000) <= std::get<2>(item)) {
|
if ((rand() % 10000) <= std::get<2>(item)) {
|
||||||
|
for (size_t i = 0; i < std::get<0>(item).size(); ++i) {
|
||||||
drop_items.push_back(std::make_tuple(
|
drop_items.push_back(std::make_tuple(
|
||||||
std::get<0>(item),
|
std::get<0>(item)[i],
|
||||||
std::get<1>(item)
|
std::get<1>(item)[i]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (total_weight > 0) {
|
} else if (total_weight > 0) {
|
||||||
int rnd = rand() % total_weight;
|
int rnd = rand() % total_weight;
|
||||||
for (auto& item : items) {
|
for (auto& item : items) {
|
||||||
if (std::get<2>(item) >= rnd) {
|
if (std::get<2>(item) >= rnd) {
|
||||||
|
for (size_t i = 0; i < std::get<0>(item).size(); ++i) {
|
||||||
drop_items.push_back(std::make_tuple(
|
drop_items.push_back(std::make_tuple(
|
||||||
std::get<0>(item),
|
std::get<0>(item)[i],
|
||||||
std::get<1>(item)
|
std::get<1>(item)[i]
|
||||||
));
|
));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ namespace MetaData
|
|||||||
void RandItems(std::vector<std::tuple<int, int>>& drop_items);
|
void RandItems(std::vector<std::tuple<int, int>>& drop_items);
|
||||||
|
|
||||||
private:
|
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;
|
int total_weight = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ void Player::LootInteraction(Loot* entity)
|
|||||||
weapons[0].weapon_idx = 0;
|
weapons[0].weapon_idx = 0;
|
||||||
weapons[0].weapon_id = entity->item_id;
|
weapons[0].weapon_id = entity->item_id;
|
||||||
weapons[0].weapon_lv = 1;
|
weapons[0].weapon_lv = 1;
|
||||||
weapons[0].ammo = entity->count;
|
weapons[0].ammo = 0;
|
||||||
need_sync_active_player = true;
|
need_sync_active_player = true;
|
||||||
}
|
}
|
||||||
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_id = entity->item_id;
|
||||||
weapon->weapon_lv = 1;
|
weapon->weapon_lv = 1;
|
||||||
weapon->ammo = entity->count;
|
weapon->ammo = 0;
|
||||||
weapon->meta = item_meta;
|
weapon->meta = item_meta;
|
||||||
AutoLoadingBullet();
|
AutoLoadingBullet();
|
||||||
need_sync_active_player = true;
|
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) {
|
for (auto& itr : new_objects) {
|
||||||
itr->FillMFObjectFull(update_msg->add_full_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) {
|
for (auto& itr : part_objects) {
|
||||||
itr->FillMFObjectPart(update_msg->add_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) {
|
if (updated_times == 0 || need_sync_active_player) {
|
||||||
update_msg->set_active_player_id(entity_uniid);
|
update_msg->set_active_player_id(entity_uniid);
|
||||||
|
@ -98,8 +98,8 @@ int Room::AliveCount()
|
|||||||
void Room::AddPlayer(Player* hum)
|
void Room::AddPlayer(Player* hum)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
hum->pos.x = 1000 + rand() % 100;
|
hum->pos.x = 3000 + rand() % 100;
|
||||||
hum->pos.y = 2000 + rand() % 200;
|
hum->pos.y = 3000 + rand() % 200;
|
||||||
hum->attack_dir = hum->pos;
|
hum->attack_dir = hum->pos;
|
||||||
hum->attack_dir.Normalize();
|
hum->attack_dir.Normalize();
|
||||||
hum->attack_dir.Rotate(a8::RandAngle());
|
hum->attack_dir.Rotate(a8::RandAngle());
|
||||||
@ -406,7 +406,7 @@ void Room::CreateThings()
|
|||||||
MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(thing_id);
|
MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(thing_id);
|
||||||
if (thing_meta) {
|
if (thing_meta) {
|
||||||
if (thing_meta->i->is_house()) {
|
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) {
|
if (building_meta) {
|
||||||
Building* entity = new Building();
|
Building* entity = new Building();
|
||||||
entity->room = this;
|
entity->room = this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user