use case instead of ifs
This commit is contained in:
		
							parent
							
								
									9858c47a14
								
							
						
					
					
						commit
						beee6a46b4
					
				@ -18,28 +18,32 @@ function handleMoonslicer(message) {
 | 
				
			|||||||
  console.log('Hit0: ' + hit0 + ' Hit1: ' + hit1);
 | 
					  console.log('Hit0: ' + hit0 + ' Hit1: ' + hit1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var old_text = textarea.value;
 | 
					  var old_text = textarea.value;
 | 
				
			||||||
  if (hit0 == 20 || hit1 == 20) {
 | 
					
 | 
				
			||||||
    textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=+[[1d6]]}} {{dmg1type=Ice}}";
 | 
					  new Set([hit0, hit1]).forEach( function(die_val) {
 | 
				
			||||||
 | 
					    switch (die_val) {
 | 
				
			||||||
 | 
					      case 20:
 | 
				
			||||||
 | 
					        textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=+[[1d6]]}} {{dmg1type=Ice}}";
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      case 19:
 | 
				
			||||||
 | 
					        textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=+[[1d4]]}} {{dmg1type=Ice}}";
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      case 2:
 | 
				
			||||||
 | 
					        textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[floor(1d4/2)]]}} {{dmg1type=Ice to self}}";
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      case 1:
 | 
				
			||||||
 | 
					        textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[floor(1d6/2)]]}} {{dmg1type=Ice to self}}";
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    submit_button.click();
 | 
					    submit_button.click();
 | 
				
			||||||
  }
 | 
					  });
 | 
				
			||||||
  if (hit0 == 19 || hit1 == 19) {
 | 
					
 | 
				
			||||||
    textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=+[[1d4]]}} {{dmg1type=Ice}}";
 | 
					 | 
				
			||||||
    submit_button.click();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if (hit0 == 2 || hit1 == 2) {
 | 
					 | 
				
			||||||
    textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[floor(1d4/2)]]}} {{dmg1type=Ice to self}}}";
 | 
					 | 
				
			||||||
    submit_button.click();
 | 
					 | 
				
			||||||
  } 
 | 
					 | 
				
			||||||
  if (hit0 == 1 || hit1 == 1) {
 | 
					 | 
				
			||||||
    textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[1d6]]} {{dmg1type=Ice to self}}}";
 | 
					 | 
				
			||||||
    submit_button.click();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  textarea.value = old_text;
 | 
					  textarea.value = old_text;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
Send a message to the page script.
 | 
					 *  Figure out what to do with the messages we find in the textchat area
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
function handleMutation(mutation) {
 | 
					function handleMutation(mutation) {
 | 
				
			||||||
  mutation.addedNodes.forEach( function(message) {
 | 
					  mutation.addedNodes.forEach( function(message) {
 | 
				
			||||||
    if (message.classList && message.classList.contains('you')) {
 | 
					    if (message.classList && message.classList.contains('you')) {
 | 
				
			||||||
@ -52,10 +56,10 @@ function handleMutation(mutation) {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
Add messagePageScript() as a listener to click events on
 | 
					 *  Watch for changes to the textchat content area
 | 
				
			||||||
the "from-content-script" element.
 | 
					 */ 
 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
var textchat = document.getElementById("textchat");
 | 
					var textchat = document.getElementById("textchat");
 | 
				
			||||||
var content = textchat.getElementsByClassName("content")[0];
 | 
					var content = textchat.getElementsByClassName("content")[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user