private bool ValidateClientInput(ICommonSession?session, EntityCoordinates coords, EntityUid uid, [NotNullWhen(true)] out EntityUid?userEntity) { userEntity = null; if (!coords.IsValid(_entityManager)) { Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}"); return(false); } if (uid.IsClientSide()) { Logger.WarningS("system.interaction", $"Client sent interaction with client-side entity. Session={session}, Uid={uid}"); return(false); } userEntity = ((IPlayerSession?)session)?.AttachedEntity; if (userEntity == null || !EntityManager.EntityExists(userEntity.Value)) { Logger.WarningS("system.interaction", $"Client sent interaction with no attached entity. Session={session}"); return(false); } return(true); }
private bool HandleWideAttack(ICommonSession session, EntityCoordinates coords, EntityUid uid) { // client sanitization if (!coords.IsValid(_entityManager)) { Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}"); return(true); } if (uid.IsClientSide()) { Logger.WarningS("system.interaction", $"Client sent attack with client-side entity. Session={session}, Uid={uid}"); return(true); } var userEntity = ((IPlayerSession)session).AttachedEntity; if (userEntity == null || !userEntity.IsValid()) { return(true); } if (userEntity.TryGetComponent(out CombatModeComponent combatMode) && combatMode.IsInCombatMode) { DoAttack(userEntity, coords, true); } return(true); }
public void IsValid_InvalidEntId_False() { var entityManager = IoCManager.Resolve <IEntityManager>(); // Same as EntityCoordinates.Invalid var coords = new EntityCoordinates(EntityUid.Invalid, Vector2.Zero); Assert.That(coords.IsValid(entityManager), Is.False); }
public IEnumerable <EntityUid> AutoHarvest(SeedData proto, EntityCoordinates position, int yieldMod = 1) { if (position.IsValid(EntityManager) && proto.ProductPrototypes.Count > 0) { return(GenerateProduct(proto, position, yieldMod)); } return(Enumerable.Empty <EntityUid>()); }
public IEnumerable <IEntity> AutoHarvest(EntityCoordinates position, int yieldMod = 1) { if (position.IsValid(IoCManager.Resolve <IEntityManager>()) && ProductPrototypes != null && ProductPrototypes.Count > 0) { return(GenerateProduct(position, yieldMod)); } return(Enumerable.Empty <IEntity>()); }
public static void AnimateEntityPickup(EntityUid entity, EntityCoordinates initialPosition, Vector2 finalPosition, IEntityManager?entMan = null) { IoCManager.Resolve(ref entMan); if (entMan.Deleted(entity) || !initialPosition.IsValid(entMan)) { return; } var animatableClone = entMan.SpawnEntity("clientsideclone", initialPosition); string val = entMan.GetComponent <MetaDataComponent>(entity).EntityName; entMan.GetComponent <MetaDataComponent>(animatableClone).EntityName = val; if (!entMan.TryGetComponent(entity, out SpriteComponent? sprite0)) { Logger.Error("Entity ({0}) couldn't be animated for pickup since it doesn't have a {1}!", entMan.GetComponent <MetaDataComponent>(entity).EntityName, nameof(SpriteComponent)); return; } var sprite = entMan.GetComponent <SpriteComponent>(animatableClone); sprite.CopyFrom(sprite0); sprite.Visible = true; var animations = entMan.GetComponent <AnimationPlayerComponent>(animatableClone); animations.AnimationCompleted += (_) => { entMan.DeleteEntity(animatableClone); }; animations.Play(new Animation { Length = TimeSpan.FromMilliseconds(125), AnimationTracks = { new AnimationTrackComponentProperty { ComponentType = typeof(TransformComponent), Property = nameof(TransformComponent.LocalPosition), InterpolationMode = AnimationInterpolationMode.Linear, KeyFrames = { new AnimationTrackProperty.KeyFrame(initialPosition.Position, 0), new AnimationTrackProperty.KeyFrame(finalPosition, 0.125f) } } } }, "fancy_pickup_anim"); }
private bool TryFindRandomGrid(IMapGrid mapGrid, out EntityCoordinates coordinates) { if (!mapGrid.Index.IsValid()) { coordinates = default; return(false); } var randomX = _robustRandom.Next((int)mapGrid.WorldBounds.Left, (int)mapGrid.WorldBounds.Right); var randomY = _robustRandom.Next((int)mapGrid.WorldBounds.Bottom, (int)mapGrid.WorldBounds.Top); coordinates = mapGrid.ToCoordinates(randomX, randomY); // TODO: Need to get valid tiles? (maybe just move right if the tile we chose is invalid?) if (!coordinates.IsValid(_entityManager)) { coordinates = default; return(false); } return(true); }
public static TileRef?GetTileRef(this EntityCoordinates coordinates, IEntityManager?entityManager = null, IMapManager?mapManager = null) { entityManager ??= IoCManager.Resolve <IEntityManager>(); if (!coordinates.IsValid(entityManager)) { return(null); } mapManager ??= IoCManager.Resolve <IMapManager>(); if (!mapManager.TryGetGrid(coordinates.GetGridId(entityManager), out var grid)) { return(null); } if (!grid.TryGetTileRef(coordinates, out var tile)) { return(null); } return(tile); }