Beispiel #1
0
            private async Task Open(InventoryWrapper inventory, LootBox variety, int count)
            {
                StringBuilder text    = new StringBuilder();
                IUserMessage  message = null;

                if (count > 1)
                {
                    string m = string.Concat(Enumerable.Repeat(variety.Emote.ToString() + "\n", count));
                    message = await ReplyAsync(m);

                    await Task.Delay(1000);
                }

                for (int i = 0; i < count; i++)
                {
                    var box = variety.Open(Context.Bot, 0);
                    if (count == 1)
                    {
                        message = await ReplyAsync(variety.Emote.ToString());

                        await Task.Delay(1000);

                        StringBuilder animation = new StringBuilder();

                        foreach (var(rarity, emoji) in box)
                        {
                            animation.Append($"{rarity.LeftBracket}❔{rarity.RightBracket}");
                        }
                        await message.ModifyAsync(m => m.Content = animation.ToString());

                        await Task.Delay(1000);

                        animation.Clear();
                    }

                    foreach (var(rarity, emoji) in box)
                    {
                        var trans = Transaction.FromLootbox(marketId: 0, buyer: inventory.UserId, variety.Name);

                        inventory.Add(new Models.Emoji
                        {
                            Owner        = Context.User.Id,
                            Transactions = new List <TransactionInfo>()
                            {
                                Context.Bot.Clerk.Queue(trans).Receive()
                            },
                            Unicode = emoji
                        }, true);

                        text.Append($"{rarity.LeftBracket}{emoji}{rarity.RightBracket}");
                    }
                    text.AppendLine();
                }

                inventory.Save();
                await message.ModifyAsync(m => m.Content = text.ToString());
            }
    public override void OnInspectorGUI()
    {
        chest.openingMethod =
            (OpeningMethods)EditorGUILayout.EnumPopup("Opening Method", chest.openingMethod);

        if (chest.openingMethod == OpeningMethods.OpenOnCollision ||
            chest.openingMethod == OpeningMethods.OpenOnKeyPress)
        {
            chest.playerTag = EditorGUILayout.TextField("Player Tag", chest.playerTag);
            if (chest.openingMethod == OpeningMethods.OpenOnKeyPress)
            {
                chest.keyCode = (KeyCode)EditorGUILayout.EnumPopup("Key Code", chest.keyCode);
            }
        }

        chest.bouncingBox = EditorGUILayout.Toggle("Bouncing Animation", chest.bouncingBox);
        chest.BounceBox(chest.bouncingBox);

        chest.closeOnExit = EditorGUILayout.Toggle("Close On Exit", chest.closeOnExit);

        if (EditorApplication.isPlaying)
        {
            if (chest.isOpen)
            {
                if (GUILayout.Button("Close Chest"))
                {
                    chest.Close();
                }
            }
            else
            {
                if (GUILayout.Button("Open Chest"))
                {
                    chest.Open();
                }
            }
        }

        SerializedProperty loots = serializedObject.FindProperty("boxContents");

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(loots, true);
        EditorGUI.EndChangeCheck();

        serializedObject.ApplyModifiedProperties();
        if (GUI.changed && !EditorApplication.isPlaying)
        {
            EditorUtility.SetDirty(chest);
            UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(chest.gameObject.scene);
        }
    }