完成武器属性

This commit is contained in:
aozhiwei 2020-05-27 15:21:01 +08:00
parent 5f3b8de6ab
commit f64e16d276
10 changed files with 101 additions and 35 deletions

View File

@ -62,10 +62,10 @@ void Bullet::OnHit(std::set<Entity*>& objects)
(hum->team_id == 0 || player->team_id != hum->team_id)) { (hum->team_id == 0 || player->team_id != hum->team_id)) {
#endif #endif
#if 1 #if 1
float dmg = gun_meta->i->atk() * (1 + player->GetBuffAttrRate(kHAT_Atk)) + float dmg = GetAtk() * (1 + player->GetBuffAttrRate(kHAT_Atk)) +
player->GetBuffAttrAbs(kHAT_Atk); player->GetBuffAttrAbs(kHAT_Atk);
#else #else
float dmg = gun_meta->i->atk() * (1 + player->buff.damage_add + player->atk_add); float dmg = GetAtk() * (1 + player->buff.damage_add + player->atk_add);
#endif #endif
#if 1 #if 1
float def = hum->ability.def * (1 + hum->GetBuffAttrRate(kHAT_Def)) + float def = hum->ability.def * (1 + hum->GetBuffAttrRate(kHAT_Def)) +
@ -92,10 +92,10 @@ 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) {
#if 1 #if 1
float dmg = gun_meta->i->atk() * (1 + player->GetBuffAttrRate(kHAT_Atk)) + float dmg = GetAtk() * (1 + player->GetBuffAttrRate(kHAT_Atk)) +
player->GetBuffAttrAbs(kHAT_Atk); player->GetBuffAttrAbs(kHAT_Atk);
#else #else
float dmg = gun_meta->i->atk() * (1 + player->buff.damage_add + player->atk_add); float dmg = GetAtk() * (1 + player->buff.damage_add + player->atk_add);
#endif #endif
float def = 0; float def = 0;
float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K); float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K);
@ -254,3 +254,10 @@ void Bullet::MapServiceUpdate()
} }
} }
} }
float Bullet::GetAtk()
{
return gun_meta->i->atk() +
(gun_upgrade_meta ? gun_upgrade_meta->GetAttrValue(gun_lv, kHAT_Atk) : 0);
}

View File

@ -40,6 +40,7 @@ class Bullet : public Entity
void ProcBomb(); void ProcBomb();
bool IsBomb(); bool IsBomb();
void MapServiceUpdate(); void MapServiceUpdate();
float GetAtk();
private: private:
CircleCollider* self_collider_ = nullptr; CircleCollider* self_collider_ = nullptr;

View File

@ -73,7 +73,7 @@ void Human::Initialize()
RecalcSelfCollider(); RecalcSelfCollider();
volume_ = meta->volume; volume_ = meta->volume;
observers_.insert(this); observers_.insert(this);
ability.hp = meta->i->health(); ability.hp = meta->i->health() + (spec_weapon.meta ? spec_weapon.GetAttrValue(kHAT_MaxHp) : 0);
} }
float Human::GetSpeed() float Human::GetSpeed()
@ -307,8 +307,8 @@ void Human::Shot(a8::Vec2& target_dir)
float bullet_angle = std::get<2>(tuple); float bullet_angle = std::get<2>(tuple);
if (curr_weapon->meta->i->bullet_angle() >= 0.10f) { if (curr_weapon->meta->i->bullet_angle() >= 0.10f) {
int angle = (int)curr_weapon->meta->i->bullet_angle() * 1000; int angle = (int)curr_weapon->meta->i->bullet_angle() * 1000;
if (curr_weapon->upgrade_meta) { if (curr_weapon->GetUpgradeMeta()) {
angle -= curr_weapon->upgrade_meta->GetAttrValue(curr_weapon->weapon_lv, kHAT_BulletAngle) * 1000; angle -= curr_weapon->GetAttrValue(kHAT_BulletAngle) * 1000;
} }
if (angle > 0) { if (angle > 0) {
bullet_angle += (rand() % angle) / 1000.0f * (rand() % 2 == 0 ? 1 : -1); bullet_angle += (rand() % angle) / 1000.0f * (rand() % 2 == 0 ? 1 : -1);
@ -395,8 +395,8 @@ void Human::TankShot(a8::Vec2& target_dir)
float bullet_angle = std::get<2>(tuple); float bullet_angle = std::get<2>(tuple);
if (tank_weapon.meta->i->bullet_angle() >= 0.01f) { if (tank_weapon.meta->i->bullet_angle() >= 0.01f) {
int angle = (int)tank_weapon.meta->i->bullet_angle() * 1000; int angle = (int)tank_weapon.meta->i->bullet_angle() * 1000;
if (tank_weapon.upgrade_meta) { if (tank_weapon.GetUpgradeMeta()) {
angle -= tank_weapon.upgrade_meta->GetAttrValue(tank_weapon.weapon_lv, kHAT_BulletAngle) * 1000; angle -= tank_weapon.GetAttrValue(kHAT_BulletAngle) * 1000;
} }
if (angle > 0) { if (angle > 0) {
bullet_angle += (rand() % angle) / 1000.0f * (rand() % 2 == 0 ? 1 : -1); bullet_angle += (rand() % angle) / 1000.0f * (rand() % 2 == 0 ? 1 : -1);

View File

@ -82,7 +82,8 @@ namespace MetaData
void EquipUpgrade::Init() void EquipUpgrade::Init()
{ {
for (int j = 0; j < i->max_lv(); ++j) { const int MAX_LV = 20;
for (int j = 0; j < MAX_LV; ++j) {
std::array<float, kHAT_End>& attrs = a8::FastAppend(level_attrs); std::array<float, kHAT_End>& attrs = a8::FastAppend(level_attrs);
for (size_t k = 0; k < kHAT_End; ++k) { for (size_t k = 0; k < kHAT_End; ++k) {
attrs[k] = 0; attrs[k] = 0;
@ -91,24 +92,29 @@ namespace MetaData
{ {
std::vector<std::string> strings; std::vector<std::string> strings;
a8::Split(i->attr_type(), strings, '|'); a8::Split(i->attr_type(), strings, '|');
int level = 1;
for (auto& str : strings) { for (auto& str : strings) {
std::vector<std::string> strings2; if (str.empty()) {
a8::Split(str, strings2, ':'); continue;
if (strings2.size() != 3) {
abort();
} }
int attr_type = a8::XValue(strings2[0]); ++level;
int attr_level = a8::XValue(strings2[1]); std::vector<std::string> strings2;
float attr_value = a8::XValue(strings2[2]).GetDouble(); a8::Split(str, strings2, ';');
if (attr_type < kHAT_End) { for (auto& str2 : strings2) {
if (attr_level >= 0 && attr_level < i->max_lv()) { std::vector<std::string> strings3;
for (int j = 1; j < i->max_lv(); ++j) { a8::Split(str2, strings3, ':');
if (j % attr_level == 0) { if (strings3.size() != 2) {
level_attrs[j][attr_type] = attr_value * (j / attr_level); abort();
} }
} int attr_type = a8::XValue(strings3[0]);
int attr_value = a8::XValue(strings3[1]);
if (attr_type <= kHAT_End) {
level_attrs[level][attr_type] = attr_value;
} }
} }
}//end for strings
for (int i = level; i < MAX_LV; ++i) {
level_attrs[i] = level_attrs[level];
} }
} }
} }
@ -121,7 +127,7 @@ namespace MetaData
if (level > (int)level_attrs.size()) { if (level > (int)level_attrs.size()) {
return 0; return 0;
} }
if (attr_type < kHAT_End) { if (attr_type <= kHAT_End) {
return level_attrs[level][attr_type]; return level_attrs[level][attr_type];
} }
return 0; return 0;

View File

@ -165,7 +165,7 @@ void Player::UpdateShot()
if (last_shot_frameno_ == 0 || if (last_shot_frameno_ == 0 ||
( (
(room->frame_no - last_shot_frameno_) * (1000 / SERVER_FRAME_RATE)) >= (room->frame_no - last_shot_frameno_) * (1000 / SERVER_FRAME_RATE)) >=
p_weapon->meta->i->fire_rate() p_weapon->GetAttrValue(kHAT_FireRate)
) { ) {
Shot(); Shot();
} }
@ -359,8 +359,8 @@ void Player::Shot()
float bullet_angle = std::get<2>(tuple); float bullet_angle = std::get<2>(tuple);
if (curr_weapon->meta->i->bullet_angle() >= 0.01f) { if (curr_weapon->meta->i->bullet_angle() >= 0.01f) {
int angle = (int)curr_weapon->meta->i->bullet_angle() * 1000; int angle = (int)curr_weapon->meta->i->bullet_angle() * 1000;
if (curr_weapon->upgrade_meta) { if (curr_weapon->GetUpgradeMeta()) {
angle -= curr_weapon->upgrade_meta->GetAttrValue(curr_weapon->weapon_lv, kHAT_BulletAngle) * 1000; angle -= curr_weapon->GetAttrValue(kHAT_BulletAngle) * 1000;
} }
if (angle > 0) { if (angle > 0) {
bullet_angle += (rand() % angle) / 1000.0f * (rand() % 2 == 0 ? 1 : -1); bullet_angle += (rand() % angle) / 1000.0f * (rand() % 2 == 0 ? 1 : -1);
@ -523,7 +523,11 @@ void Player::LootInteraction(Loot* entity)
} else { } else {
weapons[0].weapon_idx = 0; weapons[0].weapon_idx = 0;
weapons[0].weapon_id = entity->item_id; weapons[0].weapon_id = entity->item_id;
#if 1
weapons[0].weapon_lv = std::max(1, entity->item_level);
#else
weapons[0].weapon_lv = std::max(1, GetWeaponConfigLv(weapons[0].weapon_id)); weapons[0].weapon_lv = std::max(1, GetWeaponConfigLv(weapons[0].weapon_id));
#endif
weapons[0].ammo = 0; weapons[0].ammo = 0;
weapons[0].meta = item_meta; weapons[0].meta = item_meta;
weapons[0].Recalc(); weapons[0].Recalc();
@ -554,7 +558,11 @@ void Player::LootInteraction(Loot* entity)
return; return;
} }
weapon->weapon_id = entity->item_id; weapon->weapon_id = entity->item_id;
#if 1
weapon->weapon_lv = std::max(1, entity->item_level);
#else
weapon->weapon_lv = std::max(1, GetWeaponConfigLv(weapon->weapon_id)); weapon->weapon_lv = std::max(1, GetWeaponConfigLv(weapon->weapon_id));
#endif
weapon->ammo = 0; weapon->ammo = 0;
weapon->meta = item_meta; weapon->meta = item_meta;
weapon->Recalc(); weapon->Recalc();

View File

@ -5,6 +5,7 @@
#include "cs_proto.pb.h" #include "cs_proto.pb.h"
#include "ss_proto.pb.h" #include "ss_proto.pb.h"
#include "room.h" #include "room.h"
#include "metamgr.h"
#include "framework/cpp/utils.h" #include "framework/cpp/utils.h"
@ -73,10 +74,15 @@ Player* PlayerMgr::CreatePlayerByCMJoin(long ip_saddr, int socket, const cs::CMJ
#endif #endif
for (auto& weapon : msg.weapons()) { for (auto& weapon : msg.weapons()) {
if (weapon.weapon_id() != 0 && weapon.weapon_lv() > 0) { if (weapon.weapon_id() != 0 && weapon.weapon_lv() > 0) {
hum->weapon_configs[weapon.weapon_id()] = weapon.weapon_lv(); MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(weapon.weapon_id());
hum->spec_weapon.weapon_id = weapon.weapon_id(); if (equip_meta) {
hum->spec_weapon.weapon_lv = weapon.weapon_lv(); hum->weapon_configs[weapon.weapon_id()] = weapon.weapon_lv();
hum->spec_weapon.ammo = weapon.ammo(); hum->spec_weapon.weapon_id = weapon.weapon_id();
hum->spec_weapon.weapon_lv = weapon.weapon_lv();
hum->spec_weapon.ammo = weapon.ammo();
hum->spec_weapon.meta = equip_meta;
hum->spec_weapon.Recalc();
}
} }
} }
for (auto& weapon : msg.grow_weapons()) { for (auto& weapon : msg.grow_weapons()) {

View File

@ -549,7 +549,7 @@ void Room::CreateBullet(Human* hum, Weapon* weapon,
bullet->player = hum; bullet->player = hum;
bullet->room = this; bullet->room = this;
bullet->gun_meta = weapon->meta; bullet->gun_meta = weapon->meta;
bullet->gun_upgrade_meta = weapon->upgrade_meta; bullet->gun_upgrade_meta = weapon->GetUpgradeMeta();
bullet->meta = MetaMgr::Instance()->GetEquip(weapon->meta->i->use_bullet()); bullet->meta = MetaMgr::Instance()->GetEquip(weapon->meta->i->use_bullet());
bullet->SetPos(pos); bullet->SetPos(pos);
bullet->dir = dir; bullet->dir = dir;

View File

@ -26,6 +26,41 @@ int Weapon::GetClipVolume()
} }
} }
float Weapon::GetAttrValue(HumanAttrType_e attr_type)
{
if (!meta) {
return 0;
}
switch (attr_type) {
case kHAT_Atk:
{
return meta->i->atk() +
(upgrade_meta ? upgrade_meta->GetAttrValue(weapon_lv, attr_type) : 0);
}
break;
case kHAT_FireRate:
{
return meta->i->fire_rate() -
(upgrade_meta ? upgrade_meta->GetAttrValue(weapon_lv, attr_type) : 0);
}
break;
case kHAT_Volume:
{
return meta->i->clip_volume() +
(upgrade_meta ? upgrade_meta->GetAttrValue(weapon_lv, attr_type) : 0);
}
break;
case kHAT_MaxHp:
{
return 0 +
(upgrade_meta ? upgrade_meta->GetAttrValue(weapon_lv, attr_type) : 0);
}
break;
default:
return 0;
}
}
void Skin::ToPB(cs::MFSkin* pb_obj) void Skin::ToPB(cs::MFSkin* pb_obj)
{ {
pb_obj->set_skin_id(skin_id); pb_obj->set_skin_id(skin_id);

View File

@ -52,11 +52,15 @@ struct Weapon
int weapon_lv = 0; int weapon_lv = 0;
int ammo = 0; int ammo = 0;
MetaData::Equip* meta = nullptr; MetaData::Equip* meta = nullptr;
MetaData::EquipUpgrade* upgrade_meta = nullptr;
void ToPB(cs::MFWeapon* pb_obj); void ToPB(cs::MFWeapon* pb_obj);
void Recalc(); void Recalc();
int GetClipVolume(); int GetClipVolume();
float GetAttrValue(HumanAttrType_e attr_type);
MetaData::EquipUpgrade* GetUpgradeMeta() { return upgrade_meta;}
private:
MetaData::EquipUpgrade* upgrade_meta = nullptr;
}; };
struct Skin struct Skin

View File

@ -99,7 +99,6 @@ message EquipUpgrade
{ {
optional int32 id = 1; optional int32 id = 1;
optional string attr_type = 4; optional string attr_type = 4;
optional int32 max_lv = 5;
} }
message Player message Player