优化weapon

This commit is contained in:
aozhiwei 2022-09-08 20:33:37 +08:00
parent 17ac94132b
commit 42a28a190e
15 changed files with 37 additions and 188 deletions

View File

@ -662,7 +662,7 @@ int AndroidAI::GetAttackTimes()
{
Human* myself = (Human*)owner;
if (myself->GetCurrWeapon()) {
return std::min(ai_meta->i->attack_times(), myself->GetCurrWeapon()->GetClipVolume());
return std::min(ai_meta->i->attack_times(), myself->GetCurrWeapon()->GetClipVolume(myself));
} else {
return ai_meta->i->attack_times();
}

View File

@ -254,7 +254,7 @@ void Buff::ProcBecome()
weapon->weapon_lv = 1;
weapon->meta = weapon_meta;
weapon->Recalc();
weapon->ammo = weapon->GetClipVolume();
weapon->ammo = weapon->GetClipVolume(owner);
if (i == 0) {
caster_.Get()->SetCurrWeapon(weapon);
}
@ -931,7 +931,7 @@ void Buff::ProcMachineGun()
weapon->weapon_lv = 1;
weapon->meta = weapon_meta;
weapon->Recalc();
weapon->ammo = weapon->GetClipVolume();
weapon->ammo = weapon->GetClipVolume(owner);
if (i == 0) {
caster_.Get()->SetCurrWeapon(weapon);
}

View File

@ -44,7 +44,7 @@ void Car::Initialize()
weapon.weapon_lv = 1;
weapon.meta = weapon_meta;
weapon.Recalc();
weapon.ammo = weapon.GetClipVolume();
weapon.ammo = weapon.GetClipVolume(this);
SetCurrWeapon(&weapon);
}
born_frameno_ = room->GetFrameNo();

View File

@ -1180,7 +1180,7 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
second_weapon.weapon_lv = 1;
second_weapon.meta = spec_weapon_meta;
second_weapon.Recalc();
second_weapon.ammo = second_weapon.GetClipVolume();
second_weapon.ammo = second_weapon.GetClipVolume(this);
}
}
}
@ -1784,14 +1784,14 @@ void Creature::Shot(a8::Vec2& target_dir, bool& shot_ok, float fly_distance)
if (IsCar()) {
if (room->GetFrameNo() - last_shot_frameno_ > 0) {
if ((room->GetFrameNo() - last_shot_frameno_) * (1000 / SERVER_FRAME_RATE) <
GetCurrWeapon()->GetAttrValue(kHAT_FireRate)
GetCurrWeapon()->GetFireRate(this)
) {
return;
}
}
} else {
if ((room->GetFrameNo() - last_shot_frameno_) * (1000 / SERVER_FRAME_RATE) <
GetCurrWeapon()->GetAttrValue(kHAT_FireRate)
GetCurrWeapon()->GetFireRate(this)
) {
return;
}
@ -1938,7 +1938,7 @@ void Creature::AutoLoadingBullet(bool manual)
}
if (p_weapon->weapon_idx != 0 &&
(p_weapon->ammo <= 0 ||
(manual && p_weapon->ammo < p_weapon->GetClipVolume()))
(manual && p_weapon->ammo < p_weapon->GetClipVolume(this)))
) {
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(p_weapon->meta->i->use_bullet());
if (bullet_meta &&
@ -1949,11 +1949,8 @@ void Creature::AutoLoadingBullet(bool manual)
if (on_loading_bullet) {
on_loading_bullet();
}
int duration_time = p_weapon->GetAttrValue(kHAT_ReloadTime) *
int duration_time = p_weapon->GetReloadTime(this) *
(1 + GetAbility()->GetAttrRate(kHAT_WeaponReloadTime));
#if 0
duration_time = 1000 * 5;
#endif
StartAction(AT_Reload,
duration_time,
p_weapon->weapon_id,

View File

@ -56,9 +56,9 @@ void FrameEvent::AddShot(CreatureWeakPtr& sender)
p.set_player_id(sender.Get()->GetUniId());
if (sender.Get()->second_weapon.meta) {
sender.Get()->second_weapon.ToPB(p.mutable_weapon());
sender.Get()->second_weapon.ToPB(sender.Get(), p.mutable_weapon());
} else {
sender.Get()->GetCurrWeapon()->ToPB(p.mutable_weapon());
sender.Get()->GetCurrWeapon()->ToPB(sender.Get(), p.mutable_weapon());
}
if (sender.Get()->IsCar()) {
p.set_hole(sender.Get()->shot_hole);

View File

@ -526,7 +526,7 @@ int HeroAI::GetAttackTimes()
{
Hero* myself = (Hero*)owner;
if (myself->GetCurrWeapon()) {
return std::min(ai_meta->i->attack_times(), myself->GetCurrWeapon()->GetClipVolume());
return std::min(ai_meta->i->attack_times(), myself->GetCurrWeapon()->GetClipVolume(myself));
} else {
return ai_meta->i->attack_times();
}

View File

@ -342,15 +342,6 @@ void Human::Initialize()
RecalcSelfCollider();
volume_ = meta->volume;
observers_.insert(this);
#if 0
for (auto& weapon : spec_weapons) {
if (weapon.meta) {
float hp = GetHP();
hp += weapon.meta ? weapon.GetAttrValue(kHAT_MaxHp) : 0;
SetHP(hp);
}
}
#endif
SetCurrWeapon(&weapons[0]);
SetOxygen(MetaMgr::Instance()->dive_oxygen_total);
}
@ -446,7 +437,7 @@ void Human::FillMFObjectLess(Room* room, Human* hum, cs::MFPlayerFull* full_data
p->set_chest(chest);
p->set_shoot_offset_x(shoot_offset.x);
p->set_shoot_offset_y(shoot_offset.y);
GetCurrWeapon()->ToPB(p->mutable_weapon());
GetCurrWeapon()->ToPB(this, p->mutable_weapon());
GetAbility()->FillMFAttrAdditionList(room, this, p->mutable_attr_addition());
if (GetCar()) {
p->set_car_uniid(GetCar()->car_uniid);
@ -478,7 +469,7 @@ void Human::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data
p->set_backpack(backpack);
p->set_helmet(helmet);
p->set_chest(chest);
GetCurrWeapon()->ToPB(p->mutable_weapon());
GetCurrWeapon()->ToPB(this, p->mutable_weapon());
p->set_energy_shield(energy_shield);
p->set_shoot_offset_x(shoot_offset.x);
p->set_shoot_offset_y(shoot_offset.y);
@ -1586,7 +1577,7 @@ void Human::FillMFActivePlayerData(cs::MFActivePlayerData* player_data)
}
for (auto& weapon : weapons) {
auto p = player_data->add_weapons();
weapon.ToPB(p);
weapon.ToPB(this, p);
}
for (auto& inv : GetInventoryData()) {
player_data->add_inventory(inv.num);
@ -3031,20 +3022,20 @@ void Human::ProcReloadAction()
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(p_weapon->meta->i->use_bullet());
if (bullet_meta) {
int ammo = p_weapon->ammo;
if (ammo < p_weapon->GetClipVolume()) {
if (ammo < p_weapon->GetClipVolume(this)) {
if (bullet_meta->i->_inventory_slot() >= 0 &&
bullet_meta->i->_inventory_slot() < IS_END) {
if (GetInventory(bullet_meta->i->_inventory_slot()) > 0) {
int add_num = 0;
if (GetInventory(bullet_meta->i->_inventory_slot()) <=
p_weapon->GetClipVolume() - ammo) {
p_weapon->GetClipVolume(this) - ammo) {
add_num = GetInventory(bullet_meta->i->_inventory_slot());
if (p_weapon->meta->i->reloadtype() == 1) {
add_num = 1;
}
DecInventory(bullet_meta->i->_inventory_slot(), add_num);
} else {
add_num = p_weapon->GetClipVolume() - ammo;
add_num = p_weapon->GetClipVolume(this) - ammo;
if (p_weapon->meta->i->reloadtype() == 1) {
add_num = 1;
}

View File

@ -1337,53 +1337,6 @@ namespace MetaData
}
}
void Dress::Init()
{
for (int j = 0; j < i->max_lv(); ++j) {
std::array<float, kHAT_End>& attrs = a8::FastAppend(level_attrs);
for (size_t k = 0; k < kHAT_End; ++k) {
attrs[k] = 0;
}
}
{
std::vector<std::string> strings;
a8::Split(i->attr_type(), strings, '|');
for (auto& str : strings) {
std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
if (strings2.size() != 3) {
A8_ABORT();
}
int attr_type = a8::XValue(strings2[0]);
int attr_level = a8::XValue(strings2[1]);
float attr_value = a8::XValue(strings2[2]).GetDouble();
if (attr_type < kHAT_End) {
if (attr_level >= 0 && attr_level < i->max_lv()) {
for (int j = 1; j < i->max_lv(); ++j) {
if (j % attr_type == 0) {
level_attrs[j][attr_type] = attr_value * (j / attr_level);
}
}
}
}
}
}
}
float Dress::GetAttrValue(int level, int attr_type)
{
if (level < 1) {
return 0;
}
if (level > (int)level_attrs.size()) {
return 0;
}
if (attr_type < kHAT_End) {
return level_attrs[level][attr_type];
}
return 0;
}
void RankReward::Init()
{
}

View File

@ -315,17 +315,6 @@ namespace MetaData
void Init();
};
struct Dress
{
const metatable::Dress* i = nullptr;
void Init();
float GetAttrValue(int level, int attr_type);
private:
std::vector<std::array<float, kHAT_End>> level_attrs;
};
struct RankReward
{
const metatable::RankReward* i = nullptr;

View File

@ -169,8 +169,6 @@ public:
std::list<MetaData::AirRaid> airraid_list;
std::list<metatable::AirLine> airline_meta_list;
std::list<MetaData::AirLine> airline_list;
std::list<metatable::Dress> dress_meta_list;
std::list<MetaData::Dress> dress_list;
std::list<metatable::Skill> skill_meta_list;
std::list<MetaData::Skill> skill_list;
std::list<metatable::SkillNumber> skill_number_meta_list;
@ -221,8 +219,6 @@ public:
std::map<std::string, std::list<metatable::MapLayerJson>> layer_meta_hash;
std::map<std::string, std::list<metatable::MapBlockJson>> block_meta_hash;
std::map<std::string, std::vector<MetaData::MapTplThing>> maptpl_hash;
std::map<int, MetaData::Dress*> dress_hash;
std::vector<MetaData::Dress*> dress_vec;
std::map<int, MetaData::Skill*> skill_hash;
std::map<int, MetaData::SkillNumber*> skill_number_hash;
std::map<int, MetaData::Buff*> buff_hash;
@ -282,7 +278,6 @@ public:
f8::ReadCsvMetaFile(res_path + "airraid@airraid.csv", airraid_meta_list);
f8::ReadCsvMetaFile(res_path + "airline@airline.csv", airline_meta_list);
f8::ReadJsonMetaFile(res_path + "maps.json", building_meta_list);
f8::ReadCsvMetaFile(res_path + "dress@dress.csv", dress_meta_list);
f8::ReadCsvMetaFile(res_path + "skill@skill.csv", skill_meta_list);
f8::ReadCsvMetaFile(res_path + "skillNumber@skillNumber.csv", skill_number_meta_list);
f8::ReadCsvMetaFile(res_path + "attr@attr.csv", attr_meta_list);
@ -843,13 +838,6 @@ private:
}
}
for (auto& meta : dress_meta_list) {
MetaData::Dress& item = a8::FastAppend(dress_list);
item.i = &meta;
dress_hash[item.i->id()] = &item;
dress_vec.push_back(&item);
}
for (auto& meta : attr_meta_list) {
MetaData::Attr& item = a8::FastAppend(attr_list);
item.i = &meta;
@ -1177,26 +1165,12 @@ MetaData::Attr* MetaMgr::GetAttrByName(const std::string& attr_name)
return itr != loader_->attr_name_hash.end() ? itr->second : nullptr;
}
MetaData::Dress* MetaMgr::GetDress(int dress_id)
{
auto itr = loader_->dress_hash.find(dress_id);
return itr != loader_->dress_hash.end() ? itr->second : nullptr;
}
MetaData::RankReward* MetaMgr::GetRankReward(int rank)
{
auto itr = loader_->rankreward_hash.find(rank);
return itr != loader_->rankreward_hash.end() ? itr->second : nullptr;
}
MetaData::Dress* MetaMgr::RandDress()
{
if (loader_->dress_vec.empty()) {
return nullptr;
}
return loader_->dress_vec[rand() % loader_->dress_vec.size()];
}
float MetaMgr::GetRankRewardParam(int rank)
{
auto itr = loader_->rankreward_hash.find(rank);

View File

@ -49,8 +49,6 @@ class MetaMgr : public a8::Singleton<MetaMgr>
MetaData::Buff* GetBuff(int buff_id);
MetaData::Attr* GetAttrById(int attr_id);
MetaData::Attr* GetAttrByName(const std::string& attr_name);
MetaData::Dress* GetDress(int dress_id);
MetaData::Dress* RandDress();
MetaData::RankReward* GetRankReward(int rank);
MetaData::GunTalentGrow* GetTalent(int talent_id, int talent_lv);
MetaData::PveGemini* GetPveGemini(int gemini_id);

View File

@ -61,7 +61,7 @@ void Player::Initialize()
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(GetCurrWeapon()->meta->i->use_bullet());
if (bullet_meta) {
int add_num = GetInventory(bullet_meta->i->_inventory_slot());
add_num = GetCurrWeapon()->GetClipVolume();
add_num = GetCurrWeapon()->GetClipVolume(this);
GetCurrWeapon()->ammo = add_num;
}
}
@ -81,7 +81,7 @@ void Player::Initialize()
weapon->weapon_lv = spec_weapon.weapon_lv;
weapon->meta = item_meta;
weapon->Recalc();
weapon->ammo = weapon->GetClipVolume();
weapon->ammo = weapon->GetClipVolume(this);
SetCurrWeapon(&weapons[GUN_SLOT1]);
}
}
@ -329,7 +329,7 @@ void Player::UpdateShot()
if (last_shot_frameno_ == 0 ||
(
(room->GetFrameNo() - last_shot_frameno_) * (1000 / SERVER_FRAME_RATE)) >=
p_weapon->GetAttrValue(kHAT_FireRate)
p_weapon->GetFireRate(this)
) {
Shot();
}

View File

@ -3105,34 +3105,6 @@ void Room::AddPlayerPostProc(Player* hum)
}
}
}
#ifdef DEBUG
xtimer.AddRepeatTimerAndAttach
(SERVER_FRAME_RATE * 5,
a8::XParams()
.SetSender(hum),
[] (const a8::XParams& param)
{
Human* hum = (Human*)param.sender.GetUserData();
std::string debugmsg = a8::Format("weapon_id:%d weapon_lv:%d atk:%f fire_rate:%f "
"volume:%d maxhp:%f hp:%f curr_hp:%f curr_max_hp:%f "
"base_reload_time:%f grow_reload_time:%f finaly_reload_time:%f",
{
hum->GetCurrWeapon()->weapon_id,
hum->GetCurrWeapon()->weapon_lv,
hum->GetCurrWeapon()->GetAttrValue(kHAT_Atk),
hum->GetCurrWeapon()->GetAttrValue(kHAT_FireRate),
hum->GetCurrWeapon()->GetAttrValue(kHAT_Volume),
hum->GetCurrWeapon()->GetAttrValue(kHAT_MaxHp),
hum->GetCurrWeapon()->GetAttrValue(kHAT_Hp),
hum->GetHP(),
hum->GetMaxHP(),
hum->GetCurrWeapon()->meta->i->reload_time(),
hum->GetCurrWeapon()->GetAttrValue(kHAT_ReloadTime)
});
hum->SendDebugMsg(debugmsg);
},
&hum->xtimer_attacher.timer_list_);
#endif
}
void Room::AddToEntityHash(Entity* entity)

View File

@ -14,13 +14,13 @@ void Weapon::Clear()
bullet_meta = nullptr;
}
void Weapon::ToPB(cs::MFWeapon* pb_obj)
void Weapon::ToPB(Creature* c, cs::MFWeapon* pb_obj)
{
pb_obj->set_weapon_uniid(a8::XValue(weapon_uniid).GetString());
pb_obj->set_weapon_id(weapon_id);
pb_obj->set_weapon_lv(weapon_lv);
pb_obj->set_ammo(ammo);
pb_obj->set_volume(GetClipVolume());
pb_obj->set_volume(GetClipVolume(c));
}
void Weapon::Recalc()
@ -28,43 +28,17 @@ void Weapon::Recalc()
bullet_meta = MetaMgr::Instance()->GetEquip(meta->i->use_bullet());
}
int Weapon::GetClipVolume()
{
return GetAttrValue(kHAT_Volume);
}
float Weapon::GetAttrValue(HumanAttrType_e attr_type)
{
if (!meta) {
return 0;
}
switch (attr_type) {
case kHAT_Atk:
{
return meta->i->atk();
}
break;
case kHAT_FireRate:
{
return meta->i->fire_rate();
}
break;
case kHAT_Volume:
int Weapon::GetClipVolume(Creature* c)
{
return meta->i->clip_volume();
}
break;
case kHAT_MaxHp:
int Weapon::GetFireRate(Creature* c)
{
return meta->i->max_hp();
return meta->i->fire_rate();
}
break;
case kHAT_ReloadTime:
int Weapon::GetReloadTime(Creature* c)
{
return meta->i->reload_time();
}
break;
default:
return 0;
}
}

View File

@ -3,7 +3,6 @@
namespace cs
{
class MFWeapon;
class MFSkin;
}
namespace MetaData
@ -11,6 +10,7 @@ namespace MetaData
struct Equip;
}
class Creature;
struct Weapon
{
long long weapon_uniid = 0;
@ -22,8 +22,9 @@ struct Weapon
MetaData::Equip* bullet_meta = nullptr;
void Clear();
void ToPB(cs::MFWeapon* pb_obj);
void ToPB(Creature* c, cs::MFWeapon* pb_obj);
void Recalc();
int GetClipVolume();
float GetAttrValue(HumanAttrType_e attr_type);
int GetClipVolume(Creature* c);
int GetFireRate(Creature* c);
int GetReloadTime(Creature* c);
};