Merge remote-tracking branch 'origin/master' into HealthPickup

This commit is contained in:
verysecrethero
2016-02-08 10:22:35 +01:00
9 changed files with 33 additions and 72 deletions
+6 -6
View File
@@ -2,16 +2,16 @@
#define EPlayerHealthPickup_h__
#include "EventBroker.h"
#include "../Core/Entity.h"
#include "../Core/EntityWrapper.h"
namespace Events
{
struct PlayerHealthPickup : Event
{
double HealthAmount;
EntityID PlayerHealedID;
};
struct PlayerHealthPickup : Event
{
EntityWrapper Player;
double HealthAmount;
};
}
+1 -1
View File
@@ -26,7 +26,7 @@ private:
EventRelay<HealthSystem, Events::PlayerDamage> m_EPlayerDamage;
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e);
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
std::vector<std::tuple<EntityID, double>> m_DeltaHealthVector;
+2 -1
View File
@@ -13,7 +13,8 @@ A=Right,-1
R=Reload
Space=Jump
LeftControl=Crouch
LeftShift=Sprint
RightShift=Sprint
LeftShift=SpecialAbility
F1=ToggleEditor
C=ConnectToServer
N=SwitchToServer
+2 -2
View File
@@ -1,4 +1,4 @@
<?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>
</Dash>
</DashAbility>
-7
View File
@@ -104,13 +104,6 @@
</Entity>
<Entity name="Weapon">
<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>
<Resource>Models/AssaultWeaponRed.mesh</Resource>
</c:Model>
+6 -35
View File
@@ -11,38 +11,6 @@ HealthSystem::HealthSystem(World* m_World, EventBroker* eventBroker)
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)
@@ -58,10 +26,13 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
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
m_DeltaHealthVector.push_back(std::make_tuple(e.PlayerHealedID, e.HealthAmount));
ComponentWrapper cHealth = e.Player["Health"];
double& health = cHealth["Health"];
//NOTE: its possible to get more than MaxHealth health
health += e.HealthAmount;
return true;
}
+4 -4
View File
@@ -255,14 +255,14 @@ void CapturePointTest::TestSetup8()
}
void CapturePointTest::DoTouchEvent(EntityID whoDidSomething, EntityID onWhatObject) {
Events::TriggerTouch touchEvent;
touchEvent.Entity = whoDidSomething;
touchEvent.Trigger = onWhatObject;
touchEvent.Entity = EntityWrapper(m_World, whoDidSomething);
touchEvent.Trigger = EntityWrapper(m_World, onWhatObject);
m_EventBroker->Publish(touchEvent);
}
void CapturePointTest::DoLeaveEvent(EntityID whoDidSomething, EntityID onWhatObject) {
Events::TriggerLeave leaveEvent;
leaveEvent.Entity = whoDidSomething;
leaveEvent.Trigger = onWhatObject;
leaveEvent.Entity = EntityWrapper(m_World, whoDidSomething);
leaveEvent.Trigger = EntityWrapper(m_World, onWhatObject);
m_EventBroker->Publish(leaveEvent);
}
void CapturePointTest::TestSuccess1() {
+1 -1
View File
@@ -29,7 +29,7 @@ void RayTest(std::string fileName) {
Ray ray(glm::vec3(-50, 0, 0), glm::vec3(1, 0, 0));
//using a
here, else we have to init the renderingsystem
//here, else we have to init the renderingsystem
ResourceManager::RegisterType<RawModel>("RawModel");
auto unitBox = ResourceManager::Load<RawModel>(fileName);
BOOST_REQUIRE(unitBox != nullptr);
+11 -15
View File
@@ -48,42 +48,38 @@ GameHealthSystemTest::GameHealthSystemTest()
fp.MergeEntities(m_World);
// Create system pipeline
m_SystemPipeline = new SystemPipeline(m_World,m_EventBroker);
m_SystemPipeline = new SystemPipeline(m_World, m_EventBroker);
m_SystemPipeline->AddSystem<HealthSystem>(0);
//The Test
//create entity which has transform,player,model,health in it. i.e. is a player
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 health = m_World->AttachComponent(playerID, "Health");
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
Events::PlayerHealthPickup e3;
e3.HealthAmount = 40.0f;
e3.PlayerHealedID = healthsID;
e3.Player = EntityWrapper(m_World, player.EntityID);
m_EventBroker->Publish(e3);
//damage player with 50
Events::PlayerDamage e;
e.DamageAmount = 50.0f;
e.PlayerDamagedID = healthsID;
e.Damage = 50.0f;
e.Player = EntityWrapper(m_World, player.EntityID);
m_EventBroker->Publish(e);
//heal some other player with 40
Events::PlayerHealthPickup e2;
e2.HealthAmount = 40.0f;
e2.PlayerHealedID = healthsID + 1;
e2.Player = EntityWrapper(m_World, player2.EntityID);
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
}