示例#1
0
        public void Load()
        {
            _expeditions = new Dictionary <uint, Expedition>();

            var contents = FileManager.GetFileContents($"{FileManager.AppPath}Data/expedition.json");

            if (string.IsNullOrWhiteSpace(contents))
            {
                throw new IOException($"File {FileManager.AppPath}Data/expedition.json doesn't exists or is empty.");
            }

            if (!JsonHelper.TryDeserializeObject(contents, out _config, out _)) // TODO here can out Exception
            {
                throw new Exception(
                          $"ExpeditionManager: Parse {FileManager.AppPath}Data/expedition.json file");
            }
            _nameRegex = new Regex(_config.NameRegex, RegexOptions.Compiled);

            using (var connection = MySQL.CreateConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT * FROM expeditions";
                    command.Prepare();
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var expedition = new Expedition();
                            expedition.Id              = reader.GetUInt32("id");
                            expedition.MotherId        = reader.GetUInt32("mother");
                            expedition.Name            = reader.GetString("name");
                            expedition.OwnerId         = reader.GetUInt32("owner");
                            expedition.OwnerName       = reader.GetString("owner_name");
                            expedition.UnitOwnerType   = 0;
                            expedition.PoliticalSystem = 1;
                            expedition.Created         = reader.GetDateTime("created_at");
                            expedition.AggroLink       = false;
                            expedition.DiplomacyTarget = false;

                            _expeditions.Add(expedition.Id, expedition);
                        }
                    }
                }

                foreach (var expedition in _expeditions.Values)
                {
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = "SELECT * FROM expedition_members WHERE expedition_id = @expedition_id";
                        command.Prepare();
                        command.Parameters.AddWithValue("@expedition_id", expedition.Id);
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var member = new ExpeditionMember();
                                member.CharacterId        = reader.GetUInt32("character_id");
                                member.ExpeditionId       = reader.GetUInt32("expedition_id");
                                member.Role               = reader.GetByte("role");
                                member.Memo               = reader.GetString("memo");
                                member.LastWorldLeaveTime = reader.GetDateTime("last_leave_time");
                                member.Name               = reader.GetString("name");
                                member.Level              = reader.GetByte("level");
                                member.Abilities          = new byte[]
                                {
                                    reader.GetByte("ability1"), reader.GetByte("ability2"), reader.GetByte("ability3")
                                };
                                member.IsOnline = false;
                                member.InParty  = false;
                                expedition.Members.Add(member);
                            }
                        }
                    }

                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText =
                            "SELECT * FROM expedition_role_policies WHERE expedition_id = @expedition_id";
                        command.Prepare();
                        command.Parameters.AddWithValue("@expedition_id", expedition.Id);
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var policy = new ExpeditionRolePolicy();
                                policy.Id              = reader.GetUInt32("expedition_id");
                                policy.Role            = reader.GetByte("role");
                                policy.Name            = reader.GetString("name");
                                policy.DominionDeclare = reader.GetBoolean("dominion_declare");
                                policy.Invite          = reader.GetBoolean("invite");
                                policy.Expel           = reader.GetBoolean("expel");
                                policy.Promote         = reader.GetBoolean("promote");
                                policy.Dismiss         = reader.GetBoolean("dismiss");
                                policy.Chat            = reader.GetBoolean("chat");
                                policy.ManagerChat     = reader.GetBoolean("manager_chat");
                                policy.SiegeMaster     = reader.GetBoolean("siege_master");
                                policy.JoinSiege       = reader.GetBoolean("join_siege");
                                expedition.Policies.Add(policy);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
 public SCExpeditionMemberStatusChangedPacket(ExpeditionMember expeditionMember, byte flag) : base(SCOffsets.SCExpeditionMemberStatusChangedPacket, 5)
 {
     _expeditionMember = expeditionMember;
     _flag             = flag;
 }