//Note: timerPhaseAngle is expected to be in the interval [0, 1]
        private void createPlayerGun(IEntityManager entityStore, Entity player, Entity bullet, float offsetProportion, float timerPhaseAngle)
        {
            //compute the gun's offset from the player, then create the gun
            AABBComponent bulletBox = (AABBComponent)bullet.components[typeof(AABBComponent)];
            AABBComponent playerBox = (AABBComponent)player.components[typeof(AABBComponent)];
            Entity gun = createPositionSlavedEntity(player, new Vector2(playerBox.Width + 0.1f, playerBox.Height * offsetProportion - bulletBox.Height / 2.0f));

            //The gun now has a position coupled to that of the player
            //So spawn bullets at the gun!
            SpawnEntityComponent spawner = new SpawnEntityComponent();
            spawner.Factory = new ComposedEntityFactory(new List<IEntityFactory>() {
                new CloneEntityFactory(bullet),
                new InheritParentComponentEntityFactory(typeof(PositionComponent)) });

            //Bullets should be spawned periodically
            PeriodicAddComponentComponent timer = new PeriodicAddComponentComponent();
            timer.Period = 200.0f;
            timer.TimeSinceLastFiring = timer.Period * timerPhaseAngle;
            timer.ComponentToAdd = spawner;
            gun.AddComponent(timer);

            //The gun should be removed from the world when the player dies
            DestroyedOnParentDestroyedComponent existentialDependency = new DestroyedOnParentDestroyedComponent();
            existentialDependency.parent = player;
            gun.AddComponent(existentialDependency);

            //finally, add the gun to the world
            entityStore.Add(gun);
        }
Beispiel #2
0
 public void Update(IMobEntity entity, IEntityManager manager)
 {
     var cast = entity as IEntity;
     if (entity.CurrentPath != null)
         entity.AdvancePath(manager.TimeSinceLastUpdate);
     else
     {
         if (MathHelper.Random.Next(IdleChance) == 0)
         {
             var target = new Coordinates3D(
                 (int)(cast.Position.X + (MathHelper.Random.Next(Distance) - Distance / 2)),
                 0,
                 (int)(cast.Position.Z + (MathHelper.Random.Next(Distance) - Distance / 2))
             );
             IChunk chunk;
             var adjusted = entity.World.FindBlockPosition(target, out chunk, generate: false);
             target.Y = chunk.GetHeight((byte)adjusted.X, (byte)adjusted.Z) + 1;
             Task.Factory.StartNew(() =>
             {
                     entity.CurrentPath = PathFinder.FindPath(entity.World, entity.BoundingBox,
                         (Coordinates3D)cast.Position, target);
             });
         }
     }
 }
        private void initializeBackground(IEntityManager entityStore, Game game)
        {
            //Add purpleness to the background
            initializePurpleBackground(entityStore, game);

            //Add stars at varying 'depths'
            initializeBackgroundStars(entityStore, game);
        }
Beispiel #4
0
 public ListGenerator(IEntityManager entityManager, IConfiguration configuration, ITemplateEngine templateEngine, IProjectFileManager projectFileManager, IFileSystem fileSystem)
     : base(command, description)
 {
     this.entityManager = entityManager;
     this.configuration = configuration;
     this.templateEngine = templateEngine;
     this.projectFileManager = projectFileManager;
     this.fileSystem = fileSystem;
 }
Beispiel #5
0
 public FormGenerator(IEntityManager entityManager, IConfiguration configuration, ITemplateEngine templateEngine, IProjectFileManager projectFileManager, IFileSystem fileSystem, IAutoMapperHelper autoMapperHelper)
     : base(command, description)
 {
     this.entityManager = entityManager;
     this.configuration = configuration;
     this.templateEngine = templateEngine;
     this.projectFileManager = projectFileManager;
     this.fileSystem = fileSystem;
     this.autoMapperHelper = autoMapperHelper;
 }
        public void InitializeScene(IEntityManager entityStore, Game game)
        {
            Entity musicEntity = new Entity();

            MusicComponent music = new MusicComponent();
            music.music = game.Content.Load<Song>("sound/gameMusic");
            music.repeat = true;
            musicEntity.AddComponent(music);

            entityStore.Add(musicEntity);
        }
Beispiel #7
0
        public void SetUp()
        {
            entityManagerMock = MockRepository.GenerateMock<IEntityManager>();
            configurationMock = MockRepository.GenerateMock<IConfiguration>();
            projectFileManagerMock = MockRepository.GenerateMock<IProjectFileManager>();
            fileSystemMock = MockRepository.GenerateMock<IFileSystem>();

            templateEngine = new TemplateEngine(fileSystemMock);

            listGenerator = new ListGenerator(entityManagerMock, configurationMock, templateEngine, projectFileManagerMock, fileSystemMock);
        }
Beispiel #8
0
        public void SetUp()
        {
            configurationMock = MockRepository.GenerateMock<IConfiguration>();
            projectFileManagerMock = MockRepository.GenerateMock<IProjectFileManager>();
            depencyInjectionManagerMock = MockRepository.GenerateMock<IDepencyInjectionManager>();
            fileSystemMock = MockRepository.GenerateMock<IFileSystem>();
            entityManagerMock = MockRepository.GenerateMock<IEntityManager>();
            autoMapperHelperMock = MockRepository.GenerateMock<IAutoMapperHelper>();

            var templateEngine = new TemplateEngine(fileSystemMock);
            uiGenerator = new UiGenerator(entityManagerMock, templateEngine, configurationMock, projectFileManagerMock, depencyInjectionManagerMock, autoMapperHelperMock, fileSystemMock);
        }
        public void SetUp()
        {
            entityManagerMock = MockRepository.GenerateMock<IEntityManager>();
            configurationMock = MockRepository.GenerateMock<IConfiguration>();
            projectFileManagerMock = MockRepository.GenerateMock<IProjectFileManager>();
            depencyInjectionManagerMock = MockRepository.GenerateMock<IDepencyInjectionManager>();
            fileSystemMock = MockRepository.GenerateMock<IFileSystem>();

            templateEngineMock = new TemplateEngine(fileSystemMock);

            repositoryGenerator = new RepositoryGenerator(entityManagerMock, templateEngineMock, configurationMock, projectFileManagerMock, depencyInjectionManagerMock);
        }
Beispiel #10
0
 public RepositoryGenerator(IEntityManager entityManager, 
     ITemplateEngine templateEngine, 
     IConfiguration configuration,
     IProjectFileManager projectFileManager,
     IDepencyInjectionManager depencyInjectionManager)
     : base(command, description)
 {
     this.entityManager = entityManager;
     this.templateEngine = templateEngine;
     this.configuration = configuration;
     this.projectFileManager = projectFileManager;
     this.depencyInjectionManager = depencyInjectionManager;
 }
        private void generateStar(IEntityManager entityStore, Game game, Texture2D bigStarTex, Texture2D littleStarTex, Frustum generationVolume, double speedAtUnitDepth, double screenDepth, double screenWidth, double screenHeight)
        {
            //sample a 3d location for the star
            Vector3 starLoc = generationVolume.samplePoint(rand);

            //determine the speed as a function of the depth
            double speed = speedAtUnitDepth / starLoc.Z * screenDepth * screenDepth;

            //determine the depth/speed of the star

            Entity star = new Entity();

            //Component: Has a position, determined by starLoc
            PositionComponent pos = new PositionComponent();
            Vector3 starLoc2 = generationVolume.TransformFromEuclideanSpaceToPseudoSphericalSpace(starLoc);
            pos.Position = new Vector2(starLoc2.X * game.GraphicsDevice.Viewport.Width, starLoc2.Y * game.GraphicsDevice.Viewport.Height);
            star.AddComponent(pos);

            //Component: Moves at a constant speed
            LinearMovementComponent movementStrat = new LinearMovementComponent();
            star.AddComponent(movementStrat);

            //Component: Has a move speed
            MoveSpeedComponent speedComponent = new MoveSpeedComponent();
            speedComponent.MoveSpeed = (float)speed;
            star.AddComponent(speedComponent);

            //Component: Wraps around the screen
            ScreenWrappingComponent wrapper = new ScreenWrappingComponent();
            star.AddComponent(wrapper);

            //Component: Has a texture.  This should be little star for far away/slow stars, big otherwise
            TextureComponent tex = new TextureComponent();
            tex.Texture = (speed > -2.5) ? littleStarTex : bigStarTex;
            tex.SourceRect = tex.Texture.Bounds;
            star.AddComponent(tex);

            //Component: Has a bounding box
            AABBComponent aabb = new AABBComponent();
            aabb.Width = tex.Texture.Width;
            aabb.Height = tex.Texture.Height;
            star.AddComponent(aabb);

            //Component: Is rendered at a specific layer (just above the background)
            RenderLayerComponent layer = new RenderLayerComponent();
            layer.LayerID = 1;
            star.AddComponent(layer);

            entityStore.Add(star);
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerInfoRepository"/> class.
 /// </summary>
 public ServerInfoRepository()
 {
     try
     {
         _dataSource = GetDataSource("LOCAL");
         _em = new EntityManager(_dataSource);
     }
     catch (NullReferenceException ex)
     {
         throw new Exception(string.Format("Unable to find Database Connection configuration files!\r\n{0}",
                                           ex.Message));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex);
     }
 }
Beispiel #13
0
 public static IAiState GetDeadState(this IEntityManager manager, IRegularMob mob)
 {
     return(manager.Create(new AiStateFactoryHelper(), "dead", mob).CastAs <IAiState>());
 }
Beispiel #14
0
 public virtual void UpdateState(EntityUid entity, FixedPoint2 threshold, IEntityManager entityManager)
 {
 }
            public CharacterPickerButton(
                IEntityManager entityManager,
                IClientPreferencesManager preferencesManager,
                ButtonGroup group,
                ICharacterProfile profile)
            {
                AddStyleClass(StyleClassButton);
                ToggleMode = true;
                Group      = group;

                _previewDummy = entityManager.SpawnEntity("MobHumanDummy", MapCoordinates.Nullspace);
                EntitySystem.Get <SharedHumanoidAppearanceSystem>().UpdateFromProfile(_previewDummy.Uid, profile);
                var humanoid = profile as HumanoidCharacterProfile;

                if (humanoid != null)
                {
                    LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, humanoid);
                }

                var isSelectedCharacter = profile == preferencesManager.Preferences?.SelectedCharacter;

                if (isSelectedCharacter)
                {
                    Pressed = true;
                }

                var view = new SpriteView
                {
                    Sprite            = _previewDummy.GetComponent <SpriteComponent>(),
                    Scale             = (2, 2),
                    OverrideDirection = Direction.South
                };

                var description = profile.Name;

                var highPriorityJob = humanoid?.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key;

                if (highPriorityJob != null)
                {
                    var jobName = IoCManager.Resolve <IPrototypeManager>().Index <JobPrototype>(highPriorityJob).Name;
                    description = $"{description}\n{jobName}";
                }

                var descriptionLabel = new Label
                {
                    Text             = description,
                    ClipText         = true,
                    HorizontalExpand = true
                };
                var deleteButton = new Button
                {
                    Text    = Loc.GetString("character-setup-gui-character-picker-button-delete-button"),
                    Visible = !isSelectedCharacter,
                };

                deleteButton.OnPressed += _ =>
                {
                    Parent?.RemoveChild(this);
                    preferencesManager.DeleteCharacter(profile);
                };

                var internalHBox = new BoxContainer
                {
                    Orientation        = LayoutOrientation.Horizontal,
                    HorizontalExpand   = true,
                    SeparationOverride = 0,
                    Children           =
                    {
                        view,
                        descriptionLabel,
                        deleteButton
                    }
                };

                AddChild(internalHBox);
            }
Beispiel #16
0
        public LobbyGui(IEntityManager entityManager,
                        IResourceCache resourceCache,
                        IClientPreferencesManager preferencesManager)
        {
            var margin = new MarginContainer
            {
                MarginBottomOverride = 20,
                MarginLeftOverride   = 20,
                MarginRightOverride  = 20,
                MarginTopOverride    = 20,
            };

            AddChild(margin);

            var panelTex = resourceCache.GetTexture("/Nano/button.svg.96dpi.png");
            var back     = new StyleBoxTexture
            {
                Texture  = panelTex,
                Modulate = new Color(37, 37, 42),
            };

            back.SetPatchMargin(StyleBox.Margin.All, 10);

            var panel = new PanelContainer
            {
                PanelOverride = back
            };

            margin.AddChild(panel);

            var vBox = new VBoxContainer {
                SeparationOverride = 0
            };

            margin.AddChild(vBox);

            var topHBox = new HBoxContainer
            {
                CustomMinimumSize = (0, 40),
                Children          =
                {
                    new MarginContainer
                    {
                        MarginLeftOverride = 8,
                        Children           =
                        {
                            new Label
                            {
                                Text         = Loc.GetString("Lobby"),
                                StyleClasses ={ StyleNano.StyleClassLabelHeadingBigger                    },

                                /*MarginBottom = 40,
                                 * MarginLeft = 8,*/
                                VAlign = Label.VAlignMode.Center
                            }
                        }
                    },
                    (ServerName = new Label
                    {
                        StyleClasses ={ StyleNano.StyleClassLabelHeadingBigger                    },

                        /*MarginBottom = 40,
                         * GrowHorizontal = GrowDirection.Both,*/
                        VAlign = Label.VAlignMode.Center,
                        SizeFlagsHorizontal = SizeFlags.Expand | SizeFlags.ShrinkCenter
                    }),
                    (CreditsButton = new Button
                    {
                        SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
                        Text = Loc.GetString("Credits"),
                        StyleClasses ={ StyleNano.StyleClassButtonBig                             },
                        //GrowHorizontal = GrowDirection.Begin
                    }),
                    (LeaveButton = new Button
                    {
                        SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
                        Text = Loc.GetString("Leave"),
                        StyleClasses ={ StyleNano.StyleClassButtonBig                             },
                        //GrowHorizontal = GrowDirection.Begin
                    })
                }
            };

            vBox.AddChild(topHBox);

            vBox.AddChild(new PanelContainer
            {
                PanelOverride = new StyleBoxFlat
                {
                    BackgroundColor          = StyleNano.NanoGold,
                    ContentMarginTopOverride = 2
                },
            });

            var hBox = new HBoxContainer
            {
                SizeFlagsVertical  = SizeFlags.FillExpand,
                SeparationOverride = 0
            };

            vBox.AddChild(hBox);

            CharacterPreview = new LobbyCharacterPreviewPanel(
                entityManager,
                preferencesManager)
            {
                SizeFlagsHorizontal = SizeFlags.None
            };
            hBox.AddChild(new VBoxContainer
            {
                SizeFlagsHorizontal = SizeFlags.FillExpand,
                SeparationOverride  = 0,
                Children            =
                {
                    CharacterPreview,

                    new StripeBack
                    {
                        Children =
                        {
                            new MarginContainer
                            {
                                MarginRightOverride  = 3,
                                MarginLeftOverride   = 3,
                                MarginTopOverride    = 3,
                                MarginBottomOverride = 3,
                                Children             =
                                {
                                    new HBoxContainer
                                    {
                                        SeparationOverride = 6,
                                        Children           =
                                        {
                                            (ObserveButton          = new Button
                                            {
                                                Text                = Loc.GetString("Observe"),
                                                StyleClasses        = { StyleNano.StyleClassButtonBig }
                                            }),
                                            (StartTime              = new Label
                                            {
                                                SizeFlagsHorizontal = SizeFlags.FillExpand,
                                                Align               = Label.AlignMode.Right,
                                                FontColorOverride   = Color.DarkGray,
                                                StyleClasses        = { StyleNano.StyleClassLabelBig  }
                                            }),
                                            (ReadyButton            = new Button
                                            {
                                                ToggleMode          = true,
                                                Text                = Loc.GetString("Ready Up"),
                                                StyleClasses        = { StyleNano.StyleClassButtonBig }
                                            }),
                                        }
                                    }
                                }
                            }
                        }
                    },

                    new MarginContainer
                    {
                        MarginRightOverride  = 3,
                        MarginLeftOverride   = 3,
                        MarginTopOverride    = 3,
                        MarginBottomOverride = 3,
                        SizeFlagsVertical    = SizeFlags.FillExpand,
                        Children             =
                        {
                            (Chat     = new ChatBox
                            {
                                Input = { PlaceHolder = Loc.GetString("Say something!") }
                            })
                        }
                    },
                }
            });

            hBox.AddChild(new PanelContainer
            {
                PanelOverride = new StyleBoxFlat {
                    BackgroundColor = StyleNano.NanoGold
                }, CustomMinimumSize = (2, 0)
            });
Beispiel #17
0
        public DataSet Evaluer(string strFormule, string id)
        {
            CResultAErreur result = CResultAErreur.True;

            IEntityManager       em = EntityManager.FromDataSet(DataSetHelper.Create());
            ExpressionAnalysable exp;

            if (id != null && id != "")
            {
                exp = em.GetInstance <ExpressionAnalysable>(id);
            }
            else
            {
                exp = em.CreateInstance <ExpressionAnalysable>();
            }
            exp.Formule  = strFormule;
            exp.Resultat = "";

            if (strFormule == "")
            {
                return(em.Data);
            }

            C2iExpression formule;
            string        strResultat            = "";
            Hashtable     tableLastFormuleDuType = new Hashtable();
            int           nLastIndex             = 0;

            // Analyser l'expression
            //Type tp = m_objet.GetType();
            CContexteAnalyse2iExpression   ctx       = new CContexteAnalyse2iExpression(new CFournisseurGeneriqueProprietesDynamiques(), null);
            CAnalyseurSyntaxiqueExpression analyseur = new CAnalyseurSyntaxiqueExpression(ctx);

            try
            {
                result = analyseur.AnalyseChaine(strFormule);
                if (result)
                {
                    formule = (C2iExpression)result.Data;
                }
                else
                {
                    result.EmpileErreur("Erreur dans la formule");
                    exp.Resultat = result.MessageErreur;
                    em.Data.AcceptChanges();
                    return(em.Data);
                }

                // Evaluer l'expression
                if (formule != null)
                {
                    CContexteEvaluationExpression contexte = new CContexteEvaluationExpression(null);
                    result = formule.Eval(contexte);
                    if (!result)
                    {
                        exp.Resultat = result.MessageErreur;
                        em.Data.AcceptChanges();
                        return(em.Data);
                    }
                    if (result.Data == null)
                    {
                        strResultat += "null";
                    }
                    else
                    {
                        strResultat += result.Data.ToString();
                    }

                    exp.Resultat = strResultat;
                    em.Data.AcceptChanges();
                    return(em.Data);
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
            }

            return(em.Data);
        }
Beispiel #18
0
 public void Setup()
 {
     _entityManager = Substitute.For<IEntityManager>();
     _request = Substitute.For<IUsergridRequest>();
     _client = new Client(null, null, request: _request) {EntityManager = _entityManager};
 }
 public EntityManagerTests()
 {
     var channelManager = new ChannelManager();
     _entityManager = new EntityManager(channelManager, new EntityPool());
 }
Beispiel #20
0
 public void TransferEntity(IEntity entity, IEntityManager manager)
 {
     UnregisterEntity(entity);
     manager.RegisterEntity(entity);
     entity.TransferEntity(manager);
 }
Beispiel #21
0
 protected static IEnumerable <string> GetRequiredNavigationPropertyIncludes(IEntityManager entityManager, Type entityType, string ownIncludeString)
 {
     return(entityManager
            .GetRequiredNavigationPropertiesForType(entityType)
            .Select(navigationProperty => ownIncludeString + "." + navigationProperty.Name));
 }
 public BulletFactory(IEntityManager entityManager, TextureRegion2D bulletRegion)
 {
     _entityManager = entityManager;
     _bulletRegion = bulletRegion;
 }
 public HandlingEventEventSubscriber(IEntityManager entityManager)
 {
     _entityManager = entityManager;
 }
 public OrderEventSubscriber(IEntityManager entityManager)
 {
     _entityManager = entityManager;
 }
 public PostEventSubscriber(IEntityManager entityManager)
 {
     _entityManager = entityManager;
 }
 public ForumEventSubscriber(IEntityManager entityManager)
 {
     _entityManager = entityManager;
 }
 public void PerformAction(EntityUid uid, EntityUid?userUid, IEntityManager entityManager)
 {
     entityManager.EntitySysManager.GetEntitySystem <PopupSystem>()
     .PopupEntity(Loc.GetString(Text), uid, Filter.Pvs(uid, entityManager: entityManager));
 }
 public void InitializeScene(IEntityManager entityStore, Game game)
 {
     initializeMinefield(entityStore, game);
 }
Beispiel #29
0
 /// <inheritdoc />
 public IEnumerable <IEntity> Match(IEntityManager entityMan)
 {
     return(entityMan.ComponentManager.GetAllComponents(ComponentType).Select(component => component.Owner));
 }
 public ThreadEventSubscriber(IEntityManager entityManager)
 {
     _entityManager = entityManager;
 }
Beispiel #31
0
 public virtual void RemoveChildEntityManager(IEntityManager entityManager)
 {
     EntityManagers.Remove(entityManager);
 }
 public LibraryAccountEventSubscriber(IEntityManager entityManager)
 {
     _entityManager = entityManager;
 }
Beispiel #33
0
 public IEnumerable <IEntity> Match(IEntityManager entityMan)
 {
     return(entityMan.GetEntities().Where(entity => Match(entity)));
 }
Beispiel #34
0
 public override void Update(IEntityManager entityManager)
 {
     var nearbyEntities = entityManager.EntitiesInRange(Position, PickupRange);
     if ((DateTime.UtcNow - SpawnTime).TotalSeconds > 1)
     {
         var player = nearbyEntities.FirstOrDefault(e => e is PlayerEntity && (e as PlayerEntity).Health != 0
                          && e.Position.DistanceTo(Position) <= PickupRange);
         if (player != null)
         {
             var playerEntity = player as PlayerEntity;
             playerEntity.OnPickUpItem(this);
             entityManager.DespawnEntity(this);
         }
     }
     if ((DateTime.UtcNow - SpawnTime).TotalMinutes > 5)
         entityManager.DespawnEntity(this);
     base.Update(entityManager);
 }
 public HandlingEventEventSubscriber(IEntityManager entityManager)
 {
     _entityManager = entityManager;
 }
Beispiel #36
0
 public override void Update(IEntityManager entityManager)
 {
     if (CurrentState != null)
         CurrentState.Update(this, entityManager);
     else
         AdvancePath(entityManager.TimeSinceLastUpdate);
     base.Update(entityManager);
 }
Beispiel #37
0
 /// <summary>
 /// Sets the entity manager of this system
 /// </summary>
 /// <param name="manager"></param>
 public void SetEntityManager(IEntityManager manager)
 {
     entityManager = manager;
 }
        private bool IsCancelled(IEntityManager entityManager)
        {
            if (!entityManager.EntityExists(EventArgs.User) || EventArgs.Target is {} target&& !entityManager.EntityExists(target))
            {
                return(true);
            }

            //https://github.com/tgstation/tgstation/blob/1aa293ea337283a0191140a878eeba319221e5df/code/__HELPERS/mobs.dm
            if (EventArgs.CancelToken.IsCancellationRequested)
            {
                return(true);
            }

            // TODO :Handle inertia in space.
            if (EventArgs.BreakOnUserMove && !entityManager.GetComponent <TransformComponent>(EventArgs.User).Coordinates.InRange(
                    entityManager, UserGrid, EventArgs.MovementThreshold))
            {
                return(true);
            }

            if (EventArgs.Target != null &&
                EventArgs.BreakOnTargetMove &&
                !entityManager.GetComponent <TransformComponent>(EventArgs.Target !.Value).Coordinates.InRange(entityManager, TargetGrid, EventArgs.MovementThreshold))
            {
                return(true);
            }

            if (EventArgs.ExtraCheck != null && !EventArgs.ExtraCheck.Invoke())
            {
                return(true);
            }

            if (EventArgs.BreakOnStun &&
                entityManager.HasComponent <StunnedComponent>(EventArgs.User))
            {
                return(true);
            }

            if (EventArgs.NeedHand)
            {
                if (!entityManager.TryGetComponent(EventArgs.User, out HandsComponent? handsComponent))
                {
                    // If we had a hand but no longer have it that's still a paddlin'
                    if (_activeHand != null)
                    {
                        return(true);
                    }
                }
                else
                {
                    var currentActiveHand = handsComponent.ActiveHand?.Name;
                    if (_activeHand != currentActiveHand)
                    {
                        return(true);
                    }

                    var currentItem = handsComponent.ActiveHandEntity;
                    if (_activeItem != currentItem)
                    {
                        return(true);
                    }
                }
            }

            if (EventArgs.DistanceThreshold != null)
            {
                var xformQuery = entityManager.GetEntityQuery <TransformComponent>();
                TransformComponent?userXform = null;

                // Check user distance to target AND used entities.
                if (EventArgs.Target != null && !EventArgs.User.Equals(EventArgs.Target))
                {
                    //recalculate Target location in case Target has also moved
                    var targetCoordinates = xformQuery.GetComponent(EventArgs.Target.Value).Coordinates;
                    userXform ??= xformQuery.GetComponent(EventArgs.User);
                    if (!userXform.Coordinates.InRange(entityManager, targetCoordinates, EventArgs.DistanceThreshold.Value))
                    {
                        return(true);
                    }
                }

                if (EventArgs.Used != null)
                {
                    var targetCoordinates = xformQuery.GetComponent(EventArgs.Used.Value).Coordinates;
                    userXform ??= xformQuery.GetComponent(EventArgs.User);
                    if (!userXform.Coordinates.InRange(entityManager, targetCoordinates, EventArgs.DistanceThreshold.Value))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #39
0
 public BulletFactory(IEntityManager entityManager, TextureRegion2D bulletRegion)
 {
     _entityManager = entityManager;
     _bulletRegion  = bulletRegion;
 }
Beispiel #40
0
 public virtual void Update(IEntityManager entityManager)
 {
     // TODO: Losing health and all that jazz
     if (Position.Y < -50)
         entityManager.DespawnEntity(this);
 }
Beispiel #41
0
 public virtual void ExitState(EntityUid uid, IEntityManager entityManager)
 {
 }
Beispiel #42
0
 public MetaEntityRemoteService(IEntityManager entityManager)
 {
     _entityManager = entityManager;
 }
Beispiel #43
0
 // Using this makes the call shorter.
 // ReSharper disable once UnusedParameter.Global
 public static bool IsPowered(this EntitySystem system, EntityUid uid, IEntityManager entManager, ApcPowerReceiverComponent?receiver = null)
 {
     return(entManager.TryGetComponent <ApcPowerReceiverComponent>(uid, out receiver) && receiver.Powered);
 }
    public static void Write(Utf8JsonWriter writer, EntityUid value, JsonSerializerOptions options, IEntityManager entities)
    {
        writer.WriteStartObject();

        writer.WriteNumber("id", (int)value);

        if (entities.TryGetComponent(value, out MetaDataComponent metaData))
        {
            writer.WriteString("name", metaData.EntityName);
        }

        if (entities.TryGetComponent(value, out ActorComponent? actor))
        {
            writer.WriteString("player", actor.PlayerSession.UserId.UserId);
        }

        writer.WriteEndObject();
    }
Beispiel #45
0
        public LobbyCharacterPreviewPanel(IEntityManager entityManager,
                                          IClientPreferencesManager preferencesManager)
        {
            _preferencesManager = preferencesManager;
            _previewDummy       = entityManager.SpawnEntity("HumanMob_Dummy", MapCoordinates.Nullspace);

            var header = new NanoHeading
            {
                Text = Loc.GetString("lobby-character-preview-panel-header")
            };

            CharacterSetupButton = new Button
            {
                Text = Loc.GetString("lobby-character-preview-panel-character-setup-button"),
                HorizontalAlignment = HAlignment.Left
            };

            _summaryLabel = new Label();

            var viewSouth = MakeSpriteView(_previewDummy, Direction.South);
            var viewNorth = MakeSpriteView(_previewDummy, Direction.North);
            var viewWest  = MakeSpriteView(_previewDummy, Direction.West);
            var viewEast  = MakeSpriteView(_previewDummy, Direction.East);

            var vBox = new BoxContainer
            {
                Orientation = LayoutOrientation.Vertical
            };

            vBox.AddChild(header);

            _unloaded = new Label {
                Text = Loc.GetString("lobby-character-preview-panel-unloaded-preferences-label")
            };

            _loaded = new BoxContainer
            {
                Orientation = LayoutOrientation.Vertical,
                Visible     = false
            };

            _loaded.AddChild(CharacterSetupButton);
            _loaded.AddChild(_summaryLabel);

            var hBox = new BoxContainer
            {
                Orientation = LayoutOrientation.Horizontal
            };

            hBox.AddChild(viewSouth);
            hBox.AddChild(viewNorth);
            hBox.AddChild(viewWest);
            hBox.AddChild(viewEast);

            _loaded.AddChild(hBox);

            vBox.AddChild(_loaded);
            vBox.AddChild(_unloaded);
            AddChild(vBox);

            UpdateUI();

            _preferencesManager.OnServerDataLoaded += UpdateUI;
        }
Beispiel #46
0
 public TextSpeechBubble(string text, EntityUid senderEntity, IEyeManager eyeManager, IChatManager chatManager, IEntityManager entityManager, string speechStyleClass)
     : base(text, senderEntity, eyeManager, chatManager, entityManager, speechStyleClass)
 {
 }
Beispiel #47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActionSynchronizer"/> class.
 /// </summary>
 /// <param name="entityManager">The entity manager.</param>
 public ActionSynchronizer(IEntityManager entityManager)
 {
     EntityManager    = entityManager;
     _movableEntities = entityManager.Group <MovableComponent, PositionComponent>();
 }
Beispiel #48
0
        public static SpeechBubble CreateSpeechBubble(SpeechType type, string text, EntityUid senderEntity, IEyeManager eyeManager, IChatManager chatManager, IEntityManager entityManager)
        {
            switch (type)
            {
            case SpeechType.Emote:
                return(new TextSpeechBubble(text, senderEntity, eyeManager, chatManager, entityManager, "emoteBox"));

            case SpeechType.Say:
                return(new TextSpeechBubble(text, senderEntity, eyeManager, chatManager, entityManager, "sayBox"));

            case SpeechType.Whisper:
                return(new TextSpeechBubble(text, senderEntity, eyeManager, chatManager, entityManager, "whisperBox"));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #49
0
 /// <inheritdoc />
 public IEnumerable <IEntity> Match(IEntityManager entityMan)
 {
     return(entityMan.GetEntities(new TypeEntityQuery(ComponentTypes.First())).Where(entity => Match(entity)));
 }
Beispiel #50
0
        public SpeechBubble(string text, EntityUid senderEntity, IEyeManager eyeManager, IChatManager chatManager, IEntityManager entityManager, string speechStyleClass)
        {
            _chatManager   = chatManager;
            _senderEntity  = senderEntity;
            _eyeManager    = eyeManager;
            _entityManager = entityManager;

            // Use text clipping so new messages don't overlap old ones being pushed up.
            RectClipContent = true;

            var bubble = BuildBubble(text, speechStyleClass);

            AddChild(bubble);

            ForceRunStyleUpdate();

            bubble.Measure(Vector2.Infinity);
            ContentSize             = bubble.DesiredSize;
            _verticalOffsetAchieved = -ContentSize.Y;
        }
Beispiel #51
0
 public ModelMapper(IServiceProvider services, IEntityManager entityManager)
 {
     _services      = services;
     _entityManager = entityManager;
 }
Beispiel #52
0
 public void Setup()
 {
     _entityManager = Substitute.For<IEntityManager>();
     _client = new Client(null, null) {EntityManager = _entityManager};
 }
Beispiel #53
0
 public virtual void AddChildEntityManager(IEntityManager entityManager)
 {
     EntityManagers.Add(entityManager);
 }
        //create the player's guns
        private void initializePlayerGuns(IEntityManager entityStore, Game game, Entity player)
        {
            //Generate the shared bullet template
            Entity bullet = createBulletTemplate(game);

            createPlayerGun(entityStore, player, bullet, 0.333f, 0.0f);
            createPlayerGun(entityStore, player, bullet, 0.667f, 0.5f);
        }
Beispiel #55
0
 public MovableSystem(IEntityManager entityManager) : base(entityManager)
 {
 }
 public void InitializeScene(IEntityManager entityStore, Game game)
 {
     initializePlayer(entityStore, game);
 }
Beispiel #57
0
 protected virtual IEnumerable <string> GetRequiredNavigationPropertyIncludes(IEntityManager entityManager)
 {
     return(new string[0]);
 }
 /// <summary>
 /// Constructs a new instance of <see cref="EntityEventBus"/>.
 /// </summary>
 /// <param name="entMan">The entity manager to watch for entity/component events.</param>
 public EntityEventBus(IEntityManager entMan)
 {
     _entMan      = entMan;
     _eventTables = new EventTables(_entMan);
 }
        //Create the player entity and its associated entities
        private void initializePlayer(IEntityManager entityStore, Game game)
        {
            Entity player = new Entity();

            //give the player health
            HealthComponent hp = new HealthComponent();
            hp.Health = 100;
            player.AddComponent(hp);

            //Give the player a position
            PositionComponent pos = new PositionComponent();
            Vector2 playerPosition = new Vector2(game.GraphicsDevice.Viewport.TitleSafeArea.X, game.GraphicsDevice.Viewport.TitleSafeArea.Y + game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
            pos.Position = playerPosition;
            player.AddComponent(pos);

            //And a texture
            TextureComponent tex = new TextureComponent();
            tex.Texture = game.Content.Load<Texture2D>("spaceArt/png/player");
            tex.SourceRect = tex.Texture.Bounds;
            player.AddComponent(tex);

            //And the ability to react to inputs
            PlayerMovementComponent inputManager = new PlayerMovementComponent();
            player.AddComponent(inputManager);

            //And a constant movement speed
            MoveSpeedComponent speed = new MoveSpeedComponent();
            speed.MoveSpeed = 8.0f;
            player.AddComponent(speed);

            //And a bounding box for clamping (and collisions in the future!)
            AABBComponent aabb = new AABBComponent();
            aabb.Width = tex.Texture.Width;
            aabb.Height = tex.Texture.Height;
            player.AddComponent(aabb);

            //And render layer information.  We'll have the player render at level 10 for now.
            RenderLayerComponent layer = new RenderLayerComponent();
            layer.LayerID = 10;
            player.AddComponent(layer);

            //And a component to indicate the the player needs to be clamped to the screen
            ScreenClampedComponent clamper = new ScreenClampedComponent();
            player.AddComponent(clamper);

            //And a component that indicates that the player can be destroyed if it runs out of health
            DestroyedWhenNoHealthComponent destruct = new DestroyedWhenNoHealthComponent();
            player.AddComponent(destruct);

            //And the ability to damage entities on contact with them
            DamageOnContactComponent damager = new DamageOnContactComponent();
            damager.Damage = 10;
            player.AddComponent(damager);

            entityStore.Add(player);

            //also create the player's gun
            initializePlayerGuns(entityStore, game, player);
        }
        private void initializeMinefield(IEntityManager entityStore, Game game)
        {
            //Create a mine-spawning entity that spawns mines in random positions every once in a while
            Entity minespawner = new Entity();

            //Component: Spawn an entity
            SpawnEntityComponent spawnComponent = new SpawnEntityComponent();
            spawnComponent.Factory = createAsteroidFactory(game);

            //Component: Periodically add a spawn entity component
            PeriodicAddComponentComponent timer = new PeriodicAddComponentComponent();
            timer.ComponentToAdd = spawnComponent;
            timer.Period = 500;
            timer.TimeSinceLastFiring = 0.0f;
            minespawner.AddComponent(timer);

            //Add the minefield to the entity store
            entityStore.Add(minespawner);
        }