Пример #1
0
        //Fixes the map dungeon location when the map is used and consumed, expands the search range if necessary
        static void Prefix(dmAdventureMap mapItem)
        {
            LocValue  goalLocation    = mapItem.goalLocation;
            bool      tileAlreadyUsed = false;
            WorldTile checkTile       = dmUtilities.theGame.theWorld.GetTile(goalLocation);

            foreach (dmObject item in checkTile.ContainedObjects())
            {
                if (item is dmGateway)
                {
                    tileAlreadyUsed = true;
                }
            }
            if (tileAlreadyUsed)
            {
                int  range = 2;
                bool locationFoundCanStop = false;
                while (!locationFoundCanStop)
                {
                    List <LocValue> possibleLocations = new List <LocValue>();
                    for (int i = goalLocation.X - range; i < goalLocation.X + range; i++)
                    {
                        for (int j = goalLocation.Y - range; j < goalLocation.Y + range; j++)
                        {
                            LocValue  locValue = new LocValue(i, j);
                            WorldTile tile     = dmUtilities.theGame.theWorld.GetTile(locValue);

                            bool newTileAlreadyUsed = false;
                            foreach (dmObject item in tile.ContainedObjects())
                            {
                                if (item is dmGateway)
                                {
                                    newTileAlreadyUsed = true;
                                }
                            }
                            if ((tile.iTerrain == TerrainType.TT_PLAINS || tile.iTerrain == TerrainType.TT_FOREST || tile.iTerrain == TerrainType.TT_BADLANDS) &&
                                !newTileAlreadyUsed)
                            {
                                possibleLocations.Add(locValue);
                            }
                        }
                    }
                    if (possibleLocations.Count > 0)
                    {
                        goalLocation         = possibleLocations[dmUtilities.RandomInt() % possibleLocations.Count];
                        locationFoundCanStop = true;
                    }
                    if (possibleLocations.Count < 5)
                    {
                        range += 1;
                        if (range > 20)
                        {
                            locationFoundCanStop = true;
                        }
                    }
                }
            }
            mapItem.goalLocation = goalLocation;
        }
Пример #2
0
        //New map generation code that looks for all possible locations and randomly pick one from a list
        static void Postfix(dmAdventureMap __instance, bool __result)
        {
            dmGame theGame = dmUtilities.theGame;

            int[] array = new int[5]
            {
                45,
                50,
                58,
                69,
                79
            };
            int maxRange = array[Traverse.Create(__instance).Field("itemTier").GetValue <int>() - 1];

            List <LocValue> possibleLocations      = new List <LocValue>();
            int             maxDontUseThis         = maxRange - 12;
            Rectangle       dontUseInsideRectangle = new Rectangle(0, 0, maxDontUseThis, maxDontUseThis);

            for (int i = 0; i < maxRange; i++)
            {
                for (int j = 0; j < maxRange; j++)
                {
                    LocValue locValue = new LocValue(i, j);
                    if (!dontUseInsideRectangle.Contains(locValue.X, locValue.Y))
                    {
                        WorldTile tile = theGame.theWorld.GetTile(locValue);

                        bool newTileAlreadyUsed = false;
                        foreach (dmObject item in tile.ContainedObjects())
                        {
                            if (item is dmGateway)
                            {
                                newTileAlreadyUsed = true;
                            }
                        }

                        if ((!__instance.bForceSpecificDungeon || tile.iTerrain == TerrainType.TT_PLAINS) &&
                            (tile.iTerrain == TerrainType.TT_PLAINS || tile.iTerrain == TerrainType.TT_FOREST || tile.iTerrain == TerrainType.TT_BADLANDS) &&
                            !newTileAlreadyUsed)
                        {
                            possibleLocations.Add(locValue);
                        }
                    }
                }
            }

            if (possibleLocations.Count > 0)
            {
                __instance.goalLocation = possibleLocations[dmUtilities.RandomInt() % possibleLocations.Count];
                __result = true;
            }
            else
            {
                __result = false;
            }
        }