Dash effect now working over network, by sending events. Similar to jump effect.
This commit is contained in:
@@ -27,7 +27,7 @@ public:
|
||||
virtual bool OnCommand(const Events::InputCommand& e) override;
|
||||
virtual void Reset();
|
||||
|
||||
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer);
|
||||
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityWrapper player);
|
||||
virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; }
|
||||
virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; }
|
||||
|
||||
@@ -41,6 +41,7 @@ protected:
|
||||
bool m_Crouching = false;
|
||||
//assault dash membervariables - needed to calculate the doubletap- and dashlogic
|
||||
double m_AssaultDashDoubleTapDeltaTime = 0.0;
|
||||
double m_DashEffectResetTimer = 0.0;
|
||||
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable),
|
||||
//and its very unlikely that someone wants to change that value
|
||||
const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f;
|
||||
@@ -191,12 +192,19 @@ bool FirstPersonInputController<EventContext>::OnLockMouse(const Events::LockMou
|
||||
}
|
||||
|
||||
template <typename EventContext>
|
||||
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer) {
|
||||
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer, EntityWrapper player) {
|
||||
m_AssaultDashDoubleTapDeltaTime += dt;
|
||||
m_DashEffectResetTimer += dt;
|
||||
assaultDashCoolDownTimer -= dt;
|
||||
//cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work)
|
||||
if (assaultDashCoolDownTimer > (assaultDashCoolDownMaxTimer - 0.25f)) {
|
||||
m_PlayerIsDashing = true;
|
||||
if (m_DashEffectResetTimer > 0.05) {
|
||||
Events::DashAbility e;
|
||||
e.Player = player.ID;
|
||||
m_EventBroker->Publish(e);
|
||||
m_DashEffectResetTimer = 0.0;
|
||||
}
|
||||
} else {
|
||||
m_PlayerIsDashing = false;
|
||||
}
|
||||
@@ -209,6 +217,7 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
|
||||
m_AssaultDashDoubleTapped = true;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
Events::DashAbility e;
|
||||
e.Player = player.ID;
|
||||
m_EventBroker->Publish(e);
|
||||
return;
|
||||
}
|
||||
@@ -240,6 +249,7 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
|
||||
assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
|
||||
|
||||
Events::DashAbility e;
|
||||
e.Player = player.ID;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "Core/EPlayerSpawned.h"
|
||||
#include "Core/EAmmoPickup.h"
|
||||
#include "Network/ESearchForServers.h"
|
||||
#include "../Game/Events/EDashAbility.h"
|
||||
|
||||
struct ServerInfo
|
||||
{
|
||||
@@ -107,6 +108,7 @@ private:
|
||||
void parsePlayerDamage(Packet& packet);
|
||||
void parseComponentDeletion(Packet& packet);
|
||||
void parseDoubleJump(Packet& packet);
|
||||
void parseDashEffect(Packet& packet);
|
||||
void parseAmmoPickup(Packet& packet);
|
||||
void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
|
||||
void parseSnapshot(Packet& packet);
|
||||
@@ -135,6 +137,9 @@ private:
|
||||
EventRelay< Client, Events::SearchForServers> m_ESearchForServers;
|
||||
EventRelay<Client, Events::DoubleJump> m_EDoubleJump;
|
||||
bool OnDoubleJump(Events::DoubleJump & e);
|
||||
EventRelay<Client, Events::DashAbility> m_EDashAbility;
|
||||
bool OnDashAbility(const Events::DashAbility& e);
|
||||
|
||||
bool OnSearchForServers(const Events::SearchForServers& e);
|
||||
UDPClient m_ServerlistRequest;
|
||||
std::vector<ServerInfo> m_Serverlist;
|
||||
|
||||
@@ -20,6 +20,7 @@ enum class MessageType
|
||||
ComponentDeleted,
|
||||
PlayerTransform,
|
||||
OnDoubleJump,
|
||||
OnDashEffect,
|
||||
ServerlistRequest,
|
||||
AmmoPickup,
|
||||
Invalid
|
||||
|
||||
@@ -83,6 +83,7 @@ private:
|
||||
void parseClientPing();
|
||||
void parsePing();
|
||||
bool parseDoubleJump(Packet& packet);
|
||||
void parseDashEffect(Packet& packet);
|
||||
void parseUDPConnect(Packet& packet);
|
||||
void parseTCPConnect(Packet& packet);
|
||||
void parseDisconnect();
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
#define Events_DashAbility_h__
|
||||
|
||||
#include "Core/Event.h"
|
||||
#include "Core/EntityWrapper.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct DashAbility : public Event { };
|
||||
struct DashAbility : public Event
|
||||
{
|
||||
EntityID Player;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
|
||||
<Entity name="DashEffect" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
|
||||
|
||||
<Components>
|
||||
<c:Animation/>
|
||||
<c:Lifetime>
|
||||
<Lifetime>1</Lifetime>
|
||||
<Lifetime>0.5</Lifetime>
|
||||
</c:Lifetime>
|
||||
<c:ExplosionEffect>
|
||||
<Velocity X="0" Y="0" Z="0"/>
|
||||
<TimeSinceDeath>0</TimeSinceDeath>
|
||||
<ExplosionDuration>1</ExplosionDuration>
|
||||
<ExplosionDuration>0.5</ExplosionDuration>
|
||||
<EndColor A="0" B="0" G="0" R="0"/>
|
||||
</c:ExplosionEffect>
|
||||
<c:Model/>
|
||||
|
||||
@@ -33,6 +33,7 @@ void Client::Connect(std::string address, int port)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Client::OnPlayerDamage);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &Client::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &Client::OnDoubleJump);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &Client::OnDashAbility);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESearchForServers, &Client::OnSearchForServers);
|
||||
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||
m_Address = address;
|
||||
@@ -143,6 +144,9 @@ void Client::parseMessageType(Packet& packet)
|
||||
case MessageType::OnDoubleJump:
|
||||
parseDoubleJump(packet);
|
||||
break;
|
||||
case MessageType::OnDashEffect:
|
||||
parseDashEffect(packet);
|
||||
break;
|
||||
case MessageType::AmmoPickup:
|
||||
parseAmmoPickup(packet);
|
||||
break;
|
||||
@@ -262,7 +266,7 @@ void Client::parseEntityDeletion(Packet & packet)
|
||||
if (m_ServerIDToClientID.find(entityToDelete) != m_ServerIDToClientID.end()) {
|
||||
EntityID localEntity = m_ServerIDToClientID.at(entityToDelete);
|
||||
if (m_World->ValidEntity(localEntity)) {
|
||||
if (m_World->HasComponent(localEntity,"Player")) {
|
||||
if (m_World->HasComponent(localEntity, "Player")) {
|
||||
Events::PlayerDeath e;
|
||||
e.Player = EntityWrapper(m_World, localEntity);
|
||||
m_EventBroker->Publish(e);
|
||||
@@ -297,6 +301,20 @@ void Client::parseDoubleJump(Packet & packet)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Client::parseDashEffect(Packet& packet)
|
||||
{
|
||||
EntityID serverID = packet.ReadPrimitive<EntityID>();
|
||||
if (!serverClientMapsHasEntity(serverID)) {
|
||||
return;
|
||||
}
|
||||
Events::DashAbility e;
|
||||
e.Player = m_ServerIDToClientID.at(serverID);
|
||||
if (e.Player != m_LocalPlayer.ID) {
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
|
||||
void Client::parseAmmoPickup(Packet & packet)
|
||||
{
|
||||
Events::AmmoPickup e;
|
||||
@@ -518,6 +536,18 @@ bool Client::OnPlayerSpawned(const Events::PlayerSpawned& e)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Client::OnDashAbility(const Events::DashAbility& e)
|
||||
{
|
||||
if (!clientServerMapsHasEntity(e.Player) || e.Player != m_LocalPlayer.ID) {
|
||||
return false;
|
||||
}
|
||||
Packet packet(MessageType::OnDashEffect);
|
||||
packet.WritePrimitive(m_ClientIDToServerID.at(e.Player));
|
||||
m_Reliable.Send(packet);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::OnSearchForServers(const Events::SearchForServers& e)
|
||||
{
|
||||
m_SearchingForServers = true;
|
||||
|
||||
@@ -141,6 +141,9 @@ void Server::parseMessageType(Packet& packet)
|
||||
case MessageType::OnDoubleJump:
|
||||
parseDoubleJump(packet);
|
||||
break;
|
||||
case MessageType::OnDashEffect:
|
||||
parseDashEffect(packet);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -555,6 +558,11 @@ bool Server::parseDoubleJump(Packet & packet)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server::parseDashEffect(Packet& packet)
|
||||
{
|
||||
reliableBroadcast(packet);
|
||||
}
|
||||
|
||||
void Server::parseOnInputCommand(Packet& packet)
|
||||
{
|
||||
PlayerID player = -1;
|
||||
@@ -624,7 +632,7 @@ bool Server::shouldSendToClient(EntityWrapper childEntity)
|
||||
}
|
||||
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid()
|
||||
|| childEntity.HasComponent("CapturePoint") || childEntity.HasComponent("HealthPickup")
|
||||
|| childEntity.HasComponent("AmmoPickup");
|
||||
|| childEntity.HasComponent("AmmoPickup")/* || childEntity.Name() == "DashEffect"*/;
|
||||
}
|
||||
|
||||
PlayerID Server::GetPlayerIDFromEndpoint()
|
||||
|
||||
@@ -67,7 +67,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
|
||||
ComponentWrapper cPhysics = player["Physics"];
|
||||
//Assault Dash Check
|
||||
if (player.HasComponent("DashAbility")) {
|
||||
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"]);
|
||||
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"], player);
|
||||
}
|
||||
wishDirection = controller->Movement() * glm::inverse(glm::quat(ori));
|
||||
//this makes sure you can only dash in the 4 directions: forw,backw,left,right
|
||||
@@ -327,11 +327,16 @@ void PlayerMovementSystem::spawnHexagon(EntityWrapper target)
|
||||
|
||||
bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
|
||||
{
|
||||
EntityWrapper player(m_World, e.Player);
|
||||
if (!player.Valid() || !IsClient) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto dashEffectResource = ResourceManager::Load<EntityFile>("Schema/Entities/DashEffect.xml");
|
||||
EntityFileParser parser(dashEffectResource);
|
||||
EntityID dashEffectID = parser.MergeEntities(m_World);
|
||||
EntityWrapper dashEffect(m_World, dashEffectID);
|
||||
auto playerModel = LocalPlayer.FirstChildByName("PlayerModel");
|
||||
auto playerModel = player.FirstChildByName("PlayerModel");
|
||||
auto playerEntityModel = playerModel["Model"];
|
||||
auto playerEntityAnimation = playerModel["Animation"];
|
||||
playerEntityModel.Copy(dashEffect["Model"]);
|
||||
@@ -341,7 +346,7 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
|
||||
dashEffect["Animation"]["Speed1"] = 0.0;
|
||||
dashEffect["Animation"]["Speed2"] = 0.0;
|
||||
dashEffect["Animation"]["Speed3"] = 0.0;
|
||||
dashEffect["Transform"]["Position"] = (glm::vec3)LocalPlayer["Transform"]["Position"];
|
||||
dashEffect["Transform"]["Orientation"] = (glm::vec3)LocalPlayer["Transform"]["Orientation"];
|
||||
dashEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"];
|
||||
dashEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"];
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user