Exemplo n.º 1
0
        public void Handle(EntityAdded <Case> notification)
        {
            var createdCase = notification.Entity;

            var isOrganizationCase = createdCase.Organization != null;
            var subscriptionName   = isOrganizationCase ? Constants.Subscriptions.OrganizationCaseCreated : Constants.Subscriptions.UserCaseCreated;

            var subscribers = _preferencesQuery.GetSubscriptionPreferenceDetails(subscriptionName);

            foreach (var recipient in subscribers)
            {
                if (recipient.IsEmailRequested)
                {
                    _singleEntityService.Save(new EmailNotification()
                    {
                        ToAddress = recipient.EmailAddress,
                        Content   = $"New case created: {createdCase.Id}",
                        Subject   = $"New case created: {createdCase.Id}"
                    });
                }
                if (recipient.IsSmsRequested)
                {
                    _singleEntityService.Save(new SmsNotification()
                    {
                        ToPhoneNumber = recipient.PhoneNumber,
                        Content       = $"New case created: {createdCase.Id}",
                    });
                }
            }
        }
Exemplo n.º 2
0
        public Guid NewEntity(IEntityLogic logic, Guid controllerSim, float updatePeriod = 100)
        {
            if (Role == InstanceRole.OWNER)
            {
                var id = Guid.NewGuid();

                var entityAdded = new EntityAdded()
                {
                    EntityId        = id,
                    UpdatePeriod    = updatePeriod,
                    CreationInfo    = logic.GetCreationInfo(),
                    InitialSnapshot = logic.TakeSnapshot(),
                    ControllerSimId = controllerSim,
                    AuthoritySimId  = Id
                };
                _addedEntites.Add(entityAdded);

                var entity = CreateLocalEntity(logic, entityAdded);
                AddRemoteEntites(entity, entityAdded);

                return(id);
            }
            else
            {
                throw new Exception("Can only create entities on OWNER instance");
            }
        }
Exemplo n.º 3
0
        public void Add(Entity item, bool isMain)
        {
            Items.Add(item);
            if (item is EntityLiving living)
            {
                // AI を初期化する
                living.MainAi?.OnInit();
                foreach (var ai in living.CollisionAIs)
                {
                    ai.OnInit();
                }
            }

            if (item is EntityVisible visible)
            {
                // IDrawable のマッピングを行う
                drawablesMap[visible] = visible.OnSpawn();
                visible.OnUpdate(visible.Location, drawablesMap[visible]);
            }

            if (isMain)
            {
                MainEntity = item;
            }

            EntityAdded?.Invoke(this, item);
        }
Exemplo n.º 4
0
        public override void Update(GameTime gameTime)
        {
            foreach (var entityId in _addedEntities)
            {
                _entityToComponentBits[entityId] = _componentManager.CreateComponentBits(entityId);
                ActiveCount++;
                EntityAdded?.Invoke(entityId);
            }

            foreach (var entityId in _changedEntities)
            {
                _entityToComponentBits[entityId] = _componentManager.CreateComponentBits(entityId);
                EntityChanged?.Invoke(entityId);
            }

            foreach (var entityId in _removedEntities)
            {
                // we must notify subscribers before removing it from the pool
                // otherwise an entity system could still be using the entity when the same id is obtained.
                EntityRemoved?.Invoke(entityId);

                var entity = _entityBag[entityId];
                _entityBag[entityId] = null;
                _componentManager.Destroy(entityId);
                _entityToComponentBits[entityId] = default(BitVector32);
                ActiveCount--;
                _entityPool.Free(entity);
            }

            _addedEntities.Clear();
            _removedEntities.Clear();
            _changedEntities.Clear();
        }
Exemplo n.º 5
0
        private void ProcessEntityAdded(EntityAdded added)
        {
            var logic  = _interface.CreateEntity(this, added.CreationInfo);
            var entity = CreateLocalEntity(logic, added);

            AddRemoteEntites(entity, added);
        }
Exemplo n.º 6
0
        private LocalEntity CreateLocalEntity(IEntityLogic logic, EntityAdded added)
        {
            var entity = new LocalEntity(added.EntityId, logic, this, GetRoleForSim(Id, added), added.UpdatePeriod);

            _entities[entity.Id] = entity;
            logic.ApplySnapshot(added.InitialSnapshot);
            return(entity);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Adds a component to the entity with the given ID. Note that an entity can only hold one unique component of every component type. Notifies all systems that the entity has changed.
 /// </summary>
 /// <param name="entityId">The ID of the entity to add the component to.</param>
 /// <param name="component">The component to add to the entity.</param>
 public void AddComponent(uint entityId, IComponent component)
 {
     entityTable[componentIndices[component.GetType()], entityId] = component;
     if (entityInWorld[entityId])
     {
         EntityAdded?.Invoke(this, new EntityEventArgs(entityId, GetEntityBitmask(entityId)));
     }
 }
Exemplo n.º 8
0
        public void RefreshState()
        {
            if (gameController.Area.CurrentArea == null /*|| !EntitiesStack.CanRead */ || entityCollectSettingsContainer.NeedUpdate || !Player.IsValid)
            {
                return;
            }
            //   var entities = EntitiesStack.Read();
            while (Simple.Count > 0)
            {
                var entity = Simple.Pop();
                if (entity == null)
                {
                    DebugWindow.LogError($"{nameof(EntityListWrapper)}.{nameof(RefreshState)} entity is null. (Very strange).");
                    continue;
                }

                var entityId = entity.Id;
                if (entityCache.TryGetValue(entityId, out _))
                {
                    continue;
                }
                if (entityId >= Int32.MaxValue && !_settings.ParseServerEntities)
                {
                    continue;
                }

                if (/*!entity.IsValid ||*/ entity.Type == EntityType.Error)
                {
                    continue;
                }

                /*if (entity.Type == EntityType.Monster && (entity.GetComponent<Life>() == null ||
                 *                                        entity.GetComponent<ObjectMagicProperties>() == null))
                 * {
                 *  entity.IsValid = false;
                 *  continue;
                 * }*/

                if (entity.League == LeagueType.Legion)
                {
                    if (entity.Stats == null)
                    {
                        continue;
                    }
                }

                EntityAddedAny?.Invoke(entity);
                if ((int)entity.Type >= 100)
                {
                    EntityAdded?.Invoke(entity);
                }

                entityCache[entityId] = entity;
            }

            UpdateEntityCollections();
            entityCollectSettingsContainer.NeedUpdate = true;
        }
Exemplo n.º 9
0
        public void Add(IEntity entity)
        {
            Entities[entity.ID] = entity;

            entity.ComponentAdded   += ComponentAdded;
            entity.ComponentRemoved += ComponentRemoved;

            EntityAdded?.Invoke(this, new EntityChangedEventArgs(entity));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Raises the Entity Added event
        /// </summary>
        /// <param name="args">The event args</param>
        protected void OnEntityAdded(CacheObjectEventArgs args)
        {
            var handler = EntityAdded;

            if (handler != null)
            {
                EntityAdded.Invoke(this, args);
            }
        }
Exemplo n.º 11
0
        public EntityTest(
            EntityId id,
            string name,
            Guid correlationId)
        {
            var @event = new EntityAdded(correlationId, id, name);

            ApplyEvent(@event);
        }
Exemplo n.º 12
0
        public bool AddEntity(Character character)
        {
            var success = Entities.TryAdd(character.Id, character);

            if (success)
            {
                EntityAdded?.Invoke(this, new CharacterArgs(character));
            }
            return(success);
        }
Exemplo n.º 13
0
        public bool AddEntity(Character entity)
        {
            var success = Entities.TryAdd(entity.Id, entity);

            if (success)
            {
                EntityAdded?.Invoke(this, new CharacterArgs(entity));
            }
            return(success);
        }
Exemplo n.º 14
0
        public Model()
        {
            _graph = new ModelGraph();

            _graph.VertexAdded   += i => EntityAdded?.Invoke(i);
            _graph.VertexRemoved += i => EntityRemoved?.Invoke(i);
            _graph.EdgeAdded     += i => RelationshipAdded?.Invoke(i);
            _graph.EdgeRemoved   += i => RelationshipRemoved?.Invoke(i);
            _graph.Cleared       += (i, j) => ModelCleared?.Invoke();
        }
Exemplo n.º 15
0
        public void RefreshState()
        {
            UpdatePlayer();
            if (player.IsAlive && player.IsValid && player.HasComponent <Poe.Components.Stats>())
            {
                UpdatePlayerStats();
            }

            if (gameController.Area.CurrentArea == null)
            {
                return;
            }

            Dictionary <uint, Entity> newEntities = gameController.Game.IngameState.Data.EntityList.EntitiesAsDictionary;
            var newCache = new Dictionary <uint, EntityWrapper>();

            foreach (var keyEntity in newEntities)
            {
                if (!keyEntity.Value.IsValid)
                {
                    continue;
                }

                var    entityID         = keyEntity.Key;
                string uniqueEntityName = keyEntity.Value.Path + entityID;

                if (ignoredEntities.Contains(uniqueEntityName))
                {
                    continue;
                }

                if (entityCache.ContainsKey(entityID) && entityCache[entityID].IsValid)
                {
                    newCache.Add(entityID, entityCache[entityID]);
                    entityCache[entityID].IsInList = true;
                    entityCache.Remove(entityID);
                    continue;
                }

                var entity = new EntityWrapper(gameController, keyEntity.Value);

                EntityAddedAny(entity);
                if (entity.Path.StartsWith("Metadata/Effects") || ((entityID & 0x80000000L) != 0L) ||
                    entity.Path.StartsWith("Metadata/Monsters/Daemon"))
                {
                    ignoredEntities.Add(uniqueEntityName);
                    continue;
                }

                EntityAdded?.Invoke(entity);
                newCache.Add(entityID, entity);
            }
            RemoveOldEntitiesFromCache();
            entityCache = newCache;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Add entity to collection
        /// </summary>
        /// <param name="entity">document to add</param>
        /// <param name="token">cancellation token async support</param>
        /// <returns></returns>
        public virtual async Task Add(T entity, CancellationToken token = default(CancellationToken))
        {
            await Collection.InsertOneAsync(entity, new InsertOneOptions()
            {
                BypassDocumentValidation = true
            }, token);

            EntityAdded?.Invoke(this, new EntityEventArgs <T, TKey> {
                Entity = entity
            });
        }
Exemplo n.º 17
0
 /// <summary>
 /// Adds a entity to the scene.
 /// </summary>
 /// <param name="entity">The entity.</param>
 public void Add(Entity entity)
 {
     if (entity == null)
     {
         return;
     }
     entity.Scene = scene;
     entities.Add(entity.Id, entity);
     entity.Initialize();
     EntityAdded?.Invoke(this, new EntityEventArgs(entity));
 }
Exemplo n.º 18
0
        public void RefreshState()
        {
            if (gameController.Area.CurrentArea == null)
            {
                return;
            }
            if (entityCollectSettingsContainer.NeedUpdate)
            {
                return;
            }
            if (Player == null || !Player.IsValid)
            {
                return;
            }

            while (Simple.Count > 0)
            {
                var entity = Simple.Pop();

                if (entity == null)
                {
                    DebugWindow.LogError($"{nameof(EntityListWrapper)}.{nameof(RefreshState)} entity is null. (Very strange).");
                    continue;
                }

                var entityId = entity.Id;
                if (entityCache.TryGetValue(entityId, out _))
                {
                    continue;
                }

                if (entityId >= int.MaxValue && !_settings.ParseServerEntities)
                {
                    continue;
                }

                if (entity.Type == EntityType.Error)
                {
                    continue;
                }

                EntityAddedAny?.Invoke(entity);
                if ((int)entity.Type >= 100)
                {
                    EntityAdded?.Invoke(entity);
                }

                entityCache[entityId] = entity;
            }

            UpdateEntityCollections();
            entityCollectSettingsContainer.NeedUpdate = true;
        }
Exemplo n.º 19
0
        public void RefreshState()
        {
            int address = gameController.Game.IngameState.Data.LocalPlayer.Address;

            if ((Player == null) || (Player.Address != address))
            {
                Player = new EntityWrapper(gameController, address);
            }
            if (gameController.Area.CurrentArea == null)
            {
                return;
            }

            Dictionary <int, Entity> newEntities = gameController.Game.IngameState.Data.EntityList.EntitiesAsDictionary;
            var newCache = new Dictionary <int, EntityWrapper>();

            foreach (var keyEntity in newEntities)
            {
                if (!keyEntity.Value.IsValid)
                {
                    continue;
                }

                int    entityAddress    = keyEntity.Key;
                string uniqueEntityName = keyEntity.Value.Path + entityAddress;

                if (ignoredEntities.Contains(uniqueEntityName))
                {
                    continue;
                }

                if (entityCache.ContainsKey(entityAddress) && entityCache[entityAddress].IsValid)
                {
                    newCache.Add(entityAddress, entityCache[entityAddress]);
                    entityCache[entityAddress].IsInList = true;
                    entityCache.Remove(entityAddress);
                    continue;
                }

                var entity = new EntityWrapper(gameController, keyEntity.Value);
                if ((entity.Path.StartsWith("Metadata/Effects") || ((entityAddress & 0x80000000L) != 0L)) || entity.Path.StartsWith("Metadata/Monsters/Daemon"))
                {
                    ignoredEntities.Add(uniqueEntityName);
                    continue;
                }
                EntityAdded?.Invoke(entity);
                newCache.Add(entityAddress, entity);
            }
            RemoveOldEntitiesFromCache();
            entityCache = newCache;
        }
Exemplo n.º 20
0
        public void AddToMap(Coordinate coordinate, Entity entity)
        {
            MapTile mapTile = m_CoordinateToMapTile[coordinate];

            mapTile.entities.Add(entity);

            m_EntityIdToCoordinate[entity.Id] = coordinate;

            entity.EntityKilled += RemoveFromMap;

            EntityAdded?.Invoke(this, new EntityArgs()
            {
                entity     = entity,
                coordinate = coordinate
            });
        }
Exemplo n.º 21
0
 private void AddRemoteEntites(LocalEntity entity, EntityAdded added)
 {
     if (Role == InstanceRole.OWNER)
     {
         foreach (var client in _clientSims)
         {
             var remote = new RemoteEntity(entity.Id, GetRoleForSim(client.Id, added), client);
             entity.NetworkEntityAdded(remote);
         }
     }
     else
     {
         var remote = new RemoteEntity(entity.Id, GetRoleForSim(_ownerSim.Id, added), _ownerSim);
         entity.NetworkEntityAdded(remote);
     }
 }
Exemplo n.º 22
0
        private void PostSaveChanges()
        {
            foreach (var databaseEntityAddedEventArgs in addedEntites)
            {
                EntityAdded?.Invoke(this, databaseEntityAddedEventArgs);
            }

            foreach (var databaseEntityModifiedEventArgs in modifiedEntites)
            {
                EntityModified?.Invoke(this, databaseEntityModifiedEventArgs);
            }

            foreach (var databaseEntityRemovedEventArgs in removedEntites)
            {
                EntityRemoved?.Invoke(this, databaseEntityRemovedEventArgs);
            }

            addedEntites.Clear();
            modifiedEntites.Clear();
            removedEntites.Clear();
        }
Exemplo n.º 23
0
        private EntityRole GetRoleForSim(Guid simId, EntityAdded added)
        {
            var role = EntityRole.EMPTY;

            if (simId == added.ControllerSimId)
            {
                role |= EntityRole.CONTROLLER;
            }

            if (simId == added.AuthoritySimId)
            {
                role |= EntityRole.AUTHORITY;
            }

            if (!(simId == added.ControllerSimId || simId == added.AuthoritySimId))
            {
                role |= EntityRole.OBSERVER;
            }

            return(role);
        }
Exemplo n.º 24
0
        public override void Update(GameTime gameTime)
        {
            foreach (var entity in _addedEntities)
            {
                _entities[entity.Id] = entity;
                entity.Initialize(_world);
                ActiveCount++;
                EntityAdded?.Invoke(entity);
            }

            foreach (var entity in _removedEntities)
            {
                if (_entities.ContainsKey(entity.Id))
                {
                    _entities[entity.Id] = null;
                    _entities.Remove(entity.Id);
                    ActiveCount--;
                    EntityRemoved?.Invoke(entity);
                }
            }

            _addedEntities.Clear();
            _removedEntities.Clear();

            foreach (var entity in _entities)
            {
                if (!entity.Value.IsExpired)
                {
                    entity.Value.Update(gameTime);
                }
                else
                {
                    _removedEntities.Add(entity.Value);
                }
            }
        }
Exemplo n.º 25
0
 private void OnEntityAdded(Entity entity)
 {
     EntityAdded?.Invoke(entity);
 }
Exemplo n.º 26
0
 protected virtual void OnEntityAdded(Entity e)
 {
     EntityAdded?.Invoke(this, e);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Adds a child entity to this container
 /// </summary>
 /// <param name="child"></param>
 internal void AddChild(Entity child)
 {
     children.Add(child);
     EntityAdded?.Invoke(child);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Marks an entity as added to the world, and invokjes the EntityAdded event, notifying all systems
 /// of the new entity.
 /// </summary>
 /// <param name="entityId">The ID of the added entity</param>
 public void AddEntityToWorld(uint entityId)
 {
     entityInWorld[entityId] = true;
     EntityAdded?.Invoke(this, new EntityEventArgs(entityId, GetEntityBitmask(entityId)));
 }
        private static void PlaceEdge(EdgePlacerConfig cfg, Vector3D[] segments)
        {
            MyEntity holderEntity;

            MyEntities.TryGetEntityById(cfg.EntityPlacing, out holderEntity);
            var holderPlayer = holderEntity != null?MyAPIGateway.Players.GetPlayerControllingEntity(holderEntity) : null;

            var def = DefinitionFor(cfg.Placed);

            if (def == null)
            {
                MyEventContext.ValidationFailed();
                return;
            }

            #region Validation

            if (!MyEventContext.Current.IsLocallyInvoked)
            {
                if (holderEntity == null || holderPlayer == null ||
                    MyEventContext.Current.Sender.Value != holderPlayer.SteamUserId)
                {
                    MyEventContext.ValidationFailed();
                    return;
                }

                if (MyAreaPermissionSystem.Static != null)
                {
                    foreach (var pos in segments)
                    {
                        if (MyAreaPermissionSystem.Static.HasPermission(holderPlayer.IdentityId, pos,
                                                                        MyPermissionsConstants.Build))
                        {
                            continue;
                        }
                        holderPlayer.ShowNotification("You cannot build here", 2000, null, new Vector4(1, 0, 0, 1));
                        MyEventContext.ValidationFailed();
                        return;
                    }
                }

                var validPlacedType = false;
                foreach (var item in holderEntity.GetInventory(MyCharacterConstants.MainInventory).Items)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    var itemDef =
                        MyDefinitionManager.Get <MyInventoryItemDefinition>(item.DefinitionId) as MyHandItemDefinition;
                    if (itemDef == null)
                    {
                        continue;
                    }
                    foreach (var behaviorDef in itemDef.Behaviors)
                    {
                        var placeDef = behaviorDef as EdgePlacerBehaviorDefinition;
                        if (placeDef == null || placeDef.Placed != cfg.Placed)
                        {
                            continue;
                        }
                        validPlacedType = true;
                        break;
                    }

                    if (validPlacedType)
                    {
                        break;
                    }
                }

                if (!validPlacedType)
                {
                    MyEventContext.ValidationFailed();
                    MySession.Static.Log.Warning(
                        $"{holderPlayer} tried to place {cfg.Placed}, but has no item that can place it");
                    return;
                }

                var layer     = MySession.Static.Components.Get <BendyController>().GetOrCreateLayer(def.Layer);
                var annotated = AnnotateNodes(layer, segments);
                var tmp       = new List <string>();
                if (!ValidatePath(def, layer, annotated, tmp))
                {
                    holderPlayer.ShowNotification(string.Join("\n", tmp));
                    MyEventContext.ValidationFailed();
                    return;
                }
            }

            #endregion


            var graph = MySession.Static.Components.Get <BendyController>().GetOrCreateLayer(def.Layer);

            for (var i = 1; i < segments.Length; i++)
            {
                var nextNode = graph.GetOrCreateNode(segments[i - 1]);
                var prevNode = graph.GetOrCreateNode(segments[i]);

                if (graph.GetEdge(prevNode, nextNode) != null)
                {
                    continue;
                }

                var obContainer = new MyObjectBuilder_ComponentContainer();
                var worldMatrix = MatrixD.CreateWorld((prevNode.Position + nextNode.Position) / 2,
                                                      Vector3D.Normalize(nextNode.Position - prevNode.Position),
                                                      Vector3D.Normalize(nextNode.Up + prevNode.Up));
                var worldMatrixInv = MatrixD.Invert(worldMatrix);
                ((ICollection <MyObjectBuilder_EntityComponent>)obContainer.Components).Add(
                    new MyObjectBuilder_BendyComponent()
                {
                    Overrides = new[]
                    {
                        new MyObjectBuilder_BendyComponent.NodePose
                        {
                            Index    = 0,
                            Position = (Vector3)Vector3D.Transform(prevNode.Position, worldMatrixInv),
                            Up       = (Vector3)Vector3D.Transform(prevNode.Up, worldMatrixInv)
                        },
                        new MyObjectBuilder_BendyComponent.NodePose
                        {
                            Index    = 1,
                            Position = (Vector3)Vector3D.Transform(nextNode.Position, worldMatrixInv),
                            Up       = (Vector3)Vector3D.Transform(nextNode.Up, worldMatrixInv)
                        }
                    }
                });
                var entOb = new MyObjectBuilder_EntityBase()
                {
                    EntityDefinitionId     = (MyDefinitionId)cfg.Placed,
                    PersistentFlags        = MyPersistentEntityFlags2.InScene,
                    PositionAndOrientation = new MyPositionAndOrientation(worldMatrix),
                    SubtypeName            = cfg.Placed.SubtypeId,
                    ComponentContainer     = obContainer
                };
                var entity = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(entOb);
                if (holderPlayer != null && holderPlayer.IsCreative())
                {
                    entity.Components.Get <ConstructableComponent>()?.InstallFromCreative();
                    ConstructableComponentDefinition.CcComponent test;
                    int test2;
                    entity.Components.Get <ConstructableComponent>()
                    ?.IncreaseIntegrity(1e9f, out test, out test2);
                }

                entity.Components.Get <BendyPhysicsComponent>()?.DestroyEnvItems();

                EntityAdded?.Invoke(holderEntity, holderPlayer, entity);
            }
        }
Exemplo n.º 30
0
 private void OnEntityAdded(object sender, EntityCollectionChangedEventArgs <TLinkTable> e)
 {
     EntityAdded?.Invoke(this, new EntityCollectionChangedEventArgs <TEntity>(_getEntity(e.Entity)));
 }