Пример #1
0
        private void MakeNewMap()
        {
            CurrentLevel = new Guardian_Roguelike.World.Map();
            Utilities.InterStateResources.Instance.Resources["Game_CurrentLevel"] = CurrentLevel;
            MapCons.Clear();
            CurrentLevel.Creatures.Add(Player);
            Player.Level = CurrentLevel;
            CurrentLevel.DestroyTile(Player.Position);
            LevelNumber++;

            //Place a dwarf randomly
            Random RandGen = new Random();

            while (true)
            {
                int dx = RandGen.Next(0, 90);
                int dy = RandGen.Next(0, 30);

                if (CurrentLevel.CheckWalkable(dx, dy))
                {
                    World.Creatures.GiantRat Olon = new World.Creatures.GiantRat();
                    Olon.Generate();
                    Olon.Position = new System.Drawing.Point(dx, dy);
                    Olon.MyAI     = new AI.FSM_Aggressive(Olon);
                    CurrentLevel.Creatures.Add(Olon);
                    break;
                }
            }
        }
Пример #2
0
        public override void LoadContent(ContentManager Content, GraphicsDevice graphicsDevice)
        {
            base.LoadContent(Content, graphicsDevice);

            spriteBatch = new SpriteBatch(graphicsDevice);

            GameSettings.SetDefault();

            GameSettings.gameState = GameState.Explore;

            textures = new TextureManager(Content);

            world = new World.GameWorld(textures, Content);

            world.Event   += HandleEvents;
            player         = new Object.Player(textures.playerSpriteSheet, textures, world.GetPlayerStart(), 100, new Point(16, 16), new Point(2, 0), 0.1f);
            player.Action += HandleEvents;

            Viewport view = graphicsDevice.Viewport;
            float    zoom = 5f;

            hud = new HUDManager(textures, graphicsDevice, Content, player, GameSettings.windowWidth, GameSettings.windowHeight);
            cam = new Camera2D(hud, view, GameSettings.windowWidth, GameSettings.windowHeight, world, zoom);

            combat        = new Combat(player, textures, hud);
            combat.Event += HandleEvents;
        }
        private static void FindEnemy(Unit u, World.Map worldMap)
        {
            if (!u.IsAggressive)
            {
                return;
            }

            Tile t = worldMap.GetTile((int)u.position.X, (int)u.position.Y);

            // Search for units
            lock (t.GetUnits())
            {
                foreach (Unit ou in t.GetUnits(u.owner.Enemy))
                {
                    // Is he dead already?
                    if (ou.isDead)
                    {
                        continue;
                    }

                    // FIGHT TO THE DEATH!
                    u.TargetEntity = ou;
                    return;
                }
            }

            // Is there a building to kill?
            if (t.GetBuilding() != null && t.GetBuilding().owner != u.owner)
            {
                u.TargetEntity = t.GetBuilding();
                return;
            }
        }
Пример #4
0
 public MapEvent(World w, int x, int y, EventType type)
     : base(w, type)
 {
     this.x = x;
     this.y = y;
     map    = w.GetMap();
     tile   = map.GetTile(x, y);
 }
Пример #5
0
 public void OnChangedMap(Player playr)
 {
     World.Map curmap = playr.Position.CurMap;
     if (curmap.MapTiles != null)
     {
         gameLink.Send((new GameOutMessage.LoadTiles(curmap).Compile()));
     }
     gameLink.Send((new GameOutMessage.LoadWorld(this, curmap).Compile()));
     //gameLink.Send((new GameOutMessage.UpdateCharStats(this).Compile()));
     //gameLink.Send((new GameOutMessage.SetLevelGold(this).Compile()));
 }
Пример #6
0
        protected override void OnEnterMap(World.Map map)
        {
            base.OnEnterMap(map);

            if (!IsAlive && IsClient)
            {
                Anim.StartFrame = 24;
                Anim.FrameCount = 1;
                Anim.Stop();
                Anim.Reset();
            }
        }
Пример #7
0
 public Hero(string heroName, int health, int str, int agi, List <Armor> listOfArmor, List <Armor> listOfWeapons, List <Potion> potions, World.World worldHero, Map mapHero, int x, int y)
 {
     this.heroName      = heroName;
     this.health        = health;
     this.str           = str;
     this.agi           = agi;
     this.listOfArmor   = listOfArmor;
     this.listOfWeapons = listOfWeapons;
     this.potions       = potions;
     this.worldHero     = worldHero;
     this.mapHero       = mapHero;
     this.x             = x;
     this.y             = y;
 }
        /// <summary>
        /// Call the update method on each unit causing them to move towards their baseEntity.
        /// If the unit has arrived to its baseEntity, it will recieve new orders. If it was previously
        /// travelling to a fromBuilding, it will be joined with that fromBuilding upon arrival.
        /// </summary>
        /// <param name="units">The set of units to be updated</param>
        /// <param name="systemTime">The time passed since something</param>
        public static void Update(IEnumerable <Unit> units, int systemTime, World.Map worldMap)
        {
            lock (units)
            {
                foreach (Unit u in units)
                {
                    // Try to find enemies for this unit!
                    FindEnemy(u, worldMap);

                    // Update position
                    u.Update(systemTime);
                }

                RemoveDeadUnits();
            }
        }
Пример #9
0
        protected override void OnEnterMap(World.Map map)
        {
            if (IsClient)
            {
                myLight = new Light
                {
                    LightColour = new World.LightColour(1.0f, 1.0f, 1.0f),
                    Range       = 3.0
                };

                myLight.OriginX = OriginX;
                myLight.OriginY = OriginY - 0.25;

                myLight.Map = map;
                myLight.Update();

                myMap = map;
            }
        }
        public void Run()
        {
            Selection sel = new Selection();

            logger.Info("Logger started");

            sel.state = State.NONE;
            finished  = false;
            while (!finished)
            {
                previousSelection = sel;

                // Generate the appropriate menu for this state.
                // Get the active GUI Region and invoke the associated method.

                sel = retrieveSelection();

                World.Map map = theWorld.GetMap();

                switch (sel.state)
                {
                case State.BUILDING:
                case State.TILE:
                    SelectTile(map.GetTile(sel.absPoint));
                    break;

                case State.OFFSCREEN:
                    if (sel.point.X == -1)
                    {
                        ContextMenu();
                    }
                    if (sel.point.X == 1)
                    {
                        GameMenu();
                    }
                    break;
                }
            }
        }
Пример #11
0
        protected override void OnEnterMap(World.Map map)
        {
            base.OnEnterMap(map);

            if (IsClient)
            {
                myLight = new Light
                {
                    LightColour = new World.LightColour(myColour.R, myColour.G, myColour.B),
                    Range       = 2.0
                };

                mySparks        = new List <Spark>();
                myLastSparkTime = 0;

                for (int i = 0; i < 16; ++i)
                {
                    mySparks.Add(new Spark(this, 2.0));
                }

                map.AddEntity(myLight);
            }
        }
Пример #12
0
            public LoadWorld(Player.Player player, World.Map map)
                : base(0x1B)
            {
                Write((byte)map.Time);
                Write((int)player.objId);
                Write((byte)2);
                Fill(3);
                Write((short)player.Position.Face);
                Write((short)player.Position.X);
                Write((short)player.Position.Y);

                Write(player.Appearance, 0, 11);
                // Write((byte)1);
                // Fill(8);
                // Write((short)15); //sprite

                Write((byte)player.Color); //color
                Write((byte)1);
                Write((byte)player.LightRadius);
                Write((byte)player.Transparency);

                Write(player.BuffArray, 0, 4);

                Write((byte)0);                //spawn buff

                Write((byte)player.FrameType); //sprite type

                Write((byte)0x0);
                Write((byte)0x0);

                StringBuilder fmap = new StringBuilder();

                fmap.AppendFormat(string.Format("{0},{1}", map.diskName, map.Name));
                Write((short)fmap.Length);
                WriteAsciiNull(fmap.ToString());
            }
        /// <summary>
        /// Loads the Building menu from a selection.
        /// Must have building on tile.
        /// </summary>
        /// <param name="theSelection"></param>
        private void BuildingMenu()
        {
            World.Map map      = theWorld.GetMap();
            Building  building = selectedTile.GetBuilding();

            if (building == null || building.owner != playerInControll)
            {
                return;
            }
            int toHeal = Math.Min(building.maxHealth - building.currentHealth, building.units.Count());

            MenuIcon setWeight    = new MenuIcon(Language.Instance.GetString("SetWeight"));
            MenuIcon buildCell    = new MenuIcon(Language.Instance.GetString("BuildCell"));
            MenuIcon removeCell   = new MenuIcon(Language.Instance.GetString("RemoveCell"));
            MenuIcon upgradeUnits = new MenuIcon(Language.Instance.GetString("UpgradeUnits") + " (" + playerInControll.unitAcc.GetUpgradeCost() + ")");
            MenuIcon moveUnits    = new MenuIcon(Language.Instance.GetString("MoveUnits"));
            MenuIcon repairCell   = new MenuIcon(Language.Instance.GetString("RepairCell") + " (" + toHeal + ")");
            MenuIcon setAggro     = new MenuIcon(Language.Instance.GetString("SetAggro"));
            MenuIcon Cancel       = new MenuIcon(Language.Instance.GetString("Cancel"), Recellection.textureMap.GetTexture(Globals.TextureTypes.No));

            List <MenuIcon> menuIcons = new List <MenuIcon>();

            menuIcons.Add(setWeight);
            menuIcons.Add(buildCell);
            menuIcons.Add(removeCell);
            menuIcons.Add(upgradeUnits);
            menuIcons.Add(moveUnits);
            menuIcons.Add(repairCell);
            menuIcons.Add(setAggro);
            menuIcons.Add(Cancel);

            Menu buildingMenu = new Menu(Globals.MenuLayout.NineMatrix, menuIcons, Language.Instance.GetString("BuildingMenu"), Color.Black);

            MenuController.LoadMenu(buildingMenu);
            Recellection.CurrentState = MenuView.Instance;
            MenuIcon choosenMenu = MenuController.GetInput();

            Recellection.CurrentState = WorldView.Instance;
            MenuController.UnloadMenu();

            if (choosenMenu.Equals(setWeight))
            {
                GraphController.Instance.SetWeight(building);
            }
            else if (choosenMenu.Equals(buildCell))
            {
                tobii.SetFeedbackColor(Color.DarkGreen);
                Selection destsel;
                do
                {
                    SetConstructionLines(BuildingController.GetValidBuildingInterval(selectedTile.position, theWorld));
                    destsel = retrieveSelection();
                    RemoveconstructionTileLines(BuildingController.GetValidBuildingInterval(selectedTile.position, theWorld));
                }while (destsel.state != State.TILE);

                tobii.SetFeedbackColor(Color.White);

                SelectTile(map.GetTile(destsel.absPoint));

                //TODO Add a check to see if the tile is a correct one. The diffrence between the selected tiles coordinates and the source building shall not exceed 3.
                if (selectedTile.GetBuilding() == null)
                {
                    try
                    {
                        BuildingController.ConstructBuilding(playerInControll, selectedTile, building, theWorld);
                        tobii.SetFeedbackColor(Color.White);
                    }
                    catch (BuildingController.BuildingOutOfRangeException)
                    {
                        logger.Debug("Caught BuildingOutOfRangeExcpetion");
                    }
                }
                else
                {
                    //SoundsController.playSound("Denied");
                    tobii.SetFeedbackColor(Color.White);
                    return;
                }
            }
            else if (choosenMenu.Equals(removeCell))
            {
                BuildingController.RemoveBuilding(building);
            }
            else if (choosenMenu.Equals(upgradeUnits))
            {
                upgradeMenu();
            }
            else if (choosenMenu.Equals(moveUnits))
            {
                tobii.SetFeedbackColor(Color.Red);

                Selection destsel = retrieveSelection();
                if (destsel.state == State.BUILDING || destsel.state == State.TILE)
                {
                    Tile selTile = map.GetTile(destsel.absPoint);
                    UnitController.MoveUnits(playerInControll, selectedTile, selTile, building.GetUnits().Count);
                }

                tobii.SetFeedbackColor(Color.White);
            }
            else if (choosenMenu.Equals(repairCell))
            {
                playerInControll.unitAcc.DestroyUnits(building.units, toHeal);
                building.Repair(toHeal);
            }
            else if (choosenMenu.Equals(setAggro))
            {
                building.IsAggressive = !building.IsAggressive;
                building.UpdateAggressiveness(null, new Event <IEnumerable <Unit> >(building.GetUnits(), EventType.ADD));
            }
            else if (choosenMenu.Equals(Cancel))
            {
                return;
            }
            else
            {
                return;
            }
        }
Пример #14
0
 public LoadTiles(World.Map map)
     : base(0x35)
 {
     Write((short)map.MapTiles.Length);
     WriteAsciiNull(map.MapTiles);
 }
Пример #15
0
 /// <summary>
 /// Creates a LobbySaveData instance from a Map
 /// </summary>
 public static LobbySaveData FromMap(World.Map map)
 {
     return(new LobbySaveData(map.Name, map.ID, map.Description, map.Online, map.Plays, map.Rating));
 }
Пример #16
0
 private void RegenerateMap()
 {
     map = mapProvider.Get();
     RerenderMap();
 }
Пример #17
0
        public GameState() : base()
        {
            DEBUG_PassedMilliseconds = 0;
            SkipAI  = false;
            CurMode = Modes.Normal;
            if (Utilities.InterStateResources.Instance.Resources.ContainsKey("Game_FOVHandler"))
            {
                Utilities.InterStateResources.Instance.Resources.Remove("Game_FOVHandler");
            }
            if (Utilities.InterStateResources.Instance.Resources.ContainsKey("Game_PathFinder"))
            {
                Utilities.InterStateResources.Instance.Resources.Remove("Game_PathFinder");
            }
            if (Utilities.InterStateResources.Instance.Resources.ContainsKey("Game_CurrentLevel"))
            {
                Utilities.InterStateResources.Instance.Resources.Remove("Game_CurrentLevel");
            }
            if (Utilities.InterStateResources.Instance.Resources.ContainsKey("Game_NotableEventsLog"))
            {
                Utilities.InterStateResources.Instance.Resources.Remove("Game_NotableEventsLog");
            }
            if (Utilities.InterStateResources.Instance.Resources.ContainsKey("Game_DeathData"))
            {
                Utilities.InterStateResources.Instance.Resources.Remove("Game_DeathData");
            }

            Utilities.InterStateResources.Instance.Resources.Add("Game_FOVHandler", new libtcodWrapper.TCODFov(90, 30));
            Utilities.InterStateResources.Instance.Resources.Add("Game_PathFinder", new libtcodWrapper.TCODPathFinding((libtcodWrapper.TCODFov)Utilities.InterStateResources.Instance.Resources["Game_FOVHandler"], 1));
            Utilities.InterStateResources.Instance.Resources.Add("Game_CurrentLevel", new World.Map());

            /*
             * World.Creatures.Dwarf tPlayer = new Guardian_Roguelike.World.Creatures.Dwarf();
             * tPlayer.Position.X = tPlayer.Position.Y = 1;
             * tPlayer.FirstName = "Urist";
             * tPlayer.LastName = "Litasterar";
             * tPlayer.DrawColor = libtcodWrapper.ColorPresets.ForestGreen;*/
            if (Utilities.InterStateResources.Instance.Resources.ContainsKey("Game_PlayerCreature"))
            {
                Utilities.InterStateResources.Instance.Resources.Remove("Game_PlayerCreature");
            }
            World.Creatures.CreatureBase tPlayer = new World.Creatures.Dwarf();
            tPlayer.Generate();
            tPlayer.DrawColor = libtcodWrapper.ColorPresets.ForestGreen;

            Utilities.InterStateResources.Instance.Resources.Add("Game_PlayerCreature", tPlayer);

            StatusCons = libtcodWrapper.RootConsole.GetNewConsole(90, 5);

            MapCons = libtcodWrapper.RootConsole.GetNewConsole(90, 30);

            MsgCons = libtcodWrapper.RootConsole.GetNewConsole(90, 5);


            Player               = (World.Creatures.Dwarf)Utilities.InterStateResources.Instance.Resources["Game_PlayerCreature"];
            Player.BaseAim      += 2;
            Player.BaseEnergy   += 2;
            Player.BaseSpeed    += 2;
            Player.BaseStrength += 2;
            Player.BaseVigor    += 2;
            Player.FirstName     = "Urist";
            Player.LastName      = "Litasterar";

            CurrentLevel = (World.Map)Utilities.InterStateResources.Instance.Resources["Game_CurrentLevel"];
            CurrentLevel.Creatures.Add(Player);

            Player.Position = CurrentLevel.GetFirstWalkable();

            Utilities.MessageLog.AddMsg("Get running, " + Player.FirstName + "!");

            TurnsPassed = SkipTurns = 0;

            LevelNumber = 1;

            Utilities.InterStateResources.Instance.Resources.Add("Game_DeathData", new Utilities.DeathData(Player, null, 0, 1));
        }