This commit is contained in:
aozhiwei 2021-03-05 11:41:25 +08:00
parent a001cd6468
commit 0cd2123369
8 changed files with 64 additions and 59 deletions

View File

@ -33,6 +33,9 @@ void Car::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
void Car::GetDown(Human* passenger)
{
if (later_removed_) {
return;
}
if (passengers.find(passenger) == passengers.end()) {
return;
}
@ -56,6 +59,8 @@ void Car::GetDown(Human* passenger)
loot_entity->GetPos());
}
room->TakeOffCarObject(loot_uniid, GetPos());
room->RemoveObjectLater(this);
later_removed_ = true;
}
passenger->SetCar(nullptr);
passenger->SetSeat(0);
@ -65,4 +70,5 @@ void Car::GetDown(Human* passenger)
passenger->RemoveBuffByEffectId(kBET_Passenger);
room->frame_event.AddCarChg(passenger);
SyncAroundPlayers(__FILE__, __LINE__, __func__);
room->NotifyUiUpdate();
}

View File

@ -26,4 +26,7 @@ class Car : public MoveableEntity
virtual void FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) override;
void GetDown(Human* passenger);
private:
bool later_removed_ = false;
};

View File

@ -191,6 +191,21 @@ void GridService::DelBullet(Bullet* bullet)
cell.RemoveBullet(bullet);
}
void GridService::AddCar(Car* car)
{
}
void GridService::MoveCar(Car* car)
{
}
void GridService::DelCar(Car* car)
{
}
void GridService::AddRoomEntity(Room* room, Entity* entity)
{
assert(!entity->IsEntityType(ET_Player));

View File

@ -4,6 +4,7 @@ class Human;
class Entity;
class Room;
class Bullet;
class Car;
class GridCell;
class GridService
{
@ -26,6 +27,10 @@ class GridService
void MoveBullet(Bullet* bullet);
void DelBullet(Bullet* bullet);
void AddCar(Car* car);
void MoveCar(Car* car);
void DelCar(Car* car);
void AddRoomEntity(Room* room, Entity* entity);
void DelRoomEntity(Room* room, Entity* entity);

View File

@ -1378,33 +1378,6 @@ void Human::DoGetOn(int obj_uniid)
}
}
void Human::DoGetDown()
{
if (GetCar()) {
GetCar()->GetDown(this);
int loot_uniid = room->CreateLoot(car_->meta->i->id(), GetPos(), 1, 1);
Entity* loot_entity = room->GetEntityByUniId(loot_uniid);
if (loot_entity && loot_entity->IsEntityType(ET_Loot)) {
((Loot*)loot_entity)->bullet_num = 0;
((Loot*)loot_entity)->param1 = 0;
((Loot*)loot_entity)->param2 = 0;
room->UpdateCarObject(car_->car_uniid,
loot_entity->GetEntityUniId(),
loot_entity->GetPos());
}
room->TakeOffCarObject(loot_uniid, GetPos());
if (car_->meta->i->buffid()) {
RemoveBuffById(car_->meta->i->buffid());
RecalcSelfCollider();
}
SyncAroundPlayers(__FILE__, __LINE__, __func__);
room->NotifyUiUpdate();
SetCar(nullptr);
car_weapon = Weapon();
CancelAction();
}
}
void Human::FindLocation()
{
Entity* target = nullptr;
@ -4246,31 +4219,30 @@ void Human::NextReload(int prev_weapon_id, int prev_weapon_idx)
}
}
void Human::DoGetDown()
{
if (GetCar()) {
GetCar()->GetDown(this);
}
}
void Human::DoGetOnWithLoot(Loot* entity)
{
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquip(entity->item_id);
if (!item_meta) {
return;
}
if (car_) {
int loot_uniid = room->CreateLoot(car_->meta->i->id(), GetPos(), 1, 1);
Entity* loot_entity = room->GetEntityByUniId(loot_uniid);
if (loot_entity && loot_entity->IsEntityType(ET_Loot)) {
((Loot*)loot_entity)->bullet_num = 0;
((Loot*)loot_entity)->param1 = 0;
((Loot*)loot_entity)->param2 = 0;
room->UpdateCarObject(car_->car_uniid,
loot_entity->GetEntityUniId(),
loot_entity->GetPos());
}
room->TakeOffCarObject(loot_uniid, GetPos());
if (car_->meta->i->buffid()) {
RemoveBuffById(car_->meta->i->buffid());
}
car_weapon = Weapon();
if (GetCar()) {
GetCar()->GetDown(this);
}
car_ = room->CreateCar(
this,
item_meta,
GetPos()
);
car_->car_uniid = entity->GetEntityUniId();
car_->meta = item_meta;
SetCar(car_);
SetSeat(0);
SetPos(entity->GetPos());
{
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(DRIVER_BUFFID);
@ -4284,11 +4256,6 @@ void Human::DoGetOnWithLoot(Loot* entity)
AddBuff(this, buff_meta, 1);
}
}
#if 0
car_.driver = this;
car_.passengers.clear();
car_.passengers.insert(this);
#endif
CancelAction();
SyncAroundPlayers(__FILE__, __LINE__, __func__);
room->TakeOnCarObject(car_->car_uniid);

View File

@ -11,6 +11,7 @@
#include "obstacle.h"
#include "building.h"
#include "loot.h"
#include "car.h"
#include "app.h"
#include "collider.h"
#include "typeconvert.h"
@ -794,13 +795,15 @@ void Player::ProcPrepareItems(const ::google::protobuf::RepeatedField< ::google:
if (GetCar()) {
abort();
}
SetCar(room->CreateCar
(
this,
car_uniid,
item_meta,
GetPos()
));
Car* car = room->CreateCar
(
this,
item_meta,
GetPos()
);
car->car_uniid = car_uniid;
SetCar(car);
SetSeat(0);
}
}
break;

View File

@ -19,6 +19,7 @@
#include "roomobstacle.h"
#include "building.h"
#include "loot.h"
#include "car.h"
#include "roommgr.h"
#include "app.h"
#include "gamelog.h"
@ -523,7 +524,6 @@ void Room::CreateBullet(Human* hum,
}
Car* Room::CreateCar(Human* driver,
int car_uniid,
MetaData::Equip* meta,
const a8::Vec2& pos)
{
@ -565,6 +565,13 @@ void Room::RemoveObjectLater(RoomEntity* entity)
entity->room->RemoveFromHuamnHash((Human*)entity);
}
break;
case ET_Car:
{
entity->BroadcastDeleteState(entity->room);
entity->room->grid_service->DelCar((Car*)entity);
entity->room->RemoveFromMoveableHash((Car*)entity);
}
break;
default:
{
abort();

View File

@ -108,7 +108,6 @@ public:
float fly_distance,
bool is_tank_skin = false);
Car* CreateCar(Human* driver,
int car_uniid,
MetaData::Equip* meta,
const a8::Vec2& pos);
@ -157,9 +156,9 @@ public:
void OnZombieAppear(Human* hum);
int GetAliveCountByRace(RaceType_e race);
int GetOnlinePlayerNum();
int AllocUniid();
private:
int AllocUniid();
void ShuaAndroid();
void ShowAndroid(Human* target, int num);
void CreateAndroid(int android_num);