Skip to content

Commit

Permalink
Treat status as a array properly
Browse files Browse the repository at this point in the history
  • Loading branch information
dangarfield committed Oct 21, 2024
1 parent 11f59ed commit 9730749
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 137 deletions.
32 changes: 31 additions & 1 deletion app/battle/battle-damage-calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const getDefault = () => {
}
}
// https://github.com/Akari1982/q-gears_reverse/blob/master/ffvii/documents/final_fantasy_vii_battle_mech.txt
// https://wiki.ffrtt.ru/index.php/FF7/Battle/Battle_Mechanics
const calcDamage = (actor, command, attack, targets) => {
const isCritical = Math.random() >= 0.5
const damages = targets.map(t => {
Expand Down Expand Up @@ -49,4 +50,33 @@ const calcDamage = (actor, command, attack, targets) => {
})
return damages
}
export { calcDamage, DMG_TYPE }
const hasStatus = (char, status) => {
return char.status.includes(status)
}
const hasOneOfStatuses = (char, statuses) => {
return char.status.some(status => statuses.includes(status))
}
const addStatus = (char, status) => {
!char.status.includes(status) && char.status.push(status)
}
const addStatuses = (char, statuses) => {
statuses.forEach(
status => !char.status.includes(status) && char.status.push(status)
)
}
const removeStatus = (char, status) => {
char.status = char.status.filter(s => s !== status)
}
const removeStatuses = (char, statuses) => {
char.status = char.status.filter(s => !statuses.includes(s))
}
export {
calcDamage,
DMG_TYPE,
hasStatus,
hasOneOfStatuses,
addStatus,
addStatuses,
removeStatus,
removeStatuses
}
1 change: 1 addition & 0 deletions app/battle/battle-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ const getBattleStatsForChar = char => {
// console.log('battleUI equippedMateria', char, equippedMateria)
const hasLongRangeMateria = equippedMateria.some(m => m.index === 11)
// TODO - boosted stats

return {
hp,
mp,
Expand Down
11 changes: 7 additions & 4 deletions app/menu/menu-box-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getWindowTextures } from '../data/kernel-fetch-data.js'

import { sleep } from '../helpers/helpers.js'
import { addLimitBarTween } from './menu-limit-tween-helper.js'
import { hasStatus } from '../battle/battle-damage-calc.js'
const EDGE_SIZE = 8
const BUTTON_IMAGES = [
{ text: 'CANCEL', char: '✕', key: 'button cross' },
Expand Down Expand Up @@ -1073,10 +1074,12 @@ const addCharacterSummary = async (
window.config.sizing.height - y + labelOffsetY + labelGapY * 2,
0.5
)
if (status) {
const furySadnessStatus =
status.find(s => s === 'Fury' || s === 'Sadness') || null
if (furySadnessStatus) {
addTextToDialog(
dialogBox,
status,
furySadnessStatus,
`summary-status-${charId}`,
LETTER_TYPES.MenuBaseFont,
LETTER_COLORS.Purple,
Expand Down Expand Up @@ -1869,10 +1872,10 @@ const addLimitToDialog = (dialog, x, y, char) => {

let color1 = WINDOW_COLORS_SUMMARY.LIMIT_1
let color2 = WINDOW_COLORS_SUMMARY.LIMIT_2
if (char.status.statusFlags === 'Fury') {
if (hasStatus(char, 'Fury')) {
color1 = WINDOW_COLORS_SUMMARY.LIMIT_FURY_1
color2 = WINDOW_COLORS_SUMMARY.LIMIT_FURY_2
} else if (char.status.statusFlags === 'Sadness') {
} else if (hasStatus(char, 'Sadness')) {
color1 = WINDOW_COLORS_SUMMARY.LIMIT_SADNESS_1
color2 = WINDOW_COLORS_SUMMARY.LIMIT_SADNESS_2
}
Expand Down
119 changes: 82 additions & 37 deletions app/menu/menu-main-equip.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ import {
createItemListNavigation
} from './menu-box-helper.js'
import { fadeInHomeMenu, setSelectedNavByName } from './menu-main-home.js'
import { getBattleStatsForChar, getWeaponDataFromItemId, getArmorDataFromItemId } from '../battle/battle-stats.js'
import {
getBattleStatsForChar,
getWeaponDataFromItemId,
getArmorDataFromItemId
} from '../battle/battle-stats.js'
import { getMenuVisibility } from '../data/savemap-alias.js'
import { KEY } from '../interaction/inputs.js'

let headerDialog, infoDialog, slotsDialog, statsDialog, listDialog
let headerGroup, infoGroup, slotsGroup, statsLabelsGroup, statsBaseGroup, statsSelectedGroup, listGroup, listGroupContents
let headerGroup,
infoGroup,
slotsGroup,
statsLabelsGroup,
statsBaseGroup,
statsSelectedGroup,
listGroup,
listGroupContents

const DATA = {
partyMember: 0,
Expand Down Expand Up @@ -172,7 +183,7 @@ const drawHeader = () => {
55 - 8,
18.5 - 4,
DATA.char.name,
DATA.char.status.statusFlags === 'None' ? null : DATA.char.status.statusFlags,
DATA.char.status,
DATA.char.level.current,
DATA.char.stats.hp.current,
DATA.char.stats.hp.max,
Expand All @@ -183,7 +194,10 @@ const drawHeader = () => {
const equips = [
['Wpn.', DATA.char.equip.weapon.name ? DATA.char.equip.weapon.name : ''],
['Arm.', DATA.char.equip.armor.name ? DATA.char.equip.armor.name : ''],
['Acc.', DATA.char.equip.accessory.name ? DATA.char.equip.accessory.name : '']
[
'Acc.',
DATA.char.equip.accessory.name ? DATA.char.equip.accessory.name : ''
]
]

for (let i = 0; i < equips.length; i++) {
Expand All @@ -195,7 +209,7 @@ const drawHeader = () => {
LETTER_TYPES.MenuBaseFont,
LETTER_COLORS.Cyan,
125 - 8,
16.5 - 4 + (i * 17),
16.5 - 4 + i * 17,
0.5
)
// console.log('status equip', i, equip)
Expand All @@ -206,12 +220,12 @@ const drawHeader = () => {
LETTER_TYPES.MenuBaseFont,
LETTER_COLORS.White,
151.5 - 8,
16.5 - 4 + (i * 17),
16.5 - 4 + i * 17,
0.5
)
}
}
const drawInfo = (isFromList) => {
const drawInfo = isFromList => {
removeGroupChildren(infoGroup)

let description
Expand Down Expand Up @@ -239,7 +253,7 @@ const drawInfo = (isFromList) => {
)
}
}
const getGrowthText = (growthRateText) => {
const getGrowthText = growthRateText => {
if (growthRateText === 'None') {
return 'Nothing'
} else if (growthRateText === 'Double') {
Expand All @@ -251,7 +265,7 @@ const getGrowthText = (growthRateText) => {
return 'Normal'
}
}
const drawSlots = (isFromList) => {
const drawSlots = isFromList => {
removeGroupChildren(slotsGroup)
// Not right obviously, just placeholder

Expand All @@ -266,7 +280,9 @@ const drawSlots = (isFromList) => {
}
} else if (DATA.equipType === 0) {
// const equip = getWeaponDataFromItemId[DATA.char.equip.weapon.itemId] // This doesn't work?!?! WHY?!?!
const equip = window.data.kernel.weaponData.find(i => i.itemId === DATA.char.equip.weapon.itemId)
const equip = window.data.kernel.weaponData.find(
i => i.itemId === DATA.char.equip.weapon.itemId
)
slots = equip.materiaSlots
growth = getGrowthText(equip.growthRate)
} else if (DATA.equipType === 1) {
Expand Down Expand Up @@ -306,12 +322,7 @@ const drawSlots = (isFromList) => {
123.5 - 4,
0.5
)
createEquipmentMateriaViewer(slotsGroup,
75,
92 - 13.5,
slots,
DATA.char
)
createEquipmentMateriaViewer(slotsGroup, 75, 92 - 13.5, slots, DATA.char)
}
}

Expand All @@ -335,7 +346,7 @@ const drawStatsLabels = () => {
LETTER_TYPES.MenuBaseFont,
LETTER_COLORS.Cyan,
26.5 - 8,
148.5 - 4 + (i * 13),
148.5 - 4 + i * 13,
0.5
)
addTextToDialog(
Expand All @@ -345,7 +356,7 @@ const drawStatsLabels = () => {
LETTER_TYPES.MenuTextFixed,
LETTER_COLORS.Cyan,
100 + 23.5 - 8,
148.5 - 4 + (i * 13),
148.5 - 4 + i * 13,
0.5
)
}
Expand All @@ -361,7 +372,7 @@ const drawStatsBase = () => {
LETTER_TYPES.MenuTextStats,
LETTER_COLORS.White,
100 - 8,
148.5 - 4 + (i * 13),
148.5 - 4 + i * 13,
0.5
)
}
Expand All @@ -373,11 +384,26 @@ const drawStatsSelected = () => {
const charClone = JSON.parse(JSON.stringify(DATA.char))
const equip = DATA.equipable[DATA.page + DATA.pos]
if (DATA.equipType === 0) {
charClone.equip.weapon = { index: equip.index, itemId: equip.itemId, name: equip.name, description: equip.description }
charClone.equip.weapon = {
index: equip.index,
itemId: equip.itemId,
name: equip.name,
description: equip.description
}
} else if (DATA.equipType === 1) {
charClone.equip.armor = { index: equip.index, itemId: equip.itemId, name: equip.name, description: equip.description }
charClone.equip.armor = {
index: equip.index,
itemId: equip.itemId,
name: equip.name,
description: equip.description
}
} else if (DATA.equipType === 2) {
charClone.equip.accessory = { index: equip.index, itemId: equip.itemId, name: equip.name, description: equip.description }
charClone.equip.accessory = {
index: equip.index,
itemId: equip.itemId,
name: equip.name,
description: equip.description
}
}

// Note: This appears to be more accurate that the game displays in the menu
Expand All @@ -391,7 +417,12 @@ const drawStatsSelected = () => {
for (let i = 0; i < STAT_TYPES.length; i++) {
const attr = STAT_TYPES[i][1]

console.log('equip drawStatsSelected attr', attr, DATA.battleStats[attr], battleStats[attr])
console.log(
'equip drawStatsSelected attr',
attr,
DATA.battleStats[attr],
battleStats[attr]
)

let color = LETTER_COLORS.White
if (DATA.battleStats[attr] > battleStats[attr]) {
Expand All @@ -406,7 +437,7 @@ const drawStatsSelected = () => {
LETTER_TYPES.MenuTextStats,
color,
100 + 35 - 8,
148.5 - 4 + (i * 13),
148.5 - 4 + i * 13,
0.5
)
}
Expand All @@ -421,8 +452,10 @@ const drawList = () => {
for (let i = 0; i < window.data.savemap.items.length; i++) {
const item = window.data.savemap.items[i]
const type = getEquipTypeName(DATA.equipType)
if (item.itemId !== 0x7F) {
const itemData = window.data.kernel.allItemData.filter(i => i.itemId === item.itemId)[0]
if (item.itemId !== 0x7f) {
const itemData = window.data.kernel.allItemData.filter(
i => i.itemId === item.itemId
)[0]
if (itemData.type === type && itemData.equipableBy.includes(charName)) {
DATA.equipable.push(itemData)
}
Expand All @@ -433,7 +466,14 @@ const drawList = () => {
}
// console.log('equip equipable', DATA.equipable)

createItemListNavigation(listGroup, 200 + 113, 85.5 - 6.75, 151.5, DATA.equipable.length, 8)
createItemListNavigation(
listGroup,
200 + 113,
85.5 - 6.75,
151.5,
DATA.equipable.length,
8
)
listGroup.userData.slider.userData.moveToPage(DATA.page)

listGroupContents = addGroupToDialog(listGroup, 19)
Expand All @@ -453,15 +493,16 @@ const drawList = () => {
LETTER_TYPES.MenuBaseFont,
LETTER_COLORS.White,
x - 8,
y - 4 + (yAdj * i),
y - 4 + yAdj * i,
0.5
)
}
for (let i = 0; i < listGroupContents.children.length; i++) {
const listGroupContentsChild = listGroupContents.children[i]
for (let j = 0; j < listGroupContentsChild.children.length; j++) {
const listGroupContentsChildChild = listGroupContentsChild.children[j]
listGroupContentsChildChild.material.clippingPlanes = listDialog.userData.bg.material.clippingPlanes
listGroupContentsChildChild.material.clippingPlanes =
listDialog.userData.bg.material.clippingPlanes
}
}
// listGroupContents.children[0].children[0].material.clippingPlanes = listDialog.userData.bg.material.clippingPlanes
Expand All @@ -470,11 +511,11 @@ const drawList = () => {
// window.listDialog = listDialog
// window.listGroupContents = listGroupContents
}
const drawSelectTypePointer = (flashing) => {
const drawSelectTypePointer = flashing => {
const x = 123.5 - 10 + 0.5
const y = 9.5 + 7
const yAdj = 17
movePointer(POINTERS.pointer1, x, y + (yAdj * DATA.equipType), false, flashing)
movePointer(POINTERS.pointer1, x, y + yAdj * DATA.equipType, false, flashing)
if (flashing === undefined) {
movePointer(POINTERS.pointer2, 0, 0, true)
}
Expand All @@ -483,9 +524,9 @@ const drawSelectItemPointer = () => {
const x = 212.5 - 10 - 0.5
const y = 99.5 + 7
const yAdj = 18
movePointer(POINTERS.pointer2, x, y + (yAdj * DATA.pos))
movePointer(POINTERS.pointer2, x, y + yAdj * DATA.pos)
}
const selectTypeNavigation = (up) => {
const selectTypeNavigation = up => {
if (up) {
DATA.equipType++
if (DATA.equipType > 2) {
Expand Down Expand Up @@ -518,7 +559,7 @@ const selectType = () => {
const updatePage = () => {
listGroup.userData.slider.userData.moveToPage(DATA.page)
}
const selectItemNavigation = (up) => {
const selectItemNavigation = up => {
const lastPage = DATA.equipable.length - 8
// console.log('equip selectItemNavigation', up, DATA.pos, DATA.page, lastPage)

Expand Down Expand Up @@ -551,7 +592,7 @@ const selectItemNavigation = (up) => {
drawSlots(true)
drawStatsSelected()
}
const selectItemPageNavigation = (up) => {
const selectItemPageNavigation = up => {
const lastPage = DATA.equipable.length - 8
if (up) {
DATA.page = DATA.page + 8
Expand Down Expand Up @@ -581,14 +622,18 @@ const instantlyMoveItemList = () => {
}
listGroupContents.position.y = DATA.page * 18
}
const tweenItemList = (up) => {
const tweenItemList = up => {
setMenuState('equip-tweening-item')

for (let i = 0; i < DATA.page + 1; i++) {
listGroupContents.children[i].visible = true
}
const from = { y: listGroupContents.position.y }
const to = { y: up ? listGroupContents.position.y + 18 : listGroupContents.position.y - 18 }
const to = {
y: up
? listGroupContents.position.y + 18
: listGroupContents.position.y - 18
}
new TWEEN.Tween(from, MENU_TWEEN_GROUP)
.to(to, 50)
.onUpdate(function () {
Expand Down
Loading

0 comments on commit 9730749

Please sign in to comment.