Exemplo n.º 1
0
        /// <summary>
        /// returns a pokemon class.
        /// </summary>
        /// <param name="uid">the unique id of the pokemon.</param>
        /// <returns></returns>
        public static Classes.Pokemon GetPokemon(Guid uid)
        {
            if (!PokemonExists(uid))
            {
                throw new ArgumentException("Hey, bad!");
            }

            var table    = (DBDataSet.PokemonRow)_pkmnTable.GetByID(uid).Rows[0];
            var reqTable = (DBDataSet.RequirementsRow)_requTable.Get(uid).Rows[0];

            var requirements = new Classes.Requirements
            {
                Gender     = (Classes.Gender)reqTable.Gender,
                MinLevel   = reqTable.MinLevel,
                MaxLevel   = reqTable.MaxLevel,
                NationalID = reqTable.NationalID
            };

            return(new Classes.Pokemon
            {
                Blob = table.Chunk,
                Gender = (Classes.Gender)table.Gender,
                ID = table.UniqueID,
                NationalID = table.NationalID,
                Level = table.Level,
                Requirements = requirements
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs a search.
        /// </summary>
        /// <param name="request">The search parameters to follow.</param>
        /// <param name="ownerID">The current ID of the person searching.</param>
        /// <returns>A GUID which represents the search data to go look up in the SearchTracker class.</returns>
        public static Guid Search(Classes.SearchRequest request, Guid ownerID)
        {
            var sr         = _pkmnTable.GetSearch(request.NationalID, false);
            var resultList = new List <Classes.SearchPkm>();
            var searchID   = Guid.NewGuid();

            foreach (var rawRow in sr.Rows)
            {
                var pkmnRow = (DBDataSet.PokemonRow)rawRow;

                // Check to see if this pokemon has been traded, if so, continue on.
                if (pkmnRow.Traded)
                {
                    continue;
                }
                if (pkmnRow.Owner == ownerID)
                {
                    continue;
                }

                if ((pkmnRow.Level <= request.MaxLevel) &&
                    (pkmnRow.Level >= request.MinLevel))
                {
                    bool addPokemon;
                    // addPokemon = (Classes.Gender)pkmnRow.Gender != Classes.Gender.None ? request.Gender == Classes.Gender.Any ? true : request.Gender == (Classes.Gender)pkmnRow.Gender : true;

                    // See if it's genderless
                    if ((Classes.Gender)pkmnRow.Gender != Classes.Gender.None)
                    {
                        // It's not genderless.
                        // Check to see if the gender is acceptable.
                        if (request.Gender == Classes.Gender.Any)
                        {
                            addPokemon = true; // any gender, no cares.
                        }
                        else
                        {
                            // only add if the request matches the row.
                            addPokemon = (Classes.Gender)pkmnRow.Gender == request.Gender;
                        }
                    }
                    else
                    {
                        // Genderless, query doesn't matter.
                        addPokemon = true;
                    }

                    // Add only if true.
                    if (addPokemon)
                    {
                        // I also need to get the requirements!!!
                        var requirementsRow = (DBDataSet.RequirementsRow)_requTable.Get(pkmnRow.UniqueID).Rows[0];
                        var requirements    = new Classes.Requirements
                        {
                            NationalID = requirementsRow.NationalID,
                            MinLevel   = requirementsRow.MinLevel,
                            MaxLevel   = requirementsRow.MaxLevel,
                            Gender     = (Classes.Gender)requirementsRow.Gender
                        };


                        resultList.Add(new Classes.SearchPkm
                        {
                            Gender       = (Classes.Gender)pkmnRow.Gender,
                            ID           = pkmnRow.UniqueID,
                            Level        = pkmnRow.Level,
                            NationalID   = pkmnRow.NationalID,
                            Requirements = requirements
                        });
                    }
                }
            }

            // Query done, insert the results into the search manager
            SearchTracker.Add(searchID, resultList);

            // and return this
            return(searchID);
        }