示例#1
0
        public void CreateCharacter(WorldClient client, string name, sbyte breedId, bool sex, IEnumerable <int> colors, int headId, Action successCallback, Action <CharacterCreationResultEnum> failCallback)
        {
            if ((long)client.Characters.Count >= (long)((ulong)MaxCharacterSlot) && client.UserGroup.Role <= RoleEnum.Player)
            {
                failCallback(CharacterCreationResultEnum.ERR_TOO_MANY_CHARACTERS);
            }
            else
            {
                if (this.DoesNameExist(name))
                {
                    failCallback(CharacterCreationResultEnum.ERR_NAME_ALREADY_EXISTS);
                }
                else
                {
                    if (!m_nameCheckerRegex.IsMatch(name))
                    {
                        failCallback(CharacterCreationResultEnum.ERR_INVALID_NAME);
                    }
                    else
                    {
                        Breed breed = Singleton <BreedManager> .Instance.GetBreed((int)breedId);

                        if (breed == null || !client.Account.CanUseBreed((int)breedId) || !Singleton <BreedManager> .Instance.IsBreedAvailable((int)breedId))
                        {
                            failCallback(CharacterCreationResultEnum.ERR_NOT_ALLOWED);
                        }
                        else
                        {
                            Head head = Singleton <BreedManager> .Instance.GetHead(headId);

                            if ((ulong)head.Breed != (ulong)((long)breedId) || head.Gender == 1u != sex)
                            {
                                failCallback(CharacterCreationResultEnum.ERR_NO_REASON);
                            }
                            else
                            {
                                ActorLook look  = breed.GetLook(sex ? SexTypeEnum.SEX_FEMALE : SexTypeEnum.SEX_MALE, true);
                                int       num   = 0;
                                uint[]    array = (!sex) ? breed.MaleColors : breed.FemaleColors;
                                foreach (int current in colors)
                                {
                                    if (array.Length > num)
                                    {
                                        look.AddColor(num + 1, (current == -1) ? Color.FromArgb((int)array[num]) : Color.FromArgb(current));
                                    }
                                    num++;
                                }
                                short[] skins = head.Skins;
                                for (int i = 0; i < skins.Length; i++)
                                {
                                    short skin = skins[i];
                                    look.AddSkin(skin);
                                }
                                CharacterRecord record;
                                using (Transaction transaction = Database.GetTransaction())
                                {
                                    record = new CharacterRecord(breed)
                                    {
                                        Experience       = Singleton <ExperienceManager> .Instance.GetCharacterLevelExperience(breed.StartLevel),
                                        Name             = name,
                                        Sex              = sex ? SexTypeEnum.SEX_FEMALE : SexTypeEnum.SEX_MALE,
                                        Head             = headId,
                                        EntityLook       = look,
                                        CreationDate     = DateTime.Now,
                                        LastUsage        = new DateTime?(DateTime.Now),
                                        AlignmentSide    = AlignmentSideEnum.ALIGNMENT_NEUTRAL,
                                        WarnOnConnection = true,
                                        WarnOnLevel      = true
                                    };
                                    Database.Insert(record);
                                    IOrderedEnumerable <BreedSpell> source =
                                        from spell in breed.Spells
                                        where spell.ObtainLevel <= (int)breed.StartLevel
                                        orderby spell.ObtainLevel, spell.Spell
                                    select spell;
                                    int num2 = 0;
                                    foreach (CharacterSpellRecord current2 in
                                             from learnableSpell in source
                                             select Singleton <SpellManager> .Instance.CreateSpellRecord(record, Singleton <SpellManager> .Instance.GetSpellTemplate(learnableSpell.Spell)))
                                    {
                                        Database.Insert(current2);
                                        SpellShortcut poco = new SpellShortcut(record, num2, (short)current2.SpellId);
                                        Database.Insert(poco);
                                        num2++;
                                    }
                                    foreach (PlayerItemRecord current3 in
                                             from startItem in breed.Items
                                             select startItem.GenerateItemRecord(record))
                                    {
                                        Database.Insert(current3);
                                    }
                                    this.OnCreatingCharacter(record);
                                    if (client.Characters == null)
                                    {
                                        client.Characters = new List <CharacterRecord>();
                                    }
                                    client.Characters.Insert(0, record);
                                    transaction.Complete();
                                }
                                IPCAccessor.Instance.SendRequest(new AddCharacterMessage(client.Account.Id, record.Id), delegate(CommonOKMessage x)
                                {
                                    successCallback();
                                }, delegate(IPCErrorMessage x)
                                {
                                    this.Database.Delete(record);
                                    failCallback(CharacterCreationResultEnum.ERR_NO_REASON);
                                });
                                logger.Debug("Character {0} created", record.Name);
                            }
                        }
                    }
                }
            }
        }