Exemplo n.º 1
0
        public void Kill()
        {
            lock (ThreadLock)
            {
                if (Character.EntityState == EntityStates.DEAD)
                {
                    return;
                }

                GameClient.SendToPlayerView(Character, ShipDestroyedCommand.write(Character.Id, 0), true);
                GameClient.SendToPlayerView(Character,
                                            netty.commands.old_client.ShipDestroyedCommand.write(Character.Id, 0),
                                            true);

                Character.EntityState = EntityStates.DEAD;

                Character.Invalidate();

                Character.CurrentHealth   = 0;
                Character.CurrentNanoHull = 0;
                Character.CurrentShield   = 0;

                if (Character is Player player)
                {
                    var lowerMapRespawn = player.Spacemap.Disabled;
                    var closestStation  = player.GetClosestStation(lowerMapRespawn);
                    var newPos          = closestStation.Item1;
                    player.MoveToMap(closestStation.Item2, newPos, 0);
                    player.Save();
                }
            }
        }
Exemplo n.º 2
0
        public void Destroy(Attackable destroyer, DestructionType destructionType)
        {
            if (this is Spaceball || Destroyed)
            {
                return;
            }

            if (MainAttacker != null && MainAttacker is Player)
            {
                destroyer       = MainAttacker;
                destructionType = DestructionType.PLAYER;
            }

            Destroyed = true;

            var destroyCommand = ShipDestroyedCommand.write(Id, 0);

            if (this is Activatable)
            {
                GameManager.SendCommandToMap(Spacemap.Id, destroyCommand);
            }
            else if (this is Character)
            {
                SendCommandToInRangePlayers(destroyCommand);
            }

            if (this is Player player)
            {
                if (EventManager.JackpotBattle.InEvent(player))
                {
                    GameManager.SendPacketToMap(EventManager.JackpotBattle.Spacemap.Id, $"0|A|STM|msg_jackpot_players_left|%COUNT%|{(EventManager.JackpotBattle.Spacemap.Characters.Count - 1)}");
                }

                if (destroyer is Player && (destroyer as Player).Storage.KilledPlayerIds.Where(x => x == player.Id).Count() <= 13)
                {
                    (destroyer as Player).Storage.KilledPlayerIds.Add(player.Id);
                }

                player.Group?.UpdateTarget(player, new List <command_i3O> {
                    new GroupPlayerDisconnectedModule(true)
                });
                player.SkillManager.DisableAllSkills();
                player.SendCommand(destroyCommand);
                player.DisableAttack(player.Settings.InGameSettings.selectedLaser);
                player.CurrentInRangePortalId = -1;
                player.Storage.InRangeAssets.Clear();
                player.KillScreen(destroyer, destructionType);
            }
            else if (this is BattleStation battleStation)
            {
                if (destroyer.Clan.Id != 0)
                {
                    GameManager.SendPacketToAll($"0|A|STM|msg_station_destroyed_by_clan|%DESTROYER%|{destroyer.Clan.Name}|%MAP%|{Spacemap.Name}|%LOSER%|{battleStation.Clan.Name}|%STATION%|{battleStation.AsteroidName}");
                }
                else
                {
                    GameManager.SendPacketToAll($"0|A|STM|msg_station_destroyed|%MAP%|{Spacemap.Name}|%LOSER%|{battleStation.Clan.Name}|%STATION%|{battleStation.AsteroidName}");
                }

                battleStation.EquippedStationModule.Remove(battleStation.Clan.Id);
                battleStation.Clan                = GameManager.GetClan(0);
                battleStation.Name                = battleStation.AsteroidName;
                battleStation.InBuildingState     = false;
                battleStation.FactionId           = 0;
                battleStation.BuildTimeInMinutes  = 0;
                battleStation.AssetTypeId         = AssetTypeModule.ASTEROID;
                battleStation.CurrentHitPoints    = battleStation.MaxHitPoints;
                battleStation.CurrentShieldPoints = battleStation.MaxShieldPoints;

                Program.TickManager.RemoveTick(battleStation);

                //TODO check
                GameManager.SendCommandToMap(Spacemap.Id, AssetRemoveCommand.write(battleStation.GetAssetType(), battleStation.Id));
                GameManager.SendCommandToMap(Spacemap.Id, battleStation.GetAssetCreateCommand(0));

                QueryManager.BattleStations.BattleStation(battleStation);
                QueryManager.BattleStations.Modules(battleStation);
            }
            else if (this is Satellite satellite)
            {
                if (!satellite.BattleStation.Destroyed && satellite.Type != StationModuleModule.HULL && satellite.Type != StationModuleModule.DEFLECTOR)
                {
                    GameManager.SendPacketToClan($"0|A|STM|msg_station_module_destroyed|%STATION%|{satellite.BattleStation.AsteroidName}|%MAP%|{Spacemap.Name}|%MODULE%|{satellite.Name}|%LEVEL%|16", satellite.Clan.Id);
                }

                satellite.Remove(true);
                satellite.Type                = StationModuleModule.NONE;
                satellite.CurrentHitPoints    = 0;
                satellite.CurrentShieldPoints = 0;
                satellite.DesignId            = 0;

                if (satellite.BattleStation.Destroyed)
                {
                    Spacemap.Activatables.TryRemove(satellite.Id, out var activatable);
                    GameManager.SendCommandToMap(Spacemap.Id, AssetRemoveCommand.write(satellite.GetAssetType(), satellite.Id));
                }
                else if (satellite.BattleStation.AssetTypeId == AssetTypeModule.BATTLESTATION)
                {
                    GameManager.SendCommandToMap(Spacemap.Id, satellite.GetAssetCreateCommand(0));
                }

                QueryManager.BattleStations.Modules(satellite.BattleStation);
            }

            if (destroyer is Player destroyerPlayer)
            {
                int experience = 0;
                int honor      = 0;
                int uridium    = 0;
                int credits    = 0;

                bool reward     = true;
                var  changeType = ChangeType.INCREASE;

                if (this is Pet && (this as Pet).Owner == destroyerPlayer)
                {
                    changeType = ChangeType.DECREASE;
                }

                if (this is Character)
                {
                    experience = destroyerPlayer.Ship.GetExperienceBoost((this as Character).Ship.Rewards.Experience);
                    honor      = destroyerPlayer.GetHonorBoost(destroyerPlayer.Ship.GetHonorBoost((this as Character).Ship.Rewards.Honor));
                    uridium    = (this as Character).Ship.Rewards.Uridium;
                    credits    = (this as Character).Ship.Rewards.Credits;

                    var count = destroyerPlayer.Storage.KilledPlayerIds.Where(x => x == Id).Count();
                    if (this is Player && count >= 14 && !Duel.InDuel(destroyerPlayer))
                    {
                        reward = false;
                        destroyerPlayer.SendPacket($"0|A|STM|pusher_info_no_reward|%NAME%|{Name}");
                    }

                    if (this is Player && Duel.InDuel(this as Player))
                    {
                        reward = false;
                    }
                }
                else if (this is Activatable)
                {
                    credits    = 512000;
                    experience = 512000;
                    honor      = 512;
                    uridium    = 512;
                }

                experience += Maths.GetPercentage(experience, destroyerPlayer.BoosterManager.GetPercentage(BoostedAttributeType.EP));
                honor      += Maths.GetPercentage(honor, destroyerPlayer.BoosterManager.GetPercentage(BoostedAttributeType.HONOUR));
                honor      += Maths.GetPercentage(honor, destroyerPlayer.GetSkillPercentage("Cruelty"));

                if (reward)
                {
                    var groupMembers = destroyerPlayer.Group?.Members.Values.Where(x => x.AttackingOrUnderAttack());

                    if (destroyerPlayer.Group == null || (destroyerPlayer.Group != null && groupMembers.Count() == 0))
                    {
                        destroyerPlayer.ChangeData(DataType.CREDITS, credits);
                        destroyerPlayer.ChangeData(DataType.EXPERIENCE, experience);
                        destroyerPlayer.ChangeData(DataType.HONOR, honor, changeType);
                        destroyerPlayer.ChangeData(DataType.URIDIUM, uridium, changeType);
                    }
                    else if (this is Npc && destroyerPlayer.Group != null)
                    {
                        credits    = credits / groupMembers.Count();
                        experience = experience / groupMembers.Count();
                        honor      = honor / groupMembers.Count();
                        uridium    = uridium / groupMembers.Count();

                        foreach (var member in groupMembers)
                        {
                            member.ChangeData(DataType.CREDITS, credits);
                            member.ChangeData(DataType.EXPERIENCE, experience);
                            member.ChangeData(DataType.HONOR, honor, changeType);
                            member.ChangeData(DataType.URIDIUM, uridium, changeType);
                        }
                    }
                }

                if (this is Player)
                {
                    if (!Duel.InDuel(this as Player))
                    {
                        using (var mySqlClient = SqlDatabaseManager.GetClient())
                            mySqlClient.ExecuteNonQuery($"INSERT INTO log_player_kills (killer_id, target_id) VALUES ({destroyerPlayer.Id}, {Id})");
                    }

                    new CargoBox(Position, Spacemap, false, false, destroyerPlayer);
                }
            }
            else if (destructionType == DestructionType.RADIATION && this is Player && !Duel.InDuel(this as Player))
            {
                (this as Player).Destructions.dbrz++;
            }

            if (this is Character character)
            {
                if (this is Player && Duel.InDuel(this as Player))
                {
                    Duel.RemovePlayer(this as Player);
                }

                Spacemap.RemoveCharacter(character);

                CurrentHitPoints = 0;
            }

            if (this is Npc npc)
            {
                if (npc.Ship.Respawnable)
                {
                    npc.Respawn();
                }
            }

            if (destroyer is Character)
            {
                destroyer.Deselection();
            }

            Deselection();
            InRangeCharacters.Clear();
            VisualModifiers.Clear();

            if (this is Pet pet)
            {
                pet.Deactivate(true, true);
            }
        }
Exemplo n.º 3
0
        public override void Destroy(Character destroyer, DestructionType destructionType)
        {
            if (this is Spaceball)
            {
                return;
            }

            if (MainAttacker != null && MainAttacker is Player)
            {
                destroyer       = MainAttacker;
                destructionType = DestructionType.PLAYER;
            }

            if (destructionType == DestructionType.PLAYER)
            {
                var destroyerPlayer = destroyer as Player;

                destroyerPlayer.Selected = null;
                destroyerPlayer.DisableAttack(destroyerPlayer.SettingsManager.SelectedLaser);

                //if (!(this is Pet) || (this is Pet && (this as Pet).Owner != destroyerPlayer))
                int experience = destroyerPlayer.Ship.GetExperienceBoost(Ship.Rewards.Experience);
                int honor      = destroyerPlayer.GetHonorBoost(destroyerPlayer.Ship.GetHonorBoost(Ship.Rewards.Honor));
                int uridium    = Ship.Rewards.Uridium;
                var changeType = ChangeType.INCREASE;

                short relationType = destroyerPlayer.Clan != null && Clan != null?Clan.GetRelation(destroyerPlayer.Clan) : (short)0;

                if (destroyerPlayer.FactionId == FactionId && relationType != ClanRelationModule.AT_WAR && !(EventManager.JackpotBattle.Active && EventManager.JackpotBattle.Players.ContainsKey(Id)))
                {
                    changeType = ChangeType.DECREASE;
                }

                destroyerPlayer.ChangeData(DataType.EXPERIENCE, experience);
                destroyerPlayer.ChangeData(DataType.HONOR, honor, changeType);
                destroyerPlayer.ChangeData(DataType.URIDIUM, uridium, changeType);

                if (!(this is Pet))
                {
                    new CargoBox(AssetTypeModule.BOXTYPE_FROM_SHIP, Position, Spacemap, false, false, destroyerPlayer);
                }
            }

            Destroyed = true;
            var destroyCommand = ShipDestroyedCommand.write(Id, 0);

            SendCommandToInRangePlayers(destroyCommand);

            if (this is Player thisPlayer)
            {
                if (EventManager.JackpotBattle.Active && thisPlayer.Spacemap.Id == EventManager.JackpotBattle.Spacemap.Id && EventManager.JackpotBattle.Players.ContainsKey(thisPlayer.Id))
                {
                    EventManager.JackpotBattle.Players.TryRemove(thisPlayer.Id, out thisPlayer);
                    GameManager.SendPacketToMap(EventManager.JackpotBattle.Spacemap.Id, "0|LM|ST|SLE|" + EventManager.JackpotBattle.Players.Count);
                }

                thisPlayer.SkillManager.DisableAllSkills();
                thisPlayer.Pet.Deactivate(true);
                thisPlayer.CurrentHitPoints = 0;
                thisPlayer.SendCommand(destroyCommand);
                thisPlayer.DisableAttack(thisPlayer.SettingsManager.SelectedLaser);
                thisPlayer.CurrentInRangePortalId = -1;
                thisPlayer.Storage.InRangeAssets.Clear();
                thisPlayer.KillScreen(destroyer, destructionType);
            }

            Selected = null;
            InRangeCharacters.Clear();
            VisualModifiers.Clear();
            Spacemap.RemoveCharacter(this);

            if (this is Pet)
            {
                (this as Pet).Deactivate(true, true);
            }
        }