public CharacterEntity GetPlayer(ulong steamID) { long gameEntity = PlayerMap.Instance.GetPlayerEntityId(steamID); CharacterEntity characEntity = (CharacterEntity)GameEntityManager.GetEntity(gameEntity); return(characEntity); }
public override void Dispose( ) { if (IsDisposed) { return; } base.Dispose( ); if (BackingObject != null) { //Only remove if the backing object isn't already disposed bool isDisposed = (bool)InvokeEntityMethod(BackingObject, BaseEntityGetIsDisposedMethod); if (!isDisposed) { m_networkManager.RemoveEntity( ); Action action = InternalRemoveEntity; SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action); } } if (EntityId != 0) { GameEntityManager.RemoveEntity(EntityId); } EntityEventManager.EntityEvent newEvent = new EntityEventManager.EntityEvent( ); newEvent.type = EntityEventManager.EntityEventType.OnBaseEntityDeleted; newEvent.timestamp = DateTime.Now; newEvent.entity = this; newEvent.priority = 1; EntityEventManager.Instance.AddEvent(newEvent); }
// admin nobeacon scan public override bool HandleCommand(ulong userId, string[] words) { try { HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesToConfirm = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesConnected = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>(); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid); }); foreach (IMyEntity entity in entities) { if (!(entity is IMyCubeGrid)) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid); if (gridBuilder == null) { continue; } bool found = false; foreach (MyObjectBuilder_CubeBlock block in gridBuilder.CubeBlocks) { if (block.TypeId == typeof(MyObjectBuilder_Beacon)) { found = true; break; } } if (!found) { entitiesToConfirm.Add(grid); } } CubeGrids.GetGridsUnconnected(entitiesFound, entitiesToConfirm); foreach (IMyEntity entity in entitiesFound) { CubeGridEntity gridEntity = (CubeGridEntity)GameEntityManager.GetEntity(entity.EntityId); Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) at {2} with no beacon.", gridEntity.Name, gridEntity.EntityId, General.Vector3DToString(entity.GetPosition()))); } Communication.SendPrivateInformation(userId, string.Format("Found {0} grids with no beacons", entitiesFound.Count)); } catch (Exception ex) { Logging.WriteLineAndConsole(string.Format("Scan error: {0}", ex.ToString())); } return(true); }
// admin nobeacon scan public override bool HandleCommand(ulong userId, string[] words) { if (words.Count() > 1) { return(false); } if (!words.Any()) { Communication.SendPrivateInformation(userId, GetHelp()); return(true); } long entityId = 0; if (!long.TryParse(words[0], out entityId)) { Communication.SendPrivateInformation(userId, string.Format("The value '{0}' is not a valid entityId", words[0])); return(true); } CubeGridEntity entity = (CubeGridEntity)GameEntityManager.GetEntity(entityId); Communication.SendPrivateInformation(userId, string.Format("Entity {0} DisplayName: {1} FullName: {2}", entityId, entity.DisplayName, entity.Name)); return(true); }
// /admin ownership change name gridId public override bool HandleCommand(ulong userId, string[] words) { string name = words[0].ToLower(); long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(PlayerMap.Instance.GetSteamIdFromPlayerName(name, true)).First(); string gridId = words[1].ToLower(); long gridEntityId = 0; if (!long.TryParse(gridId, out gridEntityId)) { Communication.SendPrivateInformation(userId, string.Format("Invalid EntityID entered: {0}", gridId)); return(true); } CubeGridEntity grid = (CubeGridEntity)GameEntityManager.GetEntity(gridEntityId); for (int r = 0; r < grid.CubeBlocks.Count; r++) { CubeBlockEntity block = (CubeBlockEntity)grid.CubeBlocks[r]; if (block is TerminalBlockEntity) { if (block.Owner != playerId && block.Owner != 0) { Communication.SendPrivateInformation(userId, string.Format("Changing ownership of {0} - {1}", block.Name, playerId)); block.Owner = playerId; } } } return(true); }
public void Initialize() { cam.gameObject.SetActive(true); cameraObstacles = Settings.Instance().cameraObstacles; target = GameEntityManager.GetPlayerEntity().GetTransform(); if (HasCamera) { cam.transform.localPosition = Vector3.zero; cam.transform.localRotation = Quaternion.identity; } MinPitch = Mathf.Clamp(MinPitch, -85f, 0f); MaxPitch = Mathf.Clamp(MaxPitch, 0f, 85f); MinDistance = Mathf.Max(0f, MinDistance); currentMinDistance = MinDistance; currentMaxDistance = MaxDistance; currentYaw = targetYaw = 0f; currentPitch = targetPitch = Mathf.Lerp(MinPitch, MaxPitch, 0.6f); currentDistance = targetDistance = realDistance = Mathf.Lerp(MinDistance, MaxDistance, 0.5f); }
public override ItemDef GetItemDefinition(GameEntityManager usedMgr) { var def = CreateDefinitionCopy(ItemID.Cabinet, usedMgr); def.Name = "book shelve"; return(def); }
public CubeBlockEntity(CubeGridEntity parent, MyObjectBuilder_CubeBlock definition, Object backingObject) : base(definition, backingObject) { m_parent = parent; EntityEventManager.EntityEvent newEvent = new EntityEventManager.EntityEvent(); newEvent.type = EntityEventManager.EntityEventType.OnCubeBlockCreated; newEvent.timestamp = DateTime.Now; newEvent.entity = this; if (m_parent.IsLoading) { newEvent.priority = 10; } else if (EntityId != 0) { newEvent.priority = 1; } else { newEvent.priority = 2; } EntityEventManager.Instance.AddEvent(newEvent); if (EntityId != 0) { GameEntityManager.AddEntity(EntityId, this); } m_buildPercent = definition.BuildPercent; m_integrityPercent = definition.IntegrityPercent; m_owner = definition.Owner; m_shareMode = definition.ShareMode; }
public void OnCharacterGet(string playerId, io.gamemachine.messages.Character character) { Messenger messenger = ActorSystem.instance.Find("Messenger") as Messenger; string myPlayerId = GameEntityManager.GetPlayerEntity().GetEntityId(); messenger.InviteToChannel(myPlayerId, character.playerId, requestedGroup); Debug.Log("invite sent to " + character.playerId + " for channel " + requestedGroup); }
public override CraftableItem GetCraftableItem(GameEntityManager usedMgr) { var craftableCabinet = usedMgr.WorkshopDef(WorkshopID.Carpenter).CraftableItems.Single(ci => ci.ItemID == ItemID.Cabinet); var craftableBookshelve = CopyCraftableItem(craftableCabinet); craftableBookshelve.ItemID = CustomItems.GetItemIdForType <BookShelveItemProvider>(); return(craftableBookshelve); }
public override ConstructionDef GetConstructionDefinition(GameEntityManager usedMgr) { var def = CreateDefinitionCopy(ConstructionID.Cabinet, usedMgr); def.Name = "book shelve"; def.Components[0].ID = CustomItems.GetItemIdForType <BookShelveItemProvider>(); return(def); }
void Awake() { instance = this; IGameEntity gameEntity = Create(); if (gameEntity != null) { GameEntityManager.SetPlayerEntity(gameEntity); } }
void Awake() { if (Instance != null) { DestroyImmediate(Instance); } else { Instance = this; } }
public static void DrawItem(SpriteBatch spriteBatch, CustomItem item) { var map = GnomanEmpire.Instance.Map; var mapCell = (item.Parent == null) ? item.Cell() : item.Parent.Cell(); var lightLevel = mapCell.LightLevel; //map.TerrainProperties[this.MaterialID].ConvertColor(lightLevel); Color color = GameEntity.Darken(Color.White, lightLevel); Vector2 pos = GnomanEmpire.Instance.Camera.MapIndexToScreenCoords(item.Position); GameEntityManager entityManager = GnomanEmpire.Instance.EntityManager; foreach (var drawableComponent in item.Drawables) { int num = item.History.MaterialAtIndex(drawableComponent.MaterialIndex); drawableComponent.Entity.Draw(spriteBatch, pos, (drawableComponent.MaterialIndex == -1) ? color : map.TerrainProperties[num].ConvertColor(lightLevel)); } }
void Start() { if (!GamePlayer.IsNetworked()) { Destroy(this.gameObject); return; } canvas = gameObject.GetComponent <Canvas>() as Canvas; canvas.enabled = false; contentHolder = GameObject.Find("chat_text"); messageTemplate = transform.Find("msg_template").gameObject; messageTemplate.SetActive(false); groupContainer = GameObject.Find("group_container"); groupMemberContainer = GameObject.Find("group_member_container"); groupMemberTemplate = GameObject.Find("group_member"); groupMemberTemplate.SetActive(false); groupContainer.SetActive(false); chatInput = GameObject.Find("chat_input").GetComponent <InputField>() as InputField; playerId = GameEntityManager.GetPlayerEntity().GetEntityId(); characterId = GameEntityManager.GetPlayerEntity().GetCharacterId(); messenger = ActorSystem.instance.Find("Messenger") as Messenger; chatCommandHandler = new ChatCommandHandler(messenger, this, playerId); Messenger.ChannelJoined channelCallback = ChannelJoined; messenger.OnChannelJoined(channelCallback); Messenger.ChannelLeft channelLeftCallback = ChannelLeft; messenger.OnChannelLeft(channelLeftCallback); Messenger.MessageReceived messageCallback = MessageReceived; messenger.OnMessageReceived(messageCallback); Messenger.InviteReceived inviteCallback = InviteReceived; messenger.OnInviteReceived(inviteCallback); foreach (string channel in autojoinChannels) { messenger.JoinChannel(channel); } InvokeRepeating("UpdateChatStatus", 0.01f, 2.0F); }
protected static void ReceiveCurrentPowerPacket <T>(ref T packet, Object netManager) where T : struct { try { //object result = BaseObject.InvokeEntityMethod( packet, BatteryBlockNetManagerCurrentStoredPowerPacketGetIdMethod ); //object result = BaseObject.GetEntityFieldValue(packet, BatteryBlockNetManagerCurrentStoredPowerPacketGetIdField); object result = null; if (result == null) { return; } long entityId = (long)result; BaseObject matchedEntity = GameEntityManager.GetEntity(entityId); if (matchedEntity == null) { return; } if (!(matchedEntity is BatteryBlockEntity)) { return; } BatteryBlockEntity battery = (BatteryBlockEntity)matchedEntity; result = BaseObject.GetEntityFieldValue(packet, BatteryBlockNetManagerCurrentStoredPowerPacketValueField); if (result == null) { return; } float packetPowerLevel = (float)result; if (packetPowerLevel == 1.0f) { return; } BaseObject.SetEntityFieldValue(packet, BatteryBlockNetManagerCurrentStoredPowerPacketValueField, battery.CurrentStoredPower); Type refPacketType = packet.GetType( ).MakeByRefType( ); MethodInfo basePacketHandlerMethod = BaseObject.GetStaticMethod(InternalType, BatteryBlockNetManagerCurrentPowerPacketReceiver, new Type[] { refPacketType, netManager.GetType( ) }); basePacketHandlerMethod.Invoke(null, new object[] { packet, netManager }); } catch (Exception ex) { ApplicationLog.BaseLog.Error(ex); } }
void ShowStats() { if (currentStats != null) { canvas.enabled = false; foreach (Transform t in container.transform) { Destroy(t.gameObject); } ShowStat("Player bytes out", currentStats.playerBytesOut); ShowStat("Bytes out", currentStats.bytesOut); ShowStat("Messages in/out", currentStats.messageCountInOut); ShowStat("Messages in", currentStats.messageCountIn); ShowStat("Messages out", currentStats.messageCountOut); ShowStat("Connections", currentStats.connectionCount); ShowStat("Entities in visual range", GameEntityManager.GameEntityCount()); canvas.enabled = true; } }
public BaseEntity(MyObjectBuilder_EntityBase baseEntity, Object backingObject) : base(baseEntity, backingObject) { if (baseEntity != null) { m_entityId = baseEntity.EntityId; if (baseEntity.PositionAndOrientation != null) { m_positionOrientation = baseEntity.PositionAndOrientation.GetValueOrDefault( ); } else { m_positionOrientation = new MyPositionAndOrientation( ); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } } else { m_entityId = 0; m_positionOrientation = new MyPositionAndOrientation( ); m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000)); m_positionOrientation.Forward = new Vector3(0, 0, 1); m_positionOrientation.Up = new Vector3(0, 1, 0); } m_networkManager = new BaseEntityNetworkManager(this, GetEntityNetworkManager(BackingObject)); m_linearVelocity = new Vector3(0, 0, 0); m_angularVelocity = new Vector3(0, 0, 0); m_maxLinearVelocity = (float)104.7; if (EntityId != 0) { GameEntityManager.AddEntity(EntityId, this); } Action action = InternalRegisterEntityMovedEvent; SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action); }
public override void Dispose() { m_isDisposed = true; Parent.DeleteCubeBlock(this); EntityEventManager.EntityEvent newEvent = new EntityEventManager.EntityEvent(); newEvent.type = EntityEventManager.EntityEventType.OnCubeBlockDeleted; newEvent.timestamp = DateTime.Now; newEvent.entity = this; newEvent.priority = (ushort)((EntityId != 0) ? 1 : 2); EntityEventManager.Instance.AddEvent(newEvent); if (EntityId != 0) { GameEntityManager.RemoveEntity(EntityId); } base.Dispose(); }
public override void Dispose( ) { if (SandboxGameAssemblyWrapper.IsDebugging) { LogManager.APILog.WriteLine("Disposing CubeGridEntity '" + Name + "' ..."); } //Dispose the cube grid by disposing all of the blocks //This may be slow but it's reliable ... so far /* * List<CubeBlockEntity> blocks = CubeBlocks; * int blockCount = blocks.Count; * foreach (CubeBlockEntity cubeBlock in blocks) * { * cubeBlock.Dispose(); * } * * if (SandboxGameAssemblyWrapper.IsDebugging) * LogManager.APILog.WriteLine("Disposed " + blockCount.ToString() + " blocks on CubeGridEntity '" + Name + "'"); */ //Broadcast the removal to the clients just to save processing time for the clients BaseNetworkManager.RemoveEntity( ); m_isDisposed = true; if (EntityId != 0) { GameEntityManager.RemoveEntity(EntityId); } EntityEventManager.EntityEvent newEvent = new EntityEventManager.EntityEvent { type = EntityEventManager.EntityEventType.OnCubeGridDeleted, timestamp = DateTime.Now, entity = this, priority = 1 }; EntityEventManager.Instance.AddEvent(newEvent); }
private void ProtectedEntity(IMyEntity entity, ProtectedItem item) { //Logging.WriteLineAndConsole(string.Format("Protecting: {0}", entity.EntityId)); //CubeGridEntity gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity); CubeGridEntity gridEntity = (CubeGridEntity)GameEntityManager.GetEntity(entity.EntityId); MyObjectBuilder_CubeGrid grid = (MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(); int count = 0; while (gridEntity.IsLoading) { if (count >= 20) { return; } Thread.Sleep(100); count++; } bool found = false; /* * foreach(CubeBlockEntity block in gridEntity.CubeBlocks) * { * if (block.IntegrityPercent != item.IntegrityIncrease || block.BuildPercent != item.IntegrityIncrease || block.BoneDamage > 0f) * { * found = true; * block.FixBones(0, 100); * block.IntegrityPercent = item.IntegrityIncrease; * block.BuildPercent = item.IntegrityIncrease; * } * } */ if (found) { Logging.WriteLineAndConsole(string.Format("Repaired Grid: {0}", gridEntity.EntityId)); } }
public static GamePlayer Instance() { if (instance != null) { return(instance); } GameObject go = GameObject.Find("GamePlayer"); if (go == null) { return(null); } instance = go.GetComponent <GamePlayer>() as GamePlayer; if (instance == null) { return(null); } if (instance.useGameMachinePlayer) { instance.gameEntity = GameEntityManager.GetPlayerEntity(); if (instance.gameEntity != null) { instance.characterId = GameEntityManager.GetPlayerEntity().GetCharacterId(); instance.playerTransform = GameEntityManager.GetPlayerEntity().GetTransform(); instance.playerRenderers = instance.playerTransform.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); instance.playerCollider = instance.playerTransform.gameObject.GetComponent <Collider>() as Collider; } else { Debug.Log("Game player not present, assuming running as server"); } } return(instance); }
public ItemBase(System.IO.BinaryReader reader, GameEntityManager mgr) : base(reader, mgr) { Counter_Init(); }
public override ItemDef GetItemDefinition(GameEntityManager usedMgr) { var def = CreateDefinitionCopy(ItemID.Cabinet, usedMgr); def.Name = "book shelve"; return def; }
public override CraftableItem GetCraftableItem(GameEntityManager usedMgr) { var craftableCabinet = usedMgr.WorkshopDef(WorkshopID.Carpenter).CraftableItems.Single(ci => ci.ItemID == ItemID.Cabinet); var craftableBookshelve = CopyCraftableItem(craftableCabinet); craftableBookshelve.ItemID = CustomItems.GetItemIdForType<BookShelveItemProvider>(); return craftableBookshelve; }
protected bool RunBaseReflectionUnitTests() { bool result = true; if (!SandboxGameAssemblyWrapper.ReflectionUnitTest()) { result = false; Console.WriteLine("SandboxGameAssemblyWrapper reflection validation failed!"); } if (!ServerAssemblyWrapper.ReflectionUnitTest()) { result = false; Console.WriteLine("ServerAssemblyWrapper reflection validation failed!"); } if (!NetworkManager.ReflectionUnitTest()) { result = false; Console.WriteLine("NetworkManager reflection validation failed!"); } if (!ServerNetworkManager.ReflectionUnitTest()) { result = false; Console.WriteLine("ServerNetworkManager reflection validation failed!"); } if (!UtilityFunctions.ReflectionUnitTest()) { result = false; Console.WriteLine("UtilityFunctions reflection validation failed!"); } if (!ChatManager.ReflectionUnitTest()) { result = false; Console.WriteLine("ChatManager reflection validation failed!"); } if (!PlayerMap.ReflectionUnitTest()) { result = false; Console.WriteLine("PlayerMap reflection validation failed!"); } if (!PlayerManager.ReflectionUnitTest()) { result = false; Console.WriteLine("PlayerManager reflection validation failed!"); } if (!WorldManager.ReflectionUnitTest()) { result = false; Console.WriteLine("WorldManager reflection validation failed!"); } if (!RadioManager.ReflectionUnitTest()) { result = false; Console.WriteLine("RadioManager reflection validation failed!"); } if (!RadioManagerNetworkManager.ReflectionUnitTest()) { result = false; Console.WriteLine("RadioManagerNetworkManager reflection validation failed!"); } if (!PowerManager.ReflectionUnitTest()) { result = false; Console.WriteLine("PowerManager reflection validation failed!"); } if (!FactionsManager.ReflectionUnitTest()) { result = false; Console.WriteLine("FactionsManager reflection validation failed!"); } if (!Faction.ReflectionUnitTest()) { result = false; Console.WriteLine("Faction reflection validation failed!"); } if (!GameEntityManager.ReflectionUnitTest()) { result = false; Console.WriteLine("GameEntityManager reflection validation failed!"); } if (result) { Console.WriteLine("All main types passed reflection unit tests!"); } return(result); }
// admin deletearea x y z radius public override bool HandleCommand(ulong userId, string command) { string[] words = command.Split(' '); if (words.Length > 3) { return(false); } if (!words.Any()) { Communication.SendPrivateInformation(userId, GetHelp()); return(true); } int days = -1; if (!int.TryParse(words[0], out days) || days < 0) { Communication.SendPrivateInformation(userId, string.Format("Invalid argument. Days argument must be an integer that is 0 or greater.")); return(true); } // Just assume that anything after the days is going to "ignorenologin" bool removeNoLoginInformation = true; bool removeOwnerless = true; if (words.Count() > 1) { foreach (string word in words) { if (word.ToLower() == "ignorenologin") { removeNoLoginInformation = false; } if (word.ToLower() == "ignoreownerless") { removeOwnerless = false; } } } Communication.SendPrivateInformation(userId, string.Format("Scanning for grids with owners that haven't logged in {0} days. (Must Have Login Info={1})", days, removeNoLoginInformation)); HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid); }); HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>(); foreach (IMyEntity entity in entities) { if (!(entity is IMyCubeGrid)) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; CubeGridEntity gridEntity = (CubeGridEntity)GameEntityManager.GetEntity(grid.EntityId); MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid); if (gridBuilder == null) { continue; } // This entity is protected by whitelist if (PluginSettings.Instance.LoginEntityWhitelist.Length > 0 && PluginSettings.Instance.LoginEntityWhitelist.Contains(grid.EntityId.ToString())) { continue; } if (CubeGrids.GetAllOwners(gridBuilder).Count < 1 && removeOwnerless) { Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) not owned by anyone.", gridEntity.Name, entity.EntityId)); entitiesFound.Add(entity); continue; } foreach (long player in CubeGrids.GetBigOwners(gridBuilder)) { // This playerId is protected by whitelist if (PluginSettings.Instance.LoginPlayerIdWhitelist.Length > 0 && PluginSettings.Instance.LoginPlayerIdWhitelist.Contains(player.ToString())) { continue; } MyObjectBuilder_Checkpoint.PlayerItem checkItem = PlayerMap.Instance.GetPlayerItemFromPlayerId(player); if (checkItem.IsDead || checkItem.Name == "") { Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) owned by dead player - ID: {2}", gridEntity.Name, entity.EntityId, player)); entitiesFound.Add(entity); continue; } PlayerItem item = Players.Instance.GetPlayerById(player); if (item == null) { if (removeNoLoginInformation) { Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) owned by a player with no login info: {2}", gridEntity.Name, entity.EntityId, checkItem.Name)); entitiesFound.Add(entity); } } else if (item.LastLogin < DateTime.Now.AddDays(days * -1)) { Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) owned by inactive player: {2}", gridEntity.Name, entity.EntityId, PlayerMap.Instance.GetPlayerItemFromPlayerId(player).Name)); entitiesFound.Add(entity); } } } Communication.SendPrivateInformation(userId, string.Format("Found {0} grids owned by inactive users", entitiesFound.Count)); foreach (IMyEntity entity in entitiesFound) { if (!(entity is IMyCubeGrid)) { continue; } CubeGridEntity gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity); gridEntity.Dispose(); } Communication.SendPrivateInformation(userId, string.Format("Removed {0} grids owned by inactive users", entitiesFound.Count)); return(true); }
public override ConstructionDef GetConstructionDefinition(GameEntityManager usedMgr) { var def = CreateDefinitionCopy(ConstructionID.Cabinet, usedMgr); def.Name = "book shelve"; def.Components[0].ID = CustomItems.GetItemIdForType<BookShelveItemProvider>(); return def; }
/// <summary> /// Adds attack targets from save file /// </summary> /// <param name="m"></param> /// <param name="reader"></param> public static void LoadTargets(Game.Military m, BinaryReader reader) { // Need to get attack targets only. Since reflection can't differentiate between attack and defend targets without using the // field name (field name may change between releases since it's obfuscated), read them from the save file var readerPosition = reader.BaseStream.Position; reader.BaseStream.Seek(militaryPosition, SeekOrigin.Begin); int num = reader.ReadInt32(); for (int i = 0; i < num; i++) { new Uniform(reader); } num = reader.ReadInt32(); for (int i = 0; i < num; i++) { new SquadPosition(reader, m); } num = reader.ReadInt32(); for (int i = 0; i < num; i++) { new Formation(reader, m); } num = reader.ReadInt32(); for (int i = 0; i < num; i++) { new GuardStation(reader); } num = reader.ReadInt32(); for (int i = 0; i < num; i++) { ReadPatrolRoute(reader); // PatrolRoute constructor modifies the map object, so manually progress the reader position } if (GnomanEmpire.Instance.LoadingSaveVersion >= 4) { num = reader.ReadInt32(); for (int i = 0; i < num; i++) { ReadTrainingStation(reader); // TrainingStation constructor modifies the map object, so manually progress the reader position } } GameEntityManager entityManager = GnomanEmpire.Instance.EntityManager; num = reader.ReadInt32(); for (int i = 0; i < num; i++) { Character character = entityManager.Entity(reader.ReadUInt32()) as Character; if (character != null) { military.AddTarget(character); } } reader.BaseStream.Seek(readerPosition, SeekOrigin.Begin); }
void Awake() { instance = this; }
// admin deletearea x y z radius public override bool HandleCommand(ulong userId, string[] words) { HashSet <IMyEntity> entities = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesToConfirm = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesConnected = new HashSet <IMyEntity>(); HashSet <IMyEntity> entitiesFound = new HashSet <IMyEntity>(); Wrapper.GameAction(() => { MyAPIGateway.Entities.GetEntities(entities, x => x is IMyCubeGrid); }); foreach (IMyEntity entity in entities) { if (!(entity is IMyCubeGrid)) { continue; } IMyCubeGrid grid = (IMyCubeGrid)entity; MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid); if (gridBuilder == null) { continue; } bool found = false; foreach (MyObjectBuilder_CubeBlock block in gridBuilder.CubeBlocks) { if (block.TypeId == typeof(MyObjectBuilder_Beacon)) { found = true; break; } } if (!found) { entitiesToConfirm.Add(grid); } } CubeGrids.GetGridsUnconnected(entitiesFound, entitiesToConfirm); foreach (IMyEntity entity in entitiesFound) { CubeGridEntity gridEntity = (CubeGridEntity)GameEntityManager.GetEntity(entity.EntityId); if (gridEntity == null) { Log.Info("A found entity gridEntity was null!"); continue; } Communication.SendPrivateInformation(userId, string.Format("Found entity '{0}' ({1}) at {2} with no beacon.", gridEntity.Name, entity.EntityId, General.Vector3DToString(entity.GetPosition()))); } for (int r = entitiesFound.Count - 1; r >= 0; r--) { //MyAPIGateway.Entities.RemoveEntity(entity); IMyEntity entity = entitiesFound.ElementAt(r); CubeGridEntity gridEntity = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity); gridEntity.Dispose(); } Communication.SendPrivateInformation(userId, string.Format("Removed {0} grids with no beacons", entitiesFound.Count)); return(true); }
public CommandResult process(string command) { List <string> words; string messageType = null; if (command.StartsWith("/speed")) { command = command.Replace("/speed", ""); //int speed = Int32.Parse(command); //string characterId = GameEntityManager.GetPlayerEntity().GetCharacterId(); //GameEntityController controller = GameEntityManager.GetPlayerEntity().GetGameEntityController(); return(CommandResult.Ok); } else if (command.StartsWith("/zone")) { command = command.Replace("/zone", "").Trim(); DefaultClient.instance.ConnectToZone(command); return(CommandResult.Ok); } else if (command.StartsWith("/count")) { chatUI.LocalMessage(Color.yellow, GameEntityManager.GameEntityCount().ToString()); return(CommandResult.Ok); } else if (command.StartsWith("/stuck")) { SpawnPoint.Instance().SpawnHome(); return(CommandResult.Ok); } else if (command.StartsWith("/territories")) { return(CommandResult.Ok); } else if (command.StartsWith("/guild_create")) { command = command.Replace("/guild_create", "").Trim(); //string guildId = Messenger.SanitizeChannelName(command); return(CommandResult.Ok); } else if (command.StartsWith("/guild_destroy")) { command = command.Replace("/guild_destroy", "").Trim(); return(CommandResult.Ok); } else if (command.StartsWith("/guild_invite")) { command = command.Replace("/guild_invite", "").Trim(); return(CommandResult.Ok); } else if (command.StartsWith("/guild_leave")) { command = command.Replace("/guild_leave", "").Trim(); return(CommandResult.Ok); } else if (command.StartsWith("/guild_members")) { command = command.Replace("/guild_members", "").Trim(); return(CommandResult.Ok); } else if (command.StartsWith("/guild_list")) { command = command.Replace("/guild_list", "").Trim(); return(CommandResult.Ok); } else if (command.StartsWith("/guild")) { command = command.Replace("/guild", ""); messageType = "group"; //messenger.SendText(playerId, "guild name here", command, messageType); return(CommandResult.Ok); } else if (command.StartsWith("/tell")) { command = command.Replace("/tell", ""); messageType = "private"; } else if (command.StartsWith("/join")) { command = command.Replace("/join", ""); string channel = Messenger.SanitizeChannelName(command); if (IsGuildChannel(channel)) { Debug.Log("Attempt to join guild channel " + channel); return(CommandResult.Ok); } messenger.JoinChannel(channel); return(CommandResult.Ok); } else if (command.StartsWith("/leave")) { command = command.Replace("/leave", ""); messenger.leaveChannel(Messenger.SanitizeChannelName(command)); return(CommandResult.Ok); } else if (command.StartsWith("/channels")) { chatUI.RemoteChannelList(messenger.channelSubscriptions); return(CommandResult.Ok); } else if (command.StartsWith("/group_create")) { messenger.JoinChannel(groupName); return(CommandResult.Ok); } else if (command.StartsWith("/group")) { string msg = command.Replace("/group", ""); messenger.SendText(playerId, chatUI.CurrentGroup(), msg, "group"); return(CommandResult.Ok); } else if (command.StartsWith("/invite")) { command = command.Replace("/invite", ""); words = new List <string>(command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); string characterId = words[0]; InviteToChannel(characterId, groupName); return(CommandResult.Ok); } else if (command.StartsWith("/help")) { string[] commandlist = new string[] { "Valid commands:\n", "/tell [recipient] [message] - send private message", "/join [channel] - join channel", "/leave [channel] - leave channel", "/channels - show channels you are subscribed to", "/group_create - create group", "/group [message] - send group message", "/invite [player] - invite to private group", "/help - this message", "/guild_create [guild characterId] - Create a guild", "/guild_destroy - destroys your guild (must be owner)", "/guild_invite [player] - invite player to guild", "/guild_leave - leave your guild. If owner, destroys it", "/guild [message] - send message to guild", "/guild_list - show list of all guilds", "/guild_members - show members of your guild" }; chatUI.LocalMessage(Color.yellow, String.Join("\n", commandlist)); return(CommandResult.Ok); } else if (command.StartsWith("/")) { command = command.Replace("/", ""); messageType = "group"; } words = new List <string>(command.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); string channelName = words[0]; command = command.Replace(channelName, ""); string message = command; string logMessage = string.Format("channel={0} message={1} messageType={2}", channelName, message, messageType); Debug.Log(logMessage); if (message.Length == 0) { chatUI.LocalMessage(Color.red, "Invalid command"); return(CommandResult.InvalidCommand); } if (messageType == "group" && !messenger.channelSubscriptions.Contains(channelName)) { chatUI.LocalMessage(Color.red, "You are not subscribed to " + channelName); return(CommandResult.NotSubscribed); } if (IsGuildChannel(channelName)) { Debug.Log("Attempt to send message to other guild " + channelName); return(CommandResult.NoPermission); } if (messageType == "private") { channelName = "character_id__" + channelName; } messenger.SendText(playerId, channelName, message, messageType); return(CommandResult.Ok); }
void Start() { gameEntityManager = GameComponent.Get<GameEntityManager>() as GameEntityManager; InvokeRepeating("UpdateTracking", 0.010f, App.gameTickInterval); }
protected bool RunBaseReflectionUnitTests() { bool result = true; if (!DedicatedServerAssemblyWrapper.ReflectionUnitTest()) { result = false; BaseLog.Warn("DedicatedServerAssemblyWrapper reflection validation failed!"); } if (!ServerNetworkManager.ReflectionUnitTest()) { result = false; BaseLog.Warn("ServerNetworkManager reflection validation failed!"); } if (!UtilityFunctions.ReflectionUnitTest()) { result = false; BaseLog.Warn("UtilityFunctions reflection validation failed!"); } if (!ChatManager.ReflectionUnitTest()) { result = false; BaseLog.Warn("ChatManager reflection validation failed!"); } if (!PlayerMap.ReflectionUnitTest()) { result = false; BaseLog.Warn("PlayerMap reflection validation failed!"); } if (!PlayerManager.ReflectionUnitTest()) { result = false; BaseLog.Warn("PlayerManager reflection validation failed!"); } if (!WorldManager.ReflectionUnitTest()) { result = false; BaseLog.Warn("WorldManager reflection validation failed!"); } /* * if (!RadioManager.ReflectionUnitTest()) * { * result = false; * BaseLog.Warn( "RadioManager reflection validation failed!" ); * } * * if (!RadioManagerNetworkManager.ReflectionUnitTest()) * { * result = false; * BaseLog.Warn( "RadioManagerNetworkManager reflection validation failed!" ); * } * * if (!FactionsManager.ReflectionUnitTest()) * { * result = false; * BaseLog.Warn( "FactionsManager reflection validation failed!" ); * } * * if (!Faction.ReflectionUnitTest()) * { * result = false; * BaseLog.Warn( "Faction reflection validation failed!" ); * } */ if (!GameEntityManager.ReflectionUnitTest()) { result = false; BaseLog.Warn("GameEntityManager reflection validation failed!"); } if (result) { BaseLog.Info("All main types passed reflection unit tests!"); } return(result); }