Working damage dealing, a super cool reload effect and hit markers!
This commit is contained in:
@@ -65,7 +65,6 @@ void EntityFilePreprocessor::parseComponentInfo()
|
||||
|
||||
// Name
|
||||
compInfo.Name = XS::ToString(element->getName());
|
||||
bool brk = compInfo.Name == "HiddenForLocalPlayer";
|
||||
// Known allocation
|
||||
compInfo.Meta->Allocation = m_ComponentCounts[compInfo.Name];
|
||||
// Annotation
|
||||
|
||||
@@ -390,8 +390,9 @@ bool Client::OnInputCommand(const Events::InputCommand & e)
|
||||
bool Client::OnPlayerDamage(const Events::PlayerDamage & e)
|
||||
{
|
||||
Packet packet(MessageType::OnPlayerDamage, m_SendPacketID);
|
||||
packet.WritePrimitive(m_ClientIDToServerID.at(e.Inflictor.ID));
|
||||
packet.WritePrimitive(m_ClientIDToServerID.at(e.Victim.ID));
|
||||
packet.WritePrimitive(e.Damage);
|
||||
packet.WritePrimitive(m_ClientIDToServerID.at(e.Player.ID));
|
||||
send(packet);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -299,8 +299,9 @@ void Server::parseOnInputCommand(Packet& packet)
|
||||
void Server::parseOnPlayerDamage(Packet & packet)
|
||||
{
|
||||
Events::PlayerDamage e;
|
||||
e.Inflictor = EntityWrapper(m_World, packet.ReadPrimitive<EntityID>());
|
||||
e.Victim = EntityWrapper(m_World, packet.ReadPrimitive<EntityID>());
|
||||
e.Damage = packet.ReadPrimitive<double>();
|
||||
e.Player = EntityWrapper(m_World, packet.ReadPrimitive<EntityID>());
|
||||
m_EventBroker->Publish(e);
|
||||
//LOG_DEBUG("Server::parseOnPlayerDamage: Command is %s. Value is %f. PlayerID is %i.", e.DamageAmount, e.PlayerDamagedID, e.TypeOfDamage.c_str());
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ void HealthSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& comp
|
||||
|
||||
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e)
|
||||
{
|
||||
ComponentWrapper cHealth = e.Player["Health"];
|
||||
ComponentWrapper cHealth = e.Victim["Health"];
|
||||
double& health = cHealth["Health"];
|
||||
health -= e.Damage;
|
||||
|
||||
if (health <= 0.0) {
|
||||
Events::PlayerDeath ePlayerDeath;
|
||||
ePlayerDeath.Player = e.Player;
|
||||
ePlayerDeath.Player = e.Victim;
|
||||
m_EventBroker->Publish(ePlayerDeath);
|
||||
//Note: we will delete the entity in PlayerDeathSystem
|
||||
}
|
||||
|
||||
@@ -41,7 +41,9 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
||||
playerEntityModel.Copy(deathEffectEW["Model"]);
|
||||
playerEntityAnimation.Copy(deathEffectEW["Animation"]);
|
||||
//freeze the animation
|
||||
deathEffectEW["Animation"]["Speed"] = 0.0;
|
||||
deathEffectEW["Animation"]["Speed1"] = 0.0;
|
||||
deathEffectEW["Animation"]["Speed2"] = 0.0;
|
||||
deathEffectEW["Animation"]["Speed3"] = 0.0;
|
||||
|
||||
//copy the models position,orientation
|
||||
deathEffectEW["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"];
|
||||
@@ -50,8 +52,10 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
|
||||
//deathEffectEW["ExplosionEffect"]["ExplosionOrigin"] = glm::vec3(0, 0, 0);
|
||||
|
||||
//camera (with lifetime) behind the player
|
||||
auto cam = deathEffectEW.FirstChildByName("Camera");
|
||||
Events::SetCamera eSetCamera;
|
||||
eSetCamera.CameraEntity = cam;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
if (player == LocalPlayer) {
|
||||
auto cam = deathEffectEW.FirstChildByName("Camera");
|
||||
Events::SetCamera eSetCamera;
|
||||
eSetCamera.CameraEntity = cam;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e)
|
||||
}
|
||||
if (e.Command == "TakeDamage" && e.Value > 0) {
|
||||
Events::PlayerDamage ev;
|
||||
ev.Player = LocalPlayer;
|
||||
ev.Victim = LocalPlayer;
|
||||
ev.Damage = 1.0;
|
||||
m_EventBroker->Publish(ev);
|
||||
}
|
||||
|
||||
@@ -48,10 +48,12 @@ EntityWrapper SpawnerSystem::Spawn(EntityWrapper spawner, EntityWrapper parent /
|
||||
EntityFileParser parser(entityFile);
|
||||
EntityWrapper spawnedEntity(world, parser.MergeEntities(world, parent.ID));
|
||||
|
||||
// Set its position and orientation to that of the SpawnPoint
|
||||
spawnedEntity["Transform"]["Position"] = Transform::AbsolutePosition(spawnPoint.World, spawnPoint.ID);
|
||||
// TODO: Quaternions, bitch
|
||||
spawnedEntity["Transform"]["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(spawnPoint));
|
||||
if (spawnPoint != parent) {
|
||||
// Set its position and orientation to that of the SpawnPoint
|
||||
spawnedEntity["Transform"]["Position"] = Transform::AbsolutePosition(spawnPoint.World, spawnPoint.ID);
|
||||
// TODO: Quaternions, bitch
|
||||
spawnedEntity["Transform"]["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(spawnPoint));
|
||||
}
|
||||
|
||||
return spawnedEntity;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "Systems/Weapon/AssaultWeaponBehaviour.h"
|
||||
|
||||
AssaultWeaponBehaviour::AssaultWeaponBehaviour(SystemParams systemParams, Octree<EntityAABB>* collisionOctree, EntityWrapper weaponEntity)
|
||||
: WeaponBehaviour(systemParams, collisionOctree, weaponEntity)
|
||||
AssaultWeaponBehaviour::AssaultWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper player)
|
||||
: WeaponBehaviour(systemParams, renderer, collisionOctree, player)
|
||||
{
|
||||
m_FirstPersonModel = m_Entity.FirstChildByName("Hands");
|
||||
m_FirstPersonModel = m_Player.FirstChildByName("Hands");
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EAnimationComplete, &AssaultWeaponBehaviour::OnAnimationComplete);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ void AssaultWeaponBehaviour::Fire()
|
||||
m_TimeSinceLastFire = 0.0;
|
||||
m_Firing = true;
|
||||
fireRound();
|
||||
playShootAnimation();
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::CeaseFire()
|
||||
@@ -22,29 +21,48 @@ void AssaultWeaponBehaviour::CeaseFire()
|
||||
|
||||
void AssaultWeaponBehaviour::Reload()
|
||||
{
|
||||
ComponentWrapper& cAssaultWeapon = m_Entity["AssaultWeapon"];
|
||||
if (m_Reloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
int& magAmmo = cAssaultWeapon["MagazineAmmo"];
|
||||
ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"];
|
||||
int magAmmo = cAssaultWeapon["MagazineAmmo"];
|
||||
int magSize = cAssaultWeapon["MagazineSize"];
|
||||
int& ammo = cAssaultWeapon["Ammo"];
|
||||
int ammo = cAssaultWeapon["Ammo"];
|
||||
|
||||
// Don't reload if we're already fully loaded
|
||||
if (magAmmo == magSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Throw away rounds in magazine to incentivise ammo sharing
|
||||
int toLoad = glm::min(magSize, ammo);
|
||||
magAmmo = toLoad;
|
||||
ammo -= toLoad;
|
||||
// Don't reload if we're completly out of ammo
|
||||
if (ammo == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_Reloading = true;
|
||||
m_ReloadTimer = cAssaultWeapon["ReloadTime"];
|
||||
playReloadAnimation();
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::Update(double dt)
|
||||
{
|
||||
if (m_Firing) {
|
||||
m_TimeSinceLastFire += dt;
|
||||
if (m_Reloading) {
|
||||
m_ReloadTimer -= dt;
|
||||
// Re-enable glow on reload impersonator half-way through the animation
|
||||
if (m_ReloadTimer <= (double)m_Player["AssaultWeapon"]["ReloadTime"] / 2.0) {
|
||||
if (m_ReloadImpersonator.Valid()) {
|
||||
m_ReloadImpersonator["Model"]["GlowMap"] = true;
|
||||
}
|
||||
}
|
||||
if (m_ReloadTimer <= 0) {
|
||||
finishReload();
|
||||
}
|
||||
}
|
||||
|
||||
ComponentWrapper& cAssaultWeapon = m_Entity["AssaultWeapon"];
|
||||
if (m_Firing && !m_Reloading) {
|
||||
m_TimeSinceLastFire += dt;
|
||||
ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"];
|
||||
if (m_TimeSinceLastFire >= 1.0 / ((double)cAssaultWeapon["RPM"] / 60.0)) {
|
||||
fireRound();
|
||||
}
|
||||
@@ -53,6 +71,13 @@ void AssaultWeaponBehaviour::Update(double dt)
|
||||
if (!m_Firing && !m_Reloading) {
|
||||
playIdleAnimation();
|
||||
}
|
||||
|
||||
// Disable glow map on weapon if it's out of ammo
|
||||
// Make real first person weapon model visible again
|
||||
EntityWrapper firstPersonWeaponModel = m_Player.FirstChildByName("WeaponModel");
|
||||
if (firstPersonWeaponModel.Valid()) {
|
||||
firstPersonWeaponModel["Model"]["GlowMap"] = hasAmmo();
|
||||
}
|
||||
}
|
||||
|
||||
bool AssaultWeaponBehaviour::OnAnimationComplete(Events::AnimationComplete& e)
|
||||
@@ -70,9 +95,20 @@ bool AssaultWeaponBehaviour::OnAnimationComplete(Events::AnimationComplete& e)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssaultWeaponBehaviour::hasAmmo()
|
||||
{
|
||||
ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"];
|
||||
int& magAmmo = cAssaultWeapon["MagazineAmmo"];
|
||||
return magAmmo > 0;
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::fireRound()
|
||||
{
|
||||
ComponentWrapper& cAssaultWeapon = m_Entity["AssaultWeapon"];
|
||||
if (m_Reloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"];
|
||||
|
||||
int& magAmmo = cAssaultWeapon["MagazineAmmo"];
|
||||
int ammo = cAssaultWeapon["Ammo"];
|
||||
@@ -88,6 +124,11 @@ void AssaultWeaponBehaviour::fireRound()
|
||||
spawnTracer();
|
||||
playSound();
|
||||
viewPunch();
|
||||
playShootAnimation();
|
||||
bool hit = shoot(cAssaultWeapon["BaseDamage"]);
|
||||
if (hit) {
|
||||
showHitMarker();
|
||||
}
|
||||
|
||||
m_TimeSinceLastFire = 0.0;
|
||||
}
|
||||
@@ -99,25 +140,32 @@ void AssaultWeaponBehaviour::spawnTracer()
|
||||
}
|
||||
|
||||
EntityWrapper spawner;
|
||||
if (m_Entity == LocalPlayer) {
|
||||
spawner = m_Entity.FirstChildByName("WeaponMuzzle");
|
||||
if (m_Player == LocalPlayer) {
|
||||
spawner = m_Player.FirstChildByName("WeaponMuzzle");
|
||||
} else {
|
||||
spawner = m_Entity.FirstChildByName("ThirdPersonWeaponMuzzle");
|
||||
spawner = m_Player.FirstChildByName("ThirdPersonWeaponMuzzle");
|
||||
}
|
||||
|
||||
if (!spawner.Valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Events::SpawnerSpawn e;
|
||||
e.Spawner = spawner;
|
||||
m_EventBroker->Publish(e);
|
||||
float distance = traceRayDistance(Transform::AbsolutePosition(spawner), Transform::AbsoluteOrientation(spawner) * glm::vec3(0, 0, -1));
|
||||
EntityWrapper ray = SpawnerSystem::Spawn(spawner);
|
||||
((glm::vec3&)ray["Transform"]["Scale"]).z = (distance / 100.f);
|
||||
}
|
||||
|
||||
float AssaultWeaponBehaviour::traceRayDistance(glm::vec3 origin, glm::vec3 direction)
|
||||
{
|
||||
// TODO: Cast a ray and size tracer appropriately
|
||||
return 100.f;
|
||||
float distance;
|
||||
glm::vec3 pos;
|
||||
auto entity = Collision::EntityFirstHitByRay(Ray(origin, direction), m_CollisionOctree, distance, pos);
|
||||
if (entity) {
|
||||
return distance;
|
||||
} else {
|
||||
return 100.f;
|
||||
}
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::playSound()
|
||||
@@ -127,32 +175,52 @@ void AssaultWeaponBehaviour::playSound()
|
||||
}
|
||||
|
||||
Events::PlaySoundOnEntity e;
|
||||
e.EmitterID = m_Entity.ID;
|
||||
e.EmitterID = m_Player.ID;
|
||||
e.FilePath = "Audio/laser/laser1.wav";
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::viewPunch()
|
||||
{
|
||||
EntityWrapper playerCamera = m_Entity.FirstChildByName("Camera");
|
||||
EntityWrapper playerCamera = m_Player.FirstChildByName("Camera");
|
||||
if (!playerCamera.Valid()) {
|
||||
return;
|
||||
}
|
||||
float viewPunch = m_Entity["AssaultWeapon"]["ViewPunch"];
|
||||
float viewPunch = m_Player["AssaultWeapon"]["ViewPunch"];
|
||||
ComponentWrapper cTransform = playerCamera["Transform"];
|
||||
glm::vec3& orientation = cTransform["Orientation"];
|
||||
orientation.x += viewPunch;
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::finishReload()
|
||||
{
|
||||
ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"];
|
||||
int& magAmmo = cAssaultWeapon["MagazineAmmo"];
|
||||
int magSize = cAssaultWeapon["MagazineSize"];
|
||||
int& ammo = cAssaultWeapon["Ammo"];
|
||||
|
||||
// Throw away rounds in magazine to incentivise ammo sharing
|
||||
int toLoad = glm::min(magSize, ammo);
|
||||
magAmmo = toLoad;
|
||||
ammo -= toLoad;
|
||||
|
||||
// Make real first person weapon model visible again
|
||||
EntityWrapper firstPersonWeaponModel = m_Player.FirstChildByName("WeaponModel");
|
||||
firstPersonWeaponModel["Model"]["Visible"] = true;
|
||||
|
||||
m_Reloading = false;
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::playShootAnimation()
|
||||
{
|
||||
EntityWrapper firstPersonWeapon = m_Entity.FirstChildByName("Hands");
|
||||
ComponentWrapper cAnimation = firstPersonWeapon["Animation"];
|
||||
cAnimation["AnimationName1"] = "ShootRifle";
|
||||
cAnimation["Weight1"] = 1.0;
|
||||
cAnimation["Time1"] = 0.0;
|
||||
cAnimation["Speed1"] = 1.0;
|
||||
cAnimation["Loop1"] = true;
|
||||
ComponentWrapper cAnimation = m_FirstPersonModel["Animation"];
|
||||
if (cAnimation["AnimationName1"] != "ShootRifle") {
|
||||
cAnimation["AnimationName1"] = "ShootRifle";
|
||||
cAnimation["Weight1"] = 1.0;
|
||||
cAnimation["Time1"] = 0.0;
|
||||
cAnimation["Speed1"] = 1.0;
|
||||
cAnimation["Loop1"] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::playIdleAnimation()
|
||||
@@ -168,11 +236,11 @@ void AssaultWeaponBehaviour::playIdleAnimation()
|
||||
std::string animationToPlay = "Idle";
|
||||
double speedToSet = 1.0;
|
||||
|
||||
ComponentWrapper cPlayer = m_Entity["Player"];
|
||||
ComponentWrapper cPlayer = m_Player["Player"];
|
||||
glm::vec3 movementDirection = cPlayer["CurrentWishDirection"];
|
||||
if (glm::length2(movementDirection) > 0) {
|
||||
animationToPlay = "Run";
|
||||
ComponentWrapper cPhysics = m_Entity["Physics"];
|
||||
ComponentWrapper cPhysics = m_Player["Physics"];
|
||||
speedToSet = glm::length((glm::vec3)cPhysics["Velocity"]) / (float)cPlayer["MovementSpeed"];
|
||||
}
|
||||
|
||||
@@ -188,3 +256,85 @@ void AssaultWeaponBehaviour::playIdleAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::playReloadAnimation()
|
||||
{
|
||||
// Play animation
|
||||
ComponentWrapper cAnimation = m_FirstPersonModel["Animation"];
|
||||
cAnimation["AnimationName1"] = "ReloadSwitch";
|
||||
cAnimation["Weight1"] = 1.0;
|
||||
cAnimation["Time1"] = 0.0;
|
||||
cAnimation["Speed1"] = 0.5;
|
||||
cAnimation["Loop1"] = true;
|
||||
|
||||
// Hide weapon model and spawn the exploding version
|
||||
EntityWrapper firstPersonWeaponModel = m_Player.FirstChildByName("WeaponModel");
|
||||
EntityWrapper reloadSpawner = m_Player.FirstChildByName("FirstPersonReloadSpawner");
|
||||
m_ReloadImpersonator = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner);
|
||||
firstPersonWeaponModel["Model"].Copy(m_ReloadImpersonator["Model"]);
|
||||
firstPersonWeaponModel["Model"]["Visible"] = false;
|
||||
}
|
||||
|
||||
bool AssaultWeaponBehaviour::shoot(double damage)
|
||||
{
|
||||
// Only do shooting clientside
|
||||
if (!IsClient) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only handle shooting for the local player
|
||||
if (m_Player != LocalPlayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the player isn't shooting from the grave
|
||||
if (!m_Player.Valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Screen center, based on current resolution!
|
||||
Rectangle screenResolution = m_Renderer->GetViewportSize();
|
||||
glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2);
|
||||
|
||||
// Pick middle of screen
|
||||
PickData pickData = m_Renderer->Pick(centerScreen);
|
||||
if (pickData.Entity == EntityID_Invalid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityWrapper victim(m_World, pickData.Entity);
|
||||
|
||||
// Don't let us shoot ourselves in the foot
|
||||
if (victim == LocalPlayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only care about players being hit
|
||||
if (!victim.HasComponent("Player")) {
|
||||
victim = victim.FirstParentWithComponent("Player");
|
||||
}
|
||||
if (!victim.Valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for friendly fire
|
||||
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)m_Player["Team"]["Team"]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Deal damage!
|
||||
Events::PlayerDamage ePlayerDamage;
|
||||
ePlayerDamage.Victim = victim;
|
||||
ePlayerDamage.Damage = damage;
|
||||
m_EventBroker->Publish(ePlayerDamage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssaultWeaponBehaviour::showHitMarker()
|
||||
{
|
||||
// Show hit marker
|
||||
EntityWrapper hitMarkerSpawner = m_Player.FirstChildByName("HitMarkerSpawner");
|
||||
if (hitMarkerSpawner.Valid()) {
|
||||
SpawnerSystem::Spawn(hitMarkerSpawner, hitMarkerSpawner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ WeaponSystem::WeaponSystem(SystemParams params, IRenderer* renderer, Octree<Enti
|
||||
, m_CollisionOctree(collisionOctree)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &WeaponSystem::OnInputCommand);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EShoot, &WeaponSystem::OnShoot);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &WeaponSystem::OnPlayerSpawned);
|
||||
}
|
||||
|
||||
@@ -60,6 +59,14 @@ bool WeaponSystem::OnInputCommand(Events::InputCommand& e)
|
||||
}
|
||||
}
|
||||
|
||||
// Reload
|
||||
if (e.Command == "Reload" && e.Value != 0) {
|
||||
if (m_ActiveWeapons.find(player) != m_ActiveWeapons.end()) {
|
||||
auto weapon = m_ActiveWeapons.at(player);
|
||||
weapon->Reload();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,7 +76,7 @@ void WeaponSystem::selectWeapon(EntityWrapper player, ComponentInfo::EnumType sl
|
||||
if (slot == 1) {
|
||||
// TODO: if class...
|
||||
if (m_ActiveWeapons.count(player) == 0) {
|
||||
m_ActiveWeapons.insert(std::make_pair(player, std::make_shared<AssaultWeaponBehaviour>(m_SystemParams, m_CollisionOctree, player)));
|
||||
m_ActiveWeapons.insert(std::make_pair(player, std::make_shared<AssaultWeaponBehaviour>(m_SystemParams, m_Renderer, m_CollisionOctree, player)));
|
||||
} else {
|
||||
//m_ActiveWeapons.erase(player);
|
||||
}
|
||||
@@ -87,52 +94,3 @@ bool WeaponSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
// TODO: Select the active one specified by player component
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WeaponSystem::OnShoot(Events::Shoot& eShoot)
|
||||
{
|
||||
if (!eShoot.Player.Valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only run further picking code for the local player!
|
||||
if (eShoot.Player != LocalPlayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Screen center, based on current resolution!
|
||||
// TODO: check if player has enough ammo and if weapon has a cooldown or not
|
||||
Rectangle screenResolution = m_Renderer->GetViewportSize();
|
||||
glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2);
|
||||
|
||||
// TODO: check if player has enough ammo and if weapon has a cooldown or not
|
||||
|
||||
// Pick middle of screen
|
||||
PickData pickData = m_Renderer->Pick(centerScreen);
|
||||
if (pickData.Entity == EntityID_Invalid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityWrapper player(m_World, pickData.Entity);
|
||||
|
||||
// Only care about players being hit
|
||||
if (!player.HasComponent("Player")) {
|
||||
player = player.FirstParentWithComponent("Player");
|
||||
}
|
||||
if (!player.Valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for friendly fire
|
||||
EntityWrapper shooter = eShoot.Player;
|
||||
if ((ComponentInfo::EnumType)player["Team"]["Team"] == (ComponentInfo::EnumType)shooter["Team"]["Team"]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Weapon damage calculations etc
|
||||
Events::PlayerDamage ePlayerDamage;
|
||||
ePlayerDamage.Player = player;
|
||||
ePlayerDamage.Damage = 100;
|
||||
m_EventBroker->Publish(ePlayerDamage);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ GameHealthSystemTest::GameHealthSystemTest()
|
||||
//damage player with 50
|
||||
Events::PlayerDamage e;
|
||||
e.Damage = 50.0f;
|
||||
e.Player = EntityWrapper(m_World, player.EntityID);
|
||||
e.Victim = EntityWrapper(m_World, player.EntityID);
|
||||
m_EventBroker->Publish(e);
|
||||
|
||||
//heal some other player with 40
|
||||
|
||||
Reference in New Issue
Block a user