private void CheckForLaunch(AllegianceInterop.ClientConnection client, int iSide, bool isReady) { if (iSide >= 0) { _readyStatus[iSide] = isReady; } int readyTeamCount = 0; Log("Ready Status: "); for (int i = 0; i < MaxTeams; i++) { Console.Write(_readyStatus[i] + " "); if (_readyStatus[i] == true) { readyTeamCount++; } } Console.WriteLine(""); if (readyTeamCount == MaxTeams) { Log("All sides are ready, launching the game."); AllegianceInterop.FMD_C_START_GAME startGame = new AllegianceInterop.FMD_C_START_GAME(); client.SendMessageServer(startGame); } }
public void Attach(AllegianceInterop.ClientConnection client, GameInfo gameInfo, string botAuthenticationGuid, string playerName, short sideIndex, bool isGameController, bool isCommander) { ClientConnection = client; PlayerName = playerName; SideIndex = sideIndex; IsGameController = isGameController; IsCommander = isCommander; BotAuthenticationGuid = botAuthenticationGuid; GameInfo = gameInfo; _messageReceiver = new MessageReceiver(playerName); client.OnAppMessage += _messageReceiver.OnAppMessage; _messageReceiver.FMD_S_JOIN_SIDE += _messageReceiver_FMD_S_JOIN_SIDE; _messageReceiver.FMD_S_SHIP_STATUS += _messageReceiver_FMD_S_SHIP_STATUS; //_messageReceiver.FMD_S_EXPORT += _messageReceiver_FMD_S_EXPORT; _messageReceiver.FMD_S_CLUSTERINFO += _messageReceiver_FMD_S_CLUSTERINFO; _messageReceiver.FMD_CS_PING += _messageReceiver_FMD_CS_PING; // We'll get one of these every 5 seconds, using this to drive "less frequent" updates. _messageReceiver.FMD_S_DOCKED += _messageReceiver_FMD_S_DOCKED; _messageReceiver.FMD_S_MISSION_STAGE += _messageReceiver_FMD_S_MISSION_STAGE; _messageReceiver.FMD_S_BALLOT += _messageReceiver_FMD_S_BALLOT; _messageReceiver.FMD_S_GAME_OVER += _messageReceiver_FMD_S_GAME_OVER; AttachMessages(_messageReceiver, botAuthenticationGuid, playerName, sideIndex, isGameController, isCommander); Log($"Starting strategy: {StrategyID.ToString()}"); Start(); }
private void MessageReceiver_FMD_CS_FORCE_TEAM_READY(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_CS_FORCE_TEAM_READY message) { Log($"FMD_CS_FORCE_TEAM_READY - side: {message.iSide}, ready: {message.fForceReady}"); _readyStatus[message.iSide] = message.fForceReady; if (IsGameController == true) { CheckForLaunch(client, message.iSide, message.fForceReady); } }
// Set the game parameters back to their proper defaults (map to hihigher, etc.) private void ResetGameParameters(AllegianceInterop.ClientConnection client) { AllegianceInterop.FMD_CS_MISSIONPARAMS missionParameters = new AllegianceInterop.FMD_CS_MISSIONPARAMS( GameName, AllegianceInterop.MapType.c_mmHiHigher, MaxPlayersPerGame, MaxPlayersPerGame / 2 ); client.SendMessageServer(missionParameters); }
private void MessageReceiver_FMD_S_TEAM_READY(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_S_TEAM_READY message) { // Only the game controller can launch the game. if (IsGameController == false) { return; } Log($"FMD_S_TEAM_READY - Received ready status: {message.fReady} for side: {message.iSide}"); CheckForLaunch(client, message.iSide, message.fReady); }
private void MessageReceiver_FMD_S_TEAM_READY(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_S_TEAM_READY message) { // Only the game controller can launch the game. if (IsGameController == false) { // If we are not the game controller, then re-send the ready message in case the other side joined after we readied up the first time. AllegianceInterop.FMD_CS_FORCE_TEAM_READY forceReady = new AllegianceInterop.FMD_CS_FORCE_TEAM_READY(SideIndex, true); client.SendMessageServer(forceReady); return; } Log($"FMD_S_TEAM_READY - Received ready status: {message.fReady} for side: {message.iSide}"); CheckForLaunch(client, message.iSide, message.fReady); }
// Set the game parameters back to their proper defaults (map to hihigher, etc.) private void ResetGameParameters(AllegianceInterop.ClientConnection client) { AllegianceInterop.FMD_CS_MISSIONPARAMS missionParameters = new AllegianceInterop.FMD_CS_MISSIONPARAMS( GameName, AllegianceInterop.MapType.c_mmHiHigher, MaxPlayersPerGame, MaxPlayersPerGame / 2 ); client.SendMessageServer(missionParameters); Log($"ResetGameParameters: SideIndex = {SideIndex}"); AllegianceInterop.FMD_CS_FORCE_TEAM_READY forceReady = new AllegianceInterop.FMD_CS_FORCE_TEAM_READY(SideIndex, true); client.SendMessageServer(forceReady); }
private void MessageReceiver_FMD_L_SERVERS_LIST(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_L_SERVERS_LIST message) { Log("FM_L_SERVERS_LIST_OnEvent:"); AllegianceInterop.ServerCoreInfo_Managed targetServer = null; foreach (var server in message.Servers) { Log("\t" + server.szName + ":" + server.szRemoteAddress); if (Configuration.ServerName.Equals(server.szName, StringComparison.InvariantCultureIgnoreCase) == true) { targetServer = server; } } //AllegianceInterop.StaticCoreInfo_Managed targetCore = null; foreach (var core in message.Cores) { Log("\t" + "Core: " + core.cbIGCFile); //if (targetCore.cbIGCFile == CoreName) // targetCore = core; } if (_isClientConnectedToServer == false) { if (IsGameController == true && _hasCreatedGame == false && targetServer != null && (targetServer.iCurGames == 0 || targetServer.iCurGames == _receivedMissionCount)) { _hasCreatedGame = true; // Create a game on the first server found. AllegianceInterop.FMD_C_CREATE_MISSION_REQ req = new AllegianceInterop.FMD_C_CREATE_MISSION_REQ(targetServer.szName, targetServer.szRemoteAddress, CoreName, GameName); client.SendMessageLobby(req); } else if (targetServer != null) { _waitingForMissionCount += targetServer.iCurGames; Log($"Waiting for mission details from Lobby for {targetServer.iCurGames} missions. IsGameController: {IsGameController}, _hasCreatedGame: {_hasCreatedGame}, targetServer: {targetServer}, _waitingForMissionCount: {_waitingForMissionCount}, _receivedMissionCount: {_receivedMissionCount}"); } else { Log("No servers currently attached to the lobby, waiting for a server to join."); } } }
private void MessageReceiver_FMD_S_BUCKET_STATUS(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_S_BUCKET_STATUS message) { //if (message.sideID != SideIndex) // return; //var side = client.GetSide(); //var completedBucket = side.GetBucket(message.iBucket); //var completedBucketName = completedBucket.GetName(); //QueueTechForAvailableMoney(); //if (completedBucketName.StartsWith(".") == true && completedBucketName.Contains("Miner") == true) //{ // QueueMinerIfRequired(); //} }
// When a bot comm is made team leader, then it should set it's team name and faction. private void MessageReceiver_FMD_CS_SET_TEAM_LEADER(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_CS_SET_TEAM_LEADER message) { if (message.shipID <= 0) { return; } AllegianceInterop.FMD_S_PLAYERINFO playerInfo; if (message.shipID == _shipID) { Log($"This player is now the team leader of side index: {message.sideID}, _hasSetTeamAndCiv: {_hasSetTeamAndCiv}"); if (_hasSetTeamAndCiv == false) { int noSquad = -1; string[] teamNames = { "Yellow Pigs", "Blue Pigs" }; AllegianceInterop.FMD_CS_SET_TEAM_INFO teamInfo = new AllegianceInterop.FMD_CS_SET_TEAM_INFO(noSquad, SideIndex, teamNames[SideIndex]); client.SendMessageServer(teamInfo); var enumValues = Enum.GetValues(typeof(Civilization)); _targetCivID = (short)enumValues.GetValue(_random.Next(0, enumValues.Length)); AllegianceInterop.FMD_CS_CHANGE_TEAM_CIV teamCiv = new AllegianceInterop.FMD_CS_CHANGE_TEAM_CIV(SideIndex, _targetCivID, false); client.SendMessageServer(teamCiv); AllegianceInterop.FMD_CS_FORCE_TEAM_READY forceReady = new AllegianceInterop.FMD_CS_FORCE_TEAM_READY(SideIndex, true); client.SendMessageServer(forceReady); _hasSetTeamAndCiv = true; //_isCurrentCommander = true; } } //else if (message.sideID == SideIndex) // Someone else was made the leader of our side. This is an outrage! //{ // _isCurrentCommander = false; //} }
private void MessageReceiver_FMD_LS_LOBBYMISSIONINFO(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_LS_LOBBYMISSIONINFO message) { Log($"Got mission info for game: {message.szGameName}, server address: {message.szServerAddr}, server port: {message.dwPort}, mission cookie: {message.dwCookie}"); //switch (_serverType) //{ // case ServerType.Lobby: if (_isClientConnectedToServer == false && message.szGameName == GameName) { _isClientConnectedToServer = true; // Once the client connects to the server, the FM_S_LOGONACK response will trigger the disconnect from the lobby. client.ConnectToServer(message.szServerAddr, (int)message.dwPort, PlayerName, BotAuthenticationGuid, (int)message.dwCookie); } _receivedMissionCount++; _waitingForMissionCount--; // No more mission details are coming, and we didn't find a bot game, so create a new one. if (_waitingForMissionCount == 0 && _isClientConnectedToServer == false) { _hasCreatedGame = true; AllegianceInterop.FMD_C_CREATE_MISSION_REQ req = new AllegianceInterop.FMD_C_CREATE_MISSION_REQ(message.szServerName, message.szServerAddr, CoreName, GameName); client.SendMessageLobby(req); } // break; // case ServerType.Server: // Log("Ready to join mission."); // break; // default: // throw new NotSupportedException(_serverType.ToString()); //} }
//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()); } }
private void MessageReceiver_FMD_S_SET_CLUSTER(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_S_SET_CLUSTER message) { }
private void MessageReceiver_FMD_S_PAYDAY(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_S_PAYDAY message) { QueueTechForAvailableMoney(); }
private void MessageReceiver_FMD_CS_CHATMESSAGE(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_CS_CHATMESSAGE message) { var ship = client.GetShip(); if (ship.GetCommandTarget((sbyte)CommandType.c_cmdCurrent) != null) { Log($"\tcommandCurrent: {ship.GetCommandID((sbyte)CommandType.c_cmdCurrent)}, commandTarget: {ship.GetCommandTarget((sbyte)CommandType.c_cmdCurrent).GetName()}"); Log($"\tcommandPlan: {ship.GetCommandID((sbyte)CommandType.c_cmdPlan)}, commandTarget: {ship.GetCommandTarget((sbyte)CommandType.c_cmdPlan).GetName()}"); Log($"\tship.GetAutopilot() = {ship.GetAutopilot()}"); } if (message.Message == "go") { var side = client.GetSide(); var mission = side.GetMission(); var hullTypes = mission.GetHullTypes(); var station = ship.GetStation(); if (station == null) { // Works! //{ // var buoy = client.CreateBuoy((sbyte)BuoyType.c_buoyWaypoint, _random.Next(-1000, 1000), _random.Next(-1000, 1000), _random.Next(-1000, 1000), ship.GetCluster().GetObjectID(), true); // var command = ship.GetDefaultOrder(buoy); // ship.SetCommand((sbyte)CommandType.c_cmdCurrent, buoy, command); // ship.SetAutopilot(true); //} // Works! { var warps = ship.GetCluster().GetWarps(); var warp = warps[_random.Next(0, warps.Count)]; //var warp = ship.GetCluster().GetWarps().First(); CommandID command = (CommandID)ship.GetDefaultOrder(warp); Log($"moving to point: {warp.GetName()}, command: {command.ToString()}"); // This should be it. ship.SetCommand((sbyte)CommandType.c_cmdCurrent, warp, (sbyte)CommandID.c_cidGoto); ship.SetAutopilot(true); } return; } List <AllegianceInterop.IhullTypeIGCWrapper> buyableHullTypes = new List <AllegianceInterop.IhullTypeIGCWrapper>(); foreach (var hullType in hullTypes) { if (hullType.GetGroupID() >= 0 && station.CanBuy(hullType) == true && station.IsObsolete(hullType) == false) { Log("buyable hullType: " + hullType.GetName()); buyableHullTypes.Add(hullType); } } // Get a scout. var scoutHull = buyableHullTypes.FirstOrDefault(p => p.GetName().Contains("Scout")); if (scoutHull == null) { return; } Log($"Found Scout: {scoutHull.GetName()}"); var partTypes = mission.GetPartTypes(); List <AllegianceInterop.IpartTypeIGCWrapper> buyablePartTypes = new List <AllegianceInterop.IpartTypeIGCWrapper>(); foreach (var partType in partTypes) { if (partType.GetGroupID() >= 0 && station.CanBuy(partType) == true && station.IsObsolete(partType) == false) { short equipmentTypeID = partType.GetEquipmentType(); bool isIncluded = false; switch ((EquipmentType)equipmentTypeID) { case EquipmentType.NA: isIncluded = true; break; case EquipmentType.ET_Weapon: case EquipmentType.ET_Turret: for (sbyte i = 0; i < scoutHull.GetMaxFixedWeapons(); i++) { isIncluded |= scoutHull.GetPartMask(equipmentTypeID, i) != 0 && scoutHull.CanMount(partType, i) == true; } break; default: isIncluded |= scoutHull.GetPartMask(equipmentTypeID, 0) != 0 && scoutHull.CanMount(partType, 0) == true; break; } if (isIncluded == true) { buyablePartTypes.Add(partType); Log($"\tFound part: {partType.GetName()}, capacity for part: {scoutHull.GetCapacity(partType.GetEquipmentType())}"); } } } var mines = buyablePartTypes.FirstOrDefault(p => p.GetName().Contains("Prox Mine") == true); //scoutHull. // Creating the empty ship adds the ship object to the core so that it will receive updates when the core.Update() is called. //var ship = client.CreateEmptyShip(); ship.SetBaseHullType(scoutHull); client.BuyDefaultLoadout(ship, station, scoutHull, client.GetMoney()); // Clear the cargo. for (sbyte i = -5; i < 0; i++) { var currentPart = ship.GetMountedPart((short)EquipmentType.NA, i); if (currentPart != null) { currentPart.Terminate(); } } if (mines != null) { for (sbyte i = -5; i < 0; i++) { int amount = client.BuyPartOnBudget(ship, mines, i, client.GetMoney()); Log("Bought: " + amount + " mines."); } var dispenser = ship.GetMountedPart((short)EquipmentType.ET_Dispenser, 0); dispenser.Terminate(); client.BuyPartOnBudget(ship, mines, 0, client.GetMoney()); } client.BuyLoadout(ship, true); // Clean up the newShip. //newShip.Terminate(); //ship = client.Get Task.Run(() => { // Wait for the ship to enter the cluster. while (ship.GetCluster() == null) { Thread.Sleep(100); } client.FireDispenser(ship); //var buoy = client.CreateBuoy((sbyte)BuoyType.c_buoyWaypoint, 3000, 0, 0, ship.GetCluster().GetObjectID(), true); //ship.SetAutopilot(true); //ship.SetCommand((sbyte)CommandType.c_cmdAccepted, buoy, (sbyte)CommandID.c_cidGoto); //ship.SetAutopilot(true); //// Drop mines! //var launcher = AllegianceInterop.IdispenserIGCWrapper.GetDispenserForPart(ship.GetMountedPart((short)EquipmentType.ET_Dispenser, 0)); ////var launcher = (AllegianceInterop.IdispenserIGCWrapper) ship.GetMountedPart((short) EquipmentType.ET_Dispenser, 0); //client.FireExpendable(ship, launcher, (uint)DateTime.Now.Ticks); }); } if (message.Message == "miner") { var side = client.GetSide(); var buckets = side.GetBuckets(); var money = client.GetMoney(); foreach (var bucket in buckets) { if (bucket.GetName() == ".Miner") { if (money > bucket.GetPrice() && bucket.GetCompleteF() == false) { Log("Adding money to bucket. Bucket wants: " + bucket.GetPrice() + ", we have: " + money); client.AddMoneyToBucket(bucket, bucket.GetPrice()); } else { Log("Already building: " + bucket.GetPercentComplete()); } } } } }
private void MessageReceiver_FMD_LS_LOBBYMISSIONINFO_Old(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_LS_LOBBYMISSIONINFO message) { Log($"Got mission info for game: {message.szGameName}, server address: {message.szServerAddr}, server port: {message.dwPort}, mission cookie: {message.dwCookie}"); //switch (_serverType) //{ // case ServerType.Lobby: if (_isClientConnectedToServer == false && message.szGameName == GameName) { _isClientConnectedToServer = true; Log("Connecting to game, waiting for FM_S_LOGONACK from server."); bool connected = false; while (connected == false && _cancellationTokenSource.IsCancellationRequested == false) { // Once the client connects to the server, the FM_S_LOGONACK response will trigger the disconnect from the lobby. if (client.ConnectToServer(message.szServerAddr, (int)message.dwPort, PlayerName, BotAuthenticationGuid, (int)message.dwCookie) == true) { connected = true; break; } Log("\tCouldn't connect, retrying."); Thread.Sleep(100); } //Task.Run(() => //{ // bool connected = false; // while(connected == false && _cancellationTokenSource.IsCancellationRequested == false) // { // // Once the client connects to the server, the FM_S_LOGONACK response will trigger the disconnect from the lobby. // if (ClientConnection.ConnectToServer(message.szServerAddr, (int)message.dwPort, PlayerName, BotAuthenticationGuid, (int)message.dwCookie) == true) // { // connected = true; // break; // } // Log("\tCouldn't connect, retrying."); // Thread.Sleep(100); // } //}); } _receivedMissionCount++; _waitingForMissionCount--; // No more mission details are coming, and we didn't find a bot game, so create a new one. if (_waitingForMissionCount == 0 && _isClientConnectedToServer == false) { _hasCreatedGame = true; AllegianceInterop.FMD_C_CREATE_MISSION_REQ req = new AllegianceInterop.FMD_C_CREATE_MISSION_REQ(message.szServerName, message.szServerAddr, CoreName, GameName); client.SendMessageLobby(req); } // break; // case ServerType.Server: // Log("Ready to join mission."); // break; // default: // throw new NotSupportedException(_serverType.ToString()); //} }
private void MessageReceiver_FMD_LS_LOBBYMISSIONINFO(AllegianceInterop.ClientConnection client, AllegianceInterop.FMD_LS_LOBBYMISSIONINFO message) { Log($"Got mission info for game: {message.szGameName}, server address: {message.szServerAddr}, server port: {message.dwPort}, mission cookie: {message.dwCookie}"); //switch (_serverType) //{ // case ServerType.Lobby: if (_isClientConnectedToServer == false && message.szGameName == GameName) { _isClientConnectedToServer = true; Log("Connecting to game, waiting for FM_S_LOGONACK from server."); AllegianceInterop.FMD_C_JOIN_GAME_REQ joinGame = new AllegianceInterop.FMD_C_JOIN_GAME_REQ(message.dwCookie); client.SendMessageLobby(joinGame); //bool connected = false; //while (connected == false && _cancellationTokenSource.IsCancellationRequested == false) //{ // // Once the client connects to the server, the FM_S_LOGONACK response will trigger the disconnect from the lobby. // if (client.ConnectToServer(message.szServerAddr, (int)message.dwPort, PlayerName, BotAuthenticationGuid, (int)message.dwCookie) == true) // { // connected = true; // break; // } // Log("\tCouldn't connect, retrying."); // Thread.Sleep(100); //} //Task.Run(() => //{ // bool connected = false; // while(connected == false && _cancellationTokenSource.IsCancellationRequested == false) // { // // Once the client connects to the server, the FM_S_LOGONACK response will trigger the disconnect from the lobby. // if (ClientConnection.ConnectToServer(message.szServerAddr, (int)message.dwPort, PlayerName, BotAuthenticationGuid, (int)message.dwCookie) == true) // { // connected = true; // break; // } // Log("\tCouldn't connect, retrying."); // Thread.Sleep(100); // } //}); } if (Configuration.ServerName.Equals(message.szServerName, StringComparison.InvariantCultureIgnoreCase) == true) { _receivedMissionCount++; _waitingForMissionCount--; // No more mission details are coming, and we didn't find a bot game, so create a new one. if (_waitingForMissionCount == 0 && _isClientConnectedToServer == false) { Log($"MessageReceiver_FMD_LS_LOBBYMISSIONINFO(): Creating game. message.szServerName: {message.szServerName}, message.szServerAddr: {message.szServerAddr}, CoreName: {CoreName}, GameName: {GameName}"); _hasCreatedGame = true; AllegianceInterop.FMD_C_CREATE_MISSION_REQ req = new AllegianceInterop.FMD_C_CREATE_MISSION_REQ(message.szServerName, message.szServerAddr, CoreName, GameName); client.SendMessageLobby(req); } } }