shot ok
This commit is contained in:
parent
122c6286a0
commit
89887d287a
@ -60,7 +60,7 @@ static void SavePerfLog()
|
||||
|
||||
void App::Init(int argc, char* argv[])
|
||||
{
|
||||
#if 1
|
||||
#if 0
|
||||
{
|
||||
Vector2D v1(1, 1);
|
||||
Vector2D v2 = v1.Rotate(-0.25);
|
||||
@ -359,13 +359,11 @@ void App::ProcessGameGateMsg(f8::MsgHdr& hdr)
|
||||
break;
|
||||
case HID_Player:
|
||||
{
|
||||
#if 0
|
||||
Player* hum = PlayerMgr::Instance()->GetPlayerBySocket(hdr.socket_handle);
|
||||
if (hum) {
|
||||
hdr.hum = hum;
|
||||
ProcessNetMsg(handler, hum, hdr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -45,8 +45,6 @@ class Human : public Entity
|
||||
|
||||
HumanFrameData frame_data;
|
||||
|
||||
bool moving = false;
|
||||
|
||||
std::set<Human*> my_seen_players;
|
||||
std::set<Human*> seen_me_players;
|
||||
std::set<Human*> new_players;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "room.h"
|
||||
#include "metamgr.h"
|
||||
#include "movement.h"
|
||||
#include "bullet.h"
|
||||
|
||||
const int F_del_objids = 2;
|
||||
const int F_full_objects = 3;
|
||||
@ -51,7 +52,13 @@ void Player::Initialize()
|
||||
void Player::Update(int delta_time)
|
||||
{
|
||||
movement->Update(delta_time);
|
||||
if (moving) {
|
||||
UpdateMove();
|
||||
}
|
||||
if (updated_times % 2 == 0) {
|
||||
if (shot_start || shot_hold) {
|
||||
UpdateShot();
|
||||
}
|
||||
MakeUpdateMsg();
|
||||
SendNotifyMsg(*update_msg);
|
||||
{
|
||||
@ -62,9 +69,93 @@ void Player::Update(int delta_time)
|
||||
}
|
||||
}
|
||||
|
||||
void Player::UpdateMove()
|
||||
{
|
||||
++moved_frames;
|
||||
if (moved_frames > 4) {
|
||||
moving = false;
|
||||
moved_frames = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::UpdateShot()
|
||||
{
|
||||
if (shot_start) {
|
||||
shot_start = false;
|
||||
Shot();
|
||||
return;
|
||||
}
|
||||
if (shot_hold) {
|
||||
++series_shot_frames;
|
||||
if (series_shot_frames > 4) {
|
||||
shot_hold = false;
|
||||
series_shot_frames = 0;
|
||||
Shot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::Shot()
|
||||
{
|
||||
if (!weapon_meta) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
cs::MFShot* shot = room->frame_data.shots.Add();
|
||||
shot->set_player_id(entity_uniid);
|
||||
shot->set_weapon_id(weapon_meta->i->id());
|
||||
shot->set_offhand(true);
|
||||
shot->set_bullskin(10001);
|
||||
}
|
||||
{
|
||||
cs::MFBullet* bullet = room->frame_data.bullets.Add();
|
||||
bullet->set_player_id(entity_uniid);
|
||||
bullet->set_bullet_id(weapon_meta->i->use_bullet());
|
||||
pos.ToPB(bullet->mutable_pos());
|
||||
attack_dir.ToPB(bullet->mutable_dir());
|
||||
bullet->set_bulletskin(10001);
|
||||
}
|
||||
{
|
||||
Bullet* bullet = new Bullet();
|
||||
bullet->player = this;
|
||||
bullet->room = room;
|
||||
bullet->gun_meta = weapon_meta;
|
||||
bullet->meta = MetaMgr::Instance()->GetEquip(weapon_meta->i->use_bullet());
|
||||
bullet->pos = pos;
|
||||
bullet->dir = attack_dir;
|
||||
bullet->born_pos = pos;
|
||||
bullet->born_dir = attack_dir;
|
||||
bullet->entity_uniid = bullet->room->AllocUniid();
|
||||
bullet->Initialize();
|
||||
room->AddBullet(bullet);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
||||
{
|
||||
|
||||
if (msg.has_move_dir()) {
|
||||
move_dir.FromPB(&msg.move_dir());
|
||||
move_dir.Normalize();
|
||||
}
|
||||
moving = msg.has_move_dir();
|
||||
if (msg.has_attack_dir()) {
|
||||
attack_dir.FromPB(&msg.attack_dir());
|
||||
attack_dir.Normalize();
|
||||
} else {
|
||||
if (moving) {
|
||||
attack_dir = move_dir;
|
||||
}
|
||||
}
|
||||
if (moving) {
|
||||
moved_frames = 0;
|
||||
}
|
||||
shot_start = msg.shot_start();
|
||||
shot_hold = msg.shot_hold();
|
||||
if (shot_hold) {
|
||||
series_shot_frames = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::_CMDropItem(f8::MsgHdr& hdr, const cs::CMDropItem& msg)
|
||||
@ -84,7 +175,18 @@ void Player::_CMSpectate(f8::MsgHdr& hdr, const cs::CMSpectate& msg)
|
||||
|
||||
void Player::_CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg)
|
||||
{
|
||||
|
||||
cs::SMVoiceNotify notifymsg;
|
||||
notifymsg.set_mode(msg.mode());
|
||||
notifymsg.set_account_id(account_id);
|
||||
notifymsg.set_msg(msg.msg());
|
||||
auto send_func = [] (Player* hum, a8::XParams& param)
|
||||
{
|
||||
cs::SMVoiceNotify* msg = (cs::SMVoiceNotify*)param.sender.GetUserData();
|
||||
hum->SendNotifyMsg(*msg);
|
||||
};
|
||||
room->TouchPlayerList(a8::XParams()
|
||||
.SetSender(¬ifymsg),
|
||||
send_func);
|
||||
}
|
||||
|
||||
void Player::FillMFPlayerData(cs::MFPlayerData* player_data)
|
||||
|
@ -28,6 +28,13 @@ class Player : public Human
|
||||
bool use_touch = false;
|
||||
std::string avatar_url;
|
||||
|
||||
bool moving = false;
|
||||
int moved_frames = 0;
|
||||
|
||||
bool shot_start = false;
|
||||
bool shot_hold = false;
|
||||
int series_shot_frames = 0;
|
||||
|
||||
template <typename T>
|
||||
void SendNotifyMsg(T& msg)
|
||||
{
|
||||
@ -38,6 +45,9 @@ class Player : public Human
|
||||
virtual ~Player() override;
|
||||
virtual void Initialize() override;
|
||||
virtual void Update(int delta_time) override;
|
||||
void UpdateMove();
|
||||
void UpdateShot();
|
||||
void Shot();
|
||||
|
||||
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
||||
void _CMDropItem(f8::MsgHdr& hdr, const cs::CMDropItem& msg);
|
||||
|
@ -19,7 +19,7 @@ void PlayerMgr::Update()
|
||||
|
||||
}
|
||||
|
||||
Player* PlayerMgr::GetPlayerSocket(int socket)
|
||||
Player* PlayerMgr::GetPlayerBySocket(int socket)
|
||||
{
|
||||
auto itr = socket_hash_.find(socket);
|
||||
return itr != socket_hash_.end() ? itr->second : nullptr;
|
||||
|
@ -20,7 +20,7 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
|
||||
void UnInit();
|
||||
void Update();
|
||||
|
||||
Player* GetPlayerSocket(int socket);
|
||||
Player* GetPlayerBySocket(int socket);
|
||||
Player* CreatePlayerByCMJoin(unsigned short obj_uniid, const cs::CMJoin& msg);
|
||||
|
||||
private:
|
||||
|
@ -247,3 +247,16 @@ void Room::ClearDeletedObjects()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Room::TouchPlayerList(a8::XParams param,
|
||||
std::function<void (Player*, a8::XParams&)> func)
|
||||
{
|
||||
if (!func) {
|
||||
return;
|
||||
}
|
||||
for (auto& pair : accountid_hash_) {
|
||||
if (pair.second) {
|
||||
func(pair.second, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,8 @@ public:
|
||||
void AddDeletedObject(unsigned short obj_uniid);
|
||||
void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
|
||||
void ResetFrameData();
|
||||
void TouchPlayerList(a8::XParams param,
|
||||
std::function<void (Player*, a8::XParams&)> func);
|
||||
|
||||
private:
|
||||
void ClearDeletedObjects();
|
||||
|
@ -16,6 +16,12 @@ void Vector2D::ToPB(cs::MFVector2D* pb_obj)
|
||||
pb_obj->set_y(y);
|
||||
}
|
||||
|
||||
void Vector2D::FromPB(const cs::MFVector2D* pb_obj)
|
||||
{
|
||||
x = pb_obj->x();
|
||||
y = pb_obj->y();
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::Normalize()
|
||||
{
|
||||
Eigen::Vector2f v(x, y);
|
||||
|
@ -22,6 +22,7 @@ struct Vector2D
|
||||
Vector2D(float _x = 0.0f, float _y = 0.0f):x(_x), y(_y) {};
|
||||
|
||||
void ToPB(cs::MFVector2D* pb_obj);
|
||||
void FromPB(const cs::MFVector2D* pb_obj);
|
||||
Vector2D& Normalize();
|
||||
|
||||
bool operator == (const Vector2D& b) const;
|
||||
|
@ -479,8 +479,8 @@ message CMMove
|
||||
optional MFVector2D move_dir = 24; //移动-方向
|
||||
optional MFVector2D attack_dir = 20; //攻击方向(朝向)
|
||||
|
||||
optional bool shoot_start = 6; //射击-开始
|
||||
optional bool shoot_hold = 7; //射击-一直按着
|
||||
optional bool shot_start = 6; //射击-开始
|
||||
optional bool shot_hold = 7; //射击-一直按着
|
||||
optional bool reload = 8; //装弹
|
||||
|
||||
optional bool equip_primary = 10; //装备1
|
||||
@ -530,7 +530,7 @@ message CMSpectate
|
||||
message CMVoice
|
||||
{
|
||||
optional int32 mode = 1; //模式
|
||||
optional string msg = 2; //语音内容
|
||||
optional bytes msg = 2; //语音内容
|
||||
}
|
||||
|
||||
//endcmmsg
|
||||
@ -634,5 +634,5 @@ message SMVoiceNotify
|
||||
{
|
||||
optional int32 mode = 1; //模式
|
||||
optional string account_id = 2; //唯一id
|
||||
optional string msg = 3; //语音内容
|
||||
optional bytes msg = 3; //语音内容
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user