Merge remote-tracking branch 'origin/master' into AssaultBoost
# Conflicts: # resources/Schema/Components.xsd
This commit is contained in:
@@ -1,34 +1,52 @@
|
||||
#include "Systems/HealthSystem.h"
|
||||
|
||||
HealthSystem::HealthSystem(World* m_World, EventBroker* eventBroker)
|
||||
: System(m_World, eventBroker)
|
||||
HealthSystem::HealthSystem(SystemParams params)
|
||||
: System(params)
|
||||
, PureSystem("Health")
|
||||
{
|
||||
//subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &HealthSystem::OnPlayerDamaged);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerHealthPickup, &HealthSystem::OnPlayerHealthPickup);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &HealthSystem::OnInputCommand);
|
||||
m_NetworkEnabled = ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false);
|
||||
}
|
||||
|
||||
void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
|
||||
void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cHealth, double dt)
|
||||
{
|
||||
double& health = cHealth["Health"];
|
||||
if (health <= 0.0) {
|
||||
Events::PlayerDeath ePlayerDeath;
|
||||
ePlayerDeath.Player = entity;
|
||||
m_EventBroker->Publish(ePlayerDeath);
|
||||
//Note: we will delete the entity in PlayerDeathSystem
|
||||
}
|
||||
}
|
||||
|
||||
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
|
||||
{
|
||||
ComponentWrapper cHealth = e.Player["Health"];
|
||||
if (!IsServer && m_NetworkEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ComponentWrapper cHealth = e.Victim["Health"];
|
||||
double& health = cHealth["Health"];
|
||||
if (e.Player.HasComponent("BoostDefender")) {
|
||||
e.Damage -= (double)e.Player["BoostDefender"]["StrengthOfEffect"];
|
||||
}
|
||||
health -= e.Damage;
|
||||
|
||||
if (health <= 0.0) {
|
||||
Events::PlayerDeath ePlayerDeath;
|
||||
ePlayerDeath.Player = e.Player;
|
||||
m_EventBroker->Publish(ePlayerDeath);
|
||||
//Note: we will delete the entity in PlayerDeathSystem
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HealthSystem::OnInputCommand(Events::InputCommand& e)
|
||||
{
|
||||
if (e.Command == "TakeDamage" && e.Value > 0 && LocalPlayer.Valid()) {
|
||||
Events::PlayerDamage ev;
|
||||
ev.Inflictor = LocalPlayer;
|
||||
ev.Victim = LocalPlayer;
|
||||
ev.Damage = e.Value;
|
||||
m_EventBroker->Publish(ev);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user