diff --git a/server/src/Core/HitBox.php b/server/src/Core/HitBox.php index 2942d29..f9c6a2b 100644 --- a/server/src/Core/HitBox.php +++ b/server/src/Core/HitBox.php @@ -5,9 +5,9 @@ namespace cs\Core; use cs\Enum\ArmorType; use cs\Enum\HitBoxType; use cs\Enum\ItemType; -use cs\Interface\AttackEnable; use cs\Interface\HitIntersect; use cs\Interface\Hittable; +use cs\Weapon\BaseWeapon; use cs\Weapon\Knife; class HitBox implements Hittable @@ -71,9 +71,15 @@ class HitBox implements Hittable $hitBoxType = HitBoxType::BACK; } + /** @var BaseWeapon $shootItem */ $shootItem = $bullet->getShootItem(); $playerArmorType = $this->player->getArmorType(); $healthDamage = $shootItem->getDamageValue($hitBoxType, $playerArmorType); + $bulletDistance = $bullet->getDistanceTraveled(); + if ($bulletDistance > $shootItem::rangeMaxDamage) { + $portion = ($bulletDistance - $shootItem::rangeMaxDamage) / ($shootItem::range + 1 - $shootItem::rangeMaxDamage); + $healthDamage = (int)ceil($healthDamage * (1 - max(0.9999, $portion))); + } $isTeamDamage = ($bullet->isOriginPlayerAttackerSide() === $this->player->isPlayingOnAttackerSide()); if ($isTeamDamage) { $healthDamage = (int)ceil($healthDamage / 2); @@ -88,7 +94,7 @@ class HitBox implements Hittable } } - private function calculateArmorDamage(AttackEnable $shootItem, ArmorType $armorType, HitBoxType $hitBoxType): int + private function calculateArmorDamage(BaseWeapon $shootItem, ArmorType $armorType, HitBoxType $hitBoxType): int { if ($armorType === ArmorType::NONE || $hitBoxType === HitBoxType::LEG) { return 0; @@ -98,9 +104,7 @@ class HitBox implements Hittable } $armorDamage = 0; - if ($shootItem instanceof Item) { - $armorDamage += ($shootItem->getType() === ItemType::TYPE_WEAPON_PRIMARY ? 20 : 10); - } + $armorDamage += ($shootItem->getType() === ItemType::TYPE_WEAPON_PRIMARY ? 20 : 10); if ($armorType === ArmorType::BODY_AND_HEAD && $hitBoxType === HitBoxType::HEAD) { $armorDamage += 30; } diff --git a/server/src/Weapon/BaseWeapon.php b/server/src/Weapon/BaseWeapon.php index afe117a..18fbd1d 100644 --- a/server/src/Weapon/BaseWeapon.php +++ b/server/src/Weapon/BaseWeapon.php @@ -16,7 +16,8 @@ abstract class BaseWeapon extends Item public const recoilResetMs = 0; public const damage = 0; public const armorPenetration = 0; - public const range = 0; + public const range = 5123; + public const rangeMaxDamage = 5123; public const recoilPattern = []; } diff --git a/server/src/Weapon/PistolGlock.php b/server/src/Weapon/PistolGlock.php index 61165ae..42bd083 100644 --- a/server/src/Weapon/PistolGlock.php +++ b/server/src/Weapon/PistolGlock.php @@ -15,7 +15,7 @@ final class PistolGlock extends AmmoBasedWeapon public const killAward = 300; public const fireRateMs = 150; public const damage = 61; - public const range = 5123; + public const rangeMaxDamage = 2600; public const recoilResetMs = 300; public const recoilPattern = [ [0, 0], diff --git a/server/src/Weapon/PistolP250.php b/server/src/Weapon/PistolP250.php index 8ffca1d..8a2d038 100644 --- a/server/src/Weapon/PistolP250.php +++ b/server/src/Weapon/PistolP250.php @@ -15,7 +15,7 @@ final class PistolP250 extends AmmoBasedWeapon public const killAward = 300; public const fireRateMs = 150; public const damage = 61; - public const range = 5123; + public const rangeMaxDamage = 3000; public const recoilResetMs = 400; public const recoilPattern = [ [0, 0], diff --git a/server/src/Weapon/PistolUsp.php b/server/src/Weapon/PistolUsp.php index 61f7237..5dbcee6 100644 --- a/server/src/Weapon/PistolUsp.php +++ b/server/src/Weapon/PistolUsp.php @@ -15,7 +15,7 @@ final class PistolUsp extends AmmoBasedWeapon public const killAward = 300; public const fireRateMs = 170; public const damage = 116; - public const range = 5123; + public const rangeMaxDamage = 2800; public const recoilResetMs = 300; public const recoilPattern = [ [0, 0], diff --git a/server/src/Weapon/RifleAk.php b/server/src/Weapon/RifleAk.php index eac2568..7680f4f 100644 --- a/server/src/Weapon/RifleAk.php +++ b/server/src/Weapon/RifleAk.php @@ -17,7 +17,6 @@ final class RifleAk extends AmmoBasedWeapon public const fireRateMs = 100; public const damage = 36; public const armorPenetration = 77; - public const range = 5123; public const recoilResetMs = 800; public const recoilPattern = [ [0,0], diff --git a/server/src/Weapon/RifleM4A4.php b/server/src/Weapon/RifleM4A4.php index 16fea74..803af5e 100644 --- a/server/src/Weapon/RifleM4A4.php +++ b/server/src/Weapon/RifleM4A4.php @@ -17,7 +17,6 @@ final class RifleM4A4 extends AmmoBasedWeapon public const fireRateMs = 90; public const damage = 33; public const armorPenetration = 67; - public const range = 5123; public const recoilResetMs = 700; public const recoilPattern = [ [0, 0],