示例#1
0
        /// <summary>
        /// Returns the Uri and local file names of the files in the specified uri that match the search pattern.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="searchPattern"></param>
        /// <returns></returns>
        public static Doublet<Uri, FileInfo>[] GetFiles(this Uri uri, string searchPattern, bool recursiveSearch)
        {
            if (!uri.IsFileScheme())
            {
                throw new ArgumentException(String.Format("Expecting Uri scheme to be \'{0}\'.  Actual scheme is \'{1}\'."
                    , Uri.UriSchemeFile, uri.Scheme));
            }

            string searchFilePath = uri.GetFilePath();
            if (!Directory.Exists(searchFilePath))
            {
                return new Doublet<Uri, FileInfo>[0];
            }

            string pattern = !String.IsNullOrEmpty(searchPattern) ? searchPattern : "*";

            SearchOption searchOption = (recursiveSearch) ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
            string[] filePaths = Directory.GetFiles(searchFilePath, pattern, searchOption);
            if (filePaths.Length == 0)
            {
                return new Doublet<Uri, FileInfo>[0];
            }
            else
            {
                List<Doublet<Uri, FileInfo>> physicalFiles = new List<Doublet<Uri, FileInfo>>();
                foreach (string filePath in filePaths)
                {
                    Doublet<Uri, FileInfo> uriFileInfoPair = new Doublet<Uri, FileInfo>()
                    {
                        First = new Uri(String.Format("{0}:{1}", Uri.UriSchemeFile, filePath)),
                        Second = new FileInfo(filePath)
                    };

                    physicalFiles.Add(uriFileInfoPair);
                }

                return physicalFiles.ToArray();
            }
        }
示例#2
0
		public XmlQuestNPC( int gender )
			: base( AIType.AI_Melee, FightMode.None, 10, 1, 0.8, 3.0 )
		{
			SetStr( 10, 30 );
			SetDex( 10, 30 );
			SetInt( 10, 30 );

			Fame = 50;
			Karma = 50;

			CanHearGhosts = true;

			SpeechHue = Utility.RandomDyedHue();
			Title = string.Empty;
			Hue = Utility.RandomSkinHue();

			switch( gender )
			{
				case -1: this.Female = Utility.RandomBool(); break;
				case 0: this.Female = false; break;
				case 1: this.Female = true; break;
			}

			if( this.Female )
			{
				this.Body = 0x191;
				this.Name = NameList.RandomName( "female" );
				Item hair = new Item( Utility.RandomList( 0x203B, 0x203C, 0x203D, 0x2045, 0x204A, 0x2046, 0x2049 ) );
				hair.Hue = Utility.RandomHairHue();
				hair.Layer = Layer.Hair;
				hair.Movable = false;
				AddItem( hair );
				Item hat = null;
				switch( Utility.Random( 5 ) )//4 hats, one empty, for no hat
				{
					case 0: hat = new FloppyHat( Utility.RandomNeutralHue() ); break;
					case 1: hat = new FeatheredHat( Utility.RandomNeutralHue() ); break;
					case 2: hat = new Bonnet(); break;
					case 3: hat = new Cap( Utility.RandomNeutralHue() ); break;
				}
				AddItem( hat );
				Item pants = null;
				switch( Utility.Random( 3 ) )
				{
					case 0: pants = new ShortPants( GetRandomHue() ); break;
					case 1: pants = new LongPants( GetRandomHue() ); break;
					case 2: pants = new Skirt( GetRandomHue() ); break;
				}
				AddItem( pants );
				Item shirt = null;
				switch( Utility.Random( 7 ) )
				{
					case 0: shirt = new Doublet( GetRandomHue() ); break;
					case 1: shirt = new Surcoat( GetRandomHue() ); break;
					case 2: shirt = new Tunic( GetRandomHue() ); break;
					case 3: shirt = new FancyDress( GetRandomHue() ); break;
					case 4: shirt = new PlainDress( GetRandomHue() ); break;
					case 5: shirt = new FancyShirt( GetRandomHue() ); break;
					case 6: shirt = new Shirt( GetRandomHue() ); break;
				}
				AddItem( shirt );
			}
			else
			{
				this.Body = 0x190;
				this.Name = NameList.RandomName( "male" );
				Item hair = new Item( Utility.RandomList( 0x203B, 0x203C, 0x203D, 0x2044, 0x2045, 0x2047, 0x2048 ) );
				hair.Hue = Utility.RandomHairHue();
				hair.Layer = Layer.Hair;
				hair.Movable = false;
				AddItem( hair );
				Item beard = new Item( Utility.RandomList( 0x0000, 0x203E, 0x203F, 0x2040, 0x2041, 0x2067, 0x2068, 0x2069 ) );
				beard.Hue = hair.Hue;
				beard.Layer = Layer.FacialHair;
				beard.Movable = false;
				AddItem( beard );
				Item hat = null;
				switch( Utility.Random( 7 ) ) //6 hats, one empty, for no hat
				{
					case 0: hat = new SkullCap( GetRandomHue() ); break;
					case 1: hat = new Bandana( GetRandomHue() ); break;
					case 2: hat = new WideBrimHat(); break;
					case 3: hat = new TallStrawHat( Utility.RandomNeutralHue() ); break;
					case 4: hat = new StrawHat( Utility.RandomNeutralHue() ); break;
					case 5: hat = new TricorneHat( Utility.RandomNeutralHue() ); break;
				}
				AddItem( hat );
				Item pants = null;
				switch( Utility.Random( 2 ) )
				{
					case 0: pants = new ShortPants( GetRandomHue() ); break;
					case 1: pants = new LongPants( GetRandomHue() ); break;
				}
				AddItem( pants );
				Item shirt = null;
				switch( Utility.Random( 5 ) )
				{
					case 0: shirt = new Doublet( GetRandomHue() ); break;
					case 1: shirt = new Surcoat( GetRandomHue() ); break;
					case 2: shirt = new Tunic( GetRandomHue() ); break;
					case 3: shirt = new FancyShirt( GetRandomHue() ); break;
					case 4: shirt = new Shirt( GetRandomHue() ); break;
				}
				AddItem( shirt );
			}

			Item feet = null;
			switch( Utility.Random( 3 ) )
			{
				case 0: feet = new Boots( Utility.RandomNeutralHue() ); break;
				case 1: feet = new Shoes( Utility.RandomNeutralHue() ); break;
				case 2: feet = new Sandals( Utility.RandomNeutralHue() ); break;
			}
			AddItem( feet );
			Container pack = new Backpack();

			pack.Movable = false;

			AddItem( pack );
		}
        private static void WritePlayer(Packet pPacket, DatabaseQuery pQuery)
        {
            pPacket.WriteInt((int)pQuery["identifier"]);
            pPacket.WritePaddedString((string)pQuery["name"], 13);

            pPacket.WriteByte((byte)pQuery["gender"]);
            pPacket.WriteByte((byte)pQuery["skin"]);
            pPacket.WriteInt((int)pQuery["eyes_identifier"]);
            pPacket.WriteInt((int)pQuery["hair_identifier"]);
            pPacket.WriteSkip(24);
            pPacket.WriteByte((byte)pQuery["level"]);
            pPacket.WriteUShort((ushort)pQuery["job"]);
            pPacket.WriteUShort((ushort)pQuery["strength"]);
            pPacket.WriteUShort((ushort)pQuery["dexterity"]);
            pPacket.WriteUShort((ushort)pQuery["intellect"]);
            pPacket.WriteUShort((ushort)pQuery["luck"]);
            pPacket.WriteUShort((ushort)pQuery["health"]);
            pPacket.WriteUShort((ushort)pQuery["max_health"]);
            pPacket.WriteUShort((ushort)pQuery["mana"]);
            pPacket.WriteUShort((ushort)pQuery["max_mana"]);
            pPacket.WriteUShort((ushort)pQuery["ability_points"]);
            pPacket.WriteUShort((ushort)pQuery["skill_points"]);
            pPacket.WriteInt((int)pQuery["experience"]);
            pPacket.WriteUShort((ushort)pQuery["fame"]);
            pPacket.WriteSkip(4);
            pPacket.WriteInt((int)pQuery["map_identifier"]);
            pPacket.WriteByte((byte)pQuery["map_spawn"]);
            pPacket.WriteSkip(4);

            pPacket.WriteByte((byte)pQuery["gender"]);
            pPacket.WriteByte((byte)pQuery["skin"]);
            pPacket.WriteInt((int)pQuery["eyes_identifier"]);
            pPacket.WriteBool(true);
            pPacket.WriteInt((int)pQuery["hair_identifier"]);

            SortedDictionary<byte, Doublet<int, int>> equipment = new SortedDictionary<byte, Doublet<int, int>>();
            using (DatabaseQuery queryEquipment = Database.Query("SELECT inventory_slot,item_identifier FROM player_item WHERE [email protected]_identifier AND inventory_type=0 AND inventory_slot<0", new MySqlParameter("@player_identifier", (int)pQuery["identifier"])))
            {
                while (queryEquipment.NextRow())
                {
                    short slot = (short)(-((short)queryEquipment["inventory_slot"]));
                    if (slot > 100) slot -= 100;
                    Doublet<int, int> pair = equipment.GetOrDefault((byte)slot, null);
                    if (pair == null)
                    {
                        pair = new Doublet<int, int>((int)queryEquipment["item_identifier"], 0);
                        equipment.Add((byte)slot, pair);
                    }
                    else if ((short)queryEquipment["inventory_slot"] < -100)
                    {
                        pair.Second = pair.First;
                        pair.First = (int)queryEquipment["item_identifier"];
                    }
                    else pair.Second = (int)queryEquipment["item_identifier"];
                }
            }
            foreach (KeyValuePair<byte, Doublet<int, int>> pair in equipment)
            {
                pPacket.WriteByte(pair.Key);
                if (pair.Key == 11 && pair.Value.Second > 0) pPacket.WriteInt(pair.Value.Second);
                else pPacket.WriteInt(pair.Value.First);
            }
            pPacket.WriteByte(0xFF);
            foreach (KeyValuePair<byte, Doublet<int, int>> pair in equipment)
            {
                if (pair.Key != 11 && pair.Value.Second > 0)
                {
                    pPacket.WriteByte(pair.Key);
                    pPacket.WriteInt(pair.Value.Second);
                }
            }
            pPacket.WriteByte(0xFF);
            Doublet<int, int> cashWeapon = equipment.GetOrDefault((byte)11, null);
            pPacket.WriteInt(cashWeapon == null ? 0 : cashWeapon.First);
            pPacket.WriteSkip(12);

            pPacket.WriteBool(false);
        }