internal void UnlockTechGroupForAllPlayers(TechGroup techGroup) { if (UnlockedTechs.Contains(techGroup)) { return; // Already unlocked } HashSet <MyDefinitionId> technologies; if (!techsForGroup.TryGetValue(techGroup, out technologies)) { ModLog.Error("No technologies for group: " + techGroup); return; } var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players); foreach (var player in players) { foreach (var technology in technologies) { MyVisualScriptLogicProvider.PlayerResearchUnlock(player.IdentityId, technology); } } UnlockedTechs.Add(techGroup); audioSystem.PlayAudio(GetAudioClipForTechGroup(techGroup)); }
public void UnlockTechsSilently(long playerId, HashSet <TechGroup> techGroups) { foreach (var techGroup in techGroups) { var technologies = techsForGroup[techGroup]; if (technologies == null) { ModLog.Error("No technologies for group: " + techGroup); return; } foreach (var technology in technologies) { if (bNewResearch) { // unknown: does this work for ALL players? MyVisualScriptLogicProvider.ResearchListRemoveItem(technology); // SE 1.189 } else { MyVisualScriptLogicProvider.PlayerResearchUnlock(playerId, technology); } } } }
internal void InitHudMesages(bool bForce = false) { if (TextAPI == null) { ModLog.Error("Text HUD API not loaded"); return; } if (TextAPI.Heartbeat) { // ModLog.Info("Have Heartbeat"); if (hackInterruptedV2 == null || bForce) { // ModLog.Info("Creating Interrupted HUD"); sbInterruptedMessage = new StringBuilder(SeTextColor + "CONNECTION LOST"); hackInterruptedV2 = new HudAPIv2.HUDMessage(sbInterruptedMessage, new Vector2D(-0.5, 0.5)); if (hackInterruptedV2 != null) { hackInterruptedV2.Message = sbInterruptedMessage; hackInterruptedV2.Scale = 2; hackInterruptedV2.Options = HudAPIv2.Options.Shadowing; hackInterruptedV2.Options |= HudAPIv2.Options.HideHud; // hackInterruptedV2.TimeToLive = 45; hackInterruptedV2.Visible = false; } else { ModLog.Info("Could not create Interrupted HUD"); } } if (hackBarV2 == null || bForce) { // ModLog.Info("Creating Hacking HUD"); if (sbHackBarMessage == null) { sbHackBarMessage = new StringBuilder("Initial Research Bar"); } hackBarV2 = new HudAPIv2.HUDMessage(sbHackBarMessage, new Vector2D(-0.5, 0.5)); if (hackBarV2 != null) { hackBarV2.Message = sbHackBarMessage; hackBarV2.Scale = 2; hackBarV2.Options = HudAPIv2.Options.Shadowing; hackBarV2.Options |= HudAPIv2.Options.HideHud; hackBarV2.Visible = false; // hackBarV2.TimeToLive = 45; } else { ModLog.Info("Could not create Research HUD"); } } } else { ModLog.Info("NO TextHud HEARTBEAT"); } }
private void IncomingMessage(byte[] bytes) { try { var message = MyAPIGateway.Utilities.SerializeFromXML <Message>(Encoding.UTF8.GetString(bytes)); switch (message.MessageType) { case MessageType.ClientJoined: // Server only HandleClientJoinedMessage(message); break; case MessageType.ClearToolbar: StartWipeClientToolbar(); break; case MessageType.ToolbarClearedSuccessfully: RegisteredPlayers.Add(message.PlayerId); break; case MessageType.PlaySound: audio.PlayAudio(AudioClip.GetClipFromId(message.AudioClipId)); break; case MessageType.HackingProgress: hacking.ShowLocalHackingProgress(message.HackingProgressTicks); break; case MessageType.HackingSuccess: hacking.ShowLocalHackingSuccess(); break; case MessageType.HackingInterrupted: hacking.ShowLocalHackingInterrupted(); break; case MessageType.HackingInterruptStopped: hacking.ShowLocalHackingInterruptStopped(); break; default: throw new Exception("Unrecognised message type: " + message.MessageType); } } catch (Exception e) { ModLog.Error(e); } }
public void UnlockTechForJoiningPlayer(long playerId) { foreach (var techGroup in UnlockedTechs) { var technologies = techsForGroup[techGroup]; if (technologies == null) { ModLog.Error("No technologies for group: " + techGroup); return; } foreach (var technology in technologies) { MyVisualScriptLogicProvider.PlayerResearchUnlock(playerId, technology); } } }
public void UnlockTechsSilently(long playerId, HashSet <TechGroup> techGroups) { foreach (var techGroup in techGroups) { var technologies = techsForGroup[techGroup]; if (technologies == null) { ModLog.Error("No technologies for group: " + techGroup); return; } foreach (var technology in technologies) { MyVisualScriptLogicProvider.PlayerResearchUnlock(playerId, technology); } } }
internal void UnlockTechGroupForAllPlayers(TechGroup techGroup) { if (UnlockedTechs.Contains(techGroup)) { // ModLog.Info("UTGFAP():" + UnlockedTechs.Count.ToString() + " unlocked groups. Already contains TechGroup:"+techGroup.ToString()); return; // Already unlocked } HashSet <MyDefinitionId> technologies; if (!techsForGroup.TryGetValue(techGroup, out technologies)) { ModLog.Error("No technologies for group: " + techGroup); return; } var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players); foreach (var player in players) { foreach (var technology in technologies) { if (bNewResearch) { MyVisualScriptLogicProvider.ResearchListRemoveItem(technology); // SE 1.189 } else { // ModLog.Info("Old research Method: Unlock for player:" + player.IdentityId.ToString() + " tech=" + technology.ToString()); MyVisualScriptLogicProvider.PlayerResearchUnlock(player.IdentityId, technology); } } } UnlockedTechs.Add(techGroup); audioSystem.PlayAudio(GetAudioClipForTechGroup(techGroup)); }
public void KeepTechsLocked() { // ModLog.Info("KeepTechsLocked()"); foreach (var techGroup in techsForGroup) { var group = techGroup.Key; // ModLog.Info("KTL: Group=" + group.ToString()); if (UnlockedTechs.Contains(group)) { // ModLog.Info(" UNLOCKED"); // OK to unlock var technologies = techsForGroup[group]; foreach (var technology in technologies) { MyVisualScriptLogicProvider.ResearchListRemoveItem(technology); } } else { // ModLog.Info(" LOCKED"); // block should be locked var technologies = techsForGroup[group]; if (technologies == null) { ModLog.Error("No technologies for group: " + techGroup); continue; } // ModLog.Info(" # blocks=" + technologies.Count.ToString()); foreach (var technology in technologies) { MyVisualScriptLogicProvider.ResearchListAddItem(technology); } } } }
private void GiveOrdersToUnassignedShips() { bool bFoundBackup = false; while (unitialisedNewGrids.Count > 0) { var grid = unitialisedNewGrids.Dequeue(); if (!grid.IsControlledByFaction("GCORP")) { continue; } var roleAndUnitType = PrefabGrid.GetRoleAndUnitType(grid); if (roleAndUnitType == null) { // V26 debug ModLog.Info("Discarding grid because no role found"); continue; } var unitType = roleAndUnitType.Value.UnitType; switch (roleAndUnitType.Value.UnitRole) { case UnitRole.Delivery: var cargoType = CargoType.GenerateRandomCargo(random); LoadCargo(grid, cargoType); if (cargoType.subtypeName == "SteelPlate") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.SteelPlateConvoyDispatched, AudioClip.ConvoyDispatched1); } else if (cargoType.subtypeName == "MetalGrid") { audioSystem.PlayAudioRandomChance(1, AudioClip.MetalGridConvoyDispatched); } else if (cargoType.subtypeName == "Construction") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.ConstructionConvoyDispatched); } else if (cargoType.subtypeName == "InteriorPlate") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.InteriorPlateConvoyDispatched); } else if (cargoType.subtypeName == "Girder") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.GirderConvoyDispatched); } else if (cargoType.subtypeName == "SmallTube") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.SmallTubeConvoyDispatched); } else if (cargoType.subtypeName == "LargeTube") { audioSystem.PlayAudioRandomChance(0.2, AudioClip.LargeTubeConvoyDispatched); } else if (cargoType.subtypeName == "Motor") { audioSystem.PlayAudioRandomChance(0.75, AudioClip.MotorConvoyDispatched); } else if (cargoType.subtypeName == "Display") { audioSystem.PlayAudioRandomChance(0.2, AudioClip.DisplayConvoyDispatched); } else if (cargoType.subtypeName == "BulletproofGlass") { audioSystem.PlayAudioRandomChance(0.3, AudioClip.BulletproofGlassConvoyDispatched); } else if (cargoType.subtypeName == "Computer") { audioSystem.PlayAudioRandomChance(0.2, AudioClip.ComputerConvoyDispatched); } else if (cargoType.subtypeName == "Reactor") { audioSystem.PlayAudioRandomChance(0.75, AudioClip.ReactorConvoyDispatched); } else if (cargoType.subtypeName == "Medical") { audioSystem.PlayAudioRandomChance(0.7, AudioClip.MedicalConvoyDispatched); } else if (cargoType.subtypeName == "RadioCommunication") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.RadioCommunicationConvoyDispatched); } else if (cargoType.subtypeName == "Explosives") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.ExplosivesConvoyDispatched); } else if (cargoType.subtypeName == "SolarCell") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.SolarCellConvoyDispatched); } else if (cargoType.subtypeName == "PowerCell") { audioSystem.PlayAudioRandomChance(0.75, AudioClip.PowerCellConvoyDispatched); } else if (cargoType.subtypeName == "NATO_5p56x45mm") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.NATO_5p56x45mmConvoyDispatched); } else if (cargoType.subtypeName == "NATO_25x184mm") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.NATO25x184mmConvoyDispatched); } else if (cargoType.subtypeName == "Missile200mm") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.Missile200mmConvoyDispatched); } else if (cargoType.subtypeName == "Uranium") { audioSystem.PlayAudioRandomChance(1, AudioClip.UraniumConvoyDispatched); } else // we don't know what it is.. { audioSystem.PlayAudioRandomChance(0.1, AudioClip.ConvoyDispatched1, AudioClip.ConvoyDispatched2, AudioClip.ConvoyDispatched3); } string sPrefix = "T"; if (unitType == UnitType.Air) { sPrefix += "A"; } else { sPrefix += "G"; } grid.SetAllBeaconNames(sPrefix + random.Next(10000, 99999) + " - " + cargoType.GetDisplayName() + " Shipment", 200f); // V31 set short until initialize check timeout var destination = unitType == UnitType.Air ? airConvoyDestinationPosition : groundConvoyDestinationPosition; // ModLog.Info("Air Destination=" + airConvoyDestinationPosition.ToString()); // ModLog.Info("GND Destination=" + groundConvoyDestinationPosition.ToString()); // ModLog.Info("Chosen Dest=" + destination.ToString()); SetDestination(grid, destination); RegisterConvoy(grid, NpcGroupState.Travelling, unitType, destination, MyAPIGateway.Session.GameDateTime); var planet = DuckUtils.FindPlanetInGravity(grid.GetPosition()); if (planet != null) { convoySpawner.SpawnConvoyEscorts(grid, unitType, planet); } break; case UnitRole.Escort: var group = FindNearestJoinableNpcGroup(grid.GetPosition(), unitType); if (group == null) { ModLog.Error("Escort ship spawned but can't find a group to join!"); grid.CloseAll(); } else { grid.SetAllBeaconNames("E" + random.Next(10000, 99999) + " - " + EscortName, 2500f); // V31 shorten escort beacon range to decrease hud spam var nearestPlanet = DuckUtils.FindPlanetInGravity(grid.GetPosition()); if (nearestPlanet != null) { group.JoinAsEscort(grid, unitType, nearestPlanet); } } break; case UnitRole.Backup: var gCorpBase = baseManager.FindBaseWantingBackup(); // V26 bFoundBackup = true; if (gCorpBase == null) { gCorpBase = baseManager.FindBaseNear(grid.GetPosition()); } if (gCorpBase == null) { ModLog.Error("Backup ship spawned but can't find the base that asked for it!"); grid.CloseAll(); break; } var backupPosition = gCorpBase.GetBackupPosition(); grid.SendToPosition(backupPosition); // backup debug string sBeacon = "M" + random.Next(10000, 99999) + " Investigating Backup Call"; // ModLog.Info("Backup Found:" + sBeacon); // ModLog.Info(" Destination=" + backupPosition.ToString()); grid.SetAllBeaconNames(sBeacon, 20000f); var backupGroup = new BackupGroup(NpcGroupState.Travelling, backupPosition, grid, heatSystem, audioSystem, MyAPIGateway.Session.GameDateTime); //damageSensor.RegisterDamageObserver(grid.EntityId, backupGroup); npcGroups.Add(backupGroup); break; case UnitRole.Bomb: bool hasSensors = false; var slimBlocks = new List <IMySlimBlock>(); grid.GetBlocks(slimBlocks, b => b.FatBlock is IMySensorBlock); if (slimBlocks.Count > 0) { hasSensors = true; } grid.GetBlocks(slimBlocks, b => b.FatBlock is IMyWarhead); foreach (var slim in slimBlocks) { var wh = slim.FatBlock as IMyWarhead; wh.IsArmed = true; if (!hasSensors) // if no sensors, start the countdown { ModLog.Info("BOMB: no sensors: Starting timer"); wh.StartCountdown(); } } break; default: continue; } } if (bFoundBackup) { baseManager.ClearBaseBackupRequests(); } }
private void GiveOrdersToUnassignedShips() { while (unitialisedNewGrids.Count > 0) { var grid = unitialisedNewGrids.Dequeue(); if (!grid.IsControlledByNpcFaction()) { continue; } var roleAndUnitType = PrefabGrid.GetRoleAndUnitType(grid); if (roleAndUnitType == null) { continue; } var unitType = roleAndUnitType.Value.UnitType; switch (roleAndUnitType.Value.UnitRole) { case UnitRole.Delivery: var cargoType = CargoType.GenerateRandomCargo(random); LoadCargo(grid, cargoType); grid.SetAllBeaconNames("T" + random.Next(10000, 99999) + " - " + cargoType.GetDisplayName() + " Shipment", 20000f); var destination = unitType == UnitType.Air ? airConvoyDestinationPosition : groundConvoyDestinationPosition; SetDestination(grid, destination); RegisterConvoy(grid, NpcGroupState.Travelling, unitType, destination, MyAPIGateway.Session.GameDateTime); var planet = DuckUtils.FindPlanetInGravity(grid.GetPosition()); if (planet != null) { CalFactions.Gcorp.Ships.SpawnConvoyEscorts(grid, unitType, planet); } break; case UnitRole.Escort: var group = FindNearestJoinableNpcGroup(grid.GetPosition(), unitType); if (group == null) { ModLog.Error("Escort ship spawned but can't find a group to join!"); grid.CloseAll(); } else { grid.SetAllBeaconNames("E" + random.Next(10000, 99999) + " - Convoy Escort", 20000f); var nearestPlanet = DuckUtils.FindPlanetInGravity(grid.GetPosition()); if (nearestPlanet != null) { group.JoinAsEscort(grid, unitType, nearestPlanet); } } break; case UnitRole.Backup: var gCorpBase = baseManager.FindBaseWantingBackup(); if (gCorpBase == null) { ModLog.Error("Backup ship spawned but can't find the base that asked for it!"); grid.CloseAll(); break; } var backupPosition = gCorpBase.GetBackupPosition(); grid.SendToPosition(backupPosition); grid.SetAllBeaconNames("M" + random.Next(10000, 99999) + " Investigating Backup Call", 20000f); var backupGroup = new BackupGroup(NpcGroupState.Travelling, backupPosition, grid, heatSystem, audioSystem, MyAPIGateway.Session.GameDateTime); //damageSensor.RegisterDamageObserver(grid.EntityId, backupGroup); npcGroups.Add(backupGroup); break; default: continue; } } }