-
Notifications
You must be signed in to change notification settings - Fork 1
/
ncc.min.js
8 lines (8 loc) · 28.7 KB
/
ncc.min.js
1
2
3
4
5
6
7
8
/*!
* ncc-web
*
* github.com/corvec/ncc-web
* coreykump.com/ncc
*
* Copyright 2012-2013 Corey T Kump
*/function generate_pdf(){window.current_action="Generating a PDF";var e=new jsPDF;e.setFontSize(40),e.setFont("times"),e.text(58,25,"NERO Rewrite"),e.setFontSize(12),e.setTextColor(0,0,255),e.text(88,30,"coreykump.com/ncc"),e.setTextColor(0,0,0),e.setFont("helvetica"),e.setFontStyle("bold"),e.text(10,40,"Player:"),e.text(10,45,"Character:"),e.text(10,50,"Class:"),e.text(10,55,"Race:"),e.text(10,60,"Feature:"),e.text(10,65,"Level:"),e.text(65,70,"Body:"),e.text(65,75,"Max Armor:"),e.text(10,70,"Build:"),e.text(10,75,"Spent:"),e.setFontStyle("normal"),e.text(40,40,document.getElementById("player_name").value),e.text(40,45,document.getElementById("character_name").value),e.text(40,50,get_character_class()),e.text(40,55,get_character_race()),e.text(40,60,get_character_feature()),e.text(40,65,get_character_level().toString()),e.text(95,70,get_character_body().toString()),e.text(95,75,get_max_armor().toString()),e.text(40,70,get_character_total_build().toString()),e.text(40,75,document.getElementById("spent_build").value),e.setFontSize(16),e.setFontStyle("bold"),e.text(10,90,"Spells:"),e.text(10,125,"Skills:"),e.setFontSize(12),e.text(15,95,"Primary"),e.text(15,110,"Secondary"),e.setFontStyle("normal"),e.text(15,100,get_primary_school()),e.text(15,115,get_secondary_school());var t=[95,110],n=["p_","s_"];for(var r=0;r<t.length;r++){var i=t[r],s=n[r],o=["1","2","3","0","4","5","6","0","7","8","9"];for(var u=0;u<o.length;u++)parseInt(o[u])==0?e.text(40+5*u,i,"/"):(e.setFontStyle("bold"),e.text(40+5*u,i,o[u]),e.setFontStyle("normal"),e.text(40+5*u,i+5,document.getElementById(s+o[u]).textContent));e.text(105,i,"Cost"),e.text(105,i+5,document.getElementById(s+"cost").textContent)}e.setFontStyle("bold"),e.text(40,130,"Skill"),e.text(15,130,"Cost"),e.setFontStyle("normal");var a=document.getElementById("skill_table").children;for(var r=0;r<a.length;r++){var f=a.item(r).children.item(3).textContent,l=a.item(r).children.item(2).textContent,c=a.item(r).children.item(1).textContent;e.text(15,135+r*5,f),c>1?e.text(40,135+r*5,c+"x "+l):e.text(40,135+r*5,l)}var h=$("#notes").val();if(h.length>0){var p=10,d=145+r*5,v=100,m=11;a.length>20&&(console.log("Character has more than 20 skills; displaying notes offset to the right."),p=100,d=125,v=50,m=10);var g=h.split("\n");for(var r=0;r<g.length;r++){if(g[r].length-1>v){var y="";for(var u=0;u<g[r].length/v;u++)u>0&&(y+="-\n "),y+=g[r].substring(u*v,(u+1)*v);g[r]=y}g[r]+="\n"}var b=g.join("");e.setFontSize(16),e.setFontStyle("bold"),e.text(p,d,"Notes:"),e.setFontSize(m),e.setFontStyle("normal"),e.text(p+5,d+5,b)}var w=get_character_race()+" "+get_character_class();document.getElementById("character_name").value.length>0&&(w=document.getElementById("character_name").value+" - "+w),document.getElementById("player_name").value.length>0&&(w=document.getElementById("player_name").value+" - "+w),e.setProperties({title:"NERO Rewrite",subject:w,author:document.getElementById("player_name").value,keywords:"NERO, LARP, Role-Playing",creator:"coreykump.com"});var E="NERO Character - "+w+".pdf";return is_mobile_browser()?e.output("datauri"):e.save(E),Notification.success("PDF Generated",window.current_action),!1}function is_mobile_browser(){var e=navigator.userAgent||navigator.vendor||window.opera;return/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(e)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(e.substr(0,4))}function mail_character(){var e=generate_email(),t="",n="My NERO Rewrite",r="mailto:"+t+"?"+"subject="+encodeURIComponent(n)+"&"+"body="+encodeURIComponent(e);return console.log(r),$("#a_email").attr("href",r),$("#a_email").show(),!1}function generate_email(){var e="Player Name: "+document.getElementById("player_name").value+"\n";e+="Character Name: "+document.getElementById("character_name").value+"\n",e+="Class: "+get_character_class()+"\n",e+="Race: "+get_character_race()+"\n",e+="Feature: "+get_character_feature()+"\n",e+="Level: "+get_character_level().toString()+"\n",e+="Body: "+get_character_body().toString()+"\n",e+="Max Armor: "+get_max_armor().toString()+"\n",e+="Build: "+document.getElementById("total_build").value+"\n",e+="Spent: "+document.getElementById("spent_build").value+"\n",e+="\n";var t=["p_","s_"],n=["1","2","3","0","4","5","6","0","7","8","9"];for(var r=0;r<t.length;r++){t[r]=="p_"?e+="Primary Spell Tree ("+get_primary_school()+"):\n":e+="Secondary Spell Tree ("+get_secondary_school()+"):\n";for(var i=0;i<n.length;i++)parseInt(n[i])==0?e+="/ ":e+=document.getElementById(t[r]+n[i]).textContent+" ";e+="\n"}e+="\n",e+="Skills:\n";var s=document.getElementById("skill_table").children;for(var r=0;r<s.length;r++){var o=s.item(r).children.item(3).textContent,u=s.item(r).children.item(2).textContent,a=s.item(r).children.item(1).textContent;e+=o+" - ",a>1?e+=a+"x "+u:e+=u,e+="\n"}var f=$("#notes").val();return f.length>0&&(e+="\n",e+="Notes:\n",e+=f),e}function parse_URL_params(e){var t=e.indexOf("?")+1,n=e.indexOf("#")+1||e.length+1,r=e.slice(t,n-1);if(r===e||r==="")return;var i={},s=r.replace(/\+/g," ").split("&");for(var o=0;o<s.length;o++){var u=s[o].split("="),a=decodeURIComponent(u[0]),f=decodeURIComponent(u[1]);a in i||(i[a]=[]),i[a].push(u.length===2?f:null)}return i}function save_link(){var e=generate_url();return $("#a_save").attr("href",e),$("#a_save").show(),!1}function generate_url(){var e=window.location.toString();e.indexOf("?")>-1&&(e=e.slice(0,e.indexOf("?"))),e+="?class="+$("#character_class").val(),e+="&race="+encodeURIComponent($("#race").val()),$("#player_name").val().length>0&&(e+="&player="+encodeURIComponent($("#player_name").val())),$("#character_name").val().length>0&&(e+="&character="+encodeURIComponent($("#character_name").val())),$("#race").val()=="Human"&&(e+="&trait="+encodeURIComponent($("#trait").val())),get_character_total_build()!=30&&(e+="&build="+encodeURIComponent($("#total_build").val())),get_primary_school()!="Earth"&&(e+="&primary="+encodeURIComponent(get_primary_school())),e+="&skills="+encodeURIComponent(get_skill_list()),get_slots("Earth",1)>0&&(e+="&earth="+encodeURIComponent(get_spell_tree("Earth"))),get_slots("Celestial",1)>0&&(e+="&celestial="+encodeURIComponent(get_spell_tree("Celestial")));var t=$("#notes").val();return t.length>0&&(e+="¬es="+encodeURIComponent(t)),e}function get_skill_list(){var e="",t=document.getElementById("skill_table").rows;for(var n=0;n<t.length;n++){var r=t[n].cells[2].textContent,i=t[n].cells[1].textContent;e+=i+","+r+","}return e}function get_spell_tree(e){var t="";for(var n=1;n<9&&get_slots(e,n+1);n++)t+=get_slots(e,n)+",";return t+=get_slots(e,n),console.log(t),t}function set_params(e){for(param in e)switch(param){case"player":$("#player_name").val(e[param]);break;case"character":$("#character_name").val(e[param]);break;case"class":$("#character_class").val(e[param]);break;case"race":$("#race").val(e[param]);break;case"trait":$("#trait").val(e[param]);break;case"build":$("#total_build").val(e[param]);break;case"primary":e[param]=="Celestial"&&switch_schools();break;case"skills":set_skill_list(e[param]);break;case"earth":set_spell_tree("Earth",e[param]);break;case"celestial":set_spell_tree("Celestial",e[param]);break;case"notes":$("#notes").val(e[param]);break;default:console.log(param+" = "+e[param])}}function set_skill_list(e){skill_ary=e[0].split(",");for(var t=0;t<skill_ary.length-1;t+=2){var n=skill_ary[t+1],r=hash.Skills[n],i=parseInt(skill_ary[t]),s=0,o=null,u=0;n in hash.Skills?add_skill_row(n,r,i,s,o,u):Notification.error("Cannot add skill "+n,"Loading Error")}}function set_spell_tree(e,t){var n=t[0].split(","),r="#p_";e!=get_primary_school()&&(r="#s_");for(var i=0;i<n.length;i++)$(r+(i+1)).text(n[i])}function race_includes(e){if(hash["Skills"][e]==null)return!1;var t=hash.Races[get_character_race()].Include;if(t==null)return!1;for(var n=0;n<t.length;n++)if(t[n]==e||skill_includes_type(t[n],e))return!0;return!1}function change_class(){window.current_action="Changing Class",update_skill_costs(),update_spelltree_cost(),ary_contains(hash.Races[get_character_race()]["Prohibited Classes"],get_character_class())?Notification.error("Your class / race combo is invalid",window.current_action):Notification.success("Changed class to "+get_character_class(),window.current_action)}function set_class(e){document.getElementById("character_class").value=e,change_class(),$("#class_list").dialog("close")}function update_abilities(){hash.Races[document.getElementById("race").value]["Super Race"]?$("#trait_p").show():$("#trait_p").hide();var e=hash.Races[get_character_race()].Abilities;if(!e)return $("#abilities").hide(),!1;$("#abilities").show();for(var t=0;t<e.length;t++)$("#ability_"+t).html(e[t])}function change_race(){window.current_action="Changing Race",update_skill_costs(),update_spelltree_cost(),update_abilities(),ary_contains(hash.Races[get_character_race()]["Prohibited Classes"],get_character_class())?Notification.error("Your class / race combo is invalid",window.current_action):Notification.success("Changed race to "+get_character_race(),window.current_action)}function change_trait(){window.current_action="Changing Trait",document.getElementById("race").value=="Human"&&update_skill_costs(),Notification.success("Changed race to "+get_character_race(),window.current_action)}function set_race(e){document.getElementById("race").value=e,change_race(),$("#race_list").dialog("close")}function get_character_class(){return document.getElementById("character_class").value}function get_character_race(){var e=document.getElementById("race").value;return hash.Races[e]["Super Race"]?get_character_trait()+" "+e:e}function get_character_feature(){var e=document.getElementById("race").value;return hash.Races[e]["Super Race"]?"None":document.getElementById("ability_2").innerHTML}function get_character_trait(){return document.getElementById("trait").value}function get_character_total_build(){var e=parseInt(document.getElementById("total_build").value);return e>=15?e:30}function get_character_body(){var e=hash.Classes[get_character_class()];return Math.floor(e["Base Body"]+get_character_level()*e["Body Per Level"])}function get_max_armor(){var e={Fighter:25,Templar:20,Rogue:20,Scholar:15}[get_character_class()];return e+=5*get_skill_count("Wear Extra Armor"),e}function get_character_level(){return Math.floor((get_character_total_build()-5)/10)}function interpret_keycode(e){var t;if(e.which==null)t=String.fromCharCode(e.keyCode);else{if(e.which==0||e.charCode==0)return!0;t=String.fromCharCode(e.which)}window.grab_keys&&run_action(t)}function run_action(e){switch(e){case"+":Notification.info("Set Spell Add Mode on"),spell_add_mode=!0;break;case"-":Notification.info("Set Spell Add Mode off"),spell_add_mode=!1;break;case"=":spell_add_mode=!spell_add_mode,Notification.info("Toggled Spell Add Mode to "+(spell_add_mode?"on":"off"));break;case"1":numberkeypress(1);break;case"2":numberkeypress(2);break;case"3":numberkeypress(3);break;case"4":numberkeypress(4);break;case"5":numberkeypress(5);break;case"6":numberkeypress(6);break;case"7":numberkeypress(7);break;case"8":numberkeypress(8);break;case"9":numberkeypress(9);break;case"A":case"a":document.getElementById("skill_to_add").focus();break;case"p":case"P":Notification.info("Toggled primary school"),switch_schools();break;case"s":case"S":Notification.info("Toggled selected school to "+current_school),current_school=="primary"?current_school="secondary":current_school="primary";break;default:console.log("Unhandled keypress: "+e)}return!0}function numberkeypress(e){spell_add_mode?add_spell((current_school=="primary"?"p_":"s_")+e):del_spell((current_school=="primary"?"p_":"s_")+e)}function get_schools(){return["Earth","Celestial"]}function get_primary_school(){return document.getElementById("primary").textContent.search("Earth")>-1?"Earth":"Celestial"}function get_secondary_school(){return document.getElementById("secondary").textContent.search("Earth")>-1?"Earth":"Celestial"}function switch_schools(){get_primary_school()=="Earth"?(document.getElementById("primary").innerHTML="Celestial",document.getElementById("secondary").innerHTML="Earth"):(document.getElementById("primary").innerHTML="Earth",document.getElementById("secondary").innerHTML="Celestial");for(var e=1;e<10;e++){var t=document.getElementById("s_"+e).textContent;document.getElementById("s_"+e).innerHTML=document.getElementById("p_"+e).textContent,document.getElementById("p_"+e).innerHTML=t}update_spelltree_cost(),update_skill_costs()}function add_spell(e){window.current_skill="Level "+e.substring(2)+" "+(e.substring(0,1)=="p"?get_primary_school():get_secondary_school())+" Spell",window.current_action="Adding "+window.current_skill;var t=document.getElementById(e).textContent;return add_magic_requirements_unconditionally(e)?(document.getElementById(e).innerHTML=1+parseInt(t),ensure_pyramid_left(e),ensure_pyramid_right(e),update_spelltree_cost(),Notification.success("Added "+window.current_skill,window.current_action),!1):!1}function add_magic_requirements(e){return parseInt(document.getElementById(e.substring(0,2)+1).textContent)>0?add_magic_requirements_unconditionally(e):!0}function add_magic_requirements_unconditionally(e){var t="Earth";return e.substring(0,2)=="p_"?get_primary_school()!="Earth"&&(t="Celestial"):get_primary_school()=="Earth"&&(t="Celestial"),add_prereqs(hash["Schools of Magic"][t].Requires,1)}function ensure_pyramid_left(e){var t=e.substring(0,2),n=parseInt(e.substring(2));for(var r=n;r>1;r--){var i=document.getElementById(t+(r-1)),s=get_left_min_val(t+r),o=get_left_max_val(t+r),u=parseInt(i.textContent);u<s&&(i.innerHTML=s),u>o&&(i.innerHTML=o)}}function get_left_min_val(e){var t=parseInt(document.getElementById(e).textContent);return t>3?t:t>0?t+1:0}function get_left_max_val(e){var t=parseInt(document.getElementById(e).textContent);if(t>=3)return t+1;if(t>=0)return t+2}function ensure_pyramid_right(e){var t=e.substring(0,2),n=parseInt(e.substring(2));for(var r=n;r<9;r++){var i=document.getElementById(t+(r+1)),s=get_right_min_val(t+r),o=get_right_max_val(t+r),u=parseInt(i.textContent);u<s&&(i.innerHTML=s),u>o&&(i.innerHTML=o)}}function get_right_min_val(e){var t=parseInt(document.getElementById(e).textContent);return t>4?t-1:t>1?t-2:0}function get_right_max_val(e){var t=parseInt(document.getElementById(e).textContent);return t>3?t:t>0?t-1:0}function del_spell(e){window.current_skill="Level "+e.substring(2)+" "+(e.substring(0,1)=="p"?get_primary_school():get_secondary_school())+" Spell",window.current_action="Removing "+window.current_skill,delete_spell(e)?Notification.success("Removed "+current_skill,window.current_action):Notification.error("Could not remove "+current_skill,window.current_action),recursively_delete_skills(e),update_spelltree_cost()}function delete_spell(e){var t=document.getElementById(e).textContent;return parseInt(t)>0?(document.getElementById(e).innerHTML=parseInt(t)-1,ensure_pyramid_left(e),ensure_pyramid_right(e),!0):!1}function clear_spell_tree(e){var t="s_1";return e==get_primary_school()&&(t="p_1"),document.getElementById(t).innerHTML=0,ensure_pyramid_left(t),ensure_pyramid_right(t),update_spelltree_cost(),!0}function get_slots(e,t){var n="s_";return get_primary_school()==e&&(n="p_"),parseInt(document.getElementById(n+t).textContent)}function set_slots(e,t,n){var r="s_";get_primary_school()==e&&(r="p_");if(!add_magic_requirements_unconditionally(r+t))return!1;document.getElementById(r+t).innerHTML=n,ensure_pyramid_left(r+t),ensure_pyramid_right(r+t)}function set_earth_slots(e,t){var n="s_";get_primary_school()=="Earth"&&(n="p_");if(!add_magic_requirements_unconditionally(n+e))return!1;document.getElementById(n+e).innerHTML=t,ensure_pyramid_left(n+e),ensure_pyramid_right(n+e)}function set_celestial_slots(e,t){var n="s_";get_primary_school()=="Celestial"&&(n="p_");if(!add_magic_requirements_unconditionally(n+e))return!1;document.getElementById(n+e).innerHTML=t,ensure_pyramid_left(n+e),ensure_pyramid_right(n+e)}function update_spelltree_cost(){var e=["p_","s_"],t=[1,2,3,4,5,6,7,8,9],n=document.getElementById("character_class").value;for(var r=0;r<e.length;r++){var i=0,s=e[r];for(l_i=0;l_i<t.length;l_i++){var o=t[l_i],u=parseInt(document.getElementById(s+o).textContent);u>0&&(i+=u*hash["Spell Costs"][n][l_i])}s=="p_"?document.getElementById(s+"cost").innerHTML=i:document.getElementById(s+"cost").innerHTML=2*i}update_build_spent()}function add_prereqs(e,t){var n=!0;if(e instanceof Array)for(var r=0;r<e.length;r++)n=add_prereq(e[r],1)&&n;else if(e instanceof Object)for(var i in e)e[i]==0?n=add_prereq(i,1)&&n:n=add_prereq(i,t*e[i])&&n;else console.log("add_prereqs - skipping");return n}function add_prereq(e,t){var n=get_skill_count(e);return n<t&&!add_skill(e,t-n)?(Notification.error("Could not automatically add prerequisite skill, "+e,window.current_action),!1):!0}function update_skill_costs(){update_skill_cost();var e=document.getElementById("skill_table").rows;for(var t=0;t<e.length;t++){var n=get_skill_cost(e[t].cells[2].textContent,get_character_class(),get_character_race());if(n==null)e[t].cells[2].textContent=="Read Magic"&&(document.getElementById("skill_table").deleteRow(document.getElementById("skill_Read Magic").rowIndex-1),recursively_delete_skills("Read Magic"),add_skill_row("Read Magic",{},1,0,null,1)),e[t].className="unavailable",e[t].cells[3].innerHTML="N/A";else{e[t].removeAttribute("class");var r=parseInt(e[t].cells[1].textContent);e[t].cells[3].innerHTML=n*r}}}function recursively_delete_skills(e){console.log("recursive_delete_skills("+e+")");var t=!0;while(t){t=!1;var n=document.getElementById("skill_table").rows;for(var r=0;r<n.length;r++){var i=n[r].cells[2].textContent,s=hash.Skills[i].Requires,o=get_skill_count(i);if(is_at_least_one_prereq_not_met(s,e,o)){console.log("is_at_least_one_prereq_not_met() returned true");if(s instanceof Array){console.log("prereqs instanceof Array == true -> deleting"),Notification.info("Removed skill "+i,window.current_action),document.getElementById("skill_table").deleteRow(r),t=!0;break}console.log("prereqs instanceof Array == false -> decrementing"),recursively_decrement_skills(e)}}for(var u=0;u<get_schools().length;u++){var a=get_schools()[u];get_slots(a,1)>0&&is_at_least_one_prereq_not_met(hash["Schools of Magic"][a].Requires,e)&&(clear_spell_tree(a)?(t=!0,Notification.info("Cleared "+a+" spell tree",window.current_action)):Notification.error("Failed to clear "+a+" spell tree",window.current_action))}}}function recursively_decrement_skills(e){console.log("recursively_decrement_skills("+e+")");var t=!0;while(t){t=!1;var n=document.getElementById("skill_table").rows;for(var r=0;r<n.length;r++){var i=n[r].cells[2].textContent,s=get_skill_count(i),o=is_this_numbered_prereq_not_met(hash.Skills[i].Requires,e,s);if(o){t=!0;while(o){if(s<=1){delete_skill_by_name(i),o=!1;break}add_skill(i,-1),s=get_skill_count(i),o=is_this_numbered_prereq_not_met(hash.Skills[i].Requires,e,s)}recursively_decrement_skills(i)}}}}function is_at_least_one_prereq_not_met(e,t,n){console.log("is_at_least_one_prereq_not_met("+e+","+t+","+n+")");if(e==null)return!1;if(e instanceof Array){for(var r=0;r<e.length;r++)if(is_prereq_not_met(e[r],t))return!0}else if(e instanceof Object&&is_this_numbered_prereq_not_met(e,t,n))return!0;return!1}function is_this_numbered_prereq_not_met(e,t,n){return console.log("is_this_numbered_prereq_not_met("+e+","+t+","+n+")"),e instanceof Object&&e.hasOwnProperty(t)?e[t]*n>get_skill_count(t):!1}function is_prereq_not_met(e,t){console.log("is_prereq_not_met("+e+","+t+")");if(e==t)return!0;console.log("get_skill_count "+e+" = "+get_skill_count(e));if(get_skill_count(e)==0){if(hash["Skills"][e]!=null&&hash["Skills"][e]["Cost"]!=null)return!0;if(hash["Skills"][t]!=null&&hash["Skills"][t]["Includes"]!=null){if(skill_includes_type(t,e))return!0}else if(e.search("Earth")>-1||e.search("Celestial")>-1)return!0}return!1}function add_selected_skill(){var e=document.getElementById("skill_to_add").value,t=parseInt(document.getElementById("skill_number").value);return window.current_skill=e,window.current_action="Adding "+e,add_skill(e,t)&&update_build_spent(),!1}function increment_skill(e){window.current_action="Incrementing "+e,add_skill(e,1),update_build_spent()}function decrement_skill(e){window.current_action="Decrementing "+e;if(get_skill_count(e)==1)return Notification.error("Cannot decrement a skill to below 1 - delete it instead.",window.current_action),!1;add_skill(e,-1),recursively_decrement_skills(e);var t=hash.Skills[e].Includes;t==null&&(t={});for(var n=0;n<t.length;n++)recursively_decrement_skills(t[n]);update_build_spent()}function add_skill(e,t){var n=hash.Skills[e];if(n==null){for(var r=0;r<get_schools().length;r++){var i=get_schools()[r];if(e.substring(0,i.length)==i)return set_slots(i,parseInt(e.substring(i.length+1)),t),update_spelltree_cost(),Notification.info("Added required "+i+" spells.",window.current_action),!0}return e=="Level"?(Notification.info("This skill is limited to one per "+t+" levels",window.current_skill+" Prereq"),!0):!1}var s=get_skill_cost(e,get_character_class(),get_character_race());if(s==null)return hash.Skills[e].Racial&&Notification.error("This skill is a racial skill","Error Adding Skill"),!1;var o=skill_row(e),u=0;o!=null&&(u=parseInt(o.cells[1].textContent));if(t>0&&n["Requires"]!=null){var a=u;t>0&&(a=get_skill_count(e)),add_prereqs(n.Requires,t+a)}return add_skill_row(e,n,t,u,o,s)?(e==window.current_skill?Notification.success("Added skill "+e,window.current_action):window.current_action!=null&&(window.current_action.indexOf("Adding")==0?Notification.info("Added prereq "+e,window.current_action):window.current_action.indexOf("Selling Back")==0?u>parseInt(o.cells[1].textContent)?Notification.info("Sold back a "+e,window.current_action):delete_skill_by_name(e):window.current_action.indexOf("Buying ")==0&&Notification.info("Bought another "+e,window.current_action)),!0):!1}function update_skill_cost(){var e=get_skill_cost(document.getElementById("skill_to_add").value,get_character_class(),get_character_race());e==null?document.getElementById("skill_cost").value="N/A":document.getElementById("skill_cost").value=e}function add_skill_row(e,t,n,r,i,s){var o=document.getElementById("skill_table");if(i==null){i=o.insertRow(o.rows.length),i.className="skill";var u=i.insertCell(0);u.className="skill_delete";var a=i.insertCell(1);a.className="skill_count";var f=i.insertCell(2);f.className="skill_name";var l=i.insertCell(3);l.className="skill_cost";var c="skill_"+e;i.id=c,u.innerHTML="<a href='#' onclick='return delete_skill(\""+c+"\")'>X</a>",f.innerHTML=e,a.innerHTML=0,a.setAttribute("onclick",'decrement_skill("'+e+'"); '),f.setAttribute("onclick",'increment_skill("'+e+'"); ')}new_count=r+n;var h=t.Max;h instanceof Object&&(h=h[get_character_class()]);if(h==null){if(new_count>1){Notification.error(e+" cannot be purchased multiple times.",window.current_action);if(r==1)return!1}new_count=1}else h>0&&h<new_count&&(new_count=h,Notification.error(e+" cannot be purchased more than "+h+" times.",window.current_action));return new_count<1&&(new_count=1),i.cells[1].innerHTML=new_count,i.cells[3].innerHTML=s*new_count,!0}function skill_row(e){var t=document.getElementById("skill_table").rows;for(var n=0;n<t.length;n++)if(t[n].cells[2].textContent==e)return t[n];return null}function get_type_count(e){var t=document.getElementById("skill_table").rows,n=0;for(var r=0;r<t.length;r++)skill_includes_type(t[r].cells[2].textContent,e)&&(n+=parseInt(t[r].cells[1].textContent));return n}function skill_includes_type(e,t){if(hash["Skills"][e]==null)return!1;var n=hash.Skills[e].Includes;if(n==null)return!1;for(var r=0;r<n.length;r++)if(n[r]==t||skill_includes_type(n[r],t))return!0;return!1}function get_skill_count(e){if(e.substring(0,5)=="Earth")return get_slots("Earth",parseInt(e.substring(6)));if(e.substring(0,9)=="Celestial")return get_slots("Celestial",parseInt(e.substring(10)));if(e.substring(3,17)==" Handed Weapon"&&race_includes(e))return get_skill_count("Weapon");var t=0;t+=get_type_count(e);var n=skill_row(e);return n!=null&&(t+=parseInt(n.cells[1].textContent)),t}function delete_skill(e){console.log("delete_skill("+e+")");var t=document.getElementById(e).cells[2].textContent;window.current_skill=t,window.current_action="Removing "+t,document.getElementById("skill_table").deleteRow(document.getElementById(e).rowIndex-1),recursively_delete_skills(t);var n=hash.Skills[t].Includes;if(n!=null)for(var r=0;r<n.length;r++)recursively_delete_skills(n[r]);return Notification.success("Removed skill "+t,window.current_action),update_build_spent(),!1}function delete_skill_by_name(e){var t="skill_"+e;return console.log("delete_skill_by_name "+e),document.getElementById("skill_table").deleteRow(document.getElementById(t).rowIndex-1),recursively_delete_skills(e),Notification.success("Removed skill "+e,window.current_action),update_build_spent(),!0}function update_build_spent(){var e=0,t=document.getElementById("skill_table").children;for(var n=0;n<t.length;n++){var r=parseInt(t.item(n).children.item(3).textContent);r.toString()!="NaN"&&(e+=r)}e+=parseInt(document.getElementById("p_cost").textContent),e+=parseInt(document.getElementById("s_cost").textContent),document.getElementById("spent_build").value=e}function ary_contains(e,t){if(e==null)return!1;for(var n=0;n<e.length;n++)if(e[n]===t)return!0;return!1}function get_skill_cost(e,t,n){var r=hash.Skills[e].Cost;if(r==null)return racial_skills=hash.Races[get_character_race()]["Racial Skills"],racial_skills==null||racial_skills[e]==null?null:racial_skills[e];var i=null;typeof r=="number"?i=r:r[t]!=null?i=r[t]:r["Primary"]!=null&&(e.search(get_primary_school())>-1?i=r.Primary[t]:i=r.Secondary[t]),i==null&&Notification.error("Cannot determine skill cost<br/>"+e+" is limited by race.",window.current_action);var s=hash.Races[get_character_race()];return ary_contains(s["Prohibited Skills"],e)?(i=null,Notification.error("Cannot determine skill cost:<br/>"+e+" is prohibited for your race.",window.current_action)):ary_contains(s["Prohibited Classes"],get_character_class())?(i=null,window.current_action!="Changing Race"&&window.current_action!="Changing Class"&&Notification.error("Cannot determine skill cost<br />Your class/race is invalid.",window.current_action)):ary_contains(s["Double Cost for Skills"],e)?i*=2:ary_contains(s["Half Cost for Skills"],e)?i=Math.ceil(i/2):ary_contains(s["Reduced Cost for Skills"],e)&&(i-=1),i}$(function(){window.current_school="primary",document.getElementById("spent_build").value=0,window.spell_add_mode=!0,window.grab_keys=!0,!navigator.userAgent.match(/iPhone/i)&&!navigator.userAgent.match(/iPad/i)?$(document).keypress(function(e){interpret_keycode(e)}):navigator.userAgent.match(/iPhone/i)&&$("h2").hide()});var Notification=window.Notification={};Notification.info=function(e,t){t!=null&&(e="<strong>"+t+"</strong><br />"+e);var n=noty({text:e,timeout:1500,type:"information",layout:"topRight"})},Notification.error=function(e,t){t!=null&&(e=t+"<br />"+e);var n=noty({text:e,timeout:5e3,type:"error",layout:"topRight"})},Notification.success=function(e,t){t!=null&&(e="<strong>"+t+"</strong><br />"+e);var n=noty({text:e,timeout:3e3,type:"success",layout:"topRight"})},$(window).bind("load",function(){$("#notes").autoResize(),set_params(parse_URL_params(window.location.toString())),update_abilities(),update_skill_costs(),update_spelltree_cost()});