Compare commits
4 Commits
Dirtybit
...
Defender-v2
| Author | SHA1 | Date | |
|---|---|---|---|
| f31440b022 | |||
| 007dc2aace | |||
| b2eee10602 | |||
| e4c6a19c38 |
@@ -22,6 +22,7 @@
|
||||
#include "../Core/ELockMouse.h"
|
||||
#include "../Core/EFileDropped.h"
|
||||
#include "../Rendering/Texture.h"
|
||||
#include "Game/Events/ESpawnerSpawn.h"
|
||||
|
||||
class EditorGUI
|
||||
{
|
||||
|
||||
@@ -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,22 @@ 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;
|
||||
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);
|
||||
|
||||
// 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);
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -49,5 +49,6 @@
|
||||
<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:schema>
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -6,16 +6,12 @@
|
||||
<Origin X="0" Y="0.772000015" Z="0"/>
|
||||
<Size X="1" Y="1.60000002" Z="1"/>
|
||||
</c:AABB>
|
||||
<c:AssaultWeapon>
|
||||
<Slot>
|
||||
<Secondary/>
|
||||
</Slot>
|
||||
</c:AssaultWeapon>
|
||||
<c:Collidable/>
|
||||
<c:DefenderWeapon>
|
||||
<TimeSinceLastFire>1.6944730461160304</TimeSinceLastFire>
|
||||
<TimeSinceLastFire>102.85760837900634</TimeSinceLastFire>
|
||||
</c:DefenderWeapon>
|
||||
<c:DoubleJump/>
|
||||
<c:SidearmWeapon/>
|
||||
<c:Health/>
|
||||
<c:Physics>
|
||||
<Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/>
|
||||
@@ -372,7 +368,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName1>Idle</AnimationName1>
|
||||
<Time1>0.67172915251515519</Time1>
|
||||
<Time1>1.8348644854054612</Time1>
|
||||
<Speed1>1</Speed1>
|
||||
<AnimationName2></AnimationName2>
|
||||
<AnimationName3></AnimationName3>
|
||||
@@ -386,25 +382,37 @@
|
||||
<Children>
|
||||
<Entity name="PrimaryAttachment">
|
||||
<Components>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/DefenderWeaponView.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform/>
|
||||
<c:BoneAttachment>
|
||||
<BoneName>R_Arm_Weapon_Joint</BoneName>
|
||||
</c:BoneAttachment>
|
||||
<c:WeaponAttachment>
|
||||
<Weapon>DefenderWeapon</Weapon>
|
||||
</c:WeaponAttachment>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/DefenderWeaponView.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform>
|
||||
<Position X="0.120430619" Y="-0.229639441" Z="-0.181454554"/>
|
||||
<Orientation X="0.0104045719" Y="-0.00268170005" Z="0.0428441055"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="SecondaryAttachment">
|
||||
<Components>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/AssaultWeaponView.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform/>
|
||||
<c:BoneAttachment>
|
||||
<BoneName>R_Arm_Weapon_Joint</BoneName>
|
||||
</c:BoneAttachment>
|
||||
<c:WeaponAttachment>
|
||||
<Weapon>AssaultWeapon</Weapon>
|
||||
<Weapon>SidearmWeapon</Weapon>
|
||||
</c:WeaponAttachment>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/SidearmWeaponView.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform>
|
||||
<Position X="0.120430619" Y="-0.229639441" Z="-0.181454554"/>
|
||||
<Orientation X="0.0104045719" Y="-0.00268170005" Z="0.0428441055"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
@@ -430,6 +438,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName1>Idle</AnimationName1>
|
||||
<Time1>0.013134522267137072</Time1>
|
||||
<Speed1>1</Speed1>
|
||||
<AnimationName2></AnimationName2>
|
||||
<AnimationName3></AnimationName3>
|
||||
@@ -449,31 +458,37 @@
|
||||
<Children>
|
||||
<Entity name="PrimaryAttachment">
|
||||
<Components>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/DefenderWeaponWorld.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform/>
|
||||
<c:WeaponAttachment>
|
||||
<Weapon>DefenderWeapon</Weapon>
|
||||
<Person>
|
||||
<ThirdPerson/>
|
||||
</Person>
|
||||
</c:WeaponAttachment>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/DefenderWeaponWorld.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="SecondaryAttachment">
|
||||
<Components>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/AssaultWeaponWorld.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform/>
|
||||
<c:BoneAttachment>
|
||||
<BoneName>R_Arm_Weapon_Joint</BoneName>
|
||||
</c:BoneAttachment>
|
||||
<c:WeaponAttachment>
|
||||
<Weapon>AssaultWeapon</Weapon>
|
||||
<Weapon>SidearmWeapon</Weapon>
|
||||
<Person>
|
||||
<ThirdPerson/>
|
||||
</Person>
|
||||
</c:WeaponAttachment>
|
||||
<c:Spawner>
|
||||
<EntityFile>Schema/Entities/SidearmWeaponWorld.xml</EntityFile>
|
||||
</c:Spawner>
|
||||
<c:Transform>
|
||||
<Position X="0.156846598" Y="1.03287792" Z="-0.216207206"/>
|
||||
<Orientation X="-0.0626498386" Y="-0.0301200207" Z="0.12067578"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
|
||||
@@ -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>
|
||||
@@ -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,88 @@
|
||||
<?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:AmmunitionHUD/>
|
||||
<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: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"/>
|
||||
<Scale X="0.0399999991" Y="0.0399999991" Z="0.0399999991"/>
|
||||
<Orientation X="0" Y="0" Z="1.5710001"/>
|
||||
</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>
|
||||
@@ -52,6 +52,7 @@
|
||||
<xs:element ref="c:Button" minOccurs="0"/>
|
||||
<xs:element ref="c:WeaponAttachment" minOccurs="0"/>
|
||||
<xs:element ref="c:DefenderWeapon" minOccurs="0"/>
|
||||
<xs:element ref="c:SidearmWeapon" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@@ -33,8 +33,8 @@ void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int
|
||||
va_end(args);
|
||||
|
||||
if (logLevel == LOG_LEVEL_ERROR) {
|
||||
//std::cerr << file << ":" << line << " " << func << std::endl;
|
||||
//std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||
std::cerr << file << ":" << line << " " << func << std::endl;
|
||||
std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||
} else {
|
||||
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -17,6 +17,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"
|
||||
@@ -124,6 +125,7 @@ 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);
|
||||
|
||||
@@ -6,36 +6,32 @@ void DefenderWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWr
|
||||
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();
|
||||
|
||||
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);
|
||||
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);
|
||||
fireShell(cWeapon, wi);
|
||||
}
|
||||
}
|
||||
|
||||
void DefenderWeaponBehaviour::OnCeasePrimaryFire(WeaponInfo& wi)
|
||||
void DefenderWeaponBehaviour::OnCeasePrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi)
|
||||
{
|
||||
ComponentWrapper cWeapon = wi.GetComponent();
|
||||
cWeapon["IsFiring"] = false;
|
||||
}
|
||||
|
||||
bool DefenderWeaponBehaviour::OnInputCommand(WeaponInfo& wi, const Events::InputCommand& e)
|
||||
bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e)
|
||||
{
|
||||
if (e.Command == "SpecialAbility" && IsServer) {
|
||||
EntityWrapper attachment = wi.Player.FirstChildByName("ShieldAttachment");
|
||||
@@ -51,16 +47,8 @@ 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;
|
||||
}
|
||||
|
||||
void DefenderWeaponBehaviour::fireShell(WeaponInfo& wi)
|
||||
{
|
||||
ComponentWrapper cWeapon = wi.GetComponent();
|
||||
|
||||
cWeapon["TimeSinceLastFire"] = 0.0;
|
||||
int numPellets = cWeapon["NumPellets"];
|
||||
float spreadAngle = cWeapon["SpreadAngle"];
|
||||
@@ -95,13 +83,13 @@ 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,18 +148,6 @@ void DefenderWeaponBehaviour::dealDamage(WeaponInfo& wi, glm::vec3 direction, do
|
||||
LOG_DEBUG("Damage: %f", damage);
|
||||
}
|
||||
|
||||
float DefenderWeaponBehaviour::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;
|
||||
}
|
||||
}
|
||||
|
||||
Camera DefenderWeaponBehaviour::cameraFromEntity(EntityWrapper camera)
|
||||
{
|
||||
ComponentWrapper cTransform = camera["Transform"];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user