예제 #1
0
        /// <summary>
        /// Starts the internal tick system, and begins running game logic.
        /// </summary>
        public static void StartGame()
        {
            if (World.Mode == EngineMode.ServerOnly)
            {
                foreach (KeyValuePair <Guid, System.Net.Sockets.Socket> item
                         in ServerSendRecieve.TCPServer.PlayerToSocket)
                {
                    if (!WorldUtil.PlayerHasCharacter(item.Key))
                    {
                        WorldUtil.SpawnRandomCharacter(item.Key, 0);
                        WorldUtil.SpawnRandomCharacter(item.Key, 0);
                        WorldUtil.SpawnRandomCharacter(item.Key, 0);
                    }
                }
            }

            if (World.Mode == EngineMode.ServerAndClient)
            {
                if (!WorldUtil.PlayerHasCharacter(SettingsManager.PlayerSettings.Settings.PlayerID))
                {
                    WorldUtil.SpawnRandomCharacter(SettingsManager.PlayerSettings.Settings.PlayerID, 0);
                    WorldUtil.SpawnRandomCharacter(SettingsManager.PlayerSettings.Settings.PlayerID, 0);
                    WorldUtil.SpawnRandomCharacter(SettingsManager.PlayerSettings.Settings.PlayerID, 0);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Returns true if there exists a certain item that is unreserved.
        /// </summary>
        /// <param name="itemID"></param>
        /// <param name="dimension"></param>
        /// <param name="startingPoint"></param>
        /// <returns></returns>
        public static bool IsItemAvailible(int itemID, int dimension, Point2D startingPoint)
        {
            List <Point2D> nearestChunks = FindNearestChunks(itemID, startingPoint, dimension);

            if (nearestChunks != null && nearestChunks.Count > 0)
            {
                Chunk chunk;
                foreach (Point2D item in nearestChunks)
                {
                    //0-15
                    chunk = World.Data.World.GetChunk(dimension, item.X, item.Y);
                    RTree <Point2D> items  = chunk.Items[itemID];
                    List <Point2D>  result = items.Intersects(new Rectangle(WorldUtil.GetFirstTileLocation(chunk.ChunkLocation), WorldUtil.GetLastTileLocation(chunk.ChunkLocation)));

                    foreach (Point2D it in result)
                    {
                        Tile tile     = World.Data.World.GetTile(dimension, it.X, it.Y);
                        Item tileItem = tile.MainObject as Item;
                        if (tileItem != null && tileItem.ReservedID == Guid.Empty)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Finds the nearest tile to a location without an item or a resource on it.
        /// Returns null if all tiles have an item or a resource in the entire map.
        /// Will not ever return the starting point specified.
        /// Ensures that there is a walkable path for the creature to get there from the specific map location to the returned location.
        /// </summary>
        /// <param name="mapLocation"></param>
        /// <param name="dimension"></param>
        /// <returns></returns>
        public static Point2D FindItemEmptyTile(Point2D mapLocation, int dimension)
        {
            List <Point2D> tilesChecking = WorldUtil.GetNeighboringTiles(mapLocation, dimension);

            while (tilesChecking.Count > 0)
            {
                Point2D currentlyChecking = tilesChecking[0];
                Tile    tile = World.Data.World.GetTile(dimension, currentlyChecking.X, currentlyChecking.Y);

                if (tile.Item == null &&
                    tile.Resources == null &&
                    MainPathFinder.IsRoutePossible(dimension, mapLocation, currentlyChecking))
                {
                    //Found one!
                    return(currentlyChecking);
                }

                //Add all neighbors of the tile since it wasn't free from items and resources.
                tilesChecking.AddRange(WorldUtil.GetNeighboringTiles(currentlyChecking, dimension));
                tilesChecking.RemoveAt(0);
            }

            //Didn't find anything
            return(null);
        }
예제 #4
0
        /// <summary>
        /// Adds an item to the specified map location.
        /// </summary>
        public static void AddItem(Item item, Point2D mapLocation, int dimension)
        {
            Point2D chunkLocation = WorldUtil.CalculateChunkLocation(mapLocation);
            Chunk   chunk         = World.Data.World.Dimensions[dimension].GetChunk(chunkLocation.X, chunkLocation.Y);

            ItemAdder.RememberWhichChunk(chunkLocation, item.ItemID, dimension);
            ItemAdder.RememberWhichTile(item, mapLocation, chunk, dimension);
            ItemAdder.StoreItem(chunk, mapLocation, item);
        }
예제 #5
0
        /// <summary>
        /// Adds an item during the ongoing world generation.
        /// </summary>
        public static void AddItemWorldGen(Item item, Point2D mapLocation, ProtoArray <Chunk> map, int dimension)
        {
            Point2D chunkLocation = WorldUtil.CalculateChunkLocation(mapLocation);
            Chunk   chunk         = map[chunkLocation.X, chunkLocation.Y];

            ItemAdder.RememberWhichChunk(chunkLocation, item.ItemID, dimension);
            ItemAdder.RememberWhichTile(item, mapLocation, chunk, dimension);
            ItemAdder.StoreItem(chunk, mapLocation, item);
        }
예제 #6
0
        /// <summary>
        /// Starts the internal tick system, and begins running game logic.
        /// </summary>
        public static void StartGame()
        {
            foreach (KeyValuePair <Guid, JobSystem.JobSystem> item in JobSystem.JobSystemManager.Manager.PlayerToJobSystem)
            {
                if (item.Value.Idle.Count == 0 && item.Value.Busy.Count == 0)
                {
                    //Spawns a creature in the default dimension (0).
                    WorldUtil.SpawnRandomCharacter(item.Key, 0);
                }
            }

            SetupTick();
        }
예제 #7
0
        protected override void StartJob(Living living)
        {
            List <Point2D> result = WorldUtil.GetNeighboringTiles(this.Target, living.Dimension);

            result.RemoveAll(x => !World.Data.World.GetTile(living.Dimension, x.X, x.Y).IsWalkable);

            int closestIndex = Algorithms.GetClosestPoint2D(result, living.MapLocation);

            this.AdjacentLocation = result[closestIndex];
            List <PathLink> path = MainPathFinder.GetRoute(living.Dimension, living.MapLocation, result[closestIndex]);

            living.QueuedMovement.Clear();
            Extensions.EnqueueCollection(living.QueuedMovement, path);
        }
예제 #8
0
        /// <summary>
        /// Adds an item to the specified map location.
        /// </summary>
        public static void AddItem(Item item, Point2D mapLocation, int dimension)
        {
            if (World.Data.World.Mode != Networking.EngineMode.ServerOnly)
            {
                NetworkAdd(item, mapLocation, dimension);
            }

            Point2D chunkLocation = WorldUtil.CalculateChunkLocation(mapLocation);
            Chunk   chunk         = World.Data.World.Dimensions[dimension].GetChunk(chunkLocation.X, chunkLocation.Y);

            ItemAdder.RememberWhichChunk(chunkLocation, item.ItemID, dimension);
            ItemAdder.RememberWhichTile(item, mapLocation, chunk);
            ItemAdder.StoreItem(chunk, mapLocation, item);
        }
예제 #9
0
        private void InputHistory_InputAdded()
        {
            HistoricalInput historical = InputHistory.History.Last();

            if (historical.ActionSelected == ActionSelected.None && historical.Selected.Count == 1)
            {
                Point2D mapLocation = historical.Selected[0].MapLocation;
                Living  creature    = WorldUtil.GetCreature(mapLocation, RenderInfo.Dimension);

                if (creature != null)
                {
                    CharacterMenu.Initialize(creature);
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Stores an item in the specified tile.
        /// If the tile is already full or cannot accept all of the item(s) being added,
        /// then this method returns any excess.
        /// Otherwise, this method returns null.
        /// </summary>
        internal static Item StoreItem(Chunk chunk, Point2D mapLocation, Item item)
        {
            Tile tile     = WorldUtil.GetTile(mapLocation, chunk);
            Item overflow = null;

            if (tile.Item == null)
            {
                tile.Item = item;
            }
            else
            {
                Item final = Item.Combine(tile.Item, item, out overflow);
            }

            return(overflow);
        }
예제 #11
0
        /// <summary>
        /// Locates a certain quantity of a requested item that isn't reserved, and returns their locations.
        /// Returns null if not enough items were found to satisfy the request.
        /// </summary>
        /// <returns></returns>
        public static List <Point2D> LocateUnreservedQuantityOfItem(int itemID, int quantityDesired, Point2D startingPoint, int dimension)
        {
            List <Point2D> nearestChunks = FindNearestChunks(itemID, startingPoint, dimension);

            int            quantityFound = 0;
            List <Point2D> locations     = new List <Point2D>();

            if (nearestChunks != null)
            {
                Chunk          chunk;
                List <Point2D> allResults = new List <Point2D>();//Holds all found item locations.
                foreach (Point2D item in nearestChunks)
                {
                    chunk = World.Data.World.GetChunk(dimension, item.X, item.Y);
                    RTree <Point2D> items  = chunk.Items[itemID];
                    List <Point2D>  result = items.Intersects(new Rectangle(WorldUtil.GetFirstTileLocation(chunk.ChunkLocation), WorldUtil.GetLastTileLocation(chunk.ChunkLocation)));
                    allResults.AddRange(result);
                }

                //Orders all items found by their proximity to the starting location.
                Geometry.OrderPointsByProximity(startingPoint, allResults);

                int length = allResults.Count;
                for (int i = 0; i < length && quantityFound < quantityDesired; i++)
                {
                    Point2D item       = allResults[i];
                    Tile    containing = World.Data.World.GetTile(dimension, item.X, item.Y);
                    Item    tileItem   = containing.MainObject as Item;
                    if (tileItem.ReservedID.Equals(Guid.Empty))
                    {
                        locations.Add(item);
                        quantityFound += tileItem.CurrentlyStacked;
                    }
                }
            }

            if (quantityFound >= quantityDesired)
            {
                return(locations);
            }
            else
            {
                return(null);
            }
        }
예제 #12
0
        public override void MakePreparations(Living l)
        {
            List <Point2D> result = WorldUtil.GetNeighboringTiles(this.Target, l.Dimension);

            result.RemoveAll(x => !World.Data.World.GetTile(l.Dimension, x.X, x.Y).IsWalkable);

            int closestIndex = Algorithms.GetClosestPoint2D(result, l.MapLocation);

            this.AdjacentLocation = result[closestIndex];
            List <PathLink> path = MainPathFinder.GetRoute(l.Dimension, l.MapLocation, result[closestIndex]);

            if (World.Data.World.Mode == Networking.EngineMode.ClientOnly)
            {
                ClientSendRecieve.Send(new RouteCreatedMessage(path, l.ID, l.Dimension));
            }

            l.QueuedMovement.Clear();
            Extensions.EnqueueCollection(l.QueuedMovement, path);
        }
예제 #13
0
        public override bool CreateDependencies(Living l)
        {
            List <Point2D> result = WorldUtil.GetNeighboringTiles(this.Target, l.Dimension);

            result.RemoveAll(x => !World.Data.World.GetTile(l.Dimension, x.X, x.Y).IsWalkable);

            ComponentSelectable entitySelected   = l.GetExactComponent <ComponentSelectable>();
            Point2D             adjacentLocation = PathUtil.GetFirstReachable(result, entitySelected.MapLocation, l.Dimension);

            if (adjacentLocation == null)
            {
                return(false);
            }
            else
            {
                MoveTask task = new MoveTask(this.BoundID, adjacentLocation);
                this.Dependencies.PreRequisite.Add(task);
                return(true);
            }
        }
예제 #14
0
        public bool hasSpaceToGrow(World world, Random rand, PixelPos pos, int treeHeight)
        {
            WorldUtil worldUtil = new WorldUtil(world);

            if (!worldUtil.isSurroundedByPixel(
                    Pixels.AIR,
                    treeHeight,
                    WorldUtil.SurroundCheckType.UP,
                    rand,
                    pos.getX(),
                    pos.getY(),
                    pos.getZ()
                    ))
            {
                //Logger.debug("Unable to grow RTG tree with %d height. Something in the way.", treeHeight);

                return(false);
            }

            return(true);
        }
예제 #15
0
        /// <summary>
        /// Stores an item in the specified tile.
        /// If the tile is already full or cannot accept all of the item(s) being added,
        /// then this method returns any excess.
        /// Otherwise, this method returns null.
        /// </summary>
        internal static Item StoreItem(Chunk chunk, Point2D mapLocation, Item item)
        {
            Tile tile     = WorldUtil.GetTile(mapLocation, chunk);
            Item overflow = null;

            if (tile.MainObject == null)
            {
                tile.MainObject = item;
            }
            else
            {
                Item existing = tile.MainObject as Item;
                if (existing == null)
                {
                    throw new UnexpectedStateException("Invalid addition of an item to a tile with an object of another type occuping the main object slot.");
                }
                tile.MainObject = Item.Combine(existing, item, out overflow);
            }

            return(overflow);
        }
예제 #16
0
        /// <summary>
        /// Starts the internal tick system, and begins running game logic.
        /// </summary>
        public static void StartGame()
        {
            if (World.Mode == EngineMode.ServerOnly)
            {
                foreach (KeyValuePair <Guid, System.Net.Sockets.Socket> item
                         in ServerSendRecieve.TCPServer.PlayerToSocket)
                {
                    WorldUtil.SpawnRandomCharacter(item.Key, 0);
                    WorldUtil.SpawnRandomCharacter(item.Key, 0);
                    WorldUtil.SpawnRandomCharacter(item.Key, 0);
                }
            }

            if (World.Mode == EngineMode.ServerAndClient)
            {
                WorldUtil.SpawnRandomCharacter(Player.Default.PlayerID, 0);
                WorldUtil.SpawnRandomCharacter(Player.Default.PlayerID, 0);
                WorldUtil.SpawnRandomCharacter(Player.Default.PlayerID, 0);
            }

            SetupTick();
        }
예제 #17
0
        public override void HandleMessage(BaseMessage message)
        {
            RouteCreatedMessage msg = (RouteCreatedMessage)message;

            if (this.Validated(msg.Path, msg.Dimension))
            {
                Point2D location      = msg.Path[0].Origin;
                Point2D chunkLocation = WorldUtil.CalculateChunkLocation(location);
                Chunk   chunk         = World.GetChunk(msg.Dimension, chunkLocation.X, chunkLocation.Y);

                Living l = chunk.Creatures.Where(t => t.Value.MapLocation.Equals(location)).ElementAt(0).Value;

                if (l != null && l.ID == msg.LivingID)
                {
                    l.QueuedMovement.Clear();
                    MagicalLifeAPI.Util.Extensions.EnqueueCollection <PathLink>(l.QueuedMovement, msg.Path);
                }
            }
            else
            {
                MasterLog.DebugWriteLine("Server received invalid path");
            }
        }
예제 #18
0
        private async Task OnTick()
        {
            await Delay(100);

            if (Game.PlayerPed.IsDead)
            {
                wastedScaleform = new Scaleform("MP_BIG_MESSAGE_FREEMODE");
                died            = true;
                Screen.Effects.Start(ScreenEffect.DeathFailMpIn);
                Audio.PlaySoundFrontend("Bed", "WastedSounds");
                await Delay(10000);

                Screen.Fading.FadeOut(500);
                await Delay(3000);

                Game.PlayerPed.Position = WorldUtil.GetClosestImmersiveStreetSpawn(Game.PlayerPed.Position, 100f);
                Game.PlayerPed.Resurrect();
                Screen.Fading.FadeIn(500);
                Screen.Effects.Stop(ScreenEffect.DeathFailMpIn);
                died = false;
                wastedScaleform.Dispose();
            }
        }
예제 #19
0
        /// <summary>
        /// Lets a chunk know that there is an item of the specified type in the specified tile position.
        /// </summary>
        private static void RememberWhichTile(Item item, Point2D mapLocation, Chunk chunk)
        {
            if (!chunk.Items.ContainsKey(item.ItemID))
            {
                //chunk.Items doesn't store one key and value for every item in the game upfront.
                chunk.Items.Add(item.ItemID, new RTree <Point2D>());
            }

            RTree <Point2D> itemLocations = chunk.Items[item.ItemID];
            List <Point2D>  result        = itemLocations.Contains(new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y));

            if (result.Count > 0)
            {
                //The chunk already knows that there is an item of the specified type in the specified position.
            }
            else
            {
                Rectangle           r          = new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y);
                Tile                tile       = WorldUtil.GetTile(mapLocation, chunk);
                ComponentSelectable selectable = tile.GetExactComponent <ComponentSelectable>();

                itemLocations.Add(r, selectable.MapLocation);
            }
        }
예제 #20
0
        /// <summary>
        /// Lets a chunk know that there is an item of the specified type in the specified tile position.
        /// </summary>
        internal static void RememberWhichTile(Item item, Point2D mapLocation, Chunk chunk, int dimension)
        {
            if (!chunk.Items.ContainsKey(item.ItemID))
            {
                //chunk.Items doesn't store one key and value for every item in the game upfront.
                chunk.Items.Add(item.ItemID, new RTree <Point2D>());
            }

            RTree <Point2D> itemLocations = chunk.Items[item.ItemID];
            List <Point2D>  result        = itemLocations.Contains(new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y));

            if (result.Count > 0)
            {
                //The chunk already knows that there is an item of the specified type in the specified position.
            }
            else
            {
                itemLocations.Add(new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y), WorldUtil.GetTile(mapLocation, chunk).MapLocation);
            }
        }
예제 #21
0
        override public bool generate(World world, Random rand, PixelPos pos)
        {
            int x = pos.getX();
            int y = pos.getY();
            int z = pos.getZ();

            int randomFlower = flowers[rand.Next(flowers.Length)];

            if (randomFlower > 9)
            {
                //for (int l = 0; l < 64; ++l)
                {
                    int i1 = x; // + rand.nextInt(8) - rand.nextInt(8);
                    int j1 = y; // + rand.nextInt(4) - rand.nextInt(4);
                    int k1 = z; // + rand.nextInt(8) - rand.nextInt(8);

                    Pixel     doublePlant    = PixelUtil.getStateFlower(randomFlower);
                    PixelPos  doublePlantPos = new PixelPos(i1, j1, k1);
                    WorldUtil worldUtil      = new WorldUtil(world);

                    if (world.isAirPixel(doublePlantPos) &&
                        (j1 < 254))
                    {
                        worldUtil.setDoublePlant(doublePlantPos, doublePlant);
                    }
                }
            }
            else if (randomFlower == 9)
            {
                //for (int l = 0; l < 64; ++l)
                {
                    int i1 = x; // + rand.nextInt(8) - rand.nextInt(8);
                    int j1 = y; // + rand.nextInt(4) - rand.nextInt(4);
                    int k1 = z; // + rand.nextInt(8) - rand.nextInt(8);

                    Pixel    flower    = PixelUtil.getStateFlower(randomFlower);
                    PixelPos flowerPos = new PixelPos(i1, j1, k1);

                    if (world.isAirPixel(flowerPos) &&
                        (j1 < 254))
                    {
                        world.setPixelState(flowerPos, flower.getPixelID(), 2);
                    }
                }
            }
            else
            {
                //for (int l = 0; l < 64; ++l)
                {
                    int i1 = x; // + rand.nextInt(8) - rand.nextInt(8);
                    int j1 = y; // + rand.nextInt(4) - rand.nextInt(4);
                    int k1 = z; // + rand.nextInt(8) - rand.nextInt(8);

                    Pixel    flower    = PixelUtil.getStateFlower(randomFlower);
                    PixelPos flowerPos = new PixelPos(i1, j1, k1);

                    if (world.isAirPixel(flowerPos) &&
                        (j1 < 254))
                    {
                        world.setPixelState(flowerPos, flower.getPixelID(), 2);
                    }
                }
            }

            return(true);
        }
예제 #22
0
 public void SetLightLevel(int lightLevel)
 {
     LightLevel           = lightLevel;
     LightLevelNormalized = WorldUtil.ToDoomLightLevel(lightLevel);
 }
예제 #23
0
        public bool generate(World world, Random rand, int x, int y, int z)
        {
            Pixel g = world.getPixelState(new PixelPos(x, y - 1, z));

            if (g == Pixels.DIRT && g != Pixels.GRASS && g != Pixels.SAND && g != Pixels.STONE)
            {
                return(false);
            }

            WorldUtil worldUtil = new WorldUtil(world);
            int       dir       = rand.Next(2); // The direction of the log (0 = X; 1 = Z)
            int       i;
            Pixel     b;
            int       air = 0;

            List <int>   aX     = new List <int>();
            List <int>   aY     = new List <int>();
            List <int>   aZ     = new List <int>();
            List <Pixel> aPixel = new List <Pixel>();

            for (i = 0; i < logLength; i++)
            {
                b = world.getPixelState(new PixelPos(x - (dir == 0 ? 1 : 0), y, z - (dir == 1 ? 1 : 0)));
                if (b.getPixelID() != Pixels.AIR.getPixelID() && b.getPixelID() != Pixels.VINE.getPixelID() && b.getPixelID() != Pixels.DOUBLE_PLANT.getPixelID() && b.getPixelID() != Pixels.RED_FLOWER.getPixelID() && b.getPixelID() != Pixels.YELLOW_FLOWER.getPixelID())
                {
                    break;
                }

                x -= dir == 0 ? 1 : 0;
                z -= dir == 1 ? 1 : 0;

                if (airCheck(world, rand, x, y, z) > 0)
                {
                    return(false);
                }
            }

            for (i = 0; i < logLength * 2; i++)
            {
                b = world.getPixelState(new PixelPos(x + (dir == 0 ? 1 : 0), y, z + (dir == 1 ? 1 : 0)));
                if (b.getPixelID() != Pixels.AIR.getPixelID() && b.getPixelID() != Pixels.VINE.getPixelID() && b.getPixelID() != Pixels.DOUBLE_PLANT.getPixelID() && b.getPixelID() != Pixels.RED_FLOWER.getPixelID() && b.getPixelID() != Pixels.YELLOW_FLOWER.getPixelID())
                {
                    break;
                }

                air += airCheck(world, rand, x, y, z);
                if (air > 2)
                {
                    return(false);
                }

                /**
                 * Before we place the log block, let's make sure that there's an air block immediately above it.
                 * This is to ensure that the log doesn't override, for example, a 2-block tall plant,
                 * which some mods (like WAILA) have trouble handling.
                 *
                 * Also, to ensure that we don't have 'broken' logs, if one log block fails the check,
                 * then no logs actually get placed.
                 */
                if (!worldUtil.isPixelAbove(Pixels.AIR, 1, world, x, y, z, true))
                {
                    //Logger.debug("Found non-air block above log at %d %d %d", x, y, z);
                    return(false);
                }

                // Store the log information instead of placing it straight away.
                aX.Add(x);
                aY.Add(y);
                aZ.Add(z);

                // If we can't rotate the log block for whatever reason, then just place it as it is.
                try
                {
                    aPixel.Add(logPixel.withProperty(dir == 0 ? (int)PixelLog.EnumAxis.X : (int)PixelLog.EnumAxis.Z));
                }
                catch (Exception e)
                {
                    aPixel.Add(logPixel);
                }

                if (this.generateLeaves)
                {
                    addLeaves(world, rand, dir, x, y, z);
                }

                x += dir == 0 ? 1 : 0;
                z += dir == 1 ? 1 : 0;
            }

            for (int i1 = 0; i1 < aPixel.Count; i1++)
            {
                world.setPixelState(new PixelPos(aX[i1], aY[i1], aZ[i1]), aPixel[i1].getPixelID(), 2);
            }

            return(true);
        }