Feast 2.0!
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

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