Feast 2.0!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

697 lines
17 KiB

  1. <template>
  2. <div class="combat-layout">
  3. <div @wheel="horizWheelLeft" class="statblock-row left-stats">
  4. <Statblock @selected="scrollParentTo($event)" @select="doSelectLeft(combatant, $event)" class="left-stats" :data-ally="combatant.side === encounter.currentMove.side" :data-destroyed="combatant.destroyed" :data-current-turn="encounter.currentMove === combatant" :data-active="combatant === left && combatant !== encounter.currentMove" :data-active-ally="combatant === right" :data-eaten="combatant.containedIn !== null" :data-dead="combatant.vigors.Health <= 0" v-for="(combatant, index) in combatants.filter(c => c.side == Side.Heroes).slice().reverse()" v-bind:key="'left-stat-' + index" :subject="combatant" :initiative="encounter.initiatives.get(combatant)" />
  5. <div class="spacer"></div>
  6. </div>
  7. <div @wheel="horizWheelRight" class="statblock-row right-stats">
  8. <Statblock @selected="scrollParentTo($event)" @select="doSelectRight(combatant, $event)" class="right-stats" :data-ally="combatant.side === encounter.currentMove.side" :data-destroyed="combatant.destroyed" :data-current-turn="encounter.currentMove === combatant" :data-active="combatant === right && combatant !== encounter.currentMove" :data-active-ally="combatant === left" :data-eaten="combatant.containedIn !== null" :data-dead="combatant.vigors.Health <= 0" v-for="(combatant, index) in combatants.filter(c => c.side == Side.Monsters)" v-bind:key="'right-stat-' + index" :subject="combatant" :initiative="encounter.initiatives.get(combatant)" />
  9. <div class="spacer"></div>
  10. </div>
  11. <div class="statblock-separator statblock-separator-left"></div>
  12. <div class="statblock-separator statblock-separator-center"></div>
  13. <div class="statblock-separator statblock-separator-right"></div>
  14. <div class="log">
  15. <div class="log-entry log-filler"></div>
  16. </div>
  17. <div class="left-fader">
  18. </div>
  19. <div v-if="running" class="left-actions">
  20. <div v-if="encounter.currentMove === left" class="vert-display">
  21. <i class="action-label fas fa-users" v-if="left.validGroupActions(combatants).length > 0"></i>
  22. <ActionButton @described="described" @executed="executedLeft" v-for="(action, index) in left.validGroupActions(combatants)" :key="'left-' + action.name + '-' + index" :action="action" :user="left" :target="right" :combatants="combatants" />
  23. <i class="action-label fas fa-user-friends" v-if="left.validActions(right).length > 0"></i>
  24. <ActionButton @described="described" @executed="executedLeft" v-for="(action, index) in left.validActions(right)" :key="'left-' + action.name + '-' + index" :action="action" :user="left" :target="right" :combatants="combatants" />
  25. <i class="action-label fas fa-user" v-if="left.validActions(left).length > 0"></i>
  26. <ActionButton @described="described" @executed="executedLeft" v-for="(action, index) in left.validActions(left)" :key="'left-' + action.name + '-' + index" :action="action" :user="left" :target="left" :combatants="combatants" />
  27. </div>
  28. </div>
  29. <div class="right-fader">
  30. </div>
  31. <div v-if="running" class="right-actions">
  32. <div v-if="encounter.currentMove === right" class="vert-display">
  33. <i class="action-label fas fa-users" v-if="right.validGroupActions(combatants).length > 0"></i>
  34. <ActionButton @described="described" @executed="executedRight" v-for="(action, index) in right.validGroupActions(combatants)" :key="'right-' + action.name + '-' + index" :action="action" :user="right" :target="left" :combatants="combatants" />
  35. <i class="action-label fas fa-user-friends" v-if="right.validActions(left).length > 0"></i>
  36. <ActionButton @described="described" @executed="executedRight" v-for="(action, index) in right.validActions(left)" :key="'right-' + action.name + '-' + index" :action="action" :user="right" :target="left" :combatants="combatants" />
  37. <i class="action-label fas fa-user" v-if="right.validActions(right).length > 0"></i>
  38. <ActionButton @described="described" @executed="executedRight" v-for="(action, index) in right.validActions(right)" :key="'right-' + action.name + '-' + index" :action="action" :user="right" :target="right" :combatants="combatants" />
  39. </div>
  40. </div>
  41. <div v-show="actionDescVisible && encounter.winner === null" class="action-description">
  42. </div>
  43. <button @click="$emit('give-in')" v-if="playerDigested" class="give-in">
  44. Give In
  45. </button>
  46. <button @click="$emit('leave-combat')" v-if="!playerDigested && encounter.winner !== null" class="exit-combat">
  47. Exit Combat
  48. </button>
  49. <button @click="continuing = true; pickNext()" v-if="!playerDigested && encounter.winner !== null && !continuing" class="continue-combat">
  50. Continue
  51. </button>
  52. </div>
  53. </template>
  54. <script lang="ts">
  55. import { Component, Prop, Vue, Watch, Emit } from 'vue-property-decorator'
  56. import { Creature } from '@/game/creature'
  57. import { POV } from '@/game/language'
  58. import { LogEntry, LogLine, nilLog } from '@/game/interface'
  59. import Statblock from './Statblock.vue'
  60. import ActionButton from './ActionButton.vue'
  61. import { Side, Encounter } from '@/game/combat'
  62. import { World } from '@/game/world'
  63. @Component(
  64. {
  65. components: { Statblock, ActionButton },
  66. data () {
  67. return {
  68. left: null,
  69. right: null,
  70. combatants: null,
  71. won: false,
  72. continuing: false,
  73. totalWon: false,
  74. actionDescVisible: false
  75. }
  76. }
  77. }
  78. )
  79. export default class Combat extends Vue {
  80. @Prop()
  81. encounter!: Encounter
  82. @Prop()
  83. world!: World
  84. Side = Side
  85. get playerDigested () {
  86. return this.world.player.destroyed && this.world.player.containedIn !== null
  87. }
  88. get running () {
  89. if (this.encounter.winner === null || (this.$data.continuing === true && this.encounter.totalWinner === null)) {
  90. return true
  91. } else {
  92. return false
  93. }
  94. }
  95. @Emit("described")
  96. described (entry: LogEntry) {
  97. const actionDesc = this.$el.querySelector(".action-description")
  98. this.$data.actionDescVisible = entry !== nilLog
  99. if (actionDesc !== null) {
  100. const holder = document.createElement("div")
  101. entry.render().forEach(element => {
  102. holder.appendChild(element)
  103. })
  104. actionDesc.innerHTML = ''
  105. actionDesc.appendChild(holder)
  106. }
  107. }
  108. @Emit("executedLeft")
  109. executedLeft (entry: LogEntry) {
  110. this.writeLog(entry, "left")
  111. this.writeLog(this.encounter.nextMove(), "center")
  112. this.pickNext()
  113. }
  114. // TODO these need to render on the correct side
  115. @Emit("executedRight")
  116. executedRight (entry: LogEntry) {
  117. this.writeLog(entry, "right")
  118. this.writeLog(this.encounter.nextMove(), "center")
  119. this.pickNext()
  120. }
  121. writeLog (entry: LogEntry, side = "") {
  122. const log = this.$el.querySelector(".log")
  123. if (log !== null) {
  124. const elements = entry.render()
  125. if (elements.length > 0) {
  126. const before = log.querySelector("div.log-entry") as HTMLElement|null
  127. const holder = document.createElement("div")
  128. holder.classList.add("log-entry")
  129. entry.render().forEach(element => {
  130. holder.appendChild(element)
  131. })
  132. if (side !== "") {
  133. holder.classList.add(side + "-move")
  134. }
  135. const hline = document.createElement("div")
  136. hline.classList.add("log-separator")
  137. if (side !== "") {
  138. hline.classList.add("log-separator-" + side)
  139. }
  140. log.insertBefore(hline, before)
  141. log.insertBefore(holder, hline)
  142. // TODO this behaves a bit inconsistent -- sometimes it jerks and doesn't scroll to the top
  143. if (log.scrollTop === 0 && before !== null) {
  144. log.scrollTo({ top: before.offsetTop, left: 0 })
  145. }
  146. setTimeout(() => log.scrollTo({ top: 0, left: 0, behavior: "smooth" }), 20)
  147. }
  148. }
  149. }
  150. pickNext () {
  151. // Did one side win?
  152. if (this.encounter.totalWinner !== null && !this.$data.totalWon) {
  153. this.$data.totalWon = true
  154. this.$data.won = true
  155. this.writeLog(
  156. new LogLine(
  157. `game o-vore for good`
  158. ),
  159. "center"
  160. )
  161. } else if (this.encounter.winner !== null && !this.$data.won && !this.$data.continuing) {
  162. this.$data.won = true
  163. this.writeLog(
  164. new LogLine(
  165. `game o-vore`
  166. ),
  167. "center"
  168. )
  169. } else {
  170. if (this.encounter.currentMove.side === Side.Heroes) {
  171. this.$data.left = this.encounter.currentMove
  172. if (this.encounter.currentMove.containedIn !== null) {
  173. this.$data.right = this.encounter.currentMove.containedIn.owner
  174. }
  175. } else if (this.encounter.currentMove.side === Side.Monsters) {
  176. this.$data.right = this.encounter.currentMove
  177. if (this.encounter.currentMove.containedIn !== null) {
  178. this.$data.left = this.encounter.currentMove.containedIn.owner
  179. }
  180. }
  181. // scroll to the newly selected creature
  182. this.$nextTick(() => {
  183. const creature: HTMLElement|null = this.$el.querySelector("[data-current-turn]")
  184. if (creature !== null) {
  185. this.scrollParentTo(creature)
  186. }
  187. const target: HTMLElement|null = this.$el.querySelector("[data-active]")
  188. if (target !== null) {
  189. this.scrollParentTo(target)
  190. }
  191. })
  192. if (!(this.encounter.currentMove.ai === null)) {
  193. if (this.encounter.currentMove.side === Side.Heroes) {
  194. this.executedLeft(this.encounter.currentMove.ai.decide(this.encounter.currentMove, this.encounter))
  195. } else {
  196. this.executedRight(this.encounter.currentMove.ai.decide(this.encounter.currentMove, this.encounter))
  197. }
  198. }
  199. }
  200. }
  201. selectable (creature: Creature): boolean {
  202. return !creature.destroyed && this.encounter.currentMove !== creature
  203. }
  204. doScroll (target: HTMLElement, speed: number, t: number) {
  205. if (t <= 0.25) {
  206. target.scrollBy(speed / 20 - speed / 20 * Math.abs(0.125 - t) * 8, 0)
  207. setTimeout(() => this.doScroll(target, speed, t + 1 / 60), 1000 / 60)
  208. }
  209. }
  210. horizWheelLeft (event: MouseWheelEvent) {
  211. const target = this.$el.querySelector(".left-stats") as HTMLElement
  212. if (target !== null) {
  213. this.doScroll(target, event.deltaY > 0 ? 200 : -200, 0)
  214. }
  215. }
  216. horizWheelRight (event: MouseWheelEvent) {
  217. const target = this.$el.querySelector(".right-stats") as HTMLElement
  218. if (target !== null) {
  219. this.doScroll(target, event.deltaY > 0 ? 200 : -200, 0)
  220. }
  221. }
  222. scrollParentTo (element: HTMLElement): void {
  223. if (element.parentElement !== null) {
  224. const pos = (element.offsetLeft - element.parentElement.offsetLeft)
  225. const width = element.getBoundingClientRect().width / 2
  226. const offset = element.parentElement.getBoundingClientRect().width / 2
  227. element.parentElement.scrollTo({ left: pos + width - offset, behavior: "smooth" })
  228. }
  229. }
  230. doSelectLeft (combatant: Creature, element: HTMLElement) {
  231. if (this.selectable(combatant)) {
  232. if (combatant.side !== this.$props.encounter.currentMove.side) {
  233. this.$data.left = combatant
  234. } else {
  235. this.$data.right = combatant
  236. }
  237. }
  238. this.scrollParentTo(element)
  239. }
  240. doSelectRight (combatant: Creature, element: HTMLElement) {
  241. if (this.selectable(combatant)) {
  242. if (combatant.side !== this.$props.encounter.currentMove.side) {
  243. this.$data.right = combatant
  244. } else {
  245. this.$data.left = combatant
  246. }
  247. }
  248. this.scrollParentTo(element)
  249. }
  250. created () {
  251. this.$data.left = this.encounter.combatants.filter(x => x.side === Side.Heroes)[0]
  252. this.$data.right = this.encounter.combatants.filter(x => x.side === Side.Monsters)[0]
  253. this.$data.combatants = this.encounter.combatants
  254. }
  255. mounted () {
  256. const leftStats = this.$el.querySelector(".left-stats")
  257. if (leftStats !== null) {
  258. leftStats.scrollTo(leftStats.getBoundingClientRect().width * 2, 0)
  259. }
  260. this.writeLog(this.encounter.desc.intro(this.world))
  261. this.pickNext()
  262. }
  263. }
  264. </script>
  265. <!-- Add "scoped" attribute to limit CSS to this component only -->
  266. <style scoped>
  267. .spacer {
  268. flex: 1 0;
  269. min-width: 2px;
  270. min-height: 100%;
  271. }
  272. .exit-combat,
  273. .continue-combat,
  274. .give-in {
  275. width: 100%;
  276. padding: 4pt;
  277. flex: 0 1;
  278. background: #333;
  279. border-color: #666;
  280. border-style: outset;
  281. user-select: none;
  282. color: #eee;
  283. font-size: 36px;
  284. }
  285. .give-in {
  286. grid-area: 2 / main-col-start / main-row-start / main-col-end;
  287. }
  288. .exit-combat {
  289. grid-area: 2 / main-col-start / main-row-start / 3;
  290. }
  291. .continue-combat {
  292. grid-area: 2 / 3 / main-row-start / main-col-end;
  293. }
  294. .combat-layout {
  295. position: relative;
  296. display: grid;
  297. grid-template-rows: fit-content(50%) fit-content(20%) [main-row-start] 1fr 20% [main-row-end] ;
  298. grid-template-columns: 1fr [main-col-start] fit-content(25%) fit-content(25%) [main-col-end] 1fr;
  299. width: 100%;
  300. height: 100%;
  301. overflow-x: hidden;
  302. overflow-y: hidden;
  303. margin: auto;
  304. }
  305. .log {
  306. position: relative;
  307. grid-area: main-row-start / main-col-start / main-row-end / main-col-end;
  308. overflow-y: scroll;
  309. overflow-x: hidden;
  310. font-size: 1rem;
  311. width: 100%;
  312. max-height: 100%;
  313. width: 70vw;
  314. max-width: 1000px;
  315. align-self: flex-start;
  316. height: 100%;
  317. }
  318. .log-filler {
  319. height: 100%;
  320. }
  321. .left-stats,
  322. .right-stats {
  323. display: flex;
  324. }
  325. .left-stats {
  326. flex-direction: row;
  327. }
  328. .right-stats {
  329. flex-direction: row;
  330. }
  331. .left-stats {
  332. grid-area: 1 / 1 / 2 / 3
  333. }
  334. .right-stats {
  335. grid-area: 1 / 3 / 2 / 5;
  336. }
  337. .statblock-separator-left {
  338. grid-area: 1 / 1 / 2 / 1;
  339. }
  340. .statblock-separator-center {
  341. grid-area: 1 / 3 / 2 / 3;
  342. }
  343. .statblock-separator-right {
  344. grid-area: 1 / 5 / 2 / 5;
  345. }
  346. .statblock-separator {
  347. position: absolute;
  348. width: 10px;
  349. height: 100%;
  350. transform: translate(-5px, 0);
  351. background: linear-gradient(90deg, transparent, #111 3px, #111 7px, transparent 10px);
  352. }
  353. .statblock-row {
  354. overflow-x: scroll;
  355. overflow-y: auto;
  356. }
  357. .left-fader {
  358. grid-area: 2 / 1 / 5 / 2;
  359. }
  360. .right-fader {
  361. grid-area: 2 / 4 / 5 / 5;
  362. }
  363. .left-fader,
  364. .right-fader {
  365. position: absolute;
  366. z-index: 1;
  367. pointer-events: none;
  368. background: linear-gradient(to bottom, #111, #00000000 10%, #00000000 90%, #111 100%);
  369. height: 100%;
  370. width: 100%;
  371. }
  372. .left-actions {
  373. grid-area: 2 / 1 / 5 / 2;
  374. }
  375. .right-actions {
  376. grid-area: 2 / 4 / 5 / 5;
  377. }
  378. .left-actions > .vert-display {
  379. align-items: flex-end;
  380. }
  381. .right-actions > .vert-display {
  382. align-items: flex-start;
  383. }
  384. .left-actions,
  385. .right-actions {
  386. overflow-y: hidden;
  387. display: flex;
  388. flex-direction: column;
  389. height: 100%;
  390. width: 100%;
  391. }
  392. .action-description {
  393. position: absolute;
  394. grid-area: 2 / main-col-start / main-row-end / main-col-end;
  395. text-align: center;
  396. font-size: 16px;
  397. padding-bottom: 48px;
  398. max-width: 1000px;
  399. text-align: center;
  400. width: 100%;
  401. background: linear-gradient(0deg, transparent, black 48px, black)
  402. }
  403. h3 {
  404. margin: 40px 0 0;
  405. }
  406. ul {
  407. list-style-type: none;
  408. padding: 0;
  409. }
  410. li {
  411. display: inline-block;
  412. margin: 0 10px;
  413. }
  414. a {
  415. color: #42b983;
  416. }
  417. .horiz-display {
  418. display: flex;
  419. justify-content: center;
  420. }
  421. .vert-display {
  422. display: flex;
  423. flex-direction: column;
  424. align-items: center;
  425. flex-wrap: nowrap;
  426. justify-content: start;
  427. height: 100%;
  428. width: 100%;
  429. overflow-y: auto;
  430. padding: 64px 0 64px;
  431. }
  432. .action-label {
  433. font-size: 200%;
  434. max-width: 300px;
  435. width: 100%;
  436. }
  437. </style>
  438. <style>
  439. .log-damage {
  440. font-weight: bold;
  441. }
  442. .damage-instance {
  443. white-space: nowrap;
  444. }
  445. .log > div.log-entry {
  446. position: relative;
  447. color: #888;
  448. padding-top: 4pt;
  449. padding-bottom: 4pt;
  450. }
  451. div.left-move,
  452. div.right-move {
  453. color: #888;
  454. }
  455. div.left-move {
  456. text-align: start;
  457. margin-right: 25%;
  458. margin-left: 2%;
  459. }
  460. div.right-move {
  461. text-align: end;
  462. margin-left: 25%;
  463. margin-right: 2%;
  464. }
  465. .log img {
  466. width: 75%;
  467. }
  468. .log > div.left-move:nth-child(7) {
  469. color: #898;
  470. }
  471. .log > div.left-move:nth-child(6) {
  472. color: #8a8;
  473. }
  474. .log > div.left-move:nth-child(5) {
  475. color: #8b8;
  476. }
  477. .log > div.left-move:nth-child(4) {
  478. color: #8c8;
  479. }
  480. .log > div.left-move:nth-child(3) {
  481. color: #8d8;
  482. }
  483. .log > div.left-move:nth-child(2) {
  484. color: #8e8;
  485. }
  486. .log > div.left-move:nth-child(1) {
  487. color: #8f8;
  488. }
  489. .log > div.right-move:nth-child(7) {
  490. color: #988;
  491. }
  492. .log > div.right-move:nth-child(6) {
  493. color: #a88;
  494. }
  495. .log > div.right-move:nth-child(5) {
  496. color: #b88;
  497. }
  498. .log > div.right-move:nth-child(4) {
  499. color: #c88;
  500. }
  501. .log > div.right-move:nth-child(3) {
  502. color: #d88;
  503. }
  504. .log > div.right-move:nth-child(2) {
  505. color: #e88;
  506. }
  507. .log > div.right-move:nth-child(1) {
  508. color: #f88;
  509. }
  510. .left-selector,
  511. .right-selector {
  512. display: flex;
  513. flex-wrap: wrap;
  514. }
  515. .combatant-picker {
  516. flex: 1 1;
  517. }
  518. .log-separator {
  519. animation: log-keyframes 0.5s;
  520. height: 4px;
  521. background: linear-gradient(90deg, transparent, #444 10%, #444 90%, transparent 100%);
  522. }
  523. .log-separator-left {
  524. margin: 4pt auto 4pt 0;
  525. }
  526. .log-separator-center {
  527. margin: 4pt auto 4pt;
  528. }
  529. .log-separator-right {
  530. margin: 4pt 0 4pt auto;
  531. }
  532. @keyframes log-keyframes {
  533. from {
  534. width: 0%;
  535. }
  536. to {
  537. width: 100%;
  538. }
  539. }
  540. .left-move {
  541. animation: left-fly-in 1s;
  542. }
  543. .right-move {
  544. animation: right-fly-in 1s;
  545. }
  546. .center-move {
  547. animation: center-fly-in 1s;
  548. }
  549. @keyframes left-fly-in {
  550. 0% {
  551. opacity: 0;
  552. transform: translate(-50px, 0);
  553. }
  554. 50% {
  555. transform: translate(0, 0);
  556. }
  557. 100% {
  558. opacity: 1;
  559. }
  560. }
  561. @keyframes right-fly-in {
  562. 0% {
  563. opacity: 0;
  564. transform: translate(50px, 0);
  565. }
  566. 50% {
  567. transform: translate(0, 0);
  568. }
  569. 100% {
  570. opacity: 1;
  571. }
  572. }
  573. @keyframes center-fly-in {
  574. 0% {
  575. opacity: 0;
  576. }
  577. 100% {
  578. opacity: 1;
  579. }
  580. }
  581. </style>