完成载具基本逻辑

This commit is contained in:
aozhiwei 2021-03-04 19:28:19 +08:00
parent 356534153c
commit ef24695c17
13 changed files with 172 additions and 37 deletions

View File

@ -1,6 +1,10 @@
#include "precompile.h" #include "precompile.h"
#include "car.h" #include "car.h"
#include "human.h"
#include "room.h"
#include "metamgr.h"
#include "loot.h"
Car::Car() Car::Car()
{ {
@ -26,3 +30,53 @@ void Car::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
{ {
} }
void Car::GetDown(Human* passenger)
{
if (passengers.find(passenger) == passengers.end()) {
return;
}
passengers.erase(passenger);
if (passengers.empty()) {
driver = nullptr;
int loot_uniid = room->CreateLoot(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_uniid,
loot_entity->GetEntityUniId(),
loot_entity->GetPos());
}
room->TakeOffCarObject(loot_uniid, GetPos());
if (meta->i->buffid()) {
passenger->RemoveBuffById(meta->i->buffid());
passenger->RecalcSelfCollider();
}
passenger->SyncAroundPlayers(__FILE__, __LINE__, __func__);
passenger->room->NotifyUiUpdate();
passenger->SetCar(nullptr);
passenger->SetSeat(0);
passenger->car_weapon = Weapon();
passenger->CancelAction();
passenger->RemoveBuffByEffectId(kBET_Driver);
passenger->RemoveBuffByEffectId(kBET_Passenger);
room->frame_event.AddCarChg(passenger);
} else {
if (driver == passenger) {
driver = nullptr;
}
if (meta->i->buffid()) {
passenger->RemoveBuffById(meta->i->buffid());
passenger->RecalcSelfCollider();
}
passenger->SetCar(nullptr);
passenger->SetSeat(0);
passenger->car_weapon = Weapon();
passenger->CancelAction();
passenger->RemoveBuffByEffectId(kBET_Driver);
passenger->RemoveBuffByEffectId(kBET_Passenger);
room->frame_event.AddCarChg(passenger);
}
}

View File

@ -14,7 +14,10 @@ class Room;
class Car : public MoveableEntity class Car : public MoveableEntity
{ {
public: public:
int car_uniid = 0;
MetaData::Equip* meta = nullptr; MetaData::Equip* meta = nullptr;
Human* driver = nullptr;
std::set<Human*> passengers;
Car(); Car();
virtual ~Car() override; virtual ~Car() override;
@ -22,4 +25,5 @@ class Car : public MoveableEntity
virtual void FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data) override; virtual void FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) override; virtual void FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) override;
void GetDown(Human* passenger);
}; };

View File

@ -282,6 +282,7 @@ enum PropertyType_e
kPropBulletNum = 8, kPropBulletNum = 8,
kPropItem = 9, kPropItem = 9,
kPropWeaponAmmo = 10, kPropWeaponAmmo = 10,
kPropCar = 11,
kPropZombieId = 23, kPropZombieId = 23,
}; };

View File

@ -315,6 +315,18 @@ void FrameEvent::AddRevive(Human* sender)
} }
} }
void FrameEvent::AddCarChg(Human* sender)
{
chged_cars_.push_back(sender);
int idx = chged_cars_.size() - 1;
sender->TouchAllLayerHumanList
(
[idx] (Human* hum, bool& stop)
{
hum->chged_cars_.push_back(idx);
});
}
void FrameEvent::Clear() void FrameEvent::Clear()
{ {
if (!explosions_.empty()) { if (!explosions_.empty()) {
@ -359,4 +371,7 @@ void FrameEvent::Clear()
if (!dead_alive_objs_.empty()) { if (!dead_alive_objs_.empty()) {
dead_alive_objs_.clear(); dead_alive_objs_.clear();
} }
if (!chged_cars_.empty()) {
chged_cars_.clear();
}
} }

View File

@ -31,6 +31,7 @@ public:
void AddZombieIdChg(Human* hum); void AddZombieIdChg(Human* hum);
void AddDead(Human* sender, int revive_time); void AddDead(Human* sender, int revive_time);
void AddRevive(Human* sender); void AddRevive(Human* sender);
void AddCarChg(Human* sender);
void Clear(); void Clear();
private: private:
@ -47,6 +48,7 @@ private:
std::vector<Human*> chged_hps_; std::vector<Human*> chged_hps_;
std::vector<Human*> chged_skillcds_; std::vector<Human*> chged_skillcds_;
std::vector<Human*> chged_zombieids_; std::vector<Human*> chged_zombieids_;
std::vector<Human*> chged_cars_;
std::vector<std::tuple<int, int, int>> dead_alive_objs_; std::vector<std::tuple<int, int, int>> dead_alive_objs_;
friend class FrameMaker; friend class FrameMaker;

View File

@ -5,6 +5,7 @@
#include "room.h" #include "room.h"
#include "typeconvert.h" #include "typeconvert.h"
#include "metamgr.h" #include "metamgr.h"
#include "car.h"
cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum) cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum)
{ {
@ -227,6 +228,23 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum)
p->add_values(std::get<2>(room->frame_event.dead_alive_objs_[idx])); p->add_values(std::get<2>(room->frame_event.dead_alive_objs_[idx]));
} }
} }
for (size_t idx : hum->chged_cars_) {
if (idx < room->frame_event.chged_cars_.size()) {
Human* target = room->frame_event.chged_hps_[idx];
if (hum->CanSee(target)) {
auto p = msg->add_chged_property_list();
p->set_obj_id(target->GetEntityUniId());
p->set_property_type(kPropCar);
if (target->GetCar()) {
p->set_property_subtype(target->GetCar()->meta->i->id());
p->set_value(target->GetSeat());
} else {
p->set_property_subtype(0);
p->set_value(0);
}
}
}
}
if (room->GetRoomMode() == kZombieMode && room->BattleStarted()) { if (room->GetRoomMode() == kZombieMode && room->BattleStarted()) {
room->FillObjectPositions((Human*)hum, *msg); room->FillObjectPositions((Human*)hum, *msg);
} }

View File

@ -21,6 +21,7 @@
#include "obstacle.h" #include "obstacle.h"
#include "player.h" #include "player.h"
#include "buff.h" #include "buff.h"
#include "car.h"
#include "roomobstacle.h" #include "roomobstacle.h"
#include "aicomponent.h" #include "aicomponent.h"
#include "jsondatamgr.h" #include "jsondatamgr.h"
@ -68,9 +69,11 @@ void InternalShot(Human* hum,
} }
} }
bullet_dir.Rotate(bullet_angle / 180.0f); bullet_dir.Rotate(bullet_angle / 180.0f);
if (hum->GetCar().car_id != 0) { if (hum->GetCar()) {
#if 0
bullet_born_pos.x += MetaMgr::Instance()->horse_shoot_x; bullet_born_pos.x += MetaMgr::Instance()->horse_shoot_x;
bullet_born_pos.y += MetaMgr::Instance()->horse_shoot_y; bullet_born_pos.y += MetaMgr::Instance()->horse_shoot_y;
#endif
} }
hum->room->frame_event.AddBullet(hum, hum->room->frame_event.AddBullet(hum,
weapon_meta, weapon_meta,
@ -280,6 +283,13 @@ void Human::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data
if (room->GetRoomMode() == kZombieMode) { if (room->GetRoomMode() == kZombieMode) {
p->set_charid(meta->i->id()); p->set_charid(meta->i->id());
} }
if (GetCar()) {
p->set_car_uniid(GetCar()->car_uniid);
p->set_car_seat(GetSeat());
} else {
p->set_car_uniid(0);
p->set_car_seat(0);
}
} }
void Human::FillMFPlayerStats(cs::MFPlayerStats* stats_pb) void Human::FillMFPlayerStats(cs::MFPlayerStats* stats_pb)
@ -1441,25 +1451,26 @@ void Human::DoGetOn(int obj_uniid)
void Human::DoGetDown() void Human::DoGetDown()
{ {
if (car_.car_id != 0) { if (GetCar()) {
int loot_uniid = room->CreateLoot(car_.car_id, GetPos(), 1, 1); GetCar()->GetDown(this);
int loot_uniid = room->CreateLoot(car_->meta->i->id(), GetPos(), 1, 1);
Entity* loot_entity = room->GetEntityByUniId(loot_uniid); Entity* loot_entity = room->GetEntityByUniId(loot_uniid);
if (loot_entity && loot_entity->IsEntityType(ET_Loot)) { if (loot_entity && loot_entity->IsEntityType(ET_Loot)) {
((Loot*)loot_entity)->bullet_num = 0; ((Loot*)loot_entity)->bullet_num = 0;
((Loot*)loot_entity)->param1 = 0; ((Loot*)loot_entity)->param1 = 0;
((Loot*)loot_entity)->param2 = 0; ((Loot*)loot_entity)->param2 = 0;
room->UpdateCarObject(car_.car_uniid, room->UpdateCarObject(car_->car_uniid,
loot_entity->GetEntityUniId(), loot_entity->GetEntityUniId(),
loot_entity->GetPos()); loot_entity->GetPos());
} }
room->TakeOffCarObject(loot_uniid, GetPos()); room->TakeOffCarObject(loot_uniid, GetPos());
if (car_.meta->i->buffid()) { if (car_->meta->i->buffid()) {
RemoveBuffById(car_.meta->i->buffid()); RemoveBuffById(car_->meta->i->buffid());
RecalcSelfCollider(); RecalcSelfCollider();
} }
SyncAroundPlayers(__FILE__, __LINE__, __func__); SyncAroundPlayers(__FILE__, __LINE__, __func__);
room->NotifyUiUpdate(); room->NotifyUiUpdate();
car_ = HumanCar(); SetCar(nullptr);
car_weapon = Weapon(); car_weapon = Weapon();
CancelAction(); CancelAction();
} }
@ -2331,6 +2342,9 @@ void Human::ClearFrameData()
if (!dead_alive_objs_.empty()) { if (!dead_alive_objs_.empty()) {
dead_alive_objs_.clear(); dead_alive_objs_.clear();
} }
if (!chged_cars_.empty()) {
chged_cars_.clear();
}
} }
void Human::GenBattleReportData(a8::MutableXObject* params) void Human::GenBattleReportData(a8::MutableXObject* params)
@ -4309,26 +4323,25 @@ void Human::DoGetOnWithLoot(Loot* entity)
if (!item_meta) { if (!item_meta) {
return; return;
} }
if (car_.car_id != 0) { if (car_) {
int loot_uniid = room->CreateLoot(car_.car_id, GetPos(), 1, 1); int loot_uniid = room->CreateLoot(car_->meta->i->id(), GetPos(), 1, 1);
Entity* loot_entity = room->GetEntityByUniId(loot_uniid); Entity* loot_entity = room->GetEntityByUniId(loot_uniid);
if (loot_entity && loot_entity->IsEntityType(ET_Loot)) { if (loot_entity && loot_entity->IsEntityType(ET_Loot)) {
((Loot*)loot_entity)->bullet_num = 0; ((Loot*)loot_entity)->bullet_num = 0;
((Loot*)loot_entity)->param1 = 0; ((Loot*)loot_entity)->param1 = 0;
((Loot*)loot_entity)->param2 = 0; ((Loot*)loot_entity)->param2 = 0;
room->UpdateCarObject(car_.car_uniid, room->UpdateCarObject(car_->car_uniid,
loot_entity->GetEntityUniId(), loot_entity->GetEntityUniId(),
loot_entity->GetPos()); loot_entity->GetPos());
} }
room->TakeOffCarObject(loot_uniid, GetPos()); room->TakeOffCarObject(loot_uniid, GetPos());
if (car_.meta->i->buffid()) { if (car_->meta->i->buffid()) {
RemoveBuffById(car_.meta->i->buffid()); RemoveBuffById(car_->meta->i->buffid());
} }
car_weapon = Weapon(); car_weapon = Weapon();
} }
car_.car_uniid = entity->GetEntityUniId(); car_->car_uniid = entity->GetEntityUniId();
car_.car_id = item_meta->i->id(); car_->meta = item_meta;
car_.meta = item_meta;
SetPos(entity->GetPos()); SetPos(entity->GetPos());
{ {
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(DRIVER_BUFFID); MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(DRIVER_BUFFID);
@ -4337,17 +4350,19 @@ void Human::DoGetOnWithLoot(Loot* entity)
} }
} }
{ {
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(car_.meta->i->buffid()); MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(car_->meta->i->buffid());
if (buff_meta) { if (buff_meta) {
AddBuff(this, buff_meta, 1); AddBuff(this, buff_meta, 1);
} }
} }
#if 0
car_.driver = this; car_.driver = this;
car_.passengers.clear(); car_.passengers.clear();
car_.passengers.insert(this); car_.passengers.insert(this);
#endif
CancelAction(); CancelAction();
SyncAroundPlayers(__FILE__, __LINE__, __func__); SyncAroundPlayers(__FILE__, __LINE__, __func__);
room->TakeOnCarObject(car_.car_uniid); room->TakeOnCarObject(car_->car_uniid);
room->NotifyUiUpdate(); room->NotifyUiUpdate();
} }
@ -4372,7 +4387,9 @@ void Human::DoGetOnWithTeammate(Human* teammate)
return; return;
} }
#if 0
teammate->GetCar().passengers.insert(this); teammate->GetCar().passengers.insert(this);
#endif
SetPos(teammate->GetPos()); SetPos(teammate->GetPos());
{ {
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(PASSENGER_BUFFID); MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(PASSENGER_BUFFID);

View File

@ -33,6 +33,7 @@ class CircleCollider;
class AabbCollider; class AabbCollider;
class Obstacle; class Obstacle;
class Loot; class Loot;
class Car;
class Buff; class Buff;
class Human : public MoveableEntity class Human : public MoveableEntity
{ {
@ -300,7 +301,10 @@ class Human : public MoveableEntity
void ChangeToRace(RaceType_e race, int level); void ChangeToRace(RaceType_e race, int level);
void ChangeToRaceAndNotify(RaceType_e race, int level); void ChangeToRaceAndNotify(RaceType_e race, int level);
void WinExp(Human* sender, int exp); void WinExp(Human* sender, int exp);
HumanCar& GetCar() { return car_; } Car* GetCar() { return car_; }
void SetCar(Car* car) { car_ = car; }
int GetSeat() { return seat_; }
void SetSeat(int seat) { seat_ = seat; }
void DeadDrop(); void DeadDrop();
bool IsEnemy(Human* hum); bool IsEnemy(Human* hum);
@ -391,9 +395,11 @@ protected:
std::vector<int> chged_race_; std::vector<int> chged_race_;
std::vector<int> chged_zombieid_; std::vector<int> chged_zombieid_;
std::vector<int> dead_alive_objs_; std::vector<int> dead_alive_objs_;
std::vector<int> chged_cars_;
Human* follow_target_ = nullptr; Human* follow_target_ = nullptr;
bool follow_synced_active_player = false; bool follow_synced_active_player = false;
HumanCar car_; Car* car_ = nullptr;
int seat_ = 0;
MetaData::Skill* skill_meta_ = nullptr; MetaData::Skill* skill_meta_ = nullptr;
std::map<MetaData::Skill*, xtimer_list*> passive_skill_metas_; std::map<MetaData::Skill*, xtimer_list*> passive_skill_metas_;

View File

@ -791,13 +791,16 @@ void Player::ProcPrepareItems(const ::google::protobuf::RepeatedField< ::google:
{ {
int car_uniid = room->CreateAndTakeonCar(item_meta->i->id(), GetPos()); int car_uniid = room->CreateAndTakeonCar(item_meta->i->id(), GetPos());
if (car_uniid != -1) { if (car_uniid != -1) {
car_.car_uniid = car_uniid; if (GetCar()) {
car_.car_id = item_meta->i->id(); abort();
car_.meta = item_meta;
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(car_.meta->i->buffid());
if (buff_meta) {
AddBuff(this, buff_meta, 1);
} }
SetCar(room->CreateCar
(
this,
car_uniid,
item_meta,
GetPos()
));
} }
} }
break; break;

View File

@ -522,6 +522,24 @@ void Room::CreateBullet(Human* hum,
} }
} }
Car* Room::CreateCar(Human* driver,
int car_uniid,
MetaData::Equip* meta,
const a8::Vec2& pos)
{
Car* car = nullptr;
#if 0
car_.car_uniid = car_uniid;
car_.car_id = item_meta->i->id();
car_.meta = item_meta;
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(car_.meta->i->buffid());
if (buff_meta) {
AddBuff(this, buff_meta, 1);
}
#endif
return car;
}
void Room::RemoveObjectLater(RoomEntity* entity) void Room::RemoveObjectLater(RoomEntity* entity)
{ {
auto remove_func = auto remove_func =

View File

@ -33,6 +33,7 @@ class Player;
class Building; class Building;
class AabbCollider; class AabbCollider;
class Android; class Android;
class Car;
class Room class Room
{ {
public: public:
@ -106,6 +107,10 @@ public:
a8::Vec2 dir, a8::Vec2 dir,
float fly_distance, float fly_distance,
bool is_tank_skin = false); bool is_tank_skin = false);
Car* CreateCar(Human* driver,
int car_uniid,
MetaData::Equip* meta,
const a8::Vec2& pos);
void OnHumanDie(Human* hum); void OnHumanDie(Human* hum);
void OnHumanRevive(Human* hum); void OnHumanRevive(Human* hum);

View File

@ -99,16 +99,6 @@ struct CarObject
bool taken = false; bool taken = false;
}; };
struct HumanCar
{
int car_id = 0;
int car_uniid = 0;
class Human* driver = nullptr;
std::set<class Human*> passengers;
MetaData::Equip* meta = nullptr;
};
struct BornPoint struct BornPoint
{ {
MetaData::MapTplThing* thing_tpl = nullptr; MetaData::MapTplThing* thing_tpl = nullptr;

View File

@ -118,8 +118,9 @@ message MFVec2
property_type: 10 property_type: 10
property_subtype: property_subtype:
valule: valule:
property_type: 11 id property_type: 11
valule: car_uniid property_subtype: car_uniid
valule: seat
property_type: 23 charid property_type: 23 charid
valule: charid valule: charid
*/ */
@ -216,6 +217,7 @@ message MFPlayerFull
optional int32 parachute = 27; // optional int32 parachute = 27; //
repeated MFBuff buff_list = 28; //buff列表 repeated MFBuff buff_list = 28; //buff列表
optional int32 car_uniid = 29; //id optional int32 car_uniid = 29; //id
optional int32 car_seat = 34; //-0-3
optional bool can_revive = 30; // optional bool can_revive = 30; //
optional int32 revive_countdown = 31; // optional int32 revive_countdown = 31; //