Ejemplo n.º 1
0
        /// <summary>
        /// Sets the outfit of the provided <see cref="XMPPClient"/>.
        /// </summary>
        /// <param name="xmppClient">The <see cref="XMPPClient"/> to set the outfit for.</param>
        /// <param name="outfit">The name of the desired outfit.</param>
        /// <param name="variantName">The name of the desired variant, this is optional.</param>
        public async Task SetOutfit(XMPPClient xmppClient, string outfit, string variantName = null)
        {
            Dictionary <string, object> patches = new();

            // Get the outfit by its name.
            var cosmetic = await CosmeticHelper.GetCosmeticByName(outfit, "AthenaCharacter");

            // If the user provided a variant name...
            if (variantName != null)
            {
                // Get the current loadout variants from the member meta.
                var currentLoadoutVariants = JsonConvert.DeserializeObject <AthenaCosmeticLoadoutVariants>(Meta["Default:AthenaCosmeticLoadoutVariants_j"]);

                // Get the desired variant.
                var variant = cosmetic.Variants.FirstOrDefault(x => x.Options.Any(x =>
                                                                                  string.Equals(x.Name, variantName, StringComparison.CurrentCultureIgnoreCase)));

                // Set the athenaCharacter loadout to the desired variant.
                currentLoadoutVariants.Data.VariantLoadout["athenaCharacter"] = new
                {
                    i = new List <XMPP.Meta.Variant>
                    {
                        new XMPP.Meta.Variant(variant.Channel, variant.Options.FirstOrDefault(x
                                                                                              => string.Equals(x.Name, variantName, StringComparison.CurrentCultureIgnoreCase)).Tag)
                    }
                };

                // Update the meta and add it to the patch.
                Meta["Default:AthenaCosmeticLoadoutVariants_j"] = currentLoadoutVariants.ToString();
                patches.Add("Default:AthenaCosmeticLoadoutVariants_j", Meta["Default:AthenaCosmeticLoadoutVariants_j"]);
            }

            // Get the current loadout from the member meta, and set its character item definition to the desired outfit.
            var currentLoadout = JsonConvert.DeserializeObject <AthenaCosmeticLoadout>(Meta["Default:AthenaCosmeticLoadout_j"]);

            currentLoadout.Data.CharacterItemDefinition = $"/Game/Athena/Items/Cosmetics/Characters/{cosmetic.Id}.{cosmetic.Id}";

            // Update the meta and add it to the patch.
            Meta["Default:AthenaCosmeticLoadout_j"] = currentLoadout.ToString();
            patches.Add("Default:AthenaCosmeticLoadout_j", Meta["Default:AthenaCosmeticLoadout_j"]);

            // Update the member.
            await PartyService.UpdateMember(xmppClient.AuthSession, this, xmppClient.CurrentParty.Id, patches);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the emoji of the provided <see cref="XMPPClient"/>.
        /// </summary>
        /// <param name="xmppClient">The <see cref="XMPPClient"/> to set the emoji for.</param>
        /// <param name="emoji">The name of the desired emoji.</param>
        public async Task SetEmoji(XMPPClient xmppClient, string emoji)
        {
            // Get the emoji by its name.
            var cosmetic = await CosmeticHelper.GetCosmeticByName(emoji, "AthenaEmoji");

            // If the client is emoting, clear the emote.
            if (JsonConvert.DeserializeObject <FrontendEmote>(Meta["Default:FrontendEmote_j"]).Data.EmoteItemDefinition != "None")
            {
                await ClearEmote(xmppClient);
            }

            // Update the meta.
            Meta["Default:FrontendEmote_j"] = new FrontendEmote(cosmetic.Id, true, -2).ToString();

            // Update the member.
            await PartyService.UpdateMember(xmppClient.AuthSession, this, xmppClient.CurrentParty.Id, new()
            {
                { "Default:FrontendEmote_j", Meta["Default:FrontendEmote_j"] }
            });
        }