package kamicharserver;

public class KamiChar {

    int id;
    byte cid;
    String name;
    String map;
    int posx;
    int posy;
    String sheet_file;
    String colors;
    byte type;
    byte level;
    int stats;
    int hp;
    int sp;
    int gold;
    
    public KamiChar() {}
    
    public KamiChar(int i, byte c, String n, String file, String col) {
	id = i;
	cid = c;
	name = n;
	map = "w/world/start.map";
	posx = 500;
	posy = 500;
	sheet_file = file;
	colors = col;
	type = 0;
	level = 1;
	stats = 0x01010101;
	hp = 0x000f000f;
	sp = 0x00050005;
	gold = 100;
	
    }
    
    public void fillFromResult(java.sql.ResultSet res) throws java.sql.SQLException {
        
        id = res.getInt("id");
        cid = res.getByte("cid");
        name = res.getString("name");
        map = res.getString("map");
        posx = res.getInt("posx");
        posy = res.getInt("posy");
        sheet_file = res.getString("sheet_file");
        colors = res.getString("colors");
        type = res.getByte("class");
        level = res.getByte("level");
        stats = res.getInt("stats");
        hp = res.getInt("hp");
        sp = res.getInt("sp");
        gold = res.getInt("gold");
        
    }
    
    public KamiCommand getCommand() {   
        KamiCommand kc = new KamiCommand();
        kc.set(0,id);
        kc.set(1,cid);
        kc.set(2,name);
        kc.set(3,map);
        kc.set(4,posx);
        kc.set(5,posy);
        kc.set(6,sheet_file);
        kc.set(7,colors);
        kc.set(8,type);
        kc.set(9,level);
        kc.set(10,stats);
        kc.set(11,hp);
        kc.set(12,sp);
        kc.set(13,gold);
        return kc;
    }
    
    // =========================================================================
    // Misc.
    //
    public byte getCID() {
        return cid;
    }
    
    public static KamiChar getFromResult(java.sql.ResultSet res) throws java.sql.SQLException {
        KamiChar kc = new KamiChar();
        kc.fillFromResult(res);
        return kc;
    }
}
