Show some actual values in pokemon viewer (wip)

This commit is contained in:
Greg Edwards 2015-03-10 21:31:10 -04:00
parent b89eb29c62
commit 91fef43978
7 changed files with 292 additions and 15 deletions

View File

@ -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)

View File

@ -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<int> BlockScramble(uint personality)
{
int x = 4; // todo: this can be an argument but YAGNI

View File

@ -8,36 +8,40 @@
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMain" runat="server">
<asp:PlaceHolder ID="phSummary" runat="server">
<div class="gtsBox gtsPokemonSummary">
<div class="row basicInfo">
<div class="col colBasic1">
<ul>
<li class="nickname">
SparkySparky
<asp:Literal ID="litNickname" runat="server" />
</li>
<li class="portrait">
<asp:Image ID="imgPokemon" CssClass="sprite species" ImageUrl="~/images/pkmn-lg-s/25.png"
Width="96" Height="96" AlternateText="Pikachu" runat="server" />
<asp:Image ID="imgPokemon" CssClass="sprite species"
Width="96" Height="96" runat="server" />
</li>
<li class="specialFlags">
<span class="shiny">⁂</span>
<asp:PlaceHolder ID="phShiny" runat="server">
<span class="shiny">⁂</span>
</asp:PlaceHolder>
<%-- todo: use images for pkrs status --%>
<span class="pkrs">PKRS</span>
<span class="pkrs_cure">CURED</span>
<asp:PlaceHolder ID="phPkrs" runat="server">
<span class="pkrs">PKRS</span>
</asp:PlaceHolder>
<asp:PlaceHolder ID="phPkrsCured" runat="server">
<span class="pkrs_cure">CURED</span>
</asp:PlaceHolder>
&nbsp;
</li>
<li class="marks">
<span class="m">●</span>
<span class="m">▲</span>
<span>■</span>
<span class="m">♥</span>
<span class="m">★</span>
<span class="m">♦</span>
<asp:Literal ID="litMarks" runat="server" />
</li>
<li>
<asp:Image ID="imgPokeball" CssClass="sprite item" ImageUrl="~/images/item-sm/3004.png"
<asp:Image ID="imgPokeball" CssClass="sprite item"
Width="24" Height="24" runat="server" />
Lv. 20 ♂
Lv.
<asp:Literal ID="litLevel" runat="server" />
<asp:Literal ID="litGender" runat="server" />
</li>
</ul>
<p>Met December 19, 2014<br />
@ -163,4 +167,5 @@
<div class="clear"></div>
</div>
</asp:PlaceHolder>
</asp:Content>

View File

@ -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("<span class=\"m\">");
result.Append(m_marks[value]);
result.Append("</span>");
}
else
{
result.Append("<span>");
result.Append(m_marks[value]);
result.Append("</span>");
}
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 "";
}
}
}
}

View File

@ -12,6 +12,24 @@ namespace PkmnFoundations.Web.gts {
public partial class Pokemon {
/// <summary>
/// phSummary control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.PlaceHolder phSummary;
/// <summary>
/// litNickname control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal litNickname;
/// <summary>
/// imgPokemon control.
/// </summary>
@ -21,6 +39,42 @@ namespace PkmnFoundations.Web.gts {
/// </remarks>
protected global::System.Web.UI.WebControls.Image imgPokemon;
/// <summary>
/// phShiny control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.PlaceHolder phShiny;
/// <summary>
/// phPkrs control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.PlaceHolder phPkrs;
/// <summary>
/// phPkrsCured control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.PlaceHolder phPkrsCured;
/// <summary>
/// litMarks control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal litMarks;
/// <summary>
/// imgPokeball control.
/// </summary>
@ -30,6 +84,24 @@ namespace PkmnFoundations.Web.gts {
/// </remarks>
protected global::System.Web.UI.WebControls.Image imgPokeball;
/// <summary>
/// litLevel control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal litLevel;
/// <summary>
/// litGender control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal litGender;
/// <summary>
/// imgItem control.
/// </summary>

48
web/src/WebException.cs Normal file
View File

@ -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";
}
}
}
}

View File

@ -3577,6 +3577,7 @@
<Compile Include="src\RequireScript.cs" />
<Compile Include="src\RetinaImage.cs" />
<Compile Include="src\RetinaImageBase.cs" />
<Compile Include="src\WebException.cs" />
<Compile Include="test\BoxUp.aspx.cs">
<DependentUpon>BoxUp.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>