/// <summary>
        /// Fügt den Player an eine der Startstellen ein
        /// </summary>
        /// <returns>Area in die der Spieler eingefügt wurde</returns>
        /// <param name="player">Player-Instanz</param>
        public void InsertPlayer(Player player)
        {
            Vector2 x = new Vector2((float)rand.NextDouble() - 0.5f, (float)rand.NextDouble() - 0.5f);

            // Den ersten verfügbaren Startplatz finden und nutzen
            Area target = World.Areas.Where(a => a.Startpoints.Count > 0).First();
            player.Position = target.Startpoints[0] + x;
            target.Items.Add(player);
        }
Exemplo n.º 2
0
        public DialogScreen(ScreenComponent manager, Item speaker, Player player, Dialog entry) 
            : base(manager)
        {
            this.speaker = speaker;
            this.player = player;
            current = entry;

            Controls.Add(new Icon(manager) { Position = new Rectangle(10, 10, 24, 24), Texture = speaker.Icon });
            Controls.Add(message = new Label(manager) { Position = new Rectangle(40, 10, manager.GraphicsDevice.Viewport.Width - 50, 30) });
            Controls.Add(list = new DialogList(manager) { });

            list.OnInteract += OnInteract;

            Refill();
        }
        public override void Update(GameTime gameTime)
        {
            // Nur wenn Komponente aktiviert wurde.
            if (!Enabled)
                return;

            // Nur arbeiten, wenn es eine Welt, einen Player und eine aktive Area gibt.
            Area nextArea = game.Local.GetCurrentArea();
            if (game.Simulation.World == null || game.Local.Player == null || nextArea == null)
                return;
            
            // Reset aller Variablen falls sich der Player ändert
            if (player != game.Local.Player)
            {
                player = game.Local.Player;
                coins = player.Inventory.Count(i => i is Coin);
                recoveryTimes.Clear();
            }

            // Reset der Item variablen falls sich die Area ändert
            if (area != nextArea)
            {
                area = nextArea;

                // Recovery Times
                recoveryTimes.Clear();
                foreach (var item in area.Items.OfType<IAttacker>())
                    recoveryTimes.Add(item, item.Recovery);

                // Hitpoints
                hitpoints.Clear();
                foreach (var item in area.Items.OfType<IAttackable>())
                    hitpoints.Add(item, item.Hitpoints);
            }

            // Coins
            int c = player.Inventory.Count(i => i is Coin);
            if (coins < c)
                Play("coin");
            coins = c;

            // Sword
            foreach (var item in area.Items.OfType<IAttacker>())
            {
                TimeSpan recovery;
                if (!recoveryTimes.TryGetValue(item, out recovery))
                {
                    recovery = item.Recovery;
                    recoveryTimes.Add(item, item.Recovery);
                }

                if (recovery < item.Recovery)
                    Play("sword");
                recoveryTimes[item] = item.Recovery;
            }

            // Hit
            foreach (var item in area.Items.OfType<IAttackable>())
            {
                int points;
                if (!hitpoints.TryGetValue(item, out points))
                {
                    points = item.Hitpoints;
                    hitpoints.Add(item, item.Hitpoints);
                }

                if (points > item.Hitpoints)
                    Play("hit");
                hitpoints[item] = item.Hitpoints;
            }
        }
 /// <summary>
 /// Entfernt den angegebenen Spieler wieder aus dem vorhandenen Spiel.
 /// </summary>
 /// <param name="player">Zu entfernenden Spieler</param>
 public void RemovePlayer(Player player)
 {
     if (World == null)
         return;
     
     foreach (var area in World.Areas)
     {
         if (area.Items.Contains(player))
         {
             area.Items.Remove(player);
             break;
         }
     }
 }
 /// <summary>
 /// Zeigt einen Interaktionsdialog an.
 /// </summary>
 public void ShowInteractionScreen(Player player, Screen screen)
 {
     if (player == game.Local.Player)
     {
         game.Screen.ShowScreen(screen);
     }
 }