예제 #1
0
        public CreateStatus CreateCharacter(EmbeddedData dat, DbAccount acc, ushort type, int skin, out DbChar character)
        {
            var @class = dat.ObjectTypeToElement[type];

            if (_db.SetLength("alive." + acc.AccountId) >= acc.MaxCharSlot)
            {
                character = null;
                return(CreateStatus.ReachCharLimit);
            }

            var newId = (int)_db.HashIncrement(acc.Key, "nextCharId");

            character = new DbChar(acc, newId)
            {
                //LootCaches = new LootCache[] { },
                ObjectType      = type,
                Level           = 1,
                Experience      = 0,
                FakeExperience  = 0,
                IsFakeEnabled   = true,
                Bless1          = false,
                Bless2          = false,
                Bless3          = false,
                Bless4          = false,
                Bless5          = false,
                EnablePetAttack = true,
                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        = 0,
                FameStats  = new byte[0],
                TaskStats  = string.Empty,
                CreateTime = DateTime.UtcNow,
                LastSeen   = DateTime.UtcNow
            };
            character.FlushAsync();
            _db.SetAdd("alive." + acc.AccountId, BitConverter.GetBytes(newId));
            return(CreateStatus.OK);
        }
예제 #2
0
        public bool SaveCharacter(DbAccount acc, DbChar character, bool lockAcc)
        {
            var trans = _db.CreateTransaction();

            if (lockAcc)
            {
                trans.AddCondition(Condition.StringEqual($"lock.{acc.AccountId}", acc.LockToken));
            }

            character.FlushAsync(trans);

            var stats = new DbClassStats(acc);

            stats.Update(character);
            stats.FlushAsync(trans);

            return(trans.Execute());
        }