Exemplo n.º 1
0
        private bool TryGetTriggerableNPC(out DefaultEcs.Entity npc)
        {
            npc = default;
            if (playerControls.IsLocked || !world.Has <components.ActiveNPC>())
            {
                return(false);
            }

            npc = world.Get <components.ActiveNPC>().Entity;
            var npcDbRow = npc.Get <zzio.db.NpcRow>();

            if (string.IsNullOrWhiteSpace(npcDbRow.TriggerScript))
            {
                return(false);
            }

            var npcLocation = npc.Get <Location>();
            var playerToNpc = (playerLocation.GlobalPosition - npcLocation.GlobalPosition) with {
                Y = 0.001f
            };
            var cameraDir = cameraLocation.GlobalForward with {
                Y = 0.001f
            };
            var dirDistance = Vector3.Distance(Vector3.Normalize(playerToNpc), Vector3.Normalize(cameraDir));

            return(dirDistance < MaxNpcDirDistance);
        }
    }
}
        public void Setup()
        {
            _defaultWorld                      = new DefaultWorld(EntityCount);
            _defaultEntitySet                  = _defaultWorld.GetEntities().With <DefaultComponent>().AsSet();
            _defaultRunner                     = new DefaultParallelRunner(Environment.ProcessorCount);
            _defaultSystem                     = new DefaultEcsSystem(_defaultWorld);
            _defaultMultiSystem                = new DefaultEcsSystem(_defaultWorld, _defaultRunner);
            _defaultEntityComponentSystem      = new DefaultEcsEntityComponentSystem(_defaultWorld);
            _defaultMultiEntityComponentSystem = new DefaultEcsEntityComponentSystem(_defaultWorld, _defaultRunner);
            _defaultComponentSystem            = new DefaultEcsComponentSystem(_defaultWorld);
            _defaultComponentMultiSystem       = new DefaultEcsComponentSystem(_defaultWorld, _defaultRunner);

            _entitasWorld       = new Context <EntitasEntity>(1, () => new EntitasEntity());
            _entitasSystem      = new EntitasSystem(_entitasWorld);
            _entitasMultiSystem = new EntitasSystem(_entitasWorld, Environment.ProcessorCount);

            for (int i = 0; i < EntityCount; ++i)
            {
                DefaultEntity defaultEntity = _defaultWorld.CreateEntity();
                defaultEntity.Set <DefaultComponent>();

                EntitasEntity entitasEntity = _entitasWorld.CreateEntity();
                entitasEntity.AddComponent(0, new EntitasComponent());
            }
        }
Exemplo n.º 3
0
        public PlayerTriggers(ITagContainer diContainer)
        {
            world                    = diContainer.GetTag <DefaultEcs.World>();
            playerControls           = diContainer.GetTag <PlayerControls>();
            zzContainer              = diContainer.GetTag <IZanzarahContainer>();
            zzContainer.OnMouseDown += HandleMouseDown;

            var game = diContainer.GetTag <Game>();

            cameraLocation     = diContainer.GetTag <rendering.Camera>().Location;
            playerLocationLazy = new Lazy <Location>(() => game.PlayerEntity.Get <Location>());

            npcMarker = world.CreateEntity();
            npcMarker.Set(new Location());
            npcMarker.Set(new components.behaviour.Rotate(Vector3.UnitY, 90f));
            npcMarker.Set(ManagedResource <ClumpBuffers> .Create(
                              new resources.ClumpInfo(resources.ClumpType.Model, "marker.dff")));
            ModelLoader.LoadMaterialsFor(npcMarker,
                                         zzio.scn.FOModelRenderType.Solid,
                                         zzio.IColor.Green,
                                         new zzio.SurfaceProperties(1f, 1f, 1f));
            var materials = npcMarker.Get <List <materials.BaseModelInstancedMaterial> >();

            foreach (var material in materials)
            {
                material.Uniforms.Ref.vertexColorFactor = 1f;
            }
        }
 internal T CallSet <T>(DefaultEcs.Entity handle, T component)
 {
     if (!CachedSet.TryGetValue(Type, out MethodInfo fn))
     {
         fn = SetFn.MakeGenericMethod(Type);
         CachedSet.Add(Type, fn);
     }
     return((T)fn.Invoke(handle, ArrayHelper.Wrap <object>(component)));
 }
 internal T CallGet <T>(DefaultEcs.Entity handle)
 {
     if (!CachedGet.TryGetValue(Type, out MethodInfo fn))
     {
         fn = GetFn.MakeGenericMethod(Type);
         CachedGet.Add(Type, fn);
     }
     return((T)fn.Invoke(handle, _Empty));
 }
 internal bool CallHas(DefaultEcs.Entity handle)
 {
     if (!CachedHas.TryGetValue(Type, out MethodInfo fn))
     {
         fn = HasFn.MakeGenericMethod(Type);
         CachedHas.Add(Type, fn);
     }
     return((bool)fn.Invoke(handle, _Empty));
 }
Exemplo n.º 7
0
            protected override void Update(float state, ReadOnlySpan <DefaultEntity> entities)
            {
                for (int i = 0; i < entities.Length; i++)
                {
                    DefaultEntity       entity   = entities[i];
                    DefaultSpeed        speed    = entity.Get <DefaultSpeed>();
                    ref DefaultPosition position = ref entity.Get <DefaultPosition>();

                    position.X += speed.X * state;
                    position.Y += speed.Y * state;
                }
        public void Setup()
        {
            _defaultWorld                      = new DefaultWorld(EntityCount);
            _defaultEntitySet                  = _defaultWorld.GetEntities().With <DefaultComponent>().AsSet();
            _defaultRunner                     = new DefaultParallelRunner(Environment.ProcessorCount);
            _defaultSystem                     = new DefaultEcsSystem(_defaultWorld);
            _defaultMultiSystem                = new DefaultEcsSystem(_defaultWorld, _defaultRunner);
            _defaultEntityComponentSystem      = new DefaultEcsEntityComponentSystem(_defaultWorld);
            _defaultMultiEntityComponentSystem = new DefaultEcsEntityComponentSystem(_defaultWorld, _defaultRunner);
            _defaultComponentSystem            = new DefaultEcsComponentSystem(_defaultWorld);
            _defaultComponentMultiSystem       = new DefaultEcsComponentSystem(_defaultWorld, _defaultRunner);
            _defaultGeneratorSystem            = new DefaultEcsGeneratorSystem(_defaultWorld);
            _defaultGeneratorMultiSystem       = new DefaultEcsGeneratorSystem(_defaultWorld, _defaultRunner);

            _entitasWorld       = new Context <EntitasEntity>(1, () => new EntitasEntity());
            _entitasSystem      = new EntitasSystem(_entitasWorld);
            _entitasMultiSystem = new EntitasSystem(_entitasWorld, Environment.ProcessorCount);

            _monoWorld = new WorldBuilder().AddSystem(new MonoSystem()).Build();
            _time      = new GameTime();

            _leoWorld   = new LeoWorld();
            _leoSystem  = new LeoSystem();
            _leoSystems = new LeoSystems(_leoWorld).Add(_leoSystem);
            _leoSystems.ProcessInjects().Init();

            SimpleEntitiesSubmissionScheduler sveltoScheduler = new SimpleEntitiesSubmissionScheduler();

            _sveltoWorld  = new EnginesRoot(sveltoScheduler);
            _sveltoSystem = new SveltoSystem();
            _sveltoWorld.AddEngine(_sveltoSystem);
            IEntityFactory sveltoFactory = _sveltoWorld.GenerateEntityFactory();

            for (int i = 0; i < EntityCount; ++i)
            {
                DefaultEntity defaultEntity = _defaultWorld.CreateEntity();
                defaultEntity.Set <DefaultComponent>();

                EntitasEntity entitasEntity = _entitasWorld.CreateEntity();
                entitasEntity.AddComponent(0, new EntitasComponent());

                MonoEntity monoEntity = _monoWorld.CreateEntity();
                monoEntity.Attach(new MonoComponent());

                LeoEntity leoEntity = _leoWorld.NewEntity();
                leoEntity.Get <LeoComponent>();

                sveltoFactory.BuildEntity <SveltoEntity>((uint)i, _sveltoGroup);
            }

            sveltoScheduler.SubmitEntities();
        }
Exemplo n.º 9
0
        private bool IfPlayerHasCards(DefaultEcs.Entity entity, int count, CardType type, int id)
        {
            if (type == CardType.Fairy && count >= 0)
            {
                var firstFairy = PlayerInventory.GetFairyAtSlot(id);
                return(firstFairy != null && firstFairy.cardId.EntityId == id);
            }

            var actualCount = PlayerInventory.CountCards(new(type, id), inUse: false);

            return(count switch
            {
                _ when count < 0 => actualCount > 0,
                _ when count == 0 => actualCount == 0,
                _ => actualCount >= count
            });
Exemplo n.º 10
0
 public NPCChangeWaypoint(DefaultEcs.Entity entity, int from, int to)
 {
     Entity       = entity;
     FromWaypoint = from;
     ToWaypoint   = to;
 }
Exemplo n.º 11
0
 public CreaturePlaceToGround(DefaultEcs.Entity entity) => Entity = entity;