Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 10cd3bae40 | |||
| 8740e8b77a | |||
| bc227c3d61 | |||
| cca237b33f | |||
| 9bba9e493c | |||
| 2c9c374f51 | |||
| 25a7240962 | |||
| 99cdcdf289 | |||
| f1d78ae790 | |||
| bcc42a8cb7 | |||
| 041c409128 |
@@ -29,7 +29,6 @@ struct EntityWrapper
|
||||
EntityWrapper Parent();
|
||||
EntityWrapper FirstChildByName(const std::string& name);
|
||||
EntityWrapper FirstParentWithComponent(const std::string& componentType);
|
||||
std::vector<EntityWrapper> ChildrenWithComponent(const std::string& componentType);
|
||||
bool IsChildOf(EntityWrapper potentialParent);
|
||||
bool Valid() const;
|
||||
|
||||
@@ -40,7 +39,6 @@ struct EntityWrapper
|
||||
|
||||
private:
|
||||
EntityWrapper firstChildByNameRecursive(const std::string& name, EntityID parent);
|
||||
void childrenWithComponentRecursive(const std::string& componentType, EntityWrapper& entity, std::vector<EntityWrapper>& childrenWithComponent);
|
||||
};
|
||||
|
||||
namespace std
|
||||
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
m_ExtraMemory.push_back((char*)malloc(m_Stride));
|
||||
//We should preferably not enter here to avoid performance issues. Set more numMaxElements in constructor instead.
|
||||
if (!DisableMemoryPool::Value) {
|
||||
LOG_DEBUG("Allocated slots exceed Pool size, extra memory allocated dynamically. Pool size: %u, dynamic size: %u.", m_NumSlots, m_ExtraMemory.size());
|
||||
//LOG_DEBUG("Allocated slots exceed Pool size, extra memory allocated dynamically. Pool size: %u, dynamic size: %u.", m_NumSlots, m_ExtraMemory.size());
|
||||
}
|
||||
return m_ExtraMemory.back();
|
||||
}
|
||||
|
||||
@@ -192,6 +192,8 @@ bool FirstPersonInputController<EventContext>::OnLockMouse(const Events::LockMou
|
||||
|
||||
template <typename EventContext>
|
||||
void FirstPersonInputController<EventContext>::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer) {
|
||||
ImGui::Text(std::to_string(m_AssaultDashCoolDownTimer).c_str());
|
||||
|
||||
m_AssaultDashDoubleTapDeltaTime += dt;
|
||||
m_AssaultDashCoolDownTimer -= dt;
|
||||
//cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work)
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
{
|
||||
// Check if we are trying to add more than the package can fit.
|
||||
if (m_MaxPacketSize < m_Offset + sizeof(T)) {
|
||||
LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for! New size is %i bytes\n", m_MaxPacketSize*2);
|
||||
//LOG_WARNING("Packet AddPrimitive(): You are trying to add more than we have allocated for! New size is %i bytes\n", m_MaxPacketSize*2);
|
||||
resizeData();
|
||||
}
|
||||
memcpy(m_Data + m_Offset, &val, sizeof(T));
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
T ReadPrimitive()
|
||||
{
|
||||
if (m_Offset < m_ReturnDataOffset + sizeof(T)) {
|
||||
LOG_WARNING("Packet PopFrontPrimitive(): You are trying to remove more than what exists in this packet!");
|
||||
//LOG_WARNING("Packet PopFrontPrimitive(): You are trying to remove more than what exists in this packet!");
|
||||
return -1;
|
||||
}
|
||||
T returnValue;
|
||||
|
||||
@@ -20,14 +20,24 @@ public:
|
||||
private:
|
||||
EventRelay<AmmoPickupSystem, Events::TriggerTouch> m_ETriggerTouch;
|
||||
bool OnTriggerTouch(Events::TriggerTouch& e);
|
||||
EventRelay<AmmoPickupSystem, Events::TriggerLeave> m_ETriggerLeave;
|
||||
bool OnTriggerLeave(Events::TriggerLeave& e);
|
||||
|
||||
struct NewAmmoPickup {
|
||||
struct NewPickup {
|
||||
glm::vec3 Pos;
|
||||
double AmmoGain;
|
||||
double RespawnTimer;
|
||||
double DecreaseThisRespawnTimer;
|
||||
EntityID parentID;
|
||||
bool isAmmoPickup;
|
||||
};
|
||||
std::vector<NewAmmoPickup> m_ETriggerTouchVector;
|
||||
struct EntityAtMaxValuePickupStruct {
|
||||
EntityWrapper player;
|
||||
EntityWrapper pickup;
|
||||
};
|
||||
std::vector<NewPickup> m_ETriggerTouchVector;
|
||||
std::vector<EntityAtMaxValuePickupStruct> m_PickupAtMaximum;
|
||||
|
||||
void DoPickup(EntityWrapper &player, EntityWrapper &trigger);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
private:
|
||||
bool m_NetworkEnabled;
|
||||
|
||||
// methods which will take care of specific events
|
||||
// methods which will take care of specific events
|
||||
EventRelay<HealthSystem, Events::PlayerDamage> m_EPlayerDamage;
|
||||
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e);
|
||||
EventRelay<HealthSystem, Events::PlayerHealthPickup> m_EPlayerHealthPickup;
|
||||
@@ -37,6 +37,16 @@ private:
|
||||
|
||||
//vector which will keep track of health changes
|
||||
std::vector<std::tuple<EntityID, double>> m_DeltaHealthVector;
|
||||
struct DeadPlayers {
|
||||
EntityWrapper playerEntity;
|
||||
double timeSinceDeath;
|
||||
DeadPlayers(EntityWrapper entity) : playerEntity(entity) {
|
||||
timeSinceDeath = 0.0;
|
||||
}
|
||||
};
|
||||
std::vector<DeadPlayers> m_DeadPlayers;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -21,6 +21,7 @@ private:
|
||||
{
|
||||
int PlayerID;
|
||||
ComponentInfo::EnumType Team;
|
||||
double timeSinceDeath;
|
||||
};
|
||||
|
||||
bool m_NetworkEnabled = false;
|
||||
@@ -40,4 +41,7 @@ private:
|
||||
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
||||
EventRelay<PlayerSpawnSystem, Events::PlayerDeath> m_OnPlayerDeath;
|
||||
bool OnPlayerDeath(Events::PlayerDeath& e);
|
||||
|
||||
std::vector<SpawnRequest> m_LatePlayersVector;
|
||||
void CheckForLatePlayers(double dt);
|
||||
};
|
||||
@@ -1,14 +1,13 @@
|
||||
#ifndef AssaultWeaponBehaviour_h__
|
||||
#define AssaultWeaponBehaviour_h__
|
||||
|
||||
#include "Sound/EPlaySoundOnEntity.h"
|
||||
#include "Collision/Collision.h"
|
||||
#include "Rendering/AnimationSystem.h"
|
||||
#include "Core/ConfigFile.h"
|
||||
#include "WeaponBehaviour.h"
|
||||
#include "../SpawnerSystem.h"
|
||||
#include "Core/EPlayerDamage.h"
|
||||
#include "Core/EShoot.h"
|
||||
|
||||
|
||||
class AssaultWeaponBehaviour : public WeaponBehaviour
|
||||
{
|
||||
public:
|
||||
@@ -23,13 +22,16 @@ public:
|
||||
private:
|
||||
EntityWrapper m_FirstPersonModel;
|
||||
EntityWrapper m_ThirdPersonModel;
|
||||
|
||||
// State
|
||||
bool m_Firing = false;
|
||||
bool m_Reloading = false;
|
||||
double m_ReloadTimer = 0.0;
|
||||
EntityWrapper m_FirstPersonReloadImpersonator;
|
||||
EntityWrapper m_ThirdPersonReloadImpersonator;
|
||||
double m_TimeSinceLastFire = 0.0;
|
||||
EntityWrapper m_FirstPersonReloadImpostor;
|
||||
|
||||
EventRelay<WeaponBehaviour, Events::AnimationComplete> m_EAnimationComplete;
|
||||
bool OnAnimationComplete(Events::AnimationComplete& e);
|
||||
|
||||
bool hasAmmo();
|
||||
void fireRound();
|
||||
@@ -45,5 +47,3 @@ private:
|
||||
bool shoot(double damage);
|
||||
void showHitMarker();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
#include "WeaponBehaviour.h"
|
||||
|
||||
class DefenderWeaponBehaviour : public WeaponBehaviour
|
||||
{
|
||||
public:
|
||||
DefenderWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper weaponEntity);
|
||||
|
||||
virtual void Fire() override;
|
||||
//virtual void CeaseFire() override;
|
||||
//virtual void Reload() override;
|
||||
|
||||
//virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
double m_TimeSinceLastFire = 0.0;
|
||||
};
|
||||
@@ -8,21 +8,17 @@
|
||||
|
||||
class WeaponBehaviour : public System
|
||||
{
|
||||
friend class WeaponSystem;
|
||||
|
||||
public:
|
||||
WeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper player, EntityWrapper firstPersonWeapon, EntityWrapper thirdPersonWeapon)
|
||||
WeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper player)
|
||||
: System(systemParams)
|
||||
, m_Renderer(renderer)
|
||||
, m_CollisionOctree(collisionOctree)
|
||||
, m_Player(player)
|
||||
, m_FirstPerson(firstPersonWeapon)
|
||||
, m_ThirdPerson(thirdPersonWeapon)
|
||||
{ }
|
||||
virtual ~WeaponBehaviour() = default;
|
||||
|
||||
WeaponBehaviour(const WeaponBehaviour&) = delete;
|
||||
WeaponBehaviour& operator=(const WeaponBehaviour&) = delete;
|
||||
WeaponBehaviour& operator=(const WeaponBehaviour &) = delete;
|
||||
|
||||
virtual void Fire() = 0;
|
||||
virtual void CeaseFire() { }
|
||||
@@ -33,8 +29,6 @@ protected:
|
||||
IRenderer* m_Renderer;
|
||||
Octree<EntityAABB>* m_CollisionOctree;
|
||||
EntityWrapper m_Player;
|
||||
EntityWrapper m_FirstPerson;
|
||||
EntityWrapper m_ThirdPerson;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -46,5 +46,4 @@
|
||||
<xs:include schemaLocation="Components/Page.xsd"/>
|
||||
<xs:include schemaLocation="Components/SpriteIndicator.xsd"/>
|
||||
<xs:include schemaLocation="Components/Button.xsd"/>
|
||||
<xs:include schemaLocation="Components/WeaponAttachment.xsd"/>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Trigger xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Trigger.xsd">
|
||||
</Trigger>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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="Weapon">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="MagSize" type="t:int" minOccurs="0"/>
|
||||
<xs:element name="MaxAmmo" type="t:int" minOccurs="0"/>
|
||||
<xs:element name="CurrentAmmoInMag" type="t:int" minOccurs="0"/>
|
||||
<xs:element name="CurrentAmmo" type="t:int" minOccurs="0"/>
|
||||
<xs:element name="RPM" type="t:double" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<WeaponAttachment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="WeaponAttachment.xsd">
|
||||
<Person><FirstPerson/></Person>
|
||||
</WeaponAttachment>
|
||||
@@ -1,37 +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:complexType name="PersonEnum" mixed="true">
|
||||
<xs:complexContent>
|
||||
<xs:extension base="t:enum">
|
||||
<xs:choice>
|
||||
<xs:element name="FirstPerson" type="t:int" fixed="0" minOccurs="0"/>
|
||||
<xs:element name="ThirdPerson" type="t:int" fixed="1" minOccurs="0"/>
|
||||
</xs:choice>
|
||||
</xs:extension>
|
||||
</xs:complexContent>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="WeaponSlotEnum" mixed="true">
|
||||
<xs:complexContent>
|
||||
<xs:extension base="t:enum">
|
||||
<xs:choice>
|
||||
<xs:element name="Primary" type="t:int" fixed="1" minOccurs="0"/>
|
||||
<xs:element name="Secondary" type="t:int" fixed="2" minOccurs="0"/>
|
||||
</xs:choice>
|
||||
</xs:extension>
|
||||
</xs:complexContent>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:element name="WeaponAttachment">
|
||||
<xs:annotation><xs:documentation>Combine with a spawner to define a weapon attachment point</xs:documentation></xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Person" type="PersonEnum" minOccurs="0"/>
|
||||
<xs:element name="Slot" type="WeaponSlotEnum" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -215,7 +215,8 @@
|
||||
</c:CapturePoint>
|
||||
<c:Model>
|
||||
<Resource>Models\Core\UnitCube.mesh</Resource>
|
||||
<Color A="1" B="1" G="0.200000003" R="0"/>
|
||||
<Color A="0.300000012" B="1" G="0" R="0"/>
|
||||
<Transparent>true</Transparent>
|
||||
</c:Model>
|
||||
<c:Team>
|
||||
<Team>
|
||||
@@ -241,7 +242,8 @@
|
||||
</c:CapturePoint>
|
||||
<c:Model>
|
||||
<Resource>Models\Core\UnitCube.mesh</Resource>
|
||||
<Color A="1" B="1" G="1" R="0"/>
|
||||
<Color A="0.300000012" B="0" G="0" R="1"/>
|
||||
<Transparent>true</Transparent>
|
||||
</c:Model>
|
||||
<c:Team>
|
||||
<Team>
|
||||
@@ -256,6 +258,25 @@
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:AmmoPickup/>
|
||||
<c:Model>
|
||||
<Resource>Models/Props/PickUps/AmmoPickUp.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:RaptorCopter>
|
||||
<Speed>8</Speed>
|
||||
<Axis X="0" Y="0.100000001" Z="0"/>
|
||||
</c:RaptorCopter>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="1.86800003" Z="0"/>
|
||||
<Scale X="0.600000024" Y="0.600000024" Z="0.600000024"/>
|
||||
<Orientation X="0" Y="18741" Z="0"/>
|
||||
</c:Transform>
|
||||
<c:Trigger/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
|
||||
</Entity>
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
<xs:element ref="c:Menu" minOccurs="0"/>
|
||||
<xs:element ref="c:Page" minOccurs="0"/>
|
||||
<xs:element ref="c:Button" minOccurs="0"/>
|
||||
<xs:element ref="c:WeaponAttachment" minOccurs="0"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@@ -51,13 +51,6 @@ EntityWrapper EntityWrapper::FirstParentWithComponent(const std::string& compone
|
||||
return EntityWrapper::Invalid;
|
||||
}
|
||||
|
||||
std::vector<EntityWrapper> EntityWrapper::ChildrenWithComponent(const std::string& componentType)
|
||||
{
|
||||
std::vector<EntityWrapper> childrenWithComponent;
|
||||
childrenWithComponentRecursive(componentType, *this, childrenWithComponent);
|
||||
return childrenWithComponent;
|
||||
}
|
||||
|
||||
bool EntityWrapper::IsChildOf(EntityWrapper potentialParent)
|
||||
{
|
||||
EntityWrapper entity = *this;
|
||||
@@ -138,18 +131,3 @@ EntityWrapper EntityWrapper::firstChildByNameRecursive(const std::string& name,
|
||||
return EntityWrapper::Invalid;
|
||||
}
|
||||
|
||||
void EntityWrapper::childrenWithComponentRecursive(const std::string& componentType, EntityWrapper& entity, std::vector<EntityWrapper>& childrenWithComponent)
|
||||
{
|
||||
auto itPair = this->World->GetChildren(entity.ID);
|
||||
if (itPair.first == itPair.second) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto it = itPair.first; it != itPair.second; ++it) {
|
||||
if (entity.HasComponent(componentType)) {
|
||||
childrenWithComponent.push_back(entity);
|
||||
}
|
||||
childrenWithComponentRecursive(componentType, entity, childrenWithComponent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ void Client::parsePing()
|
||||
m_IsConnected = true;
|
||||
// Time since last ping was received
|
||||
m_DurationOfPingTime = 1000 * (std::clock() - m_StartPingTime) / static_cast<double>(CLOCKS_PER_SEC);
|
||||
LOG_INFO("%i: response time with ctime(ms): %f", m_PacketID, m_DurationOfPingTime);
|
||||
//LOG_INFO("%i: response time with ctime(ms): %f", m_PacketID, m_DurationOfPingTime);
|
||||
m_StartPingTime = std::clock();
|
||||
|
||||
Packet packet(MessageType::Ping, m_SendPacketID);
|
||||
|
||||
@@ -4,18 +4,20 @@ AmmoPickupSystem::AmmoPickupSystem(SystemParams params)
|
||||
: System(params)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &AmmoPickupSystem::OnTriggerTouch);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &AmmoPickupSystem::OnTriggerLeave);
|
||||
}
|
||||
|
||||
void AmmoPickupSystem::Update(double dt)
|
||||
{
|
||||
for (auto it = m_ETriggerTouchVector.begin(); it != m_ETriggerTouchVector.end(); ++it)
|
||||
{
|
||||
auto& ammoPickupPosition = *it;
|
||||
auto& somePickup = *it;
|
||||
|
||||
//set the double timer value (value 3)
|
||||
ammoPickupPosition.DecreaseThisRespawnTimer -= dt;
|
||||
if (ammoPickupPosition.DecreaseThisRespawnTimer < 0.0) {
|
||||
somePickup.DecreaseThisRespawnTimer -= dt;
|
||||
if (somePickup.DecreaseThisRespawnTimer < 0.0) {
|
||||
//spawn and delete the vector item
|
||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/AmmoPickup.xml");
|
||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/" + somePickup.isAmmoPickup ? "AmmoPickup.xml" : "HealthPickup.xml");
|
||||
EntityFileParser parser(entityFile);
|
||||
EntityID ammoPickupID = parser.MergeEntities(m_World);
|
||||
|
||||
@@ -25,17 +27,34 @@ void AmmoPickupSystem::Update(double dt)
|
||||
m_EventBroker->Publish(ePickupSpawned);
|
||||
|
||||
//set values from the old entity to the new entity
|
||||
auto& newAmmoPickupEntity = EntityWrapper(m_World, ammoPickupID);
|
||||
newAmmoPickupEntity["Transform"]["Position"] = ammoPickupPosition.Pos;
|
||||
newAmmoPickupEntity["AmmoPickup"]["AmmoGain"] = ammoPickupPosition.AmmoGain;
|
||||
newAmmoPickupEntity["AmmoPickup"]["RespawnTimer"] = ammoPickupPosition.RespawnTimer;
|
||||
m_World->SetParent(newAmmoPickupEntity.ID, ammoPickupPosition.parentID);
|
||||
auto& newPickupEntity = EntityWrapper(m_World, ammoPickupID);
|
||||
newPickupEntity["Transform"]["Position"] = somePickup.Pos;
|
||||
if (somePickup.isAmmoPickup) {
|
||||
newPickupEntity["AmmoPickup"]["AmmoGain"] = somePickup.AmmoGain;
|
||||
newPickupEntity["AmmoPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
||||
} else {
|
||||
newPickupEntity["HealthPickup"]["HealthGain"] = somePickup.AmmoGain;
|
||||
newPickupEntity["HealthPickup"]["RespawnTimer"] = somePickup.RespawnTimer;
|
||||
}
|
||||
m_World->SetParent(newPickupEntity.ID, somePickup.parentID);
|
||||
|
||||
//erase the current element (AmmoPickupPosition)
|
||||
//erase the current element (somePickup)
|
||||
m_ETriggerTouchVector.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//still touching AmmoPickupAtMaxHealthAmmo?
|
||||
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
|
||||
if (!it->player.Valid() || !it->pickup.Valid()) {
|
||||
m_PickupAtMaximum.erase(it);
|
||||
break;
|
||||
}
|
||||
if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) {
|
||||
DoPickup(it->player, it->pickup);
|
||||
m_PickupAtMaximum.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,36 +63,59 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
|
||||
if (e.Entity != LocalPlayer) {
|
||||
return false;
|
||||
}
|
||||
if (!e.Trigger.HasComponent("AmmoPickup") && !e.Trigger.HasComponent("HealthPickup")) {
|
||||
return false;
|
||||
}
|
||||
//TODO: add other weapontypes
|
||||
if (!e.Entity.HasComponent("AssaultWeapon")) {
|
||||
return false;
|
||||
}
|
||||
if (!e.Trigger.HasComponent("AmmoPickup")) {
|
||||
return false;
|
||||
}
|
||||
int maxWeaponAmmo = (int)e.Entity["AssaultWeapon"]["MaxAmmo"];
|
||||
int& currentAmmo = (int)e.Entity["AssaultWeapon"]["Ammo"];
|
||||
|
||||
int ammoGiven = 0.01*(double)e.Trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo;
|
||||
//cant pick up ammopacks if you are already at MaxAmmo
|
||||
if (currentAmmo >= maxWeaponAmmo) {
|
||||
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
|
||||
return false;
|
||||
}
|
||||
DoPickup(e.Entity, e.Trigger);
|
||||
return true;
|
||||
}
|
||||
|
||||
//personEntered = e.Entity, thingEntered = e.Trigger
|
||||
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
|
||||
//triggerleave erases possible AmmoPickupAtMaxHealthAmmo
|
||||
for (auto& it = m_PickupAtMaximum.begin(); it != m_PickupAtMaximum.end(); ++it) {
|
||||
if (it->pickup.ID == e.Trigger.ID && it->player.ID == e.Entity.ID) {
|
||||
m_PickupAtMaximum.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
|
||||
auto& weaponEntity = player["AssaultWeapon"];
|
||||
auto& pickup = trigger["AmmoPickup"];
|
||||
auto& gain = pickup["AmmoGain"];
|
||||
int maxValue = (int)weaponEntity["MaxAmmo"];
|
||||
int& currentValue = (int)weaponEntity["Ammo"];
|
||||
|
||||
//cant pick up if you are already at max
|
||||
if (currentValue >= maxValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
int increaseGiven = 0.01*(double)gain * maxValue;
|
||||
Events::AmmoPickup ePlayerAmmoPickup;
|
||||
ePlayerAmmoPickup.AmmoGain = ammoGiven;
|
||||
ePlayerAmmoPickup.Player = e.Entity;
|
||||
ePlayerAmmoPickup.AmmoGain = increaseGiven;
|
||||
ePlayerAmmoPickup.Player = player;
|
||||
m_EventBroker->Publish(ePlayerAmmoPickup);
|
||||
//immediately give the player the ammo
|
||||
currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo);
|
||||
currentValue = std::min(currentValue + increaseGiven, maxValue);
|
||||
|
||||
//copy position, ammogain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
|
||||
//we need to copy all values since each value can be different for each ammoPickup
|
||||
m_ETriggerTouchVector.push_back({ e.Trigger["Transform"]["Position"], e.Trigger["AmmoPickup"]["AmmoGain"],
|
||||
e.Trigger["AmmoPickup"]["RespawnTimer"], e.Trigger["AmmoPickup"]["RespawnTimer"], m_World->GetParent(e.Trigger.ID) });
|
||||
m_ETriggerTouchVector.push_back({ trigger["Transform"]["Position"], gain,
|
||||
pickup["RespawnTimer"], pickup["RespawnTimer"], m_World->GetParent(trigger.ID) , true });
|
||||
|
||||
//delete the ammopickup
|
||||
m_World->DeleteEntity(e.Trigger.ID);
|
||||
return true;
|
||||
m_World->DeleteEntity(trigger.ID);
|
||||
}
|
||||
|
||||
@@ -151,12 +151,12 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
|
||||
int currentTeam = 0;
|
||||
bool canCapture = false;
|
||||
if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside == 0) {
|
||||
timerDeltaChange = redTeamPlayersStandingInside*dt;
|
||||
timerDeltaChange = 3*redTeamPlayersStandingInside*dt;
|
||||
currentTeam = redTeam;
|
||||
canCapture = nextPossibleCapturePoint["Red"] == capturePointNumber;
|
||||
}
|
||||
if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside > 0) {
|
||||
timerDeltaChange = -blueTeamPlayersStandingInside*dt;
|
||||
timerDeltaChange = -3*blueTeamPlayersStandingInside*dt;
|
||||
currentTeam = blueTeam;
|
||||
canCapture = nextPossibleCapturePoint["Blue"] == capturePointNumber;
|
||||
}
|
||||
|
||||
@@ -14,16 +14,35 @@ HealthSystem::HealthSystem(SystemParams params)
|
||||
void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cHealth, double dt)
|
||||
{
|
||||
double& health = cHealth["Health"];
|
||||
if (health <= 0.0) {
|
||||
int healthInt = (int)health;
|
||||
//update struct
|
||||
for (auto& iter = m_DeadPlayers.begin(); iter < m_DeadPlayers.end(); iter++)
|
||||
{
|
||||
iter->timeSinceDeath += dt;
|
||||
if (iter->timeSinceDeath > 2.0f || !iter->playerEntity.Valid()) {
|
||||
m_DeadPlayers.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (healthInt <= 0) {
|
||||
for (auto deadPlayer : m_DeadPlayers)
|
||||
{
|
||||
if (deadPlayer.playerEntity.ID == entity.ID) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG_INFO("-> health <= 0");
|
||||
Events::PlayerDeath ePlayerDeath;
|
||||
ePlayerDeath.Player = entity;
|
||||
m_EventBroker->Publish(ePlayerDeath);
|
||||
m_DeadPlayers.emplace_back(entity);
|
||||
//Note: we will delete the entity in PlayerDeathSystem
|
||||
}
|
||||
}
|
||||
|
||||
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
|
||||
{
|
||||
LOG_INFO("<- on player damage");
|
||||
if (!IsServer && m_NetworkEnabled || !e.Victim.Valid()) {
|
||||
return false;
|
||||
}
|
||||
@@ -31,6 +50,7 @@ bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
|
||||
ComponentWrapper cHealth = e.Victim["Health"];
|
||||
double& health = cHealth["Health"];
|
||||
health -= e.Damage;
|
||||
LOG_INFO("-> health onplayerdam");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -54,9 +54,13 @@ void KillFeedSystem::Update(double dt)
|
||||
|
||||
bool KillFeedSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
{
|
||||
LOG_INFO("<- killfeed death");
|
||||
|
||||
KillFeedInfo kfInfo;
|
||||
|
||||
if (e.Player.HasComponent("Team")) {
|
||||
LOG_INFO("- killfeed death");
|
||||
|
||||
int red = e.Player["Team"].Enum("Team", "Red");
|
||||
int blue = e.Player["Team"].Enum("Team", "Blue");
|
||||
|
||||
@@ -70,6 +74,7 @@ bool KillFeedSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
m_DeathQueue.push_back(kfInfo);
|
||||
}
|
||||
}
|
||||
LOG_INFO("-> killfeed death");
|
||||
|
||||
|
||||
if(m_DeathQueue.size() > 3) {
|
||||
|
||||
@@ -8,18 +8,27 @@ PlayerDeathSystem::PlayerDeathSystem(SystemParams params)
|
||||
|
||||
void PlayerDeathSystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool PlayerDeathSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
{
|
||||
LOG_INFO("<- deathsystem: valid player");
|
||||
|
||||
if (!e.Player.Valid()) {
|
||||
return false;
|
||||
}
|
||||
LOG_INFO("-> deathsystem: valid player");
|
||||
|
||||
LOG_INFO("<- create effect");
|
||||
|
||||
createDeathEffect(e.Player);
|
||||
|
||||
// Delete player
|
||||
m_World->DeleteEntity(e.Player.ID);
|
||||
LOG_INFO("-> create effect");
|
||||
|
||||
if (!IsClient || !ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false)) {
|
||||
m_World->DeleteEntity(e.Player.ID);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -32,6 +41,8 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
||||
EntityID deathEffectID = parser.MergeEntities(m_World);
|
||||
EntityWrapper deathEffectEW = EntityWrapper(m_World, deathEffectID);
|
||||
|
||||
LOG_INFO("<- effect camera");
|
||||
|
||||
//components that we need from player
|
||||
auto playerModel = player.FirstChildByName("PlayerModel");
|
||||
if (!playerModel.Valid()) {
|
||||
@@ -42,6 +53,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
||||
}
|
||||
auto playerEntityModel = playerModel["Model"];
|
||||
auto playerEntityAnimation = playerModel["Animation"];
|
||||
LOG_INFO("-> effect camera");
|
||||
|
||||
//copy the data from player to explosioneffectmodel
|
||||
playerEntityModel.Copy(deathEffectEW["Model"]);
|
||||
@@ -57,11 +69,15 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
||||
//effect,camera is relative to playersPosition
|
||||
//deathEffectEW["ExplosionEffect"]["ExplosionOrigin"] = glm::vec3(0, 0, 0);
|
||||
|
||||
LOG_INFO("<- localplayer");
|
||||
//camera (with lifetime) behind the player
|
||||
if (player == LocalPlayer) {
|
||||
auto cam = deathEffectEW.FirstChildByName("Camera");
|
||||
Events::SetCamera eSetCamera;
|
||||
eSetCamera.CameraEntity = cam;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
LOG_INFO("in localplayer");
|
||||
}
|
||||
LOG_INFO("-> localplayer");
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
|
||||
|
||||
void PlayerSpawnSystem::Update(double dt)
|
||||
{
|
||||
CheckForLatePlayers(dt);
|
||||
for (auto& spawnReqs : m_SpawnRequests)
|
||||
{
|
||||
spawnReqs.timeSinceDeath += dt;
|
||||
}
|
||||
//Increase timer.
|
||||
m_Timer += dt;
|
||||
if (m_Timer < m_RespawnTime) {
|
||||
@@ -35,6 +40,10 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
|
||||
int numSpawnedPlayers = 0;
|
||||
for (auto& req : m_SpawnRequests) {
|
||||
if (req.timeSinceDeath < 2.5f) {
|
||||
m_LatePlayersVector.push_back(req);
|
||||
continue;
|
||||
}
|
||||
for (auto& cPlayerSpawn : *playerSpawns) {
|
||||
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
|
||||
if (!spawner.HasComponent("Spawner")) {
|
||||
@@ -111,6 +120,8 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
|
||||
SpawnRequest req;
|
||||
req.PlayerID = e.PlayerID;
|
||||
req.Team = (ComponentInfo::EnumType)e.Value;
|
||||
//set timeSinceDeath > 2.5f since we are force-spawning
|
||||
req.timeSinceDeath = 3.0f;
|
||||
m_SpawnRequests.push_back(req);
|
||||
} else {
|
||||
return false;
|
||||
@@ -134,7 +145,7 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
playerName["Text"]["Content"] = e.PlayerName;
|
||||
}
|
||||
|
||||
if (!IsClient) {
|
||||
if (m_NetworkEnabled && !IsClient) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -164,6 +175,8 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
|
||||
bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
{
|
||||
LOG_INFO("<- spawnsystem death");
|
||||
|
||||
//Only spawn request if network is disabled or we are server.
|
||||
if (!IsServer && m_NetworkEnabled) {
|
||||
return false;
|
||||
@@ -177,6 +190,8 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG_INFO("- spawnsystem death");
|
||||
|
||||
if (m_PlayerIDs.count(e.Player.ID) == 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -184,7 +199,52 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
SpawnRequest req;
|
||||
req.PlayerID = m_PlayerIDs.at(e.Player.ID);
|
||||
req.Team = cTeam["Team"];
|
||||
req.timeSinceDeath = 0.0f;
|
||||
m_SpawnRequests.push_back(req);
|
||||
LOG_INFO("-> spawnsystem death");
|
||||
|
||||
return true;
|
||||
}
|
||||
void PlayerSpawnSystem::CheckForLatePlayers(double dt) {
|
||||
for (size_t i = 0; i < m_LatePlayersVector.size(); i++)
|
||||
{
|
||||
auto& req = m_LatePlayersVector[i];
|
||||
req.timeSinceDeath += dt;
|
||||
if (req.timeSinceDeath > 2.5f) {
|
||||
//good but, this will only spawn them in the next cycle - i.e. not immediately
|
||||
//m_SpawnRequests.push_back(spawnReq);
|
||||
|
||||
//insta spawn
|
||||
auto playerSpawns = m_World->GetComponents("PlayerSpawn");
|
||||
for (auto& cPlayerSpawn : *playerSpawns) {
|
||||
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
|
||||
if (!spawner.HasComponent("Spawner")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the spawner has a team affiliation, check it
|
||||
if (spawner.HasComponent("Team")) {
|
||||
if ((int)spawner["Team"]["Team"] != req.Team) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn the player!
|
||||
EntityWrapper player = SpawnerSystem::Spawn(spawner, EntityWrapper::Invalid, "Player");
|
||||
// Set the player team affiliation
|
||||
player["Team"]["Team"] = req.Team;
|
||||
|
||||
// Publish a PlayerSpawned event
|
||||
Events::PlayerSpawned e;
|
||||
e.PlayerID = req.PlayerID;
|
||||
e.Player = player;
|
||||
e.Spawner = spawner;
|
||||
m_EventBroker->Publish(e);
|
||||
break;
|
||||
}
|
||||
//end insta spawn
|
||||
m_LatePlayersVector.erase(m_LatePlayersVector.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ AssaultWeaponBehaviour::AssaultWeaponBehaviour(SystemParams systemParams, IRende
|
||||
{
|
||||
m_FirstPersonModel = m_Player.FirstChildByName("Hands");
|
||||
m_ThirdPersonModel = m_Player.FirstChildByName("PlayerModel");
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EAnimationComplete, &AssaultWeaponBehaviour::OnAnimationComplete);
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::Fire()
|
||||
@@ -35,7 +36,7 @@ void AssaultWeaponBehaviour::Reload()
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't reload if we're completely out of ammo
|
||||
// Don't reload if we're completly out of ammo
|
||||
if (ammo == 0) {
|
||||
playEmptySound();
|
||||
m_TimeSinceLastFire = -0.0f; // HACK: To make empty sound play with interval
|
||||
@@ -55,14 +56,14 @@ void AssaultWeaponBehaviour::Update(double dt)
|
||||
{
|
||||
if (m_Reloading) {
|
||||
m_ReloadTimer -= dt;
|
||||
// Re-enable glow on reload impostor half-way through the animation
|
||||
// Re-enable glow on reload impersonator half-way through the animation
|
||||
if (IsClient) {
|
||||
if (m_ReloadTimer <= (double)m_Player["AssaultWeapon"]["ReloadTime"] / 2.0) {
|
||||
if (m_FirstPersonReloadImpostor.Valid()) {
|
||||
m_FirstPersonReloadImpostor["Model"]["GlowMap"] = true;
|
||||
if (m_FirstPersonReloadImpersonator.Valid()) {
|
||||
m_FirstPersonReloadImpersonator["Model"]["GlowMap"] = true;
|
||||
}
|
||||
if (m_ThirdPersonReloadImpostor.Valid()) {
|
||||
m_ThirdPersonReloadImpostor["Model"]["GlowMap"] = true;
|
||||
if (m_ThirdPersonReloadImpersonator.Valid()) {
|
||||
m_ThirdPersonReloadImpersonator["Model"]["GlowMap"] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,6 +96,21 @@ void AssaultWeaponBehaviour::Update(double dt)
|
||||
}
|
||||
}
|
||||
|
||||
bool AssaultWeaponBehaviour::OnAnimationComplete(Events::AnimationComplete& e)
|
||||
{
|
||||
if (e.Entity != m_FirstPersonModel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//if (e.Name == "ShootRifle") {
|
||||
// if (!m_Firing) {
|
||||
// playIdleAnimation();
|
||||
// }
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssaultWeaponBehaviour::hasAmmo()
|
||||
{
|
||||
ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"];
|
||||
@@ -199,12 +215,6 @@ void AssaultWeaponBehaviour::playEmptySound()
|
||||
|
||||
void AssaultWeaponBehaviour::viewPunch()
|
||||
{
|
||||
// Since we send absolute client orientations to server, running this server side would
|
||||
// cause aim desync.
|
||||
if (!IsClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityWrapper playerCamera = m_Player.FirstChildByName("Camera");
|
||||
if (!playerCamera.Valid()) {
|
||||
return;
|
||||
@@ -313,8 +323,8 @@ void AssaultWeaponBehaviour::playReloadAnimation()
|
||||
EntityWrapper firstPersonWeaponModel = m_Player.FirstChildByName("WeaponModel");
|
||||
EntityWrapper reloadSpawner = m_Player.FirstChildByName("FirstPersonReloadSpawner");
|
||||
if (IsClient) {
|
||||
m_FirstPersonReloadImpostor = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner);
|
||||
firstPersonWeaponModel["Model"].Copy(m_FirstPersonReloadImpostor["Model"]);
|
||||
m_FirstPersonReloadImpersonator = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner);
|
||||
firstPersonWeaponModel["Model"].Copy(m_FirstPersonReloadImpersonator["Model"]);
|
||||
}
|
||||
firstPersonWeaponModel["Model"]["Visible"] = false;
|
||||
}
|
||||
@@ -322,8 +332,8 @@ void AssaultWeaponBehaviour::playReloadAnimation()
|
||||
EntityWrapper thirdPersonWeaponModel = m_Player.FirstChildByName("ThirdPersonWeaponModel");
|
||||
EntityWrapper reloadSpawner = m_Player.FirstChildByName("ThirdPersonReloadSpawner");
|
||||
if (IsClient) {
|
||||
m_ThirdPersonReloadImpostor = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner);
|
||||
thirdPersonWeaponModel["Model"].Copy(m_ThirdPersonReloadImpostor["Model"]);
|
||||
m_ThirdPersonReloadImpersonator = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner);
|
||||
thirdPersonWeaponModel["Model"].Copy(m_ThirdPersonReloadImpersonator["Model"]);
|
||||
}
|
||||
thirdPersonWeaponModel["Model"]["Visible"] = false;
|
||||
}
|
||||
@@ -361,7 +371,7 @@ bool AssaultWeaponBehaviour::shoot(double damage)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't let us shoot ourselves in the foot somehow
|
||||
// Don't let us shoot ourselves in the foot
|
||||
if (victim == LocalPlayer) {
|
||||
return false;
|
||||
}
|
||||
@@ -376,7 +386,7 @@ bool AssaultWeaponBehaviour::shoot(double damage)
|
||||
|
||||
// Check for friendly fire
|
||||
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)m_Player["Team"]["Team"]) {
|
||||
return false;
|
||||
damage = 1;
|
||||
}
|
||||
|
||||
// Deal damage!
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "Systems/Weapon/DefenderWeaponBehaviour.h"
|
||||
|
||||
DefenderWeaponBehaviour::DefenderWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper weaponEntity)
|
||||
: WeaponBehaviour(systemParams, renderer, collisionOctree, weaponEntity) { }
|
||||
|
||||
void DefenderWeaponBehaviour::Fire()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ WeaponSystem::WeaponSystem(SystemParams params, IRenderer* renderer, Octree<Enti
|
||||
|
||||
void WeaponSystem::Update(double dt)
|
||||
{
|
||||
// TODO: Clear inactive weapons
|
||||
|
||||
}
|
||||
|
||||
void WeaponSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt)
|
||||
@@ -72,64 +72,20 @@ bool WeaponSystem::OnInputCommand(Events::InputCommand& e)
|
||||
|
||||
void WeaponSystem::selectWeapon(EntityWrapper player, ComponentInfo::EnumType slot)
|
||||
{
|
||||
std::vector<EntityWrapper> weaponAttachments = player.ChildrenWithComponent("WeaponAttachment");
|
||||
|
||||
// Find the weapon attachments matching the slot selected
|
||||
EntityWrapper firstPersonAttachment;
|
||||
EntityWrapper thirdPersonAttachment;
|
||||
for (auto& attachment : weaponAttachments) {
|
||||
ComponentWrapper cWeaponAttachment = attachment["WeaponAttachment"];
|
||||
if ((ComponentInfo::EnumType)cWeaponAttachment["Slot"] == slot) {
|
||||
ComponentWrapper::SubscriptProxy person = cWeaponAttachment["Person"];
|
||||
if (person == person.Enum("FirstPerson")) {
|
||||
firstPersonAttachment = attachment;
|
||||
} else if (person == person.Enum("ThirdPerson")) {
|
||||
thirdPersonAttachment = attachment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (firstPersonAttachment.Valid() && thirdPersonAttachment.Valid()) {
|
||||
LOG_WARNING("No weapon attachment found for slot %i of player #%i", slot, player.ID);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Delete old weapons
|
||||
|
||||
// Spawn the weapon(s)
|
||||
EntityWrapper firstPersonWeapon;
|
||||
EntityWrapper thirdPersonWeapon;
|
||||
if (firstPersonAttachment.Valid()) {
|
||||
firstPersonWeapon = SpawnerSystem::Spawn(firstPersonAttachment, firstPersonAttachment);
|
||||
}
|
||||
if (thirdPersonAttachment.Valid()) {
|
||||
firstPersonWeapon = SpawnerSystem::Spawn(thirdPersonAttachment, thirdPersonAttachment);
|
||||
}
|
||||
|
||||
// Create the correct behaviour
|
||||
if (firstPersonWeapon.Valid()) {
|
||||
if (firstPersonWeapon.HasComponent("AssaultWeapon") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Primary
|
||||
if (slot == 1) {
|
||||
// TODO: if class...
|
||||
nextBehaviour = std::make_shared<AssaultWeaponBehaviour>(m_SystemParams, m_Renderer, m_CollisionOctree, player);
|
||||
if (m_ActiveWeapons.count(player) == 0) {
|
||||
m_ActiveWeapons.insert(std::make_pair(player, std::make_shared<AssaultWeaponBehaviour>(m_SystemParams, m_Renderer, m_CollisionOctree, player)));
|
||||
} else {
|
||||
//m_ActiveWeapons.erase(player);
|
||||
}
|
||||
}
|
||||
|
||||
// Secondary
|
||||
if (slot == 2) {
|
||||
//m_ActiveWeapons[player] = std::make_shared<PistolWeaponBehaviour>();
|
||||
}
|
||||
|
||||
if (nextBehaviour != nullptr) {
|
||||
// TODO: Destroy previous behaviour and make new
|
||||
if (m_ActiveWeapons.count(player) == 0) {
|
||||
m_ActiveWeapons[player] = nextBehaviour;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool WeaponSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
|
||||
Reference in New Issue
Block a user