HealthPickups are now based on a percentage of player maxhealth. You can no longer pickup healthpacks if you are at max health. You can no longer gain more than maxHealth.
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
class HealthSystem : public PureSystem
|
class HealthSystem : public PureSystem
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<xs:annotation><xs:documentation>The respawn timer for a health pickup</xs:documentation></xs:annotation>
|
<xs:annotation><xs:documentation>The respawn timer for a health pickup</xs:documentation></xs:annotation>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
<xs:element name="HealthGain" type="t:double" minOccurs="0">
|
<xs:element name="HealthGain" type="t:double" minOccurs="0">
|
||||||
<xs:annotation><xs:documentation>How much health the player will get when he picks the healthPickup up</xs:documentation></xs:annotation>
|
<xs:annotation><xs:documentation>How much percent max-health the player will get when he picks the healthPickup up</xs:documentation></xs:annotation>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e)
|
|||||||
{
|
{
|
||||||
ComponentWrapper cHealth = e.Player["Health"];
|
ComponentWrapper cHealth = e.Player["Health"];
|
||||||
double& health = cHealth["Health"];
|
double& health = cHealth["Health"];
|
||||||
//NOTE: its possible to get more than MaxHealth health
|
|
||||||
health += e.HealthAmount;
|
health += e.HealthAmount;
|
||||||
|
health = std::min(health, (double)cHealth["MaxHealth"]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,16 @@ bool PickupSpawnSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
|||||||
if (!e.Trigger.HasComponent("HealthPickup")) {
|
if (!e.Trigger.HasComponent("HealthPickup")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
double healthGiven = 0.01*(double)e.Trigger["HealthPickup"]["HealthGain"] * (double)e.Entity["Health"]["MaxHealth"];
|
||||||
|
//cant pick up healthpacks if you are already at MaxHealth
|
||||||
|
if ((double)e.Entity["Health"]["Health"] >= (double)e.Entity["Health"]["MaxHealth"]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//personEntered = e.Entity, thingEntered = e.Trigger
|
//personEntered = e.Entity, thingEntered = e.Trigger
|
||||||
Events::PlayerHealthPickup ePlayerHealthPickup;
|
Events::PlayerHealthPickup ePlayerHealthPickup;
|
||||||
ePlayerHealthPickup.HealthAmount = e.Trigger["HealthPickup"]["HealthGain"];
|
ePlayerHealthPickup.HealthAmount = healthGiven;
|
||||||
ePlayerHealthPickup.PlayerHealedID = e.Entity.ID;
|
ePlayerHealthPickup.Player = e.Entity;
|
||||||
m_EventBroker->Publish(ePlayerHealthPickup);
|
m_EventBroker->Publish(ePlayerHealthPickup);
|
||||||
|
|
||||||
//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)
|
||||||
|
|||||||
Reference in New Issue
Block a user