Exemple #1
0
        public bool AddEntity(YmapEntityDef ent, int roomIndex)
        {
            if (ent == null)
            {
                return(false);
            }

            // entity already exists in our array. so we'll just add
            // it to the instanced entities list and continue.
            MloInstanceData mloInstance = ent.MloParent?.MloInstance;
            MCEntityDef     ymcent      = mloInstance?.TryGetArchetypeEntity(ent);

            if (ymcent != null)
            {
                return(true);
            }

            if (roomIndex > rooms.Length)
            {
                throw new ArgumentOutOfRangeException($"Room index {roomIndex} exceeds the amount of rooms in {Name}.");
            }

            var mcEntityDef = new MCEntityDef(ref ent._CEntityDef, this);

            // Add the new entity def to the entities list.
            AddEntity(ent, mcEntityDef);

            // Update the attached objects in the room index specified.
            AttachEntityToRoom(ent, roomIndex);
            return(true);
        }
Exemple #2
0
        public bool RemoveEntity(YmapEntityDef ent)
        {
            if (ent.Index >= entities.Length)
            {
                return(false);
            }

            MCEntityDef     delent = entities[ent.Index];
            MloInstanceData inst   = ent.MloParent?.MloInstance;

            if (inst == null)
            {
                return(false);
            }

            if (delent != null)
            {
                MCEntityDef[] newentities = new MCEntityDef[entities.Length - 1];
                bool          didDel      = false;
                int           index       = 0;
                int           delIndex    = 0;
                for (int i = 0; i < entities.Length; i++)
                {
                    if (entities[i] == delent)
                    {
                        delIndex = i;
                        didDel   = true;
                        continue;
                    }

                    newentities[index] = entities[i];
                    YmapEntityDef ymapEntityDef = inst.TryGetYmapEntity(newentities[index]);
                    if (ymapEntityDef != null)
                    {
                        ymapEntityDef.Index = index;
                    }
                    index++;
                }

                entities = newentities;

                if (didDel)
                {
                    FixRoomIndexes(delIndex);
                    FixPortalIndexes(delIndex);
                }
                return(didDel);
            }

            return(false);
        }
Exemple #3
0
 public MloInstanceEntitySet(MCMloEntitySet entSet, MloInstanceData instance)
 {
     EntitySet = entSet;
     Entities  = new List <YmapEntityDef>();
     Instance  = instance;
 }