From 3eaeea96867c0e172375986acabe9f91548b3906 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 28 Apr 2019 16:50:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8B=B1=E9=9B=84=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/human.cc | 21 ++++++++++++++++++++- server/gameserver/room.cc | 32 ++++++++++++++++++++++++++++++++ server/gameserver/room.h | 2 ++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 50c727f..9ce4639 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -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); + } + } + ); + } } diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 2534e4a..cdfd214 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -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); diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 449c67f..138b9f4 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -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);