Merge remote-tracking branch 'origin/master' into HealthPickup
This commit is contained in:
@@ -2,16 +2,16 @@
|
|||||||
#define EPlayerHealthPickup_h__
|
#define EPlayerHealthPickup_h__
|
||||||
|
|
||||||
#include "EventBroker.h"
|
#include "EventBroker.h"
|
||||||
#include "../Core/Entity.h"
|
#include "../Core/EntityWrapper.h"
|
||||||
|
|
||||||
namespace Events
|
namespace Events
|
||||||
{
|
{
|
||||||
|
|
||||||
struct PlayerHealthPickup : Event
|
struct PlayerHealthPickup : Event
|
||||||
{
|
{
|
||||||
double HealthAmount;
|
EntityWrapper Player;
|
||||||
EntityID PlayerHealedID;
|
double HealthAmount;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ private:
|
|||||||
EventRelay<HealthSystem, Events::PlayerDamage> m_EPlayerDamage;
|
EventRelay<HealthSystem, Events::PlayerDamage> m_EPlayerDamage;
|
||||||
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e);
|
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e);
|
||||||
EventRelay<HealthSystem, Events::PlayerHealthPickup> m_EPlayerHealthPickup;
|
EventRelay<HealthSystem, Events::PlayerHealthPickup> m_EPlayerHealthPickup;
|
||||||
bool HealthSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup& e);
|
bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e);
|
||||||
|
|
||||||
//vector which will keep track of health changes
|
//vector which will keep track of health changes
|
||||||
std::vector<std::tuple<EntityID, double>> m_DeltaHealthVector;
|
std::vector<std::tuple<EntityID, double>> m_DeltaHealthVector;
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ A=Right,-1
|
|||||||
R=Reload
|
R=Reload
|
||||||
Space=Jump
|
Space=Jump
|
||||||
LeftControl=Crouch
|
LeftControl=Crouch
|
||||||
LeftShift=Sprint
|
RightShift=Sprint
|
||||||
|
LeftShift=SpecialAbility
|
||||||
F1=ToggleEditor
|
F1=ToggleEditor
|
||||||
C=ConnectToServer
|
C=ConnectToServer
|
||||||
N=SwitchToServer
|
N=SwitchToServer
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
<Dash 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>
|
||||||
</Dash>
|
</DashAbility>
|
||||||
@@ -104,13 +104,6 @@
|
|||||||
</Entity>
|
</Entity>
|
||||||
<Entity name="Weapon">
|
<Entity name="Weapon">
|
||||||
<Components>
|
<Components>
|
||||||
<c:ExplosionEffect>
|
|
||||||
<ColorByDistance>true</ColorByDistance>
|
|
||||||
<Velocity X="0.800000012" Y="0.0379999988" Z="0"/>
|
|
||||||
<ExplosionDuration>3.7999999523162842</ExplosionDuration>
|
|
||||||
<EndColor A="0" B="23.5294113" G="11.7647057" R="0"/>
|
|
||||||
<Randomness>true</Randomness>
|
|
||||||
</c:ExplosionEffect>
|
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>Models/AssaultWeaponRed.mesh</Resource>
|
<Resource>Models/AssaultWeaponRed.mesh</Resource>
|
||||||
</c:Model>
|
</c:Model>
|
||||||
|
|||||||
@@ -11,38 +11,6 @@ HealthSystem::HealthSystem(World* m_World, EventBroker* eventBroker)
|
|||||||
|
|
||||||
void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
|
void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
|
||||||
{
|
{
|
||||||
//if entityID of health is 9 then the players ID is also 9 (player,health are connected to the same entity)
|
|
||||||
double maxHealth = (double)component["MaxHealth"];
|
|
||||||
|
|
||||||
//process the DeltaHealthVector and change the entitys health accordingly
|
|
||||||
for (size_t i = m_DeltaHealthVector.size(); i > 0; i--)
|
|
||||||
{
|
|
||||||
auto deltaHP = m_DeltaHealthVector[i - 1];
|
|
||||||
//if we have a healthchange for the current player and health is greater than 0, then apply it
|
|
||||||
if (std::get<0>(deltaHP) == component.EntityID && (double)component["Health"] > 0.0f) {
|
|
||||||
//get the deltaHP value from the tuple and make sure you dont get more than maxHealth
|
|
||||||
double newHealth = std::min((double)component["Health"] + (double)std::get<1>(deltaHP), maxHealth);
|
|
||||||
component["Health"] = newHealth;
|
|
||||||
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + i - 1);
|
|
||||||
//check if health is <= 0
|
|
||||||
if ((double)component["Health"] <= 0.0f) {
|
|
||||||
component["Health"] = 0.0;
|
|
||||||
//publish death event
|
|
||||||
Events::PlayerDeath e;
|
|
||||||
e.PlayerID = component.EntityID;
|
|
||||||
m_EventBroker->Publish(e);
|
|
||||||
//clear the remaining hpDeltas for the dead player
|
|
||||||
for (size_t j = m_DeltaHealthVector.size(); j > 0; j--)
|
|
||||||
{
|
|
||||||
if (std::get<0>(m_DeltaHealthVector[j - 1]) == component.EntityID)
|
|
||||||
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + j - 1);
|
|
||||||
}
|
|
||||||
//delete the player and break the loop
|
|
||||||
m_World->DeleteEntity(entity.ID);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
|
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
|
||||||
@@ -58,10 +26,13 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HealthSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup& e)
|
bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e)
|
||||||
{
|
{
|
||||||
//save the changed HP to a vector. it will be taken care of in UpdateComponent
|
ComponentWrapper cHealth = e.Player["Health"];
|
||||||
m_DeltaHealthVector.push_back(std::make_tuple(e.PlayerHealedID, e.HealthAmount));
|
double& health = cHealth["Health"];
|
||||||
|
//NOTE: its possible to get more than MaxHealth health
|
||||||
|
health += e.HealthAmount;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -255,14 +255,14 @@ void CapturePointTest::TestSetup8()
|
|||||||
}
|
}
|
||||||
void CapturePointTest::DoTouchEvent(EntityID whoDidSomething, EntityID onWhatObject) {
|
void CapturePointTest::DoTouchEvent(EntityID whoDidSomething, EntityID onWhatObject) {
|
||||||
Events::TriggerTouch touchEvent;
|
Events::TriggerTouch touchEvent;
|
||||||
touchEvent.Entity = whoDidSomething;
|
touchEvent.Entity = EntityWrapper(m_World, whoDidSomething);
|
||||||
touchEvent.Trigger = onWhatObject;
|
touchEvent.Trigger = EntityWrapper(m_World, onWhatObject);
|
||||||
m_EventBroker->Publish(touchEvent);
|
m_EventBroker->Publish(touchEvent);
|
||||||
}
|
}
|
||||||
void CapturePointTest::DoLeaveEvent(EntityID whoDidSomething, EntityID onWhatObject) {
|
void CapturePointTest::DoLeaveEvent(EntityID whoDidSomething, EntityID onWhatObject) {
|
||||||
Events::TriggerLeave leaveEvent;
|
Events::TriggerLeave leaveEvent;
|
||||||
leaveEvent.Entity = whoDidSomething;
|
leaveEvent.Entity = EntityWrapper(m_World, whoDidSomething);
|
||||||
leaveEvent.Trigger = onWhatObject;
|
leaveEvent.Trigger = EntityWrapper(m_World, onWhatObject);
|
||||||
m_EventBroker->Publish(leaveEvent);
|
m_EventBroker->Publish(leaveEvent);
|
||||||
}
|
}
|
||||||
void CapturePointTest::TestSuccess1() {
|
void CapturePointTest::TestSuccess1() {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void RayTest(std::string fileName) {
|
|||||||
Ray ray(glm::vec3(-50, 0, 0), glm::vec3(1, 0, 0));
|
Ray ray(glm::vec3(-50, 0, 0), glm::vec3(1, 0, 0));
|
||||||
//using a
|
//using a
|
||||||
|
|
||||||
here, else we have to init the renderingsystem
|
//here, else we have to init the renderingsystem
|
||||||
ResourceManager::RegisterType<RawModel>("RawModel");
|
ResourceManager::RegisterType<RawModel>("RawModel");
|
||||||
auto unitBox = ResourceManager::Load<RawModel>(fileName);
|
auto unitBox = ResourceManager::Load<RawModel>(fileName);
|
||||||
BOOST_REQUIRE(unitBox != nullptr);
|
BOOST_REQUIRE(unitBox != nullptr);
|
||||||
|
|||||||
@@ -48,42 +48,38 @@ GameHealthSystemTest::GameHealthSystemTest()
|
|||||||
fp.MergeEntities(m_World);
|
fp.MergeEntities(m_World);
|
||||||
|
|
||||||
// Create system pipeline
|
// Create system pipeline
|
||||||
m_SystemPipeline = new SystemPipeline(m_World,m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_World, m_EventBroker);
|
||||||
m_SystemPipeline->AddSystem<HealthSystem>(0);
|
m_SystemPipeline->AddSystem<HealthSystem>(0);
|
||||||
|
|
||||||
//The Test
|
//The Test
|
||||||
//create entity which has transform,player,model,health in it. i.e. is a player
|
//create entity which has transform,player,model,health in it. i.e. is a player
|
||||||
EntityID playerID = m_World->CreateEntity();
|
EntityID playerID = m_World->CreateEntity();
|
||||||
ComponentWrapper transform = m_World->AttachComponent(playerID, "Transform");
|
|
||||||
ComponentWrapper model = m_World->AttachComponent(playerID, "Model");
|
|
||||||
model["Resource"] = "Models/Core/UnitSphere.mesh"; // 360NoScope UnitSphere
|
|
||||||
ComponentWrapper player = m_World->AttachComponent(playerID, "Player");
|
ComponentWrapper player = m_World->AttachComponent(playerID, "Player");
|
||||||
ComponentWrapper health = m_World->AttachComponent(playerID, "Health");
|
ComponentWrapper health = m_World->AttachComponent(playerID, "Health");
|
||||||
healthsID = playerID;
|
healthsID = playerID;
|
||||||
double currentHealth = (double)m_World->GetComponent(healthsID, "Health")["Health"];
|
|
||||||
|
EntityID playerID2 = m_World->CreateEntity();
|
||||||
|
ComponentWrapper player2 = m_World->AttachComponent(playerID2, "Player");
|
||||||
|
ComponentWrapper health2 = m_World->AttachComponent(playerID2, "Health");
|
||||||
|
|
||||||
//heal player with 40
|
//heal player with 40
|
||||||
Events::PlayerHealthPickup e3;
|
Events::PlayerHealthPickup e3;
|
||||||
e3.HealthAmount = 40.0f;
|
e3.HealthAmount = 40.0f;
|
||||||
e3.PlayerHealedID = healthsID;
|
e3.Player = EntityWrapper(m_World, player.EntityID);
|
||||||
m_EventBroker->Publish(e3);
|
m_EventBroker->Publish(e3);
|
||||||
|
|
||||||
//damage player with 50
|
//damage player with 50
|
||||||
Events::PlayerDamage e;
|
Events::PlayerDamage e;
|
||||||
e.DamageAmount = 50.0f;
|
e.Damage = 50.0f;
|
||||||
e.PlayerDamagedID = healthsID;
|
e.Player = EntityWrapper(m_World, player.EntityID);
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
|
|
||||||
//heal some other player with 40
|
//heal some other player with 40
|
||||||
Events::PlayerHealthPickup e2;
|
Events::PlayerHealthPickup e2;
|
||||||
e2.HealthAmount = 40.0f;
|
e2.HealthAmount = 40.0f;
|
||||||
e2.PlayerHealedID = healthsID + 1;
|
e2.Player = EntityWrapper(m_World, player2.EntityID);
|
||||||
m_EventBroker->Publish(e2);
|
m_EventBroker->Publish(e2);
|
||||||
|
|
||||||
EntityID playerID2 = m_World->CreateEntity();
|
|
||||||
ComponentWrapper transform2 = m_World->AttachComponent(playerID2, "Transform");
|
|
||||||
ComponentWrapper model2 = m_World->AttachComponent(playerID2, "Model");
|
|
||||||
model2["Resource"] = "Models/Core/UnitSphere.mesh"; // 360NoScope UnitSphere
|
|
||||||
ComponentWrapper player2 = m_World->AttachComponent(playerID2, "Player");
|
|
||||||
ComponentWrapper health2 = m_World->AttachComponent(playerID2, "Health");
|
|
||||||
//END TEST
|
//END TEST
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user