1
This commit is contained in:
parent
6546bd65c6
commit
5964026268
@ -15,11 +15,11 @@ namespace cs
|
||||
class MFBuff;
|
||||
}
|
||||
|
||||
class Human;
|
||||
class Creature;
|
||||
class Buff
|
||||
{
|
||||
public:
|
||||
Human* owner = nullptr;
|
||||
Creature* owner = nullptr;
|
||||
MetaData::Buff* meta = nullptr;
|
||||
MetaData::Skill* skill_meta = nullptr;
|
||||
a8::XTimerAttacher xtimer_attacher;
|
||||
|
116
server/gameserver/creature.cc
Normal file
116
server/gameserver/creature.cc
Normal file
@ -0,0 +1,116 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "creature.h"
|
||||
#include "metamgr.h"
|
||||
#include "room.h"
|
||||
|
||||
bool Creature::HasBuffEffect(int buff_effect_id)
|
||||
{
|
||||
return GetBuffByEffectId(buff_effect_id) != nullptr;
|
||||
}
|
||||
|
||||
Buff* Creature::GetBuffByEffectId(int effect_id)
|
||||
{
|
||||
return IsValidBuffEffect(effect_id) ? buff_effect_[effect_id] : nullptr;
|
||||
}
|
||||
|
||||
Buff* Creature::GetBuffById(int buff_id)
|
||||
{
|
||||
for (Buff& buff : buff_list_) {
|
||||
if (buff.meta->i->buff_id() == buff_id) {
|
||||
return &buff;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Creature::AddBuff(Creature* caster,
|
||||
MetaData::Buff* buff_meta,
|
||||
int skill_lv,
|
||||
MetaData::Skill* buff_skill_meta)
|
||||
{
|
||||
if (GetBuffById(buff_meta->i->buff_id())) {
|
||||
return;
|
||||
}
|
||||
if (IsImmuneBuffEffect(buff_meta->i->buff_effect())) {
|
||||
return;
|
||||
}
|
||||
if (!buff_meta->EffectCanStack()) {
|
||||
Buff* buff = GetBuffByEffectId(buff_meta->i->buff_effect());
|
||||
if (buff) {
|
||||
RemoveBuffById(buff->meta->i->buff_id());
|
||||
}
|
||||
}
|
||||
if (buff_meta->i->buff_effect() == kBET_OnceChgAttr) {
|
||||
if ((int)buff_meta->param1== kHAT_Hp) {
|
||||
if ((int)buff_meta->param2 == 1) {
|
||||
//绝对值
|
||||
ability.hp += buff_meta->param3;
|
||||
ability.hp = std::min(ability.max_hp, ability.hp);
|
||||
} else if ((int)buff_meta->param2 == 2) {
|
||||
//百分比
|
||||
ability.hp *= 1 + buff_meta->param3;
|
||||
ability.hp = std::min(ability.max_hp, ability.hp);
|
||||
}
|
||||
SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
||||
}
|
||||
}
|
||||
Buff* buff = &a8::FastAppend(buff_list_);
|
||||
buff->skill_lv = skill_lv;
|
||||
buff->owner = this;
|
||||
buff->meta = buff_meta;
|
||||
buff->skill_meta = buff_skill_meta;
|
||||
buff->add_frameno = room->GetFrameNo();
|
||||
buff->xtimer_attacher.xtimer = &room->xtimer;
|
||||
buff_effect_[buff->meta->i->buff_effect()] = buff;
|
||||
#if 0
|
||||
room->frame_event.AddBuff(this, buff);
|
||||
{
|
||||
room->xtimer.AddDeadLineTimerAndAttach
|
||||
(
|
||||
buff_meta->i->duration_time() * SERVER_FRAME_RATE,
|
||||
a8::XParams()
|
||||
.SetSender(this)
|
||||
.SetParam1(buff_meta->i->buff_id()),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Human* hum = (Human*)param.sender.GetUserData();
|
||||
hum->RemoveBuffById(param.param1);
|
||||
},
|
||||
&buff->xtimer_attacher.timer_list_
|
||||
);
|
||||
}
|
||||
ProcBuffEffect(caster, buff);
|
||||
#endif
|
||||
#ifdef DEBUG1
|
||||
SendDebugMsg(a8::Format("添加buff_id:%d buff_effect:%d",
|
||||
{
|
||||
buff_meta->i->buff_id(),
|
||||
buff_meta->i->buff_effect()
|
||||
}));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Creature::IsImmuneBuffEffect(int buff_effect)
|
||||
{
|
||||
for (auto itr = buff_list_.begin(); itr != buff_list_.end(); ++itr) {
|
||||
if (itr->meta->IsImmuneBuffEffect(buff_effect)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Creature::MustBeAddBuff(Creature* caster, int buff_id)
|
||||
{
|
||||
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(buff_id);
|
||||
if (!buff_meta) {
|
||||
abort();
|
||||
}
|
||||
AddBuff(caster, buff_meta, 1);
|
||||
}
|
||||
|
||||
void Creature::RemoveBuffById(int buff_id)
|
||||
{
|
||||
|
||||
}
|
29
server/gameserver/creature.h
Normal file
29
server/gameserver/creature.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "moveableentity.h"
|
||||
#include "buff.h"
|
||||
|
||||
class Creature : public MoveableEntity
|
||||
{
|
||||
public:
|
||||
|
||||
HumanAbility ability;
|
||||
|
||||
|
||||
bool HasBuffEffect(int buff_effect_id);
|
||||
Buff* GetBuffByEffectId(int effect_id);
|
||||
Buff* GetBuffById(int buff_id);
|
||||
void AddBuff(Creature* caster,
|
||||
MetaData::Buff* buff_meta,
|
||||
int skill_lv,
|
||||
MetaData::Skill* buff_skill_meta = nullptr);
|
||||
bool IsImmuneBuffEffect(int buff_effect);
|
||||
void MustBeAddBuff(Creature* caster, int buff_id);
|
||||
virtual void RemoveBuffById(int buff_id);
|
||||
|
||||
protected:
|
||||
std::array<float, kHAT_End> buff_attr_abs_ = {};
|
||||
std::array<float, kHAT_End> buff_attr_rate_ = {};
|
||||
std::array<Buff*, kBET_End> buff_effect_ = {};
|
||||
std::list<Buff> buff_list_;
|
||||
};
|
@ -11,7 +11,7 @@
|
||||
#include "obstacle.h"
|
||||
#include "collider.h"
|
||||
|
||||
Hero::Hero():MoveableEntity()
|
||||
Hero::Hero():Creature()
|
||||
{
|
||||
++PerfMonitor::Instance()->entity_num[ET_Hero];
|
||||
}
|
||||
@ -69,16 +69,6 @@ void Hero::GetAabbBox(AabbCollider& aabb_box)
|
||||
aabb_box._max.y = meta->i->radius();
|
||||
}
|
||||
|
||||
bool Hero::HasBuffEffect(int buff_effect_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Buff* Hero::GetBuffByEffectId(int effect_id)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
float Hero::GetSpeed()
|
||||
{
|
||||
return 3;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "moveableentity.h"
|
||||
#include "creature.h"
|
||||
|
||||
#include "cs_proto.pb.h"
|
||||
|
||||
@ -11,9 +11,8 @@ namespace MetaData
|
||||
|
||||
class Human;
|
||||
class Room;
|
||||
class Buff;
|
||||
class HeroAI;
|
||||
class Hero : public MoveableEntity
|
||||
class Hero : public Creature
|
||||
{
|
||||
public:
|
||||
Entity* master = nullptr;
|
||||
@ -33,8 +32,6 @@ public:
|
||||
virtual void Update(int delta_time) override;
|
||||
virtual void GetAabbBox(AabbCollider& aabb_box) override;
|
||||
|
||||
bool HasBuffEffect(int buff_effect_id);
|
||||
Buff* GetBuffByEffectId(int effect_id);
|
||||
float GetSpeed();
|
||||
|
||||
protected:
|
||||
|
@ -96,7 +96,7 @@ void InternalShot(Human* hum,
|
||||
}
|
||||
}
|
||||
|
||||
Human::Human():MoveableEntity()
|
||||
Human::Human():Creature()
|
||||
{
|
||||
default_weapon.weapon_idx = 0;
|
||||
default_weapon.weapon_id = 12101;
|
||||
@ -3076,89 +3076,6 @@ void Human::TriggerBuff(std::set<Entity*>& target_list, BuffTriggerType_e trigge
|
||||
}
|
||||
}
|
||||
|
||||
void Human::AddBuff(Human* caster,
|
||||
MetaData::Buff* buff_meta,
|
||||
int skill_lv,
|
||||
MetaData::Skill* buff_skill_meta)
|
||||
{
|
||||
if (GetBuffById(buff_meta->i->buff_id())) {
|
||||
return;
|
||||
}
|
||||
if (IsImmuneBuffEffect(buff_meta->i->buff_effect())) {
|
||||
return;
|
||||
}
|
||||
if (!buff_meta->EffectCanStack()) {
|
||||
Buff* buff = GetBuffByEffectId(buff_meta->i->buff_effect());
|
||||
if (buff) {
|
||||
RemoveBuffById(buff->meta->i->buff_id());
|
||||
}
|
||||
}
|
||||
if (buff_meta->i->buff_effect() == kBET_OnceChgAttr) {
|
||||
if ((int)buff_meta->param1== kHAT_Hp) {
|
||||
if ((int)buff_meta->param2 == 1) {
|
||||
//绝对值
|
||||
ability.hp += buff_meta->param3;
|
||||
ability.hp = std::min(ability.max_hp, ability.hp);
|
||||
} else if ((int)buff_meta->param2 == 2) {
|
||||
//百分比
|
||||
ability.hp *= 1 + buff_meta->param3;
|
||||
ability.hp = std::min(ability.max_hp, ability.hp);
|
||||
}
|
||||
SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
||||
}
|
||||
}
|
||||
Buff* buff = &a8::FastAppend(buff_list_);
|
||||
buff->skill_lv = skill_lv;
|
||||
buff->owner = this;
|
||||
buff->meta = buff_meta;
|
||||
buff->skill_meta = buff_skill_meta;
|
||||
buff->add_frameno = room->GetFrameNo();
|
||||
buff->xtimer_attacher.xtimer = &room->xtimer;
|
||||
buff_effect_[buff->meta->i->buff_effect()] = buff;
|
||||
room->frame_event.AddBuff(this, buff);
|
||||
{
|
||||
room->xtimer.AddDeadLineTimerAndAttach(
|
||||
buff_meta->i->duration_time() * SERVER_FRAME_RATE,
|
||||
a8::XParams()
|
||||
.SetSender(this)
|
||||
.SetParam1(buff_meta->i->buff_id()),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Human* hum = (Human*)param.sender.GetUserData();
|
||||
hum->RemoveBuffById(param.param1);
|
||||
},
|
||||
&buff->xtimer_attacher.timer_list_
|
||||
);
|
||||
}
|
||||
ProcBuffEffect(caster, buff);
|
||||
#ifdef DEBUG
|
||||
SendDebugMsg(a8::Format("添加buff_id:%d buff_effect:%d",
|
||||
{
|
||||
buff_meta->i->buff_id(),
|
||||
buff_meta->i->buff_effect()
|
||||
}));
|
||||
#endif
|
||||
}
|
||||
|
||||
void Human::MustBeAddBuff(Human* caster, int buff_id)
|
||||
{
|
||||
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(buff_id);
|
||||
if (!buff_meta) {
|
||||
abort();
|
||||
}
|
||||
AddBuff(caster, buff_meta, 1);
|
||||
}
|
||||
|
||||
bool Human::IsImmuneBuffEffect(int buff_effect)
|
||||
{
|
||||
for (auto itr = buff_list_.begin(); itr != buff_list_.end(); ++itr) {
|
||||
if (itr->meta->IsImmuneBuffEffect(buff_effect)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Human::RemoveBuffById(int buff_id)
|
||||
{
|
||||
for (auto itr = buff_list_.begin(); itr != buff_list_.end(); ++itr) {
|
||||
@ -3211,11 +3128,6 @@ void Human::ClearBuffList()
|
||||
RecalcBuffAttr();
|
||||
}
|
||||
|
||||
bool Human::HasBuffEffect(int buff_effect_id)
|
||||
{
|
||||
return GetBuffByEffectId(buff_effect_id) != nullptr;
|
||||
}
|
||||
|
||||
void Human::ProcBuffEffect(Human* caster, Buff* buff)
|
||||
{
|
||||
switch (buff->meta->i->buff_effect()) {
|
||||
@ -3593,21 +3505,6 @@ void Human::Revive()
|
||||
}
|
||||
}
|
||||
|
||||
Buff* Human::GetBuffById(int buff_id)
|
||||
{
|
||||
for (Buff& buff : buff_list_) {
|
||||
if (buff.meta->i->buff_id() == buff_id) {
|
||||
return &buff;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Buff* Human::GetBuffByEffectId(int effect_id)
|
||||
{
|
||||
return IsValidBuffEffect(effect_id) ? buff_effect_[effect_id] : nullptr;
|
||||
}
|
||||
|
||||
void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& target_list)
|
||||
{
|
||||
switch (skill_meta_->i->skill_target()) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "moveableentity.h"
|
||||
#include "creature.h"
|
||||
#include "cs_proto.pb.h"
|
||||
#include "GGListener.h"
|
||||
|
||||
@ -33,7 +33,7 @@ class Obstacle;
|
||||
class Loot;
|
||||
class Car;
|
||||
class Buff;
|
||||
class Human : public MoveableEntity
|
||||
class Human : public Creature
|
||||
{
|
||||
public:
|
||||
int socket_handle = 0;
|
||||
@ -51,7 +51,6 @@ class Human : public MoveableEntity
|
||||
MetaData::Equip* helmet_meta = nullptr;
|
||||
MetaData::Equip* chest_meta = nullptr;
|
||||
MetaData::Dress* skin_jlf_meta = nullptr;
|
||||
HumanAbility ability;
|
||||
long long last_shot_frameno_ = 0;
|
||||
|
||||
a8::Vec2 attack_dir;
|
||||
@ -260,17 +259,9 @@ class Human : public MoveableEntity
|
||||
float GetSkillAtkAdd(int skill_id);
|
||||
void TriggerOneObjectBuff(Entity* target, BuffTriggerType_e trigger_type);
|
||||
void TriggerBuff(std::set<Entity*>& target_list, BuffTriggerType_e trigger_type);
|
||||
void AddBuff(Human* caster,
|
||||
MetaData::Buff* buff_meta,
|
||||
int skill_lv,
|
||||
MetaData::Skill* buff_skill_meta = nullptr);
|
||||
void MustBeAddBuff(Human* caster, int buff_id);
|
||||
bool IsImmuneBuffEffect(int buff_effect);
|
||||
void RemoveBuffById(int buff_id);
|
||||
void RemoveBuffByEffectId(int buff_effect_id);
|
||||
virtual void RemoveBuffById(int buff_id) override;
|
||||
void ClearBuffList();
|
||||
bool HasBuffEffect(int buff_effect_id);
|
||||
Buff* GetBuffByEffectId(int effect_id);
|
||||
void RecalcBuffAttr();
|
||||
void ProcBuffEffect(Human* caster, Buff* buff);
|
||||
int GetLevel() {return level_;};
|
||||
@ -314,7 +305,6 @@ protected:
|
||||
void ProcCamoutflage(Loot* entity, MetaData::Equip* item_meta);
|
||||
void ProcSpoils(Loot* entity, MetaData::Equip* item_meta);
|
||||
void SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& target_list);
|
||||
Buff* GetBuffById(int buff_id);
|
||||
void ProcSkillPhase(MetaData::SkillPhase* phase);
|
||||
void AutoChgWeapon();
|
||||
void CancelRevive();
|
||||
@ -407,15 +397,10 @@ private:
|
||||
RaceType_e race_ = kHumanRace;
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
long long last_sync_gas_frameno = 0;
|
||||
std::list<Buff> buff_list_;
|
||||
std::map<int, int> items_;
|
||||
std::set<int> battling_items_;
|
||||
size_t normal_drop_times_ = 0;
|
||||
size_t box_drop_times_ = 0;
|
||||
std::array<Buff*, kBET_End> buff_effect_ = {};
|
||||
|
||||
std::array<float, kHAT_End> buff_attr_abs_ = {};
|
||||
std::array<float, kHAT_End> buff_attr_rate_ = {};
|
||||
|
||||
std::array<ObjectSyncFlags, FIXED_OBJECT_MAXID> fixed_object_sync_flags_ = {};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user