Exemplo n.º 1
0
        public void Build()
        {
            AssetTypeId = AssetTypeModule.BATTLESTATION;

            RemoveVisualModifier(VisualModifierCommand.BATTLESTATION_CONSTRUCTING);
            //Visuals.Add(new VisualModifierCommand(Id, VisualModifierCommand.BATTLESTATION_DOWNTIME_TIMER, 1800, "", 0, true));
            PrepareSatellites();

            GameManager.SendCommandToMap(Spacemap.Id, AssetRemoveCommand.write(GetAssetType(), Id));

            foreach (var character in Spacemap.Characters.Values)
            {
                if (character is Player player)
                {
                    short relationType = character.Clan.Id != 0 && Clan.Id != 0 ? Clan.GetRelation(character.Clan) : (short)0;
                    player.SendCommand(GetAssetCreateCommand(relationType));
                }
            }

            BuildTimeInMinutes = 0;
            InBuildingState    = false;
        }
        public void execute(GameSession gameSession, byte[] bytes)
        {
            var read = new EquipModuleRequest();

            read.readCommand(bytes);

            var player        = gameSession.Player;
            var battleStation = player.Spacemap.GetActivatableMapEntity(read.battleStationId) as BattleStation;

            if (battleStation != null)
            {
                if (player.Position.DistanceTo(battleStation.Position) > 700)
                {
                    player.SendCommand(BattleStationErrorCommand.write(BattleStationErrorCommand.OUT_OF_RANGE));
                    return;
                }

                if (!battleStation.EquippedStationModule.ContainsKey(player.Clan.Id))
                {
                    battleStation.EquippedStationModule[player.Clan.Id] = new List <Satellite>();
                }
                else
                {
                    if (battleStation.EquippedStationModule[player.Clan.Id].Count >= 10)
                    {
                        return;
                    }
                }

                if (battleStation.EquippedStationModule[player.Clan.Id].Where(x => !x.Installed && x.OwnerId == player.Id).ToList().Count > 0)
                {
                    player.SendCommand(BattleStationErrorCommand.write(BattleStationErrorCommand.EQUIP_OF_SAME_PLAYER_RUNNING));
                    return;
                }

                var module = player.Storage.BattleStationModules.Where(x => x.Id == read.itemId).FirstOrDefault();

                if (module != null)
                {
                    if (module.Type == StationModuleModule.DEFLECTOR && read.slotId != 1 || module.Type != StationModuleModule.DEFLECTOR && read.slotId == 1)
                    {
                        return;
                    }
                    if (module.Type == StationModuleModule.HULL && read.slotId != 0 || module.Type != StationModuleModule.HULL && read.slotId == 0)
                    {
                        return;
                    }
                    if ((module.Type == StationModuleModule.DEFLECTOR || module.Type == StationModuleModule.HULL || module.Type == StationModuleModule.REPAIR || module.Type == StationModuleModule.DAMAGE_BOOSTER || module.Type == StationModuleModule.EXPERIENCE_BOOSTER || module.Type == StationModuleModule.HONOR_BOOSTER) && battleStation.EquippedStationModule[player.Clan.Id].Where(x => x.Type == module.Type).Count() >= 1)
                    {
                        return;
                    }

                    var equippedModule = battleStation.EquippedStationModule[player.Clan.Id].Where(x => x.SlotId == read.slotId).FirstOrDefault();

                    if (read.replace || equippedModule != null)
                    {
                        if (read.replace && equippedModule.OwnerId != player.Id)
                        {
                            player.SendCommand(BattleStationErrorCommand.write(BattleStationErrorCommand.ITEM_NOT_OWNED));
                            return;
                        }
                        else if (!read.replace && !equippedModule.Installed && equippedModule.OwnerId != player.Id)
                        {
                            player.SendCommand(BattleStationErrorCommand.write(BattleStationErrorCommand.CONCURRENT_EQUIP));
                            return;
                        }

                        equippedModule.Remove(false, false);

                        if (battleStation.AssetTypeId == AssetTypeModule.BATTLESTATION)
                        {
                            equippedModule.Spacemap.Activatables.TryRemove(equippedModule.Id, out var activatable);
                            GameManager.SendCommandToMap(equippedModule.Spacemap.Id, AssetRemoveCommand.write(equippedModule.GetAssetType(), equippedModule.Id));
                        }
                    }

                    int designId = module.Type == StationModuleModule.REPAIR ? 3 : module.Type == StationModuleModule.LASER_HIGH_RANGE ? 4 : module.Type == StationModuleModule.LASER_MID_RANGE ? 5 : module.Type == StationModuleModule.LASER_LOW_RANGE ? 6 : module.Type == StationModuleModule.ROCKET_LOW_ACCURACY ? 8 : module.Type == StationModuleModule.ROCKET_MID_ACCURACY ? 7 : module.Type == StationModuleModule.HONOR_BOOSTER ? 9 : module.Type == StationModuleModule.DAMAGE_BOOSTER ? 10 : module.Type == StationModuleModule.EXPERIENCE_BOOSTER ? 11 : 0;

                    var satellite = new Satellite(battleStation, player.Id, Satellite.GetName(module.Type), designId, module.Id, read.slotId, module.Type, Satellite.GetPosition(battleStation.Position, read.slotId));
                    satellite.InstallationSecondsLeft = battleStation.AssetTypeId == AssetTypeModule.BATTLESTATION ? 0 : 0;

                    module.InUse = true;

                    battleStation.EquippedStationModule[player.Clan.Id].Add(satellite);

                    if (battleStation.AssetTypeId == AssetTypeModule.BATTLESTATION)
                    {
                        satellite.AddVisualModifier(VisualModifierCommand.BATTLESTATION_INSTALLING, 0, "", 0, true);
                        satellite.Spacemap.Activatables.TryAdd(satellite.Id, satellite);

                        foreach (var character in satellite.Spacemap.Characters.Values)
                        {
                            if (character is Player)
                            {
                                short relationType = character.Clan.Id != 0 && satellite.Clan.Id != 0 ? satellite.Clan.GetRelation(character.Clan) : (short)0;
                                (character as Player).SendCommand(satellite.GetAssetCreateCommand(relationType));
                            }
                        }
                    }

                    battleStation.Click(gameSession);

                    QueryManager.SavePlayer.Modules(player);
                    QueryManager.BattleStations.Modules(battleStation);

                    //send command to other players
                }
            }
        }
Exemplo n.º 3
0
 public void Remove()
 {
     Spacemap.Objects.TryRemove(Id, out var asset);
     GameManager.SendCommandToMap(Spacemap.Id, AssetRemoveCommand.write(new AssetTypeModule(AssetTypeId), Id));
 }
Exemplo n.º 4
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.º 5
0
        public void CharacterTicker()
        {
            foreach (var character in Characters.Values)
            {
                foreach (var otherCharacter in Characters.Values.Where(x => x.Id != character.Id && !x.Equals(character)))
                {
                    if (character.InRange(otherCharacter, otherCharacter.RenderRange))
                    {
                        character.AddInRangeCharacter(otherCharacter);
                    }
                    else if (character.SelectedCharacter == null || (character.SelectedCharacter != null && !character.SelectedCharacter.Equals(otherCharacter)))
                    {
                        character.RemoveInRangeCharacter(otherCharacter);
                    }
                }

                if (character is Player player)
                {
                    foreach (var obj in Objects.Values)
                    {
                        if (obj is Collectable collectable)
                        {
                            if (!(collectable.ToPlayer == null || (collectable.ToPlayer != null && player == collectable.ToPlayer)))
                            {
                                continue;
                            }
                        }
                        else if (obj is Mine mine)
                        {
                            if (!(player == mine.Player || !Duel.InDuel(player) || (Duel.InDuel(player) && player.Storage.Duel?.GetOpponent(player) == mine.Player)))
                            {
                                continue;
                            }
                        }

                        if (player.Position.DistanceTo(obj.Position) <= 1250)
                        {
                            if (!player.Storage.InRangeObjects.ContainsKey(obj.Id))
                            {
                                player.Storage.InRangeObjects.TryAdd(obj.Id, obj);

                                if (obj is Collectable)
                                {
                                    player.SendCommand((obj as Collectable).GetCollectableCreateCommand());
                                }
                                else if (obj is Mine)
                                {
                                    player.SendCommand((obj as Mine).GetMineCreateCommand());
                                }
                                else if (obj is Asset)
                                {
                                    player.SendCommand((obj as Asset).GetAssetCreateCommand());
                                }
                            }
                            else
                            {
                                if (obj is Mine)
                                {
                                    var mine = obj as Mine;
                                    if (mine.Active && mine.activationTime.AddMilliseconds(Mine.ACTIVATION_TIME) < DateTime.Now)
                                    {
                                        if (player.Position.DistanceTo(mine.Position) < Mine.RANGE)
                                        {
                                            mine.Remove();
                                            mine.Explode();
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (player.Storage.InRangeObjects.ContainsKey(obj.Id))
                            {
                                player.Storage.InRangeObjects.TryRemove(obj.Id, out var outObj);

                                if (obj is Collectable)
                                {
                                    player.SendCommand(DisposeBoxCommand.write((obj as Collectable).Hash, true));
                                }
                                else if (obj is Mine)
                                {
                                    player.SendPacket($"0|{ServerCommands.REMOVE_ORE}|{(obj as Mine).Hash}");
                                }
                                else if (obj is Asset)
                                {
                                    player.SendCommand(AssetRemoveCommand.write(new AssetTypeModule((obj as Asset).AssetTypeId), obj.Id));
                                }
                            }
                        }
                    }

                    if (CheckRadiation(player) || CheckActivatables(player))
                    {
                        player.SendCommand(player.GetBeaconCommand());
                    }
                }
            }
        }