Inheritance: SynchronizableBaseDTO
Exemple #1
0
 public CharacterSkill(CharacterSkillDTO dto)
 {
     this.CharacterId = dto.CharacterId;
     this.Id = dto.Id;
     this.SkillVNum = dto.SkillVNum;
     LastUse = DateTime.Now.AddHours(-1);
     Hit = 0;
 }
        public void CreateCharacter(string packet)
        {
            Logger.Debug(packet, Session.SessionId);
            if (Session.HasCurrentMap)
            {
                return;
            }

            // TODO: Hold Account Information in Authorized object
            long accountId = Session.Account.AccountId;
            string[] packetsplit = packet.Split(' ');

            byte slot = Convert.ToByte(packetsplit[3]);
            string characterName = packetsplit[2];
            Random random = new Random();
            if (slot <= 2 && DAOFactory.CharacterDAO.LoadBySlot(accountId, slot) == null)
            {
                if (characterName.Length > 3 && characterName.Length < 15)
                {
                    int isIllegalCharacter = 0;

                    System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^[\u0021-\u007E\u00A1-\u00AC\u00AE-\u00FF\u4E00-\u9FA5\u0E01-\u0E3A\u0E3F-\u0E5B]*$");
                    isIllegalCharacter = rg.Matches(characterName).Count;

                    if (isIllegalCharacter == 1)
                    {
                        if (DAOFactory.CharacterDAO.LoadByName(characterName) == null)
                        {
                            if (Convert.ToByte(packetsplit[3]) > 2)
                            {
                                return;
                            }
                            CharacterDTO newCharacter = new CharacterDTO()
                            {
                                Class = (byte)ClassType.Adventurer,
                                Gender = (GenderType)Enum.Parse(typeof(GenderType), packetsplit[4]),
                                HairColor = (HairColorType)Enum.Parse(typeof(HairColorType), packetsplit[6]),
                                HairStyle = (HairStyleType)Enum.Parse(typeof(HairStyleType), packetsplit[5]),
                                Hp = 221,
                                JobLevel = 1,
                                Level = 1,
                                MapId = 1,
                                MapX = (short)(random.Next(78, 81)),
                                MapY = (short)(random.Next(114, 118)),
                                Mp = 221,
                                SpPoint = 10000,
                                SpAdditionPoint = 0,
                                Name = characterName,
                                Slot = slot,
                                AccountId = accountId,
                                State = CharacterState.Active,
                            };

                            SaveResult insertResult = DAOFactory.CharacterDAO.InsertOrUpdate(ref newCharacter);
                            CharacterSkillDTO sk1 = new CharacterSkillDTO { CharacterId = newCharacter.CharacterId, SkillVNum = 200 };
                            CharacterSkillDTO sk2 = new CharacterSkillDTO { CharacterId = newCharacter.CharacterId, SkillVNum = 201 };
                            CharacterSkillDTO sk3 = new CharacterSkillDTO { CharacterId = newCharacter.CharacterId, SkillVNum = 209 };
                            QuicklistEntryDTO qlst1 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type = 1,
                                Slot = 1,
                                Pos = 1
                            };
                            QuicklistEntryDTO qlst2 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Q2 = 1,
                                Slot = 2,
                            };
                            QuicklistEntryDTO qlst3 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Q2 = 8,
                                Type = 1,
                                Slot = 1,
                                Pos = 16
                            };
                            QuicklistEntryDTO qlst4 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Q2 = 9,
                                Type = 1,
                                Slot = 3,
                                Pos = 1
                            };
                            qlst1 = DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst1);
                            qlst2 = DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst2);
                            qlst3 = DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst3);
                            qlst4 = DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst4);
                            sk1 = DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk1);
                            sk2 = DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk2);
                            sk3 = DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk3);

                            IList<ItemInstanceDTO> startupInventory = new List<ItemInstanceDTO>();
                            ItemInstance inventory = new WearableInstance() // first weapon
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot = (byte)EquipmentType.MainWeapon,
                                Type = InventoryType.Wear,
                                Amount = 1,
                                ItemVNum = 1,
                            };
                            startupInventory.Add(inventory);

                            inventory = new WearableInstance() // second weapon
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot = (byte)EquipmentType.SecondaryWeapon,
                                Type = InventoryType.Wear,
                                Amount = 1,
                                ItemVNum = 8
                            };
                            startupInventory.Add(inventory);

                            inventory = new WearableInstance() // armor
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot = (byte)EquipmentType.Armor,
                                Type = InventoryType.Wear,
                                Amount = 1,
                                ItemVNum = 12
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // snack
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type = InventoryType.Etc,
                                Amount = 10,
                                ItemVNum = 2024
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // ammo
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot = 1,
                                Type = InventoryType.Etc,
                                Amount = 1,
                                ItemVNum = 2081
                            };
                            startupInventory.Add(inventory);

                            DAOFactory.ItemInstanceDAO.InsertOrUpdate(startupInventory);
                            LoadCharacters(packet);
                        }
                        else
                        {
                            Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("ALREADY_TAKEN")}");
                        }
                    }
                    else
                    {
                        Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("INVALID_CHARNAME")}");
                    }
                }
            }
        }