Ejemplo n.º 1
0
        private void InitializeLevels(SequentialMessageQueue <GameManager> queue)
        {
            Add <LevelComponent>(EntityComponent.Level, poolSize: 2);
            Add <ConnectionComponent>(EntityComponent.Connection, poolSize: 2);
            Add <PositionComponent>(EntityComponent.Position, poolSize: 32);

            Levels = CreateGroup(nameof(Levels),
                                 new EntityMatcher <GameEntity>().AllOf((int)EntityComponent.Level));
            Connections = CreateGroup(nameof(Connections),
                                      new EntityMatcher <GameEntity>().AllOf((int)EntityComponent.Position, (int)EntityComponent.Connection));
            LevelEntities = CreateGroup(nameof(LevelEntities),
                                        new EntityMatcher <GameEntity>().AllOf((int)EntityComponent.Position));

            ConnectionsToLevelRelationship = new EntityRelationship <GameEntity>(
                nameof(ConnectionsToLevelRelationship),
                Connections,
                Levels,
                new SimpleKeyValueGetter <GameEntity, int>(
                    component => ((PositionComponent)component).LevelId,
                    (int)EntityComponent.Position),
                (effectEntity, _, __) => effectEntity.RemoveComponent(EntityComponent.Position));

            IncomingConnectionsToLevelRelationship = new EntityRelationship <GameEntity>(
                nameof(IncomingConnectionsToLevelRelationship),
                Connections,
                Levels,
                new SimpleKeyValueGetter <GameEntity, int>(
                    component => ((ConnectionComponent)component).TargetLevelId,
                    (int)EntityComponent.Connection),
                (effectEntity, _, __) => effectEntity.RemoveComponent(EntityComponent.Position));

            TravelSystem = new TravelSystem();
            queue.Add <TravelMessage>(TravelSystem, TravelSystem.TravelMessageName, 0);
            queue.Add <DiedMessage>(TravelSystem, LivingSystem.DiedMessageName, 6);
        }
Ejemplo n.º 2
0
        private void InitializeSenses(SequentialMessageQueue <GameManager> queue)
        {
            Add <SensorComponent>(EntityComponent.Sensor, poolSize: 32);

            SensorySystem = new SensorySystem();
            queue.Add <TraveledMessage>(SensorySystem, TravelSystem.TraveledMessageName, 3);
            queue.Add <EntityAddedMessage <GameEntity> >(SensorySystem, Beings.GetEntityAddedMessageName(), 1);
        }
Ejemplo n.º 3
0
        private void InitializeFaculties(SequentialMessageQueue <GameManager> queue)
        {
            BeingToPrimaryNaturalWeaponRelationship = new UniqueEntityRelationship <GameEntity>(
                nameof(BeingToPrimaryNaturalWeaponRelationship),
                Beings,
                EntityItems,
                new SimpleKeyValueGetter <GameEntity, int>(
                    component => ((BeingComponent)component).PrimaryNaturalWeaponId,
                    (int)EntityComponent.Being),
                (effectEntity, _, __) => effectEntity.Being.PrimaryNaturalWeaponId = null,
                referencedKeepAlive: true,
                referencingKeepAlive: false);

            BeingToSecondaryNaturalWeaponRelationship = new UniqueEntityRelationship <GameEntity>(
                nameof(BeingToSecondaryNaturalWeaponRelationship),
                Beings,
                EntityItems,
                new SimpleKeyValueGetter <GameEntity, int>(
                    component => ((BeingComponent)component).SecondaryNaturalWeaponId,
                    (int)EntityComponent.Being),
                (effectEntity, _, __) => effectEntity.Being.SecondaryNaturalWeaponId = null,
                referencedKeepAlive: true,
                referencingKeepAlive: false);

            SkillAbilitiesSystem = new SkillAbilitiesSystem();
            queue.Add <ItemEquippedMessage>(SkillAbilitiesSystem, ItemUsageSystem.ItemEquippedMessageName, 4);
            queue.Add <PropertyValueChangedMessage <GameEntity, ExtremityType> >(SkillAbilitiesSystem,
                                                                                 Beings.GetPropertyValueChangedMessageName(nameof(BeingComponent.UpperExtremities)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.HandWeapons)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.ShortWeapons)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.MediumWeapons)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.LongWeapons)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.CloseRangeWeapons)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.ShortRangeWeapons)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.MediumRangeWeapons)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.LongRangeWeapons)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.LightArmor)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.HeavyArmor)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int> >(SkillAbilitiesSystem,
                                                                       Players.GetPropertyValueChangedMessageName(nameof(PlayerComponent.Artifice)), 0);
        }
Ejemplo n.º 4
0
        private void InitializeEffects(SequentialMessageQueue <GameManager> queue)
        {
            Add <EffectComponent>(EntityComponent.Effect, poolSize: 32);

            Effects = CreateGroup(nameof(Effects),
                                  new EntityMatcher <GameEntity>().AllOf((int)EntityComponent.Effect));

            AppliedEffectsToAffectableEntityRelationship = new EntityRelationship <GameEntity>(
                nameof(AppliedEffectsToAffectableEntityRelationship),
                Effects,
                AffectableEntities,
                new SimpleKeyValueGetter <GameEntity, int>(
                    component => ((EffectComponent)component).AffectedEntityId,
                    (int)EntityComponent.Effect),
                (effectEntity, _, __) => effectEntity.RemoveComponent((int)EntityComponent.Effect),
                referencedKeepAlive: false, referencingKeepAlive: true);

            EffectsToContainingAbilityRelationship = new EntityRelationship <GameEntity>(
                nameof(EffectsToContainingAbilityRelationship),
                Effects,
                Abilities,
                new SimpleKeyValueGetter <GameEntity, int>(
                    component => ((EffectComponent)component).ContainingAbilityId,
                    (int)EntityComponent.Effect),
                (effectEntity, _, __) => effectEntity.RemoveComponent((int)EntityComponent.Effect),
                referencedKeepAlive: false, referencingKeepAlive: true);

            AppliedEffectsToSourceAbilityRelationship = new EntityRelationship <GameEntity>(
                nameof(AppliedEffectsToSourceAbilityRelationship),
                Effects,
                Abilities,
                new SimpleKeyValueGetter <GameEntity, int>(
                    component => ((EffectComponent)component).SourceAbilityId,
                    (int)EntityComponent.Effect),
                (effectEntity, _, changedComponent) =>
            {
                var sourceAbility = changedComponent as AbilityComponent
                                    ?? effectEntity.Manager.FindEntity(effectEntity.Effect.SourceAbilityId)
                                    ?.Ability;
                if (sourceAbility?.IsActive == true)
                {
                    effectEntity.Effect = null;
                }
                else
                {
                    effectEntity.Effect.SourceAbilityId = null;
                }
            });

            EffectApplicationSystem = new EffectApplicationSystem();
            queue.Add <AbilityActivatedMessage>(EffectApplicationSystem,
                                                AbilityActivationSystem.AbilityActivatedMessageName, 0);
            queue.Add <ApplyEffectMessage>(EffectApplicationSystem,
                                           EffectApplicationSystem.ApplyEffectMessageName, 0);
            queue.Add <EntityAddedMessage <GameEntity> >(EffectApplicationSystem,
                                                         AffectableEntities.GetEntityAddedMessageName(), 0);
            queue.Add <EntityAddedMessage <GameEntity> >(EffectApplicationSystem,
                                                         Effects.GetEntityAddedMessageName(), 0);
            queue.Add <EntityRemovedMessage <GameEntity> >(EffectApplicationSystem,
                                                           Effects.GetEntityRemovedMessageName(), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, int?> >(EffectApplicationSystem,
                                                                        Effects.GetPropertyValueChangedMessageName(nameof(EffectComponent.Amount)), 0);
            queue.Add <PropertyValueChangedMessage <GameEntity, string> >(EffectApplicationSystem,
                                                                          Effects.GetPropertyValueChangedMessageName(nameof(EffectComponent.AmountExpression)), 0);

            queue.Add <EntityAddedMessage <GameEntity> >(AbilityActivationSystem,
                                                         Effects.GetEntityAddedMessageName(), 1);
            queue.Add <EntityRemovedMessage <GameEntity> >(AbilityActivationSystem,
                                                           Effects.GetEntityRemovedMessageName(), 1);
        }