text: function manageEquipCanClick(contexted){
      if(player[contexted.layer].clickables[contexted.id] == "locked") return false;
      if(player[contexted.layer].clickables[contexted.id] == "equiped") return true;
      if(equipIsBuyable(contexted.cost)) return true;
      return false
  }
  
  function manageEquipOnClick(contexted){
      if (player[contexted.layer].clickables[contexted.id] != "equiped") {
          player[contexted.layer].clickables[contexted.id]  = "equiped";
          equipPay(contexted.cost);
          console.log(`${tmp[contexted.layer].clickables[contexted.id].title} ${player[contexted.layer].clickables[contexted.id]} !`)
      } else {
          player[contexted.layer].clickables[contexted.id] = "unequiped";
          equipRefund(contexted.cost);
          console.log(`${tmp[contexted.layer].clickables[contexted.id].title} ${player[contexted.layer].clickables[contexted.id]} !`)
      }
  }
  
  
  function equipIsBuyable(cost) {
      tPath = player["hero"]
  
      for (currency in cost) {
          if(asD(player["hero"][currency]).lt(cost[currency])) return false
      }
  
      return true
  }
  
  function equipPay(cost) {
      tPath = player["hero"]
  
      for (currency in cost) {
          tPath[currency] = tPath[currency].sub(cost[currency])
      }
  }
  
  function equipRefund(cost) {
      tPath = player["hero"]
  
      for (currency in cost) {
          tPath[currency] = tPath[currency].add(cost[currency])
      }
  }
  
  function totalEquipCost(currency) {
      let tResultArray= []
      tResultArray.length = 0;
  
      for (e in tmp["hero"].clickables) {
          if(!isNaN(e)){ // select only pseudo array object
              for (f in tmp["hero"].clickables[e].cost) {
                  if (player["hero"].clickables[e] == "equiped") {
                      if (tResultArray[0].includes(f)) {
                          let arrIndex = tResultArray[0].indexOf(f)
                          tResultArray[1][arrIndex] = tResultArray[1][arrIndex].add(tmp["hero"].clickables[e].cost[f])
                      } else {
                          tResultArray[0].push(f)
                          tResultArray[1].push(tmp["hero"].clickables[e].cost[f])
                      }
                  }
              }
          }
      }
      return tResultArray
  }
  
  function getEventLoadout(){
  
      let tResultArray = [];
      let _layerToCheck = ["hero" , "mission"]
  
      for (layer of _layerToCheck) {
          // Check clickables
          for (e in tmp[layer].clickables) {
              if(!isNaN(e)){ // select only pseudo array object
                  if (player[layer].clickables[e] == "equiped" && (tmp[layer].clickables[e].event)) {
                      for (f of tmp[layer].clickables[e].event) {
                          if (player[layer].clickables[e] == "equiped") {
                              tResultArray.push(_.cloneDeep(f))                    
                          }
                      }
                  }
              }
          }
  
          // Check Upgrades
          for (e of player[layer].upgrades) {
              if (tmp[layer].upgrades[e].modToAdd != null && tmp[layer].upgrades[e].modToAdd != undefined) {
                  for (f of tmp[layer].upgrades[e].modToAdd) {
                      for (g of tResultArray) {
                          if (g.tags != null || g.tags != undefined) {
                              if(g.tags.includes(...f.addToTags) || f.addToTags.includes("all")) {
                                  g.modStorage.push(_.cloneDeep(f))
                              }
                          }
                      }
                  }
              }
          }
  
          // Check upgrades for Mod to apply
          for (e of player[layer].upgrades) {
              if (tmp[layer].upgrades[e].event != null && tmp[layer].upgrades[e].event != undefined) {
                  for (f of tmp[layer].upgrades[e].event) {
                      tResultArray.push(_.cloneDeep(f))
                  }
              }
          }
      }
  
  
      return tResultArray;
  }
  
  function getEquippedEventTitle(loadoutArray){
      let tString = ""
      loadoutArray.forEach(e => {tString = `${tString}[${e.title.toString()}]`})    
  return tString
  }
  
  addLayer("hero", {
      name: "Hero", // This is optional, only used in a few places, If absent it just uses the layer id.
      symbol: "H", // This appears on the layer's node. Default is the id with the first letter capitalized
      position: 0, // Horizontal position within a row. By default it uses the layer id and sorts in alphabetical order
      startData() { return {
          unlocked: true,
  		
          points: new Decimal(1),
  		xp : new Decimal(0),
          
          equipMax: new Decimal(10),
          equipPoints: new Decimal(9),
  
          weaponSlot: new Decimal(0),
          weaponSlotMax : new Decimal(1),
  
          clickables : {[11] : "equiped",[12] : "locked"},
  
          equipedEvent : [], // array of effect to Add to Hero Actor eventStorage
          /*
          { need Name, optional Title
              name : "burst",
              title : "hero event test",
          },
          */
      }},
  	
      tabFormat: {
          "Hero": {
              content:
                  [
                  "main-display",
                  "resource-display",
                  ["prestige-button","text to prestige here "],
                  "buyables",
                  "clickables",
                  "upgrades",
                  "milestones",
                  ],
          },
  
          "Class": {
              content:
                  [
                  ["display-text","Class stuff goes here"],
                  "buyables",
                  "clickables",
                  "upgrades",
                  "milestones",
                  ],
          },
          
          "Weapon": {
              content:
                  [
                  //["display-text","Weapon stuff goes here"],
                  ["display-text",() => {return "You have " + formatWhole(player["hero"].equipPoints) + " of " + formatWhole(player["hero"].equipMax) + " Equip Points"}],
                  ["display-text",() => {return "You have " + formatWhole(player["hero"].weaponSlot) + " of " + formatWhole(player["hero"].weaponSlotMax) + " Weapon Slots"}],
                  ["display-text",() => {return `${getEquippedEventTitle(getEventLoadout())}`}],
                  ["blank","10px"],
                  "buyables",
                  "clickables",
                  "upgrades",
                  "milestones",
                  ],
          },
  
          "Gear": {
              content:
                  [
                  ["display-text",() => {return "You have " + formatWhole(player["hero"].equipPoints) + " of " + formatWhole(player["hero"].equipMax) + " Equip Points"}],
                  ["blank","10px"],
                  "buyables",
                  "clickables",
                  "upgrades",
                  "milestones",
                  ],
          },
  
      },
  
  	branches:["hq"],
      color: "#4BDC13",
      requires: new Decimal(10), // Can be a function that takes requirement increases into account
      resource: "Levels", // Name of prestige currency
      baseResource: "XP", // Name of resource prestige is based on
      baseAmount() {return player.hero.xp}, // Get the current amount of baseResource
      type: "static", // normal: cost to gain currency depends on amount gained. static: cost depends on how much you already have
      exponent: 0.5, // Prestige currency exponent
  	base:new Decimal(10),
      roundUpCost : true,
      autoPrestige(){return true},
      onPrestige(gain){
          player["hero"].xp = asD(player["hero"].xp).sub(asD(gain).times(tmp["hero"].nextAt))
      },
      resetNothing : true,
      gainMult() { // Calculate the multiplier for main currency from bonuses
          mult = new Decimal(1)
          return mult
      },
      gainExp() { // Calculate the exponent on main currency from bonuses
          return new Decimal(1)
      },
      row: 15, // Row the layer is in on the tree (0 is the first row)
      hotkeys: [
          {key: "h", description: "H: Reset for prestige points", onPress(){showTab("hero")}},
      ],
      layerShown : true,
  
      upgrades : {
          rows: 5,
          cols: 5,
          11: {
              title: "Rifle Crit", //**optional**. Displayed at the top in a larger font. It can also be a function that returns updating text. Can use basic HTML.
              description: "Crit Mod Test", //A description of the upgrade's effect. *You will also have to implement the effect where it is applied.* It can also be a function that returns updating text. Can use basic HTML.
              nextStepBehaviour : "keep",
  
              equipTab : "Class", //Capitalized to match tabs name
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true}, // unlocked(): **optional**. A function returning a bool to determine if the upgrade is visible or not. Default is unlocked.
  
              cost: new Decimal(1), // A Decimal for the cost of the upgrade. By default, upgrades cost the main prestige currency for the layer.
              currencyDisplayName: "RP",
              currencyInternalName: "points",
  
              modToAdd : [{
                      name : "shotparametermod",
                      title : "Crit UP !",
                      addToTags : ["rifle"],
                      eventChance : 25,
                      shotParameter : new ShotParameter(0, {shotDamage : new SplitObject(0,3,0)}),                                        
              }],            
          },
  
          12: {
              title: "Fast Advance", //**optional**. Displayed at the top in a larger font. It can also be a function that returns updating text. Can use basic HTML.
              description: "progress fast with no enemy", //A description of the upgrade's effect. *You will also have to implement the effect where it is applied.* It can also be a function that returns updating text. Can use basic HTML.
  
              equipTab : "Class", //Capitalized to match tabs name
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true}, // unlocked(): **optional**. A function returning a bool to determine if the upgrade is visible or not. Default is unlocked.
  
              cost: new Decimal(1), // A Decimal for the cost of the upgrade. By default, upgrades cost the main prestige currency for the layer.
              currencyDisplayName: "RP",
              currencyInternalName: "points",
  
              event : [new Event("progressup", {
                  title : "Fast Advance",
                  nextStepBehaviour : "keep",
  
                  tags : ["nothreat"],
  
                  cooldown : new SplitObject(1000),
  
                  power : new Decimal (50),
              },),],
          },
  
          13: {
              title: "Small Fry Stomper", //**optional**. Displayed at the top in a larger font. It can also be a function that returns updating text. Can use basic HTML.
              description: "Enemy quantity increases threat cap", //A description of the upgrade's effect. *You will also have to implement the effect where it is applied.* It can also be a function that returns updating text. Can use basic HTML.
  
              equipTab : "Class", //Capitalized to match tabs name
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true}, // unlocked(): **optional**. A function returning a bool to determine if the upgrade is visible or not. Default is unlocked.
  
              cost: new Decimal(1), // A Decimal for the cost of the upgrade. By default, upgrades cost the main prestige currency for the layer.
              currencyDisplayName: "RP",
              currencyInternalName: "points",
  
              event : [new Event("threatcapup", {
                  title : "CAP per Qt",
                  nextStepBehaviour : "keep",
  
                  tags : ["perenemyquantity"],
  
                  cooldown : new SplitObject(1000),
  
                  power : new Decimal (1),
              },),],
          },
  
          14: {
              title: "Building Success", //**optional**. Displayed at the top in a larger font. It can also be a function that returns updating text. Can use basic HTML.
              description: "Better progress and threat cap per step", //A description of the upgrade's effect. *You will also have to implement the effect where it is applied.* It can also be a function that returns updating text. Can use basic HTML.
  
              equipTab : "Class", //Capitalized to match tabs name
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true}, // unlocked(): **optional**. A function returning a bool to determine if the upgrade is visible or not. Default is unlocked.
  
              cost: new Decimal(1), // A Decimal for the cost of the upgrade. By default, upgrades cost the main prestige currency for the layer.
              currencyDisplayName: "RP",
              currencyInternalName: "points",
  
              event : [
                  new Event("threatcapup", {
                      
                      title : "Per Step",
                      nextStepBehaviour : "reset",
  
                      tags : ["perstep"],
  
                      cooldown : new SplitObject(1000),
  
                      power : new Decimal (10),
                  },),
  
                  new Event("progressup", {
                      title : "Per Step",
                      nextStepBehaviour : "reset",
  
                      tags : ["perstep"],
  
                      cooldown : new SplitObject(1000),
  
                      power : new Decimal (1),
                  },),
              ],
          },
      },
  
      clickables: {
          masterButtonPress(){return console.log("Master button clicked !")},
          masterButtonText: "Reset equipments",
          showMasterButton(){
              let showInArray = ["Weapon","Gear"] // Defaults to true if absent, put subtabs in array you want master button in
              return [showInArray].some(a => a == player.subtabs["hero"].mainTabs) ? true : false}, 
          rows: 9,
          cols: 9,
  
          11: {
              title:"M-X16",
              equipTab : "Weapon", //Capitalized to match tabs name
  
              cost:{
                  equipPoints: new Decimal(1),
                  weaponSlot: new Decimal(1)
              },
  
              display() {return `${player[this.layer].clickables[this.id]}`}, // returning state of the clickable
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true},
              canClick(){
                  /*
                  if(player[this.layer].clickables[this.id] == "equiped" ||
                  equipIsBuyable(this.cost))
                  return true
                  */
                  return manageEquipCanClick(this)
              },
              onClick(){
                  manageEquipOnClick(this)
                  /*
                  if (player[this.layer].clickables[this.id] != "equiped") {
                      player[this.layer].clickables[this.id]  = "equiped";
                      equipPay(this.cost);
                      console.log(`${tmp[this.layer].clickables[this.id].title} ${player[this.layer].clickables[this.id]} !`)
                  } else {
                      player[this.layer].clickables[this.id] = "unequiped";
                      equipRefund(this.cost);
                      console.log(`${tmp[this.layer].clickables[this.id].title} ${player[this.layer].clickables[this.id]} !`)
                  }
                  */
              },
  
              event : [new Event("weapon", {
                  title : "Rifle",
                  nextStepBehaviour : "keep",
  
                  tags : ["rifle", "burst"],
  
                  cooldown : new SplitObject(1000),
                  shotParameter : new QuickShotParameter(5,3),
  
                  settings : {
                      useAmmo : true,
                  },
  
                  ammo : new Ammo({
                      name : "bullet",
                      magazine : new SplitObject(30),
                      reload : new SplitObject(1000),
  
                      settings : {
                          useReload : true
                      },
                  },),
  
                  modStorage : [{
                      name : "shotparametermod",
                      shotParameter : new ShotParameter({}, {shotDamage : new SplitObject(0,1,1)})
                  },],
              },),],
          },
  
          12: {
              title:"Shotgun Ben2",
              equipTab : "Weapon", //Capitalized to match tabs name
              cost:{
                  equipPoints: new Decimal(1),
                  weaponSlot: new Decimal(1)
              },
              display() {return `${player[this.layer].clickables[this.id]}`}, // returning state of the clickable
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true},
              
              canClick(){
                  return manageEquipCanClick(this)
              },
              onClick(){
                  manageEquipOnClick(this)
              },
  
              event : [new Event("weapon", {
                  title : "Shotgun",
                  nextStepBehaviour : "keep",
                  cooldown : new SplitObject(1000),
  
                  shotParameter : new QuickShotParameter(3,6),
              },),],
          },
  
          13: {
              title:"Rocket Launcher",
              equipTab : "Weapon", //Capitalized to match tabs name
              cost:{
                  equipPoints: new Decimal(5),
                  weaponSlot: new Decimal(1)
              },
              display() {return `${player[this.layer].clickables[this.id]}`}, // returning state of the clickable
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true},
              
              canClick(){
                  return manageEquipCanClick(this)
              },
              onClick(){
                  manageEquipOnClick(this)
              },
  
              event : [new Event("weapon", {
                  title : "Rocket",
                  nextStepBehaviour : "keep",
  
                  favoredTargetTags : ["structure"],
  
                  followupEvent : [
                      new Event("weapon", {
                          title : "Rocket Blast",
                          nextStepBehaviour : "keep",
                          shotParameter : new QuickShotParameter(4,1),
                      },),],
  
                  cooldown : new SplitObject(1000),
  
                  shotParameter : new QuickShotParameter(25,1),
              },),],
          },
  
          61: {
              title:"Grenade",
              equipTab : "Gear", //Capitalized to match tabs name
              cost:{
                  equipPoints: new Decimal(1),
              },
              display() {return `${player[this.layer].clickables[this.id]}`}, // returning state of the clickable
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true},
              canClick(){
                  return manageEquipCanClick(this)
              },
              onClick(){
                  manageEquipOnClick(this)
              },
  
              event : [new Event("weapon", {
                  name : "weapon",
                  title : "Grenade",
                  nextStepBehaviour : "keep",
                  cooldown : new SplitObject(1000),
                  eventChance : 10, // flat in percent chance to fire
                  shotParameter : new QuickShotParameter(10,10),
              },),],
          },
  
          62: {
              title:"Armor",
              equipTab : "Gear", //Capitalized to match tabs name
              cost:{
                  equipPoints: new Decimal(1),
              },
              display() {return `${player[this.layer].clickables[this.id]}`}, // returning state of the clickable
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true},
              canClick(){
                  return manageEquipCanClick(this)
              },
              onClick(){
                  manageEquipOnClick(this)
              },
  
              event : [new Event("threatcapup", {
                  name : "threatcapup",
                  nextStepBehaviour : "keep",
                  title : "Armor up",
                  tags : ["accumulate"],
                  cooldown : new SplitObject(1000),
              },),],
          },
  
          63: {
              title:"Turret Layer",
              equipTab : "Gear", //Capitalized to match tabs name
              cost:{
                  equipPoints: new Decimal(1),
              },
              display() {return `${player[this.layer].clickables[this.id]}`}, // returning state of the clickable
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true},
              canClick(){
                  return manageEquipCanClick(this)
              },
              onClick(){
                  manageEquipOnClick(this)
              },
  
              event : [new Event("summonactor", {
                  name : "summonactor",
                  title : "Deploy Turret",
                  nextStepBehaviour : "keep",
                  // tags : ["forcenewactor"], // make sure a new group is created instead of reinforcing existing turrent
                  cooldown : new SplitObject(1000),
                  // eventChance : 25,
  
                  settings : {
                      summonMaxGroupSize : true,
                      summonMaxUnitCount : true,
                  },
  
                  summonMaxGroupSize : new Decimal(1),
                  summonMaxUnitCount : 2,
  
                  summonName : "hqturret",
                  summonExtraParameters : {title : "Mini Turret"},
                  summonExtraEvents : [],                
                  
                  power : new Decimal(1),
              },),],
          },
  
          64: {
              title:"Chronobelt",
              equipTab : "Gear", //Capitalized to match tabs name
              cost:{
                  equipPoints: new Decimal(1),
              },
              display() {return `${player[this.layer].clickables[this.id]}`}, // returning state of the clickable
              unlocked(){if(player.subtabs["hero"].mainTabs == this.equipTab) return true},
              canClick(){
                  return manageEquipCanClick(this)
              },
              onClick(){
                  manageEquipOnClick(this)
              },
  
              event : [new Event("cooldownmodifier", {
                  name : "cooldownmodifier",
                  nextStepBehaviour : "keep",
                  title : "move faster",
                  cooldown : new SplitObject(1000),
                  eventChance : 10,
                  power : new Decimal(1000),
              },),],
  
  
          },
      },
  
      update(diff){
      },
  })