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);
        }
Exemplo n.º 2
0
        public void RocketAttack(ref int lapCount, RocketAmmunition rocket, bool force = false)
        {
            lock (_rocketLock) {
                #region {[ CHECKING ]}
                if (PlayerController.Locked == null ||
                    (rocket.ID != RocketAmmunition.R_IC3.ID && PlayerController.Locked.MovementAssembly.ActualPosition()
                     .DistanceTo(PlayerController.MovementAssembly.ActualPosition()) > 650) ||
                    PlayerController.Locked.MovementAssembly.ActualPosition()
                    .DistanceTo(PlayerController.MovementAssembly.ActualPosition()) > 550 ||
                    (!force && !_attackRunning))
                {
                    return;
                }

                if (PlayerController.Locked.ZoneAssembly.IsInDMZ)
                {
                    PlayerController.Send(PacketBuilder.Messages.PeaceArea());
                    return;
                }

                if (!CheckRocketCount(rocket, false, out int currentCount))
                {
                    PlayerController.Send(PacketBuilder.Messages.NoRocketAmmo());
                    return;
                }

                if (!RocketCooldown(ref lapCount, rocket))
                {
                    return;
                }
                #endregion

                CheckRocketCount(rocket, true, out currentCount); // deduct count

                LastAttack = PlayerController.CurrentClock.ElapsedMilliseconds;
                ICommand attackCommand = PacketBuilder.AttackRocketCommand(PlayerController, PlayerController.Locked, rocket.ID);
                PlayerController.Send(attackCommand, PacketBuilder.Slotbar.RocketItemStatus(rocket.Name, currentCount, true));
                PlayerController.EntitesInRange(x => x.Send(attackCommand));

                if (PlayerController.Locked.EffectsAssembly.HasProtection ||
                    (PlayerController.Locked is PlayerController lockedPlayerController && lockedPlayerController.SpecialItemsAssembly.IsInvicible) ||
                    (!PlayerController.PlayerTechAssembly.PrecisionTargeterActive && Miss()))
                {
                    PlayerController.Locked.AttackTraceAssembly.LogAttack(PlayerController, 0, 0);
                    ICommand missCommand = new AttackMissedCommand(new AttackTypeModule(AttackTypeModule.LASER), PlayerController.Locked.ID, 0);
                    PlayerController.Locked.Send(new AttackMissedCommand(new AttackTypeModule(AttackTypeModule.LASER), PlayerController.Locked.ID, 1));
                    PlayerController.Locked.EntitiesLocked(x => x.Send(missCommand));
                    return;
                }

                RocketDelayedAttack(PlayerController.Locked, rocket);
            }
        }
        public void CheckOrStopSingularity(bool force = false)
        {
            try {
                ShipAbility ability = ShipAbility.SINGULARITY;

                PlayerController.Account.Cooldown.AbilityCooldown.TryGetValue(ability.ID, out DateTime lastAbilityTime);
                if (_singularityActive && (_singularityCounter == (int)ability.Duration.TotalSeconds * 2 || force))
                {
                    _singularityActive = false;
                    PlayerController.Account.Cooldown.AbilityCooldown[ability.ID] = DateTime.Now - ability.Duration;

                    PlayerController.EffectsAssembly.DeactivateSingularity();
                    PlayerController.Locked.EffectsAssembly.DeactivateSingularity();

                    PlayerController.Send(PacketBuilder.Slotbar.ItemCooldownCommand(ability.Name, ability.Cooldown.TotalMilliseconds));
                }
                else if (_singularityActive)
                {
                    if (++_singularityCounter % 2 == 0)
                    {
                        if (PlayerController.Locked.EffectsAssembly.HasProtection ||
                            (PlayerController.Locked is PlayerController lockedPlayerController &&
                             lockedPlayerController.SpecialItemsAssembly.IsInvicible))
                        {
                            PlayerController.Locked.AttackTraceAssembly.LogAttack(PlayerController, 0, 0, false);
                            ICommand missCommand = new AttackMissedCommand(new AttackTypeModule(AttackTypeModule.SINGULARITY), PlayerController.Locked.ID, 0);
                            PlayerController.Locked.Send(new AttackMissedCommand(new AttackTypeModule(AttackTypeModule.SINGULARITY), PlayerController.Locked.ID, 1));
                            PlayerController.Locked.EntitiesLocked(x => x.Send(missCommand));
                        }
                        else
                        {
                            PlayerController.Locked.HangarAssembly.ChangeHitpoints(-_singularityLastDamage, false);
                            PlayerController.Locked.AttackTraceAssembly.LogAttack(PlayerController, 0, _singularityLastDamage, false);
                            PlayerController.Locked.HangarAssembly.CheckDeath();

                            ICommand damageCommand = PacketBuilder.AttackCommand(PlayerController, PlayerController.Locked, AttackTypeModule.SINGULARITY, _singularityLastDamage);
                            PlayerController.Locked.Send(damageCommand);                        // send to player
                            PlayerController.Locked.EntitiesLocked(y => y.Send(damageCommand)); // send to all who have him in lock
                        }

                        _singularityLastDamage += _singularityDamageIncrease;
                    }
                }
            } catch { }
        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(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;
                }
            }
        }
Exemplo n.º 6
0
        public void RocketLauncherAttack(int count, RocketLauncherAmmunition rlAmmo)
        {
            lock (_rocketLauncherLock) {
                #region {[ CHECKING ]}
                if (PlayerController.Locked == null ||
                    PlayerController.Locked.MovementAssembly.ActualPosition()
                    .DistanceTo(PlayerController.MovementAssembly.ActualPosition()) > 650 ||
                    count <= 0)
                {
                    return;
                }

                if (PlayerController.Locked.ZoneAssembly.IsInDMZ)
                {
                    PlayerController.Send(PacketBuilder.Messages.PeaceArea());
                    return;
                }

                if (!RocketLauncherCooldown())
                {
                    return;
                }

                CheckRocketLauncherCount(rlAmmo, count, out int currentCount);
                #endregion

                LastAttack = PlayerController.CurrentClock.ElapsedMilliseconds;
                _lastRocketLauncherAttack = PlayerController.CurrentClock.ElapsedMilliseconds;
                PlayerController.Account.CurrentHangar.Selection.RocketLauncherLoadedCount = 0;

                ICommand attackCommand = PacketBuilder.AttackHellstormCommand(PlayerController, PlayerController.Locked, count, (short)rlAmmo.ID);
                PlayerController.Send(
                    attackCommand,
                    PacketBuilder.Slotbar.RocketLauncherStateCommand(PlayerController),
                    PacketBuilder.Slotbar.ItemCooldownCommand("equipment_weapon_rocketlauncher_hst", (int)(3000 * PlayerController.BoosterAssembly.Get(BoosterType.ROCKET_LAUNCHER_COOLDOWN))),
                    PacketBuilder.Slotbar.RocketItemStatus(rlAmmo.Name, currentCount, false)
                    );
                PlayerController.EntitesInRange(x => x.Send(attackCommand));

                int hitCount = 0;
                for (int i = 0; i < count; i++)
                {
                    if (!Miss())
                    {
                        hitCount++;
                    }
                }

                if (PlayerController.Locked.EffectsAssembly.HasProtection ||
                    (rlAmmo.ID != RocketLauncherAmmunition.HSTRM_01.ID &&
                     PlayerController.Locked is PlayerController lockedPlayerController &&
                     lockedPlayerController.SpecialItemsAssembly.IsInvicible) ||
                    hitCount == 0)
                {
                    PlayerController.Locked.AttackTraceAssembly.LogAttack(PlayerController, 0, 0);
                    ICommand missCommand = new AttackMissedCommand(new AttackTypeModule(AttackTypeModule.LASER), PlayerController.Locked.ID, 0);
                    PlayerController.Locked.Send(new AttackMissedCommand(new AttackTypeModule(AttackTypeModule.LASER), PlayerController.Locked.ID, 1));
                    PlayerController.Locked.EntitiesLocked(x => x.Send(missCommand));
                    return;
                }

                RocketLauncherDelayedAttack(PlayerController.Locked, rlAmmo, hitCount);
            }
        }
Exemplo n.º 7
0
        public void LaserAttack(ref int lapCount, Ammuninition ammo)
        {
            lock (_laserLock) {
                #region {[ CHECKING ]}
                if (PlayerController.Locked == null ||
                    PlayerController.Locked.MovementAssembly.ActualPosition()
                    .DistanceTo(PlayerController.MovementAssembly.ActualPosition()) > 600 ||
                    !_attackRunning)
                {
                    return;
                }

                bool stopLoop   = true;
                bool stopAttack = false;
                if (PlayerController.Locked.ZoneAssembly.IsInDMZ)
                {
                    PlayerController.Send(PacketBuilder.Messages.PeaceArea());
                    stopAttack = true;
                }

                if (!PlayerController.Account.CurrentHangar.LaserEquipped)
                {
                    PlayerController.Send(PacketBuilder.Messages.NoLasersOnBoard());
                    stopAttack = true;
                }

                if (!stopAttack && !CheckLaserCount(ammo, false, out int currentCount))
                {
                    PlayerController.Send(PacketBuilder.Messages.NoLaserAmmo());
                    stopAttack = true;
                }

                if (!stopAttack && !LaserCooldown(ref lapCount, ammo))
                {
                    stopAttack = true;
                    stopLoop   = false;
                }

                if (stopAttack)
                {
                    if (stopLoop)
                    {
                        Stop();
                    }

                    return;
                }
                #endregion

                CheckLaserCount(ammo, true, out currentCount); // deduct

                LastAttack = PlayerController.CurrentClock.ElapsedMilliseconds;
                ICommand attackCommand = PacketBuilder.AttackLaserCommand(PlayerController, PlayerController.Locked, ammo.ID);
                PlayerController.Send(attackCommand, PacketBuilder.Slotbar.LaserItemStatus(ammo.Name, currentCount, true));
                PlayerController.EntitesInRange(x => x.Send(attackCommand));

                if (PlayerController.Locked.EffectsAssembly.HasProtection ||
                    (PlayerController.Locked is PlayerController lockedPlayerController && lockedPlayerController.SpecialItemsAssembly.IsInvicible) ||
                    Miss())
                {
                    PlayerController.Locked.AttackTraceAssembly.LogAttack(PlayerController, 0, 0);
                    ICommand missCommand = new AttackMissedCommand(new AttackTypeModule(AttackTypeModule.LASER), PlayerController.Locked.ID, 0);
                    PlayerController.Locked.Send(new AttackMissedCommand(new AttackTypeModule(AttackTypeModule.LASER), PlayerController.Locked.ID, 1));
                    PlayerController.Locked.EntitiesLocked(x => x.Send(missCommand));
                    return;
                }

                CalculateLaserDamage(ammo, PlayerController.Locked, out double damage, out double shieldDamage);

                if (shieldDamage > 0)
                {
                    shieldDamage = Math.Abs(PlayerController.Locked.HangarAssembly.ChangeShield(-(int)shieldDamage, false));
                    PlayerController.HangarAssembly.ChangeShield((int)shieldDamage);
                }

                double shieldDamageDealt    = shieldDamage;
                double hitpointsDamageDealt = 0;

                if (damage > 0)
                {
                    double shieldAbsorption = Math.Max(0, Math.Min(1, PlayerController.Locked.BoosterAssembly.Get(BoosterType.SHIELD_ABSORBATION) - (PlayerController.BoosterAssembly.Get(BoosterType.LASER_SHIELD_PENETRATION) - 1)));

                    double damageShield = damage * shieldAbsorption;
                    if (PlayerController.PlayerAbilityAssembly.WeakenShieldsActive &&
                        PlayerController.PlayerAbilityAssembly.WeakenShieldsVictim.ID == PlayerController.Locked.ID)
                    {
                        damageShield *= 1.6;
                    }

                    damageShield = Math.Abs(PlayerController.Locked.HangarAssembly.ChangeShield(-(int)damageShield, false));
                    int damageHitpoints = Math.Abs(PlayerController.Locked.HangarAssembly.ChangeHitpoints(-(int)(damage - Math.Min(damage * shieldAbsorption, damageShield)), false));

                    shieldDamageDealt    += damageShield;
                    hitpointsDamageDealt += damageHitpoints;

                    // energy transfer
                    double hitpointsRegain = PlayerController.BoosterAssembly.Get(BoosterType.DAMAGE_LASER_TO_HITPOINTS_TRANSFORMER) - 1.0;
                    if (hitpointsRegain > 0 && ammo.ID == Ammuninition.UCB_100.ID)
                    {
                        int regain = PlayerController.HangarAssembly.ChangeHitpoints(Math.Max(0, (int)((damageShield + damageHitpoints) * hitpointsRegain)));
                        if (regain > 0 && !PlayerController.PlayerTechAssembly.EnergyTransferActive && ++_healCounter % 2 == 0)
                        {
                            _healCounter = 0;

                            ICommand energyTransferCommand = PacketBuilder.AttackLaserCommand(PlayerController.Locked, PlayerController, 7);
                            PlayerController.Locked.Send(energyTransferCommand);                        // send to player
                            PlayerController.Locked.EntitesInRange(y => y.Send(energyTransferCommand)); // send to all who have him in lock
                        }
                    }
                }

                // set stats
                PlayerController.Locked.AttackTraceAssembly.LogAttack(PlayerController, (int)shieldDamageDealt, (int)hitpointsDamageDealt);
                PlayerController.Locked.HangarAssembly.CheckDeath();

                ActivateLaserSpecialAttack(ammo);    // initialize special attack

                if (PlayerController.Locked != null) // Locked kann nach der CheckDeath-Methode tot sein (wahrscheinlichkeit: hoch)
                {
                    ICommand damageCommand = PacketBuilder.AttackCommand(PlayerController, PlayerController.Locked, AttackTypeModule.LASER, (int)(shieldDamageDealt + hitpointsDamageDealt));
                    PlayerController.Locked.Send(damageCommand);                        // send to player
                    PlayerController.Locked.EntitiesLocked(y => y.Send(damageCommand)); // send to all who have him in lock
                }
            }
        }
Exemplo n.º 8
0
        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();
            }
        }