internal Character CreateNewCharacter(CharacterCreatePacket characterCreatePacket, string accountUsername)
        {
            AccountDAO accMgr    = new AccountDAO(Server.ServerInstance.Database);
            int        accountID = accMgr.GetAccountID(accountUsername);

            if (GetCharactersByAccount(accountID).Length >= 4)
            {
                // Se necessario, possiamo creare due classi che ereditano da Exception per queste due eccezioni invece di usare SqlAlreadyFilledException.
                throw new SqlAlreadyFilledException(
                          "This account already have four characters. Is not allowed another character.");
            }
            if (GetCharacter(characterCreatePacket.CharacterName) != null)
            {
                throw new SqlAlreadyFilledException("A character with this name already exists!");
            }
            MySqlDataReader writer = // OK LOL!!!
                                     _conn.Query(
                string.Format("INSERT INTO `character` (`name`, `race`, `account_id`) VALUES ('{0}', {1}, {2})",
                              characterCreatePacket.CharacterName, characterCreatePacket.SexRace, accountID));

            // TODO: Add CharacterPosition (account-relative) & Look to character table.
            // TODO: Set all values for the record and so call GetCharacter(uint) to get a Character's instance and return...
            writer.Close();
            return(null);
        }
    private void SendCharacterCreateInfo(GameObject[] statNumbers, GameObject nameField, ushort statsAllowed)
    {
        ushort[] stats = new ushort[statNumbers.Length];
        for (int i = 0; i < statNumbers.Length; i++)
        {
            ushort stat = ushort.Parse(statNumbers[i].GetComponent <Text>().text);
            stats[i] = stat;
        }

        //    bytesToSend = o920i
        CharacterCreatePacket cp           = new CharacterCreatePacket(nameField.GetComponent <InputField>().text, stats, statsAllowed, CharacterSelect.selectedSlot);
        var        bytesToSend             = cp.GetData();
        SubPacket  sp                      = new SubPacket(GamePacketOpCode.CreateCharacter, 0, 0, bytesToSend, SubPacketTypes.GamePacket);
        BasePacket characterCreationPacket = BasePacket.CreatePacket(sp, PacketProcessor.isAuthenticated, false);
        var        box                     = gameObject.GetComponent <StatusBoxHandler>();

        // StatusBoxHandler.readyToClose = false;
        //modal status box is prefab
        box.InstantiateStatusBoxPrefabWithNoMenuLink(MenuPrefabs.StatusBox);
        StatusBoxHandler.statusText = "Waiting for response from server..";
        packetProcessor             = GameObject.FindGameObjectWithTag("PacketProcessor").GetComponent <PacketProcessor>();
        packetProcessor.SendPacket(characterCreationPacket);
        StartCoroutine(WaitForServerResponse(box));
    }
        /// <summary>
        /// Char_NEW character creation character
        /// </summary>
        /// <param name="characterCreatePacket"></param>
        public void CreateCharacter(CharacterCreatePacket characterCreatePacket)
        {
            if (Session.HasCurrentMapInstance)
            {
                return;
            }
            // TODO: Hold Account Information in Authorized object
            long   accountId     = Session.Account.AccountId;
            byte   slot          = characterCreatePacket.Slot;
            string characterName = characterCreatePacket.Name;

            if (slot > 2 || DaoFactory.CharacterDao.LoadBySlot(accountId, slot) != null)
            {
                return;
            }
            if (characterName.Length <= 3 || characterName.Length >= 15)
            {
                return;
            }
            Regex rg = new Regex(@"^[\u0021-\u007E\u00A1-\u00AC\u00AE-\u00FF\u4E00-\u9FA5\u0E01-\u0E3A\u0E3F-\u0E5B\u002E]*$");

            if (rg.Matches(characterName).Count == 1)
            {
                CharacterDTO character = DaoFactory.CharacterDao.LoadByName(characterName);
                if (character == null || character.State == CharacterState.Inactive)
                {
                    if (characterCreatePacket.Slot > 2)
                    {
                        return;
                    }
                    CharacterDTO newCharacter = new CharacterDTO
                    {
                        Class           = (byte)ClassType.Adventurer,
                        Gender          = characterCreatePacket.Gender,
                        HairColor       = characterCreatePacket.HairColor,
                        HairStyle       = characterCreatePacket.HairStyle,
                        Hp              = 221,
                        JobLevel        = 20,
                        Level           = 15,
                        MapId           = 1,
                        MapX            = (short)ServerManager.Instance.RandomNumber(78, 81),
                        MapY            = (short)ServerManager.Instance.RandomNumber(109, 112),
                        Mp              = 221,
                        MaxMateCount    = 10,
                        Gold            = 15000,
                        SpPoint         = 10000,
                        SpAdditionPoint = 0,
                        Name            = characterName,
                        Slot            = slot,
                        AccountId       = accountId,
                        MinilandMessage = "Welcome",
                        State           = CharacterState.Active
                    };

                    SaveResult        insertResult = DaoFactory.CharacterDao.InsertOrUpdate(ref newCharacter);
                    CharacterQuestDTO firstQuest   = new CharacterQuestDTO {
                        CharacterId = newCharacter.CharacterId, QuestId = 1997, IsMainQuest = true
                    };
                    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
                    };
                    DaoFactory.CharacterQuestDao.InsertOrUpdate(firstQuest);
                    DaoFactory.QuicklistEntryDao.InsertOrUpdate(qlst1);
                    DaoFactory.QuicklistEntryDao.InsertOrUpdate(qlst2);
                    DaoFactory.QuicklistEntryDao.InsertOrUpdate(qlst3);
                    DaoFactory.QuicklistEntryDao.InsertOrUpdate(qlst4);
                    DaoFactory.CharacterSkillDao.InsertOrUpdate(sk1);
                    DaoFactory.CharacterSkillDao.InsertOrUpdate(sk2);
                    DaoFactory.CharacterSkillDao.InsertOrUpdate(sk3);

                    Inventory startupInventory = new Inventory((Character)newCharacter);
                    startupInventory.AddNewToInventory(2024, 10, InventoryType.Etc);
                    startupInventory.AddNewToInventory(2081, 1, InventoryType.Etc);
                    startupInventory.AddNewToInventory(1907, 1, InventoryType.Main);
                    startupInventory.Select(s => s.Value).ToList().ForEach(i => DaoFactory.IteminstanceDao.InsertOrUpdate(i));

                    LoadCharacters(characterCreatePacket.OriginalContent);
                }
                else
                {
                    Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("ALREADY_TAKEN")}");
                }
            }
            else
            {
                Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("INVALID_CHARNAME")}");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Char_NEW character creation character
        /// </summary>
        /// <param name="characterCreatePacket"></param>
        public void CreateCharacter(CharacterCreatePacket characterCreatePacket)
        {
            Logger.Debug(Session.GenerateIdentity(), characterCreatePacket.ToString());
            if (Session.HasCurrentMapInstance)
            {
                return;
            }
            // TODO: Hold Account Information in Authorized object
            long   accountId     = Session.Account.AccountId;
            byte   slot          = characterCreatePacket.Slot;
            string characterName = characterCreatePacket.Name;

            if (slot <= 2 && DAOFactory.CharacterDAO.LoadBySlot(accountId, slot) == null)
            {
                if (characterName.Length > 3 && characterName.Length < 15)
                {
                    Regex rg = new Regex(@"^[\u0021-\u007E\u00A1-\u00AC\u00AE-\u00FF\u4E00-\u9FA5\u0E01-\u0E3A\u0E3F-\u0E5B\u002E]*$");
                    if (rg.Matches(characterName).Count == 1)
                    {
                        if (DAOFactory.CharacterDAO.LoadByName(characterName) == null)
                        {
                            if (characterCreatePacket.Slot > 2)
                            {
                                return;
                            }
                            CharacterDTO newCharacter = new CharacterDTO
                            {
                                Class           = (byte)ClassType.Adventurer,
                                Gender          = characterCreatePacket.Gender,
                                HairColor       = characterCreatePacket.HairColor,
                                HairStyle       = characterCreatePacket.HairStyle,
                                Hp              = 221,
                                JobLevel        = 1,
                                Level           = 1,
                                MapId           = 1,
                                MapX            = (short)ServerManager.Instance.RandomNumber(78, 81),
                                MapY            = (short)ServerManager.Instance.RandomNumber(114, 118),
                                Mp              = 221,
                                MaxMateCount    = 10,
                                SpPoint         = 10000,
                                SpAdditionPoint = 0,
                                Name            = characterName,
                                Slot            = slot,
                                AccountId       = accountId,
                                MinilandMessage = "Welcome",
                                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
                            };
                            DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst1);
                            DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst2);
                            DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst3);
                            DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst4);
                            DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk1);
                            DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk2);
                            DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk3);

                            Inventory startupInventory = new Inventory((Character)newCharacter);
                            startupInventory.AddNewToInventory(1, 1, InventoryType.Wear);
                            startupInventory.AddNewToInventory(8, 1, InventoryType.Wear);
                            startupInventory.AddNewToInventory(12, 1, InventoryType.Wear);
                            startupInventory.AddNewToInventory(2024, 10, InventoryType.Etc);
                            startupInventory.AddNewToInventory(2081, 1, InventoryType.Etc);
                            startupInventory.GetAllItems().ForEach(i => DAOFactory.IteminstanceDAO.InsertOrUpdate(i));

                            LoadCharacters(characterCreatePacket.OriginalContent);
                        }
                        else
                        {
                            Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("ALREADY_TAKEN")}");
                        }
                    }
                    else
                    {
                        Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("INVALID_CHARNAME")}");
                    }
                }
            }
        }
Ejemplo n.º 5
0
 private void CreateCharacter() //TODO move this call to player class
 {
     CharacterCreatePacket ccp       = (CharacterCreatePacket)ReadPacket(new CharacterCreatePacket());
     Character             character = Character.Create(AccountName, ccp);
 }
Ejemplo n.º 6
0
        internal static Character Create(string accountName, CharacterCreatePacket characterCreatePacket)
        {
            CharacterDAO chrMgr = new CharacterDAO(Server.ServerInstance.Database);

            return(chrMgr.CreateNewCharacter(characterCreatePacket, accountName)); // Cosa fare con OnCreate()?
        }