修复宕机问题

This commit is contained in:
aozhiwei 2020-03-20 18:23:03 +08:00
parent f46d7dd153
commit 7302bb67ee
4 changed files with 28 additions and 18 deletions

View File

@ -80,6 +80,13 @@ void GridService::GetAllCellsByXy(int x, int y, std::set<GridCell*>& grid_list)
GetAllCells(new_grid_id, grid_list); GetAllCells(new_grid_id, grid_list);
} }
bool GridService::CanAdd(float x, float y)
{
int new_x = (int)x + cell_width_;
int new_y = (int)x + cell_width_;
return !BroderOverFlow(new_x, new_y);
}
void GridService::AddHuman(Human* hum) void GridService::AddHuman(Human* hum)
{ {
int x = (int)hum->GetX() + cell_width_; int x = (int)hum->GetX() + cell_width_;

View File

@ -25,6 +25,7 @@ class GridService
bool BroderOverFlow(int x, int y); bool BroderOverFlow(int x, int y);
void GetAllCells(int grid_id, std::set<GridCell*>& grid_list); void GetAllCells(int grid_id, std::set<GridCell*>& grid_list);
void GetAllCellsByXy(int x, int y, std::set<GridCell*>& grid_list); void GetAllCellsByXy(int x, int y, std::set<GridCell*>& grid_list);
bool CanAdd(float x, float y);
void AddHuman(Human* hum); void AddHuman(Human* hum);
void MoveHuman(Human* hum); void MoveHuman(Human* hum);

View File

@ -2929,9 +2929,9 @@ void Human::ProcSkillPhase(MetaData::SkillPhase* phase)
void Human::AutoChgWeapon() void Human::AutoChgWeapon()
{ {
if (weapons[GUN_SLOT1].weapon_idx != 0) { if (weapons[GUN_SLOT1].weapon_id != 0) {
curr_weapon = &weapons[GUN_SLOT1]; curr_weapon = &weapons[GUN_SLOT1];
} else if (weapons[GUN_SLOT2].weapon_idx != 0) { } else if (weapons[GUN_SLOT2].weapon_id != 0) {
curr_weapon = &weapons[GUN_SLOT2]; curr_weapon = &weapons[GUN_SLOT2];
} else { } else {
curr_weapon = &weapons[0]; curr_weapon = &weapons[0];

View File

@ -578,22 +578,24 @@ int Room::CreateLoot(int equip_id, a8::Vec2 pos, int count, int equip_lv)
void Room::CreateBullet(Human* hum, Weapon* weapon, void Room::CreateBullet(Human* hum, Weapon* weapon,
a8::Vec2 pos, a8::Vec2 dir, float fly_distance, bool is_tank_skin) a8::Vec2 pos, a8::Vec2 dir, float fly_distance, bool is_tank_skin)
{ {
Bullet* bullet = new Bullet(); if (grid_service.CanAdd(pos.x, pos.y)) {
bullet->player = hum; Bullet* bullet = new Bullet();
bullet->room = this; bullet->player = hum;
bullet->gun_meta = weapon->meta; bullet->room = this;
bullet->gun_upgrade_meta = weapon->upgrade_meta; bullet->gun_meta = weapon->meta;
bullet->meta = MetaMgr::Instance()->GetEquip(weapon->meta->i->use_bullet()); bullet->gun_upgrade_meta = weapon->upgrade_meta;
bullet->SetPos(pos); bullet->meta = MetaMgr::Instance()->GetEquip(weapon->meta->i->use_bullet());
bullet->dir = dir; bullet->SetPos(pos);
bullet->born_pos = pos; bullet->dir = dir;
bullet->born_dir = dir; bullet->born_pos = pos;
bullet->fly_distance = fly_distance; bullet->born_dir = dir;
bullet->is_tank_skin = is_tank_skin; bullet->fly_distance = fly_distance;
bullet->entity_uniid = AllocUniid(); bullet->is_tank_skin = is_tank_skin;
bullet->Initialize(); bullet->entity_uniid = AllocUniid();
AddObjectLater(bullet); bullet->Initialize();
grid_service.AddBullet(bullet); AddObjectLater(bullet);
grid_service.AddBullet(bullet);
}
} }
void Room::RemoveObjectLater(Entity* entity) void Room::RemoveObjectLater(Entity* entity)