Example #1
0
        public void Update(Camera camera, Control control, SpriteFont font)
        {
            #region Setup Dialog Area

            if (State == NpcInteractionState.Intro || State == NpcInteractionState.Gossip)
            {
                // Calculate dialog area
                CurrentLines = TextHelper.SplitWrap(CurrentText, 330, font, 0.75f).Length;
                CurrentBody = camera.FromRectangle(new Rectangle(Subject.Movement.Area.Center.X - Width / 2, Subject.Movement.Area.Top - Height - 20, Width, Height));
                CurrentHeader = camera.FromRectangle(new Rectangle(Subject.Movement.Area.Center.X - Width / 2, Subject.Movement.Area.Top - Height - 52, Width, 32));
                Height = 30 + (int)(font.MeasureString("S").Y - 4) * (CurrentLines + 1);

                if (control.MousePos.Intersects(CurrentBody))
                    control.MouseLock = true;
            }

            #endregion

            #region Intro

            if (State == NpcInteractionState.Intro)
            {

                // Actions
                Vector2 footer_offset = new Vector2(CurrentBody.X + 10, CurrentBody.Y + Height - 25);
                CurrentSelection = "";
                Vector2 current_font;

                // if shop
                current_font = font.MeasureString("Shop") * ScaleActions;
                if (control.MousePos.Intersects(new Rectangle((int)footer_offset.X, (int)footer_offset.Y, (int)current_font.X, (int)current_font.Y)))
                {
                    CurrentSelection = "Shop";
                    if (control.Click()) { State = NpcInteractionState.Shop; }
                }
                footer_offset.X += (int)(font.MeasureString("Shop").X * 0.7f) + 10;

                // if gossip
                current_font = font.MeasureString("Gossip") * ScaleActions;
                if (control.MousePos.Intersects(new Rectangle((int)footer_offset.X, (int)footer_offset.Y, (int)current_font.X, (int)current_font.Y)))
                {
                    CurrentSelection = "Gossip";
                    if (control.Click()) { State = NpcInteractionState.Gossip; CurrentText = Subject.Type.Dialog.Get(State).Line; }
                }
                footer_offset.X += (int)(font.MeasureString("Gossip").X * 0.7f) + 10;

                // if follow
                current_font = font.MeasureString("Follow Me") * ScaleActions;
                if (control.MousePos.Intersects(new Rectangle((int)footer_offset.X, (int)footer_offset.Y, (int)current_font.X, (int)current_font.Y)))
                {
                    CurrentSelection = "Follow Me";
                    if (control.Click()) { State = NpcInteractionState.None; }
                }
                footer_offset.X += (int)(font.MeasureString("Follow Me").X * 0.7f) + 10;

            }

            #endregion
        }
Example #2
0
        public void Update( Map map, Player player, Control control, Camera camera, SpriteFont font )
        {
            for (int i = 0; i < ActiveNpcs.Count; i++)
            {
                //ActiveNpcs[i].Npc.Ai.Update(ActiveNpcs[i].Movement, player); ai off

                ActiveNpc npc = ActiveNpcs[i];

                // Follow the path
                if (npc.CurrentPath != null)
                {
                    if (npc.CurrentDestination == Point.Zero)
                        npc.CurrentDestination = npc.CurrentPath.Pop();

                    if (npc.Movement.Area.Intersects(new Rectangle(npc.CurrentDestination.X * 24, npc.CurrentDestination.Y * 24, 24, 24)))
                    {
                        if (npc.CurrentPath.Count > 0)
                            { npc.CurrentDestination = npc.CurrentPath.Pop(); }
                        else
                            { npc.CurrentPath = null; npc.CurrentDestination = Point.Zero; }

                    }
                }

                if (npc.CurrentDestination != Point.Zero)
                    MovementChase(npc.Movement, npc.CurrentDestination);
                else
                    npc.Movement.Intention.Stop();

                ActiveNpcs[i].Movement.Update(map);
                ActiveNpcs[i].Type.Race.Animation.Update(ActiveNpcs[i].Movement);

                #region Interaction

                if (control.MousePos.Intersects(camera.FromRectangle(npc.Movement.Area)))
                {
                    control.State = Control.CursorStates.Interact;
                    if (control.Click(false))
                        Interaction.Start(npc);
                }

                if (Interaction.State != NpcInteraction.NpcInteractionState.None)
                {
                    if (Geometry.Range(player.Movement.Area, npc.Movement.Area) > 7)
                        Interaction.End();
                }

                Interaction.Update(camera, control, font);

                #endregion

                #region Damage / Combat

                if(npc.Movement.Area.Intersects(player.Movement.Area))
                {
                    player.Damage(5);
                }

                #endregion

                ActiveNpcs[i].Invunerable -= 1;
            }
        }