Functionally working defender weapon
This commit is contained in:
@@ -27,9 +27,11 @@ private:
|
|||||||
std::random_device m_RandomDevice;
|
std::random_device m_RandomDevice;
|
||||||
std::mt19937 m_RandomEngine;
|
std::mt19937 m_RandomEngine;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Weapon functions
|
// Weapon functions
|
||||||
void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi);
|
void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi);
|
||||||
void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage);
|
void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, const std::vector<glm::vec2>& pattern);
|
||||||
bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi);
|
bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi);
|
||||||
|
|
||||||
// Utility
|
// Utility
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
<Ammo>64</Ammo>
|
<Ammo>64</Ammo>
|
||||||
<MaxAmmo>64</MaxAmmo>
|
<MaxAmmo>64</MaxAmmo>
|
||||||
<BaseDamage>90</BaseDamage>
|
<BaseDamage>90</BaseDamage>
|
||||||
<SpreadAngle>0.174533</SpreadAngle> <!-- 0.174533 = 10 degrees -->
|
<SpreadAngle>10</SpreadAngle>
|
||||||
<MaxTravelAngle>0.174533</MaxTravelAngle> <!-- 0.174533 = 10 degrees -->
|
<MaxTravelAngle>0.174533</MaxTravelAngle> <!-- 0.174533 = 10 degrees -->
|
||||||
<NumPellets>10</NumPellets>
|
<NumPellets>9</NumPellets>
|
||||||
<RPM>120</RPM>
|
<RPM>120</RPM>
|
||||||
<ViewPunch>0.03</ViewPunch>
|
<ViewPunch>0.03</ViewPunch>
|
||||||
<ViewReturnSpeed>0.2</ViewReturnSpeed>
|
<ViewReturnSpeed>0.2</ViewReturnSpeed>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
<xs:annotation><xs:documentation>Damage dealt if all shotgun pellets hit</xs:documentation></xs:annotation>
|
<xs:annotation><xs:documentation>Damage dealt if all shotgun pellets hit</xs:documentation></xs:annotation>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
<xs:element name="SpreadAngle" type="t:float" minOccurs="0">
|
<xs:element name="SpreadAngle" type="t:float" minOccurs="0">
|
||||||
<xs:annotation><xs:documentation>Spread angle in radians</xs:documentation></xs:annotation>
|
<xs:annotation><xs:documentation>The spread angle radius.</xs:documentation></xs:annotation>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
<xs:element name="MaxTravelAngle" type="t:float" minOccurs="0">
|
<xs:element name="MaxTravelAngle" type="t:float" minOccurs="0">
|
||||||
<xs:annotation><xs:documentation>Maximum vertical aim travel angle in radians</xs:documentation></xs:annotation>
|
<xs:annotation><xs:documentation>Maximum vertical aim travel angle in radians</xs:documentation></xs:annotation>
|
||||||
|
|||||||
@@ -1,39 +1,95 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
<Entity name="Shield" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
|
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
|
||||||
|
|
||||||
<Components>
|
<Components>
|
||||||
<c:Blend>
|
<c:Transform>
|
||||||
<Pose1>Deploy</Pose1>
|
<Position X="1.70262027" Y="0.261695802" Z="-3.26634645"/>
|
||||||
<Pose2>Idle</Pose2>
|
</c:Transform>
|
||||||
<Weight>0</Weight>
|
|
||||||
</c:Blend>
|
|
||||||
<c:Model>
|
|
||||||
<Resource>Models/Characters/Defender/DefenderShield.mesh</Resource>
|
|
||||||
</c:Model>
|
|
||||||
<c:Transform/>
|
|
||||||
</Components>
|
</Components>
|
||||||
|
|
||||||
<Children>
|
<Children>
|
||||||
<Entity name="Deploy">
|
<Entity name="Back">
|
||||||
<Components>
|
<Components>
|
||||||
<c:Animation>
|
<c:Blend>
|
||||||
<AnimationName>ActivateDeactiveShieldF</AnimationName>
|
<Pose1>Deploy</Pose1>
|
||||||
<Time>1</Time>
|
<Pose2>Idle</Pose2>
|
||||||
<Speed>1</Speed>
|
<Weight>0</Weight>
|
||||||
</c:Animation>
|
</c:Blend>
|
||||||
|
<c:Shielded/>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Characters/Defender/DefenderShieldBack.mesh</Resource>
|
||||||
|
<Color A="0.219607845" B="3.92156863" G="1" R="1"/>
|
||||||
|
<Shadow>false</Shadow>
|
||||||
|
<Transparent>true</Transparent>
|
||||||
|
<NormalMap>false</NormalMap>
|
||||||
|
<DiffuseTexture>false</DiffuseTexture>
|
||||||
|
<SpecularMap>false</SpecularMap>
|
||||||
|
<GlowMap>false</GlowMap>
|
||||||
|
</c:Model>
|
||||||
<c:Transform/>
|
<c:Transform/>
|
||||||
</Components>
|
</Components>
|
||||||
<Children/>
|
<Children>
|
||||||
|
<Entity name="Deploy">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>ActivateDeactiveShieldF</AnimationName>
|
||||||
|
<Play>true</Play>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="Idle">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>ShieldFrontF</AnimationName>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
</Entity>
|
</Entity>
|
||||||
<Entity name="Idle">
|
<Entity name="Front">
|
||||||
<Components>
|
<Components>
|
||||||
<c:Animation>
|
<c:Blend>
|
||||||
<AnimationName>ShieldFrontF</AnimationName>
|
<Pose1>Deploy</Pose1>
|
||||||
<Speed>1</Speed>
|
<Pose2>Idle</Pose2>
|
||||||
</c:Animation>
|
<Weight>0</Weight>
|
||||||
|
</c:Blend>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Characters/Defender/DefenderShieldFront.mesh</Resource>
|
||||||
|
<Color A="0.219607845" B="3.92156863" G="1" R="1"/>
|
||||||
|
<Shadow>false</Shadow>
|
||||||
|
<Transparent>true</Transparent>
|
||||||
|
<NormalMap>false</NormalMap>
|
||||||
|
<DiffuseTexture>false</DiffuseTexture>
|
||||||
|
<SpecularMap>false</SpecularMap>
|
||||||
|
<GlowMap>false</GlowMap>
|
||||||
|
</c:Model>
|
||||||
<c:Transform/>
|
<c:Transform/>
|
||||||
</Components>
|
</Components>
|
||||||
<Children/>
|
<Children>
|
||||||
|
<Entity name="Deploy">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>ActivateDeactiveShieldF</AnimationName>
|
||||||
|
<Play>true</Play>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="Idle">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>ShieldFrontF</AnimationName>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
</Entity>
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?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:Lifetime>
|
||||||
|
<Lifetime>1</Lifetime>
|
||||||
|
</c:Lifetime>
|
||||||
|
<c:ExplosionEffect>
|
||||||
|
<Velocity X="2" Y="2.30000019" Z="0"/>
|
||||||
|
<ExplosionDuration>1</ExplosionDuration>
|
||||||
|
<Randomness>true</Randomness>
|
||||||
|
<ExponentialAccelaration>true</ExponentialAccelaration>
|
||||||
|
</c:ExplosionEffect>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Core/UnitSphere.mesh</Resource>
|
||||||
|
<Color A="1" B="1" G="1" R="3.92156863"/>
|
||||||
|
<Shadow>false</Shadow>
|
||||||
|
<Transparent>true</Transparent>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
|
||||||
|
<Children/>
|
||||||
|
|
||||||
|
</Entity>
|
||||||
@@ -190,19 +190,28 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
|||||||
magAmmo -= 1;
|
magAmmo -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numPellets = cWeapon["NumPellets"];
|
// We can't really do any valuable calculations without a valid camera
|
||||||
float spreadAngle = cWeapon["SpreadAngle"];
|
if (!m_CurrentCamera.Valid()) {
|
||||||
std::uniform_real_distribution<float> randomSpreadAngle(-spreadAngle, spreadAngle);
|
return;
|
||||||
|
|
||||||
// Calculate pellet angles
|
|
||||||
// HACK: Random for now?
|
|
||||||
// TODO: Make distribution even for each quadrant
|
|
||||||
std::vector<glm::vec2> pelletAngles;
|
|
||||||
for (int i = 0; i < numPellets; i++) {
|
|
||||||
pelletAngles.push_back(glm::vec2(randomSpreadAngle(m_RandomEngine), randomSpreadAngle(m_RandomEngine)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double pelletDamage = (double)cWeapon["BaseDamage"] / numPellets;
|
int numPellets = cWeapon["NumPellets"];
|
||||||
|
|
||||||
|
// Create a spread pattern
|
||||||
|
std::vector<glm::vec2> pattern;
|
||||||
|
// The first pellet is always centered
|
||||||
|
pattern.push_back(glm::vec2(0, 0));
|
||||||
|
// Any additional pellets form circles around the middle
|
||||||
|
int numOuterPellets = numPellets - 1;
|
||||||
|
float angleIncrement = glm::two_pi<float>() / numOuterPellets;
|
||||||
|
for (int i = 0; i < numOuterPellets; ++i) {
|
||||||
|
float angle = angleIncrement * i;
|
||||||
|
glm::vec2 pellet = glm::vec2(glm::cos(angle), glm::sin(angle));
|
||||||
|
pattern.push_back(pellet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal damage (clientside)
|
||||||
|
dealDamage(cWeapon, wi, pattern);
|
||||||
|
|
||||||
// View punch
|
// View punch
|
||||||
if (IsClient) {
|
if (IsClient) {
|
||||||
@@ -224,7 +233,7 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tracers
|
// Tracers
|
||||||
EntityWrapper weaponModelEntity;
|
/* EntityWrapper weaponModelEntity;
|
||||||
if (wi.Player == LocalPlayer) {
|
if (wi.Player == LocalPlayer) {
|
||||||
weaponModelEntity = wi.FirstPersonEntity;
|
weaponModelEntity = wi.FirstPersonEntity;
|
||||||
} else {
|
} else {
|
||||||
@@ -243,7 +252,7 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
|||||||
glm::vec3 trajectory = direction * distance;
|
glm::vec3 trajectory = direction * distance;
|
||||||
dealDamage(cWeapon, wi, direction, pelletDamage);
|
dealDamage(cWeapon, wi, direction, pelletDamage);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Play animation
|
// Play animation
|
||||||
playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Fire");
|
playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Fire");
|
||||||
@@ -255,7 +264,7 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
|||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage)
|
void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, const std::vector<glm::vec2>& pattern)
|
||||||
{
|
{
|
||||||
// Only deal damage client side
|
// Only deal damage client side
|
||||||
if (!IsClient) {
|
if (!IsClient) {
|
||||||
@@ -271,47 +280,68 @@ void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& w
|
|||||||
if (!wi.Player.Valid()) {
|
if (!wi.Player.Valid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 maxRange = direction * 2.f;
|
// Convert the spread angle to screen coordinates, taking FOV into account
|
||||||
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
|
Rectangle res = m_Renderer->GetViewportSize();
|
||||||
glm::vec3 cameraPosition = Transform::AbsolutePosition(camera);
|
float spreadAngle = glm::radians((float)cWeapon["SpreadAngle"]);
|
||||||
if (!camera.Valid()) {
|
float nearClip = glm::radians((double)m_CurrentCamera["Camera"]["NearClip"]);
|
||||||
return;
|
float yFOV = glm::radians((double)m_CurrentCamera["Camera"]["FOV"]);
|
||||||
}
|
float yRefFOV = glm::radians(59.f);
|
||||||
Rectangle screenResolution = m_Renderer->GetViewportSize();
|
float yRef = glm::tan(yRefFOV) * nearClip;
|
||||||
glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2);
|
float yRatio = yRef / (glm::tan(yFOV) * nearClip);
|
||||||
glm::vec2 screenCoords = cameraFromEntity(m_CurrentCamera).WorldToScreen(cameraPosition + maxRange, m_Renderer->GetViewportSize());
|
float yMax = (yRatio / 2.f) * spreadAngle * (res.Height / 2.f);
|
||||||
PickData pickData = m_Renderer->Pick(centerScreen + screenCoords);
|
|
||||||
EntityWrapper victim(m_World, pickData.Entity);
|
double pelletDamage = (double)cWeapon["BaseDamage"] / pattern.size();
|
||||||
if (!victim.Valid()) {
|
|
||||||
return;
|
// Pick!
|
||||||
|
std::unordered_map<EntityWrapper, double> damageSum;
|
||||||
|
glm::vec2 screenCenter(res.Width / 2.f, res.Height / 2.f);
|
||||||
|
for (auto& pellet : pattern) {
|
||||||
|
glm::vec2 pickCoord = screenCenter + (pellet * glm::vec2(yMax, yMax));
|
||||||
|
PickData pick = m_Renderer->Pick(pickCoord);
|
||||||
|
|
||||||
|
EntityWrapper victim(m_World, pick.Entity);
|
||||||
|
if (!victim.Valid()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Temp hit decal
|
||||||
|
EntityWrapper hit = ResourceManager::Load<EntityFile>("Schema/Entities/HitTest.xml")->MergeInto(m_World);
|
||||||
|
hit["Transform"]["Position"] = pick.Position;
|
||||||
|
|
||||||
|
// Don't let us shoot ourselves in the foot somehow
|
||||||
|
if (victim == LocalPlayer) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only care about players being hit
|
||||||
|
if (!victim.HasComponent("Player")) {
|
||||||
|
victim = victim.FirstParentWithComponent("Player");
|
||||||
|
if (!victim.Valid()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for friendly fire
|
||||||
|
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
|
||||||
|
// TODO: Ammo sharing
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
damageSum[victim] += pelletDamage;
|
||||||
|
((glm::vec3&)hit["Model"]["Color"]).b = 1.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't let us shoot ourselves in the foot somehow
|
// Deal damage!
|
||||||
if (victim == LocalPlayer) {
|
for (auto& kv : damageSum) {
|
||||||
return;
|
// Deal damage!
|
||||||
|
Events::PlayerDamage ePlayerDamage;
|
||||||
|
ePlayerDamage.Inflictor = wi.Player;
|
||||||
|
ePlayerDamage.Victim = kv.first;
|
||||||
|
ePlayerDamage.Damage = kv.second;
|
||||||
|
m_EventBroker->Publish(ePlayerDamage);
|
||||||
|
LOG_DEBUG("Dealt %f damage to #%i", kv.second, kv.first.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only care about players being hit
|
|
||||||
if (!victim.HasComponent("Player")) {
|
|
||||||
victim = victim.FirstParentWithComponent("Player");
|
|
||||||
}
|
|
||||||
if (!victim.Valid()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for friendly fire
|
|
||||||
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deal damage!
|
|
||||||
Events::PlayerDamage ePlayerDamage;
|
|
||||||
ePlayerDamage.Inflictor = wi.Player;
|
|
||||||
ePlayerDamage.Victim = victim;
|
|
||||||
ePlayerDamage.Damage = damage;
|
|
||||||
m_EventBroker->Publish(ePlayerDamage);
|
|
||||||
LOG_DEBUG("Damage: %f", damage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DefenderWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi)
|
bool DefenderWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi)
|
||||||
|
|||||||
Reference in New Issue
Block a user