using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.Odbc;
using Ultima;
using System.Drawing.Imaging;
using System.IO;
namespace xxx
{
/// <summary>
/// Summary description for CharacterInfo.
/// </summary>
public class CharacterInfoID : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Response.Clear();
bool ok = true;
int id=0;
try
{
id = int.Parse( Request.QueryString["CharID"] );
}
catch
{
ok = false;
return;
}
OdbcConnection con=new OdbcConnection(ConnectionConfig.ODBCConnectionString());
OdbcCommand commandText=new OdbcCommand();
commandText.Connection=con;
string name = "";
bool female=false;
ushort bodyhue = 0;
string nototitle = "";
if ( ok )
{
try
{
con.Open();
commandText.CommandText=String.Format("Select * from myrunuo_characters where char_id={0}",id.ToString());
OdbcDataReader characterReader = commandText.ExecuteReader();
if ( characterReader.Read() )
{
name = characterReader.GetString( 1 );
string fem = characterReader.GetString( 5 );
if (fem=="1") female=true;
bodyhue = Convert.ToUInt16(characterReader.GetInt32( 10 ));
nototitle = characterReader.GetString( 9 );
Session["public"]=characterReader.GetString(11);
}
characterReader.Close();
}
catch
{
ok=false;
}
}
if ( ok )
{
try
{
ArrayList itemEntries = new ArrayList();
commandText.CommandText =String.Format("SELECT * FROM myrunuo_characters_layers WHERE char_id={0} ORDER BY layer_id ASC",id.ToString());
OdbcDataReader layerReader = commandText.ExecuteReader();
while ( layerReader.Read() )
{
byte layerID = layerReader.GetByte( 1 );
ushort itemID = (ushort)layerReader.GetInt16( 2 );
ushort itemHue = (ushort)layerReader.GetInt16( 3 );
itemEntries.Add( new ItemEntry( layerID, itemID, itemHue ) );
}
layerReader.Close();
Bitmap surface = new Bitmap( 262, 324 );
Hues.GetHue((int)Color.White.GetHue()).ApplyTo(surface,false);
Graphics result = Graphics.FromImage( surface );
result.DrawImage( Ultima.Gumps.GetGump( 2001 ), 0, 0 ); // Paperdoll background
Font titleFont = new Font( "times", 10,FontStyle.Bold );
Brush titleBrush = Brushes.WhiteSmoke;
int index=nototitle.IndexOf(name);
string profession="";
int profindex=0;
if (nototitle.Length > (profindex=index + name.Length))
{
profession=nototitle.Substring(profindex+1,nototitle.Length-(profindex+1));
nototitle=nototitle.Substring(0,profindex);
}
result.DrawString( nototitle, titleFont, titleBrush, new PointF( 35, 270 ) );
if (profession!="")
result.DrawString(profession, titleFont, titleBrush, new PointF(35, 285));
Bitmap bodyImage = Ultima.Gumps.GetGump( female ? 13 : 12 ); // Body graphic
Hues.GetHue( bodyhue ).ApplyTo( bodyImage, false );
result.DrawImage(bodyImage, 0, 15 );
Bitmap status=Ultima.Gumps.GetGump( 2027);
result.DrawImage(status, new PointF(183,230));
Bitmap backpack=Ultima.Gumps.GetGump (50422);
result.DrawImage(backpack, 12,15);
if ( itemEntries.Count > 0 )
{
foreach ( ItemEntry entry in itemEntries )
{
Bitmap bmp = entry.CompileBitmap( female );
if ( bmp == null )
bmp = entry.CompileBitmap( !female );
if ( bmp != null )
{
Response.Write(bmp.Height);
if ( entry.Hue > 0 )
Hues.GetHue( entry.Hue ).ApplyTo( bmp, false );
result.DrawImage( bmp, 0, 15 );
bmp.Dispose();
}
}
}
MemoryStream memStream = new MemoryStream();
Response.Clear();
Response.ContentType="image/png";
surface.Save( memStream, ImageFormat.Png);
Response.BinaryWrite(memStream.ToArray());
con.Close();
if (result != null) result.Dispose();
if (surface != null) surface.Dispose();
Response.End();
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}
}
private class ItemEntry
{
private int m_LayerID, m_ItemID, m_ItemHue;
public int Hue{ get{ return m_ItemHue; } }
public ItemEntry( int layerID, int itemID, int itemHue )
{
m_LayerID = layerID;
m_ItemID = itemID;
m_ItemHue = itemHue;
}
public Bitmap CompileBitmap( bool female )
{
int gumpID = ( female ? 60000 : 50000 ) + Ultima.TileData.ItemTable[ m_ItemID ].Animation;
return Ultima.Gumps.GetGump( gumpID );
}
}
#region Web Form Designer generated code
protected override void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}