<template>
  <div id="app">
    <Header />
    <Explore v-if="mode === 'explore'" :world="world" />
    <Combat v-if="mode === 'combat'" :encounter="encounter" />
  </div>
</template>

<script lang="ts">
import { Component, Vue, Prop, Emit } from 'vue-property-decorator'
import Combat from './components/Combat.vue'
import Header from './components/Header.vue'
import Explore from './components/Explore.vue'
import * as Creatures from '@/game/creatures'
import * as Items from '@/game/items'
import { Creature } from '@/game/creature'
import { ProperNoun, TheyPronouns, FemalePronouns, MalePronouns, ImproperNoun, POV } from '@/game/language'
import { Place, Direction, World, Choice } from '@/game/world'
import { Encounter, Side } from './game/combat'
import { LogLine, nilLog } from './game/interface'
import { InstantKillEffect } from './game/combat/effects'

@Component({
  components: {
    Combat, Header, Explore
  },
  data () {
    return {
      encounter: null,
      encounters: null,
      world: null,
      mode: 'explore'
    }
  }
})
export default class App extends Vue {
  constructor () {
    super()
  }

  @Emit('startFight')
  startFight (encounter: Encounter) {
    this.$data.encounter = encounter
    this.$data.mode = 'combat'
  }

  created () {
    this.$data.encounters = []

    this.$data.encounters.push(new Encounter({ name: 'Boss Fight' }, this.makeParty().concat([new Creatures.Withers(), new Creatures.Kenzie()])))
    this.$data.encounters.push(new Encounter({ name: 'Cafat' }, this.makeParty().concat([new Creatures.Cafat()])))
    this.$data.encounters.push(new Encounter({ name: 'Dragon' }, this.makeParty().concat([new Creatures.Dragon()])))
    this.$data.encounters.push(new Encounter({ name: 'Wolves' }, this.makeParty().concat([new Creatures.Wolf(), new Creatures.Wolf(), new Creatures.Wolf(), new Creatures.Wolf()])))
    this.$data.encounters.push(new Encounter({ name: 'Large Wah' }, this.makeParty().concat([new Creatures.Shingo()])))

    this.$data.encounter = this.$data.encounters[0]

    const home = new Place('Home', 'This is not not home')

    const street = new Place('Street', 'The street')
    home.biconnect(Direction.North, street)

    this.$data.encounters.forEach((encounter: Encounter) => home.choices.push(new Choice(
      encounter.desc.name,
      'Fight time!',
      (world, executor) => {
        this.startFight(
          encounter
        )
        return nilLog
      }
    )))

    const bar = new Place('Bar', 'This is the bar')
    street.biconnect(Direction.East, bar)

    const player = new Creatures.Wolf()
    player.perspective = POV.Second
    player.side = Side.Heroes
    player.location = home
    this.$data.world = new World(player)
  }

  makeParty (): Creature[] {
    const fighter = new Creatures.Human(new ProperNoun("Redgar"), MalePronouns, {
      stats: {
        Toughness: 20,
        Power: 20,
        Speed: 15,
        Willpower: 15,
        Charm: 10
      }
    })
    fighter.title = "Lv. 6 Fighter"
    fighter.items.push(Items.Sword)
    const rogue = new Creatures.Human(new ProperNoun('Lidda'), FemalePronouns, {
      stats: {
        Toughness: 10,
        Power: 15,
        Speed: 20,
        Willpower: 15,
        Charm: 20
      }
    })
    rogue.title = "Lv. 5 Rogue"
    rogue.items.push(Items.Dagger)
    const wizard = new Creatures.Human(new ProperNoun('Mialee'), FemalePronouns, {
      stats: {
        Toughness: 10,
        Power: 10,
        Speed: 15,
        Willpower: 20,
        Charm: 25
      }
    })
    wizard.title = "Lv. 6 Wizard"
    wizard.items.push(Items.Wand)
    const cleric = new Creatures.Human(new ProperNoun('Jozan'), MalePronouns, {
      stats: {
        Toughness: 15,
        Power: 15,
        Speed: 10,
        Willpower: 20,
        Charm: 15
      }
    })
    cleric.title = "Lv. 5 Cleric"
    cleric.items.push(Items.Mace)

    return [fighter, cleric, rogue, wizard]
  }
}
</script>

<style>
body, html {
  background: #181818;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #ddd;
  background: #111;
  width: 100%;
  margin: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.tippy-box {
  text-align: center;
  border-radius: 10px;
}

.tippy-box .tooltip-title {
  font-size: 18pt;
  font-family: sans-serif;
}

.tippy-box .tooltip-body {
  font-size: 12pt;
  font-family: sans-serif;
}

*::-webkit-scrollbar {
    height: 12px;
  }
*::-webkit-scrollbar-button {
    width: 0px;
    height: 0px;
}
*::-webkit-scrollbar-thumb {
    background: #e1e1e1;
    border: 0px none #ffffff;
    border-radius: 50px;
}
*::-webkit-scrollbar-thumb:hover {
    background: #ffffff;
}
*::-webkit-scrollbar-thumb:active {
    background: #000000;
}
*::-webkit-scrollbar-track {
    background: #00000000;
    border: 0px none #ffffff;
    border-radius: 50px;
}
*::-webkit-scrollbar-track:hover {
    background: #666666;
}
*::-webkit-scrollbar-track:active {
    background: #333333;
}
*::-webkit-scrollbar-corner {
    background: transparent;
}

</style>
