コード例 #1
0
        //private void MessageReceiver_FMD_L_JOIN_MISSION(ClientConnection client, AllegianceInterop.FMD_L_JOIN_MISSION message)
        //{
        //    bool connected = false;
        //    while (connected == false && _cancellationTokenSource.IsCancellationRequested == false)
        //    {
        //        Log($"Connecting to szServer: {message.szServer}, message.dwPort: {message.dwPort}, PlayerName: {PlayerName}, message.dwCookie: {message.dwCookie}");
        //        // Once the client connects to the server, the FM_S_LOGONACK response will trigger the disconnect from the lobby.
        //        if (client.ConnectToServer(message.szServer, (int)message.dwPort, PlayerName, BotAuthenticationGuid, (int)message.dwCookie) == true)
        //        {
        //            Log("\tConnected!");
        //            connected = true;
        //            break;
        //        }

        //        Log("\tCouldn't connect, retrying.");

        //        Thread.Sleep(100);
        //    }
        //}

        // Handles a client rejoining a game already in progress.
        private void MessageReceiver_FMD_S_SHIP_STATUS(ClientConnection client, AllegianceInterop.FMD_S_SHIP_STATUS message)
        {
            if (client.GetCore().GetMissionStage() == MissionStage.STAGE_STARTED)
            {
                FinishStrategy();
            }
        }
コード例 #2
0
        //private void _messageReceiver_FMD_S_EXPORT(ClientConnection client, AllegianceInterop.FMD_S_EXPORT message)
        //{
        //    var exportObjectType = (ObjectType)message.objecttype;

        //    Log($"Export ObjectType {exportObjectType.ToString()} received.");
        //}


        private void _messageReceiver_FMD_S_SHIP_STATUS(ClientConnection client, AllegianceInterop.FMD_S_SHIP_STATUS message)
        {
            // Check to ensure that we don't have any money hanging around in the bank.
            if (client.SideLeaderShipID(SideIndex) != client.GetShip()?.GetObjectID() && client.GetMoney() > 1000)
            {
                SetAutoDonateAndDonateAllMoneyToTeamLeader(client.GetSide()?.GetShip(client.SideLeaderShipID(SideIndex)));
            }

            // Update ship status for hull, station and cluster IDs.
            var ship = client.GetCore().GetShip(message.shipID);

            var shipName = ship.GetName();

            // Update ship, clintlib doesn't do this for us, it expects us to use the sector view to
            // get information about the game states.
            if (message.shipID != client.GetShip().GetObjectID())
            {
                //    if (message.status.GetHullID() > -1)
                //        ship.SetBaseHullType(client.GetCore().GetHullType(message.status.GetHullID()));


                //if (message.status.GetStationID() >= 0)
                //    ship.SetStation(client.GetCore().GetStation(message.status.GetStationID()));
                //else
                //    ship.SetStation(null);

                // For some reason, the sectorID from this message isn't set into the ship's cluster ID.
                // I think the real allegiance client must track drone states outside of clintlib? It appears that this message only sets Last Seen Sector, but not the current cluster.
                // As a work-around, always set each ship's current cluster to the message's sector ID.
                if (message.status.GetStationID() < 0 && ship.GetHullType() != null)
                {
                    ship.SetCluster(client.GetCore().GetCluster(message.status.GetSectorID()));
                }
                else
                {
                    ship.SetCluster(null);
                }
            }

            // Log the ship's current telemetry
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"position: X: {client.GetShip()?.GetPosition()?.X()}, Y: {client.GetShip()?.GetPosition()?.Y()}, Z: {client.GetShip()?.GetPosition()?.Z()}");
            sb.AppendLine($"speed: {client.GetShip()?.GetVelocity()?.Length()}");
            sb.AppendLine($"current command: {((CommandID ?)client.GetShip()?.GetCommandID((sbyte)CommandType.c_cmdCurrent))?.ToString()}, command target: {client.GetShip()?.GetCommandTarget((sbyte)CommandType.c_cmdCurrent)?.GetName()}");

            File.WriteAllText($@"c:\1\Logs\{client.GetShip().GetName()}_telemetry.txt", sb.ToString());
        }
コード例 #3
0
        private void MessageReceiver_FMD_S_SHIP_STATUS(ClientConnection client, AllegianceInterop.FMD_S_SHIP_STATUS message)
        {
            Log("MessageReceiver_FMD_S_SHIP_STATUS");

            var    ship     = _client.GetShip();
            string shipName = ship.GetName();

            UpdateUnexploredWarpsList();

            //if (_sweepLeft == true || _sweepRight == true)
            //    NavigateToNextSweepPoint();

            if (ship.GetCluster() == null || message.status.GetSectorID() == _currentSectorID || _isSweeping == true)
            {
                Log($"Skipping message: ship.GetCluster() = {ship.GetCluster().GetName()}, message.status.GetSectorID() = {message.status.GetSectorID()}, _currentSectorID = {_currentSectorID}, _isSweeping = {_isSweeping}");
                return;
            }

            if (_navigatingToCluster != null)
            {
                if (_navigatingToCluster.GetObjectID() != ship.GetCluster().GetObjectID())
                {
                    if (GameInfo.UnexploredClustersByObjectID.ContainsKey(_navigatingToCluster.GetObjectID()) == true)
                    {
                        Log($"Entered cluster: {ship.GetCluster().GetName()}, continuing on route to {_navigatingToCluster.GetName()}");
                        return;
                    }
                    else
                    {
                        Log($"Arrived at cluster: {ship.GetCluster().GetName()}, but destination cluster {_navigatingToCluster.GetName()} has already been swept. Cancelling navigation, checking for next step.");
                        _navigatingToCluster = null;
                    }
                }
                else
                {
                    Log($"Arrived at cluster: {ship.GetCluster().GetName()}, checking for next step.");
                    _navigatingToCluster = null;
                }
            }


            _currentSectorID = message.status.GetSectorID();
            //_sweepLeft = false;
            //_sweepRight = false;
            //_startingAngleInRadians = 0;
            //_currentAngleInRadians = 0;
            //_totalRadiansTraversed = 0;
            //_startingPoint = ship.GetPosition();
            //_currentSweepHop = 0;

            var otherFriendlyScoutShips = ship.GetCluster().GetShips().Where(p => p.GetObjectID() != ship.GetObjectID() && p.GetBaseHullType().GetName().Contains("Scout") == true && p.GetSide().GetObjectID() == ship.GetSide().GetObjectID());
            var otherSweepingScoutShips = otherFriendlyScoutShips.Where(p => p.GetCommandTarget((sbyte)CommandType.c_cmdCurrent)?.GetObjectType() == (short)ObjectType.OT_buoy);

            Log($"otherFriendlyScoutShips: {otherFriendlyScoutShips.Count()}, otherSweepingScoutShips: {otherSweepingScoutShips.Count()}, is unexplored: {GameInfo.UnexploredClustersByObjectID.ContainsKey(ship.GetCluster().GetObjectID())} ");

            // Ship has entered a cluster, find the next target and start scouting.

            // If cluster is unexplored, and less than 2 ships sweeping, start sweeping
            if (GameInfo.UnexploredClustersByObjectID.ContainsKey(ship.GetCluster().GetObjectID()) == true && otherSweepingScoutShips.Count() < 2)
            {
                SweepCluster();
            }

            // If there are two ships sweeping, fly to a point 1/3 of the angle we entered in at, and wait for alephs to appear.
            else if (otherSweepingScoutShips.Count() >= 2)
            {
                FlyToStationPointAndWaitForAelphs();
            }

            // If there are no ships sweeping, go to the next system.
            else
            {
                SelectNextAelphTarget();
            }



            //var mission = ship.GetMission();

            //var warps = mission.GetWarps();

            //// Get all the clusters that are available in the mission.
            //var missionClusters = mission.GetClusters();

            //var currentShipCluster = ship.GetCluster();
            //var currentMissionCluster = missionClusters.FirstOrDefault(p => p.GetObjectID() == currentShipCluster.GetObjectID());

            //var shipVisibleWarps = currentShipCluster.GetWarps();
            //var allWarpsInCluster = currentMissionCluster.GetWarps();
        }
コード例 #4
0
        private void MessageReceiver_FMD_S_SHIP_STATUS(ClientConnection client, AllegianceInterop.FMD_S_SHIP_STATUS message)
        {
            var ship    = ClientConnection.GetShip();
            var station = ship.GetStation();

            // Ignore messages that are not for us.
            if (message.shipID != ship.GetObjectID())
            {
                return;
            }

            // Ignore messages until we actually get into a sector
            if (ship.GetCluster() == null)
            {
                return;
            }

            Log($"MessageReceiver_FMD_S_SHIP_STATUS: my ship id = {ship.GetObjectID()},  message.shipID = {message.shipID}, message.status.GetSectorID(): {message.status.GetSectorID()}");


            string shipName = ship.GetName();

            //UpdateUnexploredWarpsList();

            // If we are in a station, then get into a scout and get out there.
            if (station != null)
            {
                if (_waitingForLaunchToComplete == false)
                {
                    Log("\tI'm sitting in base? Time to launch a scout!");
                    ChangeShip(ShipType.Scout, new ScoutProbeLoadout());
                    return;
                }
            }
            else
            {
                _waitingForLaunchToComplete = false;
            }

            if (IsCurrentShipAScout() == false)
            {
                Log("\tI'm not in a scout... returning to base.");
                ReturnToBase();
                return;
            }

            // If we don't have any command and the ship is stopped, reset and get moving!
            if ((CommandID)ship.GetCommandID((sbyte)CommandType.c_cmdCurrent) <= CommandID.c_cidNone && ship.GetVelocity().Length() == 0)
            {
                Log($"\tWe're stopped with no command. Resetting current variables, and selecting a new destination. _currentSectorID: {_currentSectorID}, _isSweeping: {_isSweeping}, _navigatingToCluster: {_navigatingToCluster}, _waitingForLaunchToComplete: {_waitingForLaunchToComplete}");

                _currentSectorID            = -1;
                _isSweeping                 = false;
                _navigatingToCluster        = null;
                _waitingForLaunchToComplete = false;

                //return;
            }

            // If we are already moving, and this status message is for our current sector, or we are already sweeping, then ignore it.
            if (ship.GetVelocity().Length() > 0 && (message.status.GetSectorID() == _currentSectorID || _isSweeping == true))
            {
                Log($"\tSkipping message: ship.GetVelocity(): {ship.GetVelocity().Length()},  ship.GetCluster() = {ship.GetCluster()?.GetName()}, message.status.GetSectorID() = {message.status.GetSectorID()}, _currentSectorID = {_currentSectorID}, _isSweeping = {_isSweeping}");
                return;
            }

            // These clusters still need to be explored.
            var currentUnexploredClusters = GameInfo.GetUnexploredClusters(client.GetCore());

            // Are we on the way to another cluster to explore?
            if (_navigatingToCluster != null)
            {
                // If we are not at the destination yet...
                if (_navigatingToCluster.GetObjectID() != ship.GetCluster().GetObjectID())
                {
                    // And our destination cluster still hasn't been explored...
                    if (currentUnexploredClusters.ContainsKey(_navigatingToCluster.GetObjectID()) == true)
                    {
                        Log($"\tEntered cluster: {ship.GetCluster().GetName()}, continuing on route to {_navigatingToCluster.GetName()}");
                        return;
                    }
                    else // The detination was explored by someone else, let's find a new destination.
                    {
                        Log($"\tArrived at cluster: {ship.GetCluster().GetName()}, but destination cluster {_navigatingToCluster.GetName()} has already been swept. Cancelling navigation, checking for next step.");
                        _navigatingToCluster = null;
                    }
                }
                else // We've arrived, let's see what we need to do next.
                {
                    Log($"\tArrived at cluster: {ship.GetCluster().GetName()}, checking for next step.");
                    _navigatingToCluster = null;
                }
            }


            _currentSectorID = message.status.GetSectorID();

            var otherFriendlyScoutShips = ship.GetCluster().GetShips().Where(p => p.GetObjectID() != ship.GetObjectID() && p.GetBaseHullType().GetName().Contains("Scout") == true && p.GetSide().GetObjectID() == ship.GetSide().GetObjectID());
            //var otherSweepingScoutShips = otherFriendlyScoutShips.Where(p => p.GetCommandTarget((sbyte)CommandType.c_cmdCurrent)?.GetObjectType() == (short)ObjectType.OT_buoy);
            var sweepingScoutCount = GameInfo.GetSweepingScoutCount(ship.GetCluster());

            Log($"\totherFriendlyScoutShips: {otherFriendlyScoutShips.Count()}, otherSweepingScoutShips: {sweepingScoutCount}, is unexplored: {currentUnexploredClusters.ContainsKey(ship.GetCluster().GetObjectID())} ");

            // Ship has entered a cluster, find the next target and start scouting.

            // If cluster is unexplored, and less than 2 ships sweeping, start sweeping
            if (currentUnexploredClusters.ContainsKey(ship.GetCluster().GetObjectID()) == true && sweepingScoutCount < 2)
            {
                SweepCluster();
            }

            // If there are two ships sweeping, fly to a point 1/3 of the angle we entered in at, and wait for alephs to appear.
            else if (sweepingScoutCount >= 2)
            {
                FlyToStationPointAndWaitForAelphs();
            }

            // If there are no ships sweeping, go to the next system.
            else
            {
                SelectNextAelphTarget();
            }



            //var mission = ship.GetMission();

            //var warps = mission.GetWarps();

            //// Get all the clusters that are available in the mission.
            //var missionClusters = mission.GetClusters();

            //var currentShipCluster = ship.GetCluster();
            //var currentMissionCluster = missionClusters.FirstOrDefault(p => p.GetObjectID() == currentShipCluster.GetObjectID());

            //var shipVisibleWarps = currentShipCluster.GetWarps();
            //var allWarpsInCluster = currentMissionCluster.GetWarps();
        }
コード例 #5
0
        //private void QueueMinerIfRequired()
        //{
        //    if (ClientConnection.GetSide().GetShips().Where(p => p.GetName().Contains("Miner")).Count() < ClientConnection.GetCore().GetMissionParams().GetMaxDrones())
        //    {
        //        QueueTech(".Miner");
        //    }
        //}

        private void MessageReceiver_FMD_S_SHIP_STATUS(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_S_SHIP_STATUS message)
        {
            //            Log($@"FMD_S_SHIP_STATUS:
            //\tshipID:{message.shipID}
            //\thullID:{message.status.GetHullID()}
            //\thullName:{client.GetCore().GetHullType(message.status.GetHullID()).GetName()}
            //\tshipName:{client.GetCore().GetShip(message.shipID).GetName()}
            //\tship.Autopilot: {client.GetCore().GetShip(message.shipID).GetAutopilot()}");

            // Ignore ships that are already on thier way to a destination.
            if (_constuctorsInFlightToClusterObjectIDByShipObjectID.ContainsKey(message.shipID) == true)
            {
                return;
            }


            var ship = client.GetCore().GetShip(message.shipID);


            if ((PilotType)ship.GetPilotType() == PilotType.c_ptBuilder && message.status.GetSectorID() >= 0 && ship.GetSide().GetObjectID() == client.GetSide().GetObjectID())
            {
                PlaceStation(ship, message.status.GetSectorID());
            }
        }