コード例 #1
0
        /// <summary>
        /// Called from ArtifactScholar when he receives a whisper
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public override bool WhisperReceive(GameLiving source, GameLiving target, string text)
        {
            if (!(source is GamePlayer player) || !(target is ArtifactScholar scholar))
            {
                return(false);
            }

            // Did they send a valid string?
            if (CurrentTypes.Contains(text))
            {
                // Apend their choice to the chosen types
                ChosenTypes = $"{ChosenTypes}{text};";

                // Lets get the next set of options
                // Get the versions of this art
                Dictionary <string, ItemTemplate> versions = ArtifactMgr.GetArtifactVersions(ArtifactId, (eCharacterClass)player.CharacterClass.ID, player.Realm);

                // If we still have more options, give it to them
                if (GetNextOptions(versions) && _virtualStep < MaxNumOfSteps)
                {
                    SaveProperties();

                    scholar.TurnTo(player);
                    scholar.SayTo(player, $"Would you prefer {GetOptions()} of {ArtifactId}?");
                    Step++;
                }

                // Else lets hand them their finished artifact!
                else
                {
                    scholar.TurnTo(player);

                    // Attempt to get the right version of the artifact
                    ChosenTypes = ChosenTypes.Replace(";;", ";");

                    if (!versions.ContainsKey(ChosenTypes))
                    {
                        Log.Warn($"Artifact version {ChosenTypes} not found");
                        scholar.SayTo(player, eChatLoc.CL_PopupWindow, "I can't find your chosen replacement, it may not be available for your class. Please try again.");
                        ReturnArtifact(player);
                        return(true);
                    }

                    ItemTemplate template = versions[ChosenTypes];

                    if (GiveItem(player, template))
                    {
                        FinishQuest();
                        scholar.SayTo(player, eChatLoc.CL_PopupWindow, $"Here is your {ArtifactId}, {player.CharacterClass.Name}. May it serve you well!");
                        return(true);
                    }

                    return(false);
                }
            }

            return(base.WhisperReceive(source, target, text));
        }
コード例 #2
0
        private bool GetNextOptions(Dictionary <string, ItemTemplate> versions)
        {
            // Clear the current types since we are going to be offering more
            CurrentTypes.Clear();

            // Loop until we find the next set of options
            while (CurrentTypes.Count <= 1 && _virtualStep < MaxNumOfSteps)
            {
                // Go through each set of options in our list
                foreach (string str in versions.Keys)
                {
                    // Used as the key to store the option in the database
                    string[] splitVersion = str.Split(';');

                    // multiple versions may not available
                    if (splitVersion.Length <= _virtualStep)
                    {
                        return(false);
                    }

                    // Get the current option using our virtual step.  This gets the right option in the DT;WT;STAT; list
                    string type = splitVersion[_virtualStep];

                    // If we got a valid type and we don't already have it, put/save it
                    if (type != string.Empty && !CurrentTypes.Contains(type))
                    {
                        CurrentTypes.Add(type);
                    }
                }

                // If there was only one option added, obviously that is the only thing they can pick
                if (CurrentTypes.Count == 1)
                {
                    ChosenTypes = $"{ChosenTypes}{CurrentTypes[0]};";
                    CurrentTypes.Clear();
                }
                else if (CurrentTypes.Count == 0)
                {
                    // We need to add the end semi-colon even if we don't get an option!
                    ChosenTypes = $"{ChosenTypes};";
                }

                // Increment our virtual step, if this loops again it will proceed to the next set of options
                _virtualStep++;
            }

            return(true);
        }