Example #1
0
 public bool SaveCharacter(DbAccount acc, DbChar character, bool lockAcc)
 {
     using (var trans = CreateTransaction())
     {
         if (lockAcc)
         {
             trans.AddCondition(Condition.KeyEquals(1,
                                                    $"lock.{acc.AccountId}", acc.LockToken));
         }
         character.Flush(trans);
         var stats = new DbClassStats(acc);
         stats.Update(character);
         stats.Flush(trans);
         return(trans.Execute().Exec());
     }
 }
Example #2
0
        public CreateStatus CreateCharacter(EmbeddedData dat, DbAccount acc, ushort type, int skin, out DbChar character)
        {
            var @class = dat.ObjectTypeToElement[type];

            if (Sets.GetLength(0, "alive." + acc.AccountId).Exec() >= acc.MaxCharSlot)
            {
                character = null;
                return(CreateStatus.ReachCharLimit);
            }

            int newId = (int)Hashes.Increment(0, acc.Key, "nextCharId").Exec();

            character = new DbChar(acc, newId)
            {
                ObjectType  = type,
                Level       = 1,
                Experience  = 0,
                Fame        = 0,
                HasBackpack = false,
                Items       = @class.Element("Equipment").Value.Replace("0xa22", "-1").CommaToArray <int>(),
                Stats       = new int[] {
                    int.Parse(@class.Element("MaxHitPoints").Value),
                    int.Parse(@class.Element("MaxMagicPoints").Value),
                    int.Parse(@class.Element("Attack").Value),
                    int.Parse(@class.Element("Defense").Value),
                    int.Parse(@class.Element("Speed").Value),
                    int.Parse(@class.Element("Dexterity").Value),
                    int.Parse(@class.Element("HpRegen").Value),
                    int.Parse(@class.Element("MpRegen").Value),
                },
                HP         = int.Parse(@class.Element("MaxHitPoints").Value),
                MP         = int.Parse(@class.Element("MaxMagicPoints").Value),
                Tex1       = 0,
                Tex2       = 0,
                Skin       = skin,
                Pet        = -1,
                FameStats  = new byte[0],
                CreateTime = DateTime.Now,
                LastSeen   = DateTime.Now
            };
            character.Flush();
            Sets.Add(0, "alive." + acc.AccountId, BitConverter.GetBytes(newId));
            return(CreateStatus.OK);
        }