This commit is contained in:
aozhiwei 2021-03-19 17:35:49 +08:00
parent 85024f9892
commit 9493d04527
10 changed files with 121 additions and 63 deletions

View File

@ -66,21 +66,21 @@ void Bullet::OnHit(std::set<Entity*>& objects)
hum->HasBuffEffect(kBET_AdPlaying)) {
continue;
}
if (player->room->GetRoomMode() == kZombieMode &&
player->GetRace() == hum->GetRace()) {
if (sender->room->GetRoomMode() == kZombieMode &&
sender->GetRace() == hum->GetRace()) {
continue;
}
if (!hum->dead && (IsBomb() || player->team_id != hum->team_id)) {
float dmg = GetAtk() * (1 + player->GetAttrRate(kHAT_Atk)) +
player->GetAttrAbs(kHAT_Atk);
if (!hum->dead && (IsBomb() || sender->team_id != hum->team_id)) {
float dmg = GetAtk() * (1 + sender->GetAttrRate(kHAT_Atk)) +
sender->GetAttrAbs(kHAT_Atk);
float def = hum->ability.def * (1 + hum->GetAttrRate(kHAT_Def)) +
hum->GetAttrAbs(kHAT_Def);
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
finaly_dmg = std::max(finaly_dmg, 0.0f);
player->stats.damage_amount_out += finaly_dmg;
hum->DecHP(finaly_dmg, player->GetEntityUniId(), player->name, gun_meta->i->id());
sender->stats.damage_amount_out += finaly_dmg;
hum->DecHP(finaly_dmg, sender->GetEntityUniId(), sender->name, gun_meta->i->id());
#ifdef DEBUG
player->SendDebugMsg(a8::Format("bullet weapon_id:%d atk:%f",
sender->SendDebugMsg(a8::Format("bullet weapon_id:%d atk:%f",
{
gun_meta->i->id(),
GetAtk()
@ -96,8 +96,8 @@ void Bullet::OnHit(std::set<Entity*>& objects)
if (!obstacle->IsDead(room) &&
obstacle->Attackable() &&
!obstacle->IsTerminatorAirDropBox(room)) {
float dmg = GetAtk() * (1 + player->GetAttrRate(kHAT_Atk)) +
player->GetAttrAbs(kHAT_Atk);
float dmg = GetAtk() * (1 + sender->GetAttrRate(kHAT_Atk)) +
sender->GetAttrAbs(kHAT_Atk);
float def = 0;
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
obstacle->SetHealth(room, std::max(0.0f, obstacle->GetHealth(room) - finaly_dmg));
@ -109,11 +109,11 @@ void Bullet::OnHit(std::set<Entity*>& objects)
obstacle->meta->i->damage() > 0.01f) {
obstacle->Explosion(this);
}
player->DropItems(obstacle);
sender->DropItems(obstacle);
}
obstacle->BroadcastFullState(room);
#ifdef DEBUG
player->SendDebugMsg(a8::Format("bullet weapon_id:%d atk:%f",
sender->SendDebugMsg(a8::Format("bullet weapon_id:%d atk:%f",
{
gun_meta->i->id(),
GetAtk()
@ -137,11 +137,11 @@ void Bullet::ProcBomb()
(
[this, &objects] (Human* hum, bool& stop)
{
if (!is_tank_skin || player->team_id != hum->team_id) {
if (!is_tank_skin || sender->team_id != hum->team_id) {
//友军火箭筒伤害取消
if ((meta->i->_inventory_slot() == 4 ||
meta->i->_inventory_slot() == 5) &&
player->team_id == hum->team_id) {
sender->team_id == hum->team_id) {
return;
}
if (TestCollision(room, hum)) {
@ -174,7 +174,7 @@ void Bullet::ProcBomb()
{
//榴弹炮
a8::Vec2 bomb_pos = GetPos();
room->frame_event.AddExplosionEx(player, meta->i->id(), bomb_pos,
room->frame_event.AddExplosionEx(sender, meta->i->id(), bomb_pos,
gun_meta->i->explosion_effect());
OnHit(objects);
}
@ -271,8 +271,8 @@ float Bullet::GetAtk()
{
float atk = gun_meta->i->atk() +
(gun_upgrade_meta ? gun_upgrade_meta->GetAttrValue(gun_lv, kHAT_Atk) : 0);
if (player->IsAndroid()) {
Android* android = (Android*)player;
if (sender->IsAndroid()) {
Android* android = (Android*)sender;
atk *= android->ai->GetAttackRate();
}
return atk;
@ -285,7 +285,7 @@ void Bullet::Check(float distance)
(
[this, &objects] (Human* hum, bool& stop)
{
if (hum != player && !hum->dead && TestCollision(room, hum)) {
if (hum != sender && !hum->dead && TestCollision(room, hum)) {
objects.insert(hum);
}
});

View File

@ -20,7 +20,7 @@ class Bullet : public MoveableEntity
MetaData::Equip* gun_meta = nullptr;
MetaData::EquipUpgrade* gun_upgrade_meta = nullptr;
MetaData::Equip* meta = nullptr;
Human* player = nullptr;
Human* sender = nullptr;
a8::Vec2 dir;
a8::Vec2 born_pos;
a8::Vec2 born_dir;

View File

@ -6,6 +6,66 @@
#include "skill.h"
#include "human.h"
void InternalShot(Creature* c,
MetaData::Equip* weapon_meta,
MetaData::EquipUpgrade* weapon_upgrade_meta,
MetaData::Equip* bullet_meta,
int weapon_lv,
int skill_id,
float fly_distance,
bool is_tank_skin)
{
for (auto& tuple : weapon_meta->bullet_born_offset) {
a8::Vec2 bullet_born_offset = a8::Vec2(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(c->attack_dir.CalcAngle(a8::Vec2::UP));
a8::Vec2 bullet_born_pos = c->GetPos() + bullet_born_offset;
if (c->room->OverBorder(bullet_born_pos, 0)) {
return;
}
}
c->room->frame_event.AddShot(c);
for (auto& tuple : weapon_meta->bullet_born_offset) {
a8::Vec2 bullet_born_offset = a8::Vec2(std::get<0>(tuple), std::get<1>(tuple));
bullet_born_offset.Rotate(c->attack_dir.CalcAngle(a8::Vec2::UP));
a8::Vec2 bullet_born_pos = c->GetPos() + bullet_born_offset;
a8::Vec2 bullet_dir = c->attack_dir;
float bullet_angle = std::get<2>(tuple);
if (weapon_meta->i->bullet_angle() >= 0.10f) {
int angle = (int)weapon_meta->i->bullet_angle() * 1000;
if (angle > 0) {
bullet_angle += (rand() % angle) / 1000.0f * (rand() % 2 == 0 ? 1 : -1);
}
}
bullet_dir.Rotate(bullet_angle / 180.0f);
#if 0
if (hum->GetCar()) {
bullet_born_pos.x += MetaMgr::Instance()->horse_shoot_x;
bullet_born_pos.y += MetaMgr::Instance()->horse_shoot_y;
}
#endif
c->room->frame_event.AddBullet(c,
weapon_meta,
weapon_lv,
bullet_born_pos,
bullet_dir,
fly_distance);
if (c->room->BattleStarted() ||
(c->room->GetGasData().gas_mode == GasJump &&
!c->HasBuffEffect(kBET_Jump))) {
#if 0
c->room->CreateBullet(hum,
weapon_meta,
weapon_upgrade_meta,
bullet_meta,
bullet_born_pos,
bullet_dir,
fly_distance,
is_tank_skin);
#endif
}
}
}
Creature::~Creature()
{
for (auto& pair : skill_hash_) {
@ -87,17 +147,17 @@ void Creature::AddBuff(Creature* caster,
c->RemoveBuffById(param.param1);
},
&buff->xtimer_attacher.timer_list_
);
);
}
ProcBuffEffect(caster, buff);
AddBuffPostProc(caster, buff);
#ifdef DEBUG
#ifdef DEBUG
SendDebugMsg(a8::Format("添加buff_id:%d buff_effect:%d",
{
buff_meta->i->buff_id(),
buff_meta->i->buff_effect()
}));
#endif
buff_meta->i->buff_effect()
}));
#endif
}
bool Creature::IsImmuneBuffEffect(int buff_effect)
@ -133,12 +193,12 @@ void Creature::RemoveBuffById(int buff_id)
}
}
RecalcBuffAttr();
#ifdef DEBUG
#ifdef DEBUG
SendDebugMsg(a8::Format("移除buff_id:%d",
{
buff_id
}));
#endif
}));
#endif
}
void Creature::SendDebugMsg(const std::string& debug_msg)
@ -444,7 +504,7 @@ void Creature::ProcSkillPhase(MetaData::SkillPhase* phase)
a8::Vec2 old_attack_dir = attack_dir;
attack_dir = entity->GetPos() - GetPos();
attack_dir.Normalize();
#if 0
#if 0
InternalShot
(
this,
@ -456,7 +516,7 @@ void Creature::ProcSkillPhase(MetaData::SkillPhase* phase)
target_distance,
false);
attack_dir = old_attack_dir;
#endif
#endif
}
}
}
@ -498,7 +558,7 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
equip_meta->i->equip_type() == EQUIP_TYPE_CAR &&
equip_meta->i->equip_subtype() == 1
) {
#if 0
#if 0
MetaData::Equip* car_weapon_meta = MetaMgr::Instance()->GetEquip(equip_meta->int_param1);
if (car_weapon_meta) {
car_weapon.weapon_idx = 100;
@ -508,7 +568,7 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
car_weapon.Recalc();
car_weapon.ammo = car_weapon.GetClipVolume();
}
#endif
#endif
}
}
}
@ -589,7 +649,7 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
break;
case kBET_Terminator:
{
#if 0
#if 0
if (GetRace() == kHumanRace &&
MetaMgr::Instance()->terminator_meta &&
meta != MetaMgr::Instance()->terminator_meta) {
@ -597,7 +657,7 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
room->NotifySysPiao(TEXT("battle_server_terminator_appear", "终结者出现"), a8::MkRgb(255, 0, 0), 3);
OnChgToTerminator();
}
#endif
#endif
}
break;
case kBET_PlayShotAni:
@ -612,18 +672,18 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
break;
case kBET_DecHp:
{
#if 0
#if 0
float def = hum->ability.def * (1 + hum->GetBuffAttrRate(kHAT_Def)) +
hum->GetBuffAttrAbs(kHAT_Def);
#endif
#if 0
#endif
#if 0
if (caster->GetEntityType() == ET_Player) {
DecHP(buff->meta->param1,
caster->GetEntityUniId(),
((Human*)caster)->name,
0);
}
#endif
#endif
}
break;
case kBET_DelayAddBuff:
@ -691,3 +751,8 @@ void Creature::ClearSkill()
skill_hash_[reserve_skill->meta->i->skill_id()] = reserve_skill;
}
}
bool Creature::CanSee(const Creature* c) const
{
return room->grid_service->InView(GetGridId(), c->GetGridId());
}

View File

@ -26,6 +26,9 @@ class Creature : public MoveableEntity
a8::Vec2 target_pos;
std::function<bool ()> on_move_collision;
Weapon* curr_weapon = nullptr;
Weapon car_weapon;
virtual ~Creature() override;
virtual void Initialize() override;
bool HasBuffEffect(int buff_effect_id);
@ -59,6 +62,7 @@ class Creature : public MoveableEntity
void ResetSkill();
Skill* CurrentSkill();
MetaData::SkillPhase* GetCurrSkillPhase();
bool CanSee(const Creature* c) const;
virtual void CancelAction() {};
virtual void ResetAction() {};

View File

@ -38,7 +38,7 @@ void FrameEvent::AddEmote(Human* sender, int emote_id)
}
}
void FrameEvent::AddShot(Human* sender)
void FrameEvent::AddShot(Creature* sender)
{
{
auto& tuple = a8::FastAppend(shots_);
@ -51,10 +51,6 @@ void FrameEvent::AddShot(Human* sender)
} else {
sender->curr_weapon->ToPB(p.mutable_weapon());
}
#if 0
p.set_offhand(true);
p.set_bullskin(10001);
#endif
}
{
int shot_idx = shots_.size() - 1;
@ -67,7 +63,7 @@ void FrameEvent::AddShot(Human* sender)
}
}
void FrameEvent::AddBullet(Human* sender,
void FrameEvent::AddBullet(Creature* sender,
MetaData::Equip* weapon_meta,
int weapon_lv,
a8::Vec2 born_pos,
@ -105,16 +101,16 @@ void FrameEvent::AddExplosion(Bullet* bullet, int item_id, a8::Vec2 bomb_pos)
{
{
auto& tuple = a8::FastAppend(explosions_);
std::get<0>(tuple) = bullet->player;
std::get<0>(tuple) = bullet->sender;
auto& p = std::get<1>(tuple);
p.set_item_id(item_id);
TypeConvert::ToPb(bomb_pos, p.mutable_pos());
p.set_player_id(bullet->player->GetEntityUniId());
p.set_player_id(bullet->sender->GetEntityUniId());
}
{
int explosion_idx = explosions_.size() - 1;
bullet->player->TouchAllLayerHumanList
bullet->sender->TouchAllLayerHumanList
(
[explosion_idx] (Human* hum, bool& stop)
{
@ -157,16 +153,16 @@ void FrameEvent::AddSmoke(Bullet* bullet, int item_id, a8::Vec2 pos)
{
{
auto& tuple = a8::FastAppend(smokes_);
std::get<0>(tuple) = bullet->player;
std::get<0>(tuple) = bullet->sender;
auto& p = std::get<1>(tuple);
p.set_item_id(item_id);
TypeConvert::ToPb(pos, p.mutable_pos());
p.set_player_id(bullet->player->GetEntityUniId());
p.set_player_id(bullet->sender->GetEntityUniId());
}
{
int idx = smokes_.size() - 1;
bullet->player->TouchAllLayerHumanList
bullet->sender->TouchAllLayerHumanList
(
[idx] (Human* hum, bool& stop)
{

View File

@ -6,13 +6,14 @@ class Bullet;
class Human;
class Buff;
class Room;
class Creature;
struct FrameEvent
{
public:
void AddAirDrop(int appear_time, int box_id, a8::Vec2 box_pos);
void AddEmote(Human* hum, int emote_id);
void AddShot(Human* hum);
void AddBullet(Human* hum,
void AddShot(Creature* sender);
void AddBullet(Creature* sender,
MetaData::Equip* weapon_meta,
int weapon_lv,
a8::Vec2 born_pos,
@ -36,8 +37,8 @@ public:
void Clear();
private:
::google::protobuf::RepeatedPtrField<::cs::MFAirDrop> airdrops_;
std::vector<std::tuple<Human*, ::cs::MFShot>> shots_;
std::vector<std::tuple<Human*, ::cs::MFBullet>> bullets_;
std::vector<std::tuple<Creature*, ::cs::MFShot>> shots_;
std::vector<std::tuple<Creature*, ::cs::MFBullet>> bullets_;
std::vector<std::tuple<Human*, ::cs::MFExplosion>> explosions_;
std::vector<std::tuple<Human*, ::cs::MFSmoke>> smokes_;
std::vector<std::tuple<Human*, ::cs::MFEmote>> emotes_;

View File

@ -1584,11 +1584,6 @@ void Human::FillMFGasData(cs::MFGasData* gas_data)
gas_data->set_rad_new(room->GetGasData().rad_new);
}
bool Human::CanSee(const Human* hum) const
{
return room->grid_service->InView(GetGridId(), hum->GetGridId());
}
void Human::RecalcVolume()
{
MetaData::Equip* backpack_meta = MetaMgr::Instance()->GetEquip(backpack);

View File

@ -98,9 +98,7 @@ class Human : public Creature
long long real_dead_frameno = 0;
Weapon default_weapon;
Weapon car_weapon;
std::vector<Weapon> weapons;
Weapon* curr_weapon = nullptr;
int curr_scope_idx = 0;
@ -200,7 +198,6 @@ class Human : public Creature
virtual void SyncAroundPlayers(const char* file, int line, const char* func) override;
void FillMFActivePlayerData(cs::MFActivePlayerData* player_data);
void FillMFGasData(cs::MFGasData* gas_data);
bool CanSee(const Human* hum) const;
void RecalcVolume();
void RecalcBaseAttr();
int GetInventory(int slot_id);

View File

@ -314,7 +314,7 @@ void Obstacle::Explosion(Bullet* bullet)
obstacle->Die(room);
}
if (obstacle->IsDead(room)) {
bullet->player->DropItems(obstacle);
bullet->sender->DropItems(obstacle);
}
obstacle->BroadcastFullState(room);
}

View File

@ -531,7 +531,7 @@ void Room::CreateBullet(Human* hum,
{
if (grid_service->CanAdd(pos.x, pos.y)) {
Bullet* bullet = EntityFactory::Instance()->MakeBullet(AllocUniid());
bullet->player = hum;
bullet->sender = hum;
bullet->room = this;
bullet->gun_meta = weapon_meta;
bullet->gun_upgrade_meta = weapon_upgrade_meta;