diff --git a/library/Pokedex/Pokedex.cs b/library/Pokedex/Pokedex.cs index 42389a5d..39fdc031 100644 --- a/library/Pokedex/Pokedex.cs +++ b/library/Pokedex/Pokedex.cs @@ -170,7 +170,7 @@ namespace PkmnFoundations.Pokedex // fixme: fact check the values for apricorn pokeballs. // What's used here is most assuredly wrong (and probably quite silly) // todo: add a PokeballValue field to the Items table and a dictionary here - return m_items_generations[Generations.Generation6][value]; + return m_items_generations[Generations.Generation5][value]; } public Move Moves(int value) diff --git a/library/Structures/PokemonBase.cs b/library/Structures/PokemonBase.cs index 481b644f..6d24c9d1 100644 --- a/library/Structures/PokemonBase.cs +++ b/library/Structures/PokemonBase.cs @@ -126,6 +126,17 @@ namespace PkmnFoundations.Structures public abstract Genders Gender { get; set; } public abstract String Nickname { get; set; } + public virtual bool IsShiny + { + get + { + // Gen3/4/5 formula. Gen6 must override. + uint step1 = Personality ^ TrainerID; + int step2 = (int)((step1 >> 16) ^ (step1 & 0xffffu)); + return step2 >> 3 == 0; + } + } + protected static List BlockScramble(uint personality) { int x = 4; // todo: this can be an argument but YAGNI diff --git a/web/gts/Pokemon.aspx b/web/gts/Pokemon.aspx index 45b2cd9e..2124c50d 100644 --- a/web/gts/Pokemon.aspx +++ b/web/gts/Pokemon.aspx @@ -8,36 +8,40 @@ +
  • - SparkySparky +
  • - +
  • - + + + <%-- todo: use images for pkrs status --%> - PKRS - CURED + + PKRS + + + CURED +  
  • - - - - - - +
  • - - Lv. 20 ♂ + Lv. + +

Met December 19, 2014
@@ -163,4 +167,5 @@

+ diff --git a/web/gts/Pokemon.aspx.cs b/web/gts/Pokemon.aspx.cs index 56e90656..77266738 100644 --- a/web/gts/Pokemon.aspx.cs +++ b/web/gts/Pokemon.aspx.cs @@ -1,17 +1,157 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using PkmnFoundations.Data; +using PkmnFoundations.Structures; +using PkmnFoundations.Support; namespace PkmnFoundations.Web.gts { public partial class Pokemon : System.Web.UI.Page { + private Pokedex.Pokedex m_pokedex; + protected void Page_Load(object sender, EventArgs e) { + m_pokedex = (Pokedex.Pokedex)Application["pkmncfPokedex"]; + Pokemon4 pkmn = null; + if (Request.QueryString.Count == 0 || Request.QueryString.Count > 2) throw new WebException(400); + if (Request.QueryString["offer"] != null || + Request.QueryString["exchange"] != null) + { + String generation = Request.QueryString["g"]; + if (generation == null || + Request.QueryString.Count != 2) + throw new WebException(400); + + int tradeId; + bool isExchanged; + + if (Request.QueryString["offer"] != null) + { + tradeId = Convert.ToInt32(Request.QueryString["offer"]); + isExchanged = false; + } + else if (Request.QueryString["exchange"] != null) + { + tradeId = Convert.ToInt32(Request.QueryString["exchange"]); + isExchanged = true; + } + else + { + AssertHelper.Unreachable(); + throw new WebException(400); + } + + // todo: when userprofiles are ready, add checks that they allow viewing their GTS history + switch (generation) + { + case "4": + { + GtsRecord4 record = Database.Instance.GtsGetRecord4(tradeId, isExchanged, true); + if (record != null) pkmn = new Pokemon4(m_pokedex, record.Data); + + } break; + case "5": + { + GtsRecord5 record = Database.Instance.GtsGetRecord5(tradeId, isExchanged, true); + if (record != null) pkmn = new Pokemon4(m_pokedex, record.Data); + + } break; + default: + throw new WebException(400); + } + } + else if (Request.QueryString["check"] != null) + { + int checkId = Convert.ToInt32(Request.QueryString["check"]); + throw new NotImplementedException(); + } + else throw new WebException(400); + + if (pkmn == null) + throw new WebException(403); + + Bind(pkmn); + } + + private void Bind(Pokemon4 pkmn) + { + litNickname.Text = pkmn.Nickname; + bool shiny = pkmn.IsShiny; + imgPokemon.ImageUrl = (shiny ? "~/images/pkmn-lg-s/" : "~/images/pkmn-lg/") + + SpeciesFilename(pkmn) + ".png"; + imgPokemon.AlternateText = pkmn.Species.Name.ToString(); + phShiny.Visible = shiny; + // todo: pokerus + phPkrs.Visible = false; + phPkrsCured.Visible = false; + litMarks.Text = CreateMarks(pkmn.Markings); + imgPokeball.ImageUrl = "~/images/item-sm/" + pkmn.Pokeball.ID.ToString() + ".png"; + imgPokeball.AlternateText = pkmn.Pokeball.Name.ToString(); + litLevel.Text = pkmn.Level.ToString(); + litGender.Text = CreateGender(pkmn.Gender); + } + + private String[] m_marks = new String[] { "●", "▲", "■", "♥", "★", "♦" }; + + private String CreateMarks(Markings markings) + { + StringBuilder result = new StringBuilder(); + int marking = 1; + for (int value = 0; value < 6; value++) + { + if (((int)markings & marking) != 0) + { + result.Append(""); + result.Append(m_marks[value]); + result.Append(""); + } + else + { + result.Append(""); + result.Append(m_marks[value]); + result.Append(""); + } + + marking <<= 1; + } + + return result.ToString(); + } + + private String SpeciesFilename(Pokemon4 pkmn) + { + // todo: move to a more central location + StringBuilder builder = new StringBuilder(); + builder.Append(pkmn.SpeciesID); + if (pkmn.Form.Suffix.Length > 0) + { + builder.Append('-'); + builder.Append(pkmn.Form.Suffix); + } + if (pkmn.Species.GenderVariations && pkmn.Gender == Genders.Female) + builder.Append("-f"); + + return builder.ToString(); + } + + private String CreateGender(Genders gender) + { + switch (gender) + { + case Genders.Male: + return "♂"; + case Genders.Female: + return "♀"; + default: + return ""; + } } } } \ No newline at end of file diff --git a/web/gts/Pokemon.aspx.designer.cs b/web/gts/Pokemon.aspx.designer.cs index 16a65fa5..e949bb3c 100644 --- a/web/gts/Pokemon.aspx.designer.cs +++ b/web/gts/Pokemon.aspx.designer.cs @@ -12,6 +12,24 @@ namespace PkmnFoundations.Web.gts { public partial class Pokemon { + /// + /// phSummary control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.PlaceHolder phSummary; + + /// + /// litNickname control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Literal litNickname; + /// /// imgPokemon control. /// @@ -21,6 +39,42 @@ namespace PkmnFoundations.Web.gts { /// protected global::System.Web.UI.WebControls.Image imgPokemon; + /// + /// phShiny control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.PlaceHolder phShiny; + + /// + /// phPkrs control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.PlaceHolder phPkrs; + + /// + /// phPkrsCured control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.PlaceHolder phPkrsCured; + + /// + /// litMarks control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Literal litMarks; + /// /// imgPokeball control. /// @@ -30,6 +84,24 @@ namespace PkmnFoundations.Web.gts { /// protected global::System.Web.UI.WebControls.Image imgPokeball; + /// + /// litLevel control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Literal litLevel; + + /// + /// litGender control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Literal litGender; + /// /// imgItem control. /// diff --git a/web/src/WebException.cs b/web/src/WebException.cs new file mode 100644 index 00000000..b2944f6c --- /dev/null +++ b/web/src/WebException.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace PkmnFoundations.Web +{ + public class WebException : Exception + { + public WebException(String message, int responseCode) : base(message) + { + ResponseCode = responseCode; + } + + public WebException(String message) : this(message, 500) + { + + } + + public WebException(int responseCode) : this(DefaultMessage(responseCode), responseCode) + { + + } + + public WebException() : this(500) + { + + } + + public int ResponseCode { get; private set; } + + public static String DefaultMessage(int responseCode) + { + switch (responseCode) + { + case 400: + return "Bad request"; + case 403: + return "Forbidden"; + case 404: + return "Not found"; + case 500: + default: + return "Server error"; + } + } + } +} \ No newline at end of file diff --git a/web/web.csproj b/web/web.csproj index 184e4f26..a972ab24 100644 --- a/web/web.csproj +++ b/web/web.csproj @@ -3577,6 +3577,7 @@ + BoxUp.aspx ASPXCodeBehind