merge master

This commit is contained in:
aozhiwei 2019-04-11 12:42:31 +08:00
commit fd1151523a
5 changed files with 40 additions and 9 deletions

View File

@ -80,6 +80,7 @@ void Bullet::OnHit(std::vector<Entity*>& objects)
{ {
Human* hum = (Human*)target; Human* hum = (Human*)target;
if (!hum->dead) { if (!hum->dead) {
player->stats.damage_amount += 10;
hum->DecHP(10, player->entity_uniid, player->name); hum->DecHP(10, player->entity_uniid, player->name);
} }
} }

View File

@ -328,8 +328,32 @@ void Human::ResetAction()
void Human::FillSMGameOver(cs::SMGameOver& msg) void Human::FillSMGameOver(cs::SMGameOver& msg)
{ {
std::vector<Human*> human_list;
room->TouchHumanList(a8::XParams(),
[&human_list] (Human* hum, a8::XParams& param)
{
human_list.push_back(hum);
});
std::sort(human_list.begin(), human_list.end(),
[] (Human* a, Human* b )
{
if (a->dead_frameno == b->dead_frameno) {
return a->entity_uniid < b->entity_uniid;
} else {
return a->dead_frameno == 0 ||
(b->dead_frameno != 0 && a->dead_frameno > b->dead_frameno);
}
});
int rank = human_list.size();
for (size_t i = 0; i < human_list.size(); ++i) {
if (human_list[i] == this) {
rank = i + 1;
break;
}
}
msg.set_team_id(0); msg.set_team_id(0);
msg.set_team_rank(0); msg.set_team_rank(rank);
msg.set_team_allcnt(1); msg.set_team_allcnt(1);
msg.set_game_over(true); msg.set_game_over(true);
msg.set_victory(false); msg.set_victory(false);
@ -341,6 +365,10 @@ void Human::FillSMGameOver(cs::SMGameOver& msg)
void Human::BeKill(int killer_id, const std::string& killer_name) void Human::BeKill(int killer_id, const std::string& killer_name)
{ {
if (!dead) { if (!dead) {
Entity* hum = room->GetEntityByUniId(killer_id);
if (hum && hum->entity_type == ET_Player) {
((Human*)hum)->stats.kills++;
}
stats.killer_id = killer_id; stats.killer_id = killer_id;
stats.killer_name = killer_name; stats.killer_name = killer_name;
dead = true; dead = true;
@ -354,7 +382,7 @@ void Human::BeKill(int killer_id, const std::string& killer_name)
void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name) void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name)
{ {
health = std::min(0.0f, health - dec_hp); health = std::max(0.0f, health - dec_hp);
if (health <= 0.0001f) { if (health <= 0.0001f) {
BeKill(killer_id, killer_name); BeKill(killer_id, killer_name);
} }

View File

@ -195,8 +195,10 @@ void Player::UpdateAction()
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id); MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id);
if (item_meta){ if (item_meta){
if (inventory[item_meta->i->_inventory_slot()] > 0) { if (inventory[item_meta->i->_inventory_slot()] > 0) {
float old_health = health;
health += item_meta->i->heal(); health += item_meta->i->heal();
health = std::min(100.0f, health); health = std::min(100.0f, health);
stats.heal_amount += health - old_health;
--inventory[item_meta->i->_inventory_slot()]; --inventory[item_meta->i->_inventory_slot()];
need_sync_active_player = true; need_sync_active_player = true;
SyncAroundPlayers(); SyncAroundPlayers();
@ -517,7 +519,7 @@ void Player::LootInteraction(Loot* entity)
if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) { if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) {
return; return;
} }
room->DropItem(pos, old_item_meta->i->id()); room->DropItem(pos, old_item_meta->i->id(), 1);
} }
backpack = item_meta->i->id(); backpack = item_meta->i->id();
} }
@ -532,7 +534,7 @@ void Player::LootInteraction(Loot* entity)
if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) { if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) {
return; return;
} }
room->DropItem(pos, old_item_meta->i->id()); room->DropItem(pos, old_item_meta->i->id(), 1);
} }
chest = item_meta->i->id(); chest = item_meta->i->id();
} else if (item_meta->i->equip_subtype() == 2) { } else if (item_meta->i->equip_subtype() == 2) {
@ -542,7 +544,7 @@ void Player::LootInteraction(Loot* entity)
if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) { if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) {
return; return;
} }
room->DropItem(pos, old_item_meta->i->id()); room->DropItem(pos, old_item_meta->i->id(), 1);
} }
helmet = item_meta->i->id(); helmet = item_meta->i->id();
} }

View File

@ -300,7 +300,7 @@ void Room::ScatterDrop(Vector2D center, int drop_id)
for (auto& item : drop_items) { for (auto& item : drop_items) {
Vector2D dir = Vector2D::UP; Vector2D dir = Vector2D::UP;
dir.Rotate(a8::RandAngle()); dir.Rotate(a8::RandAngle());
DropItem(center + dir * (5 + rand() % 50), std::get<0>(item)); DropItem(center + dir * (5 + rand() % 50), std::get<0>(item), std::get<1>(item));
} }
} }
} }
@ -381,7 +381,7 @@ void Room::FillSMMapInfo(cs::SMMapInfo& map_info)
} }
} }
void Room::DropItem(Vector2D pos, int item_id) void Room::DropItem(Vector2D pos, int item_id, int item_count)
{ {
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(item_id); MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(item_id);
if (equip_meta) { if (equip_meta) {
@ -395,7 +395,7 @@ void Room::DropItem(Vector2D pos, int item_id)
entity->pos = pos + dir * (25 + rand() % 50); entity->pos = pos + dir * (25 + rand() % 50);
} }
entity->item_id = equip_meta->i->id(); entity->item_id = equip_meta->i->id();
entity->count = 1; entity->count = item_count;
entity->Initialize(); entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity; uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) { for (auto& pair : human_hash_) {

View File

@ -49,7 +49,7 @@ public:
std::function<void (Human*, a8::XParams&)> func); std::function<void (Human*, a8::XParams&)> func);
void ScatterDrop(Vector2D center, int drop_id); void ScatterDrop(Vector2D center, int drop_id);
void DropItem(Vector2D pos, int item_id); void DropItem(Vector2D pos, int item_id, int item_count);
void CreateThings(); void CreateThings();
void CreateDoor(Building* building, int door_idx); void CreateDoor(Building* building, int door_idx);