Beispiel #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));
        }
        private void SetCurrentTypes()
        {
            Dictionary <string, List <string> > dictionatyTypes = new Files.FileParametersTypes().IninializeDictionatyTypeName();

            foreach (string item in CurrentTypes.Replace(" ", "").Split(','))
            {
                bool findSeparator = item.FirstOrDefault(f => f == '.') != char.MinValue;

                string nameParent = "";
                string nameChildren;

                if (findSeparator)
                {
                    string[] itemSubstring = item.Split('.');
                    nameParent   = itemSubstring[0];
                    nameChildren = itemSubstring[1];
                }
                else
                {
                    nameChildren = item;

                    foreach (KeyValuePair <string, List <string> > keyNames in dictionatyTypes)
                    {
                        foreach (string elementNames in keyNames.Value)
                        {
                            if (elementNames == nameChildren)
                            {
                                nameParent = keyNames.Key;
                                break;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(nameParent))
                {
                    var children = _treeType.Tree.FirstOrDefault(f => f.Text == nameParent)?.Children;

                    if (children != null)
                    {
                        for (int i = 0; i < children.Count; i++)
                        {
                            if (children[i].Text == nameChildren)
                            {
                                children[i].IsChecked = true;
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public Compiler TypePush(Type type, int popCount = 0)
        {
            for (int i = 0; i < popCount; i++)
            {
                CurrentTypes.Pop();
            }

            if (type != null)
            {
                CurrentTypes.Push(type);
            }

            return(this);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public Compiler EmitSource(string source, string label = null, bool isMethod = false, Node owner = null)
        {
            Compilation.ExecutableLines[CurrentAddrIdx] = new SourceData
            {
                Source   = source,
                Stack    = CurrentTypes.Any() ? CurrentTypes.Select(t => t.FullName).ToArray() : null,
                IsMethod = isMethod
            };

            if (!string.IsNullOrEmpty(label))
            {
                EmitLabelDef(label, owner, isMethod);
            }

            CurrentTypesDebug.Add($"{source} = {string.Join(",", CurrentTypes)}");
            return(this);
        }
Beispiel #6
0
 public Compiler TypePop()
 {
     CurrentTypes.Pop();
     return(this);
 }
Beispiel #7
0
 public Type TypePeek(int skip = 0)
 => Correct(CurrentTypes.Skip(skip).First());
Beispiel #8
0
        public static IEnumerable <String> ToText(this CurrentTypes CurrentTypesEnum)

        => CurrentTypesEnum.ToEnumeration().Select(item => item.ToString());
Beispiel #9
0
        public static IEnumerable <CurrentTypes> ToEnumeration(this CurrentTypes CurrentTypesEnum)

        => Enum.GetValues(typeof(CurrentTypes)).
        Cast <CurrentTypes>().
        Where(flag => CurrentTypesEnum.HasFlag(flag) && flag != CurrentTypes.Unspecified);
        /// <summary>
        /// Inherited from <see cref="IEntityGenerator"/>.
        /// Provides the content for a single object file.
        /// </summary>
        /// <param name="targetType">An <see cref="EdmType"/> representing the type to generate output for.</param>
        /// <param name="container">An <see cref="IEnumerable{EdmType}"/> list containing all types defined for reference.</param>
        /// <param name="writer">The <see cref="TextWriter"/> object to write too.</param>
        public void WriteObject(EdmType targetType, IEnumerable<EdmType> container, TextWriter writer)
        {
            if (targetType == null)
                throw new ArgumentNullException("targetType must not be null.");
            if (writer == null)
                throw new ArgumentNullException("writer must not be null.");

            if (targetType is EntityType)
                Type = CurrentTypes.Entity;
            else if (targetType is ComplexType)
                Type = CurrentTypes.ComplexType;
            else
                throw new ArgumentException("targetType must be of type EntityType or ComplexType");

            ParentType = targetType.BaseType;
            ChildTypes = container.Where(a => a.BaseType != null && a.BaseType.FullName == targetType.FullName);
            NamespaceName = targetType.NamespaceName;

            IEnumerable<EdmProperty> usableProperties = null;
            IEnumerable<NavigationProperty> usableNavProperties = null;

            if (Type == CurrentTypes.Entity)
            {
                EntityType entity = targetType as EntityType;

                usableProperties = (targetType as EntityType).Properties;
                usableNavProperties = (targetType as EntityType).NavigationProperties;

                usableProperties =
                    entity.BaseType == null ? entity.Properties : entity.Properties.Where(a => !(entity.BaseType as EntityType).Properties.Any(b => b.Name == a.Name));
                usableNavProperties =
                    ParentType == null ? entity.NavigationProperties : entity.NavigationProperties.Where(a => !(entity.BaseType as EntityType).NavigationProperties.Any(b => b.Name == a.Name));
            }
            else if (Type == CurrentTypes.ComplexType)
            {
                ComplexType complex = targetType as ComplexType;

                usableProperties = (targetType as ComplexType).Properties;
                usableNavProperties = Enumerable.Empty<NavigationProperty>();

                usableProperties =
                    complex.BaseType == null ? complex.Properties : complex.Properties.Where(a => !(complex.BaseType as ComplexType).Properties.Any(b => b.Name == a.Name));
            }

            string result = null;

            if (!string.IsNullOrEmpty(result = WriteDocumentation(targetType)))
                writer.Write(result);
            if (!string.IsNullOrEmpty(result = WriteTypeUsingStatements(targetType)))
                writer.Write(result);
            if (!string.IsNullOrEmpty(result = WriteTypeBeginNamespace(targetType)))
                writer.Write(result);
            if (!string.IsNullOrEmpty(result = WriteDocumentationType(targetType)))
                writer.Write(result);
            if (!string.IsNullOrEmpty(result = WriteTypeClassAttributes(targetType)))
                writer.Write(result);
            if (!string.IsNullOrEmpty(result = WriteTypeBeginClass(targetType)))
                writer.Write(result);

            foreach (EdmProperty property in usableProperties)
            {
                if (!string.IsNullOrEmpty(result = WriteTypeFieldAttributes(property)))
                    writer.Write(result);
                if (!string.IsNullOrEmpty(result = WriteTypeField(property)))
                    writer.Write(result);
            }
            foreach (NavigationProperty navProperty in usableNavProperties)
            {
                if (!string.IsNullOrEmpty(result = WriteTypeFieldAttributes(navProperty)))
                    writer.Write(result);
                if (!string.IsNullOrEmpty(result = WriteTypeField(navProperty)))
                    writer.Write(result);
            }

            writer.WriteLine();

            foreach (EdmProperty property in usableProperties)
            {
                if (!string.IsNullOrEmpty(result = WriteTypePropertyAttributes(property)))
                    writer.Write(result);
                if (!string.IsNullOrEmpty(result = WriteTypeProperty(property)))
                    writer.Write(result);
            }
            foreach (NavigationProperty navProperty in usableNavProperties)
            {
                if (!string.IsNullOrEmpty(result = WriteTypePropertyAttributes(navProperty)))
                    writer.Write(result);
                if (!string.IsNullOrEmpty(result = WriteTypeProperty(navProperty)))
                    writer.Write(result);
            }

            if (!string.IsNullOrEmpty(result = WriteTypeEndClass(targetType)))
                writer.Write(result);
            if (!string.IsNullOrEmpty(result = WriteTypeEndNamespace(targetType)))
                writer.Write(result);
        }