Beispiel #1
0
        public bool HandleMouseInput(MouseEventArgs e)
        {
            int pY = CoordY;
            int pX = CoordX;

            if (Program.MA == MouseArea.TileInv)
            {
                #region TileInv
                int index = (Program.TileInvClickCoords[0] * 11) + Program.TileInvClickCoords[1];
                // get the item from the inv
                Item toPickUp = Program.world.Data[pY, pX].Inventory.Items[index];
                // if it's not null, try to add
                if (toPickUp != null)
                {
                    if (Inventory.AddItem(toPickUp))
                    {
                        toPickUp.OnPickUp(this);
                        Program.world.Data[pY, pX].Inventory.RemoveItem(toPickUp);
                        Program.console.SetText("You pick up the " + toPickUp.Name + ".");
                        return(true);
                    }
                }
                #endregion
            }
            else if (Program.MA == MouseArea.PlayerInv)
            {
                #region PlayerInv
                // check for item relevance
                int  index      = (Program.PlayerInvClickCoords[0] * 11) + Program.PlayerInvClickCoords[1];
                Item toWorkWith = Inventory.Items[index];
                if (toWorkWith == null)
                {
                    return(false);
                }
                // Wait for the next mouseclick
                Program.waitState = 2;
                while (Program.waitState == 2)
                {
                    String prompt = "Click to shuffle items.";
                    Program.sidebar.promptText = prompt;
                    Application.DoEvents();
                }
                Program.sidebar.promptText = "";
                if (Program.waitState == -1)
                {
                    Program.LastMA = MouseArea.Hidden;
                    return(false);
                }
                if (Program.MA == MouseArea.Grid || Program.MA == MouseArea.PlayerInv)
                {
                    Program.LastMA = MouseArea.Hidden;
                    return(false);
                }
                if (Program.MA == MouseArea.TileInv)    // DROP ITEM
                {
                    if (Program.world[pY, pX].Inventory.AddItem(toWorkWith))
                    {
                        Inventory.RemoveItem(toWorkWith);
                        Program.console.SetText("You drop the " + toWorkWith.Name + ".");
                        return(true);
                    }
                }
                else if (Program.MA == MouseArea.HoldBox)
                {
                    if (HeldItem == null)
                    {
                        HeldItem = toWorkWith;
                        Inventory.RemoveItem(HeldItem);
                        Program.console.SetText("You grasp the " + HeldItem.Name + " in your off hand.");
                        return(true);
                    }
                    else
                    {
                        if (Inventory.AddItem(HeldItem))
                        {
                            HeldItem = toWorkWith;
                            Inventory.RemoveItem(HeldItem);
                            Program.console.SetText("You shuffle some items in your pack.");
                            return(true);
                        }
                        else if (Program.world[pY, pX].Inventory.AddItem(HeldItem))
                        {
                            HeldItem = toWorkWith;
                            Inventory.RemoveItem(HeldItem);
                            Program.console.SetText("You lose your grip and some things tumble to the floor.");
                            return(true);
                        }
                        else
                        {
                            Program.console.SetText("You're without a place to put this item!");
                        }
                    }
                }
                else if (Program.MA == MouseArea.WearBox)
                {
                    if (toWorkWith is Armor)
                    {
                        if (WornArmor == null)
                        {
                            WornArmor = (Armor)toWorkWith;
                            Inventory.RemoveItem(WornArmor);
                            Program.console.SetText("You don your " + WornArmor.Name + ".");
                            return(true);
                        }
                        else
                        {
                            if (Inventory.AddItem(WornArmor))
                            {
                                WornArmor = (Armor)toWorkWith;
                                Inventory.RemoveItem(WornArmor);
                                Program.console.SetText("You shuffle some items in your pack.");
                                return(true);
                            }
                            else if (Program.world[pY, pX].Inventory.AddItem(WornArmor))
                            {
                                WornArmor = (Armor)toWorkWith;
                                Inventory.RemoveItem(WornArmor);
                                Program.console.SetText("You lose your grip and some things tumble to the floor.");
                                return(true);
                            }
                            else
                            {
                                Program.console.SetText("You're without a place to put this item!");
                            }
                        }
                    }
                    else
                    {
                        Program.console.SetText("You can't wear that!");
                    }
                }
                else if (Program.MA == MouseArea.WieldBox)
                {
                    if (toWorkWith is Weapon)
                    {
                        if (HeldWeapon == null)
                        {
                            HeldWeapon = (Weapon)toWorkWith;
                            Inventory.RemoveItem(HeldWeapon);
                            Program.console.SetText("You grasp your " + HeldWeapon.Name + ".");
                            return(true);
                        }
                        else
                        {
                            if (Inventory.AddItem(HeldWeapon))
                            {
                                HeldWeapon = (Weapon)toWorkWith;
                                Inventory.RemoveItem(HeldWeapon);
                                Program.console.SetText("You shuffle some items in your pack.");
                                return(true);
                            }
                            else if (Program.world[pY, pX].Inventory.AddItem(HeldWeapon))
                            {
                                HeldWeapon = (Weapon)toWorkWith;
                                Inventory.RemoveItem(HeldWeapon);
                                Program.console.SetText("You lose your grip and some things tumble to the floor.");
                                return(true);
                            }
                            else
                            {
                                Program.console.SetText("You're without a place to put this item!");
                            }
                        }
                    }
                    else
                    {
                        Program.console.SetText("You can't wield that!");
                    }
                }
                #endregion
            }
            else if (Program.MA == MouseArea.HoldBox)
            {
                #region HoldBox

                if (HeldItem == null)
                {
                    return(false);
                }
                Program.waitState = 2;
                Program.Exception = MouseArea.HoldBox;
                while (Program.waitState == 2)
                {
                    Application.DoEvents();
                }
                if (Program.waitState == -1)
                {
                    Program.LastMA = MouseArea.Hidden;
                    return(false);
                }
                if (Program.MA == MouseArea.Grid)
                {
                    Program.LastMA = MouseArea.Hidden;
                    return(false);
                }
                else if (Program.MA == MouseArea.HoldBox)
                {
                    if (HeldItem.Activate(this))
                    {
                        HeldItem = null;
                        return(true);
                    }
                }
                else if (Program.MA == MouseArea.PlayerInv)
                {
                    if (Inventory.AddItem(HeldItem))
                    {
                        Program.console.SetText("You put the " + HeldItem.Name + " into your pack.");
                        HeldItem = null;
                        return(true);
                    }
                }
                else if (Program.MA == MouseArea.TileInv)
                {
                    if (Program.world[pY, pX].Inventory.AddItem(HeldItem))
                    {
                        Program.console.SetText("You place the " + HeldItem.Name + " on the floor below.");
                        HeldItem = null;
                        return(true);
                    }
                }
                #endregion
            }
            else if (Program.MA == MouseArea.WearBox)
            {
                #region WearBox
                if (WornArmor == null)
                {
                    return(false);
                }
                Program.waitState = 2;
                while (Program.waitState == 2)
                {
                    Application.DoEvents();
                }
                if (Program.waitState == -1)
                {
                    Program.LastMA = MouseArea.Hidden;
                    return(false);
                }
                if (Program.MA == MouseArea.Grid || Program.MA == MouseArea.WearBox)
                {
                    Program.LastMA = MouseArea.Hidden;
                    return(false);
                }
                else if (Program.MA == MouseArea.PlayerInv)
                {
                    if (Inventory.AddItem(WornArmor))
                    {
                        Program.console.SetText("You put the " + WornArmor.Name + " into your pack.");
                        WornArmor = null;
                        return(true);
                    }
                }
                else if (Program.MA == MouseArea.TileInv)
                {
                    if (Program.world[pY, pX].Inventory.AddItem(WornArmor))
                    {
                        Program.console.SetText("You place the " + WornArmor.Name + " on the floor below.");
                        WornArmor = null;
                        return(true);
                    }
                }
                else if (Program.MA == MouseArea.HoldBox)
                {
                }
                #endregion
            }
            else if (Program.MA == MouseArea.WieldBox)
            {
                #region WieldBox
                if (HeldWeapon == null)
                {
                    return(false);
                }
                Program.waitState = 2;
                while (Program.waitState == 2)
                {
                    Application.DoEvents();
                }
                if (Program.waitState == -1)
                {
                    Program.LastMA = MouseArea.Hidden;
                    return(false);
                }
                if (Program.MA == MouseArea.Grid || Program.MA == MouseArea.WieldBox)
                {
                    Program.LastMA = MouseArea.Hidden;
                    return(false);
                }
                else if (Program.MA == MouseArea.PlayerInv)
                {
                    if (Inventory.AddItem(HeldWeapon))
                    {
                        Program.console.SetText("You put the " + HeldWeapon.Name + " into your pack.");
                        HeldWeapon = null;
                        return(true);
                    }
                }
                else if (Program.MA == MouseArea.TileInv)
                {
                    if (Program.world[pY, pX].Inventory.AddItem(HeldWeapon))
                    {
                        Program.console.SetText("You place the " + HeldWeapon.Name + " on the floor below.");
                        HeldWeapon = null;
                        return(true);
                    }
                }
                #endregion
            }
            else if (Program.MA == MouseArea.Grid)
            {
                #region Grid
                int y     = Program.GridClickCoords[0];
                int x     = Program.GridClickCoords[1];
                int index = -1;
                foreach (Ability a in Abilities)
                {
                    if (y >= a.GridY && y < a.GridY + a.GridHeight && x >= a.GridX && x < a.GridX + a.GridWidth)
                    {
                        index = Abilities.IndexOf(a);
                    }
                }
                if (index != -1)
                {
                    if (Abilities[index].Use(this))
                    {
                        return(true);
                    }
                }
                #endregion
            }
            return(false);
        }