2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 25.05.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SHOOTER_CLIENT_H
|
|
|
|
#define SHOOTER_CLIENT_H
|
|
|
|
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "engine/network/ClientUDP.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
#include "Player.h"
|
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class Client final : public ClientUDP {
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
2021-10-26 09:50:59 +03:00
|
|
|
std::string _lastEvent;
|
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
std::map<sf::Uint16, std::shared_ptr<Player>> _players{};
|
2021-10-02 20:36:07 +03:00
|
|
|
std::shared_ptr<Player> _player;
|
2021-09-14 13:47:53 +03:00
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
std::function<void(sf::Uint16)> _spawnPlayerCallBack;
|
|
|
|
std::function<void(sf::Uint16)> _removePlayerCallBack;
|
2021-10-12 17:12:47 +03:00
|
|
|
std::function<void(const Vec3D&, const Vec3D&)> _addFireTraceCallBack;
|
|
|
|
std::function<void(const std::string&, const Vec3D&)> _addBonusCallBack;
|
2021-10-17 10:21:10 +03:00
|
|
|
std::function<void(const ObjectNameTag&)> _removeBonusCallBack;
|
2021-10-18 18:30:02 +03:00
|
|
|
std::function<void(const std::string&, sf::Uint16)> _changeEnemyWeaponCallBack;
|
2021-09-13 15:53:43 +03:00
|
|
|
public:
|
2021-10-03 07:52:30 +03:00
|
|
|
explicit Client(std::shared_ptr<Player> player) : _player(player){};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
void updatePacket() override;
|
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
void setSpawnPlayerCallBack(std::function<void(sf::Uint16)> spawn);
|
|
|
|
void setRemovePlayerCallBack(std::function<void(sf::Uint16)> remove);
|
2021-10-12 17:12:47 +03:00
|
|
|
void setAddFireTraceCallBack(std::function<void(const Vec3D&, const Vec3D&)> addTrace);
|
|
|
|
void setAddBonusCallBack(std::function<void(const std::string&, const Vec3D&)> addBonus);
|
2021-10-17 10:21:10 +03:00
|
|
|
void setRemoveBonusCallBack(std::function<void(const ObjectNameTag&)> removeBonus);
|
2021-10-02 20:36:07 +03:00
|
|
|
|
2021-10-18 18:30:02 +03:00
|
|
|
void setChangeEnemyWeaponCallBack(std::function<void(const std::string&, sf::Uint16)> changeEnemyWeapon);
|
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
void processInit(sf::Packet& packet) override;
|
|
|
|
void processUpdate(sf::Packet& packet) override;
|
|
|
|
void processNewClient(sf::Packet& packet) override;
|
|
|
|
void processDisconnect(sf::Uint16 targetId) override;
|
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
void processCustomPacket(sf::Packet& packet) override;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
void processDisconnected() override;
|
|
|
|
|
|
|
|
void damagePlayer(sf::Uint16 targetId, double damage);
|
|
|
|
|
|
|
|
void takeBonus(const std::string& bonusName);
|
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
void addTrace(const Vec3D& from, const Vec3D& to);
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-18 18:30:02 +03:00
|
|
|
void changeWeapon(const std::string& weaponName);
|
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
void addPlayer(sf::Uint16 id, std::shared_ptr<Player> player);
|
2021-10-26 09:50:59 +03:00
|
|
|
[[nodiscard]] std::map<sf::Uint16, std::shared_ptr<Player>>const & players() const { return _players; }
|
|
|
|
|
|
|
|
[[nodiscard]] std::string lastEvent() const { return _lastEvent; }
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //MINECRAFT_3DZAVR_CLIENT_H
|