private List <MyGps> FindGrids(IGridDetectionStrategy gridDetectionStrategy, int min, int distance, bool ignoreOffline, bool ignoreNpcs, long seconds) { List <KeyValuePair <long, List <MyCubeGrid> > > grids = gridDetectionStrategy.FindGrids(Plugin.Config, Plugin.UseConnectedGrids); List <KeyValuePair <long, List <MyCubeGrid> > > filteredGrids = gridDetectionStrategy.GetFilteredGrids(grids, min, distance, Plugin.TopGrids, ignoreOffline, ignoreNpcs); List <MyGps> gpsList = new List <MyGps>(); int i = 0; Color gpsColor = Plugin.GpsColor; foreach (KeyValuePair <long, List <MyCubeGrid> > pair in filteredGrids) { i++; MyCubeGrid grid = pair.Value[0]; /* Cannot be empty because where do the PCUs come from? */ var position = grid.PositionComp.GetPosition(); if (Plugin.LogBroadcastedGrids) { LogGrid(grid); } MyGps gps = CreateGps(i, grid, gpsColor, seconds); gpsList.Add(gps); } return(gpsList); }
public MyGps GetDeliveryLocation() { MyGps gps = ScanChat(DeliveryGPS); gps.Description = "Deliver " + amountToMine + " " + contract.subTypeId + " ore"; return(gps); }
private void SendGps(HashSet <MyGps> gpsSet, GridsBroadcastConfig config) { MyGpsCollection gpsCollection = (MyGpsCollection)MyAPIGateway.Session?.GPS; if (gpsCollection == null) { return; } bool followGrids = config.GpsFollowGrids; bool playSound = config.PlayGpsSound; foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers()) { Log.Trace($"Sending biggest grid GPS to player '{player.DisplayName}'"); foreach (MyGps gps in gpsSet) { MyGps gpsRef = gps; long entityId = 0L; if (followGrids) { _gpsSendClient.AddOrModifyGps(player.Identity.IdentityId, ref gpsRef, playSound); continue; } gpsCollection.SendAddGps(player.Identity.IdentityId, ref gpsRef, entityId, playSound); } } }
internal void RegisterMarker(MyGps ins) { if (!m_Inss.Contains(ins)) { m_Inss.Add(ins); } }
public void LoadGpss(MyObjectBuilder_Checkpoint checkpoint) { if (MyFakes.ENABLE_GPS && checkpoint.Gps != null) { foreach (var entry in checkpoint.Gps.Dictionary)//identity { foreach (var gpsEntry in entry.Value.Entries) { MyGps gps = new MyGps(gpsEntry); Dictionary <int, MyGps> playersGpss; if (!m_playerGpss.TryGetValue(entry.Key, out playersGpss)) { playersGpss = new Dictionary <int, MyGps>(); m_playerGpss.Add(entry.Key, playersGpss); } if (!playersGpss.ContainsKey(gps.GetHashCode())) { playersGpss.Add(gps.GetHashCode(), gps); if (gps.ShowOnHud && entry.Key == MySession.Static.LocalPlayerId && MySession.Static.LocalPlayerId != 0)// LocalPlayerId=0 => loading MP game and not yet initialized. Or server, which does not matter { MyHud.GpsMarkers.RegisterMarker(gps); } } } } } }
/// <summary> /// Updates before simulation. Will add all persistent gpss to the players, /// that dont have them yet. /// </summary> public override void UpdateBeforeSimulation() { if (MySettingsSession.Static.IsEnabled()) { foreach (var entry in m_globalGpss.Keys) { foreach (var p in MySession.Static.Players.GetOnlinePlayers()) { if (m_globalGpss[entry].Players.Contains(p.Identity.IdentityId)) { continue; } MyGps gps = new MyGps { Name = m_globalGpss[entry].Name, Coords = m_globalGpss[entry].Position, GPSColor = m_globalGpss[entry].Color, ShowOnHud = !m_globalGpss[entry].Hidden, AlwaysVisible = false, DiscardAt = null }; gps.CalculateHash(); MySession.Static.Gpss.SendAddGps(p.Identity.IdentityId, ref gps, playSoundOnCreation: false); m_globalGpss[entry].Players.Add(p.Identity.IdentityId); } } } }
public override void UpdateBeforeSimulation() { if (SettingsSession.Static.Settings.Enable || true) { foreach (var g in ToAddGpss) { Gpss.Add(g); } ToAddGpss.Clear(); foreach (var gps in Gpss) { foreach (var p in MySession.Static.Players.GetOnlinePlayers()) { MyGps g = gps; List <MyGps> gpses = new List <MyGps>(); if (!(AddedGpss.TryGetValue(p.Identity.IdentityId, out HashSet <int> value) && value.Contains(gps.Hash))) { MySession.Static.Gpss.SendAddGps(p.Identity.IdentityId, ref g, playSoundOnCreation: false); if (!AddedGpss.ContainsKey(p.Identity.IdentityId)) { AddedGpss.Add(p.Identity.IdentityId, new HashSet <int>()); } AddedGpss[p.Identity.IdentityId].Add(gps.Hash); } } } } }
public bool AddPlayerGps(long identityId, ref MyGps gps) { if (gps == null) { return(false); } Dictionary <int, MyGps> result; var success = m_playerGpss.TryGetValue(identityId, out result); if (!success) { result = new Dictionary <int, MyGps>(); m_playerGpss.Add(identityId, result); } if (result.ContainsKey(gps.Hash)) { //Request to add existing. We update timestamp: MyGps mGps; result.TryGetValue(gps.Hash, out mGps); if (mGps.DiscardAt != null)//not final { mGps.SetDiscardAt(); } return(false); } result.Add(gps.Hash, gps); return(true); }
private void SendGps(HashSet <MyGps> gpsSet, GridsBroadcastConfig config) { MyGpsCollection gpsCollection = (MyGpsCollection)MyAPIGateway.Session?.GPS; if (gpsCollection == null) { return; } bool followGrids = config.GpsFollowGrids; bool playSound = config.PlayGpsSound; foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers()) { foreach (MyGps gps in gpsSet) { MyGps gpsRef = gps; long entityId = 0L; if (followGrids) { entityId = gps.EntityId; } gpsCollection.SendAddGps(player.Identity.IdentityId, ref gpsRef, entityId, playSound); } } }
private void SpawnBackpack(MyEntity obj) { MyInventory inventory = new MyInventory(); inventory.Init(this.m_spawnInventory.GetObjectBuilder()); this.m_spawnInventory = inventory; if (this.m_spawnInventory != null) { MyContainerDefinition definition; if (!MyComponentContainerExtension.TryGetContainerDefinition(base.Character.Definition.InventorySpawnContainerId.Value.TypeId, base.Character.Definition.InventorySpawnContainerId.Value.SubtypeId, out definition)) { MyDefinitionId id = new MyDefinitionId(typeof(MyObjectBuilder_InventoryBagEntity), base.Character.Definition.InventorySpawnContainerId.Value.SubtypeId); MyComponentContainerExtension.TryGetContainerDefinition(id.TypeId, id.SubtypeId, out definition); } if (((definition != null) && Sync.IsServer) && !MyFakes.USE_GPS_AS_FRIENDLY_SPAWN_LOCATIONS) { MyGps gps1 = new MyGps(); gps1.ShowOnHud = true; gps1.Name = new StringBuilder().AppendStringBuilder(MyTexts.Get(MySpaceTexts.GPS_Body_Location_Name)).Append(" - ").AppendFormatedDateTime(DateTime.Now).ToString(); gps1.DisplayName = MyTexts.GetString(MySpaceTexts.GPS_Body_Location_Name); gps1.DiscardAt = null; gps1.Coords = base.Character.PositionComp.GetPosition(); gps1.Description = ""; gps1.AlwaysVisible = true; gps1.GPSColor = new Color(0x75, 0xc9, 0xf1); gps1.IsContainerGPS = true; MyGps gps = gps1; MySession.Static.Gpss.SendAddGps(base.Character.DeadPlayerIdentityId, ref gps, this.SpawnInventoryContainer(base.Character.Definition.InventorySpawnContainerId.Value, this.m_spawnInventory, false, base.Character.DeadPlayerIdentityId), false); } } }
private void FillRight(MyGps ins) { UnhookSyncEvents(); m_panelInsName.SetText(new StringBuilder(ins.Name)); m_panelInsDesc.SetText(new StringBuilder(ins.Description)); //m_textInsDesc m_xCoord.SetText(new StringBuilder(ins.Coords.X.ToString("F2", System.Globalization.CultureInfo.InvariantCulture))); m_yCoord.SetText(new StringBuilder(ins.Coords.Y.ToString("F2", System.Globalization.CultureInfo.InvariantCulture))); m_zCoord.SetText(new StringBuilder(ins.Coords.Z.ToString("F2", System.Globalization.CultureInfo.InvariantCulture))); m_checkInsShowOnHud.IsCheckedChanged -= OnShowOnHudChecked; m_checkInsShowOnHud.IsChecked = ins.ShowOnHud; m_checkInsShowOnHud.IsCheckedChanged += OnShowOnHudChecked; m_checkInsAlwaysVisible.IsCheckedChanged -= OnAlwaysVisibleChecked; m_checkInsAlwaysVisible.IsChecked = ins.AlwaysVisible; m_checkInsAlwaysVisible.IsCheckedChanged += OnAlwaysVisibleChecked; m_previousHash = ins.Hash; HookSyncEvents(); m_needsSyncName = false; m_needsSyncDesc = false; m_needsSyncX = false; m_needsSyncY = false; m_needsSyncZ = false; m_panelInsName.ColorMask = Vector4.One; m_xCoord.ColorMask = Vector4.One; m_yCoord.ColorMask = Vector4.One; m_zCoord.ColorMask = Vector4.One; m_nameOk = m_xOk = m_yOk = m_zOk = true; updateWarningLabel(); }
public void Close() { trySync(); if (m_tableIns != null) { ClearList(); m_tableIns.ItemSelected -= OnTableItemSelected; m_tableIns.ItemDoubleClicked -= OnTableDoubleclick; } m_syncedGps = null; MySession.Static.Gpss.GpsChanged -= OnInsChanged; MySession.Static.Gpss.ListChanged -= OnListChanged; UnhookSyncEvents(); m_checkInsShowOnHud.IsCheckedChanged -= OnShowOnHudChecked; m_checkInsAlwaysVisible.IsCheckedChanged -= OnAlwaysVisibleChecked; m_buttonAdd.ButtonClicked -= OnButtonPressedNew; m_buttonAddFromClipboard.ButtonClicked -= OnButtonPressedNewFromClipboard; m_buttonAddCurrent.ButtonClicked -= OnButtonPressedNewFromCurrent; m_buttonDelete.ButtonClicked -= OnButtonPressedDelete; m_buttonCopy.ButtonClicked -= OnButtonPressedCopy; }
public override MyActionDescription GetActionInfo(UseActionEnum actionEnum) { m_buttonPanel.Toolbar.UpdateItem(m_index); var slot = m_buttonPanel.Toolbar.GetItemAtIndex(m_index); switch (actionEnum) { case UseActionEnum.Manipulate: if (m_buttonDesc == null) { m_buttonDesc = new MyGps(); m_buttonDesc.Description = ""; m_buttonDesc.Coords = ActivationMatrix.Translation; m_buttonDesc.ShowOnHud = true; m_buttonDesc.DiscardAt = null; } MyHud.ButtonPanelMarkers.RegisterMarker(m_buttonDesc); SetButtonName(m_buttonPanel.GetCustomButtonName(m_index)); if (slot != null) { return(new MyActionDescription() { Text = MyCommonTexts.NotificationHintPressToUse, FormatParams = new object[] { MyInput.Static.GetGameControl(MyControlsSpace.USE), slot.DisplayName }, IsTextControlHint = true, JoystickFormatParams = new object[] { MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.USE), slot.DisplayName }, }); } else { return(new MyActionDescription() { Text = MySpaceTexts.Blank }); } case UseActionEnum.OpenTerminal: return(new MyActionDescription() { Text = MySpaceTexts.NotificationHintPressToOpenButtonPanel, FormatParams = new object[] { MyInput.Static.GetGameControl(MyControlsSpace.TERMINAL) }, IsTextControlHint = true, JoystickText = MySpaceTexts.NotificationHintJoystickPressToOpenButtonPanel, }); default: Debug.Fail("Invalid branch reached."); return(new MyActionDescription() { Text = MySpaceTexts.NotificationHintPressToOpenButtonPanel, FormatParams = new object[] { MyInput.Static.GetGameControl(MyControlsSpace.TERMINAL) }, IsTextControlHint = true }); } }
private void OnInsChanged(long id, int hash) { //screen refresh is only needed when an GPS applies to this player if (id == MySession.Static.LocalPlayerId) { FillRight(); //color/name in table: int i = 0; while (i < m_tableIns.RowsCount) { if (((MyGps)m_tableIns.GetRow(i).UserData).GetHashCode() == hash) { Sandbox.Graphics.GUI.MyGuiControlTable.Cell cell = m_tableIns.GetRow(i).GetCell(0); if (cell != null) { MyGps ins = (MyGps)m_tableIns.GetRow(i).UserData; cell.TextColor = (ins.DiscardAt != null ? Color.Gray : (ins.ShowOnHud ? ITEM_SHOWN_COLOR : Color.White)); cell.Text.Clear().Append(((MyGps)m_tableIns.GetRow(i).UserData).Name); //FillRight((MyIns)m_tableIns.SelectedRow.UserData); } break; } ++i; } } }
static void OnAddGps(AddMsg msg) { MyGps gps = new MyGps(); gps.Name = msg.Name; gps.Description = msg.Description; gps.Coords = msg.Coords; gps.ShowOnHud = msg.ShowOnHud; gps.AlwaysVisible = msg.AlwaysVisible; gps.DiscardAt = null; gps.GPSColor = msg.GPSColor; if (!msg.IsFinal) { gps.SetDiscardAt(); } gps.UpdateHash(); if (msg.EntityId > 0) { gps.SetEntity(MyEntities.GetEntityById(msg.EntityId)); } if (MySession.Static.Gpss.AddPlayerGps(msg.IdentityId, ref gps)) {//new entry succesfully added if (gps.ShowOnHud && msg.IdentityId == MySession.Static.LocalPlayerId) { MyHud.GpsMarkers.RegisterMarker(gps); } } var handler = MySession.Static.Gpss.ListChanged; if (handler != null) { handler(msg.IdentityId); } }
/// <summary> /// Adds a new Dynamic gps to the player /// </summary> /// <param name="name">Name of the gps</param> /// <param name="color">Color of the gps</param> /// <param name="pos">Position of the gps</param> /// <param name="playerId">Player, the gps belongs to</param> /// <param name="id">The id of the gps</param> /// <returns>False, if the gps is already added, else true</returns> public bool AddDynamicGps(string name, Color color, Vector3D pos, long playerId, Guid id) { Tuple <Guid, long> key = new Tuple <Guid, long>(id, playerId); if (m_dynamicGpss.ContainsKey(key)) { RemoveDynamicGps(playerId, id); } MyGps gps = new MyGps { Name = name, Coords = pos, GPSColor = color, ShowOnHud = true, AlwaysVisible = false, DiscardAt = null }; gps.CalculateHash(); gps.UpdateHash(); MySession.Static.Gpss.SendAddGps(playerId, ref gps, playSoundOnCreation: false); m_dynamicGpss.Add(key, gps.Hash); return(true); }
private MyGps CreateGps(Vector3D location, MyIdentity identity) { var offset = Plugin.Config.GpsOffsetFromPlayerKm; var offsetMax = Plugin.Config.GpsOffsetFromPlayerKmMax; if (offsetMax < offset) { offsetMax = offset; } if (offset > 0) { double distance = offset * 1000.0; double distanceMax = offsetMax * 1000.0; location = FindRandomPosition(location, distance, distanceMax); } MyGps gps = new MyGps { Coords = location, Name = "Location of " + identity.DisplayName + " #" + DateTimeOffset.Now.ToUnixTimeMilliseconds(), DisplayName = "Location of " + identity.DisplayName, Description = "Bought via GPS Roulette plugin", GPSColor = Color.Cyan, IsContainerGPS = true, ShowOnHud = true, DiscardAt = new TimeSpan?(), AlwaysVisible = true }; gps.UpdateHash(); return(gps); }
static void AddSuccess(ref AddMsg msg, MyNetworkClient sender) { MyGps gps = new MyGps(); gps.Name = msg.Name; gps.Description = msg.Description; gps.Coords = msg.Coords; gps.ShowOnHud = msg.ShowOnHud; gps.DiscardAt = null; if (!msg.IsFinal) { gps.SetDiscardAt(); } gps.UpdateHash(); if (MySession.Static.Gpss.AddPlayerGps(msg.IdentityId, ref gps)) {//new entry succesfully added if (gps.ShowOnHud && msg.IdentityId == MySession.LocalPlayerId) { MyHud.GpsMarkers.RegisterMarker(gps); } } var handler = MySession.Static.Gpss.ListChanged; if (handler != null) { handler(msg.IdentityId); } }
private void Broadcast(MeasureResult result) { if (MyAPIGateway.Session == null) { return; } var gpsName = FormatResult(result); var gps = new MyGps(new MyObjectBuilder_Gps.Entry { name = gpsName, DisplayName = gpsName, // ReSharper disable once PossibleInvalidOperationException coords = result.EntityCoords, showOnHud = true, color = Color.Purple, description = FormatResult(result), entityId = 0, isFinal = false }); //to all online players MySession.Static.Players.GetOnlinePlayers().Where(it => it.IsRealPlayer) .ForEach(it => { var identityId = it.Identity.IdentityId; MyAPIGateway.Session.GPS.AddGps(identityId, gps); Plugin.AddedGps.AddOrUpdateList(identityId, gps); }); }
private MyGuiControlTable.Row AddToList(MyGps ins) { var row = new MyGuiControlTable.Row(ins); var name = new StringBuilder(ins.Name); row.AddCell(new MyGuiControlTable.Cell(text: name, userData: ins, textColor: (ins.DiscardAt != null ? Color.Gray : (ins.ShowOnHud ? ITEM_SHOWN_COLOR : Color.White)))); m_tableIns.Add(row); return row; }
public MyObjectBuilder_Gps.Entry GetObjectBuilderEntry(MyGps gps) { return(new MyObjectBuilder_Gps.Entry() { name = gps.Name, description = gps.Description, coords = gps.Coords, isFinal = (gps.DiscardAt == null ? true : false), showOnHud = gps.ShowOnHud }); }
//MODIFY: public void SendModifyGps(long identityId, MyGps gps) {//beware: gps must still contain original hash. Recompute during/after success. var msg = new ModifyMsg(); msg.IdentityId = identityId; msg.Name = gps.Name; msg.Description = gps.Description; msg.Coords = gps.Coords; msg.Hash = gps.Hash; MyMultiplayer.RaiseStaticEvent(s => MyGpsCollection.ModifyRequest, msg); }
//MODIFY: public void SendModifyGps(long identityId, MyGps gps) {//beware: gps must still contain original hash. Recompute during/after success. var msg = new ModifyMsg(); msg.IdentityId = identityId; msg.Name = gps.Name; msg.Description = gps.Description; msg.Coords = gps.Coords; msg.Hash = gps.Hash; Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request); }
//ADD: public void SendAddGps(long identityId, ref MyGps gps) { var msg = new AddMsg(); msg.IdentityId = identityId; msg.Name = gps.Name; msg.Description = gps.Description; msg.Coords = gps.Coords; msg.ShowOnHud = gps.ShowOnHud; msg.IsFinal = (gps.DiscardAt == null?true:false); MyMultiplayer.RaiseStaticEvent(s => MyGpsCollection.OnAddGps, msg); }
private void OnButtonPressedNew(MyGuiControlButton sender) { trySync(); MyGps ins = new MyGps(); ins.Name = MyTexts.Get(MySpaceTexts.TerminalTab_GPS_NewCoord_Name).ToString(); ins.Description = MyTexts.Get(MySpaceTexts.TerminalTab_GPS_NewCoord_Desc).ToString(); ins.Coords = new Vector3D(0, 0, 0); ins.ShowOnHud = true; ins.DiscardAt = null;//finalize MySession.Static.Gpss.SendAddGps(MySession.LocalPlayerId, ref ins); m_searchIns.Text = ""; enableEditBoxes(false); }
//ADD: public void SendAddGps(long identityId, ref MyGps gps) { var msg = new AddMsg(); msg.IdentityId = identityId; msg.Name = gps.Name; msg.Description = gps.Description; msg.Coords = gps.Coords; msg.ShowOnHud = gps.ShowOnHud; msg.IsFinal = (gps.DiscardAt == null?true:false); Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request); }
private MyGps CreateGPS(MarketDataObject market, Vector3D position) { var gps = new MyGps(); gps.Coords = position; gps.Name = $"(Market) {market.Name}"; gps.DisplayName = $"(Market) {market.Name}"; gps.GPSColor = new Color(0, 275, 275); gps.IsContainerGPS = true; gps.ShowOnHud = true; gps.DiscardAt = new TimeSpan?(); gps.UpdateHash(); return(gps); }
public void AddGps(string name, Color color, Vector3D pos) { MyGps g = new MyGps() { Name = name, Coords = pos, ShowOnHud = true, GPSColor = color, AlwaysVisible = true, DiscardAt = null }; g.UpdateHash(); ToAddGpss.Add(g); }
private bool trySync() {//takes current right side values of name, description and coordinates, compares them against record with previous hash and synces if necessary if (m_previousHash != null && (m_needsSyncName || m_needsSyncDesc || m_needsSyncX || m_needsSyncY || m_needsSyncZ)) { if (MySession.Static.Gpss.ExistsForPlayer(MySession.Static.LocalPlayerId)) { if (IsNameOk(m_panelInsName.Text) && IsCoordOk(m_xCoord.Text) && IsCoordOk(m_yCoord.Text) && IsCoordOk(m_zCoord.Text)) { Dictionary <int, MyGps> insList; insList = MySession.Static.Gpss[MySession.Static.LocalPlayerId]; MyGps ins; if (insList.TryGetValue((int)m_previousHash, out ins)) { if (m_needsSyncName) { ins.Name = m_panelInsName.Text; } if (m_needsSyncDesc) { ins.Description = m_panelInsDesc.Text; } StringBuilder str = new StringBuilder(); if (m_needsSyncX) { m_xCoord.GetText(str); ins.Coords.X = Math.Round(double.Parse(str.ToString(), System.Globalization.CultureInfo.InvariantCulture), 2); } str.Clear(); if (m_needsSyncY) { m_yCoord.GetText(str); ins.Coords.Y = Math.Round(double.Parse(str.ToString(), System.Globalization.CultureInfo.InvariantCulture), 2); } str.Clear(); if (m_needsSyncZ) { m_zCoord.GetText(str); ins.Coords.Z = Math.Round(double.Parse(str.ToString(), System.Globalization.CultureInfo.InvariantCulture), 2); } m_syncedGps = ins; MySession.Static.Gpss.SendModifyGps(MySession.Static.LocalPlayerId, ins); return(true); } } } } return(false); }
public static void SendGps(Vector3D Position, string name, long EntityID, double Miniutes = 5) { MyGps myGps = new MyGps(); myGps.ShowOnHud = true; myGps.Coords = Position; myGps.Name = name; myGps.Description = "Hangar location for loading grid at or around this position"; myGps.AlwaysVisible = true; MyGps gps = myGps; gps.DiscardAt = TimeSpan.FromMinutes(MySession.Static.ElapsedPlayTime.TotalMinutes + Miniutes); gps.GPSColor = Color.Yellow; MySession.Static.Gpss.SendAddGps(EntityID, ref gps, 0L, true); }