mirror of
https://github.com/MathiasLui/CSGO-Projects.git
synced 2025-05-06 22:01:18 +00:00
Add taser to weapon list
* Taser has new shock damage type, that doesn't account for multipliers/armor
This commit is contained in:
parent
bce1fa13fa
commit
65959bff26
3 changed files with 110 additions and 48 deletions
|
@ -1055,51 +1055,59 @@ namespace Damage_Calculator
|
||||||
// Range
|
// Range
|
||||||
damage *= Math.Pow(this.selectedWeapon.DamageDropoff, double.Parse((this.unitsDistance / 500f).ToString()));
|
damage *= Math.Pow(this.selectedWeapon.DamageDropoff, double.Parse((this.unitsDistance / 500f).ToString()));
|
||||||
|
|
||||||
// Multipliers and armor penetration
|
switch (this.selectedWeapon.DamageType)
|
||||||
if (radioHead.IsChecked == true)
|
|
||||||
{
|
{
|
||||||
// Headshot
|
case DamageType.Shock:
|
||||||
damage *= this.selectedWeapon.HeadshotModifier;
|
// Deals the same damage everywhere
|
||||||
|
break;
|
||||||
|
case DamageType.Bullet:
|
||||||
|
// Multipliers and armor penetration
|
||||||
|
if (radioHead.IsChecked == true)
|
||||||
|
{
|
||||||
|
// Headshot
|
||||||
|
damage *= this.selectedWeapon.HeadshotModifier;
|
||||||
|
|
||||||
if (chkHelmet.IsChecked == true)
|
if (chkHelmet.IsChecked == true)
|
||||||
{
|
{
|
||||||
// Has helmet
|
// Has helmet
|
||||||
double previousDamage = damage;
|
double previousDamage = damage;
|
||||||
damage *= this.selectedWeapon.ArmorPenetration / 100f;
|
damage *= this.selectedWeapon.ArmorPenetration / 100f;
|
||||||
absorbedDamageByArmor = previousDamage - (int)damage;
|
absorbedDamageByArmor = previousDamage - (int)damage;
|
||||||
wasArmorHit = true;
|
wasArmorHit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (radioChestArms.IsChecked == true)
|
else if (radioChestArms.IsChecked == true)
|
||||||
{
|
{
|
||||||
// Chest or arms
|
// Chest or arms
|
||||||
if (chkKevlar.IsChecked == true)
|
if (chkKevlar.IsChecked == true)
|
||||||
{
|
{
|
||||||
// Has kevlar
|
// Has kevlar
|
||||||
double previousDamage = damage;
|
double previousDamage = damage;
|
||||||
damage *= this.selectedWeapon.ArmorPenetration / 100f;
|
damage *= this.selectedWeapon.ArmorPenetration / 100f;
|
||||||
absorbedDamageByArmor = previousDamage - (int)damage;
|
absorbedDamageByArmor = previousDamage - (int)damage;
|
||||||
wasArmorHit = true;
|
wasArmorHit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (radioStomach.IsChecked == true)
|
else if (radioStomach.IsChecked == true)
|
||||||
{
|
{
|
||||||
// Stomach
|
// Stomach
|
||||||
damage *= 1.25f;
|
damage *= 1.25f;
|
||||||
|
|
||||||
if (chkKevlar.IsChecked == true)
|
if (chkKevlar.IsChecked == true)
|
||||||
{
|
{
|
||||||
// Has kevlar
|
// Has kevlar
|
||||||
double previousDamage = damage;
|
double previousDamage = damage;
|
||||||
damage *= this.selectedWeapon.ArmorPenetration / 100f;
|
damage *= this.selectedWeapon.ArmorPenetration / 100f;
|
||||||
absorbedDamageByArmor = previousDamage - (int)damage;
|
absorbedDamageByArmor = previousDamage - (int)damage;
|
||||||
wasArmorHit = true;
|
wasArmorHit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Legs
|
// Legs
|
||||||
damage *= 0.75f;
|
damage *= 0.75f;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
txtResult.Text = ((int)damage).ToString();
|
txtResult.Text = ((int)damage).ToString();
|
||||||
|
|
|
@ -235,11 +235,12 @@ namespace Shared
|
||||||
Element items = vdfItems["items_game"]?["items"]!;
|
Element items = vdfItems["items_game"]?["items"]!;
|
||||||
|
|
||||||
if (prefabs == null || items == null)
|
if (prefabs == null || items == null)
|
||||||
|
// There is no prefab list or item list to read out
|
||||||
return null!;
|
return null!;
|
||||||
|
|
||||||
var weapons = new List<CsgoWeapon>();
|
var weapons = new List<CsgoWeapon>();
|
||||||
|
|
||||||
foreach(var item in items.Children)
|
foreach (var item in items.Children)
|
||||||
{
|
{
|
||||||
string? itemPrefab = item["prefab"]?.Value!;
|
string? itemPrefab = item["prefab"]?.Value!;
|
||||||
string? itemName = item["name"].Value;
|
string? itemName = item["name"].Value;
|
||||||
|
@ -247,11 +248,25 @@ namespace Shared
|
||||||
if (itemPrefab == null || !itemName!.StartsWith("weapon_"))
|
if (itemPrefab == null || !itemName!.StartsWith("weapon_"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Here we're sure the item is supposed to be a weapon
|
||||||
|
|
||||||
var weapon = new CsgoWeapon();
|
var weapon = new CsgoWeapon();
|
||||||
weapon.ClassName = itemName;
|
weapon.ClassName = itemName;
|
||||||
|
|
||||||
if(this.tryPopulateWeapon(weapon, prefabs, itemPrefab))
|
// Handle weapon specific modifications before fetching its attributes
|
||||||
|
switch (weapon.ClassName)
|
||||||
{
|
{
|
||||||
|
case "weapon_taser":
|
||||||
|
weapon.DamageType = DamageType.Shock;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
weapon.DamageType = DamageType.Bullet;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.tryPopulateWeapon(weapon, prefabs, itemPrefab))
|
||||||
|
{
|
||||||
|
// Item has an initial prefab and is allowed based on the conditions met in isWeaponFireable()
|
||||||
weapons.Add(weapon);
|
weapons.Add(weapon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,8 +274,29 @@ namespace Shared
|
||||||
return weapons;
|
return weapons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool isWeaponFireable(CsgoWeapon weapon, List<string>? prefabTrace)
|
||||||
|
{
|
||||||
|
bool isWhitelisted = false;
|
||||||
|
|
||||||
|
if(prefabTrace != null)
|
||||||
|
{
|
||||||
|
// Stuff involving prefab trace here
|
||||||
|
if(prefabTrace.FirstOrDefault(pr => pr == "primary" || pr == "secondary") != null)
|
||||||
|
// Allow any weapon in the primary or secondary slot
|
||||||
|
isWhitelisted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Other
|
||||||
|
if(weapon.ClassName == "weapon_taser")
|
||||||
|
// Allow zeus, even though it's "equipment" and listed in the melee slot
|
||||||
|
isWhitelisted = true;
|
||||||
|
|
||||||
|
return isWhitelisted;
|
||||||
|
}
|
||||||
|
|
||||||
private bool tryPopulateWeapon(CsgoWeapon weapon, Element prefabs, string prefabName, List<string>? prefabTrace = null)
|
private bool tryPopulateWeapon(CsgoWeapon weapon, Element prefabs, string prefabName, List<string>? prefabTrace = null)
|
||||||
{
|
{
|
||||||
|
// Get the initial prefab specified in the item
|
||||||
Element prefab = prefabs[prefabName];
|
Element prefab = prefabs[prefabName];
|
||||||
|
|
||||||
if (prefab == null)
|
if (prefab == null)
|
||||||
|
@ -269,16 +305,24 @@ namespace Shared
|
||||||
|
|
||||||
string nextPrefab = prefab["prefab"]?.Value!;
|
string nextPrefab = prefab["prefab"]?.Value!;
|
||||||
|
|
||||||
if (prefab == null || (nextPrefab == null && prefabTrace?.FirstOrDefault(pr => pr == "primary" || pr == "secondary") == null))
|
if (nextPrefab == null)
|
||||||
// We've reached the end of abstraction but it wasn't found to be primary nor secondary
|
// We've reached the end of abstraction but it wasn't found to be primary nor secondary
|
||||||
return false;
|
// However the taser is special because it's "equipment" and not primary or secondary.
|
||||||
|
// So we will treat it like a special lil guy and add him either way
|
||||||
|
if (!this.isWeaponFireable(weapon, prefabTrace))
|
||||||
|
{
|
||||||
|
// We're done but we don't want this fucker included as a weapon
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool gatheredAllInfo = true;
|
bool gatheredAllInfo = true;
|
||||||
|
|
||||||
Element attributes = prefab["attributes"];
|
Element attributes = prefab["attributes"];
|
||||||
|
|
||||||
if (attributes == null)
|
if (attributes == null && nextPrefab != null)
|
||||||
return false;
|
// it might have no attributes but just skip to the next prefab in that case, because they might have attributes
|
||||||
|
// one example of this is the taser (zeus)
|
||||||
|
return this.tryPopulateWeapon(weapon, prefabs, nextPrefab, prefabTrace);
|
||||||
|
|
||||||
// =========================== ATTRIBUTES =========================== //
|
// =========================== ATTRIBUTES =========================== //
|
||||||
|
|
||||||
|
@ -365,6 +409,8 @@ namespace Shared
|
||||||
// ================================================================== //
|
// ================================================================== //
|
||||||
|
|
||||||
if (gatheredAllInfo || nextPrefab == null)
|
if (gatheredAllInfo || nextPrefab == null)
|
||||||
|
// We've got all we need or we've reached the end of abstraction
|
||||||
|
// We're sure the weapon is for example either primary, secondary or it's the zeus, since it's treated as "equipment" instead
|
||||||
return true; // ?
|
return true; // ?
|
||||||
|
|
||||||
if (prefabTrace == null)
|
if (prefabTrace == null)
|
||||||
|
|
|
@ -45,5 +45,13 @@ namespace Shared.Models
|
||||||
/// Gets or sets the multiplier of headshots by this weapon. At the point of writing this is "4" for all weapons except two.
|
/// Gets or sets the multiplier of headshots by this weapon. At the point of writing this is "4" for all weapons except two.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float HeadshotModifier { get; set; } = -1;
|
public float HeadshotModifier { get; set; } = -1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the type of damage done by this weapon.
|
||||||
|
/// Used for damage multipliers, since shock damage deals the same damage on every hitgroup.
|
||||||
|
/// </summary>
|
||||||
|
public DamageType DamageType { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DamageType { Bullet, Shock }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue