public void AttackMissed(Attackable target, DamageType damageType) { var attackMissedCommand = AttackMissedCommand.write(new AttackTypeModule((short)damageType), target.Id, 0); var attackMissedCommandToInRange = AttackMissedCommand.write(new AttackTypeModule((short)damageType), target.Id, 1); Player.SendCommand(attackMissedCommand); Player.SendCommandToInRangePlayers(attackMissedCommandToInRange); }
public void Attack(Attackable target, double shieldPenetration = 0) { var missProbability = Type == StationModuleModule.LASER_LOW_RANGE ? 0.1 : Type == StationModuleModule.LASER_MID_RANGE ? 0.3 : Type == StationModuleModule.LASER_HIGH_RANGE ? 0.4 : Type == StationModuleModule.ROCKET_LOW_ACCURACY ? 0.5 : Type == StationModuleModule.ROCKET_MID_ACCURACY ? 0.3 : 1.00; var damage = AttackManager.RandomizeDamage((Type == StationModuleModule.LASER_LOW_RANGE ? 59850 : Type == StationModuleModule.LASER_MID_RANGE ? 48450 : Type == StationModuleModule.LASER_HIGH_RANGE ? 28500 : Type == StationModuleModule.ROCKET_LOW_ACCURACY ? 85500 : Type == StationModuleModule.ROCKET_MID_ACCURACY ? 71250 : 0), missProbability); damage = 1000; //for test var damageType = (Type == StationModuleModule.LASER_LOW_RANGE || Type == StationModuleModule.LASER_MID_RANGE || Type == StationModuleModule.LASER_HIGH_RANGE) ? DamageType.LASER : (Type == StationModuleModule.ROCKET_LOW_ACCURACY || Type == StationModuleModule.ROCKET_MID_ACCURACY) ? DamageType.ROCKET : DamageType.LASER; var cooldown = (Type == StationModuleModule.ROCKET_LOW_ACCURACY || Type == StationModuleModule.ROCKET_MID_ACCURACY) ? 2 : 1; if (target.Position.DistanceTo(Position) < GetRange()) { if (!TargetDefinition(target)) { return; } if (lastAttackTime.AddSeconds(cooldown) < DateTime.Now) { int damageShd = 0, damageHp = 0; double shieldAbsorb = System.Math.Abs(target.ShieldAbsorption - shieldPenetration); if (shieldAbsorb > 1) { shieldAbsorb = 1; } if ((target.CurrentShieldPoints - damage) >= 0) { damageShd = (int)(damage * shieldAbsorb); damageHp = damage - damageShd; } else { int newDamage = damage - target.CurrentShieldPoints; damageShd = target.CurrentShieldPoints; damageHp = (int)(newDamage + (damageShd * shieldAbsorb)); } if ((target.CurrentHitPoints - damageHp) < 0) { damageHp = target.CurrentHitPoints; } if (target is Player && !(target as Player).Attackable()) { damage = 0; damageShd = 0; damageHp = 0; } if (damageType == DamageType.LASER) { if (target is Player && (target as Player).Storage.Sentinel) { damageShd -= Maths.GetPercentage(damageShd, 30); } if (target is Player && (target as Player).Storage.Diminisher) { if ((target as Player).Storage.UnderDiminisherEntity == this) { damageShd += Maths.GetPercentage(damage, 30); } } var laserRunCommand = AttackLaserRunCommand.write(Id, target.Id, 0, false, false); SendCommandToInRangeCharacters(laserRunCommand); } else if (damageType == DamageType.ROCKET) { var rocketRunPacket = $"0|v|{Id}|{target.Id}|H|" + 1 + "|0|1"; SendPacketToInRangeCharacters(rocketRunPacket); } if (damage == 0) { SendCommandToInRangeCharacters(AttackMissedCommand.write(new AttackTypeModule((short)damageType), target.Id, 1), target); if (target is Player) { (target as Player).SendCommand(AttackMissedCommand.write(new AttackTypeModule((short)damageType), target.Id, 0)); } } else { var attackHitCommand = AttackHitCommand.write(new AttackTypeModule((short)damageType), Id, target.Id, target.CurrentHitPoints, target.CurrentShieldPoints, target.CurrentNanoHull, damage > damageShd ? damage : damageShd, false); SendCommandToInRangeCharacters(attackHitCommand); } if (damageHp >= target.CurrentHitPoints || target.CurrentHitPoints <= 0) { target.Destroy(this, DestructionType.MISC); } else { if (target.CurrentNanoHull > 0) { if (target.CurrentNanoHull - damageHp < 0) { var nanoDamage = damageHp - target.CurrentNanoHull; target.CurrentNanoHull = 0; target.CurrentHitPoints -= nanoDamage; } else { target.CurrentNanoHull -= damageHp; } } else { target.CurrentHitPoints -= damageHp; } } target.CurrentShieldPoints -= damageShd; target.LastCombatTime = DateTime.Now; target.UpdateStatus(); lastAttackTime = DateTime.Now; } } }
public static void Damage(Player attacker, Attackable target, DamageType damageType, int damage, bool toDestroy, bool toHp, bool toShd, bool missedEffect = true) { if (damageType == DamageType.MINE && target.Invincible) { return; } if (attacker.Invincible && damageType != DamageType.RADIATION) { attacker.Storage.DeactiveInvincibilityEffect(); } if (target is Player && !(target as Player).Attackable()) { if (missedEffect) { var attackMissedCommandToInRange = AttackMissedCommand.write(new AttackTypeModule((short)damageType), target.Id, 0); var attackMissedCommand = AttackMissedCommand.write(new AttackTypeModule((short)damageType), target.Id, 0); attacker.SendCommand(attackMissedCommand); attacker.SendCommandToInRangePlayers(attackMissedCommandToInRange); } damage = 0; return; } target.LastCombatTime = DateTime.Now; if (toHp && toDestroy && (damage >= target.CurrentHitPoints || target.CurrentHitPoints <= 0)) { if (damageType == DamageType.RADIATION) { target.Destroy(null, DestructionType.RADIATION); } else if (damageType == DamageType.MINE && attacker.Attackers.Count <= 0) { target.Destroy(null, DestructionType.MINE); } else { target.Destroy(attacker, DestructionType.PLAYER); } } else if (toHp) { if (target.CurrentNanoHull > 0) { if (target.CurrentNanoHull - damage < 0) { var nanoDamage = damage - target.CurrentNanoHull; target.CurrentNanoHull = 0; target.CurrentHitPoints -= nanoDamage; } else { target.CurrentNanoHull -= damage; } } else { target.CurrentHitPoints -= damage; } } if (toShd) { target.CurrentShieldPoints -= damage; } var attackHitCommand = AttackHitCommand.write(new AttackTypeModule((short)damageType), attacker.Id, target.Id, target.CurrentHitPoints, target.CurrentShieldPoints, target.CurrentNanoHull, damage, false); attacker.SendCommand(attackHitCommand); attacker.SendCommandToInRangePlayers(attackHitCommand); target.UpdateStatus(); }
public void Attack() { var damage = AttackManager.RandomizeDamage(Damage, (Storage.underPLD8 ? 0.5 : 0.1)); var target = SelectedCharacter; if (!TargetDefinition(target, false)) { return; } if (target is Player player && player.AttackManager.EmpCooldown.AddMilliseconds(TimeManager.EMP_DURATION) > DateTime.Now) { return; } if (lastAttackTime.AddSeconds(1) < DateTime.Now) { if (target is Player && (target as Player).Storage.Spectrum) { damage -= Maths.GetPercentage(damage, 50); } int damageShd = 0, damageHp = 0; double shieldAbsorb = System.Math.Abs(target.ShieldAbsorption - 0); if (shieldAbsorb > 1) { shieldAbsorb = 1; } if ((target.CurrentShieldPoints - damage) >= 0) { damageShd = (int)(damage * shieldAbsorb); damageHp = damage - damageShd; } else { int newDamage = damage - target.CurrentShieldPoints; damageShd = target.CurrentShieldPoints; damageHp = (int)(newDamage + (damageShd * shieldAbsorb)); } if ((target.CurrentHitPoints - damageHp) < 0) { damageHp = target.CurrentHitPoints; } if (target is Player && !(target as Player).Attackable()) { damage = 0; damageShd = 0; damageHp = 0; } if (target is Player && (target as Player).Storage.Sentinel) { damageShd -= Maths.GetPercentage(damageShd, 30); } var laserRunCommand = AttackLaserRunCommand.write(Id, target.Id, 0, false, false); SendCommandToInRangePlayers(laserRunCommand); if (damage == 0) { var attackMissedCommandToInRange = AttackMissedCommand.write(new AttackTypeModule(AttackTypeModule.LASER), target.Id, 1); SendCommandToInRangePlayers(attackMissedCommandToInRange); } else { var attackHitCommand = AttackHitCommand.write(new AttackTypeModule(AttackTypeModule.LASER), Id, target.Id, target.CurrentHitPoints, target.CurrentShieldPoints, target.CurrentNanoHull, damage > damageShd ? damage : damageShd, false); SendCommandToInRangePlayers(attackHitCommand); } if (damageHp >= target.CurrentHitPoints || target.CurrentHitPoints <= 0) { target.Destroy(this, DestructionType.NPC); } else { target.CurrentHitPoints -= damageHp; } target.CurrentShieldPoints -= damageShd; target.LastCombatTime = DateTime.Now; lastAttackTime = DateTime.Now; target.UpdateStatus(); } }