Merge commit '0e8b97dbbade6bb39c6f2b8af6c1cfc43ce67cde' into ScoreBoard

# Conflicts:
#	resources/Schema/Entities/Player.xml
#	src/Game/Game.cpp
This commit is contained in:
Tleety
2016-03-03 13:22:28 +01:00
30 changed files with 753 additions and 177 deletions
+1
View File
@@ -27,6 +27,7 @@ struct EntityWrapper
bool HasComponent(const std::string& componentType);
void AttachComponent(const char* componentName);
EntityWrapper Parent();
EntityWrapper FirstParentByName(const std::string& parentEntityName);
EntityWrapper FirstChildByName(const std::string& name);
EntityWrapper FirstParentWithComponent(const std::string& componentType);
EntityWrapper Clone(EntityWrapper parent = EntityWrapper::Invalid);
+1
View File
@@ -22,6 +22,7 @@
#include "../Core/ELockMouse.h"
#include "../Core/EFileDropped.h"
#include "../Rendering/Texture.h"
#include "Game/Events/ESpawnerSpawn.h"
class EditorGUI
{
@@ -1,17 +0,0 @@
#ifndef AmmunitionHUDSystem_h__
#define AmmunitionHUDSystem_h__
#include "../../Engine/Core/System.h"
#include "../../Engine/GLM.h"
class AmmunitionHUDSystem : public ImpureSystem
{
public:
AmmunitionHUDSystem(SystemParams params)
: System(params)
{ }
virtual void Update(double dt) override;
};
#endif
+19
View File
@@ -0,0 +1,19 @@
#ifndef AmmunitionHUDSystem_h__
#define AmmunitionHUDSystem_h__
#include <boost/lexical_cast.hpp>
#include "../../Engine/Core/System.h"
#include "../../Engine/GLM.h"
class TextFieldReader : public PureSystem
{
public:
TextFieldReader(SystemParams params)
: System(params)
, PureSystem("TextFieldReader")
{ }
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cTextFieldReader, double dt) override;
};
#endif
@@ -1,7 +1,6 @@
#include "WeaponBehaviour.h"
#include "Collision/Collision.h"
#include "Core/EPlayerDamage.h"
#include "Rendering/ESetCamera.h"
class DefenderWeaponBehaviour : public WeaponBehaviour<DefenderWeaponBehaviour>
{
@@ -10,29 +9,24 @@ public:
: System(systemParams)
, WeaponBehaviour(systemParams, "DefenderWeapon", renderer, collisionOctree)
, m_RandomEngine(m_RandomDevice())
{
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &DefenderWeaponBehaviour::OnSetCamera);
}
{ }
void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) override;
void UpdateWeapon(WeaponInfo& wi, double dt) override;
void OnPrimaryFire(WeaponInfo& wi) override;
void OnCeasePrimaryFire(WeaponInfo& wi) override;
bool OnInputCommand(WeaponInfo& wi, const Events::InputCommand& e) override;
void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) override;
void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override;
void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override;
void OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) override;
bool OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) override;
private:
std::random_device m_RandomDevice;
std::mt19937 m_RandomEngine;
EntityWrapper m_CurrentCamera;
EventRelay<DefenderWeaponBehaviour, Events::SetCamera> m_ESetCamera;
bool OnSetCamera(const Events::SetCamera& e);
// Weapon functions
void fireShell(WeaponInfo& wi);
void dealDamage(WeaponInfo& wi, glm::vec3 direction, double damage);
void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi);
void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage);
bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi);
// Utility
float traceRayDistance(glm::vec3 origin, glm::vec3 direction);
Camera cameraFromEntity(EntityWrapper camera);
};
@@ -0,0 +1,33 @@
#include "WeaponBehaviour.h"
#include "Collision/Collision.h"
#include "Core/EPlayerDamage.h"
class SidearmWeaponBehaviour : public WeaponBehaviour<SidearmWeaponBehaviour>
{
public:
SidearmWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree)
: System(systemParams)
, WeaponBehaviour(systemParams, "SidearmWeapon", renderer, collisionOctree)
, m_RandomEngine(m_RandomDevice())
{ }
void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) override;
void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) override;
void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override;
void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) override;
void OnEquip(ComponentWrapper cWeapon, WeaponInfo& wi) override;
void OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) override;
private:
std::random_device m_RandomDevice;
std::mt19937 m_RandomEngine;
// Weapon functions
void fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi);
//void dealDamage(WeaponInfo& wi, glm::vec3 direction, double damage);
// Utility
bool canFire(ComponentWrapper cWeapon);
bool playerInFirstPerson(EntityWrapper player);
//float traceRayDistance(glm::vec3 origin, glm::vec3 direction);
};
+98 -31
View File
@@ -7,6 +7,7 @@
#include "Collision/EntityAABB.h"
#include "Input/EInputCommand.h"
#include "Systems/SpawnerSystem.h"
#include "Rendering/ESetCamera.h"
template <typename ETYPE>
class WeaponBehaviour : public PureSystem
@@ -21,41 +22,81 @@ public:
, m_CollisionOctree(collisionOctree)
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &WeaponBehaviour::_OnInputCommand)
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &WeaponBehaviour::_OnSetCamera)
}
virtual ~WeaponBehaviour() = default;
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt) override
{
auto weapon = getActiveWeapon(entity);
if (!weapon) {
return;
} else {
UpdateWeapon(*weapon, dt);
UpdateWeapon(cWeapon, *weapon, dt);
}
}
protected:
struct WeaponInfo
{
std::string WeaponComponent;
EntityWrapper Player;
EntityWrapper WeaponEntity;
EntityWrapper FirstPersonEntity;
EntityWrapper ThirdPersonEntity;
ComponentWrapper GetComponent() { return WeaponEntity[WeaponComponent]; }
};
IRenderer* m_Renderer;
EntityWrapper m_CurrentCamera;
Octree<EntityAABB>* m_CollisionOctree;
std::unordered_map<EntityWrapper, WeaponInfo> m_ActiveWeapons;
virtual void UpdateWeapon(WeaponInfo& wi, double dt) { }
virtual void OnPrimaryFire(WeaponInfo& wi) { }
virtual void OnCeasePrimaryFire(WeaponInfo& wi) { }
virtual void OnReload(WeaponInfo& wi) { }
virtual bool OnInputCommand(WeaponInfo& wi, const Events::InputCommand& e) { return false; }
virtual void UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { }
virtual void OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { }
virtual void OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { }
virtual void OnReload(ComponentWrapper cWeapon, WeaponInfo& wi) { }
virtual void OnEquip(ComponentWrapper cWeapon, WeaponInfo& wi) { }
virtual void OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi) { }
virtual bool OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) { return false; }
bool isPlayerInFirstPerson(EntityWrapper player)
{
if (!m_CurrentCamera.Valid()) {
return false;
} else {
return m_CurrentCamera == player || m_CurrentCamera.IsChildOf(player);
}
}
// Returns wi.FirstPersonEntity or wi.ThirdPersonEntity depending on
// if the player is in first person mode or not.
EntityWrapper getRelevantWeaponModelEntity(WeaponInfo& wi)
{
if (isPlayerInFirstPerson(wi.Player)) {
return wi.FirstPersonEntity;
} else {
return wi.ThirdPersonEntity;
}
}
float traceRayDistance(glm::vec3 origin, glm::vec3 direction)
{
float distance;
glm::vec3 pos;
auto entity = Collision::EntityFirstHitByRay(Ray(origin, direction), m_CollisionOctree, distance, pos);
if (entity) {
return distance;
} else {
return 100.f;
}
}
private:
EventRelay<ETYPE, Events::SetCamera> m_ESetCamera;
bool _OnSetCamera(const Events::SetCamera& e)
{
m_CurrentCamera = e.CameraEntity;
return true;
}
EventRelay<ETYPE, Events::InputCommand> m_EInputCommand;
bool _OnInputCommand(const Events::InputCommand& e)
{
@@ -70,15 +111,19 @@ private:
}
// Make sure the player has this weapon
auto weapon = getWeaponComponent(player);
if (!weapon) {
auto cWeapon = getWeaponComponent(player);
if (!cWeapon) {
return false;
}
// Weapon selection
if (e.Command == "SelectWeapon") {
if (static_cast<ComponentInfo::EnumType>(e.Value) == static_cast<ComponentInfo::EnumType>((*weapon)["Slot"])) {
selectWeapon(player);
if (e.Value > 0) {
if (static_cast<ComponentInfo::EnumType>(e.Value) == static_cast<ComponentInfo::EnumType>((*cWeapon)["Slot"])) {
selectWeapon(*cWeapon, player);
} else {
holsterWeapon(*cWeapon, player);
}
}
}
@@ -91,18 +136,18 @@ private:
// Fire
if (e.Command == "PrimaryFire") {
if (e.Value > 0) {
OnPrimaryFire(*activeWeapon);
OnPrimaryFire(*cWeapon, *activeWeapon);
} else {
OnCeasePrimaryFire(*activeWeapon);
OnCeasePrimaryFire(*cWeapon, *activeWeapon);
}
}
// Reload
if (e.Command == "Reload" && e.Value != 0) {
OnReload(*activeWeapon);
OnReload(*cWeapon, *activeWeapon);
}
return OnInputCommand(*activeWeapon, e);
return OnInputCommand(*cWeapon, *activeWeapon, e);
}
boost::optional<ComponentWrapper> getWeaponComponent(EntityWrapper player)
@@ -129,8 +174,13 @@ private:
return activeWeapon;
}
void selectWeapon(EntityWrapper player)
void selectWeapon(ComponentWrapper cWeapon, EntityWrapper player)
{
// Don't reselect weapon if it's already active
if (getActiveWeapon(player)) {
return;
}
// Find the weapon attachments matching the weapon type
std::vector<EntityWrapper> weaponAttachments = player.ChildrenWithComponent("WeaponAttachment");
EntityWrapper firstPersonAttachment;
@@ -152,14 +202,6 @@ private:
return;
}
// Purge other weapon entities
for (auto& attachment : weaponAttachments) {
//if (attachment == firstPersonAttachment || attachment == thirdPersonAttachment) {
// continue;
//}
attachment.DeleteChildren();
}
// Spawn the weapon(s)
EntityWrapper firstPersonWeapon;
EntityWrapper thirdPersonWeapon;
@@ -170,11 +212,36 @@ private:
thirdPersonWeapon = SpawnerSystem::Spawn(thirdPersonAttachment, thirdPersonAttachment);
}
m_ActiveWeapons[player].WeaponComponent = m_ComponentType;
m_ActiveWeapons[player].Player = player;
m_ActiveWeapons[player].WeaponEntity = player;
m_ActiveWeapons[player].FirstPersonEntity = firstPersonWeapon;
m_ActiveWeapons[player].ThirdPersonEntity = thirdPersonWeapon;
WeaponInfo& wi = m_ActiveWeapons[player];
wi.Player = player;
wi.WeaponEntity = player;
wi.FirstPersonEntity = firstPersonWeapon;
wi.ThirdPersonEntity = thirdPersonWeapon;
OnEquip(cWeapon, wi);
}
void holsterWeapon(ComponentWrapper cWeapon, EntityWrapper player)
{
auto activeWeapon = getActiveWeapon(player);
if (!activeWeapon) {
return;
}
WeaponInfo& wi = *activeWeapon;
// Send holster event
OnHolster(cWeapon, wi);
// Delete weapon entities
if (wi.FirstPersonEntity.Valid()) {
m_World->DeleteEntity(wi.FirstPersonEntity.ID);
}
if (wi.ThirdPersonEntity.Valid()) {
m_World->DeleteEntity(wi.ThirdPersonEntity.ID);
}
// Make weapon inactive
m_ActiveWeapons.erase(player);
}
};
+2 -1
View File
@@ -45,7 +45,7 @@
<xs:include schemaLocation="Components/Sprite.xsd"/>
<xs:include schemaLocation="Components/Shielded.xsd"/>
<xs:include schemaLocation="Components/CapturePointHUD.xsd"/>
<xs:include schemaLocation="Components/AmmunitionHUD.xsd"/>
<xs:include schemaLocation="Components/TextFieldReader.xsd"/>
<xs:include schemaLocation="Components/Menu.xsd"/>
<xs:include schemaLocation="Components/KillFeed.xsd"/>
<xs:include schemaLocation="Components/Page.xsd"/>
@@ -55,6 +55,7 @@
<xs:include schemaLocation="Components/DoubleJump.xsd"/>
<xs:include schemaLocation="Components/WeaponAttachment.xsd"/>
<xs:include schemaLocation="Components/DefenderWeapon.xsd"/>
<xs:include schemaLocation="Components/SidearmWeapon.xsd"/>
<xs:include schemaLocation="Components/CapturePointGameMode.xsd"/>
<xs:include schemaLocation="Components/CapturePointArrowHUD.xsd"/>
<xs:include schemaLocation="Components/FloatingEffect.xsd"/>
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<AmmunitionHUD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="AmmunitionHUD.xsd">
</AmmunitionHUD>
@@ -1,10 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:include schemaLocation="../Types/TeamEnum.xsd"/>
<xs:element name="AmmunitionHUD">
<xs:annotation>
<xs:documentation>Hud element for tracking ammunition from parent with AssaultWeapon component. Child with the name "MagazineAmmo" tracks clip ammunition. Child with the name "Ammo" tracks ammo.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
@@ -11,6 +11,8 @@
<ViewPunch>0.01</ViewPunch>
<ReloadTime>0.5</ReloadTime>
<Slot><Primary/></Slot>
<IsFiring>false</IsFiring>
<TimeSinceLastFire>0</TimeSinceLastFire>
<TriggerHeld>false</TriggerHeld>
<FireCooldown>0</FireCooldown>
<IsReloading>false</IsReloading>
<ReloadTimer>0</ReloadTimer>
</DefenderWeapon>
+16 -2
View File
@@ -4,6 +4,18 @@
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:include schemaLocation="../Types/WeaponSlotEnum.xsd"/>
<xs:complexType name="WeaponStateEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="Idle" type="t:int" fixed="0" minOccurs="0"/>
<xs:element name="Firing" type="t:int" fixed="1" minOccurs="0"/>
<xs:element name="Reloading" type="t:int" fixed="2" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="DefenderWeapon">
<xs:complexType>
<xs:all>
@@ -36,8 +48,10 @@
<xs:annotation><xs:documentation>Time it takes to load ONE SHELL into the weapon in seconds</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Slot" type="WeaponSlotEnum" minOccurs="0"/>
<xs:element name="IsFiring" type="t:bool" minOccurs="0"/>
<xs:element name="TimeSinceLastFire" type="t:double" minOccurs="0"/>
<xs:element name="TriggerHeld" type="t:bool" minOccurs="0"/>
<xs:element name="FireCooldown" type="t:double" minOccurs="0"/>
<xs:element name="IsReloading" type="t:bool" minOccurs="0"/>
<xs:element name="ReloadTimer" type="t:double" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<SidearmWeapon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SidearmWeapon.xsd">
<MagazineAmmo>16</MagazineAmmo>
<MagazineSize>16</MagazineSize>
<BaseDamage>20</BaseDamage>
<RPM>500</RPM>
<Automatic>false</Automatic>
<ViewPunch>0.01</ViewPunch>
<ReloadTime>0.5</ReloadTime>
<EquipTime>0.5</EquipTime>
<Slot><Secondary/></Slot>
<TriggerHeld>false</TriggerHeld>
<FireCooldown>0</FireCooldown>
<IsReloading>false</IsReloading>
<ReloadTimer>0</ReloadTimer>
</SidearmWeapon>
@@ -0,0 +1,52 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:include schemaLocation="../Types/WeaponSlotEnum.xsd"/>
<xs:complexType name="WeaponStateEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="Idle" type="t:int" fixed="0" minOccurs="0"/>
<xs:element name="Firing" type="t:int" fixed="1" minOccurs="0"/>
<xs:element name="Reloading" type="t:int" fixed="2" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="SidearmWeapon">
<xs:complexType>
<xs:all>
<xs:element name="MagazineAmmo" type="t:int" minOccurs="0">
<xs:annotation><xs:documentation>Ammo currently loaded into the magazine</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="MagazineSize" type="t:int" minOccurs="0">
<xs:annotation><xs:documentation>Max number of rounds in a magazine</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="BaseDamage" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Damage dealt if all shotgun pellets hit</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="RPM" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Rate of fire in rounds per minute</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Automatic" type="t:bool" minOccurs="0"/>
<xs:element name="ViewPunch" type="t:float" minOccurs="0">
<xs:annotation><xs:documentation>View punch in radians for each shell fired</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="ReloadTime" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Time it takes to load ONE SHELL into the weapon in seconds</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="EquipTime" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Time it takes from selecting the weapon until it's ready to fire</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Slot" type="WeaponSlotEnum" minOccurs="0"/>
<xs:element name="TriggerHeld" type="t:bool" minOccurs="0"/>
<xs:element name="FireCooldown" type="t:double" minOccurs="0"/>
<xs:element name="IsReloading" type="t:bool" minOccurs="0"/>
<xs:element name="ReloadTimer" type="t:double" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<TextFieldReader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="TextFieldReader.xsd">
<ParentEntityName></ParentEntityName>
<ComponentType></ComponentType>
<Field></Field>
</TextFieldReader>
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="TextFieldReader">
<xs:annotation><xs:documentation>Reads a value from a specific field of a compoent of parent entity and writes it to the Text component on this entity.</xs:documentation></xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="ParentEntityName" type="t:string" minOccurs="0">
<xs:annotation><xs:documentation>The name of the parent entity to read the component field from. Leave empty to read from this entity.</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="ComponentType" type="t:string" minOccurs="0">
<xs:annotation><xs:documentation>The component type to read the field value from.</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Field" type="t:string" minOccurs="0">
<xs:annotation><xs:documentation>The field name to read the value from.</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -1,16 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="WeaponModel" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Entity name="DefenderWeapon" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:BoneAttachment>
<BoneName>R_Arm_Weapon_Joint</BoneName>
<PositionOffset X="0" Y="0.0480000004" Z="-0.183000013"/>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Weapons/Blue/DefenderGunBlue.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0.120430306" Y="0.775375426" Z="1.36542225"/>
<Position X="0" Y="0.0350000001" Z="-0.295000017"/>
</c:Transform>
</Components>
@@ -37,7 +33,6 @@
</Entity>
<Entity name="AmmunitionHUD">
<Components>
<c:AmmunitionHUD/>
<c:Transform>
<Position X="-0.0490000024" Y="0.0520000011" Z="-0.063000001"/>
<Scale X="0.400000006" Y="0.400000006" Z="0.400000006"/>
@@ -65,8 +60,13 @@
<Children>
<Entity name="MagazineAmmo">
<Components>
<c:TextFieldReader>
<ParentEntityName>Player</ParentEntityName>
<ComponentType>DefenderWeapon</ComponentType>
<Field>MagazineAmmo</Field>
</c:TextFieldReader>
<c:Text>
<Content>32</Content>
<Content>0</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="3.92156863" G="1.17647064" R="0"/>
</c:Text>
@@ -78,8 +78,13 @@
</Entity>
<Entity name="Ammo">
<Components>
<c:TextFieldReader>
<ParentEntityName>Player</ParentEntityName>
<ComponentType>DefenderWeapon</ComponentType>
<Field>Ammo</Field>
</c:TextFieldReader>
<c:Text>
<Content>360</Content>
<Content>0</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="3.92156863" G="1.17647064" R="0"/>
</c:Text>
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<GlowMap></GlowMap>
<Color A="1" B="0" G="0" R="1"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0.690654039" Z="2.69841838"/>
<Scale X="2" Y="0.0260000005" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
+43
View File
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform>
<Scale X="0" Y="1" Z="1"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<GlowMap></GlowMap>
<Color A="1" B="0" G="0" R="1"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-50"/>
<Scale X="100" Y="0.0260000005" Z="0"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<GlowMap></GlowMap>
<Color A="1" B="0" G="0" R="1"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-50"/>
<Scale X="100" Y="0.0260000005" Z="0"/>
<Orientation X="0" Y="-1.57099998" Z="3.1400001"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="SidearmWeapon" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Model>
<Resource>Models/Weapons/SecondaryWeapon.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="-0.00200000009" Y="0.0600000024" Z="-0.297000021"/>
</c:Transform>
</Components>
<Children>
<Entity name="WeaponMuzzle">
<Components>
<c:Spawner>
<EntityFile>Schema/Entities/Ray2Red.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="0" Y="0.105000004" Z="-0.256000012"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="AmmunitionHUD">
<Components>
<c:TextFieldReader>
<ParentEntityName></ParentEntityName>
<ComponentType></ComponentType>
<Field></Field>
</c:TextFieldReader>
<c:Transform>
<Position X="-0.0300000012" Y="0.077000007" Z="-0.063000001"/>
<Scale X="0.400000006" Y="0.400000006" Z="0.400000006"/>
</c:Transform>
</Components>
<Children>
<Entity name="AmmunitionHUDBackground">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
<GlowMap></GlowMap>
<Color A="0.588235319" B="0" G="0" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.00300000003"/>
<Scale X="0.119999997" Y="0.119999997" Z="0.119999997"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="AmmunitionText">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity name="MagazineAmmo">
<Components>
<c:TextFieldReader>
<ParentEntityName>Player</ParentEntityName>
<ComponentType>SidearmWeapon</ComponentType>
<Field>MagazineAmmo</Field>
</c:TextFieldReader>
<c:Text>
<Content>16</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="3.92156863" G="1.17647064" R="0"/>
</c:Text>
<c:Transform>
<Position X="0" Y="-0.00600000005" Z="0"/>
<Scale X="0.0599999987" Y="0.0599999987" Z="0.0599999987"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Infinity!">
<Components>
<c:Text>
<Content>8</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="3.92156863" G="1.17647064" R="0"/>
</c:Text>
<c:Transform>
<Position X="0.0150000006" Y="-0.029000001" Z="0"/>
<Orientation X="0" Y="0" Z="1.5710001"/>
<Scale X="0.0399999991" Y="0.0399999991" Z="0.0399999991"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="SidearmWeapon" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Model>
<Resource>Models/Weapons/SecondaryWeapon.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="-0.0160000008" Y="0.0800000057" Z="-0.275000006"/>
</c:Transform>
</Components>
<Children>
<Entity name="WeaponMuzzle">
<Components>
<c:Spawner>
<EntityFile>Schema/Entities/RayBlue.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="0.0123999491" Y="0.102453232" Z="-0.273824364"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+2 -1
View File
@@ -43,7 +43,7 @@
<xs:element ref="c:Shield" minOccurs="0"/>
<xs:element ref="c:Shielded" minOccurs="0"/>
<xs:element ref="c:CapturePointHUD" minOccurs="0"/>
<xs:element ref="c:AmmunitionHUD" minOccurs="0"/>
<xs:element ref="c:TextFieldReader" minOccurs="0"/>
<xs:element ref="c:KillFeed" minOccurs="0"/>
<xs:element ref="c:Sprite" minOccurs="0"/>
<xs:element ref="c:AnimationOffset" minOccurs="0"/>
@@ -53,6 +53,7 @@
<xs:element ref="c:WeaponAttachment" minOccurs="0"/>
<xs:element ref="c:AbilityCooldownHUD" minOccurs="0"/>
<xs:element ref="c:DefenderWeapon" minOccurs="0"/>
<xs:element ref="c:SidearmWeapon" minOccurs="0"/>
<xs:element ref="c:CapturePointArrowHUD" minOccurs="0"/>
<xs:element ref="c:BoostIconsHUD" minOccurs="0"/>
<xs:element ref="c:FloatingEffect" minOccurs="0"/>
+12
View File
@@ -34,6 +34,18 @@ EntityWrapper EntityWrapper::Parent()
}
}
EntityWrapper EntityWrapper::FirstParentByName(const std::string& parentEntityName)
{
EntityWrapper entity = *this;
while (entity.Parent().Valid()) {
entity = entity.Parent();
if (entity.Name() == parentEntityName) {
return entity;
}
}
return EntityWrapper::Invalid;
}
EntityWrapper EntityWrapper::FirstChildByName(const std::string& name)
{
return firstChildByNameRecursive(name, this->ID);
+54 -7
View File
@@ -338,6 +338,15 @@ bool EditorGUI::drawComponentNode(EntityWrapper entity, const ComponentInfo& ci)
}
}
if (ci.Name == "Spawner") {
if (ImGui::Button("Activate")) {
Events::SpawnerSpawn e;
e.Spawner = entity;
e.Parent = entity;
m_EventBroker->Publish(e);
}
}
return true;
}
@@ -381,14 +390,52 @@ bool EditorGUI::drawComponentField_Vector(ComponentWrapper &c, const ComponentIn
// Limit scale values to a minimum of 0
return ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, 0.f, std::numeric_limits<float>::max());
} else if (field.Name == "Orientation") {
// Make orentations have a period of 2*Pi
glm::vec3 tempVal = glm::fmod(val, glm::vec3(glm::two_pi<float>()));
if (ImGui::SliderFloat3("", glm::value_ptr(tempVal), 0.f, glm::two_pi<float>())) {
val = tempVal;
return true;
} else {
return false;
//glm::vec3 tempVal = val;
glm::vec3 originalVal = val;
ImVec2 cursorPos = ImGui::GetCursorScreenPos();
glm::tvec3<bool> isSnapping(false, false, false);
bool changed = ImGui::DragFloat3("", glm::value_ptr(val), 0.066666f);
if (changed) {
// Make orentations have a period of 2*Pi
val = glm::fmod(val, glm::vec3(glm::two_pi<float>()));
for (int i = 0; i < 3; i++) {
if (val[i] < 0) {
val[i] += glm::two_pi<float>();
}
}
}
// Snap to angle
//float snapRange = glm::pi<float>() / 15.f;
//float snapAngle = glm::quarter_pi<float>();
//glm::vec3 snap = glm::fmod(val, glm::vec3(snapAngle));
//for (int i = 0; i < 3; i++) {
// isSnapping[i] = glm::abs(snap[i] - (snapRange / 2.f)) < snapRange;
//}
//if (changed && ImGui::IsMouseDown(0)) {
// glm::vec3 change = val - originalVal;
// for (int i = 0; i < 3; i++) {
// if (isSnapping[i] && glm::abs(change[i]) < snapRange) {
// val[i] -= snap[i] - snapRange;
// }
// }
//}
// Draw snapping outline
float width = ImGui::CalcItemWidth() / 3.f;;
float spacing = GImGui->Style.ItemInnerSpacing.x;
for (int i = 0; i < 3; i++) {
if (isSnapping[i]) {
ImVec2 pos = cursorPos + ImVec2(i * (width + spacing), 0.f);
ImRect bb(pos - ImVec2(1, 1), pos + ImVec2(width, 17));
auto window = ImGui::GetCurrentWindow();
const ImU32 col = window->Color(ImGuiCol_HeaderActive);
window->DrawList->AddRect(bb.Min, bb.Max, col, 3.f);
}
}
return changed;
} else {
return ImGui::DragFloat3("", glm::value_ptr(val), 0.1f, std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max());
}
+1 -1
View File
@@ -17,7 +17,7 @@ void Renderer::Initialize()
m_TextPass->Initialize();
/* m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.obj");
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
m_UnitQuad = ResourceManager::Load<Model>(sModels/Core/UnitQuad.obj");
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");*/
m_ImGuiRenderPass = new ImGuiRenderPass(this, m_EventBroker);
+5 -3
View File
@@ -19,6 +19,7 @@
#include "Game/Systems/AmmoPickupSystem.h"
#include "Game/Systems/DamageIndicatorSystem.h"
#include "Game/Systems/Weapon/DefenderWeaponBehaviour.h"
#include "Game/Systems/Weapon/SidearmWeaponBehaviour.h"
#include "Rendering/AnimationSystem.h"
#include "Game/Systems/HealthHUDSystem.h"
#include "Rendering/BoneAttachmentSystem.h"
@@ -26,7 +27,7 @@
#include "../Engine/Core/UniformScaleSystem.h"
#include "Rendering/AnimationSystem.h"
#include "Network/MultiplayerSnapshotFilter.h"
#include "Game/Systems/AmmunitionHUDSystem.h"
#include "Game/Systems/TextFieldReader.h"
#include "Game/Systems/AbilityCooldownHUDSystem.h"
#include "Game/Systems/CapturePointArrowHUDSystem.h"
#include "Game/Systems/KillFeedSystem.h"
@@ -130,13 +131,14 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<SpawnerSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<DefenderWeaponBehaviour>(updateOrderLevel, m_Renderer, m_OctreeCollision);
m_SystemPipeline->AddSystem<SidearmWeaponBehaviour>(updateOrderLevel, m_Renderer, m_OctreeCollision);
m_SystemPipeline->AddSystem<LifetimeSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmoPickupSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmunitionHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<TextFieldReader>(updateOrderLevel);
m_SystemPipeline->AddSystem<AbilityCooldownHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointArrowHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
@@ -146,7 +148,7 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmoPickupSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmunitionHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<TextFieldReader>(updateOrderLevel);
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<BoostSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
-36
View File
@@ -1,36 +0,0 @@
#include "Game/Systems/AmmunitionHUDSystem.h"
void AmmunitionHUDSystem::Update(double dt)
{
//Hud element for tracking ammunition from parent with AssaultWeapon component.Child with the name "MagazineAmmo" tracks clip ammunition.Child with the name "Ammo" tracks ammo.</xs:documentation>
auto ammunitionHUDs = m_World->GetComponents("AmmunitionHUD");
if (ammunitionHUDs == nullptr) {
return;
}
for (auto& ammunitionHUDComponent : *ammunitionHUDs) {
EntityWrapper entity = EntityWrapper(m_World, ammunitionHUDComponent.EntityID);
EntityWrapper playerEntity = entity.FirstParentWithComponent("AssaultWeapon");
if (!playerEntity.Valid()) {
return;
}
EntityWrapper magazineAmmo = entity.FirstChildByName("MagazineAmmo");
if(magazineAmmo.Valid()) {
if(magazineAmmo.HasComponent("Text")) {
(std::string&)magazineAmmo["Text"]["Content"] = std::to_string((int)playerEntity["AssaultWeapon"]["MagazineAmmo"]);
}
}
EntityWrapper ammo = entity.FirstChildByName("Ammo");
if (ammo.Valid()) {
if (ammo.HasComponent("Text")) {
(std::string&)ammo["Text"]["Content"] = std::to_string((int)playerEntity["AssaultWeapon"]["Ammo"]);
}
}
}
}
+46
View File
@@ -0,0 +1,46 @@
#include "Game/Systems/TextFieldReader.h"
void TextFieldReader::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cAmmunitionHUD, double dt)
{
if (!entity.HasComponent("Text")) {
return;
}
// Find the entity to read from
const std::string& parentEntityName = cAmmunitionHUD["ParentEntityName"];
EntityWrapper readEntity = entity;
if (!parentEntityName.empty()) {
readEntity = entity.FirstParentByName(parentEntityName);
if (!readEntity.Valid()) {
return;
}
}
// Find the component to read from
const std::string& componentType = cAmmunitionHUD["ComponentType"];
if (componentType.empty() || !readEntity.HasComponent(componentType)) {
return;
}
ComponentWrapper component = readEntity[componentType];
// Find the field to read from
const std::string& fieldName = cAmmunitionHUD["Field"];
if (fieldName.empty() || component.Info.Fields.count(fieldName) == 0) {
return;
}
const ComponentInfo::Field_t& field = component.Info.Fields.at(fieldName);
std::string& text = entity["Text"]["Content"];
if (field.Type == "int") {
text = boost::lexical_cast<std::string>((const int&)component[fieldName]);
} else if (field.Type == "float") {
text = boost::lexical_cast<std::string>((const float&)component[fieldName]);
} else if (field.Type == "double") {
text = boost::lexical_cast<std::string>((const double&)component[fieldName]);
} else if (field.Type == "bool") {
text = boost::lexical_cast<std::string>((const bool&)component[fieldName]);
} else if (field.Type == "string") {
text = (const std::string&)component[fieldName];
}
}
@@ -2,40 +2,76 @@
void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt)
{
(double&)cWeapon["TimeSinceLastFire"] += dt;
double& fireCooldown = cWeapon["FireCooldown"];
fireCooldown = glm::max(0.0, fireCooldown - dt);
WeaponBehaviour::UpdateComponent(entity, cWeapon, dt);
}
void DefenderWeaponBehaviour::UpdateWeapon(WeaponInfo& wi, double dt)
void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt)
{
ComponentWrapper cWeapon = wi.GetComponent();
double& reloadTimer = cWeapon["ReloadTimer"];
reloadTimer = glm::max(0.0, reloadTimer - dt);
bool isFiring = cWeapon["IsFiring"];
bool cooldownPassed = (double)cWeapon["TimeSinceLastFire"] >= (60.0 / (double)cWeapon["RPM"]);
bool isNotShielding = wi.Player.ChildrenWithComponent("Shield").size() == 0;
if (isFiring && cooldownPassed && isNotShielding) {
fireShell(wi);
double reloadTime = cWeapon["ReloadTime"];
bool& isReloading = cWeapon["IsReloading"];
if (isReloading && reloadTimer <= 0.0) {
int& magAmmo = cWeapon["MagazineAmmo"];
int& magSize = cWeapon["MagazineSize"];
int& ammo = cWeapon["Ammo"];
if (magAmmo < magSize && ammo > 0) {
ammo -= 1;
magAmmo += 1;
reloadTimer = reloadTime;
} else {
isReloading = false;
}
}
if (canFire(cWeapon, wi)) {
fireShell(cWeapon, wi);
}
}
void DefenderWeaponBehaviour::OnPrimaryFire(WeaponInfo& wi)
void DefenderWeaponBehaviour::OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi)
{
ComponentWrapper cWeapon = wi.GetComponent();
cWeapon["IsFiring"] = true;
bool cooldownPassed = (double)cWeapon["TimeSinceLastFire"] >= (60.0 / (double)cWeapon["RPM"]);
bool isNotShielding = wi.Player.ChildrenWithComponent("Shield").size() == 0;
if (cooldownPassed && isNotShielding) {
fireShell(wi);
cWeapon["TriggerHeld"] = true;
if (canFire(cWeapon, wi)) {
fireShell(cWeapon, wi);
}
}
void DefenderWeaponBehaviour::OnCeasePrimaryFire(WeaponInfo& wi)
void DefenderWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi)
{
ComponentWrapper cWeapon = wi.GetComponent();
cWeapon["IsFiring"] = false;
cWeapon["TriggerHeld"] = false;
}
bool DefenderWeaponBehaviour::OnInputCommand(WeaponInfo& wi, const Events::InputCommand& e)
void DefenderWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
{
bool& isReloading = cWeapon["IsReloading"];
if (isReloading) {
return;
}
int& magAmmo = cWeapon["MagazineAmmo"];
int& magSize = cWeapon["MagazineSize"];
if (magAmmo >= magSize) {
return;
}
int& ammo = cWeapon["Ammo"];
if (ammo <= 0) {
return;
}
double reloadTime = cWeapon["ReloadTime"];
double& reloadTimer = cWeapon["ReloadTimer"];
// Start reload
isReloading = true;
reloadTimer = reloadTime;
}
bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e)
{
if (e.Command == "SpecialAbility" && IsServer) {
EntityWrapper attachment = wi.Player.FirstChildByName("ShieldAttachment");
@@ -51,17 +87,23 @@ bool DefenderWeaponBehaviour::OnInputCommand(WeaponInfo& wi, const Events::Input
return false;
}
bool DefenderWeaponBehaviour::OnSetCamera(const Events::SetCamera& e)
void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi)
{
m_CurrentCamera = e.CameraEntity;
return true;
}
cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"];
void DefenderWeaponBehaviour::fireShell(WeaponInfo& wi)
{
ComponentWrapper cWeapon = wi.GetComponent();
// Stop reloading
bool& isReloading = cWeapon["IsReloading"];
isReloading = false;
// Ammo
int& magAmmo = cWeapon["MagazineAmmo"];
if (magAmmo <= 0) {
OnReload(cWeapon, wi);
return;
} else {
magAmmo -= 1;
}
cWeapon["TimeSinceLastFire"] = 0.0;
int numPellets = cWeapon["NumPellets"];
float spreadAngle = cWeapon["SpreadAngle"];
std::uniform_real_distribution<float> randomSpreadAngle(-spreadAngle, spreadAngle);
@@ -95,13 +137,12 @@ void DefenderWeaponBehaviour::fireShell(WeaponInfo& wi)
orientation.x += angles.x;
orientation.y += angles.y;
glm::vec3 trajectory = direction * distance;
dealDamage(wi, direction, pelletDamage);
dealDamage(cWeapon, wi, direction, pelletDamage);
}
}
}
void DefenderWeaponBehaviour::dealDamage(WeaponInfo& wi, glm::vec3 direction, double damage)
void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage)
{
// Only deal damage client side
if (!IsClient) {
@@ -160,16 +201,13 @@ void DefenderWeaponBehaviour::dealDamage(WeaponInfo& wi, glm::vec3 direction, do
LOG_DEBUG("Damage: %f", damage);
}
float DefenderWeaponBehaviour::traceRayDistance(glm::vec3 origin, glm::vec3 direction)
bool DefenderWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi)
{
float distance;
glm::vec3 pos;
auto entity = Collision::EntityFirstHitByRay(Ray(origin, direction), m_CollisionOctree, distance, pos);
if (entity) {
return distance;
} else {
return 100.f;
}
bool triggerHeld = cWeapon["TriggerHeld"];
bool cooldownPassed = (double)cWeapon["FireCooldown"] <= 0.0;
bool isNotShielding = wi.Player.ChildrenWithComponent("Shield").size() == 0;
// TODO: Ammo checks
return triggerHeld && cooldownPassed && isNotShielding;
}
Camera DefenderWeaponBehaviour::cameraFromEntity(EntityWrapper camera)
@@ -0,0 +1,79 @@
#include "Systems/Weapon/SidearmWeaponBehaviour.h"
void SidearmWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cWeapon, double dt)
{
double& cooldown = cWeapon["FireCooldown"];
if (cooldown > 0) {
cooldown -= dt;
if (cooldown < 0) {
cooldown = 0;
}
}
WeaponBehaviour::UpdateComponent(entity, cWeapon, dt);
}
void SidearmWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt)
{
if ((bool)cWeapon["Automatic"] && canFire(cWeapon)) {
fireBullet(cWeapon, wi);
}
}
void SidearmWeaponBehaviour::OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi)
{
cWeapon["TriggerHeld"] = true;
if (canFire(cWeapon)) {
fireBullet(cWeapon, wi);
}
}
void SidearmWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi)
{
cWeapon["TriggerHeld"] = false;
}
void SidearmWeaponBehaviour::OnEquip(ComponentWrapper cWeapon, WeaponInfo& wi)
{
cWeapon["FireCooldown"] = (double)cWeapon["EquipTime"];
}
void SidearmWeaponBehaviour::OnHolster(ComponentWrapper cWeapon, WeaponInfo& wi)
{
// Make sure the trigger is released if weapon is holstered while firing
cWeapon["TriggerHeld"] = false;
// Cancel any reload
cWeapon["IsReloading"] = false;
cWeapon["ReloadTimer"] = 0.0;
LOG_DEBUG("HOLSTER");
}
void SidearmWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi)
{
cWeapon["FireCooldown"] = 60.0 / (double)cWeapon["RPM"];
// Get weapon model based on current person
EntityWrapper weaponModelEntity = getRelevantWeaponModelEntity(wi);
if (!weaponModelEntity.Valid()) {
return;
}
// Tracer
EntityWrapper tracerSpawner = weaponModelEntity.FirstChildByName("WeaponMuzzle");
if (tracerSpawner.Valid()) {
glm::vec3 origin = Transform::AbsolutePosition(tracerSpawner);
glm::vec3 direction = Transform::AbsoluteOrientation(tracerSpawner) * glm::vec3(0, 0, -1);
float distance = traceRayDistance(origin, direction);
EntityWrapper ray = SpawnerSystem::Spawn(tracerSpawner);
((glm::vec3&)ray["Transform"]["Scale"]).z = (distance / 100.f);
}
}
bool SidearmWeaponBehaviour::canFire(ComponentWrapper cWeapon)
{
bool triggerHeld = cWeapon["TriggerHeld"];
double& cooldown = cWeapon["FireCooldown"];
// TODO: Ammo checks
return triggerHeld && cooldown <= 0.0;
}