/**
 * 天赋输出的相关对象。
 * @create   2004-09-29 source0
 * @author   source0 source0@hotmail.com
 * @copyright 版权所有（C） 2004  source0
 *                这一程序是自由软件，你可以遵照自由软件基金会出版的GNU通用
 *            公共许可证条款来修改和重新发布这一程序。或者用许可证的第二版，
 *            或者（根据你的选择）用任何更新的版本。
 *                发布这一程序的目的是希望它有用，但没有任何担保。甚至没有
 *            适合特定目的的隐含的担保。更详细的情况请参阅GNU通用公共许可证。
 *                你应该已经和程序一起收到一份GNU通用公共许可证的副本。如果
 *            还没有，写信给：
 *                The Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
 *                MA02139, USA
 */

/**
 * 鼠标移动到某类天赋的总点数上时的处理函数，此时显示该类天赋已经添加点数的所有技能的列表。
 * @param id 天赋类的ID。
 * @param e 鼠标事件（仅对mozilla）。
 */
function createTalentsListArea(){
    for ( var i = 0; i < TALENT_CLASS_VIEWS.length; i++ ){
        var rt = new String();
        rt += "<table width=" + (1.5 * TOOL_TIP_AREA_WIDTH) + "><tbody>";
        rt += "<tr>";
        rt += "<td height=30 align='left'>";
        rt += "<input class='resetTalentClass' type=button";
        rt += " id='RESET_TALENT_CLASS_" + TALENT_CLASS_VIEWS[i].model.id + "'";
        rt += " onClick='resetTalentClass(\"" + TALENT_CLASS_VIEWS[i].model.id + "\")' ";
        rt += " value='重置" + TALENT_CLASS_VIEWS[i].model.name + "'/>";
        rt += "</td>";
        rt += "<td align=right>";
        rt += "<input type='button' class='closeToolTip'";
        rt += " value='关闭' onClick='hideTalentsListArea(" + i + ");'>";
        rt += "</td>";
        rt += "</tr>";
        rt += "<tr><td colspan=2>";
        rt += "<table width='100%' cellspacing=0 cellpadding=0 height='1' style='background-color:#fff;'><tr><td height='1' ></td></tr></table>";
        rt += "</td></tr>";
        rt += "</tbody></table>";

        rt += getTalentClassInfo(TALENT_CLASS_VIEWS[i].model, "TALENTS_LIST", true);

        var areaObj = document.getElementById("TALENTS_LIST_AREA_" + i);
        setInnerHTML(areaObj, rt);
        createImageButton("RESET_TALENT_CLASS_" + TALENT_CLASS_VIEWS[i].model.id, "resetButton");
    }
}
/**
 * 得到当前类别的天赋的加点信息。
 * @param talentClass 天赋类别模型实例。
 * @param showAll 是否忽略天赋是否升级，显示所有的天赋。
 * @return HTML格式的信息。
 */
function getTalentClassInfo(talentClass, areaSymbol, showAll){
    var tvs = talentClass.getTalentViews();

    if ( null == areaSymbol ){
        areaSymbol = "TALENT_LIST";
    }
    var rt = new String();
    rt += "<table width=" + (1.35 * TOOL_TIP_AREA_WIDTH) + ">";
    rt += "<tr><td>";
    for ( var key in tvs)
    {
        var tv = tvs[key];
        var visible = showAll || (tv.getRank() > 0);
        rt += "<table class=talentClassInfo id='AREA_" + areaSymbol + "_" + talentClass.id + "_" + tv.model.id + "'";
        rt += " style='display:" + (visible ? "" : "none") + ";'";
        rt += "><tbody>";
        rt += "<tr>";
//        rt += "<td><img id='TALENT_ICON_FOR_LIST_" + talentClass.id + "_" + tv.model.id + "' width=40 height=40 src=''/></td>";
        rt += "<td><img width=40 height=40 src='" + talentClass.path + "/" + tv.icon + "'/></td>";
        rt += "<td>";
        rt += "<table class=talentClassInfo><tbody>";

        /* 第一行为技能名称和当前级别。 */
        rt += "<tr>";
        rt += "<td>";
        rt += "<span class=";
        if ( tv.model.type == TALENT_TYPE_IMPROVE ){
            rt += "'talentImproveName'>";
        } else {
            rt += "'talentSkillName'>"
        }
        rt += tv.model.name;
        rt += "</span>";

        rt += "&nbsp;";
        /* 根据级别决定显示风格。 */
        var rankStyle = getRankStyle(tv);
        rt += "<span id='RANK_" + areaSymbol + "_" + talentClass.id + "_" + tv.model.id + "'";
        rt += " class=" + rankStyle + ">";
        rt += tv.getRank();
        rt += "</span>";
        rt += "<span class='talentRankValueValid'>";
        rt += "/" + tv.model.data.maxRank + " 级</td>";
        rt += "</span>";

        rt += "</td>";
        rt += "</tr>";

        /* 第二行为技能效果说明及当前效果。 */
        rt += "<tr>";
        rt += "<td>";
        rt += "<span id='EFFECT_" + areaSymbol + "_" + talentClass.id + "_" + tv.model.id + "'";
        rt += " class='commonText'>";
        if ( tv.model.type == TALENT_TYPE_IMPROVE ){
            rt += formatTalentEffects(tv);
        } else {
            rt += tv.model.data.description;
        }
        rt += "</span>";
        rt += "</td>";
        rt += "</tr>";
        rt += "</tbody></table>";


        rt += "</td>";
        rt += "</tr>";
        rt += "</tbody></table>";
    }
    rt += "</td></tr>";
    rt += "</tbody></table>";
    return rt;
}

/**
 * 得到当前天赋的信息。
 * @param talentClass 天赋类别模型实例。
 * @param id 天赋的ID。
 * @return HTML格式的信息。
 */
function getTalentInfo(talentClass, id){
    var tv = talentClass.getTalentView(id);
    var rt = new String();

    if ( null == tv ){
        return rt;
    }

    rt += "<table border=0 width=" + TOOL_TIP_AREA_WIDTH + "><tbody>";
    rt += "<tr><td class=";

    if ( tv.model.type == TALENT_TYPE_IMPROVE ){
        rt += "'talentImproveName'>";
    } else {
        rt += "'talentSkillName'>"
    }
    if ( tv.model.name.indexOf('[') > 0 )
    {
        rt += tv.model.name.substring(0, tv.model.name.indexOf('['));
        rt += "<BR/>";
        rt += tv.model.name.substring(1 + parseInt(tv.model.name.indexOf('[')), tv.model.name.indexOf(']'));
    }
    else
    {
        rt += tv.model.name;
    }

    rt += "</td>";

    /* 输出当前技能的级别。 */
    var rankStyle = getRankStyle(tv);
    rt += "<td align=right class=" + rankStyle + ">";
    rt += "<div class=commonText>";

    if ( tv.model.type == TALENT_TYPE_IMPROVE ) {
        rt += tv.getRank() + "/" + tv.model.data.maxRank;
    } else {
        if ( tv.getRank() > 0 ) {
            rt += "已学习";
        } else {
            rt += "未学习";
        }
    }
    rt += "</div>";
    rt += "</td></tr>";

    rt += "<tr><td height=5 colspan=2></td></tr>";

    /* 输出技能所需要的条件 */
    rt += "<tr><td colspan=2>";
    rt += "<div class=commonText>";
    if ( !tv.isValid() ){
        rt += "<div class=";
        if ( talentClass.getAmount() < 5 * tv.model.tier ) {
            rt += "requireCondition"
        } else {
            rt += "talentRankValueMax";
        }
        rt += ">";
        rt += "需要 " + 5 * tv.model.tier + " 点 " + talentClass.name + " 系天赋点";
        rt += "</div>";
        if ( null != tv.model.requirements ){
            rt += "<div class='requireCondition'>";
            var reqs = tv.model.requirements;
            for ( var key in reqs ){
                rt += "需要 " + reqs[key].rank + " 级的 ";
                rt += talentClass.getTalentView(reqs[key].talent).model.name + " 天赋";
                rt += "<br/>";
            }
            rt += "</div>";
        }
    }
    else
    {
        if ( (tv.getRank() < tv.model.data.maxRank)
            && ( CURRENT_ROLE.getUsedPoints() >= 51 ))
        {
            rt += "<div class='requireCondition'>已无剩余点数</div>";
        }
    }

    rt += "</div>";
    rt += "<BR/>";

    /* 输出技能的效果。 */
    rt += formatTalentEffects(tv);

    rt += "<BR/><BR/>";
    if ( tv.model.type == TALENT_TYPE_IMPROVE ) {
        var effects = tv.model.data.effects;

        rt += "<table class='talentEffect' cellspacing=0 cellpadding=0>";
        for ( var rank = 1; rank <= tv.model.data.maxRank; rank++ ){
            rt += "<tr>";
            rt += "<td>";
            rt += "第 " + rank + " 级：";
            rt += "</td>";
            rt += "<td class='talentRankValueValid' align='right'>";
            for ( var key in effects ){
                rt += "<td align='right'";
                if ( rank == tv.getRank() ){
                    rt += "class='talentRankValueMax'";
                } else {
                    rt += "class='talentRankValueValid'";
                }
                rt += ">";
                rt += effects[key].getValue(rank) + effects[key].unit;
                rt += "&nbsp;&nbsp;</td>";
            }
            rt += "</td>";
            rt += "</tr>";
        }
        rt += "</table>";
    } else {
        rt += "<div class='talentEffect'>";
        var consumeTypeName = getConsumeTypeName(tv.model.data.consumeType);
        if ( tv.model.data.consume > 0 ){
            rt += "技能消耗：" + tv.model.data.consume + " " + consumeTypeName + "<BR/>";
        }
        rt += "释放时间：" + ((tv.model.data.castTime == 0) ? "立即释放" : (tv.model.data.castTime + " 秒")) + "<BR/>";
        var cooldown = tv.model.data.cooldown;
        if ( cooldown > 0 ){
            rt += "释放间隔：";
            if ( cooldown >= 3600 ){
                rt += cooldown / 3600 + " 小时 ";
               cooldown %= 3600;
            }
            if ( cooldown >= 60 ){
                rt += cooldown / 60 + " 分钟 ";
                cooldown %= 60;
            }
            if ( cooldown > 0 ){
                rt += cooldown + " 秒";
            }
            rt += "<BR/>";
        }
        if ( tv.model.data.maxRange > 0 ){
            var range = tv.model.data.maxRange;
            if ( tv.model.data.minRange > 0){
                range = tv.model.data.minRange + "-" + range;
            }
            rt += "有效距离：" + range;
        }
        if ( null != tv.model.data.remark ){
            rt += "<br/>" + tv.model.data.remark;
        }
        rt += "</div>";

    }

    if ( tv.isValid() && (tv.getRank() < tv.model.data.maxRank)){
        rt += "<br/>";
        if ( CURRENT_ROLE.getUsedPoints() < 51 )
        {
            if ( tv.model.type == TALENT_TYPE_IMPROVE ) {
                rt += "<div class=canUpdate>单击学习一级</div>";
                rt += "<div class=canUpdate>双击学习至顶级</div>";
            } else {
                rt += "<div class=canUpdate>单击学习此技能</div>";
            }
        }
        else
        {
            //rt += "<div class='requireCondition'>已无剩余点数</div>";
        }
    }
    if (( tv.getRank() > 0 ) && (talentClass.canUndoUpdate(tv.model.id))){
        rt += "<br/>";
        rt += "<div class=canUndoUpdate>右键撤销学习</div>";
    }

    rt += "</td></tr></tbody></table>";
    return rt;
}