Example #1
0
        public static XElement GetNews(AccountModel acc)
        {
            int      maxNews   = 7;
            int      newsCount = 0;
            XElement news      = new XElement("News");

            foreach (XElement item in Resources.News)
            {
                if (++newsCount > maxNews)
                {
                    break;
                }
                news.Add(item);
            }
            foreach (int d in acc.DeadChars)
            {
                if (++newsCount > maxNews)
                {
                    break;
                }
                CharacterModel character = LoadCharacter(acc, d);
                character.Load();
                news.Add(new XElement("Item",
                                      new XElement("Icon", "fame"),
                                      new XElement("Title", $"Your {Resources.Type2Player[(ushort)character.ClassType].DisplayId} died at Level {character.Level}"),
                                      new XElement("TagLine", $"Earning {character.Fame} Base Fame and {character.DeathFame} Total Fame"),
                                      new XElement("Link", $"fame:{character.Id}"),
                                      new XElement("Date", character.DeathTime)));
            }
            return(news);
        }
Example #2
0
        public static CharacterModel LoadCharacter(AccountModel acc, int charId)
        {
            CharacterModel character = new CharacterModel(acc.Id, charId);

            if (!character.IsNull)
            {
                character.Load();
            }
            return(character);
        }
Example #3
0
        public static void FlushLegends()
        {
            int time = UnixTime();

            Legends.Clear();
            foreach (KeyValuePair <string, TimeSpan> span in TimeSpans)
            {
                string[] legends = GetKeyLines($"legends.{span.Key}", true);
                if (span.Key != "all")
                {
                    legends = legends.Where(k => !((time - span.Value.TotalSeconds) > int.Parse(k.Split(':')[3]))).ToArray();
                    legends = legends.OrderByDescending(k => int.Parse(k.Split(':')[2])).ToArray();
                    SetKeyLines($"legends.{span.Key}", legends.ToArray(), true);
                }

                //Update famelist
                XElement list = new XElement("FameList");
                list.Add(new XAttribute("timespan", span.Key));

                foreach (string i in legends.Take(20))
                {
                    string[] s         = i.Split(':');
                    int      accId     = int.Parse(s[0]);
                    int      charId    = int.Parse(s[1]);
                    int      totalFame = int.Parse(s[2]);
                    int      deathTime = int.Parse(s[3]);

                    AccountModel acc = new AccountModel(accId);
                    //acc.Load(); Only name is accessed so no load needed

                    CharacterModel character = new CharacterModel(accId, charId);
                    character.Load();

                    list.Add(
                        new XElement("FameListElem",
                                     new XAttribute("accountId", accId),
                                     new XAttribute("charId", charId),
                                     new XElement("Name", acc.Name),
                                     new XElement("ObjectType", character.ClassType),
                                     new XElement("Tex1", character.Tex1),
                                     new XElement("Tex2", character.Tex2),
                                     new XElement("Texture", character.SkinType),
                                     new XElement("Equipment", string.Join(",", character.Inventory)),
                                     new XElement("ItemDatas", string.Join(",", character.ItemDatas)),
                                     new XElement("TotalFame", totalFame)));
                    Legends.Add(accId);
                }

                FameLists[span.Key] = list
                ;
            }
        }
Example #4
0
        public static bool DeleteCharacter(AccountModel acc, int charId)
        {
            if (!acc.AliveChars.Contains(charId))
            {
                return(false);
            }

            CharacterModel character = new CharacterModel(acc.Id, charId);

            character.Load();

            character.Deleted = true;
            character.Save();

            acc.AliveChars.Remove(charId);
            acc.Save();
            return(true);
        }