Example #1
0
        public static string CreatureTextLocale()
        {
            if (Storage.CreatureTexts.IsEmpty() || !Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_text_locale))
            {
                return(string.Empty);
            }



            /* can't use compare DB without knowing values of groupid or id
             * var entries = Storage.CreatureTexts.Keys.ToList();
             * var creatureTextDb = SQLDatabase.GetDict<uint, CreatureText>(entries);
             */

            var rows       = new RowList <CreatureText>();
            var rowLocales = new RowList <CreatureTextLocale>();
            Dictionary <uint, uint> entryCount = new Dictionary <uint, uint>();

            foreach (var text in Storage.CreatureTexts.OrderBy(t => t.Key))
            {
                foreach (var textValue in text.Value)
                {
                    var count = entryCount.ContainsKey(text.Key) ? entryCount[text.Key] : 0;

                    if (rows.Where(text2 => text2.Data.Text == textValue.Item1.Text).Count() != 0)
                    {
                        continue;
                    }

                    var row = new Row <CreatureTextLocale>
                    {
                        Data = new CreatureTextLocale
                        {
                            Entry   = text.Key,
                            GroupId = "" + count, ///@GROUP_ID+
                            ID      = "0",        ///@ID+
                            Text    = textValue.Item1.Text
                        },
                    };

                    if (!entryCount.ContainsKey(text.Key))
                    {
                        entryCount.Add(text.Key, count + 1);
                    }
                    else
                    {
                        entryCount[text.Key] = count + 1;
                    }

                    rowLocales.Add(row);
                }
            }

            return(new SQLInsert <CreatureTextLocale>(rowLocales, true).Build());
        }
Example #2
0
        public static string CreatureText()
        {
            if (Storage.CreatureTexts.IsEmpty() || !Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_text))
            {
                return(string.Empty);
            }

            // For each sound and emote, if the time they were send is in the +1/-1 seconds range of
            // our texts, add that sound and emote to our Storage.CreatureTexts

            foreach (var text in Storage.CreatureTexts)
            {
                // For each text
                foreach (var textValue in text.Value)
                {
                    // For each emote
                    var text1  = text;
                    var value1 = textValue;
                    foreach (var emoteValue in from emote in Storage.Emotes where emote.Key.GetEntry() == text1.Key from emoteValue in emote.Value let timeSpan = value1.Item2 - emoteValue.Item2 where timeSpan != null && timeSpan.Value.Duration() <= TimeSpan.FromSeconds(1) select emoteValue)
                    {
                        textValue.Item1.Emote = emoteValue.Item1;
                    }

                    // For each sound
                    var value = textValue;
                    foreach (var sound in from sound in Storage.Sounds let timeSpan = value.Item2 - sound.Item2 where timeSpan != null && timeSpan.Value.Duration() <= TimeSpan.FromSeconds(1) select sound)
                    {
                        textValue.Item1.Sound = sound.Item1;
                    }

                    List <int> textList;
                    if (SQLDatabase.BroadcastTexts.TryGetValue(textValue.Item1.Text, out textList) ||
                        SQLDatabase.BroadcastText1s.TryGetValue(textValue.Item1.Text, out textList))
                    {
                        if (textList.Count == 1)
                        {
                            textValue.Item1.BroadcastTextID = (uint)textList.First();
                        }
                        else
                        {
                            textValue.Item1.BroadcastTextID        = "PLEASE_SET_A_BROADCASTTEXT_ID";
                            textValue.Item1.BroadcastTextIDHelper  = "BroadcastTextID: ";
                            textValue.Item1.BroadcastTextIDHelper += string.Join(" - ", textList);
                        }
                    }

                    // Set comment
                    string from = null, to = null;
                    if (!textValue.Item1.SenderGUID.IsEmpty())
                    {
                        if (textValue.Item1.SenderGUID.GetObjectType() == ObjectType.Player)
                        {
                            from = "Player";
                        }
                        else
                        {
                            from = !string.IsNullOrEmpty(textValue.Item1.SenderName) ? textValue.Item1.SenderName : StoreGetters.GetName(StoreNameType.Unit, (int)textValue.Item1.SenderGUID.GetEntry(), false);
                        }
                    }

                    if (!textValue.Item1.ReceiverGUID.IsEmpty())
                    {
                        if (textValue.Item1.ReceiverGUID.GetObjectType() == ObjectType.Player)
                        {
                            to = "Player";
                        }
                        else
                        {
                            to = !string.IsNullOrEmpty(textValue.Item1.ReceiverName) ? textValue.Item1.ReceiverName : StoreGetters.GetName(StoreNameType.Unit, (int)textValue.Item1.ReceiverGUID.GetEntry(), false);
                        }
                    }

                    Trace.Assert(text.Key == textValue.Item1.SenderGUID.GetEntry() ||
                                 text.Key == textValue.Item1.ReceiverGUID.GetEntry());

                    if (from != null && to != null)
                    {
                        textValue.Item1.Comment = from + " to " + to;
                    }
                    else if (from != null)
                    {
                        textValue.Item1.Comment = from;
                    }
                    else
                    {
                        Trace.Assert(false);
                    }
                }
            }

            /* can't use compare DB without knowing values of groupid or id
             * var entries = Storage.CreatureTexts.Keys.ToList();
             * var creatureTextDb = SQLDatabase.GetDict<uint, CreatureText>(entries);
             */

            var rows = new RowList <CreatureText>();
            Dictionary <uint, uint> entryCount = new Dictionary <uint, uint>();

            foreach (var text in Storage.CreatureTexts.OrderBy(t => t.Key))
            {
                foreach (var textValue in text.Value)
                {
                    var count = entryCount.ContainsKey(text.Key) ? entryCount[text.Key] : 0;

                    if (rows.Where(text2 => text2.Data.Entry == text.Key && text2.Data.Text == textValue.Item1.Text).Count() != 0)
                    {
                        continue;
                    }

                    var row = new Row <CreatureText>
                    {
                        Data = new CreatureText
                        {
                            Entry           = text.Key,
                            GroupId         = "@GROUP_ID+" + count,
                            ID              = "@ID+",
                            Text            = textValue.Item1.Text,
                            Type            = textValue.Item1.Type,
                            Language        = textValue.Item1.Language,
                            Probability     = 100.0f,
                            Emote           = (textValue.Item1.Emote != null ? textValue.Item1.Emote : 0),
                            Duration        = 0,
                            Sound           = (textValue.Item1.Sound != null ? textValue.Item1.Sound : 0),
                            BroadcastTextID = textValue.Item1.BroadcastTextID,
                            Comment         = textValue.Item1.Comment
                        },

                        Comment = textValue.Item1.BroadcastTextIDHelper
                    };

                    if (!entryCount.ContainsKey(text.Key))
                    {
                        entryCount.Add(text.Key, count + 1);
                    }
                    else
                    {
                        entryCount[text.Key] = count + 1;
                    }

                    rows.Add(row);
                }
            }

            return(new SQLInsert <CreatureText>(rows, false).Build());
        }
 public static LoginUserIntegrate Row(this IdEnum value)
 {
     return(RowList.Where(item => item.IdName == IdEnumAttribute.IdNameFromEnum(value)).SingleOrDefault());
 }