This commit is contained in:
aozhiwei 2019-11-20 16:14:13 +08:00
parent a36859194e
commit 3351e7d8ed
8 changed files with 1 additions and 416 deletions

View File

@ -36,9 +36,6 @@ void Android::Update(int delta_time)
pos = room->plane.curr_pos;
room->grid_service.MoveHuman(this);
}
if (action_type != AT_None) {
UpdateAction();
}
ai->Update(delta_time);
}

View File

@ -84,42 +84,6 @@ void FrameEvent::AddBullet(Human* hum, a8::Vec2 born_pos, a8::Vec2 dir, float fl
}
p.set_fly_distance(fly_distance);
}
{
int bullet_idx = bullets_.size() - 1;
for (auto& cell : hum->grid_list) {
for (auto& hum : cell->human_list) {
hum->bullets_.push_back(bullet_idx);
}
}
}
}
void FrameEvent::AddBulletNumChg(Human* hum)
{
chged_bullet_nums_.push_back(hum);
int idx = chged_bullet_nums_.size() - 1;
hum->chged_bullet_nums_.push_back(idx);
}
void FrameEvent::AddTankBulletNumChg(Human* hum)
{
chged_tank_bullet_nums_.push_back(hum);
int idx = chged_tank_bullet_nums_.size() - 1;
hum->chged_tank_bullet_nums_.push_back(idx);
}
void FrameEvent::AddTankOilValueChg(Human* hum)
{
chged_tank_oil_value_.push_back(hum);
int idx = chged_tank_oil_value_.size() - 1;
hum->chged_tank_oil_value_.push_back(idx);
}
void FrameEvent::AddTankOilMaxChg(Human* hum)
{
chged_tank_oil_max_.push_back(hum);
int idx = chged_tank_oil_max_.size() - 1;
hum->chged_tank_oil_max_.push_back(idx);
}
void FrameEvent::AddHpChg(Human* hum)

View File

@ -51,80 +51,6 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum)
}
}
}
for (size_t idx : hum->bullets_) {
if (idx < room->frame_event.bullets_.size()) {
auto& tuple = room->frame_event.bullets_[idx];
if (hum->CanSee(std::get<0>(tuple))) {
*msg->add_bullets() = std::get<1>(tuple);
}
}
}
for (size_t idx : hum->explosions_) {
if (idx < room->frame_event.explosions_.size()) {
auto& tuple = room->frame_event.explosions_[idx];
if (hum->CanSee(std::get<0>(tuple))) {
*msg->add_explosions() = std::get<1>(tuple);
}
}
}
for (size_t idx : hum->smokes_) {
if (idx < room->frame_event.smokes_.size()) {
auto& tuple = room->frame_event.smokes_[idx];
if (hum->CanSee(std::get<0>(tuple))) {
*msg->add_smokes() = std::get<1>(tuple);
}
}
}
for (size_t idx : hum->emotes_) {
if (idx < room->frame_event.emotes_.size()) {
auto& tuple = room->frame_event.emotes_[idx];
if (hum->CanSee(std::get<0>(tuple))) {
*msg->add_emotes() = std::get<1>(tuple);
}
}
}
for (size_t idx : hum->chged_bullet_nums_) {
if (idx < room->frame_event.chged_bullet_nums_.size()) {
Human* target = room->frame_event.chged_bullet_nums_[idx];
if (target->curr_weapon) {
auto p = msg->add_chged_property_list();
p->set_obj_id(target->entity_uniid);
p->set_property_type(kPropBulletNum);
p->set_value(target->curr_weapon->ammo);
}
}
}
for (size_t idx : hum->chged_tank_bullet_nums_) {
if (idx < room->frame_event.chged_tank_bullet_nums_.size()) {
Human* target = room->frame_event.chged_tank_bullet_nums_[idx];
if (target->curr_weapon) {
auto p = msg->add_chged_property_list();
p->set_obj_id(target->entity_uniid);
p->set_property_type(kPropTankBulletNum);
p->set_value(target->tank_weapon.ammo);
}
}
}
for (size_t idx : hum->chged_tank_oil_max_) {
if (idx < room->frame_event.chged_tank_oil_max_.size()) {
Human* target = room->frame_event.chged_tank_oil_max_[idx];
auto p = msg->add_chged_property_list();
p->set_obj_id(target->entity_uniid);
p->set_property_type(kPropTankOil);
p->set_property_subtype(1);
p->set_value(target->tank_oil_max);
}
}
for (size_t idx : hum->chged_tank_oil_value_) {
if (idx < room->frame_event.chged_tank_oil_value_.size()) {
Human* target = room->frame_event.chged_tank_oil_value_[idx];
auto p = msg->add_chged_property_list();
p->set_obj_id(target->entity_uniid);
p->set_property_type(kPropTankOil);
p->set_property_subtype(0);
p->set_value(target->tank_oil_value);
}
}
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

@ -76,9 +76,7 @@ float Human::GetSpeed()
if (shot_hold) {
if (curr_weapon->weapon_idx == GUN_SLOT1 ||
curr_weapon->weapon_idx == GUN_SLOT2) {
if (action_type != AT_Reload) {
return meta->i->shot_speed();
}
return meta->i->shot_speed();
}
}
return meta->i->move_speed() + buff.speed;
@ -465,70 +463,6 @@ void Human::SyncAroundPlayers(const char* file, int line, const char* func)
}
}
void Human::AutoLoadingBullet(bool manual)
{
if (curr_weapon->weapon_idx != 0 &&
(curr_weapon->ammo <= 0 ||
(manual && curr_weapon->ammo < curr_weapon->GetClipVolume()))
) {
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
if (bullet_meta &&
bullet_meta->i->_inventory_slot() >= 0 &&
bullet_meta->i->_inventory_slot() < (int)inventory_.size()
) {
if (GetInventory(bullet_meta->i->_inventory_slot()) > 0) {
StartAction(AT_Reload,
curr_weapon->meta->i->reload_time(),
curr_weapon->weapon_id,
curr_weapon->weapon_idx);
}
}
return;
}
}
void Human::StartAction(ActionType_e action_type,
int action_duration,
int item_id,
int target_id)
{
if (this->action_type == action_type &&
this->action_item_id == item_id &&
this->action_target_id == target_id) {
return;
}
this->action_type = action_type;
this->action_frameno = room->frame_no;
this->action_duration = action_duration;
this->action_item_id = item_id;
this->action_target_id = target_id;
need_sync_active_player = true;
}
void Human::CancelAction()
{
if (action_type == AT_Relive) {
Entity* entity = room->GetEntityByUniId(action_target_id);
if (entity->entity_type != ET_Player) {
Human* hum = (Human*)entity;
if (hum->action_type == AT_Rescue) {
hum->CancelAction();
}
}
}
ResetAction();
}
void Human::ResetAction()
{
action_type = AT_None;
action_duration = 0;
action_frameno = 0;
action_item_id = 0;
action_target_id = 0;
need_sync_active_player = true;
}
void Human::FillSMGameOver(cs::SMGameOver& msg)
{
if (stats.rank <= 0) {
@ -1154,18 +1088,6 @@ void Human::OnGridListChange(std::set<GridCell*>& old_grid_list,
void Human::FillMFActivePlayerData(cs::MFActivePlayerData* player_data)
{
{
player_data->set_action_type(action_type);
if (action_type != AT_None) {
int duration = std::max(0,
action_duration -
(int)((room->frame_no - action_frameno) * 1.0f / SERVER_FRAME_RATE) * 1000
);
player_data->set_action_item_id(action_item_id);
player_data->set_action_duration(duration);
player_data->set_action_target_id(action_target_id);
}
}
skin.ToPB(player_data->mutable_skin());
player_data->set_backpack(backpack);
player_data->set_helmet(helmet);
@ -1557,142 +1479,6 @@ void Human::SendRollMsg(const std::string& roll_msg)
);
}
void Human::UpdateAction()
{
int duration = std::max(0,
action_duration -
(int)((room->frame_no - action_frameno) * 1.0f / SERVER_FRAME_RATE) * 1000
);
if (duration <= 0) {
switch (action_type) {
case AT_Reload:
{
if (curr_weapon->weapon_idx == action_target_id &&
curr_weapon->weapon_id == action_item_id &&
curr_weapon->weapon_idx != 0) {
MetaData::Equip* bullet_meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
if (bullet_meta) {
int ammo = curr_weapon->ammo;
if (ammo < curr_weapon->GetClipVolume()) {
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()) <=
curr_weapon->GetClipVolume() - ammo) {
add_num = GetInventory(bullet_meta->i->_inventory_slot());
DecInventory(bullet_meta->i->_inventory_slot(), add_num);
} else {
add_num = curr_weapon->GetClipVolume() - ammo;
DecInventory(bullet_meta->i->_inventory_slot(), add_num);
}
curr_weapon->ammo += add_num;
need_sync_active_player = true;;
}
}
}
}
}
}
break;
case AT_UseItem:
{
switch (action_item_id) {
case IS_HEALTHKIT:
{
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;
DecInventory(item_meta->i->_inventory_slot(), 1);
need_sync_active_player = true;
SyncAroundPlayers(__FILE__, __LINE__, __func__);
}
}
}
break;
case IS_PAIN_KILLER:
{
MetaData::Equip* item_meta = MetaMgr::Instance()->GetEquipBySlotId(action_item_id);
if (item_meta){
if (GetInventory(item_meta->i->_inventory_slot()) > 0) {
if (pain_killer_timer) {
int passed_time = (room->frame_no - pain_killer_frameno) * FRAME_RATE_MS;
int left_time = std::max(0, pain_killer_lastingtime * 1000 - passed_time);
int anodyne_max_time = MetaMgr::Instance()->GetSysParamAsInt("anodyne_max_time");
left_time = std::min(left_time, anodyne_max_time * 1000);
pain_killer_lastingtime += std::min(item_meta->i->time() * 1000, anodyne_max_time * 1000 - left_time) / 1000;
need_sync_active_player = true;
} else {
pain_killer_frameno = room->frame_no;
pain_killer_lastingtime = item_meta->i->time();
pain_killer_timer = room->xtimer.AddRepeatTimerAndAttach(
SERVER_FRAME_RATE,
a8::XParams()
.SetSender(this)
.SetParam1(item_meta->i->heal()),
[] (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;
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);
hum->pain_killer_timer = nullptr;
}
},
&xtimer_attacher.timer_list_
);
}
DecInventory(item_meta->i->_inventory_slot(), 1);
need_sync_active_player = true;
}
}
}
break;
default:
{
}
break;
}
}
break;
case AT_Relive:
{
Entity* entity = room->GetEntityByUniId(action_target_id);
if (entity->entity_type != ET_Player) {
return;
}
Human* hum = (Human*)entity;
if (hum->action_type == AT_Rescue) {
hum->CancelAction();
return;
}
if (!hum->dead && hum->downed) {
hum->health = MetaMgr::Instance()->GetSysParamAsInt("downed_relive_recover_hp");
hum->downed = false;
if (hum->downed_timer) {
room->xtimer.DeleteTimer(hum->downed_timer);
hum->downed_timer = nullptr;
}
++hum->stats.rescue_member;
}
hum->SyncAroundPlayers(__FILE__, __LINE__, __func__);
}
break;
default:
break;
}
ResetAction();
}
}
void Human::SendUIUpdate()
{
cs::SMUiUpdate notifymsg;
@ -1872,30 +1658,9 @@ void Human::ClearFrameData()
if (!shots_.empty()) {
shots_.clear();
}
if (!bullets_.empty()) {
bullets_.clear();
}
if (!explosions_.empty()) {
explosions_.clear();
}
if (!smokes_.empty()) {
smokes_.clear();
}
if (!emotes_.empty()) {
emotes_.clear();
}
if (!chged_bullet_nums_.empty()) {
chged_bullet_nums_.clear();
}
if (!chged_tank_bullet_nums_.empty()) {
chged_tank_bullet_nums_.clear();
}
if (!chged_tank_oil_value_.empty()){
chged_tank_oil_value_.clear();
}
if (!chged_tank_oil_max_.empty()){
chged_tank_oil_max_.clear();
}
if (!chged_hps_.empty()) {
chged_hps_.clear();
}
@ -2095,7 +1860,6 @@ void Human::ProcLootSkin(Loot* entity, MetaData::Equip* item_meta)
}
a8::XParams* mutable_param = hum->room->xtimer.MutableParams(hum->room->xtimer.GetRunningTimer());
if (std::abs(mutable_param->param2.GetDouble() - (double)hum->tank_oil_value) > 0.1f) {
hum->room->frame_event.AddTankOilValueChg(hum);
mutable_param->param2 = hum->tank_oil_value;
}
};
@ -2132,9 +1896,6 @@ void Human::ProcLootSkin(Loot* entity, MetaData::Equip* item_meta)
SyncAroundPlayers(__FILE__, __LINE__, __func__);
room->TakeOnCarObject(skin_tank.tank_uniid);
room->NotifyUiUpdate();
room->frame_event.AddTankBulletNumChg(this);
room->frame_event.AddTankOilMaxChg(this);
room->frame_event.AddTankOilValueChg(this);
room->xtimer.AddRepeatTimerAndAttach(
SERVER_FRAME_RATE,
a8::XParams()
@ -2229,14 +1990,6 @@ void Human::OnDie()
{
room->OnHumanDie(this);
SyncAroundPlayers(__FILE__, __LINE__, __func__);
if (team_members) {
for (auto& hum : *team_members) {
if (hum != this && hum->action_type == AT_Relive &&
hum->action_target_id == entity_uniid) {
hum->CancelAction();
}
}
}
{
std::set<Human*> over_humans;
if (!leave_) {

View File

@ -65,11 +65,6 @@ class Human : public Entity
bool disconnected = false;
int anim_type = 0;
int anim_seq = 0;
ActionType_e action_type = AT_None;
long long action_frameno = 0;
int action_duration = 0;
int action_item_id = 0;
int action_target_id = 0;
Skin skin_jlf;
Skin skin_tank;
int backpack = 0;
@ -151,13 +146,6 @@ class Human : public Entity
float GetMaxHP();
void UpdatePoisoning();
void SyncAroundPlayers(const char* file, int line, const char* func);
void AutoLoadingBullet(bool manual = false);
void StartAction(ActionType_e action_type,
int action_duration,
int item_id,
int target_id);
void CancelAction();
void ResetAction();
void BeKill(int killer_id, const std::string& killer_name, int weapon_id);
void DecHP(float dec_hp, int killer_id, const std::string& killer_name, int weapon_id);
void AddToNewObjects(Entity* entity);
@ -203,7 +191,6 @@ class Human : public Entity
void FollowTarget(Human* target);
void SendDebugMsg(const std::string& debug_msg);
void SendRollMsg(const std::string& roll_msg);
void UpdateAction();
void SendUIUpdate();
void SendWxVoip();
int GetWeaponConfigLv(int weapon_id);
@ -252,12 +239,9 @@ protected:
std::set<int> out_objects;
std::vector<int> shots_;
std::vector<int> emotes_;
std::vector<int> bullets_;
std::vector<int> smokes_;
std::vector<int> explosions_;
std::set<Human*> observers_;
std::vector<int> chged_bullet_nums_;
std::vector<int> chged_tank_bullet_nums_;
std::vector<int> chged_tank_oil_value_;
std::vector<int> chged_tank_oil_max_;
std::vector<int> chged_hps_;

View File

@ -155,7 +155,6 @@ void Obstacle::Explosion(Bullet* bullet)
}
}//end for
}
a8::Vec2 bomb_pos = pos;
for (auto& target : objects) {
switch (target->entity_type) {
case ET_Player:

View File

@ -63,9 +63,6 @@ void Player::Update(int delta_time)
void Player::UpdateMove()
{
if (action_type == AT_Relive) {
CancelAction();
}
if (dead || a8::HasBitFlag(status, HS_Fly)) {
moving = false;
moved_frames = 0;
@ -152,12 +149,6 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
if (moving) {
moved_frames = 0;
}
shot_start = msg.shot_start();
shot_hold = msg.shot_hold();
fly_distance = std::min(200.0f, msg.fly_distance());
if (!shot_hold) {
series_shot_frames = 0;
}
last_seq_id = msg.seq();
if (msg.has_spectate()) {
spectate = true;

View File

@ -181,8 +181,6 @@ message MFPlayerFull
optional bool disconnected = 9; //
optional int32 anim_type = 10; //
optional int32 anim_seq = 11; //
//optional int32 action_type = 12; //0: none 1:reload 2:useitem 3:relive 4: rescue
//optional int32 action_duration = 22; //
optional MFSkin skin = 13; //id
optional int32 backpack = 14; //
optional int32 helmet = 16; //
@ -418,11 +416,6 @@ message MFObjectFull
//()
message MFActivePlayerData
{
optional int32 action_type = 3; //0: none 1:reload 2:useitem 3:relive 4: rescue
optional int32 action_duration = 5; //
optional int32 action_item_id = 6;
optional int32 action_target_id = 7;
optional MFSkin skin = 30; //id
optional int32 backpack = 31; //
optional int32 helmet = 32; //
@ -666,30 +659,8 @@ message CMMove
optional MFVector2D move_dir = 24; //-
optional MFVector2D attack_dir = 20; //()
optional bool shot_start = 6; //-
optional bool shot_hold = 7; //-
optional bool reload = 8; //
optional float fly_distance = 12; //()
optional int32 select_weapon = 10; //()
optional int32 drop_weapon = 11; //
optional bool cancel_action = 26; //(使)
optional int32 use_item_idx = 22; //使0-16
optional int32 use_scope = 25; //使 0-4
optional bool interaction = 9; //
repeated int32 interaction_objids = 23; //id列表
optional bool use_skill = 29; //使
optional bool spectate = 30; //
optional int32 emote = 31; //id
optional bool jump = 32; //
optional bool get_down = 33; //
}
//