Exemple #1
0
        public bool OnPickUp(Object.Item objt)
        {
            if (objt is Gold)
            {
                State.Gold += (objt as Gold).Amount;
                return(true);
            }
            else if (objt.StackSize > 0)
            {
                KeyValuePair <int, Object.Item> itm;
                //  if (objt is Ore)
                //      itm = Inventory.ContainsItem(objt._Name, (objt as Ore).Grade);
                //   else
                itm = Inventory.ContainsItem(objt._Name);
                if (itm.Value != null)
                {
                    itm.Value.StackSize += objt.StackSize;
                    gameLink.Send(new GameOutMessage.AddItemToInventory(itm.Value, itm.Key).Compile());
                    return(true);
                }
            }

            if (Inventory.AddItem(objt))
            {
                return(true);
            }
            return(false);
        }
Exemple #2
0
            public AddItemToEntrust(Object.Item item, int slot)
                : base(0x31)
            {
                Write((byte)slot);
                Write((short)item.SprId);
                Write((byte)00);
                string txtstats = item.TextStats;

                Write((short)txtstats.Length);
                WriteAsciiNull(txtstats);
            }
Exemple #3
0
            public AddItemToInventory(Object.Item item, int slot)
                : base(0x17)
            {
                Write((byte)slot);
                Write((short)item.SprId);
                Write((byte)02);
                string txtstats = item.TextStats;

                Write((short)txtstats.Length);
                WriteAsciiNull(txtstats);
            }
Exemple #4
0
 internal Object.Item Drop(int slot)
 {
     Object.Item outi = null;
     if (InventItems.TryRemove(slot, out outi))
     {
         playerLink.gameLink.Send(new Network.GameOutMessage.DeleteItemSlot(slot).Compile());
         outi.Position.X = playerLink.Position.X;
         outi.Position.Y = playerLink.Position.Y;
         playerLink.Position.CurMap.Enter(outi);
     }
     return(outi);
 }
Exemple #5
0
        static Object.Item SmeltBronze(Object.Item ibar, Object.Item cbar, ref int XPGained)
        {
            var ironstack = ibar.StackSize;
            var copstack  = cbar.StackSize;
            var amt       = ironstack <= copstack ? ironstack : copstack;

            ibar.StackSize -= amt;
            cbar.StackSize -= amt;
            XPGained       += amt * 5;

            return(Scripts.Items.CreateItem("BRONZE BAR", amt));
        }
Exemple #6
0
        Object.Item Split(Object.Item itm, int amt)
        {
            if (amt <= 0)
            {
                return(null);
            }
            if (itm.StackSize < amt)
            {
                return(null);
            }

            Object.Item newi = Scripts.Items.CreateItem(itm._Name, amt);
            itm.StackSize -= amt;
            return(newi);
        }
Exemple #7
0
        internal void Sell(int slot)
        {
            Object.Item outi = null;
            if (InventItems.TryGetValue(slot, out outi))
            {
                if (outi.SellPrice == 0)
                {
                    return;
                }

                playerLink.State.Gold += outi.SellPrice;
                InventItems.TryRemove(slot, out outi);
                playerLink.gameLink.Send(new Network.GameOutMessage.DeleteItemSlot(slot).Compile());
            }
        }
Exemple #8
0
 internal void Delete(int slot, bool oneof = false)
 {
     Object.Item outi = null;
     if (InventItems.TryRemove(slot, out outi))
     {
         if (oneof && outi.StackSize > 1)
         {
             outi.StackSize--;
             InventItems.TryAdd(slot, outi);
             playerLink.gameLink.Send(new Network.GameOutMessage.AddItemToInventory(outi, slot).Compile());
         }
         else
         {
             playerLink.gameLink.Send(new Network.GameOutMessage.DeleteItemSlot(slot).Compile());
         }
     }
 }
Exemple #9
0
        internal bool AddItem(Object.Item objt)
        {
            var freeslot = FreeSlot;

            if (freeslot.Key == true)
            {
                Object.Item tempo = objt;
                if (objt.Static)
                {
                    tempo = Scripts.Items.CreateItem(objt._Name, objt.StackSize);
                }
                InventItems.TryAdd(freeslot.Value, tempo);
                playerLink.gameLink.Send(new Network.GameOutMessage.AddItemToInventory(tempo, freeslot.Value).Compile());
                return(true);
            }
            return(false);
        }
Exemple #10
0
        static Object.Item SmeltOre(Object.Item ore, string barname, int pb, Player.Player plyr, int lvl, int xp, ref int XPGained)
        {
            if (!AssertLevel(plyr, lvl, barname))
            {
                return(null);
            }

            var amt = ore.StackSize / pb;

            if (amt == 0)
            {
                return(null);
            }

            ore.StackSize -= amt * pb;
            XPGained      += amt * xp;

            return(Scripts.Items.CreateItem(barname, amt));
        }
Exemple #11
0
        internal void Swap(int froms, int tos)
        {
            Object.Item fromss;
            Object.Item toss;
            if (InventItems.TryGetValue(froms, out fromss))
            {
                if (InventItems.TryGetValue(tos, out toss))
                {
                    InventItems[froms] = toss;
                    InventItems[tos]   = fromss;
                    playerLink.gameLink.Send(new Network.GameOutMessage.AddItemToInventory(toss, froms).Compile());
                    playerLink.gameLink.Send(new Network.GameOutMessage.AddItemToInventory(fromss, tos).Compile());
                }
                else
                {
                    if (fromss.StackSize > 1)
                    {
                        playerLink.WriteWarn(string.Format("How many do you wish to move? [0-{0}]", fromss.StackSize));
                        playerLink.gameLink.stackmoveCallback = new Func <int, bool>((amt) =>
                        {
                            if (fromss.StackSize < amt || amt <= 0)
                            {
                                return(false);
                            }

                            if (InventItems.TryRemove(froms, out fromss))
                            {
                                Object.Item newi  = Scripts.Items.CreateItem(fromss._Name, amt);
                                fromss.StackSize -= amt;
                                if (InventItems.TryAdd(tos, newi))
                                {
                                    if (fromss.StackSize == 0)
                                    {
                                        playerLink.gameLink.Send(new Network.GameOutMessage.DeleteItemSlot(froms).Compile());
                                    }
                                    else
                                    {
                                        InventItems.TryAdd(froms, fromss);
                                        playerLink.gameLink.Send(new Network.GameOutMessage.AddItemToInventory(fromss, froms).Compile());
                                    }

                                    playerLink.gameLink.Send(new Network.GameOutMessage.AddItemToInventory(newi, tos).Compile());
                                }
                            }

                            return(true);
                        });
                        return;
                    }

                    if (InventItems.TryRemove(froms, out fromss))
                    {
                        if (InventItems.TryAdd(tos, fromss))
                        {
                            playerLink.gameLink.Send(new Network.GameOutMessage.DeleteItemSlot(froms).Compile());
                            playerLink.gameLink.Send(new Network.GameOutMessage.AddItemToInventory(fromss, tos).Compile());
                        }
                    }
                }
            }
        }
Exemple #12
0
        public static void Smelt(Player.Player plyr, Object.Craft cauldron)
        {
            int XPGained = 0;
            var content  = cauldron.Contents.Skip(0).Select(xe => xe.Value).ToList();

            foreach (var itm in content)
            {
                if (itm.StackSize == 0)
                {
                    continue;
                }

                Object.Item result = null;
                int         pb     = GetPb(itm._Name);

                switch (itm._Name)
                {
                case "IRON PB":
                case "IRON PN":
                case "IRON PG":
                    result = SmeltOre(itm, "IRON BAR", pb, plyr, 0, 5, ref XPGained);
                    break;

                case "COPPER PB":
                case "COPPER PN":
                case "COPPER PG":
                    result = SmeltOre(itm, "COPPER BAR", pb, plyr, 2, 6, ref XPGained);
                    break;

                case "WAX PB":
                case "WAX PN":
                case "WAX PG":
                    result = SmeltOre(itm, "WAX BAR", pb, plyr, 4, 9, ref XPGained);
                    break;

                case "ALUMINUM PB":
                case "ALUMINUM PN":
                case "ALUMINUM PG":
                    result = SmeltOre(itm, "ALUMINUM BAR", pb, plyr, 6, 13, ref XPGained);
                    break;

                case "COPPER BAR":
                case "IRON BAR":
                    if (!AssertLevel(plyr, 1, "BRONZE BAR"))
                    {
                        return;
                    }

                    var copbar  = cauldron.Contents.Skip(0).Where(xe => xe.Value._Name == "COPPER BAR").FirstOrDefault();
                    var ironbar = cauldron.Contents.Skip(0).Where(xe => xe.Value._Name == "IRON BAR").FirstOrDefault();
                    if (copbar.Value != null && ironbar.Value != null && copbar.Value.StackSize > 0 && ironbar.Value.StackSize > 0)
                    {
                        result = SmeltBronze(ironbar.Value, copbar.Value, ref XPGained);
                        if (copbar.Value.StackSize == 0)
                        {
                            cauldron.RemoveItem(copbar.Value);
                        }
                        if (ironbar.Value.StackSize == 0)
                        {
                            cauldron.RemoveItem(ironbar.Value);
                        }
                    }

                    break;
                }

                if (result != null)
                {
                    result.Position.X      = plyr.Position.X;
                    result.Position.Y      = plyr.Position.Y;
                    result.Position.CurMap = plyr.Position.CurMap;
                    plyr.Position.CurMap.Enter(result);
                }

                if (itm is Object.Ore)
                {
                    if (itm.StackSize == 0)
                    {
                        cauldron.RemoveItem(itm);
                    }
                }
            }
            if (XPGained > 0)
            {
                plyr.State.MinerXP += XPGained;
                plyr.WriteWarn(string.Format("You have gained {0} experience.", XPGained));
            }
        }