添加英雄处理

This commit is contained in:
aozhiwei 2019-04-28 16:50:40 +08:00
parent ccd8fa6493
commit 3eaeea9686
3 changed files with 54 additions and 1 deletions

View File

@ -1117,5 +1117,24 @@ void Human::FillBodyState(::google::protobuf::RepeatedPtrField<::cs::MFBodyState
void Human::SummonHero()
{
Hero* hero = room->CreateHero(this);
if (hero) {
room->xtimer.AddDeadLineTimerAndAttach(skill_meta->i->last_time() * SERVER_FRAME_RATE,
a8::XParams()
.SetSender(this)
.SetParam1(hero->entity_uniid),
[] (const a8::XParams& param)
{
},
&skill_xtimer_attacher_.timer_list_,
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
Entity* hero = hum->room->GetEntityByUniId(param.param1);
if (hero && hero->entity_type == ET_Hero) {
hum->room->RemoveObjectLater(hero);
}
}
);
}
}

View File

@ -20,6 +20,7 @@
#include "collision.h"
#include "roommgr.h"
#include "app.h"
#include "hero.h"
const int ROOM_MAX_PLAYER_NUM = 50;
#if 0
@ -421,6 +422,36 @@ Obstacle* Room::CreateObstacle(int id, float x, float y)
return entity;
}
Hero* Room::CreateHero(Human* hum)
{
Vector2D pos = hum->pos;
{
Vector2D dir = Vector2D::UP;
dir.Rotate(a8::RandAngle());
pos = pos + dir * (25 + rand() % 50);
}
Hero* hero = new Hero();
hero->room = this;
hero->entity_uniid = AllocUniid();
hero->pos = pos;
hero->move_dir = hum->move_dir;
hero->attack_dir = hum->attack_dir;
hero->master = hum;
hero->skin = hum->skin;
hero->backpack = hum->backpack;
hero->helmet = hum->helmet;
hero->chest = hum->chest;
hero->weapon = *hum->curr_weapon;
hero->Initialize();
#if 1
uniid_hash_[hero->entity_uniid] = hero;
grid_service.AddEntity(hero);
#endif
hero->BroadcastFullState();
return hero;
}
void Room::CreateLoot(int equip_id, Vector2D pos, int count)
{
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(equip_id);
@ -471,6 +502,7 @@ void Room::RemoveObjectLater(Entity* entity)
}
break;
case ET_Loot:
case ET_Hero:
{
entity->BroadcastDeleteState();
entity->room->grid_service.DelEntity(entity);

View File

@ -27,6 +27,7 @@ class Bullet;
class Human;
class Player;
class Building;
class Hero;
class Room
{
public:
@ -74,6 +75,7 @@ public:
void ScatterDrop(Vector2D center, int drop_id);
void DropItem(Vector2D pos, int item_id, int item_count);
Hero* CreateHero(Human* hum);
void CreateLoot(int equip_id, Vector2D pos, int count);
void CreateBullet(Human* hum, MetaData::Equip* gun_meta,
Vector2D pos, Vector2D dir, float fly_distance);