const api = foundry.applications.api; const sheets = foundry.applications.sheets; export default class pokemonCharacterSheet extends api.HandlebarsApplicationMixin(sheets.ActorSheetV2) { effectivenessChart = { 'normal': {'rock': '0.5', 'ghost': '0', 'steel': '0.5'}, 'fire': {'fire': '0.5', 'water': '0.5', 'grass': '2', 'ice': '2', 'bug': '2', 'rock': '0.5', 'dragon': '0.5', 'steel': '2'}, 'water': {'fire': '2', 'water': '0.5', 'grass': '0.5', 'ground': '2', 'rock': '2', 'dragon': '0.5'}, 'electric': {'water': '2', 'electric': '0.5', 'grass': '0.5', 'ground': '0', 'flying': '2', 'dragon': '0.5'}, 'grass': {'fire': '0.5', 'water': '2', 'grass': '0.5', 'poison': '0.5', 'ground': '2', 'flying': '0.5', 'bug': '0.5', 'rock': '2', 'dragon': '0.5', 'steel': '0.5'}, 'ice': {'fire': '0.5', 'water': '0.5', 'grass': '2', 'ice': '0.5', 'ground': '2', 'flying': '2', 'dragon': '2', 'steel': '0.5'}, 'fighting': {'normal': '2', 'ice': '2', 'poison': '0.5', 'flying': '0.5', 'psychic': '0.5', 'bug': '0.5', 'rock': '2', 'ghost': '0', 'dark': '2', 'steel': '2', 'fairy': '0.5'}, 'poison': {'grass': '2', 'poison': '0.5', 'ground': '0.5', 'rock': '0.5', 'ghost': '0.5', 'steel': '0', 'fairy': '2'}, 'ground': {'fire': '2', 'electric': '2', 'grass': '0.5', 'poison': '2', 'flying': '0', 'bug': '0.5', 'rock': '2', 'steel': '2'}, 'flying': {'electric': '0.5', 'grass': '2', 'fighting': '2', 'bug': '2', 'rock': '0.5', 'steel': '0.5'}, 'psychic': {'fighting': '2', 'poison': '2', 'psychic': '0.5', 'dark': '0', 'steel': '0.5'}, 'bug': {'fire': '0.5', 'grass': '2', 'fighting': '0.5', 'poison': '0.5', 'flying': '0.5', 'psychic': '2', 'ghost': '0.5', 'dark': '2', 'steel': '0.5', 'fairy': '0.5'}, 'rock': {'fire': '0.5', 'ice': '2', 'fighting': '0.5', 'ground': '0.5', 'flying': '2', 'bug': '2', 'steel': '0.5'}, 'ghost': {'normal': '0', 'psychic': '2', 'ghost': '2', 'dark': '0.5'}, 'dragon': {'dragon': '2', 'steel': '0.5', 'fairy': '0'}, 'dark': {'fighting': '0.5', 'psychic': '2', 'ghost': '2', 'dark': '0.5', 'fairy': '0.5'}, 'steel': {'fire': '0.5', 'water': '0.5', 'electric': '0.5', 'ice': '2', 'rock': '2', 'steel': '0.5', 'fairy': '2'}, 'fairy': {'fire': '0.5', 'fighting': '2', 'poison': '0.5', 'dragon': '2', 'dark': '2', 'steel': '0.5'} }; sheetContext = {}; tab = "tab1"; static DEFAULT_OPTIONS = { tag: "form", classes: ["pokemon", "sheet", "characterSheet"], tabs: [ {navSelector: ".tabs", contentSelector: ".content", initial: this.tab} ], form: { submitOnChange: true, closeOnSubmit: false }, position: { width: 650 } } static PARTS = { header: { template: "systems/pokemon/templates/sheets/character/header.hbs" }, sidebar: { template: "systems/pokemon/templates/sheets/character/sidebar.hbs" } } get title() { return this.actor.name; } /** @override */ _configureRenderOptions(options) { super._configureRenderOptions(options); if (this.document.limited) options.parts = ["header"] else options.parts = ["header", "sidebar"]; } /** @override */ async _prepareContext(options) { // ################################################################################################# // ################################################################################################# // ## ## // ## Creates Basic Datamodel, which is used to fill the HTML together with Handelbars with Data. ## // ## ## // ################################################################################################# // ################################################################################################# const baseData = await super._prepareContext(); let context = { // Set General Values owner: baseData.document.isOwner, editable: baseData.editable, actor: baseData.document, system: baseData.document.system, items: baseData.document.items, config: CONFIG.POKEMON, isGM: baseData.user.isGM, effects: baseData.document.effects, types: ["normal", "fire", "water", "electric", "grass", "ice", "fighting", "poison", "ground", "flying", "psychic", "bug", "rock", "ghost", "dragon", "dark", "steel", "fairy"] }; context = this.calculateDerivated(context) this.sheetContext = context; context.system.tab = this.tab; return context; } calculateDerivated(context) { context.system.phArmorClass = 10+context.system.stats.defense; context.system.spArmorClass = 10+context.system.stats.defense; if (context.system.defenseCategory == "Physical") { context.system.phArmorClass += 2; } else { context.system.spArmorClass += 2; } context.defenses = context.types.map(type => this.calcEffectiveness(context, type)); context.system.speed = 30+5*context.system.stats.speed; return context; } calcEffectiveness(context, type) { var effectiveness = 1 effectiveness *= this.effectivenessChart[type][context.system.type1] ?? 1; if (context.system.type2 != "") { effectiveness *= this.effectivenessChart[type][context.system.type2] ?? 1; } if (effectiveness == 0.5) { effectiveness = "½"; } if (effectiveness == 0.25) { effectiveness = "¼"; } return effectiveness } /** @override */ _onRender(context, options) { const tabs = new foundry.applications.ux.Tabs({navSelector: ".tabs", contentSelector: ".content", initial: this.tab}); tabs.bind(this.element); // tabs.activate(this.tab); tabs.callback = () => { this.tab = tabs.active; } } }