⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datarecorder.java

📁 《神州》RPG游戏引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

import java.util.*;
import javax.microedition.rms.*;

public class DataRecorder
{
    public static int TYPE_USED = 0;       //吃
    public static int TYPE_EQUIP = 1;      //part
    private static final String SEPARATOR = "&&";

    private DataRsIO xRsIO;
    public String[] retString;
    private String storeName;
    /*
     rsBag;             //可吃物品
     rsEquip;           //装备
     rsEquipUsed;       //使用中的装备
     rsScene;           //场景
     rsMainRole;        //角色信息
     rsRecordBook;      //保存信息
    */


    public DataRecorder()
    {
    }


    public void insRsSkills(String strOID)
    {
        String strValue = "";
        Vector vc = GameMIDlet.mainRole.getSkillVC();

        storeName = "rsSkills";
        xRsIO = new DataRsIO(storeName);
        xRsIO.open(storeName);

        for (int i=0; vc!=null && i<vc.size(); i++)
        {
            Skill tmp = (Skill)vc.elementAt(i);
            strValue = "OID=" + strOID + SEPARATOR;
            strValue += "SkillName=" + tmp.getName() + SEPARATOR;
            System.out.println(tmp.getName());

            xRsIO.insert(strValue);
        }
        xRsIO.close();
        xRsIO = null;
    }

    public void insRsMainRole(String strOID)
    {
        String strValue = "";
        strValue = "OID=" + strOID + SEPARATOR;
        //strValue += GameMIDlet.mainRole.getId() + SEPARATOR;
        strValue += "Lv=" + GameMIDlet.mainRole.getLv() + SEPARATOR;
        strValue += "Life=" + GameMIDlet.mainRole.getLife() + SEPARATOR;
        strValue += "MaxLife=" + GameMIDlet.mainRole.getMaxLife() + SEPARATOR;
        strValue += "Power=" + GameMIDlet.mainRole.getPower() + SEPARATOR;
        strValue += "Defence=" + GameMIDlet.mainRole.getDefence() + SEPARATOR;
        strValue += "Magic=" + GameMIDlet.mainRole.getMagic() + SEPARATOR;
        strValue += "MaxMagic=" + GameMIDlet.mainRole.getMaxMagic() + SEPARATOR;
        strValue += "Money=" + GameMIDlet.mainRole.getMoney() + SEPARATOR;
        strValue += "ActSpeed=" + GameMIDlet.mainRole.getActSpeed() + SEPARATOR;
        strValue += "Exp=" + GameMIDlet.mainRole.getExp() + SEPARATOR;
        strValue += "NextExp=" + GameMIDlet.mainRole.getNextExp() + SEPARATOR;
        strValue += "RoleX=" + GameMIDlet.mainRole.getX() + SEPARATOR;
        strValue += "RoleY=" + GameMIDlet.mainRole.getY() + SEPARATOR;
        strValue += "RoleDirect=" + GameMIDlet.mainRole.currentDirect + SEPARATOR;

        storeName = "rsMainRole";
        xRsIO = new DataRsIO(storeName);
        xRsIO.open(storeName);
        xRsIO.insert(strValue);
        xRsIO.close();
        xRsIO = null;
    }

    public void insRsEquipUsed(String strOID)
    {
        String strValue = "";
        Vector vc = GameMIDlet.mainRole.getEquipVC();

        storeName = "rsEquipUsed";
        xRsIO = new DataRsIO(storeName);
        xRsIO.open(storeName);

        if (vc != null)
        for (int i=0; i<vc.size(); i++)
        {
            Mat tmpMat = (Mat) vc.elementAt(i);
            strValue = "";
            strValue = "OID=" + strOID + SEPARATOR;
            strValue += "EquipName=" + tmpMat.getName()+ SEPARATOR;
            strValue += "EquipAmount=" + tmpMat.getAmount() + SEPARATOR;
            strValue += "EquipPart=" + tmpMat.getPart() + SEPARATOR;

            xRsIO.insert(strValue);
        }

        xRsIO.close();
        xRsIO = null;
    }
    public void insRsEquip(String strOID)
    {
        //没有使用的装备
        Vector vc = GameMIDlet.mainRole.getBagMatVC(Mat.TYPE_EQUIP);
        String strValue;

        storeName = "rsEquip";
        xRsIO = new DataRsIO(storeName);
        xRsIO.open(storeName);

        if (vc != null)
        for (int i=0; i<vc.size(); i++)
        {
            Mat tmpMat = (Mat)vc.elementAt(i);

            strValue = "OID=" + strOID + SEPARATOR;
            strValue += "EquipName=" + tmpMat.getName()+ SEPARATOR;
            strValue += "EquipAmount=" + tmpMat.getAmount() + SEPARATOR;

            xRsIO.insert(strValue);
        }

        xRsIO.close();
        xRsIO = null;
    }

    public void insBag(String strOID)
    {
        String strValue = "";
        Vector vc = GameMIDlet.mainRole.getBagMatVC(Mat.TYPE_USED);

        storeName = "rsBag";
        xRsIO = new DataRsIO(storeName);
        xRsIO.open(storeName);

        if (vc != null)
        for (int i=0; i < vc.size(); i++)
        {
            Mat tmpMat = (Mat) vc.elementAt(i);
            strValue = "OID=" + strOID + SEPARATOR;
            strValue += "MatName=" + tmpMat.getName()+ SEPARATOR;
            strValue += "MatAmount=" + tmpMat.getAmount() + SEPARATOR;
            //strValue += tmpMat.getPart() + SEPARATOR;

            xRsIO.insert(strValue);
        }
        xRsIO.close();
        xRsIO = null;
    }

    public void insScene(String strOID)
    {
        String strValue = "";
        strValue = "OID=" + strOID + SEPARATOR;
        strValue += "SceneIndex=" + SceneLib.currentSceneIndex + SEPARATOR;
        strValue += "isSonic=" + GameMIDlet.isSonic + SEPARATOR;
        strValue += "isVibratory=" + GameMIDlet.isVibratory + SEPARATOR;

        storeName = "rsScene";
        xRsIO = new DataRsIO(storeName);
        xRsIO.open(storeName);
        xRsIO.insert(strValue);
        xRsIO.close();
        xRsIO = null;
    }

    public void insRsMission(String strOID)
    {
        Vector vc = GameMIDlet.mainRole.getMissionVC();
        String strValue;

        storeName = "rsMission";
        xRsIO = new DataRsIO(storeName);
        xRsIO.open(storeName);

        for (int i=0; vc!=null && i<vc.size(); i++)
        {
            Mission tmp = (Mission)vc.elementAt(i);

            strValue = "OID=" + strOID + SEPARATOR;
            strValue += "MissionName=" + tmp.getName()+ SEPARATOR;
            strValue += "MissionStatus=" + tmp.getStatus() + SEPARATOR;
            strValue += "MainRole=" + GameMIDlet.mainRole.getName() + SEPARATOR;

            xRsIO.insert(strValue);
        }

        xRsIO.close();
        xRsIO = null;
    }

    public void insRcdByFilter(String inStoreName, String strOID)
    {
        System.out.println(inStoreName + "   " + strOID);

        if (inStoreName.equals("rsBag"))
            this.insBag(strOID);

        if (inStoreName.equals("rsEquip"))
            this.insRsEquip(strOID);

        if (inStoreName.equals("rsEquipUsed"))
            this.insRsEquipUsed(strOID);

        if (inStoreName.equals("rsScene"))
            this.insScene(strOID);

        if (inStoreName.equals("rsMainRole"))
            this.insRsMainRole(strOID);

        if (inStoreName.equals("rsSkills"))
            this.insRsSkills(strOID);

        if (inStoreName.equals("rsMission"))
            this.insRsMission(strOID);
    }

    public void init()
    {
        String[] strValue = new String[3];             //3行

        for(int i = 0; i < strValue.length; i++)
        {
            strValue[i] = "OID=" + (i + 1) + SEPARATOR;
            strValue[i]	+= "SceneName=" + SEPARATOR;
            strValue[i] += "Date=" + SEPARATOR;
            strValue[i] += "Time=" + SEPARATOR;
        }

        storeName = "rsRecordBook";
        //--- test ---
        //this.delAllRs(storeName);
        //--- For Test End ---

        String[] strQuery = getRecordString(storeName);

        xRsIO = new DataRsIO(storeName);
        xRsIO.open(storeName);

        //如果rs中没有记录
        if (xRsIO.getNumRecords()==0)
        {
            for(int i=0; i<strValue.length; i++)
            {
                xRsIO.insert(strValue[i]);
            }
            System.out.println(storeName + "rs中没有记录, insert completed");
        }else{
            //如果rs中有记录行,则将记录行中的数据get出来,检查是否含有必要的数据字段
            //ID指数据库记录的编号,OID指记录行数编号
            //如果查询到的记录<3条,则相应增加所缺的行数
            for (int i = 0; i < strValue.length; i++)
            {
                if(i >= xRsIO.getNumRecords())
                {
                    xRsIO.insert(strValue[i]);   //不足记录,补上
                }
                else
                {
                    //StringParser sParser = new StringParser(strQuery[i]);
                    //if (!sParser.getValue("ID").equals("") && sParser.getValue("OID").equals(""))
                    //    xRsIO.delete(Integer.parseInt(sParser.getValue("ID")));
                }
            }
            System.out.println(storeName + " rs有记录, Scan completed");
        }

        xRsIO.close();
        xRsIO = null;
    }

    public void delRcdBook(String strOID)
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -