Example #1
0
 public static bool IsCommandValid(EntityManager globalManager, Guid factionGuid, Guid targetEntityGuid, out Entity factionEntity, out Entity targetEntity)
 {
     if (globalManager.FindEntityByGuid(targetEntityGuid, out targetEntity))
     {
         if (globalManager.FindEntityByGuid(factionGuid, out factionEntity))
         {
             if (targetEntity.GetDataBlob <OwnedDB>().OwnedByFaction == factionEntity)
             {
                 return(true);
             }
         }
     }
     factionEntity = Entity.InvalidEntity;
     return(false);
 }
Example #2
0
        public static Entity ImportEntity([NotNull] Game game, [NotNull] Stream inputStream, [NotNull] EntityManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }


            var protoEntity = new ProtoEntity();

            protoEntity = Import(game, inputStream, protoEntity);

            //the block of code below is a somewhat hacky way of fixing a problem where an entity has a datablob that refers back to the entity.
            //eg a faction entitiy with a NameDB. in such cases the Import above creates an empty entity because of the NameDB's reference.
            //then Entity.Create below checks for an exsisting entity guid, finds it, then returns an entity with a new GUID.
            //this then gives us two entities, one with the correct guid but with no datablobs, and a second one with a new different guid and all the datablobs.
            //checking if the datablob count is 0 is a poor and not guarenteed way of seeing if the entity hasn't been created some other way previously.
            //I'm wondering if we shouldn't throw an exception if we try to add an entity with the same guid, instead of just changing the guid.
            Entity entity;

            if (manager.FindEntityByGuid(protoEntity.Guid, out entity) && entity.DataBlobs.Count == 0)
            {
                manager.RemoveEntity(entity);
            }



            entity = Entity.Create(manager, protoEntity);
            game.PostGameLoad();
            return(entity);
        }
Example #3
0
        internal Entity([NotNull] EntityManager manager, Guid id, IEnumerable <BaseDataBlob> dataBlobs = null)
        {
            Manager = manager;
            Guid    = id;

            Entity checkEntity;

            while (Guid == Guid.Empty || manager.FindEntityByGuid(Guid, out checkEntity))
            {
                Guid = Guid.NewGuid();
            }

            ID = Manager.SetupEntity(this);
            _protectedDataBlobMask_ = Manager.EntityMasks[ID];

            if (dataBlobs == null)
            {
                return;
            }

            foreach (BaseDataBlob dataBlob in dataBlobs)
            {
                if (dataBlob != null)
                {
                    SetDataBlob(dataBlob);
                }
            }
        }