jsObjectsPractice.js
//Determine where an attack hits on a mech 

Determine where an attack hits on a mech
Determine where an attack hits on a mech
function damageLocation (diceRoll, facing, battleMech, damageRoll){
    var frontLocation = ["front head armor",
            "front arm armor (Left)",
            "front arm armor (Right)",
            "front torso armor",
            "front leg armor (Left)",
            "front leg armor (Right)"];
    var rearLocation = ["rear head armor",
            "rear arm armor (Left)",
            "rear arm armor (Right)",
            "rear torso armor",
            "rear leg armor (Left)",
            "rear leg armor (Right)"];
    var internalLocation = ["head internal structure",
            "arm internal struture (Left)",
            "arm internal struture (Right)",
            "torso internal struture",
            "leg internal struture (Right)",
            "leg internal struture (Right)"];
    var carryOverDmg = 0; 
    if (facing == 0){
        switch (diceRoll){
            case 0:
                if(battleMech.frontHeadArmor > damageRoll){
                    applyDamage(damageRoll, battleMech.frontHeadArmor);
                } else{
                    carryOverDmg = carryOverDamageCalculator(damageRoll, battleMech.frontHeadArmor);
                    battleMech.frontHeadArmor = 0;
                    document.write("FRONT HEAD ARMOR DESTROYED!!" + "<br>");
                    if(battleMech.internalHead > carryOverDmg){
                        applyDamage(carryOverDmg, battleMech.internalHead);
                        document.write("Damage to "+internalLocation[diceRoll]+ " reported. INTERNAL DAMAGE TO COCKPIT!!" + "<br>");
                    }else{
                        battleMech.internalHead = 0;
                        document.write("PILOT HAS BEEN KILLED!!" + "<br>");
                    }
                }
                break;
            case 1:
                if(battleMech.frontArmArmorL > damageRoll){
                    applyDamage(carryOverDmg, battleMech.frontArmArmorL);
                } else{
                    carryOverDmg = carryOverDamageCalculator(damageRoll, battleMech.frontArmArmorL);
                    battleMech.frontArmArmorL = 0;
                    document.write("FRONT LEFT ARM ARMOR DESTROYED!!" + "<br>");
                    if(battleMech.internalArmL > carryOverDmg){
                        applyDamage(carryOverDmg, battleMech.internalArmL);
                        document.write("Damage to "+internalLocation[diceRoll]+ " reported. INTERNAL DAMAGE TO LEFT ARM!!" + "<br>");
                    }else{
                        battleMech.internalArmL = 0;
                        battleMech.leftArmWeapons = false;
                        document.write("LEFT ARM HAS BEEN DESTROYED!!" + "<br>");
                    }
                }
                break;
            case 2:
                if(battleMech.frontArmArmorR > damageRoll){
                    applyDamage(carryOverDmg, battleMech.frontArmArmorR);
                }else{
                    carryOverDmg = carryOverDamageCalculator(damageRoll, battleMech.frontArmArmorR);
                    battleMech.frontArmArmorR = 0;
                    document.write("FRONT RIGHT ARM ARMOR DESTROYED!!" + "<br>");
                    if(battleMech.internalArmR > carryOverDmg){
                        applyDamage(carryOverDmg, battleMech.internalArmR);
                        document.write("Damage to "+internalLocation[diceRoll]+ " reported. INTERNAL DAMAGE TO RIGHT ARM!!" + "<br>");
                    }else{
                        battleMech.internalArmR = 0;
                        battleMech.rightArmWeapons = false;
                        document.write("RIGHT ARM HAS BEEN DESTROYED!!" + "<br>");
                    }
                }
                break;
            case 3:
                if(battleMech.frontTorsoArmor > damageRoll){
                    applyDamage(carryOverDmg, battleMech.frontTorsoArmor);
                }else{
                    carryOverDmg = carryOverDamageCalculator(damageRoll, battleMech.frontTorsoArmor);
                    battleMech.frontTorsoArmor = 0;
                    document.write("FRONT TORSO ARMOR DESTROYED!!" + "<br>");
                    if(battleMech.internalTorso > carryOverDmg){
                        applyDamage(carryOverDmg, battleMech.internalTorso);
                        document.write("Damage to "+internalLocation[diceRoll]+ " reported. INTERNAL DAMAGE TO TORSO!!" + "<br>");
                    }else{
                        battleMech.internalTorso = 0;
                        battleMech.torsoWeapons = false;
                        document.write("CORE CONTAINMENT LEAK DETECTED...NUCLEAR REACTOR EXPLOSION...NO ESCAPE------------" + "<br>");
                    }
                }
                break;
            case 4:
                if(battleMech.frontLegArmorL > damageRoll){
                    applyDamage(carryOverDmg, battleMech.frontLegArmorL);
                }else{
                    carryOverDmg = carryOverDamageCalculator(damageRoll, battleMech.frontLegArmorL);
                    battleMech.frontLegArmorL = 0;
                    document.write("FRONT LEFT LEG ARMOR DESTROYED!!" + "<br>");
                    if(battleMech.internalLegL > carryOverDmg){
                        applyDamage(carryOverDmg, battleMech.internalLegL);
                        document.write("Damage to "+internalLocation[diceRoll]+ " reported. INTERNAL DAMAGE TO LEFT LEG!!" + "<br>");
                    }else{
                        battleMech.internalLegL = 0;
                        battleMech.topSpeedKm = 0;
                        document.write("FRONT LEFT LEG HAS BEEN DESTROYED!!" + "<br>");
                        if(battleMech.internalLegR > 0){
                            document.write("MECH HAS BEEN HOBBLED, BRACE FOR COLLAPSE!!")
                        }else{
                            document.write("MECH HAS BEEN DISABLED. EJECT.")
                        }
                    }
                }
                break;  
            case 5:
                if(battleMech.frontLegArmorR > damageRoll){
                    applyDamage(carryOverDmg, battleMech.frontLegArmorR);
                }else{
                    carryOverDmg = carryOverDamageCalculator(damageRoll, battleMech.frontLegArmorR);
                    battleMech.frontLegArmorR = 0;
                    document.write("FRONT RIGHT LEG ARMOR DESTROYED!!" + "<br>");
                    if(battleMech.internalLegR > carryOverDmg){
                        applyDamage(carryOverDmg, battleMech.internalLegR);
                        document.write("Damage to "+internalLocation[diceRoll]+ " reported. INTERNAL DAMAGE TO RIGHT LEG!!" + "<br>");
                    }else{
                        battleMech.internalLegR = 0;
                        battleMech.topSpeedKm = 0;
                        document.write("FRONT RIGHT LEG HAS BEEN DESTROYED!!" + "<br>");
                        if(battleMech.internalLegL > 0){
                            document.write("MECH HAS BEEN HOBBLED, BRACE FOR COLLAPSE!!")
                        }else{
                            document.write("MECH HAS BEEN DISABLED. EJECT.")
                        }
                    }
                }
                break;  
        }
        document.write(" A location roll of " + diceRoll+ " hits the "+frontLocation[diceRoll]+ " of the " +battleMech.mechName+ "<br>");
        return frontLocation[diceRoll];
    } 
    else {
        switch (diceRoll){
            case 0:
                battleMech.rearHeadArmor -= damageRoll;
                break;
            case 1:
                battleMech.rearArmArmorL -= damageRoll;
                break;
            case 2:
                battleMech.rearArmArmorR -= damageRoll;
                break;
            case 3:
                battleMech.rearTorsoArmor -= damageRoll;
                break;
            case 4:
                battleMech.rearLegArmorL -= damageRoll;
                break;  
            case 5:
                battleMech.rearLegArmorR -= damageRoll;
                break; 
        }
        document.write(" A location roll of " + diceRoll+ " hits the "+rearLocation[diceRoll]+  " of the " +battleMech.mechName+ "<br>");
        return rearLocation[diceRoll];
   }
}
function damageLocation ( diceRoll , facing , battleMech , damageRoll ) { var frontLocation = [ "front head armor" , "front arm armor (Left)" , "front arm armor (Right)" , "front torso armor" , "front leg armor (Left)" , "front leg armor (Right)" ] ; var rearLocation = [ "rear head armor" , "rear arm armor (Left)" , "rear arm armor (Right)" , "rear torso armor" , "rear leg armor (Left)" , "rear leg armor (Right)" ] ; var internalLocation = [ "head internal structure" , "arm internal struture (Left)" , "arm internal struture (Right)" , "torso internal struture" , "leg internal struture (Right)" , "leg internal struture (Right)" ] ; var carryOverDmg = 0 ; if ( facing == 0 ) { switch ( diceRoll ) { case 0 : if ( battleMech . frontHeadArmor > damageRoll ) { applyDamage ( damageRoll , battleMech . frontHeadArmor ) ; } else { carryOverDmg = carryOverDamageCalculator ( damageRoll , battleMech . frontHeadArmor ) ; battleMech . frontHeadArmor = 0 ; document . write ( "FRONT HEAD ARMOR DESTROYED!!" + "<br>" ) ; if ( battleMech . internalHead > carryOverDmg ) { applyDamage ( carryOverDmg , battleMech . internalHead ) ; document . write ( "Damage to " + internalLocation [ diceRoll ] + " reported. INTERNAL DAMAGE TO COCKPIT!!" + "<br>" ) ; } else { battleMech . internalHead = 0 ; document . write ( "PILOT HAS BEEN KILLED!!" + "<br>" ) ; } } break ; case 1 : if ( battleMech . frontArmArmorL > damageRoll ) { applyDamage ( carryOverDmg , battleMech . frontArmArmorL ) ; } else { carryOverDmg = carryOverDamageCalculator ( damageRoll , battleMech . frontArmArmorL ) ; battleMech . frontArmArmorL = 0 ; document . write ( "FRONT LEFT ARM ARMOR DESTROYED!!" + "<br>" ) ; if ( battleMech . internalArmL > carryOverDmg ) { applyDamage ( carryOverDmg , battleMech . internalArmL ) ; document . write ( "Damage to " + internalLocation [ diceRoll ] + " reported. INTERNAL DAMAGE TO LEFT ARM!!" + "<br>" ) ; } else { battleMech . internalArmL = 0 ; battleMech . leftArmWeapons = false ; document . write ( "LEFT ARM HAS BEEN DESTROYED!!" + "<br>" ) ; } } break ; case 2 : if ( battleMech . frontArmArmorR > damageRoll ) { applyDamage ( carryOverDmg , battleMech . frontArmArmorR ) ; } else { carryOverDmg = carryOverDamageCalculator ( damageRoll , battleMech . frontArmArmorR ) ; battleMech . frontArmArmorR = 0 ; document . write ( "FRONT RIGHT ARM ARMOR DESTROYED!!" + "<br>" ) ; if ( battleMech . internalArmR > carryOverDmg ) { applyDamage ( carryOverDmg , battleMech . internalArmR ) ; document . write ( "Damage to " + internalLocation [ diceRoll ] + " reported. INTERNAL DAMAGE TO RIGHT ARM!!" + "<br>" ) ; } else { battleMech . internalArmR = 0 ; battleMech . rightArmWeapons = false ; document . write ( "RIGHT ARM HAS BEEN DESTROYED!!" + "<br>" ) ; } } break ; case 3 : if ( battleMech . frontTorsoArmor > damageRoll ) { applyDamage ( carryOverDmg , battleMech . frontTorsoArmor ) ; } else { carryOverDmg = carryOverDamageCalculator ( damageRoll , battleMech . frontTorsoArmor ) ; battleMech . frontTorsoArmor = 0 ; document . write ( "FRONT TORSO ARMOR DESTROYED!!" + "<br>" ) ; if ( battleMech . internalTorso > carryOverDmg ) { applyDamage ( carryOverDmg , battleMech . internalTorso ) ; document . write ( "Damage to " + internalLocation [ diceRoll ] + " reported. INTERNAL DAMAGE TO TORSO!!" + "<br>" ) ; } else { battleMech . internalTorso = 0 ; battleMech . torsoWeapons = false ; document . write ( "CORE CONTAINMENT LEAK DETECTED...NUCLEAR REACTOR EXPLOSION...NO ESCAPE------------" + "<br>" ) ; } } break ; case 4 : if ( battleMech . frontLegArmorL > damageRoll ) { applyDamage ( carryOverDmg , battleMech . frontLegArmorL ) ; } else { carryOverDmg = carryOverDamageCalculator ( damageRoll , battleMech . frontLegArmorL ) ; battleMech . frontLegArmorL = 0 ; document . write ( "FRONT LEFT LEG ARMOR DESTROYED!!" + "<br>" ) ; if ( battleMech . internalLegL > carryOverDmg ) { applyDamage ( carryOverDmg , battleMech . internalLegL ) ; document . write ( "Damage to " + internalLocation [ diceRoll ] + " reported. INTERNAL DAMAGE TO LEFT LEG!!" + "<br>" ) ; } else { battleMech . internalLegL = 0 ; battleMech . topSpeedKm = 0 ; document . write ( "FRONT LEFT LEG HAS BEEN DESTROYED!!" + "<br>" ) ; if ( battleMech . internalLegR > 0 ) { document . write ( "MECH HAS BEEN HOBBLED, BRACE FOR COLLAPSE!!" ) } else { document . write ( "MECH HAS BEEN DISABLED. EJECT." ) } } } break ; case 5 : if ( battleMech . frontLegArmorR > damageRoll ) { applyDamage ( carryOverDmg , battleMech . frontLegArmorR ) ; } else { carryOverDmg = carryOverDamageCalculator ( damageRoll , battleMech . frontLegArmorR ) ; battleMech . frontLegArmorR = 0 ; document . write ( "FRONT RIGHT LEG ARMOR DESTROYED!!" + "<br>" ) ; if ( battleMech . internalLegR > carryOverDmg ) { applyDamage ( carryOverDmg , battleMech . internalLegR ) ; document . write ( "Damage to " + internalLocation [ diceRoll ] + " reported. INTERNAL DAMAGE TO RIGHT LEG!!" + "<br>" ) ; } else { battleMech . internalLegR = 0 ; battleMech . topSpeedKm = 0 ; document . write ( "FRONT RIGHT LEG HAS BEEN DESTROYED!!" + "<br>" ) ; if ( battleMech . internalLegL > 0 ) { document . write ( "MECH HAS BEEN HOBBLED, BRACE FOR COLLAPSE!!" ) } else { document . write ( "MECH HAS BEEN DISABLED. EJECT." ) } } } break ; } document . write ( " A location roll of " + diceRoll + " hits the " + frontLocation [ diceRoll ] + " of the " + battleMech . mechName + "<br>" ) ; return frontLocation [ diceRoll ] ; } else { switch ( diceRoll ) { case 0 : battleMech . rearHeadArmor -= damageRoll ; break ; case 1 : battleMech . rearArmArmorL -= damageRoll ; break ; case 2 : battleMech . rearArmArmorR -= damageRoll ; break ; case 3 : battleMech . rearTorsoArmor -= damageRoll ; break ; case 4 : battleMech . rearLegArmorL -= damageRoll ; break ; case 5 : battleMech . rearLegArmorR -= damageRoll ; break ; } document . write ( " A location roll of " + diceRoll + " hits the " + rearLocation [ diceRoll ] + " of the " + battleMech . mechName + "<br>" ) ; return rearLocation [ diceRoll ] ; } }
Determine where an attack hits on a mech
Determine where an attack hits on a mech
//in the case of the damage roll exceeding the armor store left over damage to be applied to internal structure
