public override void Update(SimulationEntity entity, Simulation simulation)
        {
            SimulationEntity effect = SimulationEntity.SimulationEntityFactory("MiniStarParticle");

            effect.Position = entity.Position.Clone();
            simulation.AddEntity(effect);

            effect          = SimulationEntity.SimulationEntityFactory("StarParticle");
            effect.Position = entity.Position.Clone();
            simulation.AddEntity(effect);

            effect          = SimulationEntity.SimulationEntityFactory("XParticle");
            effect.Position = entity.Position.Clone();
            simulation.AddEntity(effect);
        }
        private void CreateBoss(Simulation simulation, [CanBeNull] SimulationEntity target, bool fromMonsters)
        {
            // Loop through player monsters and pick a random one to make a monster.
            if (target == null)
            {
                int who = _random.Next(simulation.GetPlayerEntities().Count);

                if (!fromMonsters)
                {
                    while (simulation.GetPlayerEntities()[who].EntityConfiguration.EntityKey != "Human")
                    {
                        who = _random.Next(simulation.GetPlayerEntities().Count);
                    }
                }
                else
                {
                    while (simulation.GetPlayerEntities()[who].EntityConfiguration.EntityKey == "Human")
                    {
                        who = _random.Next(simulation.GetPlayerEntities().Count);
                    }
                }

                target = simulation.GetPlayerEntities()[who];
            }

            simulation.RemoveEntity(target.EntityId, EntityRemovalReason.BossSpawn);
            SimulationEntity player = SimulationEntity.SimulationEntityFactory("AdamBoss", socket: target.Socket);

            player.Position.X = target.Position.X;
            player.Position.Y = target.Position.Y;

            simulation.AddEntity(player);
        }
 public override void Update(SimulationEntity entity, Simulation simulation)
 {
     for (int i = 0; i < 4; i++)
     {
         SimulationEntity effect = SimulationEntity.SimulationEntityFactory("FireBallParticle");
         effect.Position = entity.Position.Clone();
         simulation.AddEntity(effect);
     }
 }
Ejemplo n.º 4
0
        public override void Update(SimulationEntity entity, Simulation simulation)
        {
            lock (_lock)
            {
                if (entity.ControlState != null && entity.Inventory != null && entity.ControlState.DropItem)
                {
                    IItem activeItem = entity.Inventory.GetActiveSlot()?.Clone();

                    if (activeItem != null)
                    {
                        if (entity.Inventory.GetActiveSlot()?.DecrementStack() == false)
                        {
                            entity.Inventory.Remove(entity.Inventory.GetActiveSlotId());
                        }

                        activeItem.SetStackSize(1);
                        _dropItems.Add(activeItem);
                    }
                }

                if (!_dropItems.Any())
                {
                    return;
                }

                foreach (IItem dropItem in _dropItems)
                {
                    InventoryManager inventory = new InventoryManager();
                    inventory.Insert(dropItem);

                    SimulationEntity newItem = SimulationEntity.SimulationEntityFactory("Item");

                    newItem.TextureKey = dropItem.Configuration.TextureKey;
                    newItem.Inventory  = inventory;

                    if (entity.Facing == DirectionFacing.Left)
                    {
                        newItem.Position         = entity.Position.Clone();
                        newItem.Position.X      -= 50;
                        newItem.SteeringVector.X = -40;
                    }
                    else
                    {
                        newItem.Position         = entity.Position.Clone();
                        newItem.Position.X      += entity.Width + 50;
                        newItem.SteeringVector.X = 40;
                    }
                    simulation.AddEntity(newItem);
                }

                _dropItems.Clear();
            }
        }
        private void Explode(Simulation simulation, SimulationEntity entity)
        {
            for (int i = 0; i < 25; i++)
            {
                if (simulation.World.ChunkFromPixelLocation((int)entity.Position.X, (int)entity.Position.Y) == null)
                {
                    return;
                }

                SimulationEntity effect = SimulationEntity.SimulationEntityFactory("rMiniStarParticle");
                effect.Position = entity.OriginPosition;
                simulation.AddEntity(effect);

                effect          = SimulationEntity.SimulationEntityFactory("rStarParticle");
                effect.Position = entity.OriginPosition;
                simulation.AddEntity(effect);

                effect          = SimulationEntity.SimulationEntityFactory("rXParticle");
                effect.Position = entity.OriginPosition;
                simulation.AddEntity(effect);
            }
        }
Ejemplo n.º 6
0
    private void InitSimulation()
    {
        simulation.AddParameter(VoxelWorld.PARAMETER_WORLD_SIZE, new IntVector3(sizeX, sizeY, sizeZ));
        simulation.AddParameter(Simulation.PARAMETER_STEPS_PER_SECOND, 20);
        simulation.AddParameter(Simulation.PARAMETER_SIMULATION_LISTENER, this);

        simulation.Init();

        voxelView.Init(simulation.GetComponentManager <VoxelWorld>());

        EntityTemplate template1 = new EntityTemplate();

        template1.AddComponent <VoxelComponent>()
        .AddParameter(VoxelComponent.PARAMETER_SHAPE, VoxelShape.Sphere)
        .AddParameter(VoxelComponent.PARAMETER_RADIUS, fint.quarter)
        .AddParameter(VoxelComponent.PARAMETER_COLOR, new FVector3(fint.one, fint.zero, fint.zero))
        .AddParameter(VoxelComponent.PARAMETER_POSITION, FVector3.one + FVector3.up * fint.half + FVector3.forward);

        template1.AddComponent <VoxelPathWalker>();
        template1.AddComponent <Avatar>();

        EntityTemplate template2 = new EntityTemplate();

        template2.AddComponent <VoxelComponent>()
        .AddParameter(VoxelComponent.PARAMETER_SHAPE, VoxelShape.Cylinder)
        .AddParameter(VoxelComponent.PARAMETER_RADIUS, fint.quarter)
        .AddParameter(VoxelComponent.PARAMETER_HEIGHT, fint.one)
        .AddParameter(VoxelComponent.PARAMETER_COLOR, new FVector3(fint.zero, fint.one, fint.zero))
        .AddParameter(VoxelComponent.PARAMETER_POSITION, FVector3.one + FVector3.up * fint.half);

        template2.AddComponent <AvatarMoveRandom>();

        for (int i = 0; i < 100; i++)
        {
            simulation.AddEntity(template1);

            simulation.AddEntity(template2);
        }
    }
Ejemplo n.º 7
0
        public Player LoginPlayer(string playerName)
        {
            if (Simulation == null)
                throw new NotSupportedException();

            if (Simulation.State != SimulationState.Running && Simulation.State != SimulationState.Paused)
                throw new NotSupportedException();

            //TODO: [Network] Anstelle von ID einen einstellbaren Playernamen implementieren
            Player player = resourceManager.LoadPlayer(playerName);
            player.Components.AddComponent(new RenderComponent { Name = "Wauzi", ModelName = "dog", TextureName = "texdog", BaseZRotation = -90 }, true);
            Simulation.AddEntity(player);


            return player;
        }
Ejemplo n.º 8
0
        public void Use(Simulation simulation, SimulationEntity entity, IItem item)
        {
            ItemConfiguration itemConfig = item.Configuration;

            if (entity.ControlState == null || entity.Meta == null || entity.Meta.Mana < itemConfig.ManaCost)
            {
                return;
            }

            entity.Meta.Health += itemConfig.HealthGain;
            entity.Meta.Health -= itemConfig.HealthCost;

            entity.Meta.Mana += itemConfig.ManaGain;
            entity.Meta.Mana -= itemConfig.ManaCost;

            if (entity.Meta.Health > entity.EntityConfiguration.Health)
            {
                entity.Meta.Health = entity.EntityConfiguration.Health;
            }

            if (entity.Meta.Mana > entity.EntityConfiguration.Mana)
            {
                entity.Meta.Health = entity.EntityConfiguration.Mana;
            }

            BfbVector directionVector = BfbVector.Sub(entity.ControlState.Mouse, entity.OriginPosition);
            float     direction       = (float)System.Math.Atan2(directionVector.Y, directionVector.X) + (float)(System.Math.PI / 2);

            //place a copy of the spell config inside the projectile
            InventoryManager inventory = new InventoryManager();
            Item             newItem   = new Item(item.ItemConfigKey);

            inventory.Insert(newItem);

            SimulationEntity spellEntity = SimulationEntity.SimulationEntityFactory(itemConfig.EntitySpawnKey);

            spellEntity.SteeringVector = directionVector;
            spellEntity.Rotation       = direction;
            spellEntity.ParentEntityId = entity.EntityId;
            spellEntity.Position       = entity.OriginPosition.Clone();
            spellEntity.Inventory      = inventory;

            simulation.AddEntity(spellEntity);
        }
Ejemplo n.º 9
0
        public Player LoginPlayer(string playerName)
        {
            if (Simulation == null)
            {
                throw new NotSupportedException();
            }

            if (Simulation.State != SimulationState.Running && Simulation.State != SimulationState.Paused)
            {
                throw new NotSupportedException();
            }

            Player player = resourceManager.LoadPlayer(playerName);

            player.Components.AddComponent(new RenderComponent()
            {
                Name = "Wauzi", ModelName = "dog", TextureName = "texdog", BaseZRotation = -90
            }, true);
            Simulation.AddEntity(player);


            return(player);
        }
Ejemplo n.º 10
0
        public void Use(Simulation simulation, SimulationEntity entity, IItem item)
        {
            if (entity.ControlState == null)
            {
                return;
            }

            int mouseX = (int)entity.ControlState.Mouse.X;
            int mouseY = (int)entity.ControlState.Mouse.Y;

            Tuple <int, int, int, int> chunkInformation = simulation.World.TranslatePixelPosition(mouseX, mouseY);

            //If we are inside map
            if (chunkInformation == null)
            {
                return;
            }

            Chunk targetChunk = simulation.World.ChunkFromChunkLocation(chunkInformation.Item1, chunkInformation.Item2);

            //If the chunk exist
            if (targetChunk == null)
            {
                return;
            }

            int xSelection = chunkInformation.Item3;
            int ySelection = chunkInformation.Item4;

            if (item.TileTarget.X != xSelection || item.TileTarget.Y != ySelection)
            {
                item.TileTarget.X             = xSelection;
                item.TileTarget.Y             = ySelection;
                item.TileTarget.Progress      = 0;
                item.TileTarget.ProgressTotal = ConfigurationRegistry.GetInstance()?
                                                .GetWallConfiguration((WorldTile)targetChunk.Wall[xSelection, ySelection])?.BreakSpeed ?? 0;
                return;
            }
            item.TileTarget.Progress++;

            WorldTile             tileType;
            ConfigurationRegistry config = ConfigurationRegistry.GetInstance();

            if (targetChunk.Block[xSelection, ySelection] == 0 && (tileType = (WorldTile)targetChunk.Wall[xSelection, ySelection]) != 0)
            {//Is block
                if (item.TileTarget.Progress < config.GetBlockConfiguration(tileType).BreakSpeed)
                {
                    return;//Not ready yet
                }
            }
            else
            {//is wall or air
                item.TileTarget.Progress = 0;
                return;
            }

            //If we made it here then we are ready to break a block
            targetChunk.ApplyBlockUpdate(new TileUpdate
            {
                X         = (byte)xSelection,
                Y         = (byte)ySelection,
                Mode      = false,
                TileValue = (ushort)WorldTile.Air
            });

            item.TileTarget.Progress = 0;

            int blockX = (simulation.World.WorldOptions.ChunkSize * chunkInformation.Item1 + xSelection) * simulation.World.WorldOptions.WorldScale;
            int blockY = (simulation.World.WorldOptions.ChunkSize * chunkInformation.Item2 + ySelection) * simulation.World.WorldOptions.WorldScale;

            InventoryManager inventory = new InventoryManager();
            Item             newItem   = new Item(config.GetWallConfiguration(tileType).ItemKey);

            inventory.Insert(newItem);

            SimulationEntity itemEntity = SimulationEntity.SimulationEntityFactory("Item");

            itemEntity.TextureKey = config.GetWallConfiguration(tileType).TextureKey;
            itemEntity.Position   = new BfbVector(blockX, blockY);
            itemEntity.Inventory  = inventory;
            simulation.AddEntity(itemEntity);
        }
Ejemplo n.º 11
0
        public void Use(Simulation simulation, SimulationEntity entity, IItem item)
        {
            if (entity.ControlState == null)
            {
                return;
            }

            int mouseX = (int)entity.ControlState.Mouse.X;
            int mouseY = (int)entity.ControlState.Mouse.Y;

            Tuple <int, int, int, int> chunkInformation = simulation.World.TranslatePixelPosition(mouseX, mouseY);

            //If we are inside map
            if (chunkInformation == null)
            {
                return;
            }

            Chunk targetChunk = simulation.World.ChunkFromChunkLocation(chunkInformation.Item1, chunkInformation.Item2);

            //If the chunk exist
            if (targetChunk == null)
            {
                return;
            }

            int xSelection = chunkInformation.Item3;
            int ySelection = chunkInformation.Item4;

            if (item.TileTarget.X != xSelection || item.TileTarget.Y != ySelection)
            {
                item.TileTarget.X             = xSelection;
                item.TileTarget.Y             = ySelection;
                item.TileTarget.Progress      = 0;
                item.TileTarget.ProgressTotal = ConfigurationRegistry.GetInstance()?
                                                .GetBlockConfiguration((WorldTile)targetChunk.Block[xSelection, ySelection])?.BreakSpeed ?? 0;
                return;
            }
            item.TileTarget.Progress++;

            WorldTile             tileType;
            ConfigurationRegistry config = ConfigurationRegistry.GetInstance();

            if ((tileType = (WorldTile)targetChunk.Block[xSelection, ySelection]) != 0)
            {//Is block
                if (item.TileTarget.Progress < config.GetBlockConfiguration(tileType).BreakSpeed)
                {
                    return;//Not ready yet
                }
            }
            else
            {//is wall or air
                return;
            }

            //If we made it here then we are ready to break a block
            targetChunk.ApplyBlockUpdate(new TileUpdate
            {
                X         = (byte)xSelection,
                Y         = (byte)ySelection,
                Mode      = true,
                TileValue = (ushort)WorldTile.Air
            });

            item.TileTarget.Progress = 0;

            int blockX = (simulation.World.WorldOptions.ChunkSize * chunkInformation.Item1 + xSelection) * simulation.World.WorldOptions.WorldScale;
            int blockY = (simulation.World.WorldOptions.ChunkSize * chunkInformation.Item2 + ySelection) * simulation.World.WorldOptions.WorldScale;

            InventoryManager inventory = new InventoryManager();
            Item             newItem   = new Item(config.GetBlockConfiguration(tileType).ItemKey);

            inventory.Insert(newItem);

            SimulationEntity itemEntity = SimulationEntity.SimulationEntityFactory("Item");

            itemEntity.TextureKey = config.GetBlockConfiguration(tileType).TextureKey;
            itemEntity.Position   = new BfbVector(blockX, blockY);
            itemEntity.Inventory  = inventory;
            simulation.AddEntity(itemEntity);

//            simulation.AddEntity(new SimulationEntity(
//                Guid.NewGuid().ToString(),
//                new EntityOptions
//                {
//                    TextureKey = config.GetBlockConfiguration(tileType).TextureKey,
//                    Position = new BfbVector(blockX, blockY),
//                    Dimensions = new BfbVector(1 * simulation.World.WorldOptions.WorldScale,
//                        1 * simulation.World.WorldOptions.WorldScale),
//                    Rotation = 0,
//                    Origin = new BfbVector(0, 0),
//                    EntityType = EntityType.Item
//                }, new List<EntityComponent>
//                {
//                    new LifetimeComponent(2000),
//                    new TilePhysics()
//                })
//            {
//                CollideFilter = "item",
//                CollideWithFilters = new List<string>{ "tile" },
//                Inventory = inventory
//            });
        }
Ejemplo n.º 12
0
        private void Init()
        {
            ConfigurationRegistry.InitializeRegistry();

            #region Server Callbacks

            #region Terminal Header

            //Terminal Header format
            _server.SetTerminalHeader(() =>
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write($"[BFB-Server|{DateTime.Now:h:mm:ss tt}|T:{Process.GetCurrentProcess().Threads.Count}] ");
                Console.ResetColor();
            });

            #endregion

            #region Handle Client Connection

            _server.OnClientConnect = socket =>
            {
                _server.PrintMessage($"Client {socket.ClientId} Connected");
            };

            #endregion

            #region Handle Client Authentication

            _server.OnClientAuthentication = m =>
            {
                _server.PrintMessage($"Client {m.ClientId} Authenticated.");
                return(true);
            };

            #endregion

            #region OnClientPrepare

            _server.OnClientPrepare = socket =>
            {
                socket.Emit("prepare", _simulation.World.GetInitWorldData());
            };

            #endregion

            #region Handle Client Ready

            _server.OnClientReady = socket =>
            {
                SimulationEntity player = SimulationEntity.SimulationEntityFactory("Human", socket: socket);
                _simulation.AddEntity(player);
                _simulation.ConnectedClients += 1;

                _server.PrintMessage($"Client {socket.ClientId} Ready and added to Simulation");
            };

            #endregion

            #region Handle Client Disconnect

            _server.OnClientDisconnect = id =>
            {
                _simulation.RemoveEntity(id, EntityRemovalReason.Disconnect);
                _simulation.ConnectedClients -= 1;
                _server.PrintMessage($"Client {id} Disconnected");
            };

            #endregion

            #region OnServerStart/Generate World

            //probably should just be triggered to generate the first time the simulation starts
            _server.OnServerStart = () =>
            {
                Console.WriteLine("Generating World...");
                Console.Write("[");
                _cursorPositionStart = Console.CursorLeft;
                Console.CursorLeft   = _cursorPositionStart + 101;
                Console.Write("]");
                Console.CursorLeft      = _cursorPositionStart;
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.CursorVisible   = false;
                _simulation.GenerateWorld();
                Console.ResetColor();
                Console.CursorVisible = true;
                Console.WriteLine();
                _server.PrintMessage();
            };

            #endregion

            #endregion

            #region Simulation Callbacks

            #region OnSimulationStart

            _simulation.OnSimulationStart = () => _server.PrintMessage("Simulation exiting Hibernation");

            #endregion

            #region OnSimulationStop

            _simulation.OnSimulationStop = () => _server.PrintMessage("Simulation entering Hibernation");

            #endregion

            #region OnSimulationTick

            _simulation.OnSimulationTick = () =>
            {
                _server.Emit("HeartBeat");
            };

            #endregion

            #region OnWorldGenerationProgress

            _simulation.OnWorldGenerationProgress = progress =>
            {
                Console.Write("=");
                int previous = Console.CursorLeft;
                Console.CursorLeft = _cursorPositionStart + 50;
                Console.Write(progress);
                Console.CursorLeft = previous;
            };

            #endregion

            #region OnEntityAdd

            _simulation.OnEntityAdd = (entityKey, isPlayer) =>
            {
                if (isPlayer)
                {
                    _server.GetClient(entityKey).On("UISelect", (m) =>
                    {
                        SimulationEntity player = SimulationEntity.SimulationEntityFactory(m.Message, socket: _server.GetClient(m.ClientId));
                        player.Position.X       = 100;
                        player.Position.Y       = 100;
                        _simulation.AddEntity(player);
                    });
                }
            };

            #endregion

            #region OnEntityRemove

            _simulation.OnEntityRemove = (entityKey, isPlayer) =>
            {
                _server.Emit("/player/disconnect", new DataMessage {
                    Message = entityKey
                });
            };

            #endregion

            #region OnEntityUpdates

            _simulation.OnEntityUpdates = (entityKey, updates) =>
            {
                _server.GetClient(entityKey)?.Emit("/players/updates", updates);
            };

            #endregion

            #region OnInventoryUpdates

            _simulation.OnInventoryUpdate = (entityKey, updates) =>
            {
                _server.GetClient(entityKey)?.Emit("/players/inventoryUpdates", updates);
            };

            #endregion

            #region OnChunkUpdates

            _simulation.OnChunkUpdates = (entityKey, updates) =>
            {
                _server.GetClient(entityKey)?.Emit("/players/chunkUpdates", updates);
            };

            #endregion

            #region OnSimulationOverload

            _simulation.OnSimulationOverLoad = ticksBehind => _server.PrintMessage($"SERVER IS OVERLOADED. ({ticksBehind}).");

            #endregion

            #endregion

            #region Terminal Prep

            Console.Clear();
            Console.Title = "BFB Server";
            _server.PrintMessage();

            #endregion
        }