예제 #1
0
        public void Init()
        {
            using (var connection = DatabaseManager.Instance.GetConnection())
            {
                BankMoney = InitBankMoney(connection);
                Inventory = new Inventory(this);
                Inventory.Init(connection, SlotType.Inventory);
                Inventory.Init(connection, SlotType.Equipments);
                Inventory.Init(connection, SlotType.Bank);
                if (ActivePran != null)
                {
                    Inventory.Init(connection, SlotType.PranInventory);
                    Inventory.Init(connection, SlotType.PranEquipments);
                }

                Quests = new Quests(this);
                Quests.Init(connection);
                Skills = new Skills(this);
                Skills.Init(connection);
                // Skillbars must be initialized after skills
                SkillsBar = new SkillsBar(this);
                SkillsBar.Init(connection);
                Friends = new Friends(this);
                Friends.Init(connection);
                Titles = new Titles(this);
                Titles.Init(connection);
            }

            IsInternalDisconnect = false;
        }
예제 #2
0
        public bool Save(SaveType saveType = SaveType.All)
        {
            using (var connection = DatabaseManager.Instance.GetConnection())
                using (var transaction = connection.BeginTransaction())
                {
                    try
                    {
                        var parameters = new Dictionary <string, object>
                        {
                            { "id", DbId },
                            { "acc_id", Account.DbId },
                            { "slot", Slot },
                            { "name", Name },
                            { "level", Level },
                            { "class", (ushort)Profession },
                            { "width", BodyTemplate.Width },
                            { "chest", BodyTemplate.Chest },
                            { "leg", BodyTemplate.Leg },
                            { "body", BodyTemplate.Body },
                            { "exp", Experience },
                            { "money", Money },
                            { "skill_points", SkillPoints },
                            { "attr_points", AttrPoints },
                            { "hp", Hp },
                            { "mp", Mp },
                            { "x", Position.CoordX },
                            { "y", Position.CoordY },
                            { "rotation", Position.Rotation },
                            { "honor_point", HonorPoints },
                            { "pvp_point", PvpPoints },
                            { "infamy_point", InfamyPoints },
                            { "str", Attributes.Strenght },
                            { "agi", Attributes.Agility },
                            { "int", Attributes.Intelligence },
                            { "const", Attributes.Constitution },
                            { "spi", Attributes.Spirit },
                            { "token", Token }
                        };
                        DatabaseManager.Instance.MySqlCommand(SqlCommandType.Replace, "characters", parameters, connection, transaction);

                        SaveBankMoney(connection, transaction);
                        switch (saveType)
                        {
                        case SaveType.All:
                            Inventory?.Save(connection, transaction);
                            Quests?.Save(connection, transaction);
                            Skills?.Save(connection, transaction);
                            Friends?.Save(connection, transaction);
                            Titles?.Save(connection, transaction);
                            break;

                        case SaveType.Inventory:
                            Inventory?.Save(connection, transaction);
                            break;

                        case SaveType.Quests:
                            Quests?.Save(connection, transaction);
                            break;

                        case SaveType.OnlyCharacter:
                            break;

                        case SaveType.Skills:
                            Skills?.Save(connection, transaction);
                            break;

                        case SaveType.SkillBars:
                            SkillsBar?.Save(connection, transaction);
                            break;

                        case SaveType.Friends:
                            Friends?.Save(connection, transaction);
                            break;

                        case SaveType.Titles:
                            Titles?.Save(connection, transaction);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(saveType), saveType, null);
                        }

                        transaction.Commit();
                        return(true);
                    }
                    catch (Exception e)
                    {
                        _log.Error(e);
                        transaction.Rollback();
                        Connection?.Close();
                        return(false);
                    }
                }
        }