Exemplo n.º 1
0
    protected virtual void AddEntity(Group collection, Entity entity, int index, IComponent component)
    {
        IdComponent iDComponent = null;

        foreach (var c in entity.GetComponents())
        {
            if (c.GetType() == typeof(IdComponent))
            {
                iDComponent = (IdComponent)c;
            }
        }

        if (iDComponent != null)
        {
            if (lookup.ContainsKey(iDComponent.Id) && lookup[iDComponent.Id] == entity)
            {
                return;
            }

            if (lookup.ContainsKey(iDComponent.Id) && lookup[iDComponent.Id] != entity)
            {
                throw new Exception("the key " + iDComponent + " is not unique. Present on entity: " + entity.creationIndex + " and entity: " + lookup[iDComponent.Id].creationIndex);
            }
            entity.Retain(this);
            lookup[iDComponent.Id] = entity;
        }
    }
Exemplo n.º 2
0
        public void GenerateId(IEntity entity)
        {
            IdComponent component = entity.CreateComponent(_index, typeof(IdComponent)) as IdComponent;

            component.Id = _id++;

            entity.AddComponent(_index, component);
        }
Exemplo n.º 3
0
        private void LoadEntities()
        {
            throw new NotImplementedException();
            int entitesCount     = _savedComponents.Positions.Length;
            int?firstEntityIndex = null;

            _context.ReplacePlayerEntity(_savedComponents.PlayerEntityId);
            for (int i = 0; i < entitesCount; i++)
            {
                GameEntity entity = _context.CreateEntity();
                if (!firstEntityIndex.HasValue)
                {
                    firstEntityIndex = entity.creationIndex;
                }
                int currentEntityIndex = entity.creationIndex;
                int componentIndex     = currentEntityIndex - firstEntityIndex.Value;

                IdComponent savedId = _savedComponents.Ids[componentIndex];
                entity.ReplaceId(savedId.Id);

                bool[] componentPresence = _savedComponents.EntityToHasComponent[savedId.Id];

                PositionComponent savedPosition = _savedComponents.Positions[componentIndex];
                if (componentPresence[GameComponentsLookup.Position])
                {
                    entity.AddPosition(savedPosition.Position);
                    entity.AddPositionAfterLastTurn(default(Position));
                }

                VisionComponent savedVision = _savedComponents.Visions[componentIndex];
                if (componentPresence[GameComponentsLookup.Vision])
                {
                    entity.AddVision(savedVision.VisionRange, savedVision.PerceptionRange,
                                     savedVision.EntitiesNoticed ?? new HashSet <Guid>());
                }

                RecipeeComponent savedRecipee = _savedComponents.Recipees[componentIndex];
                if (componentPresence[GameComponentsLookup.Recipee])
                {
                    entity.AddRecipee(savedRecipee.RecipeeName);
                }

                EnergyComponent savedEnergy = _savedComponents.Energies[componentIndex];
                if (componentPresence[GameComponentsLookup.Energy])
                {
                    entity.AddEnergy(savedEnergy.EnergyGainPerSegment, savedEnergy.Energy);
                }

                IntegrityComponent savedIntegrity = _savedComponents.Integrities[componentIndex];
                if (componentPresence[GameComponentsLookup.Integrity])
                {
                    entity.AddIntegrity(savedIntegrity.Integrity, savedIntegrity.MaxIntegrity);
                }

                SkillsComponent savedSkill = _savedComponents.Skills[componentIndex];
                if (componentPresence[GameComponentsLookup.Skills])
                {
                    entity.AddSkills(savedSkill.Skills);
                }

                StomachComponent savedStomach = _savedComponents.Stomachs[componentIndex];
                if (componentPresence[GameComponentsLookup.Stomach])
                {
                    entity.AddStomach(savedStomach.Satiation, savedStomach.MaxSatiation);
                }

                TeamComponent savedTeam = _savedComponents.Teams[componentIndex];
                if (componentPresence[GameComponentsLookup.Team])
                {
                    entity.AddTeam(savedTeam.Team);
                }

                LooksComponent savedLooks = _savedComponents.Looks[componentIndex];
                if (componentPresence[GameComponentsLookup.Looks])
                {
                    entity.AddLooks(savedLooks.BodySprite);
                }

                EdibleComponent savedEdible = _savedComponents.Edibles[componentIndex];
                if (componentPresence[GameComponentsLookup.Edible])
                {
                    entity.AddEdible(savedEdible.Satiety);
                }

                if (componentPresence[GameComponentsLookup.BlockingPosition])
                {
                    entity.isBlockingPosition = true;
                }

                entity.isFinishedTurn = true;
                if (_context.playerEntity.Id == entity.id.Id)
                {
                    entity.isPlayerControlled = true;
                }
            }
        }