This commit is contained in:
antc13
2016-03-02 11:44:29 +01:00
17 changed files with 163 additions and 82 deletions
+2 -1
View File
@@ -12,7 +12,8 @@ namespace Events
struct Captured : Event struct Captured : Event
{ {
int TeamNumberThatCapturedCapturePoint; int TeamNumberThatCapturedCapturePoint;
EntityID CapturePointID; EntityID CapturePointTakenID;
EntityWrapper NextCapturePoint;
}; };
} }
@@ -104,6 +104,11 @@ protected:
if (!m_Enabled) { if (!m_Enabled) {
return false; return false;
} }
ImGuiIO& io = ImGui::GetIO();
if (io.WantCaptureMouse || io.WantCaptureKeyboard) {
return false;
}
m_SpeedMultiplier += e.DeltaY * (0.1 * m_SpeedMultiplier); m_SpeedMultiplier += e.DeltaY * (0.1 * m_SpeedMultiplier);
m_Config->Set("Editor.CameraSpeed", m_SpeedMultiplier); m_Config->Set("Editor.CameraSpeed", m_SpeedMultiplier);
@@ -27,7 +27,7 @@ public:
virtual bool OnCommand(const Events::InputCommand& e) override; virtual bool OnCommand(const Events::InputCommand& e) override;
virtual void Reset(); virtual void Reset();
void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer); void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer);
virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; } virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; }
virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; } virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; }
@@ -41,7 +41,6 @@ protected:
bool m_Crouching = false; bool m_Crouching = false;
//assault dash membervariables - needed to calculate the doubletap- and dashlogic //assault dash membervariables - needed to calculate the doubletap- and dashlogic
double m_AssaultDashDoubleTapDeltaTime = 0.0; double m_AssaultDashDoubleTapDeltaTime = 0.0;
double m_AssaultDashCoolDownTimer = 0.0;
//i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable), //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 //and its very unlikely that someone wants to change that value
const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f; const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f;
@@ -191,21 +190,21 @@ bool FirstPersonInputController<EventContext>::OnLockMouse(const Events::LockMou
} }
template <typename EventContext> template <typename EventContext>
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer) { void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer, double& assaultDashCoolDownTimer) {
m_AssaultDashDoubleTapDeltaTime += dt; m_AssaultDashDoubleTapDeltaTime += dt;
m_AssaultDashCoolDownTimer -= dt; assaultDashCoolDownTimer -= dt;
//cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work) //cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work)
if (m_AssaultDashCoolDownTimer > (assaultDashCoolDownMaxTimer - 0.25f)) { if (assaultDashCoolDownTimer > (assaultDashCoolDownMaxTimer - 0.25f)) {
m_PlayerIsDashing = true; m_PlayerIsDashing = true;
} else { } else {
m_PlayerIsDashing = false; m_PlayerIsDashing = false;
} }
//dashing with shift //dashing with shift
if (m_ShiftDashing && m_AssaultDashCoolDownTimer <= 0.0f) { if (m_ShiftDashing && assaultDashCoolDownTimer <= 0.0f) {
//player is dashing with shift //player is dashing with shift
//the wanted-direction is set in playermovement already so we dont need to check what direction we want to dash in! //the wanted-direction is set in playermovement already so we dont need to check what direction we want to dash in!
m_AssaultDashCoolDownTimer = assaultDashCoolDownMaxTimer; assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
m_AssaultDashDoubleTapped = true; m_AssaultDashDoubleTapped = true;
m_AssaultDashDoubleTapDeltaTime = 0.f; m_AssaultDashDoubleTapDeltaTime = 0.f;
return; return;
@@ -227,7 +226,7 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
} }
m_ValidDoubleTap = false; m_ValidDoubleTap = false;
if (!(m_AssaultDashCoolDownTimer <= 0.0f)) { if (!(assaultDashCoolDownTimer <= 0.0f)) {
//if we cant dash at the moment, then just reset the tap-sensitivity-timer //if we cant dash at the moment, then just reset the tap-sensitivity-timer
m_AssaultDashDoubleTapDeltaTime = 0.f; m_AssaultDashDoubleTapDeltaTime = 0.f;
return; return;
@@ -235,7 +234,7 @@ void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool
//ok, we have a valid tap, lets do it //ok, we have a valid tap, lets do it
m_AssaultDashDoubleTapped = true; m_AssaultDashDoubleTapped = true;
m_AssaultDashDoubleTapDeltaTime = 0.f; m_AssaultDashDoubleTapDeltaTime = 0.f;
m_AssaultDashCoolDownTimer = assaultDashCoolDownMaxTimer; assaultDashCoolDownTimer = assaultDashCoolDownMaxTimer;
Events::DashAbility e; Events::DashAbility e;
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
+3 -1
View File
@@ -26,6 +26,7 @@
#include "Network/EInterpolate.h" #include "Network/EInterpolate.h"
#include "Network/SnapshotFilter.h" #include "Network/SnapshotFilter.h"
#include "Core/EPlayerSpawned.h" #include "Core/EPlayerSpawned.h"
#include "Core/EAmmoPickup.h"
#include "Network/ESearchForServers.h" #include "Network/ESearchForServers.h"
struct ServerInfo struct ServerInfo
@@ -106,7 +107,8 @@ private:
void parsePlayerDamage(Packet& packet); void parsePlayerDamage(Packet& packet);
void parseComponentDeletion(Packet& packet); void parseComponentDeletion(Packet& packet);
void parseDoubleJump(Packet& packet); void parseDoubleJump(Packet& packet);
void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType); void parseAmmoPickup(Packet& packet);
void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType);
void parseSnapshot(Packet& packet); void parseSnapshot(Packet& packet);
void identifyPacketLoss(); void identifyPacketLoss();
void hasServerTimedOut(); void hasServerTimedOut();
+1
View File
@@ -21,6 +21,7 @@ enum class MessageType
PlayerTransform, PlayerTransform,
OnDoubleJump, OnDoubleJump,
ServerlistRequest, ServerlistRequest,
AmmoPickup,
Invalid Invalid
}; };
+4 -1
View File
@@ -20,6 +20,7 @@
#include "../Game/Events/EDoubleJump.h" #include "../Game/Events/EDoubleJump.h"
#include "Core/EEntityDeleted.h" #include "Core/EEntityDeleted.h"
#include "Core/EComponentDeleted.h" #include "Core/EComponentDeleted.h"
#include "Core/EAmmoPickup.h"
class Server : public Network class Server : public Network
{ {
@@ -88,7 +89,7 @@ private:
void parseServerlistRequest(boost::asio::ip::udp::endpoint endpoint); void parseServerlistRequest(boost::asio::ip::udp::endpoint endpoint);
bool shouldSendToClient(EntityWrapper childEntity); bool shouldSendToClient(EntityWrapper childEntity);
// Debug event // Events
EventRelay<Server, Events::InputCommand> m_EInputCommand; EventRelay<Server, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e); bool OnInputCommand(const Events::InputCommand& e);
EventRelay<Server, Events::PlayerSpawned> m_EPlayerSpawned; EventRelay<Server, Events::PlayerSpawned> m_EPlayerSpawned;
@@ -99,6 +100,8 @@ private:
bool OnComponentDeleted(const Events::ComponentDeleted& e); bool OnComponentDeleted(const Events::ComponentDeleted& e);
EventRelay<Server, Events::PlayerDamage> m_EPlayerDamage; EventRelay<Server, Events::PlayerDamage> m_EPlayerDamage;
bool OnPlayerDamage(const Events::PlayerDamage& e); bool OnPlayerDamage(const Events::PlayerDamage& e);
EventRelay<Server, Events::AmmoPickup> m_EAmmoPickup;
bool OnAmmoPickup(const Events::AmmoPickup& e);
}; };
#endif #endif
+2
View File
@@ -20,6 +20,8 @@ public:
private: private:
EventRelay<AmmoPickupSystem, Events::TriggerTouch> m_ETriggerTouch; EventRelay<AmmoPickupSystem, Events::TriggerTouch> m_ETriggerTouch;
bool OnTriggerTouch(Events::TriggerTouch& e); bool OnTriggerTouch(Events::TriggerTouch& e);
EventRelay<AmmoPickupSystem, Events::AmmoPickup> m_EAmmoPickup;
bool OnAmmoPickup(Events::AmmoPickup& e);
struct NewAmmoPickup { struct NewAmmoPickup {
glm::vec3 Pos; glm::vec3 Pos;
+2 -2
View File
@@ -42,9 +42,9 @@ private:
int m_NumberOfCapturePoints = 0; int m_NumberOfCapturePoints = 0;
std::map<int, EntityWrapper> m_CapturePointNumberToEntityMap; std::map<int, EntityWrapper> m_CapturePointNumberToEntityMap;
//std::vector<ComponentWrapper>
bool m_ResetTimers = false; bool m_ResetTimers = false;
bool m_RecentlyCapturedNeedNextCapturePointNow = false;
Events::Captured m_CapturedEvent;
//vectors which will keep track of enter/leave changes //vectors which will keep track of enter/leave changes
std::vector<std::tuple<EntityWrapper, EntityWrapper>> m_ETriggerTouchVector; std::vector<std::tuple<EntityWrapper, EntityWrapper>> m_ETriggerTouchVector;
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<DashAbility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DashAbility.xsd"> <DashAbility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DashAbility.xsd">
<CoolDownMaxTimer>2.0</CoolDownMaxTimer> <CoolDownMaxTimer>2.0</CoolDownMaxTimer>
<CoolDownTimer>0.0</CoolDownTimer>
</DashAbility> </DashAbility>
+4 -1
View File
@@ -10,7 +10,10 @@
<xs:complexType> <xs:complexType>
<xs:all> <xs:all>
<xs:element name="CoolDownMaxTimer" type="t:double" minOccurs="0"> <xs:element name="CoolDownMaxTimer" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>This is the cooldown on dash</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>This is the max cooldown on dash</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="CoolDownTimer" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>This is the current cooldown on dash</xs:documentation></xs:annotation>
</xs:element> </xs:element>
</xs:all> </xs:all>
</xs:complexType> </xs:complexType>
+12 -3
View File
@@ -101,8 +101,7 @@ void Client::Update()
void Client::parseMessageType(Packet& packet) void Client::parseMessageType(Packet& packet)
{ {
// Pop packetSize which is used by TCP Client to // Pop packetSize
// create a packet of the correct size
packet.ReadPrimitive<int>(); packet.ReadPrimitive<int>();
int messageType = packet.ReadPrimitive<int>(); int messageType = packet.ReadPrimitive<int>();
if (messageType == -1) if (messageType == -1)
@@ -144,6 +143,9 @@ void Client::parseMessageType(Packet& packet)
case MessageType::OnDoubleJump: case MessageType::OnDoubleJump:
parseDoubleJump(packet); parseDoubleJump(packet);
break; break;
case MessageType::AmmoPickup:
parseAmmoPickup(packet);
break;
default: default:
break; break;
} }
@@ -233,7 +235,6 @@ void Client::parseSpawnEvents()
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
m_PlayerSpawnEvents = tempSpawn; m_PlayerSpawnEvents = tempSpawn;
// m_PlayerSpawnEvents.clear();
} }
void Client::parsePlayersSpawned(Packet& packet) void Client::parsePlayersSpawned(Packet& packet)
@@ -296,6 +297,14 @@ void Client::parseDoubleJump(Packet & packet)
} }
} }
void Client::parseAmmoPickup(Packet & packet)
{
Events::AmmoPickup e;
e.AmmoGain = packet.ReadPrimitive<int>();
e.Player = m_LocalPlayer;
m_EventBroker->Publish(e);
}
void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID) void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID)
{ {
for (auto field : componentInfo.FieldsInOrder) { for (auto field : componentInfo.FieldsInOrder) {
+18 -3
View File
@@ -13,7 +13,7 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &Server::OnEntityDeleted); EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &Server::OnEntityDeleted);
EVENT_SUBSCRIBE_MEMBER(m_EComponentDeleted, &Server::OnComponentDeleted); EVENT_SUBSCRIBE_MEMBER(m_EComponentDeleted, &Server::OnComponentDeleted);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Server::OnPlayerDamage); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Server::OnPlayerDamage);
EVENT_SUBSCRIBE_MEMBER(m_EAmmoPickup, &Server::OnAmmoPickup);
// BindWW // BindWW
if (port == 0) { if (port == 0) {
port = config->Get<float>("Networking.Port", 27666); port = config->Get<float>("Networking.Port", 27666);
@@ -510,6 +510,19 @@ bool Server::OnPlayerDamage(const Events::PlayerDamage& e)
return true; return true;
} }
bool Server::OnAmmoPickup(const Events::AmmoPickup & e)
{
for (auto& kv : m_ConnectedPlayers) {
if (e.Player.ID == kv.second.EntityID) {
Packet packet(MessageType::AmmoPickup);
// We dont send playerID as it will be set at client to local
packet.WritePrimitive(e.AmmoGain);
m_Reliable.Send(packet, kv.second);
}
}
return true;
}
void Server::parseClientPing() void Server::parseClientPing()
{ {
LOG_INFO("%i: Parsing ping", m_PacketID); LOG_INFO("%i: Parsing ping", m_PacketID);
@@ -604,12 +617,14 @@ bool Server::shouldSendToClient(EntityWrapper childEntity)
auto children = m_World->GetDirectChildren(childEntity.ID); auto children = m_World->GetDirectChildren(childEntity.ID);
for (auto it = children.first; it != children.second; it++) { for (auto it = children.first; it != children.second; it++) {
EntityWrapper child(m_World, it->second); EntityWrapper child(m_World, it->second);
if(child.HasComponent("CapturePoint")) { if (child.HasComponent("CapturePoint") || child.HasComponent("HealthPickup")
|| child.HasComponent("AmmoPickup")) {
return true; return true;
} }
} }
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid() return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid()
|| childEntity.HasComponent("CapturePoint"); || childEntity.HasComponent("CapturePoint") || childEntity.HasComponent("HealthPickup")
|| childEntity.HasComponent("AmmoPickup");
} }
PlayerID Server::GetPlayerIDFromEndpoint() PlayerID Server::GetPlayerIDFromEndpoint()
+56 -26
View File
@@ -3,37 +3,43 @@
AmmoPickupSystem::AmmoPickupSystem(SystemParams params) AmmoPickupSystem::AmmoPickupSystem(SystemParams params)
: System(params) : System(params)
{ {
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &AmmoPickupSystem::OnTriggerTouch); if (IsServer) {
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &AmmoPickupSystem::OnTriggerTouch);
}
if (IsClient) {
EVENT_SUBSCRIBE_MEMBER(m_EAmmoPickup, &AmmoPickupSystem::OnAmmoPickup);
}
} }
void AmmoPickupSystem::Update(double dt) void AmmoPickupSystem::Update(double dt)
{ {
for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it) if (IsServer) {
{ for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it) {
auto& ammoPickupPosition = *it; auto& ammoPickupPosition = *it;
//set the double timer value (value 3) //set the double timer value (value 3)
ammoPickupPosition.DecreaseThisRespawnTimer -= dt; ammoPickupPosition.DecreaseThisRespawnTimer -= dt;
if (ammoPickupPosition.DecreaseThisRespawnTimer < 0.0) { if (ammoPickupPosition.DecreaseThisRespawnTimer < 0.0) {
//spawn and delete the vector item //spawn and delete the vector item
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/AmmoPickup.xml"); auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/AmmoPickup.xml");
EntityFileParser parser(entityFile); EntityFileParser parser(entityFile);
EntityID ammoPickupID = parser.MergeEntities(m_World); EntityID ammoPickupID = parser.MergeEntities(m_World);
//let the world know a pickup has spawned (graphics effects, etc) //let the world know a pickup has spawned (graphics effects, etc)
Events::PickupSpawned ePickupSpawned; Events::PickupSpawned ePickupSpawned;
ePickupSpawned.Pickup = EntityWrapper(m_World, ammoPickupID); ePickupSpawned.Pickup = EntityWrapper(m_World, ammoPickupID);
m_EventBroker->Publish(ePickupSpawned); m_EventBroker->Publish(ePickupSpawned);
//set values from the old entity to the new entity //set values from the old entity to the new entity
auto& newAmmoPickupEntity = EntityWrapper(m_World, ammoPickupID); auto& newAmmoPickupEntity = EntityWrapper(m_World, ammoPickupID);
newAmmoPickupEntity["Transform"]["Position"] = ammoPickupPosition.Pos; newAmmoPickupEntity["Transform"]["Position"] = ammoPickupPosition.Pos;
newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = ammoPickupPosition.AmmoGain; newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = ammoPickupPosition.AmmoGain;
newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = ammoPickupPosition.RespawnTimer; newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = ammoPickupPosition.RespawnTimer;
m_World->SetParent(newAmmoPickupEntity.ID, ammoPickupPosition.parentID); m_World->SetParent(newAmmoPickupEntity.ID, ammoPickupPosition.parentID);
//erase the current element (AmmoPickupPosition) //erase the current element (AmmoPickupPosition)
m_ETriggerTouchVector.erase(it); m_ETriggerTouchVector.erase(it);
break; break;
}
} }
} }
} }
@@ -41,7 +47,11 @@ void AmmoPickupSystem::Update(double dt)
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e) bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
{ {
if (e.Entity != LocalPlayer) { /*if (e.Entity != LocalPlayer) {
return false;
}*/
if (!e.Entity.Valid()) {
return false; return false;
} }
//TODO: add other weapontypes //TODO: add other weapontypes
@@ -66,7 +76,7 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
ePlayerAmmoPickup.Player = e.Entity; ePlayerAmmoPickup.Player = e.Entity;
m_EventBroker->Publish(ePlayerAmmoPickup); m_EventBroker->Publish(ePlayerAmmoPickup);
//immediately give the player the ammo //immediately give the player the ammo
currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo); //currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo);
//copy position, ammogain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object) //copy position, ammogain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
//we need to copy all values since each value can be different for each ammoPickup //we need to copy all values since each value can be different for each ammoPickup
@@ -77,3 +87,23 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
m_World->DeleteEntity(e.Trigger.ID); m_World->DeleteEntity(e.Trigger.ID);
return true; return true;
} }
bool AmmoPickupSystem::OnAmmoPickup(Events::AmmoPickup & e)
{
if (!e.Player.Valid()) {
return false;
}
//TODO: add other weapontypes
if (!e.Player.HasComponent("AssaultWeapon")) {
return false;
}
int maxWeaponAmmo = (int)e.Player["AssaultWeapon"]["MaxAmmo"];
int& currentAmmo = (int)e.Player["AssaultWeapon"]["Ammo"];
//cant pick up ammopacks if you are already at MaxAmmo
if (currentAmmo >= maxWeaponAmmo) {
return false;
}
currentAmmo = std::min(currentAmmo + e.AmmoGain, maxWeaponAmmo);
return false;
}
+12 -6
View File
@@ -6,7 +6,7 @@ CapturePointSystem::CapturePointSystem(SystemParams params)
, PureSystem("CapturePoint") , PureSystem("CapturePoint")
{ {
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker) //subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
if (!IsClient) { if (IsServer) {
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch); EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave); EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave);
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured); EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured);
@@ -18,7 +18,7 @@ CapturePointSystem::CapturePointSystem(SystemParams params)
//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt //NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt
void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt) void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt)
{ {
if (IsClient) { if (!IsServer) {
return; return;
} }
if (m_WinnerWasFound) { if (m_WinnerWasFound) {
@@ -102,6 +102,13 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
nextPossibleCapturePoint["Blue"] = i - 1; nextPossibleCapturePoint["Blue"] = i - 1;
} }
} }
if (m_RecentlyCapturedNeedNextCapturePointNow) {
m_CapturedEvent.NextCapturePoint = m_CapturedEvent.TeamNumberThatCapturedCapturePoint == blueTeam ?
m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]] :
m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]];
m_EventBroker->Publish(m_CapturedEvent);
m_RecentlyCapturedNeedNextCapturePointNow = false;
}
//reset timers and reset the bool that triggers this //reset timers and reset the bool that triggers this
if (m_ResetTimers) { if (m_ResetTimers) {
@@ -188,10 +195,9 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
teamComponent["Team"] = currentTeam; teamComponent["Team"] = currentTeam;
cCapturePoint["CaptureTimer"] = glm::sign((double)cCapturePoint["CaptureTimer"])*captureTimeToTakeOver; cCapturePoint["CaptureTimer"] = glm::sign((double)cCapturePoint["CaptureTimer"])*captureTimeToTakeOver;
//publish Captured event //publish Captured event
Events::Captured e; m_RecentlyCapturedNeedNextCapturePointNow = true;
e.CapturePointID = cCapturePoint.EntityID; m_CapturedEvent.CapturePointTakenID = cCapturePoint.EntityID;
e.TeamNumberThatCapturedCapturePoint = currentTeam; m_CapturedEvent.TeamNumberThatCapturedCapturePoint = currentTeam;
m_EventBroker->Publish(e);
//NextPossibleCapturePoint will be calculated in the next update... //NextPossibleCapturePoint will be calculated in the next update...
} }
} }
+29 -26
View File
@@ -3,37 +3,40 @@
PickupSpawnSystem::PickupSpawnSystem(SystemParams params) PickupSpawnSystem::PickupSpawnSystem(SystemParams params)
: System(params) : System(params)
{ {
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &PickupSpawnSystem::OnTriggerTouch); if (IsServer) {
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &PickupSpawnSystem::OnTriggerTouch);
}
} }
void PickupSpawnSystem::Update(double dt) void PickupSpawnSystem::Update(double dt)
{ {
for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it) if (IsServer) {
{ for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it) {
auto& healthPickupPosition = *it; auto& healthPickupPosition = *it;
//set the double timer value (value 3) //set the double timer value (value 3)
healthPickupPosition.DecreaseThisRespawnTimer -= dt; healthPickupPosition.DecreaseThisRespawnTimer -= dt;
if (healthPickupPosition.DecreaseThisRespawnTimer < 0) { if (healthPickupPosition.DecreaseThisRespawnTimer < 0) {
//spawn and delete the vector item //spawn and delete the vector item
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/HealthPickup.xml"); auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/HealthPickup.xml");
EntityFileParser parser(entityFile); EntityFileParser parser(entityFile);
EntityID healthPickupID = parser.MergeEntities(m_World); EntityID healthPickupID = parser.MergeEntities(m_World);
//let the world know a pickup has spawned (graphics effects, etc) //let the world know a pickup has spawned (graphics effects, etc)
Events::PickupSpawned ePickupSpawned; Events::PickupSpawned ePickupSpawned;
ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID); ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID);
m_EventBroker->Publish(ePickupSpawned); m_EventBroker->Publish(ePickupSpawned);
//set values from the old entity to the new entity //set values from the old entity to the new entity
auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID); auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID);
newHealthPickupEntity["Transform"]["Position"] = healthPickupPosition.Pos; newHealthPickupEntity["Transform"]["Position"] = healthPickupPosition.Pos;
newHealthPickupEntity["HealthPickup"]["HealthGain"] = healthPickupPosition.HealthGain; newHealthPickupEntity["HealthPickup"]["HealthGain"] = healthPickupPosition.HealthGain;
newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = healthPickupPosition.RespawnTimer; newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = healthPickupPosition.RespawnTimer;
m_World->SetParent(newHealthPickupEntity.ID, healthPickupPosition.parentID); m_World->SetParent(newHealthPickupEntity.ID, healthPickupPosition.parentID);
//erase the current element (healthPickupPosition) //erase the current element (healthPickupPosition)
m_ETriggerTouchVector.erase(it); m_ETriggerTouchVector.erase(it);
break; break;
}
} }
} }
} }
@@ -58,8 +61,8 @@ bool PickupSpawnSystem::OnTriggerTouch(Events::TriggerTouch& e)
//copy position, healthgain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object) //copy position, healthgain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
//we need to copy all values since each value can be different for each healthPickup //we need to copy all values since each value can be different for each healthPickup
m_ETriggerTouchVector.push_back({ (glm::vec3)e.Trigger["Transform"]["Position"] ,e.Trigger["HealthPickup"]["HealthGain"], m_ETriggerTouchVector.push_back({ (glm::vec3)e.Trigger["Transform"]["Position"], e.Trigger["HealthPickup"]["HealthGain"],
e.Trigger["HealthPickup"]["RespawnTimer"],e.Trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(e.Trigger.ID) }); e.Trigger["HealthPickup"]["RespawnTimer"], e.Trigger["HealthPickup"]["RespawnTimer"], m_World->GetParent(e.Trigger.ID) });
//delete the healthpickup //delete the healthpickup
m_World->DeleteEntity(e.Trigger.ID); m_World->DeleteEntity(e.Trigger.ID);
+3 -2
View File
@@ -48,7 +48,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
EntityWrapper playerModel = player.FirstChildByName("PlayerModel"); EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
if (playerModel.Valid()) { if (playerModel.Valid()) {
ComponentWrapper cAnimationOffset = playerModel["AnimationOffset"]; ComponentWrapper cAnimationOffset = playerModel["AnimationOffset"];
float pitch = cameraOrientation.x + 0.2; float pitch = cameraOrientation.x + 0.2f;
double time = (pitch + glm::half_pi<float>()) / glm::pi<float>(); double time = (pitch + glm::half_pi<float>()) / glm::pi<float>();
cAnimationOffset["Time"] = time; cAnimationOffset["Time"] = time;
} }
@@ -66,7 +66,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
ComponentWrapper cPhysics = player["Physics"]; ComponentWrapper cPhysics = player["Physics"];
//Assault Dash Check //Assault Dash Check
if (player.HasComponent("DashAbility")) { if (player.HasComponent("DashAbility")) {
controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"]); controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"], player["DashAbility"]["CoolDownTimer"]);
} }
wishDirection = controller->Movement() * glm::inverse(glm::quat(ori)); wishDirection = controller->Movement() * glm::inverse(glm::quat(ori));
//this makes sure you can only dash in the 4 directions: forw,backw,left,right //this makes sure you can only dash in the 4 directions: forw,backw,left,right
@@ -311,6 +311,7 @@ bool PlayerMovementSystem::OnDoubleJump(Events::DoubleJump & e)
return false; return false;
} }
spawnHexagon(EntityWrapper(m_World, e.entityID)); spawnHexagon(EntityWrapper(m_World, e.entityID));
return true;
} }
void PlayerMovementSystem::spawnHexagon(EntityWrapper target) void PlayerMovementSystem::spawnHexagon(EntityWrapper target)
+1 -1
View File
@@ -94,7 +94,7 @@ bool SoundSystem::OnCaptured(const Events::Captured & e)
if (!LocalPlayer.Valid()) { if (!LocalPlayer.Valid()) {
return false; return false;
} }
int homeTeam = (int)m_World->GetComponent(e.CapturePointID, "Team")["Team"]; int homeTeam = (int)m_World->GetComponent(e.CapturePointTakenID, "Team")["Team"];
int team = (int)m_World->GetComponent(LocalPlayer.ID, "Team")["Team"]; int team = (int)m_World->GetComponent(LocalPlayer.ID, "Team")["Team"];
Events::PlaySoundOnEntity ev; Events::PlaySoundOnEntity ev;
if (team == homeTeam) { if (team == homeTeam) {