private void LoadSound()
 {
     try
     {
         if (Globals.ContentManager.SoundPacks != null && Globals.ContentManager.SoundPacks.Contains(mRealPath))
         {
             using (var stream = Globals.ContentManager.SoundPacks.GetAsset(mRealPath))
             {
                 mSound = SoundEffect.FromStream(stream);
             }
         }
         else
         {
             using (var fileStream = new FileStream(mRealPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
             {
                 mSound = SoundEffect.FromStream(fileStream);
             }
         }
     }
     catch (Exception exception)
     {
         Log.Error($"Error loading '{mPath}'.", exception);
         ChatboxMsg.AddMessage(
             new ChatboxMsg(
                 $"{Strings.Errors.LoadFile.ToString( Strings.Words.lcase_sound )} [{mPath}]",
                 new Color(0xBF, 0x0, 0x0), Enums.ChatMessageType.Error
                 )
             );
     }
 }
Exemple #2
0
        //Craft the item
        void craft_Clicked(Base sender, ClickedEventArgs arguments)
        {
            //This shouldn't be client side :(
            //Quickly Look through the inventory and create a catalog of what items we have, and how many
            var availableItemQuantities = new Dictionary <Guid, int>();

            foreach (var item in Globals.Me.Inventory)
            {
                if (item != null)
                {
                    if (availableItemQuantities.ContainsKey(item.ItemId))
                    {
                        availableItemQuantities[item.ItemId] += item.Quantity;
                    }
                    else
                    {
                        availableItemQuantities.Add(item.ItemId, item.Quantity);
                    }
                }
            }

            var craftDescriptor = CraftBase.Get(mCraftId);
            var canCraft        = craftDescriptor?.Ingredients != null;

            if (canCraft)
            {
                foreach (var ingredient in craftDescriptor.Ingredients)
                {
                    if (!availableItemQuantities.TryGetValue(ingredient.ItemId, out var availableQuantity))
                    {
                        canCraft = false;

                        break;
                    }

                    if (availableQuantity < ingredient.Quantity)
                    {
                        canCraft = false;

                        break;
                    }

                    availableItemQuantities[ingredient.ItemId] -= ingredient.Quantity;
                }
            }

            if (canCraft)
            {
                Crafting  = true;
                mBarTimer = Globals.System.GetTimeMs();
                PacketSender.SendCraftItem(mCraftId);
                mCraftWindow.IsClosable = false;

                return;
            }

            ChatboxMsg.AddMessage(new ChatboxMsg(Strings.Crafting.incorrectresources, Color.Red));
        }
 //ChatMsgPacket
 private static void HandlePacket(ChatMsgPacket packet)
 {
     ChatboxMsg.AddMessage(
         new ChatboxMsg(
             packet.Message ?? "", new Color(packet.Color.A, packet.Color.R, packet.Color.G, packet.Color.B),
             packet.Target
             )
         );
 }
Exemple #4
0
 private void GuildBtn_Clicked(Base sender, ClickedEventArgs arguments)
 {
     if (!string.IsNullOrEmpty(Globals.Me.Guild))
     {
         ToggleGuildWindow();
     }
     else
     {
         ChatboxMsg.AddMessage(new ChatboxMsg(Strings.Guilds.NotInGuild, CustomColors.Alerts.Error, ChatMessageType.Guild));
     }
 }
        public DynamicSoundEffectInstance LoadSong()
        {
            lock (mInstanceLock)
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(mRealPath))
                    {
                        if (Reader == null)
                        {
                            // Do we have this cached?
                            if (Globals.ContentManager.MusicPacks != null && Globals.ContentManager.MusicPacks.Contains(Path.GetFileName(mRealPath)))
                            {
                                // Read from cache, but close reader when we're done with it!
                                Reader = new VorbisReader(Globals.ContentManager.MusicPacks.GetAsset(Path.GetFileName(mRealPath)), true);
                            }
                            else
                            {
                                Reader = new VorbisReader(mRealPath);
                            }
                        }

                        if (Instance != null)
                        {
                            Instance.Dispose();
                            Instance = null;
                        }

                        Instance = new DynamicSoundEffectInstance(
                            Reader.SampleRate, Reader.Channels == 1 ? AudioChannels.Mono : AudioChannels.Stereo
                            );
                        mActiveSource = this;
                        return(Instance);
                    }
                }
                catch (Exception exception)
                {
                    Log.Error($"Error loading '{mPath}'.", exception);
                    ChatboxMsg.AddMessage(
                        new ChatboxMsg(
                            $"{Strings.Errors.LoadFile.ToString(Strings.Words.lcase_sound)} [{mPath}]", new Color(0xBF, 0x0, 0x0), Enums.ChatMessageType.Error
                            )
                        );
                }
            }
            mActiveSource = this;
            return(null);
        }
        public void LoadTexture()
        {
            if (mTexture != null)
            {
                return;
            }

            if (mPackFrame != null)
            {
                ((MonoTexture)mPackFrame.PackTexture).LoadTexture();

                return;
            }

            mLoadError = true;
            if (!File.Exists(mPath))
            {
                return;
            }

            using (var fileStream = new FileStream(mPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                try
                {
                    mTexture = Texture2D.FromStream(mGraphicsDevice, fileStream);
                    if (mTexture != null)
                    {
                        mWidth     = mTexture.Width;
                        mHeight    = mTexture.Height;
                        mLoadError = false;
                    }
                }
                catch (Exception ex)
                {
                    //Failed to load texture.. lets log like we do with audio
                    Log.Error($"Error loading '{mName}'.", ex);
                    ChatboxMsg.AddMessage(
                        new ChatboxMsg(
                            Strings.Errors.LoadFile.ToString(Strings.Words.lcase_sprite) + " [" + mName + "]",
                            new Color(0xBF, 0x0, 0x0)
                            )
                        );
                }
            }
        }
Exemple #7
0
 private void LoadSound()
 {
     using (var fileStream = new FileStream(mFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         try
         {
             mSound = SoundEffect.FromStream(fileStream);
         }
         catch (Exception exception)
         {
             Log.Error($"Error loading '{mFilename}'.", exception);
             ChatboxMsg.AddMessage(
                 new ChatboxMsg(
                     $"{Strings.Errors.LoadFile.ToString(Strings.Words.lcase_sound)} [{mFilename}]",
                     new Color(0xBF, 0x0, 0x0)
                     )
                 );
         }
     }
 }
Exemple #8
0
        public DynamicSoundEffectInstance LoadSong()
        {
            lock (mInstanceLock)
            {
                if (!string.IsNullOrWhiteSpace(mPath))
                {
                    try
                    {
                        if (Reader == null)
                        {
                            Reader = new VorbisReader(mPath);
                        }

                        if (Instance != null)
                        {
                            Instance.Dispose();
                            Instance = null;
                        }

                        Instance = new DynamicSoundEffectInstance(
                            Reader.SampleRate, Reader.Channels == 1 ? AudioChannels.Mono : AudioChannels.Stereo
                            );
                        mActiveSource = this;
                        return(Instance);
                    }
                    catch (Exception exception)
                    {
                        Log.Error($"Error loading '{mPath}'.", exception);
                        ChatboxMsg.AddMessage(
                            new ChatboxMsg(
                                Strings.Errors.LoadFile.ToString(Strings.Words.lcase_sound), new Color(0xBF, 0x0, 0x0)
                                )
                            );
                    }
                }
            }
            mActiveSource = this;
            return(null);
        }
        public void Update()
        {
            if (Globals.Bank[mMySlot].ItemId != mCurrentItemId)
            {
                mCurrentItemId = Globals.Bank[mMySlot].ItemId;
                var item = ItemBase.Get(Globals.Bank[mMySlot].ItemId);
                if (item != null)
                {
                    var itemTex = Globals.ContentManager.GetTexture(GameContentManager.TextureType.Item, item.Icon);
                    if (itemTex != null)
                    {
                        Pnl.Texture     = itemTex;
                        Pnl.RenderColor = item.Color;
                    }
                    else
                    {
                        if (Pnl.Texture != null)
                        {
                            Pnl.Texture = null;
                        }
                    }
                }
                else
                {
                    if (Pnl.Texture != null)
                    {
                        Pnl.Texture = null;
                    }
                }
            }

            if (!IsDragging)
            {
                if (mMouseOver)
                {
                    if (!Globals.InputManager.MouseButtonDown(GameInput.MouseButtons.Left))
                    {
                        mCanDrag = true;
                        mMouseX  = -1;
                        mMouseY  = -1;
                        if (Globals.System.GetTimeMs() < mClickTime)
                        {
                            //Globals.Me.TryUseItem(_mySlot);
                            mClickTime = 0;
                        }
                    }
                    else
                    {
                        if (mCanDrag && Draggable.Active == null)
                        {
                            if (mMouseX == -1 || mMouseY == -1)
                            {
                                mMouseX = InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X;
                                mMouseY = InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y;
                            }
                            else
                            {
                                var xdiff = mMouseX -
                                            (InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X);

                                var ydiff = mMouseY -
                                            (InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y);

                                if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5)
                                {
                                    IsDragging = true;
                                    mDragIcon  = new Draggable(
                                        Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseX,
                                        Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseY, Pnl.Texture
                                        );
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (mDragIcon.Update())
                {
                    //Drug the item and now we stopped
                    IsDragging = false;
                    var dragRect = new FloatRect(
                        mDragIcon.X - sItemXPadding / 2, mDragIcon.Y - sItemYPadding / 2, sItemXPadding / 2 + 32,
                        sItemYPadding / 2 + 32
                        );

                    float bestIntersect      = 0;
                    var   bestIntersectIndex = -1;

                    //So we picked up an item and then dropped it. Lets see where we dropped it to.
                    //Check inventory first.
                    if (mBankWindow.RenderBounds().IntersectsWith(dragRect))
                    {
                        for (var i = 0; i < Globals.BankSlots; i++)
                        {
                            if (mBankWindow.Items[i].RenderBounds().IntersectsWith(dragRect))
                            {
                                if (FloatRect.Intersect(mBankWindow.Items[i].RenderBounds(), dragRect).Width *
                                    FloatRect.Intersect(mBankWindow.Items[i].RenderBounds(), dragRect).Height >
                                    bestIntersect)
                                {
                                    bestIntersect =
                                        FloatRect.Intersect(mBankWindow.Items[i].RenderBounds(), dragRect).Width *
                                        FloatRect.Intersect(mBankWindow.Items[i].RenderBounds(), dragRect).Height;

                                    bestIntersectIndex = i;
                                }
                            }
                        }

                        if (bestIntersectIndex > -1)
                        {
                            if (mMySlot != bestIntersectIndex)
                            {
                                var allowed = true;

                                //Permission Check
                                if (Globals.GuildBank)
                                {
                                    var rank = Globals.Me.GuildRank;
                                    if (string.IsNullOrWhiteSpace(Globals.Me.Guild) || (!rank.Permissions.BankDeposit && Globals.Me.Rank != 0))
                                    {
                                        ChatboxMsg.AddMessage(new ChatboxMsg(Strings.Guilds.NotAllowedSwap.ToString(Globals.Me.Guild), CustomColors.Alerts.Error, ChatMessageType.Bank));
                                        allowed = false;
                                    }
                                }

                                if (allowed)
                                {
                                    PacketSender.SendMoveBankItems(bestIntersectIndex, mMySlot);
                                }

                                //Globals.Me.SwapItems(bestIntersectIndex, _mySlot);
                            }
                        }
                    }

                    mDragIcon.Dispose();
                }
            }
        }
Exemple #10
0
        private void LoadCraftItems(Guid id)
        {
            //Combined item
            mCraftId = id;
            if (mCombinedItem != null)
            {
                mCraftWindow.Children.Remove(mCombinedItem.Container);
            }

            //Clear the old item description box
            if (mCombinedItem != null && mCombinedItem.DescWindow != null)
            {
                mCombinedItem.DescWindow.Dispose();
            }

            if (!Globals.ActiveCraftingTable.Crafts.Contains(id))
            {
                return;
            }

            var craft = Globals.ActiveCraftingTable.Crafts.Get(id);

            if (craft == null)
            {
                return;
            }

            mCombinedItem = new RecipeItem(this, new CraftIngredient(craft.ItemId, 0))
            {
                Container = new ImagePanel(mCraftWindow, "CraftedItem")
            };

            mCombinedItem.Setup("CraftedItemIcon");
            mCombinedValue = new Label(mCombinedItem.Container, "CraftedItemQuantity");

            mCombinedItem.Container.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());

            mCombinedItem.LoadItem();
            mCombinedValue.Show();
            var quantity = Math.Max(craft.Quantity, 1);
            var itm      = ItemBase.Get(craft.ItemId);

            if (itm == null || !itm.IsStackable)
            {
                quantity = 1;
            }

            mCombinedValue.Text = quantity.ToString();

            for (var i = 0; i < mItems.Count; i++)
            {
                //Clear the old item description box
                if (mItems[i].DescWindow != null)
                {
                    mItems[i].DescWindow.Dispose();
                }

                mItemContainer.RemoveChild(mItems[i].Container, true);
            }

            mItems.Clear();
            mValues.Clear();

            //Quickly Look through the inventory and create a catalog of what items we have, and how many
            var itemdict = new Dictionary <Guid, int>();

            foreach (var item in Globals.Me.Inventory)
            {
                if (item != null)
                {
                    if (itemdict.ContainsKey(item.ItemId))
                    {
                        itemdict[item.ItemId] += item.Quantity;
                    }
                    else
                    {
                        itemdict.Add(item.ItemId, item.Quantity);
                    }
                }
            }

            for (var i = 0; i < craft.Ingredients.Count; i++)
            {
                mItems.Add(new RecipeItem(this, craft.Ingredients[i]));
                mItems[i].Container = new ImagePanel(mItemContainer, "CraftingIngredient");
                mItems[i].Setup("IngredientItemIcon");

                var lblTemp = new Label(mItems[i].Container, "IngredientItemValue");

                var onHand = 0;
                if (itemdict.ContainsKey(craft.Ingredients[i].ItemId))
                {
                    onHand = itemdict[craft.Ingredients[i].ItemId];
                }

                lblTemp.Text = onHand + "/" + craft.Ingredients[i].Quantity;
                mValues.Add(lblTemp);

                mItems[i].Container.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());

                mItems[i].LoadItem();

                var xPadding = mItems[i].Container.Margin.Left + mItems[i].Container.Margin.Right;
                var yPadding = mItems[i].Container.Margin.Top + mItems[i].Container.Margin.Bottom;
                mItems[i]
                .Container.SetPosition(
                    i %
                    ((mItemContainer.Width - mItemContainer.GetVerticalScrollBar().Width) /
                     (mItems[i].Container.Width + xPadding)) *
                    (mItems[i].Container.Width + xPadding) +
                    xPadding,
                    i /
                    ((mItemContainer.Width - mItemContainer.GetVerticalScrollBar().Width) /
                     (mItems[i].Container.Width + xPadding)) *
                    (mItems[i].Container.Height + yPadding) +
                    yPadding
                    );
            }

            //If crafting & we no longer have the items for the craft then stop!
            if (Crafting)
            {
                var cancraft = true;
                foreach (var c in CraftBase.Get(mCraftId).Ingredients)
                {
                    if (itemdict.ContainsKey(c.ItemId))
                    {
                        if (itemdict[c.ItemId] >= c.Quantity)
                        {
                            itemdict[c.ItemId] -= c.Quantity;
                        }
                        else
                        {
                            cancraft = false;

                            break;
                        }
                    }
                    else
                    {
                        cancraft = false;

                        break;
                    }
                }

                if (!cancraft)
                {
                    Crafting = false;
                    mCraftWindow.IsClosable = true;
                    mBar.Width = 0;
                    ChatboxMsg.AddMessage(new ChatboxMsg(Strings.Crafting.incorrectresources, Color.Red));

                    return;
                }
            }
        }
Exemple #11
0
        public void LoadTexture()
        {
            if (mTexture != null)
            {
                return;
            }

            if (CreateStream != null)
            {
                using (var stream = CreateStream())
                {
                    Load(stream);
                    return;
                }
            }

            if (mPackFrame != null)
            {
                ((MonoTexture)mPackFrame.PackTexture)?.LoadTexture();

                return;
            }

            mLoadError = true;
            if (string.IsNullOrWhiteSpace(mRealPath))
            {
                Log.Error("Invalid texture path (empty/null).");

                return;
            }

            var relativePath = FileSystemHelper.RelativePath(Directory.GetCurrentDirectory(), mPath);

            if (!File.Exists(mRealPath))
            {
                Log.Error($"Texture does not exist: {relativePath}");

                return;
            }

            using (var fileStream = File.Open(mRealPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                try
                {
                    if (Path.GetExtension(mPath) == ".asset")
                    {
                        using (var gzip = GzipCompression.CreateDecompressedFileStream(fileStream))
                        {
                            Load(gzip);
                        }
                    }
                    else
                    {
                        Load(fileStream);
                    }
                }
                catch (Exception exception)
                {
                    Log.Error(
                        exception,
                        $"Failed to load texture ({FileSystemHelper.FormatSize( fileStream.Length )}): {relativePath}"
                        );

                    ChatboxMsg.AddMessage(
                        new ChatboxMsg(
                            Strings.Errors.LoadFile.ToString(Strings.Words.lcase_sprite) + " [" + mName + "]",
                            new Color(0xBF, 0x0, 0x0), Enums.ChatMessageType.Error
                            )
                        );
                }
            }
        }
Exemple #12
0
        public void LoadTexture()
        {
            if (mTexture != null)
            {
                return;
            }

            if (mPackFrame != null)
            {
                ((MonoTexture)mPackFrame.PackTexture)?.LoadTexture();

                return;
            }


            mLoadError = true;
            if (string.IsNullOrWhiteSpace(mRealPath))
            {
                Log.Error("Invalid texture path (empty/null).");

                return;
            }

            var relativePath = FileSystemHelper.RelativePath(Directory.GetCurrentDirectory(), mPath);

            if (!File.Exists(mRealPath))
            {
                Log.Error($"Texture does not exist: {relativePath}");

                return;
            }

            using (var fileStream = File.Open(mRealPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                try
                {
                    mTexture = Texture2D.FromStream(mGraphicsDevice, fileStream);
                    if (mTexture == null)
                    {
                        Log.Error($"Failed to load texture due to unknown error: {relativePath}");
                        ChatboxMsg.AddMessage(
                            new ChatboxMsg(
                                Strings.Errors.LoadFile.ToString(Strings.Words.lcase_sprite) + " [" + mName + "]",
                                new Color(0xBF, 0x0, 0x0)
                                )
                            );
                        return;
                    }

                    mWidth     = mTexture.Width;
                    mHeight    = mTexture.Height;
                    mLoadError = false;
                }
                catch (Exception exception)
                {
                    Log.Error(
                        exception,
                        $"Failed to load texture ({FileSystemHelper.FormatSize(fileStream.Length)}): {relativePath}"
                        );
                    ChatboxMsg.AddMessage(
                        new ChatboxMsg(
                            Strings.Errors.LoadFile.ToString(Strings.Words.lcase_sprite) + " [" + mName + "]",
                            new Color(0xBF, 0x0, 0x0)
                            )
                        );
                }
            }
        }