添加伤害公式

This commit is contained in:
aozhiwei 2019-04-26 11:19:46 +08:00
parent ccda49a1d7
commit f362689a6e
7 changed files with 36 additions and 3 deletions

View File

@ -104,8 +104,11 @@ void Bullet::OnHit(std::set<Entity*>& objects)
#else #else
if (!hum->dead && (hum->team_id == 0 || hum->team_id != player->team_id)) { if (!hum->dead && (hum->team_id == 0 || hum->team_id != player->team_id)) {
#endif #endif
player->stats.damage_amount += 10; float dmg = gun_meta->i->atk();
hum->DecHP(10, player->entity_uniid, player->name); float def = hum->def;
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
player->stats.damage_amount += finaly_dmg;
hum->DecHP(finaly_dmg, player->entity_uniid, player->name);
} }
} }
break; break;
@ -113,7 +116,12 @@ void Bullet::OnHit(std::set<Entity*>& objects)
{ {
Obstacle* obstacle = (Obstacle*)target; Obstacle* obstacle = (Obstacle*)target;
if (!obstacle->dead && obstacle->meta->i->attack_type() == 1) { if (!obstacle->dead && obstacle->meta->i->attack_type() == 1) {
obstacle->health = std::max(0.0f, obstacle->health - 10); float dmg = gun_meta->i->atk();
float def = 0;
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
player->stats.damage_amount += finaly_dmg;
obstacle->health = std::max(0.0f, obstacle->health - finaly_dmg);
obstacle->dead = obstacle->health <= 0.01f; obstacle->dead = obstacle->health <= 0.01f;
obstacle->dead_frameno = room->frame_no; obstacle->dead_frameno = room->frame_no;
if (obstacle->dead) { if (obstacle->dead) {

View File

@ -826,3 +826,16 @@ bool Human::CanSee(Human* hum)
{ {
return room->grid_service.InView(grid_id, hum->grid_id); return room->grid_service.InView(grid_id, hum->grid_id);
} }
void Human::RecalcAttr()
{
def = meta->i->def();
MetaData::Equip* chest_meta = MetaMgr::Instance()->GetEquip(chest);
if (chest_meta) {
def += chest_meta->i->def();
}
MetaData::Equip* helmet_meta = MetaMgr::Instance()->GetEquip(helmet);
if (helmet_meta) {
def += helmet_meta->i->def();
}
}

View File

@ -86,6 +86,9 @@ class Human : public Entity
long long jump_frameno = 0; long long jump_frameno = 0;
long long send_msg_times = 0; long long send_msg_times = 0;
float def = 0.0f;
Human(); Human();
virtual ~Human() override; virtual ~Human() override;
virtual void Initialize() override; virtual void Initialize() override;
@ -128,6 +131,7 @@ class Human : public Entity
void FillMFActivePlayerData(cs::MFActivePlayerData* player_data); void FillMFActivePlayerData(cs::MFActivePlayerData* player_data);
void FillMFGasData(cs::MFGasData* gas_data); void FillMFGasData(cs::MFGasData* gas_data);
bool CanSee(Human* hum); bool CanSee(Human* hum);
void RecalcAttr();
protected: protected:
long long last_shot_frameno_ = 0; long long last_shot_frameno_ = 0;

View File

@ -71,6 +71,10 @@ public:
{ {
MetaMgr::Instance()->gas_inactive_time = MetaMgr::Instance()->GetSysParamAsInt("gas_inactive_time"); MetaMgr::Instance()->gas_inactive_time = MetaMgr::Instance()->GetSysParamAsInt("gas_inactive_time");
MetaMgr::Instance()->jump_time = MetaMgr::Instance()->GetSysParamAsFloat("jump_time"); MetaMgr::Instance()->jump_time = MetaMgr::Instance()->GetSysParamAsFloat("jump_time");
MetaMgr::Instance()->K = MetaMgr::Instance()->GetSysParamAsFloat("K");
if (MetaMgr::Instance()->K < 0.01f) {
abort();
}
} }
#endif #endif
} }

View File

@ -33,6 +33,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
int gas_inactive_time = 10; int gas_inactive_time = 10;
int jump_time = 10; int jump_time = 10;
float K = 100.0f;
private: private:
MetaDataLoader* loader_ = nullptr; MetaDataLoader* loader_ = nullptr;

View File

@ -675,6 +675,7 @@ void Player::LootInteraction(Loot* entity)
room->DropItem(pos, old_item_meta->i->id(), 1); room->DropItem(pos, old_item_meta->i->id(), 1);
} }
chest = item_meta->i->id(); chest = item_meta->i->id();
RecalcAttr();
} else if (item_meta->i->equip_subtype() == 2) { } else if (item_meta->i->equip_subtype() == 2) {
//头盔 //头盔
MetaData::Equip* old_item_meta = MetaMgr::Instance()->GetEquip(helmet); MetaData::Equip* old_item_meta = MetaMgr::Instance()->GetEquip(helmet);
@ -685,6 +686,7 @@ void Player::LootInteraction(Loot* entity)
room->DropItem(pos, old_item_meta->i->id(), 1); room->DropItem(pos, old_item_meta->i->id(), 1);
} }
helmet = item_meta->i->id(); helmet = item_meta->i->id();
RecalcAttr();
} }
} }
break; break;

View File

@ -78,6 +78,7 @@ message Player
optional float radius = 2; // optional float radius = 2; //
optional int32 health = 3; // optional int32 health = 3; //
optional int32 move_speed = 4; // optional int32 move_speed = 4; //
optional float def = 5; //
} }
message Skill message Skill