添加拾取处理

This commit is contained in:
aozhiwei 2019-03-29 12:00:16 +08:00
parent 23e9ef0af5
commit 8ade050841
5 changed files with 29 additions and 10 deletions

View File

@ -16,6 +16,7 @@ class Loot : public Entity
MetaData::Equip* meta = nullptr;
int item_id = 0;
int count = 0;
bool pickuped = false;
Loot();
virtual ~Loot() override;

View File

@ -11,6 +11,7 @@
#include "bullet.h"
#include "obstacle.h"
#include "building.h"
#include "loot.h"
const int F_del_objids = 2;
const int F_full_objects = 3;
@ -59,7 +60,7 @@ void Player::Update(int delta_time)
if (moving) {
UpdateMove();
}
if (updated_times % 2 == 0) {
if (room->frame_no % 2 == 0) {
if (shot_start || shot_hold) {
UpdateShot();
}
@ -169,7 +170,7 @@ void Player::ProcInteraction()
break;
case ET_Loot:
{
LootInteraction((Loot*)entity);
}
break;
default:
@ -202,9 +203,19 @@ void Player::ObstacleInteraction(Obstacle* entity)
pair.second->last_collision_door = nullptr;
}
}
} else {
}
}
void Player::LootInteraction(Loot* entity)
{
if (entity->pickuped) {
return;
}
entity->pickuped = true;
room->AddDeletedObject(entity->entity_uniid);
}
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
{
bool has_move_dir = msg.has_move_dir();

View File

@ -14,6 +14,7 @@ namespace cs
}
class Room;
class Loot;
class Obstacle;
class Player : public Human
{
@ -53,6 +54,7 @@ class Player : public Human
void Shot();
void ProcInteraction();
void ObstacleInteraction(Obstacle* entity);
void LootInteraction(Loot* entity);
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
void _CMDropItem(f8::MsgHdr& hdr, const cs::CMDropItem& msg);

View File

@ -19,18 +19,19 @@ const int ANDROID_NUM = 0;
void Room::Update(int delta_time)
{
elapsed_time_ += delta_time;
++frame_no;
while (elapsed_time_ >= 50) {
ResetFrameData();
int i = 0;
if (frame_no % 2 == 0) {
ResetFrameData();
}
for (auto& pair : moveable_hash_) {
pair.second->Update(50);
pair.second->updated_times++;
++i;
assert(i < 1000);
}
ClearDeletedObjects();
ProcAddedObjects();
if (frame_no % 2 == 0) {
ClearDeletedObjects();
ProcAddedObjects();
}
++frame_no;
elapsed_time_ -= 50;
}
}
@ -372,6 +373,10 @@ void Room::ClearDeletedObjects()
uniid_hash_.erase(entity->entity_uniid);
moveable_hash_.erase(entity->entity_uniid);
}
for (auto& pair : human_hash_) {
pair.second->new_objects.erase(entity);
pair.second->part_objects.erase(entity);
}
delete entity;
}
}

View File

@ -140,7 +140,7 @@ message MFPlayerFull
optional int32 anim_seq = 11; //
optional int32 action_type = 12; //0: none 1:reload 2:useitem 3:relive
optional int32 skin = 13; //id
//backpack
optional int32 backpack = 14; //
optional int32 helmet = 16; //
optional int32 chest = 17; //
optional int32 weapon = 18; //