shooter/network/ShooterClient.h

82 lines
2.6 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 25.05.2021.
//
2021-10-28 17:06:10 +03:00
#ifndef SHOOTER_SHOOTERCLIENT_H
#define SHOOTER_SHOOTERCLIENT_H
2021-09-13 15:53:43 +03:00
2023-05-21 16:34:55 +03:00
#include "../3dzavr/engine/network/ClientUDP.h"
2022-07-19 12:37:37 +03:00
#include "../player/Player.h"
2023-05-21 16:34:55 +03:00
#include <SFML/Config.hpp>
2022-07-22 22:52:54 +03:00
#include "Chat.h"
2021-09-13 15:53:43 +03:00
2021-10-28 17:06:10 +03:00
class ShooterClient 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-10-02 20:36:07 +03:00
std::function<void(sf::Uint16)> _spawnPlayerCallBack;
std::function<void(sf::Uint16)> _removePlayerCallBack;
2021-10-31 11:39:08 +03:00
std::function<void(const Vec3D &, const Vec3D &)> _addFireTraceCallBack;
std::function<void(const std::string &, const Vec3D &)> _addBonusCallBack;
std::function<void(const ObjectNameTag &)> _removeBonusCallBack;
std::function<void(const std::string &, sf::Uint16)> _changeEnemyWeaponCallBack;
2022-07-22 22:52:54 +03:00
std::shared_ptr<ChatManager> chatManager;
2021-09-13 15:53:43 +03:00
public:
2021-10-31 11:39:08 +03:00
explicit ShooterClient(std::shared_ptr<Player> player) : _player(player) {};
2021-09-13 15:53:43 +03:00
2022-07-22 22:52:54 +03:00
void sendMessage(std::string message);
void newMessage(std::string message, std::string name);
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);
2021-10-31 11:39:08 +03:00
2021-10-02 20:36:07 +03:00
void setRemovePlayerCallBack(std::function<void(sf::Uint16)> remove);
2021-10-31 11:39:08 +03:00
void setAddFireTraceCallBack(std::function<void(const Vec3D &, const Vec3D &)> addTrace);
void setAddBonusCallBack(std::function<void(const std::string &, const Vec3D &)> addBonus);
void setRemoveBonusCallBack(std::function<void(const ObjectNameTag &)> removeBonus);
void setChangeEnemyWeaponCallBack(std::function<void(const std::string &, sf::Uint16)> changeEnemyWeapon);
void processInit(sf::Packet &packet) override;
void processUpdate(sf::Packet &packet) override;
void processNewClient(sf::Packet &packet) override;
2021-09-13 15:53:43 +03:00
void processDisconnect(sf::Uint16 targetId) override;
2021-10-31 11:39:08 +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);
2021-10-31 11:39:08 +03:00
void takeBonus(const std::string &bonusName);
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
void addTrace(const Vec3D &from, const Vec3D &to);
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
void changeWeapon(const std::string &weaponName);
2022-07-22 22:52:54 +03:00
void setChatManager(std::shared_ptr<ChatManager> chat) { chatManager = chat; };
2021-10-02 20:36:07 +03:00
void addPlayer(sf::Uint16 id, std::shared_ptr<Player> player);
2021-10-31 11:39:08 +03:00
2023-05-21 16:34:55 +03:00
static void requestMap(const std::string& clientIp, std::string *current_map);
2021-10-31 11:39:08 +03:00
[[nodiscard]] std::map<sf::Uint16, std::shared_ptr<Player>> const &players() const { return _players; }
2021-10-26 09:50:59 +03:00
[[nodiscard]] std::string lastEvent() const { return _lastEvent; }
2021-09-13 15:53:43 +03:00
};
#endif //MINECRAFT_3DZAVR_CLIENT_H