Пример #1
0
 public Item(string name, string wearslot, Coordinates pos, int spriteid, int id = 0, int strength = 0, int defense = 0, bool visible = true)
 {
     Name = name;
     ID = id;
     Position = pos;
     Visible = visible;
     EntityType = Entity.ItemEntity;
     SpriteID = spriteid;
     Strength = strength;
     Defense = defense;
     WearSlot = wearslot;
     if (wearslot == ItemSlot.Bag)
     {
         Container = new Backpack();
         Container.ID = this.ID;
         Container.ItemID = spriteid;
     }
     Parent = new Backpack();
 }
Пример #2
0
 public Item(string name, int realid, string wearslot, Coordinates pos, int spriteid, int id = 0, int strength = 0, int defense = 0, bool visible = true, int wearingplayerid = 0, int zorder = 0)
 {
     RealID = realid;
     Name = name;
     ID = id;
     Position = pos;
     Visible = visible;
     EntityType = Entity.ItemEntity;
     SpriteID = spriteid;
     Strength = strength;
     Defense = defense;
     WearSlot = wearslot;
     WearingPlayerID = wearingplayerid;
     if (wearslot == ItemSlot.Bag)
     {
         Container = new Backpack();
         Container.ID = this.ID;
         Container.ItemID = spriteid;
     }
     Z_order = zorder;
     Parent = new Backpack();
 }
Пример #3
0
 public void ThrowItemToBag(Item item, Backpack Bag, Coordinates target, UI SourceEquipment = null, Backpack Parent = null)
 {
     if (Parent != null)
     {
         Parent.RemoveItem(item);
     }
     item.Slot = null;
     item.Position = new Coordinates(target.X, target.Y);
     Bag.AddItem(item);
     if (SourceEquipment != null)
     {
         Players[0].UnequipItem(SourceEquipment.Name);
     }
 }
Пример #4
0
 internal void ThrowItemToBag(Item item, Backpack Bag, Coordinates target, UI SourceEquipment = null, Backpack Parent = null)
 {
     if (Parent != null)
     {
         Parent.RemoveItem(item);
         item.Slot = null;
         item.WearingPlayerID = Players[0].ID;
         item.Position = new Coordinates(target.X, target.Y);
         Bag.AddItem(item);
         if (SourceEquipment != null)
         {
             Players[0].UnequipItem(SourceEquipment.Name);
         }
     }
     else
     {
         if (SourceEquipment != null)
         {
             item.Slot = null;
             item.WearingPlayerID = Players[0].ID;
             item.Position = new Coordinates(target.X, target.Y);
             Bag.AddItem(item);
             Players[0].UnequipItem(SourceEquipment.Name);
         }
         else
         {
             if (AdjacentToItem(Players[0], item))
             {
                 item.Slot = null;
                 item.WearingPlayerID = Players[0].ID;
                 item.Position = new Coordinates(target.X, target.Y);
                 Bag.AddItem(item);
             }
         }
     }
 }
Пример #5
0
 private void ThrowItemToBag(Backpack Bag, Coordinates Destination, UI SourceEquipment = null)
 {
     // TODO: Don't allow main bag to be thrown into any of its nested bags
     if (dragItem.Container == null || dragItem.Container.ID != Bag.ID)
     {
         if (SourceEquipment == null)
         {
             if (dragItem.Parent.IsEmpty())
             {
                 map.ThrowItemToBag(dragItem, Bag, Destination);
             }
             else
             {
                 map.ThrowItemToBag(dragItem, Bag, Destination, null, dragItem.Parent);
             }
         }
         else
         {
             SourceEquipment.Sprite = GetSpriteByName(SourceEquipment.Name);
             map.ThrowItemToBag(dragItem, Bag, Destination, SourceEquipment);
         }
     }
 }
Пример #6
0
        private Backpack TopBag(Item BagInsideBag)
        {
            bool LoopDone = false;
            Item currentBag = BagInsideBag;
            Backpack topBag = new Backpack();
            if (BagInsideBag.Slot == ItemSlot.Bag)
            {
                topBag = BagInsideBag.Container;
            }
            else
            {
                while (!LoopDone)
                {
                    if (currentBag.Parent != null)
                    {
                        if (currentBag.Parent.ID != -1)
                        {
                            topBag = currentBag.Parent;
                        }
                        currentBag = GetItemByID(currentBag.Parent.ID);
                    }
                    else
                    {
                        LoopDone = true;
                    }
                }
            }

            return topBag;
        }
Пример #7
0
        private void DoLeftClickEvents(GameTime gameTime)
        {
            if (Mouse.GetState().LeftButton == ButtonState.Released && LeftClicked)
            {

                Vector2 newPos = GetScalableMousePosition(Mouse.GetState().Position.ToVector2());
                int mx = (int)newPos.X, my = (int)newPos.Y;
                //int x = (mx / (32 * (int)ScalingFactor.X)) * 32;
                //int y = (my / (32 * (int)ScalingFactor.Y)) * 32;

                int x = (mx / 32) * 32;
                int y = (my / 32) * 32;

                Coordinates target_UI = new Coordinates(x, y);
                Coordinates target_Game = new Coordinates((mx / (32 * (int)ScalingFactor.X)) * 32, (my / (32 * (int)ScalingFactor.Y)) * 32);
                //Coordinates truePos = new Coordinates(map.Players[0].Position.X + (x / 32) - Utility.ScreenX, map.Players[0].Position.Y + (y / 32) - Utility.ScreenY);
                Coordinates truePos = ConvertScreenPosToGamePos(mx, my, map.Players[0].Position);
                //Coordinates truePos = ConvertScreenPosToGamePos(mx, my, map.Players[0].Position);
                if (!Resizing)
                {
                    if (gameTime.TotalGameTime.TotalMilliseconds - leftClickTime < 200)
                    {
                        Backpack bagToClose = GetCloseButtonFromCoordinates(mx, my);
                        if (bagToClose.ID == -1)
                        {
                            Backpack bagToScrollUp = GetUpArrow(mx, my);
                            if (bagToScrollUp.ID == -1)
                            {
                                Backpack bagToScrollDown = GetDownArrow(mx, my);
                                if (bagToScrollDown.ID == -1)
                                {
                                    if (!map.OutOfBoundaries(truePos) && !OutOfClientBoundaries(target_Game))
                                    {
                                        if (map.IsTileWalkable(truePos))
                                        {
                                            map.GeneratePathFromPlayer(map.Players[0], truePos);
                                        }
                                    }
                                }
                                else
                                {
                                    ScrollDownBag(bagToScrollDown);
                                }
                            }
                            else
                            {
                                ScrollUpBag(bagToScrollUp);
                            }
                        }
                        else
                        {
                            //Window.Title = bagToClose.ID.ToString();
                            Item bagClosing = GetItemByID(bagToClose.ID);
                            if (bagClosing.ID != -1)
                            {
                                CloseBag(bagClosing);
                            }
                        }
                    }
                    else
                    {
                        if (dragItem.ID != -1)
                        {
                            UI targetEquipment = GetListUIByMousePosition(x, y);
                            UI sourceEquipment = GetListUIByMousePosition(dragItem.Position.X, dragItem.Position.Y);
                            Item FromBag = GetItemFromBagCoordinates(dragItem.Position.X, dragItem.Position.Y);
                            Backpack ToBag = GetBagFromCoordinates(x, y);
                            if (FromBag.ID == -1)
                            {
                                if (targetEquipment.ID == -1)
                                {
                                    if (ToBag.Open)
                                    {
                                        if (sourceEquipment.ID == -1)
                                        {
                                            ThrowItemToBag(ToBag, target_UI);
                                        }
                                        else
                                        {
                                            ThrowItemToBag(ToBag, target_UI, sourceEquipment);
                                        }
                                    }
                                    else
                                    {
                                        if (sourceEquipment.ID == -1)
                                        {
                                            if (!map.OutOfBoundaries(truePos) && !OutOfClientBoundaries(target_Game))
                                            {
                                                truePos.Z = map.TopTileZ(truePos);
                                                if (InHouse && truePos.Z > map.Players[0].Position.Z)
                                                {
                                                    truePos.Z = map.Players[0].Position.Z;
                                                }
                                                map.DragItem(dragItem, truePos);
                                            }
                                        }
                                        else
                                        {
                                            if (!map.OutOfBoundaries(truePos) && !OutOfClientBoundaries(target_Game))
                                            {
                                                truePos.Z = map.TopTileZ(truePos);
                                                if (InHouse && truePos.Z > map.Players[0].Position.Z)
                                                {
                                                    truePos.Z = map.Players[0].Position.Z;
                                                }
                                                UnequipItem(sourceEquipment, truePos);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (sourceEquipment.ID == -1)
                                    {
                                        EquipItem(targetEquipment);
                                    }
                                    else
                                    {
                                        EquipItem(targetEquipment, sourceEquipment);
                                    }
                                }
                            }
                            else
                            {
                                if (targetEquipment.ID == -1)
                                {
                                    if (ToBag.Open)
                                    {
                                        ThrowItemToBag(ToBag, target_UI);
                                    }
                                    else
                                    {
                                        if (!map.OutOfBoundaries(truePos) && !OutOfClientBoundaries(target_Game))
                                        {
                                            truePos.Z = map.TopTileZ(truePos);
                                            //Window.Title = truePos.Z.ToString();
                                            if (InHouse && truePos.Z > map.Players[0].Position.Z)
                                            {
                                                truePos.Z = map.Players[0].Position.Z;
                                            }
                                            ThrowItemFromBag(truePos);
                                        }
                                    }
                                }
                                else
                                {
                                    EquipItemFromBag(targetEquipment);
                                }
                            }
                        }
                    }
                }

                Textbox clickedTextbox = GetTextboxByMousePosition(x, y);
                if (clickedTextbox.ID != -1)
                {
                    FocusedTextbox = clickedTextbox.ID;
                }
                else
                {
                    FocusedTextbox = GetTextboxByName("Chat").ID;
                }

                // For debug purposes: Window.Title = map.Players[0].TargetID.ToString();*/
                // For debug purposes: Window.Title = x.ToString() + " " + y.ToString();
                LeftClicked = false;
                currentMouse = 0;
                CheckOpenBags();
                Resizing = false;
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed && (!Keyboard.GetState().IsKeyDown(Keys.LeftControl) && !Keyboard.GetState().IsKeyDown(Keys.RightControl)))
            {
                if (!LeftClicked)
                {
                    Vector2 newPos = GetScalableMousePosition(Mouse.GetState().Position.ToVector2());
                    int mx = (int)newPos.X, my = (int)newPos.Y;
                    int x = (mx / 32) * 32;
                    int y = (my / 32) * 32;
                    if (currentMouse == 3)
                    {
                        Resizing = true;
                        LeftClicked = true;
                        ResizingBag = GetBagFromCoordinates(x, y);
                    }
                    else
                    {
                        ScrollingBag = GetScrollbar(mx, my);
                        if (ScrollingBag.ID == -1)
                        {
                            leftClickTime = (int)gameTime.TotalGameTime.TotalMilliseconds;
                            dragItem = GetItemByMousePosition(mx, my);
                            LeftClicked = true;

                            if (dragItem.Parent != null && dragItem.Parent.ID != -1)
                            {
                                Item newz = GetItemFromBagCoordinates(mx, my);
                                if (GetItemFromBagCoordinates(mx, my).ID == -1)
                                {
                                    dragItem = new Item();
                                }
                            }
                        }
                        else
                        {
                            LeftClicked = true;
                            Scrolling = true;
                        }
                    }
                }
                else
                {
                    if (Resizing)
                    {
                        ResizeBag(ResizingBag);
                    }
                    else
                    {
                        if (Scrolling)
                        {
                            ScrollBag(ScrollingBag);
                        }
                        else
                        {
                            if (gameTime.TotalGameTime.TotalMilliseconds - leftClickTime > 200)
                            {
                                if (dragItem.ID != -1)
                                {
                                    MouseCursors[2].Sprite = storage.GetSpriteByName(dragItem.Name);
                                    lastMouse = currentMouse;
                                    currentMouse = 2;
                                }
                                else
                                {
                                    lastMouse = currentMouse;
                                    currentMouse = 1;
                                }
                            }
                        }
                    }
                }
            }
            else if (Mouse.GetState().LeftButton == ButtonState.Pressed && (Keyboard.GetState().IsKeyDown(Keys.LeftControl) || Keyboard.GetState().IsKeyDown(Keys.RightControl)) && !LeftClicked && !Looked)
            {
                Vector2 newPos = GetScalableMousePosition(Mouse.GetState().Position.ToVector2());
                int mx = (int)newPos.X, my = (int)newPos.Y;
                int x = (mx / 32) * 32;
                int y = (my / 32) * 32;
                Item lookItem = GetItemByMousePosition(mx, my);
                if (lookItem.ID != -1)
                {
                    TextPopUps.Add(new Animation(1000, 0, 1, (int)gameTime.TotalGameTime.TotalMilliseconds, "You see " + lookItem.Name + " (ID: " + lookItem.ID + ")."));
                }
                Looked = true;
            }
        }
Пример #8
0
 private void ScrollUpBag(Backpack Bag)
 {
     // Scroll up
     if (Bag.Scroll.CurrentStep > 0)
     {
         Bag.Scroll.CurrentStep -= 1;
     }
     else
     {
         Bag.Scroll.CurrentStep = 0;
     }
 }
Пример #9
0
 private void ScrollDownBag(Backpack Bag)
 {
     // Scroll down
     if (Bag.Scroll.CurrentStep < (Bag.Scroll.MaxHeight / 10) - (Bag.Height / 10))
     {
         Bag.Scroll.CurrentStep += 1;
     }
     else
     {
         Bag.Scroll.CurrentStep = (Bag.Scroll.MaxHeight / 10) - (Bag.Height / 10);
     }
 }
Пример #10
0
        private void ScrollBag(Backpack Bag)
        {
            int y = Mouse.GetState().Y;

            if (y > OldMousePos.Y)
            {
                ScrollDownBag(Bag);
                if (y != OldMousePos.Y)
                    OldMousePos = Mouse.GetState();
            }
            else if (y < OldMousePos.Y)
            {
                ScrollUpBag(Bag);
                if (y != OldMousePos.Y)
                    OldMousePos = Mouse.GetState();
            }
        }
Пример #11
0
        private void ResizeBag(Backpack Bag)
        {
            Vector2 newPos = GetScalableMousePosition(Mouse.GetState().Position.ToVector2());
            int y = (int)newPos.Y;
            int MaxHeight = Bag.MaxHeight;
            int MinHeight = 40;
            int Height = 0;

            Height = y - Bag.Position.Y - (GetBackpackNumber(Bag) * 10);

            if (Bag.ID != -1)
            {
                if (Height < MinHeight)
                {
                    Height = MinHeight;
                }
                else if (Height > MaxHeight)
                {
                    Height = MaxHeight;
                }
                if (Height + Bag.Scroll.CurrentStep * 10 > MaxHeight)
                {
                    Bag.Scroll.CurrentStep = 0;
                }
                Bag.Height = Height;
            }
        }
Пример #12
0
 private int GetBackpackNumber(Backpack bag)
 {
     for (int i = 0; i < OpenBackpacks.Count; i++)
     {
         if (OpenBackpacks[i].ID == bag.ID)
         {
             return i;
         }
     }
     return 0;
 }