boost check for defender

This commit is contained in:
viktorljung
2016-03-13 21:10:22 +01:00
parent e929ecab50
commit 3a0cff7a83
6 changed files with 187 additions and 23 deletions
@@ -41,6 +41,7 @@ private:
// Utility
Camera cameraFromEntity(EntityWrapper camera);
void CheckBoost(ComponentWrapper cWeapon, WeaponInfo& wi);
};
#endif
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="FriendlyBoostAttachment" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Spawner>
<EntityFile>Schema/Entities/FriendlyBoostBlueHUD.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="-0.000110394583" Y="-0.0891034827" Z="6.07890324e-05"/>
</c:Transform>
</Components>
<Children/>
</Entity>
@@ -6,7 +6,7 @@
<Lifetime>0.5</Lifetime>
</c:Lifetime>
<c:Transform>
<Scale X="1.5" Y="1.5" Z="1"/>
<Scale X="1.20000005" Y="1.20000005" Z="1"/>
</c:Transform>
</Components>
@@ -78,6 +78,19 @@
</c:Transform>
</Components>
<Children>
<Entity name="Inactive">
<Components>
<c:Text>
<Content>\2</Content>
<Resource>Fonts/Hind-Edited.otf,64</Resource>
<Color A="1" B="0.784313738" G="0.784313738" R="0.784313738"/>
</c:Text>
<c:Transform>
<Position X="0" Y="0" Z="-8.43336147e-06"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Active">
<Components>
<c:Text>
@@ -92,19 +105,6 @@
</Components>
<Children/>
</Entity>
<Entity name="Inactive">
<Components>
<c:Text>
<Content>\2</Content>
<Resource>Fonts/Hind-Edited.otf,64</Resource>
<Color A="1" B="0.784313738" G="0.784313738" R="0.784313738"/>
</c:Text>
<c:Transform>
<Position X="0" Y="0" Z="-8.43336147e-06"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="SniperBoost">
@@ -224,15 +224,6 @@
</Components>
<Children/>
</Entity>
<Entity name="BoostShareEffectSpawner">
<Components>
<c:Spawner>
<EntityFile>Schema/Entities/AmmoShareEffectView.xml</EntityFile>
</c:Spawner>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
@@ -218,6 +218,17 @@
</Entity>
</Children>
</Entity>
<Entity name="FriendlyBoostAttachment">
<Components>
<c:Spawner>
<EntityFile>Schema/Entities/FriendlyBoostBlueHUD.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="-0.000110394583" Y="-0.0960000008" Z="6.07890324e-05"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="WeaponOrigin">
@@ -10,6 +10,7 @@ void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWr
void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt)
{
CheckBoost(cWeapon, wi);
// Decrement reload timer
Field<double> reloadTimer = cWeapon["ReloadTimer"];
reloadTimer = glm::max(0.0, reloadTimer - dt);
@@ -518,3 +519,148 @@ Camera DefenderWeaponBehaviour::cameraFromEntity(EntityWrapper camera)
cam.SetOrientation(glm::quat((const glm::vec3&)cTransform["Orientation"]));
return cam;
}
void DefenderWeaponBehaviour::CheckBoost(ComponentWrapper cWeapon, WeaponInfo& wi)
{
// Only check ammo client side
if (!IsClient) {
return;
}
// Only handle ammo check for the local player
if (wi.Player != LocalPlayer) {
return;
}
// Make sure the player isn't checking from the grave
if (!wi.Player.Valid()) {
return;
}
// 3D-pick middle of screen
Rectangle viewport = m_Renderer->GetViewportSize();
glm::vec2 centerScreen(viewport.Width / 2, viewport.Height / 2);
// TODO: Some horizontal spread
PickData pickData = m_Renderer->Pick(centerScreen);
EntityWrapper victim(m_World, pickData.Entity);
if (!victim.Valid()) {
return;
}
// Don't let us somehow shoot ourselves in the foot
if (victim == LocalPlayer) {
return;
}
// Only care about players being hit
if (!victim.HasComponent("Player")) {
victim = victim.FirstParentWithComponent("Player");
}
if (!victim.Valid()) {
return;
}
// If friendly fire, reduce damage to 0 (needed to make Boosts, Ammosharing work)
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
EntityWrapper friendlyBoostHudSpawner = wi.FirstPersonPlayerModel.FirstChildByName("FriendlyBoostAttachment");
if (friendlyBoostHudSpawner.Valid()) {
EntityWrapper assaultBoost = victim.FirstChildByName("BoostAssault");
EntityWrapper defenderBoost = victim.FirstChildByName("BoostDefender");
EntityWrapper sniperBoost = victim.FirstChildByName("BoostSniper");
auto children = m_World->GetDirectChildren(friendlyBoostHudSpawner.ID);
if (children.first == children.second) {
if (friendlyBoostHudSpawner.HasComponent("Spawner")) {
EntityWrapper friendlyBoostHud = SpawnerSystem::Spawn(friendlyBoostHudSpawner, friendlyBoostHudSpawner);
if (friendlyBoostHud.Valid()) {
EntityWrapper assaultBoostEntity = friendlyBoostHud.FirstChildByName("AssaultBoost");
if (assaultBoostEntity.Valid()) {
EntityWrapper active = assaultBoostEntity.FirstChildByName("Active");
if (active.HasComponent("Text")) {
if (assaultBoost.Valid()) {
(Field<bool>)active["Text"]["Visible"] = true;
} else {
(Field<bool>)active["Text"]["Visible"] = false;
}
}
}
EntityWrapper defenderBoostEntity = friendlyBoostHud.FirstChildByName("DefenderBoost");
if (defenderBoostEntity.Valid()) {
EntityWrapper active = defenderBoostEntity.FirstChildByName("Active");
if (active.HasComponent("Text")) {
if (defenderBoost.Valid()) {
(Field<bool>)active["Text"]["Visible"] = true;
} else {
(Field<bool>)active["Text"]["Visible"] = false;
}
}
}
EntityWrapper sniperBoostEntity = friendlyBoostHud.FirstChildByName("SniperBoost");
if (sniperBoostEntity.Valid()) {
EntityWrapper active = sniperBoostEntity.FirstChildByName("Active");
if (active.HasComponent("Text")) {
if (sniperBoost.Valid()) {
(Field<bool>)active["Text"]["Visible"] = true;
} else {
(Field<bool>)active["Text"]["Visible"] = false;
}
}
}
}
}
} else {
EntityWrapper friendlyBoostHud = friendlyBoostHudSpawner.FirstChildByName("FriendlyBoostHUD");
if (friendlyBoostHud.Valid()) {
if (friendlyBoostHud.HasComponent("Lifetime")) {
(Field<double>)friendlyBoostHud["Lifetime"]["Lifetime"] = 0.5;
}
EntityWrapper assaultBoostEntity = friendlyBoostHud.FirstChildByName("AssaultBoost");
if (assaultBoostEntity.Valid()) {
EntityWrapper active = assaultBoostEntity.FirstChildByName("Active");
if (active.HasComponent("Text")) {
if (assaultBoost.Valid()) {
(Field<bool>)active["Text"]["Visible"] = true;
} else {
(Field<bool>)active["Text"]["Visible"] = false;
}
}
}
EntityWrapper defenderBoostEntity = friendlyBoostHud.FirstChildByName("DefenderBoost");
if (defenderBoostEntity.Valid()) {
EntityWrapper active = defenderBoostEntity.FirstChildByName("Active");
if (active.HasComponent("Text")) {
if (defenderBoost.Valid()) {
(Field<bool>)active["Text"]["Visible"] = true;
} else {
(Field<bool>)active["Text"]["Visible"] = false;
}
}
}
EntityWrapper sniperBoostEntity = friendlyBoostHud.FirstChildByName("SniperBoost");
if (sniperBoostEntity.Valid()) {
EntityWrapper active = sniperBoostEntity.FirstChildByName("Active");
if (active.HasComponent("Text")) {
if (sniperBoost.Valid()) {
(Field<bool>)active["Text"]["Visible"] = true;
} else {
(Field<bool>)active["Text"]["Visible"] = false;
}
}
}
}
}
}
}
}