Пример #1
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);
        }
Пример #2
0
        public static void Death(string killer, AccountModel acc, CharacterModel character)
        {
#if DEBUG
            if (character == null)
            {
                throw new Exception("Undefined character model");
            }
#endif
            acc.AliveChars.Remove(character.Id);
            if (acc.DeadChars.Count == AccountModel.MaxDeadCharsStored)
            {
                acc.DeadChars.RemoveAt(AccountModel.MaxDeadCharsStored - 1);
            }
            acc.DeadChars.Insert(0, character.Id);

            int deathTime = UnixTime();
            int baseFame  = character.Fame;
            int totalFame = character.Fame;

            XElement fame = new XElement("Fame");
            XElement ce   = character.ExportFame();
            ce.Add(new XAttribute("id", character.Id));
            ce.Add(new XElement("Account", new XElement("Name", acc.Name)));
            fame.Add(ce);
            character.FameStats.ExportTo(fame);

            ClassStatsInfo classStats = acc.Stats.GetClassStats(character.ClassType);
            FameStats      fameStats  = CalculateStats(acc, character, killer);
            totalFame = fameStats.TotalFame;
            foreach (FameBonus bonus in fameStats.Bonuses)
            {
                fame.Add(new XElement("Bonus", new XAttribute("id", bonus.Name), bonus.Fame));
            }

            fame.Add(new XElement("CreatedOn", character.CreationTime));
            fame.Add(new XElement("KilledOn", deathTime));
            fame.Add(new XElement("KilledBy", killer));
            fame.Add(new XElement("BaseFame", baseFame));
            fame.Add(new XElement("TotalFame", totalFame));

            if (classStats.BestFame < baseFame)
            {
                classStats.BestFame = baseFame;
            }

            if (classStats.BestLevel < character.Level)
            {
                classStats.BestLevel = character.Level;
            }


            character.Dead      = true;
            character.DeathTime = UnixTime();
            character.DeathFame = totalFame;
            character.Save();

            acc.Stats.Fame         += totalFame;
            acc.Stats.TotalCredits += totalFame;
            acc.Save();

            if (character.Fame >= MinFameRequiredToEnterLegends)
            {
                PushLegend(acc.Id, character.Id, totalFame, deathTime);
            }

            CreateKey($"death.{acc.Id}.{character.Id}", fame.ToString());
        }
Пример #3
0
 public static void SaveCharacter(CharacterModel character)
 {
     character.Save();
 }
Пример #4
0
        public static CharacterModel CreateCharacter(AccountModel acc, int classType, int skinType)
        {
#if DEBUG
            if (acc == null)
            {
                throw new Exception("Account is null.");
            }
#endif
            if (!HasEnoughCharacterSlots(acc))
            {
                return(null);
            }

            if (!Resources.Type2Player.TryGetValue((ushort)classType, out PlayerDesc player))
            {
                return(null);
            }

            if (skinType != 0)
            {
                if (!Resources.Type2Skin.TryGetValue((ushort)skinType, out SkinDesc skin))
                {
                    return(null);
                }
                if (skin.PlayerClassType != classType)
                {
                    return(null);
                }
            }

            int newId = acc.NextCharId;
            acc.NextCharId++;
            acc.AliveChars.Add(newId);
            acc.Save();

            CharacterModel character = new CharacterModel(acc.Id, newId)
            {
                ClassType     = classType,
                Level         = 1,
                Experience    = 0,
                Fame          = 0,
                Inventory     = player.Equipment.ToArray(),
                ItemDatas     = player.ItemDatas.ToArray(),
                Stats         = player.StartingValues.ToArray(),
                HP            = player.StartingValues[0],
                MP            = player.StartingValues[1],
                Tex1          = 0,
                Tex2          = 0,
                SkinType      = skinType,
                HasBackpack   = false,
                HealthPotions = Player.MaxPotions,
                MagicPotions  = Player.MaxPotions,
                CreationTime  = UnixTime(),
                Deleted       = false,
                Dead          = false,
                DeathFame     = -1,
                DeathTime     = -1,
                FameStats     = new FameStatsInfo(),
                PetId         = -1
            };

            character.Save();
            return(character);
        }