123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- <html>
- <head>
- <meta charset="utf8">
- <link rel="stylesheet" type="text/css" href="style/anim.css">
- <script src="game/dice.js"></script>
- <script src="data/names.js"></script>
- <script src="data/l5r_data.js"></script>
- <script src="helper/random.js"></script>
- <script src="game/display.js"></script>
- <script src="game/character.js"></script>
- <script src="game/l5r.js"></script>
- <script src="data/players.js"></script>
- <script src="data/npc.js"></script>
- <script>
-
- var npcs = [];
- var result = [];
- var result1 = [];
- var result2 = [];
- var current_target= 0;
-
- function target(){
- return characters.at(current_target) ;
- }
-
- var npc_summary = document.getElementById("npc.summary");
-
- function generateNPC(){
- var newNPC = new Character();
- newNPC.generate( document.getElementById("npc-level").value );
- return newNPC;
- }
-
- function generateNPCs( size ){
- let result = [];
-
- for(let i = 0; i < size ; i++){
- result[i] = generateNPC( i );
- }
-
- return result;
- }
-
- function skirmish( size ){
- let npcs = generateNPCs( size );
-
- for(let i = 0; i < size ; i+=2){
- if( (npcs[i]) && (npcs[i + 1]))
- result[i] = fight(npcs[i], npcs[i + 1]);
- }
-
- for( let i = 0; i < size ; i++ ){
- ;
- }
- }
-
- function swissContest( size ){
- let result = [];
- let npcs = generateNPCs( size );
-
- for(let i = 0; i < npcs.length; i++){
- result[i] = [];
-
- for(let j = 0; j < npcs.length; j++){
- result[i][j] = ( fight( npcs[i], npcs[j] ) );
- npcs[i].fullHeal();
- npcs[j].fullHeal();
- }
- }
- return result;
- }
-
- function winRateSwissContest( array, stat){
- let result = [];
-
- for(let i = 0; i < array.length; i++){
- let winrate = 0;
- let total = 0;
- for(let j = 0; j < array[i].length; j++){
- winrate += ( array[i][j].winner_side == "attacker" )? 1: 0;
- total++;
- }
-
- result[i] = winrate/total;
- }
- return result;
- }
-
- function hasClass( elem, className){
-
- for( let i = 0 ; i < elem.classList.length ; i++ )
- if( elem.classList[ i ] === className )
- return elem;
-
- return 0;
- };
-
- function getClassFromList( list, className ){
- let result = [];
-
- for( let i = 0 ; i < list.childNodes.length ; i++ )
- if( hasClass( list.childNodes[ i ], className ))
- result.push( list.childNodes[ i ] );
-
- return result;
- }
-
- function inputFromElementList( list, input_type ){
- let result = [];
-
- for( let i = 0 ; i ; i++ )
- if( list[ i ].getAttributeNames().includes( input_type ))
- result.push( list[i] );
-
- return result;
- }
-
- function display_data( data, anchor ){
- let html_display = document.getElementById( anchor );
- let headers = [ "name", "initiative", "TN", "attack", "damage", "wounds" ];
- let hs = document.createElement("tr");
-
-
- for(let i = 0; i < headers.length ; i++){
- let h = document.createElement("th");
- h.innerText = headers[ i ];
- hs.appendChild( h );
- }
-
- html_display.appendChild( hs ) ;
-
- for(let i = 0; i < data.length ; i++){
- let line = document.createElement( "tr" );
- line.setAttribute("id", i + "-" + anchor );
- let name = document.createElement("td");
- name.innerText = data[i]["get"+capitalize( headers[0] )]();
- line.appendChild( name );
-
- for(let j = 1; j < headers.length ; j++){
- let cell = document.createElement("td");
- let button = document.createElement("button");
- button.setAttribute("class", headers[j]);
- let id = i + "-"+j+"-" + anchor;
-
- button.innerText = headers[j];
-
- button.addEventListener('click', function(event) {
- document.getElementById( id ).value = data[i]["get"+capitalize( headers[j] )]();
- });
- cell.appendChild( button );
-
- let result = document.createElement("input");
- result.setAttribute("id", id);
- result.setAttribute("type", "text");
- result.setAttribute("class", "result");
- cell.appendChild( result );
- line.appendChild( cell );
- }
- let cell1 = document.createElement("td");
- let targeted = document.createElement("input");
- targeted.setAttribute("type", "checkbox");
- targeted.setAttribute("class", "targeted");
- targeted.checked = false;
- targeted.addEventListener('click', function(event) {
- let targeteds = document.getElementsByClassName( "targeted" );
- for(let targeted in targeteds){
- if(targeteds[targeted] != this)
- targeteds[targeted].checked = false;
-
- current_target = this.parentNode.parentNode.id.split("-")[0];
- }
- });
- cell1.appendChild( targeted );
- line.appendChild( cell1 );
-
- cell2 = document.createElement("td");
- let attacking = document.createElement("input");
- attacking.setAttribute("type", "button");
- attacking.setAttribute("class", "attacking");
- attacking.value = "Attack";
- attacking.checked = false;
- attacking.addEventListener('click', function(event) {
- characters.at( this.parentNode.parentNode.id.split("-")[0] ).attacking( target() );
- triggerField( "Wounds" );
- triggerField( "TN" );
- });
- cell2.appendChild( attacking );
- line.appendChild( cell2 );
-
- let cell_switchStance = document.createElement("td");
- let switchStance = document.createElement("input");
- switchStance.setAttribute("type", "button");
- switchStance.value = "Attack Stance";
- cell_switchStance.appendChild( switchStance );
- cell_switchStance.addEventListener('click', function(event) {
- let charac = characters.at( this.parentNode.id.split("-")[0] );
- charac.switchStance();
- event.target.value = charac.stance;
- triggerField( "TN" );
- });
- line.appendChild( cell_switchStance );
-
- html_display.appendChild( line );
- }
- }
-
- function popAssociativeMaker( associative, anchor ){
-
- let result = document.createElement( "div" );
- result.setAttribute( "class", "popup" );
- let exit = document.createElement("input");
- exit.setAttribute("type", "button");
- exit.setAttribute("class", "exit");
- exit.value = "×";
- exit.addEventListener('click', function(event) {
- anchor.value = JSON.stringify( formToData( result ) );
- result.parentNode.removeChild( result );
- });
-
- result.appendChild( exit );
-
- for( let i in associative ){
- switch( typeof varType ){
- case "function":
- break;
- case "object":
- result.appendChild( inputField( i, associative[ i ] || "", true, null, function(event) {
- this.value = popObjectMaker( associative[ i ], line );
- } ));
- break;
- default:
- result.appendChild( inputField( i, associative[ i ] || "") );
- }
- }
-
- let add = document.createElement("input");
- add.setAttribute("type", "button");
- add.setAttribute("class", "add");
- add.value = "+";
- add.addEventListener('click', function(event) {
- result.appendChild( inputField( "", "", true) );
- });
- result.appendChild( add );
-
- document.getElementsByTagName('body')[0].appendChild( result );
-
- return result;
- }
-
- function inputField( field, value, modifiable, label_onclick, input_onclick ){
- field = (( typeof field === "unsigned" ) || !field )? "" : field;
- value = (( typeof value === "unsigned" ) || !value )? "" : value;
- modifiable = (( typeof modifiable === "unsigned" ) || !modifiable )? false : true ;
-
- let line= document.createElement("div");
- let input = document.createElement("input");
- let label ;
-
- if( modifiable ){
- label = document.createElement("input");
- label.setAttribute("type", "text");
- }else{
- label = document.createElement("label");
- }
-
- line.setAttribute("class", "line");
- label.setAttribute("class", "label");
- label.innerText = field;
-
- if( label_onclick instanceof Function )
- label.addEventListener('click', label_onclick );
-
- line.appendChild( label );
-
- input.setAttribute("type", "text");
- input.setAttribute("class", "maker");
- input.value = value;
-
- if( input_onclick instanceof Function )
- input.addEventListener('click', label_onclick );
-
- input.checked = false;
- line.appendChild( input );
-
- return line;
- }
-
- function popObjectMaker( object, anchor, dictionnary ){
- let prototype = new object;
- let result = document.createElement( "div" );
- result.setAttribute( "class", "popup" );
-
- let exit = document.createElement("input");
- exit.setAttribute("type", "button");
- exit.setAttribute("class", "exit");
- exit.value = "×";
-
- if( typeof dictionnary === "object" )
- exit.addEventListener('click', function(event) {
- formToDictonnary( result, dictionnary);});
- else
- exit.addEventListener('click', function(event) {
- saveAndExitForm( result);});
- result.appendChild( exit );
-
- for( let i in prototype ){
- let varType = prototype[i];
- let line= document.createElement("div");
- let input = document.createElement("input");
- let label = document.createElement("label");
-
- switch( typeof varType ){
- case "function":
- break;
- case "object":
- line= document.createElement("div");
- line.setAttribute("class", "line");
- label.setAttribute("type", "button");
- label.classList.add("label");
- label.innerText = i;
- line.appendChild( label );
-
- input.setAttribute("type", "text");
- input.classList.add("json");
- input.classList.add("maker");
- input.value = prototype[ i ] || "";
- input.checked = false;
- input.addEventListener('click', function(event) {
- this.value = popAssociativeMaker( prototype[ i ], input );
- });
- line.appendChild( input );
-
- result.appendChild( line );
- break;
- default:
- line.setAttribute("class", "line");
- label.setAttribute("type", "button");
- label.classList.add("label");
- label.innerText = i;
- line.appendChild( label );
-
- input.setAttribute("type", "text");
- input.classList.add("maker");
- input.value = prototype[ i ] || "";
- input.checked = false;
- line.appendChild( input );
-
- result.appendChild( line );
- }
- }
-
- if( anchor instanceof Element )
- anchor.appendChild( result );
- else
- document.getElementsByTagName('body')[0].appendChild( result );
-
- return result;
- }
-
- function formToData( form ){
- let lines = form.getElementsByClassName( "line" ) ;
- let data = {} ;
-
- for ( let i = 0 ; i < lines.length ; i++ ){
- let labels = getClassFromList( lines[ i ], "label");
- let makers = getClassFromList( lines[ i ], "maker");
-
- if(( lines[ i ] instanceof Element ) && ( labels[0] || makers[0] )){
- let index = labels[0].value || labels[0].innerText;
- let value = makers[0].value || makers[0].innerText ;
- value = (hasClass( makers[0], "json" ))? JSON.parse( value ) : value ;
-
- data[ index ] = value ;
- }
- }
- return data ;
- }
-
- function saveAndExitForm( form ){
- form.value = JSON.stringify( formToData( form ) );
- form.parentNode.removeChild( form );
- }
-
- function formToDictonnary( form, dictionnary){
- return dictionnary.create( formToData( form ) );
- }
-
- function triggerField( field ){
- let fields = document.getElementsByClassName( field ) ;
-
- for (let i = 0 ; i < fields.length ; i++ ){
- fields[i].click();
- }
- }
-
- function main(){
- display_data( characters.pool, "players_summary");
- triggerField( "wounds" );
- triggerField( "TN" );
- }
- </script>
- <style>
- .result{
- width : 3em;
- }
- </style>
- </head>
- <body onload="main()">
- <button onclick="popObjectMaker( Character )">Créer un Personnage</button>
- <table id="players_summary"></div>
- <div id="npc_summary"></div>
- </table>
- <button onclick="generateNPC()">Générer NPC</button><input id="npc-level" type="number" value="1"/><select id="npc-role"></select>
- <button onclick="popObjectMaker( Character, null, characters )">Générer Personnage</button>
- </body>
- </html>
|