完成属性计算

This commit is contained in:
aozhiwei 2020-03-03 10:21:48 +08:00
parent 0ab93f7ff6
commit 06b36b60c9
9 changed files with 81 additions and 78 deletions

View File

@ -25,9 +25,9 @@ Android::~Android()
void Android::Initialize()
{
Human::Initialize();
health = meta->i->health();
RandSkin();
GiveEquip();
RecalcBaseAttr();
}
void Android::Update(int delta_time)

View File

@ -109,28 +109,15 @@ enum BuffEffectType_e
{
kBET_Begin = 0,
kBET_ChgAttr = 1, //改变属性
kBET_Vertigo = 2, //眩晕
kBET_InGrass = 3, //在草丛
kBET_LastBurn = 4, //持续灼烧
kBET_Invincible = 5, //无敌
kBET_Hide = 6, //隐身
kBET_Dcgr = 7, //电磁干扰
kBET_ReleaseDcgr = 8, //释放电磁干扰
kBET_ReleaseFireBomb = 9, //喷火
kBET_Assault = 10, //向心突击
kBET_Jump = 2, //翻滚
kBET_OnceChgAttr = 11, //一次性buff
kBET_LastRecover = 12, //持续回血
kBET_Shield = 13, //护盾
kBET_ImmediatelyRevive = 14, //立刻复活
kBET_End
};
enum SkillFunc_e
{
kSkill_FuncNone = 0,
kSkill_Jump = 2,
kSkill_Shot = 3,
kSkill_SummonObject = 4,
kSkill_Jump = 1,
kSkill_FuncEnd
};
@ -225,6 +212,8 @@ enum PropertyType_e
{
kPropHp = 1,
kPropMaxHp = 2,
kPropSkillLeftTime = 4,
kPropSkillCd = 5,
kPropTankBulletNum = 6,
kPropTankOil = 7,
kPropBulletNum = 8

View File

@ -125,6 +125,29 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum)
p->set_value(target->tank_oil_value);
}
}
for (size_t idx : hum->chged_buffs_) {
if (idx < room->frame_event.chged_buffs_.size()) {
auto p = msg->add_chged_buff_list();
*p = std::get<1>(room->frame_event.chged_buffs_[idx]);
}
}
for (size_t idx : hum->chged_skillcds_) {
if (idx < room->frame_event.chged_skillcds_.size()) {
Human* target = room->frame_event.chged_skillcds_[idx];
{
auto p = msg->add_chged_property_list();
p->set_obj_id(target->entity_uniid);
p->set_property_type(kPropSkillLeftTime);
p->set_value(target->GetSkillLeftTime());
}
{
auto p = msg->add_chged_property_list();
p->set_obj_id(target->entity_uniid);
p->set_property_type(kPropSkillCd);
p->set_value(target->GetSkillCd());
}
}
}
for (size_t idx : hum->chged_hps_) {
if (idx < room->frame_event.chged_hps_.size()) {
Human* target = room->frame_event.chged_hps_[idx];

View File

@ -125,7 +125,7 @@ void Human::FillMFObjectFull(cs::MFObjectFull* full_data)
TypeConvert::ToPb(pos, p->mutable_pos());
TypeConvert::ToPb(attack_dir, p->mutable_dir());
p->set_health(health);
p->set_health(GetHP());
p->set_max_health(GetMaxHP());
p->set_dead(dead);
p->set_downed(downed);
@ -264,7 +264,7 @@ void Human::FillMFTeamData(cs::MFTeamData* team_data)
team_data->set_name(name);
TypeConvert::ToPb(pos, team_data->mutable_pos());
TypeConvert::ToPb(attack_dir, team_data->mutable_dir());
team_data->set_health(health);
team_data->set_health(GetHP());
team_data->set_max_health(GetMaxHP());
team_data->set_disconnected(false);
team_data->set_dead(dead);
@ -581,12 +581,12 @@ float Human::GetRadius()
float Human::GetHP()
{
return health;
return ability.hp;
}
float Human::GetMaxHP()
{
return meta->i->health();
return ability.max_hp;
}
void Human::UpdateSkill()
@ -844,7 +844,7 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id)
stats.weapon_id = weapon_id;
dead = true;
downed = false;
health = 0.0f;
ability.hp = 0.0f;
dead_frameno = room->frame_no;
++dead_times;
int max_revive_times = MetaMgr::Instance()->GetSysParamAsInt("max_revive_times", 1);
@ -892,12 +892,12 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i
energy_shield = std::max(0.0f, energy_shield - dec_hp);
SyncAroundPlayers(__FILE__, __LINE__, __func__);
} else {
float old_health = health;
health = std::max(0.0f, health - dec_hp);
if (health - old_health > 0.001f) {
stats.damage_amount_in += health - old_health;
float old_health = GetHP();
ability.hp = std::max(0.0f, GetHP() - dec_hp);
if (GetHP() - old_health > 0.001f) {
stats.damage_amount_in += GetHP() - old_health;
}
if (health <= 0.0001f && !dead) {
if (GetHP() <= 0.0001f && !dead) {
if (downed) {
if (downed_timer) {
room->xtimer.DeleteTimer(downed_timer);
@ -908,7 +908,7 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i
SyncAroundPlayers(__FILE__, __LINE__, __func__);
} else {
if (HasNoDownedTeammate()) {
health = MetaMgr::Instance()->GetSysParamAsInt("downed_recover_hp");
ability.hp = MetaMgr::Instance()->GetSysParamAsInt("downed_recover_hp");
downed = true;
downed_timer = room->xtimer.AddRepeatTimerAndAttach(
SERVER_FRAME_RATE,
@ -1030,12 +1030,6 @@ bool Human::CanUseSkill()
if (GetSkillLeftTime() > 0) {
return false;
}
if (a8::HasBitFlag(status, HS_Assaulting) ||
HasBuffEffect(kBET_Vertigo) ||
HasBuffEffect(kBET_Dcgr)
) {
return false;
}
return true;
}
@ -1049,6 +1043,9 @@ void Human::DoSkill()
skill_param1 = 0.0f;
playing_skill = true;
last_use_skill_frameno_ = room->frame_no;
#if 1
skill_target_id = entity_uniid;
#endif
Entity* entity = room->GetEntityByUniId(skill_target_id);
if (entity && entity->entity_type == ET_Player) {
Human* hum = (Human*)entity;
@ -1245,7 +1242,7 @@ void Human::FillMFActivePlayerData(cs::MFActivePlayerData* player_data)
player_data->set_backpack(backpack);
player_data->set_helmet(helmet);
player_data->set_chest(chest);
player_data->set_health(health);
player_data->set_health(GetHP());
player_data->set_max_health(GetMaxHP());
player_data->set_cur_weapon_idx(curr_weapon->weapon_idx);
player_data->set_cur_scope(curr_scope_idx);
@ -1338,6 +1335,8 @@ void Human::RecalcBaseAttr()
if (helmet_meta) {
ability.def += helmet_meta->i->def();
}
ability.hp = meta->i->health();
ability.max_hp = ability.hp;
}
int Human::GetInventory(int slot_id)
@ -1377,8 +1376,8 @@ int Human::GetVolume(int slot_id)
void Human::RecoverHp(int inc_hp)
{
if (!dead) {
health += inc_hp;
health = std::max(health, GetMaxHP());
ability.hp += inc_hp;
ability.hp = std::max(GetHP(), GetMaxHP());
}
}
@ -1700,10 +1699,10 @@ void Human::UpdateAction()
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id);
if (item_meta){
if (GetInventory(item_meta->i->_inventory_slot()) > 0) {
float old_health = health;
health += item_meta->i->heal();
health = std::min(health, GetMaxHP());
stats.heal_amount += health - old_health;
float old_health = GetHP();
ability.hp += item_meta->i->heal();
ability.hp = std::min(GetHP(), GetMaxHP());
stats.heal_amount += GetHP() - old_health;
DecInventory(item_meta->i->_inventory_slot(), 1);
need_sync_active_player = true;
SyncAroundPlayers(__FILE__, __LINE__, __func__);
@ -1734,10 +1733,10 @@ void Human::UpdateAction()
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
float old_health = hum->health;
hum->health += param.param1.GetDouble();
hum->health = std::min(hum->health, hum->GetMaxHP());
hum->stats.heal_amount += hum->health - old_health;
float old_health = hum->GetHP();
hum->ability.hp += param.param1.GetDouble();
hum->ability.hp = std::min(hum->GetHP(), hum->GetMaxHP());
hum->stats.heal_amount += hum->GetHP() - old_health;
hum->SyncAroundPlayers(__FILE__, __LINE__, __func__);
if (hum->room->frame_no - hum->pain_killer_frameno > hum->pain_killer_lastingtime * SERVER_FRAME_RATE) {
hum->room->xtimer.DeleteTimer(hum->pain_killer_timer);
@ -1772,7 +1771,7 @@ void Human::UpdateAction()
return;
}
if (!hum->dead && hum->downed) {
hum->health = MetaMgr::Instance()->GetSysParamAsInt("downed_relive_recover_hp");
hum->ability.hp = MetaMgr::Instance()->GetSysParamAsInt("downed_relive_recover_hp");
hum->downed = false;
if (hum->downed_timer) {
room->xtimer.DeleteTimer(hum->downed_timer);
@ -2566,16 +2565,12 @@ void Human::ClearBuffList()
if (buff_effect_[itr->meta->i->buff_effect()] == &(*itr)) {
buff_effect_[itr->meta->i->buff_effect()] = nullptr;
}
#if 0
switch (itr->meta->i->buff_effect()) {
case kBET_Shield:
{
energy_shield = 0.0f;
max_energy_shield = 0.0f;
}
break;
default:
break;
}
#endif
room->frame_event.RemoveBuff(this, itr->meta->i->buff_id());
}
buff_list_.clear();
@ -2598,6 +2593,16 @@ void Human::ProcBuffEffect(Buff* buff)
RecalcBuffAttr();
}
break;
case kBET_Jump:
{
if (curr_skill_phase < skill_meta_->phases.size()) {
MetaData::SkillPhase* phase = &skill_meta_->phases[curr_skill_phase];
if (phase->time_offset >= (int)((room->frame_no - last_use_skill_frameno_) * FRAME_RATE_MS)) {
_UpdateMove(phase->param1);
}
}
}
break;
default:
break;
}
@ -2787,14 +2792,6 @@ void Human::ProcSkillPhase(MetaData::SkillPhase* phase)
{
}
break;
case kSkill_Shot:
{
}
break;
case kSkill_SummonObject:
{
}
break;
default:
break;
}

View File

@ -55,7 +55,6 @@ class Human : public Entity
std::string name;
std::string avatar_url;
float health = 0.0;
bool downed = false;
bool disconnected = false;
int anim_type = 0;

View File

@ -275,11 +275,11 @@ private:
dress_vec.push_back(&item);
}
for (auto& meta : skill_meta_list) {
MetaData::Skill& item = a8::FastAppend(skill_list);
for (auto& meta : attr_meta_list) {
MetaData::Attr& item = a8::FastAppend(attr_list);
item.i = &meta;
item.Init();
skill_hash[item.i->skill_id()] = &item;
attr_id_hash[item.i->attr_id()] = &item;
attr_name_hash[item.i->attr_ename()] = &item;
}
for (auto& meta : buff_meta_list) {
@ -292,11 +292,11 @@ private:
buff_hash[item.i->buff_id()] = &item;
}
for (auto& meta : attr_meta_list) {
MetaData::Attr& item = a8::FastAppend(attr_list);
for (auto& meta : skill_meta_list) {
MetaData::Skill& item = a8::FastAppend(skill_list);
item.i = &meta;
attr_id_hash[item.i->attr_id()] = &item;
attr_name_hash[item.i->attr_ename()] = &item;
item.Init();
skill_hash[item.i->skill_id()] = &item;
}
for (auto& meta : rankreward_meta_list) {

View File

@ -30,7 +30,6 @@ Player::~Player()
void Player::Initialize()
{
Human::Initialize();
health = meta->i->health();
max_energy_shield = energy_shield;
skill_meta_ = MetaMgr::Instance()->GetSkill(41001);
RecalcBaseAttr();
@ -85,9 +84,6 @@ void Player::Update(int delta_time)
if (jump) {
UpdateJump();
}
if (use_skill) {
UpdateUseSkill();
}
if (get_down) {
UpdateGetDown();
}
@ -916,9 +912,6 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
if (msg.has_jump()) {
jump = true;
}
if (msg.has_use_skill()) {
use_skill = true;
}
if (msg.has_aiming()) {
aiming = msg.aiming();
} else {
@ -928,8 +921,10 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
get_down = msg.get_down();
}
if (msg.has_use_skill()) {
use_skill = true;
use_skill = msg.use_skill();
skill_target_id = msg.skill_target_id();
} else {
use_skill = false;
}
}
@ -1113,7 +1108,7 @@ void Player::_CMRevive(f8::MsgHdr& hdr, const cs::CMRevive& msg)
real_dead = false;
downed = false;
FreeDownedTimer();
health = GetMaxHP();
ability.hp = GetMaxHP();
ResetTankSkin();
SyncAroundPlayers(__FILE__, __LINE__, __func__);
FreeReviveTimer();

View File

@ -44,7 +44,6 @@ Player* PlayerMgr::CreatePlayerByCMJoin(long ip_saddr, int socket, const cs::CMJ
hum->session_id = msg.session_id();
hum->from_appid = msg.from_appid();
hum->name = msg.name();
hum->health = 0;
hum->team_uuid = msg.team_uuid();
hum->team_mode = msg.team_mode();
hum->auto_fill = msg.auto_fill();

View File

@ -822,6 +822,7 @@ message SMUpdate
repeated MFEmote emotes = 23; //
optional MFAirDrop airdrop = 26; //
optional MFPlane plane = 27; //
repeated MFBuffChg chged_buff_list = 28; //buff变更列表
repeated MFPropertyChg chged_property_list = 31; //property变更列表
}