private bool ServerActiveControlUpdate(PacketObj data) { var packet = data.Packet; var dPacket = (BoolUpdatePacket)packet; var cube = MyEntities.GetEntityByIdOrDefault(packet.EntityId) as MyCubeBlock; if (cube == null) { return(Error(data, Msg("Cube"))); } GridAi ai; long playerId = 0; if (GridToMasterAi.TryGetValue(cube.CubeGrid, out ai) && SteamToPlayer.TryGetValue(packet.SenderId, out playerId)) { uint[] mIds; if (PlayerMIds.TryGetValue(packet.SenderId, out mIds) && mIds[(int)packet.PType] < packet.MId) { mIds[(int)packet.PType] = packet.MId; ai.Construct.UpdateConstructsPlayers(cube, playerId, dPacket.Data); data.Report.PacketValid = true; } else { Log.Line($"ServerActiveControlUpdate: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}"); } } else { Log.Line($"ServerActiveControlUpdate: ai:{ai != null} - targetingAi:{GridTargetingAIs.ContainsKey(cube.CubeGrid)} - masterAi:{GridToMasterAi.ContainsKey(cube.CubeGrid)} - IdToComp:{IdToCompMap.ContainsKey(cube.EntityId)} - {cube.BlockDefinition.Id.SubtypeName} - playerId:{playerId}({packet.SenderId}) - marked:{cube.MarkedForClose}({cube.CubeGrid.MarkedForClose}) - active:{dPacket.Data}"); } return(true); }
public bool IsWeaponAreaRestricted(MyStringHash subtype, MyOrientedBoundingBoxD cubeBoundingBox, MyCubeGrid myGrid, long ignoredEntity, GridAi gridAi, out MyOrientedBoundingBoxD restrictedBox, out BoundingSphereD restrictedSphere) { _tmpNearByBlocks.Clear(); GridAi ai; if (gridAi == null) { if (!GridToMasterAi.ContainsKey(myGrid)) { restrictedSphere = new BoundingSphereD(); restrictedBox = new MyOrientedBoundingBoxD(); return(false); } ai = GridToMasterAi[myGrid]; } else { ai = gridAi; } CalculateRestrictedShapes(subtype, cubeBoundingBox, out restrictedBox, out restrictedSphere); var queryRadius = Math.Max(restrictedBox.HalfExtent.AbsMax(), restrictedSphere.Radius); if (queryRadius < 0.01) { return(false); } var restriction = WeaponAreaRestrictions[subtype]; var checkBox = restriction.RestrictionBoxInflation > 0; var checkSphere = restriction.RestrictionRadius > 0; var querySphere = new BoundingSphereD(cubeBoundingBox.Center, queryRadius); myGrid.Hierarchy.QuerySphere(ref querySphere, _tmpNearByBlocks); foreach (var grid in ai.SubGrids) { if (grid == myGrid || !GridTargetingAIs.ContainsKey(grid)) { continue; } grid.Hierarchy.QuerySphere(ref querySphere, _tmpNearByBlocks); } for (int l = 0; l < _tmpNearByBlocks.Count; l++) { var cube = _tmpNearByBlocks[l] as MyCubeBlock; if (cube == null || cube.EntityId == ignoredEntity || !WeaponCoreBlockDefs.ContainsKey(cube.BlockDefinition.Id.SubtypeId.String)) { continue; } if (!restriction.CheckForAnyWeapon && cube.BlockDefinition.Id.SubtypeId != subtype) { continue; } if (checkBox) { var cubeBox = new MyOrientedBoundingBoxD(cube.PositionComp.LocalAABB, cube.PositionComp.WorldMatrixRef); if (restrictedBox.Contains(ref cubeBox) != ContainmentType.Disjoint) { return(true); } } if (checkSphere && restrictedSphere.Contains(cube.PositionComp.WorldAABB) != ContainmentType.Disjoint) { return(true); } } return(false); }