完成载具基本逻辑
This commit is contained in:
parent
356534153c
commit
ef24695c17
@ -1,6 +1,10 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "car.h"
|
||||
#include "human.h"
|
||||
#include "room.h"
|
||||
#include "metamgr.h"
|
||||
#include "loot.h"
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,10 @@ class Room;
|
||||
class Car : public MoveableEntity
|
||||
{
|
||||
public:
|
||||
int car_uniid = 0;
|
||||
MetaData::Equip* meta = nullptr;
|
||||
Human* driver = nullptr;
|
||||
std::set<Human*> passengers;
|
||||
|
||||
Car();
|
||||
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 FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) override;
|
||||
|
||||
void GetDown(Human* passenger);
|
||||
};
|
||||
|
@ -282,6 +282,7 @@ enum PropertyType_e
|
||||
kPropBulletNum = 8,
|
||||
kPropItem = 9,
|
||||
kPropWeaponAmmo = 10,
|
||||
kPropCar = 11,
|
||||
|
||||
kPropZombieId = 23,
|
||||
};
|
||||
|
@ -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()
|
||||
{
|
||||
if (!explosions_.empty()) {
|
||||
@ -359,4 +371,7 @@ void FrameEvent::Clear()
|
||||
if (!dead_alive_objs_.empty()) {
|
||||
dead_alive_objs_.clear();
|
||||
}
|
||||
if (!chged_cars_.empty()) {
|
||||
chged_cars_.clear();
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
void AddZombieIdChg(Human* hum);
|
||||
void AddDead(Human* sender, int revive_time);
|
||||
void AddRevive(Human* sender);
|
||||
void AddCarChg(Human* sender);
|
||||
|
||||
void Clear();
|
||||
private:
|
||||
@ -47,6 +48,7 @@ private:
|
||||
std::vector<Human*> chged_hps_;
|
||||
std::vector<Human*> chged_skillcds_;
|
||||
std::vector<Human*> chged_zombieids_;
|
||||
std::vector<Human*> chged_cars_;
|
||||
std::vector<std::tuple<int, int, int>> dead_alive_objs_;
|
||||
|
||||
friend class FrameMaker;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "room.h"
|
||||
#include "typeconvert.h"
|
||||
#include "metamgr.h"
|
||||
#include "car.h"
|
||||
|
||||
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]));
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
room->FillObjectPositions((Human*)hum, *msg);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "obstacle.h"
|
||||
#include "player.h"
|
||||
#include "buff.h"
|
||||
#include "car.h"
|
||||
#include "roomobstacle.h"
|
||||
#include "aicomponent.h"
|
||||
#include "jsondatamgr.h"
|
||||
@ -68,9 +69,11 @@ void InternalShot(Human* hum,
|
||||
}
|
||||
}
|
||||
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.y += MetaMgr::Instance()->horse_shoot_y;
|
||||
#endif
|
||||
}
|
||||
hum->room->frame_event.AddBullet(hum,
|
||||
weapon_meta,
|
||||
@ -280,6 +283,13 @@ void Human::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data
|
||||
if (room->GetRoomMode() == kZombieMode) {
|
||||
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)
|
||||
@ -1441,25 +1451,26 @@ void Human::DoGetOn(int obj_uniid)
|
||||
|
||||
void Human::DoGetDown()
|
||||
{
|
||||
if (car_.car_id != 0) {
|
||||
int loot_uniid = room->CreateLoot(car_.car_id, GetPos(), 1, 1);
|
||||
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,
|
||||
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());
|
||||
if (car_->meta->i->buffid()) {
|
||||
RemoveBuffById(car_->meta->i->buffid());
|
||||
RecalcSelfCollider();
|
||||
}
|
||||
SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
||||
room->NotifyUiUpdate();
|
||||
car_ = HumanCar();
|
||||
SetCar(nullptr);
|
||||
car_weapon = Weapon();
|
||||
CancelAction();
|
||||
}
|
||||
@ -2331,6 +2342,9 @@ void Human::ClearFrameData()
|
||||
if (!dead_alive_objs_.empty()) {
|
||||
dead_alive_objs_.clear();
|
||||
}
|
||||
if (!chged_cars_.empty()) {
|
||||
chged_cars_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void Human::GenBattleReportData(a8::MutableXObject* params)
|
||||
@ -4309,26 +4323,25 @@ void Human::DoGetOnWithLoot(Loot* entity)
|
||||
if (!item_meta) {
|
||||
return;
|
||||
}
|
||||
if (car_.car_id != 0) {
|
||||
int loot_uniid = room->CreateLoot(car_.car_id, GetPos(), 1, 1);
|
||||
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,
|
||||
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());
|
||||
if (car_->meta->i->buffid()) {
|
||||
RemoveBuffById(car_->meta->i->buffid());
|
||||
}
|
||||
car_weapon = Weapon();
|
||||
}
|
||||
car_.car_uniid = entity->GetEntityUniId();
|
||||
car_.car_id = item_meta->i->id();
|
||||
car_.meta = item_meta;
|
||||
car_->car_uniid = entity->GetEntityUniId();
|
||||
car_->meta = item_meta;
|
||||
SetPos(entity->GetPos());
|
||||
{
|
||||
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) {
|
||||
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);
|
||||
room->TakeOnCarObject(car_->car_uniid);
|
||||
room->NotifyUiUpdate();
|
||||
}
|
||||
|
||||
@ -4372,7 +4387,9 @@ void Human::DoGetOnWithTeammate(Human* teammate)
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
teammate->GetCar().passengers.insert(this);
|
||||
#endif
|
||||
SetPos(teammate->GetPos());
|
||||
{
|
||||
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(PASSENGER_BUFFID);
|
||||
|
@ -33,6 +33,7 @@ class CircleCollider;
|
||||
class AabbCollider;
|
||||
class Obstacle;
|
||||
class Loot;
|
||||
class Car;
|
||||
class Buff;
|
||||
class Human : public MoveableEntity
|
||||
{
|
||||
@ -300,7 +301,10 @@ class Human : public MoveableEntity
|
||||
void ChangeToRace(RaceType_e race, int level);
|
||||
void ChangeToRaceAndNotify(RaceType_e race, int level);
|
||||
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();
|
||||
bool IsEnemy(Human* hum);
|
||||
|
||||
@ -391,9 +395,11 @@ protected:
|
||||
std::vector<int> chged_race_;
|
||||
std::vector<int> chged_zombieid_;
|
||||
std::vector<int> dead_alive_objs_;
|
||||
std::vector<int> chged_cars_;
|
||||
Human* follow_target_ = nullptr;
|
||||
bool follow_synced_active_player = false;
|
||||
HumanCar car_;
|
||||
Car* car_ = nullptr;
|
||||
int seat_ = 0;
|
||||
|
||||
MetaData::Skill* skill_meta_ = nullptr;
|
||||
std::map<MetaData::Skill*, xtimer_list*> passive_skill_metas_;
|
||||
|
@ -791,13 +791,16 @@ void Player::ProcPrepareItems(const ::google::protobuf::RepeatedField< ::google:
|
||||
{
|
||||
int car_uniid = room->CreateAndTakeonCar(item_meta->i->id(), GetPos());
|
||||
if (car_uniid != -1) {
|
||||
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);
|
||||
if (GetCar()) {
|
||||
abort();
|
||||
}
|
||||
SetCar(room->CreateCar
|
||||
(
|
||||
this,
|
||||
car_uniid,
|
||||
item_meta,
|
||||
GetPos()
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -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)
|
||||
{
|
||||
auto remove_func =
|
||||
|
@ -33,6 +33,7 @@ class Player;
|
||||
class Building;
|
||||
class AabbCollider;
|
||||
class Android;
|
||||
class Car;
|
||||
class Room
|
||||
{
|
||||
public:
|
||||
@ -106,6 +107,10 @@ public:
|
||||
a8::Vec2 dir,
|
||||
float fly_distance,
|
||||
bool is_tank_skin = false);
|
||||
Car* CreateCar(Human* driver,
|
||||
int car_uniid,
|
||||
MetaData::Equip* meta,
|
||||
const a8::Vec2& pos);
|
||||
|
||||
void OnHumanDie(Human* hum);
|
||||
void OnHumanRevive(Human* hum);
|
||||
|
@ -99,16 +99,6 @@ struct CarObject
|
||||
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
|
||||
{
|
||||
MetaData::MapTplThing* thing_tpl = nullptr;
|
||||
|
@ -118,8 +118,9 @@ message MFVec2
|
||||
property_type: 10 更新武器子弹数
|
||||
property_subtype: 武器索引
|
||||
valule: 当前数量
|
||||
property_type: 11 载具唯一id
|
||||
valule: car_uniid
|
||||
property_type: 11 载具
|
||||
property_subtype: car_uniid
|
||||
valule: seat
|
||||
property_type: 23 charid
|
||||
valule: charid
|
||||
*/
|
||||
@ -216,6 +217,7 @@ message MFPlayerFull
|
||||
optional int32 parachute = 27; //降落伞
|
||||
repeated MFBuff buff_list = 28; //buff列表
|
||||
optional int32 car_uniid = 29; //载具id
|
||||
optional int32 car_seat = 34; //载具-座位0-3
|
||||
|
||||
optional bool can_revive = 30; //是否可复活
|
||||
optional int32 revive_countdown = 31; //复活倒计时
|
||||
|
Loading…
x
Reference in New Issue
Block a user