feat : add equip dialogs

This commit is contained in:
Kazhnuz 2021-04-22 23:41:20 +02:00
parent 0d4fe92a90
commit 6c451e7aee
13 changed files with 214 additions and 29 deletions

View file

@ -23,7 +23,7 @@ function TransitionParent:loadResources()
end end
function TransitionParent:update(dt) function TransitionParent:update(dt)
self.tween:update(dt) self.tween:update(dt * 1.5)
end end
function TransitionParent:timerResponse(timer) function TransitionParent:timerResponse(timer)

View file

@ -0,0 +1,16 @@
return {
name = "darkgloves",
fullname = "Dark Gloves",
description = "Gloves engluffed with darkness",
conditions = {},
effects = {},
statsBoost = {
attack = 5,
hpmax = -10
},
isEquipement = true,
usableInBattle = false,
usableOnMap = false,
affectEverybody = false,
duration = 0
}

View file

@ -0,0 +1,16 @@
return {
name = "slowmoshoes",
fullname = "SlowMo Shoes",
description = "Shoes that make you slower",
conditions = {},
effects = {},
statsBoost = {
speed = -5,
mind = 6
},
isEquipement = true,
usableInBattle = false,
usableOnMap = false,
affectEverybody = false,
duration = 0
}

View file

@ -8,4 +8,16 @@ CONST.RANK_A = 80
CONST.RANK_S = 100 CONST.RANK_S = 100
CONST.MULT_HP = 4.5 CONST.MULT_HP = 4.5
CONST.LIST = {"hpmax", "ppmax", "attack", "power", "defense", "mind", "technic", "speed"}
CONST.SIMPLENAME = {}
CONST.SIMPLENAME["hpmax"] = "HP"
CONST.SIMPLENAME["ppmax"] = "PP"
CONST.SIMPLENAME["attack"] = "ATK"
CONST.SIMPLENAME["power"] = "POW"
CONST.SIMPLENAME["defense"] = "DEF"
CONST.SIMPLENAME["mind"] = "MND"
CONST.SIMPLENAME["technic"] = "TEK"
CONST.SIMPLENAME["speed"] = "SPD"
return CONST return CONST

View file

@ -29,13 +29,13 @@ function CharacterData:setData(data)
self.level = data.level self.level = data.level
self.exp = data.exp self.exp = data.exp
self.exp_next = data.exp_next self.exp_next = data.exp_next
self:createStats()
self.hp = data.hp self.hp = data.hp
self.pp = data.pp self.pp = data.pp
self.statuts = data.statuts self.statuts = data.statuts
self.equip = data.equip or {} self.equip = data.equip
self:createStats()
end end
return CharacterData return CharacterData

View file

@ -19,14 +19,17 @@ end
function CharacterEquip:setEquip(category, name) function CharacterEquip:setEquip(category, name)
if (not utils.string.isEmpty(self.equip[category])) then if (not utils.string.isEmpty(self.equip[category])) then
game.loot:addItem(category, self.equip[category]) game.loot:addItem(category, self.equip[category], 1)
end end
self.equip[category] = name self.equip[category] = name
game.loot:removeItem(category, name) game.loot:removeItem(category, name, 1)
self.stats = self:createStats()
end end
function CharacterEquip:predictStat(category, name) function CharacterEquip:predictStat(statName, category, name)
local data = itemutils.getItemData(category, name)
local boost = data.statsBoost[statName] or 0
return self:getStat(statName, category) + boost
end end
function CharacterEquip:getEquipStats(stat, ignore) function CharacterEquip:getEquipStats(stat, ignore)

View file

@ -27,6 +27,12 @@ function AbstractCharacter:createStats()
for _, name in ipairs(statNames) do for _, name in ipairs(statNames) do
stats[name] = self:getStat(name) stats[name] = self:getStat(name)
end end
if (self.hp ~= nil) then
self.hp = math.min(self.hp, stats.hpmax)
end
if (self.pp ~= nil) then
self.pp = math.min(self.pp, stats.ppmax)
end
return stats return stats
end end

View file

@ -1,7 +1,7 @@
local CharacterLevel = Object:extend() local CharacterLevel = Object:extend()
local charutils = require "game.utils.characters" local charutils = require "game.utils.characters"
local statList = {"hpmax", "ppmax", "attack", "power", "defense", "mind", "technic", "speed"} local STATS = require "datas.stats"
function CharacterLevel:initLevel() function CharacterLevel:initLevel()
self.level = self.data.startlevel self.level = self.data.startlevel
@ -49,7 +49,7 @@ function CharacterLevel:getComputedStat(statname)
end end
function CharacterLevel:getStatList() function CharacterLevel:getStatList()
return statList return STATS.LIST
end end
return CharacterLevel return CharacterLevel

View file

@ -3,8 +3,8 @@ local CharacterMenu = baseMenu:extend()
local const = require "scenes.overworld.screens.mainmenu.const" local const = require "scenes.overworld.screens.mainmenu.const"
function CharacterMenu:new(scene) function CharacterMenu:new(scene, x)
local x = const.X + 136 local x = x or const.X + 136
local w = const.WIDTH - x + 28 local w = const.WIDTH - x + 28
CharacterMenu.super.new(self, scene, "character", x, const.Y, w, const.HEIGHT, 4) CharacterMenu.super.new(self, scene, "character", x, const.Y, w, const.HEIGHT, 4)
end end

View file

@ -3,13 +3,15 @@ local CharacterWidget = baseWidget:extend()
local ComplexHPBar = require "game.modules.gui.complexhpbar" local ComplexHPBar = require "game.modules.gui.complexhpbar"
local Emblem = require "game.modules.gui.emblem" local Emblem = require "game.modules.gui.emblem"
local itemutils = require "game.utils.items"
-- Hero custom widget -- Hero custom widget
-- --
function CharacterWidget:new(scene, name) function CharacterWidget:new(scene, name, showEquip)
self.charName = name self.charName = name
self.emblem = Emblem(game.characters.list[name], scene) self.emblem = Emblem(game.characters.list[name], scene)
self.font2 = scene.assets.fonts["hudnbrs_small"] self.font2 = scene.assets.fonts["hudnbrs_small"]
self.showEquip = showEquip
CharacterWidget.super.new(self, scene, "character") CharacterWidget.super.new(self, scene, "character")
self.hpbar = ComplexHPBar(88) self.hpbar = ComplexHPBar(88)
@ -26,25 +28,35 @@ function CharacterWidget:drawCanvas()
local debut = 0 local debut = 0
local xDebut = 32 local xDebut = 32
self.font:draw(character.fullname, xDebut, debut, -1, "left") self.font:draw(character.fullname, xDebut, debut, -1, "left")
local yLvl = debut + 16 if (self.showEquip == nil) then
local xLvl = xDebut local yLvl = debut + 16
self.scene.assets.images["lvl"]:draw(xLvl, yLvl) local xLvl = xDebut
self.scene.assets.images["exp"]:draw(xLvl, yLvl + 10) self.scene.assets.images["lvl"]:draw(xLvl, yLvl)
self.font2:print(character.level, xLvl + 19, yLvl, "left") self.scene.assets.images["exp"]:draw(xLvl, yLvl + 10)
local expString = character.exp .. "/" .. character.exp_next self.font2:print(character.level, xLvl + 19, yLvl, "left")
self.font2:print(expString, xLvl + 19, yLvl + 10, "left") local expString = character.exp .. "/" .. character.exp_next
self.font2:print(expString, xLvl + 19, yLvl + 10, "left")
else
local charEquip = character.equip[self.showEquip]
local equipString = "None"
if (not utils.string.isEmpty(charEquip)) then
local data = itemutils.getItemData(self.showEquip, charEquip)
equipString = data.fullname
end
self.font:draw(equipString, xDebut, debut + 16, -1, "left")
end
end end
function CharacterWidget:draw(x, y) function CharacterWidget:draw(x, y)
local character = game.characters.list[self.charName] local character = game.characters.list[self.charName]
self.emblem:draw(x, y + 6) self.emblem:draw(x, y + 6)
if (self.showEquip == nil) then
local xDebut = x + 52 local xDebut = x + 52
local yDebut = y + 15 local yDebut = y + 15
self.scene.assets.fonts["hudnbrs_small"]:set() self.scene.assets.fonts["hudnbrs_small"]:set()
self.hpbar:drawWithLabels(xDebut + 53, yDebut, character.hp, character.stats.hpmax) self.hpbar:drawWithLabels(xDebut + 53, yDebut, character.hp, character.stats.hpmax)
self.ppbar:drawWithLabels(xDebut + 64, yDebut + 11, character.pp, character.stats.ppmax) self.ppbar:drawWithLabels(xDebut + 64, yDebut + 11, character.pp, character.stats.ppmax)
end
if self.canvas.texture ~= nil then if self.canvas.texture ~= nil then
love.graphics.draw(self.canvas.texture, x - self.ox, y - self.oy) love.graphics.draw(self.canvas.texture, x - self.ox, y - self.oy)
end end

View file

@ -0,0 +1,115 @@
local ParentScreen = require "scenes.overworld.screens.parent"
local EquipScreen = ParentScreen:extend()
local menu = require "game.modules.menus.list"
local const = require "scenes.overworld.screens.mainmenu.const"
local gui = require "game.modules.gui"
local baseCharacterMenu = require "scenes.overworld.screens.mainmenu.common.charmenu"
local baseCharacterWidget = require "scenes.overworld.screens.mainmenu.common.charwidget"
local CharacterMenu = baseCharacterMenu:extend()
local CharacterWidget = baseCharacterWidget:extend()
local STATS = require "datas.stats"
local DESC_SIZE = 32 * 6
function EquipScreen:new(scene, category, item, widgetId)
self.category = category
self.item = item
self.itemData = game.loot:getItemData(category, self.item.name)
self.widgetId = widgetId
self.choiceBack = gui.newChoiceBack(48 + 16)
self.descBox = gui.newTextBox("assets/gui/dialogbox.png", DESC_SIZE, 40 + 48+16)
self.desc = self.itemData.description
self.charName = ""
EquipScreen.super.new(self, scene, "Equipement")
end
function EquipScreen:setMenu()
CharacterMenu(self.scene, 224)
for i, name in ipairs(game.characters.team) do
CharacterWidget(self.scene, name, self.category)
end
self.scene.menusystem:switchMenu("character")
end
function EquipScreen:draw()
self.scene.assets.fonts["small"]:setLineHeight(16 / 18)
self:drawPocket()
self:drawDescription(const.X, const.Y)
end
function EquipScreen:drawDescription(x, y)
love.graphics.draw(self.descBox, x, y)
local xx, yy, ww = x + 6, y + 4, DESC_SIZE - 12
self.scene.assets.fonts["small"]:draw(self.itemData.fullname, xx, yy, ww, "left")
if (self.charName ~= "") then
local char = game.characters.list[self.charName]
for i, statName in ipairs(STATS.LIST) do
local xStat = xx + (((i - 1) % 2) * (ww/2))
local yStat = yy + (math.floor((i-1)/2) * 16) + 24
local middle = xStat + 10 + ww/4
local stat = char.stats[statName]
local newStat = char:predictStat(statName, self.category, self.item.name)
self.scene.assets.fonts["small"]:draw(STATS.SIMPLENAME[statName], xStat, yStat, ww, "left")
self.scene.assets.fonts["small"]:setColor(1, 1, 1, 0.9)
self.scene.assets.fonts["small"]:draw(stat .. " ", middle, yStat, -1, "right")
self.scene.assets.fonts["small"]:draw(">", middle, yStat, -1, "center")
if (newStat > stat) then
self.scene.assets.fonts["small"]:setColor(0.3, 1, 0.3, 0.9)
elseif (newStat < stat) then
self.scene.assets.fonts["small"]:setColor(1, 0.3, 0.3, 0.9)
end
self.scene.assets.fonts["small"]:draw(" " .. newStat, middle, yStat, -1, "left")
self.scene.assets.fonts["small"]:setColor(1, 1, 1, 1)
utils.graphics.resetColor()
end
end
end
function EquipScreen:drawPocket()
local x = const.X + DESC_SIZE - 48
local y = const.Y2 - 24
love.graphics.draw(self.choiceBack, x, y)
self.scene.assets.fonts["small"]:draw("x" .. self.item.number, x + 16, y - 2, -1, "left")
end
function EquipScreen:goBack()
self.scene.screens.mainmenu["items"](self.scene, game.loot:getPocketIdByName(self.category), self.widgetId)
end
function EquipScreen:useItem(charName)
local character = game.characters.list[charName]
if (self.item.number <= 1) then
character:setEquip(self.category, self.item.name)
self:goBack()
else
character:setEquip(self.category, self.item.name)
end
end
-- Character menu
function CharacterMenu:cancelAction()
-- Switch à l'écran précédant
self.scene.assets:playSFX("mBack")
self.scene.currentScreen:goBack()
end
-- Hero custom widget
--
function CharacterWidget:selectAction()
self.scene.currentScreen.charName = self.charName
end
function CharacterWidget:action()
self.scene.assets:playSFX("mSelect")
self.scene.currentScreen:useItem(self.charName)
self:redrawCanvas()
end
return EquipScreen

View file

@ -2,5 +2,6 @@ return {
pause = require "scenes.overworld.screens.mainmenu.pause", pause = require "scenes.overworld.screens.mainmenu.pause",
character = require "scenes.overworld.screens.mainmenu.character", character = require "scenes.overworld.screens.mainmenu.character",
items = require "scenes.overworld.screens.mainmenu.items", items = require "scenes.overworld.screens.mainmenu.items",
useItems = require "scenes.overworld.screens.mainmenu.useitems" useItems = require "scenes.overworld.screens.mainmenu.useitems",
equip = require "scenes.overworld.screens.mainmenu.equip"
} }

View file

@ -178,15 +178,19 @@ function UseWidget:new(scene, pocket, item, widgetId)
self.item = item self.item = item
self.itemData = game.loot:getItemData(pocket, self.item.name) self.itemData = game.loot:getItemData(pocket, self.item.name)
self.pocket = pocket self.pocket = pocket
self.pocketData = game.loot:getPocketByName(self.pocket)
self.widgetId = widgetId self.widgetId = widgetId
UseWidget.super.new(self, scene, "useMenu", "Use", "") UseWidget.super.new(self, scene, "useMenu", "Use", "")
if (not self.itemData.usableOnMap) then if (not (self.itemData.usableOnMap or self.pocketData.isEquipement)) then
self.color = {0.6, 0.6, 0.6} self.color = {0.6, 0.6, 0.6}
end end
end end
function UseWidget:action() function UseWidget:action()
if (self.itemData.usableOnMap) then if (self.pocketData.isEquipement) then
self.scene.screens.mainmenu["equip"](self.scene, self.pocket, self.item, self.widgetId)
self.scene.assets:playSFX("mSelect")
elseif (self.itemData.usableOnMap) then
self.scene.screens.mainmenu["useItems"](self.scene, self.pocket, self.item, self.widgetId) self.scene.screens.mainmenu["useItems"](self.scene, self.pocket, self.item, self.widgetId)
self.scene.assets:playSFX("mSelect") self.scene.assets:playSFX("mSelect")
else else