Skip to content

Commit

Permalink
feat: add tags to cards
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed Dec 30, 2023
1 parent eb703f2 commit 2b961eb
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions assets/scripts/cards/berserker_rage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ register_card("BERSERKER_RAGE", {
highlight("3 action points") .. ", but take " .. highlight(tostring(30 - ctx.level * 10) .. "%") .. " (" ..
tostring(get_player().hp * (0.3 - ctx.level * 0.1)) .. ") of your HP as damage."
end,
tags = { "BUFF" },
max_level = 0,
color = "#d8a448",
need_target = false,
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/cards/block.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ register_card("BLOCK", {
state = function(ctx)
return "Shield yourself and gain " .. highlight(5 + ctx.level * 3) .. " block."
end,
tags = { "DEF" },
max_level = 1,
color = "#219ebc",
need_target = false,
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/cards/combined_shot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ register_card("COMBINED_SHOT", {
state = function(ctx)
return "Deal " .. highlight((5 + ctx.level * 5) * #get_opponent_guids(ctx.owner)) .. " damage for each enemy."
end,
tags = { "ATK" },
max_level = 1,
color = "#d8a448",
need_target = true,
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/cards/fear.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ register_card("FEAR", {
state = function(ctx)
return nil
end,
tags = { "CC" },
max_level = 0,
color = "#725e9c",
need_target = true,
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/cards/melee_hit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ register_card("MELEE_HIT", {
state = function(ctx)
return string.format(l("cards.MELEE_HIT.state", "Use your bare hands to deal %s damage."), highlight(5 + ctx.level * 3))
end,
tags = { "ATK" },
max_level = 1,
color = "#2f3e46",
need_target = true,
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/cards/radiant_seed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ register_card("RADIANT_SEED", {
return "Inflict " .. highlight(10 + ctx.level * 2) .. " damage to all enemies, but also causes " .. highlight(5 - ctx.level * 2) ..
" damage to the caster."
end,
tags = { "ATK" },
max_level = 1,
color = "#82c93e",
need_target = false,
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/cards/rupture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ register_card("RUPTURE", {
state = function(ctx)
return "Inflict your enemy with " .. highlight(tostring(1 + ctx.level) .. " Vulnerable") .. "."
end,
tags = { "ATK" },
max_level = 3,
color = "#cf532d",
need_target = true,
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/cards/shield_bash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ register_card("SHIELD_BASH", {
return "Deal " .. highlight(4 + ctx.level * 2) .. " damage to the enemy and gain " .. highlight("block") ..
" status effect equal to the damage dealt."
end,
tags = { "ATK" },
max_level = 1,
color = "#ff5722",
need_target = true,
Expand Down
2 changes: 2 additions & 0 deletions assets/scripts/definitions/callbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
---@field owner? guid
---@field caster? guid
---@field level? number
---@field tags? string[]
---@field damage? number
---@field heal? number
---@field stacks? number
Expand All @@ -17,6 +18,7 @@
---@class callbacks
---@field on_actor_die? fun(ctx:ctx):nil
---@field on_cast? fun(ctx:ctx):nil
---@field on_actor_did_cast? fun(ctx:ctx):nil
---@field on_damage? fun(ctx:ctx):nil
---@field on_damage_calc? fun(ctx:ctx):number|nil
---@field on_heal_calc? fun(ctx:ctx):number|nil
Expand Down
1 change: 1 addition & 0 deletions assets/scripts/definitions/card.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
---@field id? type_id
---@field name string
---@field description string
---@field tags? string[]
---@field state? fun(ctx:card_state_ctx):nil
---@field color string
---@field point_cost number
Expand Down
1 change: 1 addition & 0 deletions game/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
CallbackOnDamageCalc = "OnDamageCalc"
CallbackOnHealCalc = "OnHealCalc"
CallbackOnCast = "OnCast"
CallbackOnActorDidCast = "OnActorDidCast"
CallbackOnInit = "OnInit"
CallbackOnPickUp = "OnPickUp"
CallbackOnTurn = "OnTurn"
Expand Down
1 change: 1 addition & 0 deletions game/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Card struct {
ID string
Name string
Description string
Tags []string
State luhelp.OwnedCallback
Color string
PointCost int
Expand Down
26 changes: 26 additions & 0 deletions game/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,9 @@ func (s *Session) CastCard(guid string, target string) bool {
s.logLuaError(CallbackOnCast, instance.TypeID, err)
}
if val, ok := res.(bool); ok {
if val {
s.TriggerCallbackAll(CallbackOnActorDidCast, CreateContext("type_id", card.ID, "guid", guid, "caster", instance.Owner, "target", target, "level", instance.Level, "tags", card.Tags))
}
return val
}
}
Expand Down Expand Up @@ -1969,6 +1972,29 @@ func (s *Session) TriggerOnPlayerTurn() {
})
}

// TriggerCallbackAll triggers a callback on all artifacts, status effects and enemies.
func (s *Session) TriggerCallbackAll(callback string, ctx Context) {
s.TraverseArtifactsStatus(lo.Keys(s.instances),
func(instance ArtifactInstance, artifact *Artifact) {
if _, err := artifact.Callbacks[callback].Call(ctx); err != nil {
s.logLuaError(callback, instance.TypeID, err)
}
},
func(instance StatusEffectInstance, statusEffect *StatusEffect) {
if _, err := statusEffect.Callbacks[callback].Call(ctx); err != nil {
s.logLuaError(callback, instance.TypeID, err)
}
},
)
lo.ForEach(s.GetOpponents(PlayerActorID), func(actor Actor, index int) {
if enemy := s.GetEnemy(actor.TypeID); enemy != nil {
if _, err := enemy.Callbacks[callback].Call(ctx); err != nil {
s.logLuaError(callback, enemy.ID, err)
}
}
})
}

//
// Misc Functions
//
Expand Down
5 changes: 3 additions & 2 deletions ui/components/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func HalfCard(session *game.Session, guid string, active bool, baseHeight int, m
if !canCast {
pointText = cantCastStyle.Render(pointText)
}
tagsText := strings.Join(card.Tags, ", ")

cardCol, _ := colorful.Hex(card.Color)
bgCol, _ := colorful.MakeColor(style.BaseGrayDarker)
Expand All @@ -41,7 +42,7 @@ func HalfCard(session *game.Session, guid string, active bool, baseHeight int, m
if active {
return cardStyle.
Height(ui.Min(maxHeight-1, baseHeight+5)).
Render(fmt.Sprintf("%s\n\n%s\n\n%s", pointText, style.BoldStyle.Render(card.Name), cardState))
Render(fmt.Sprintf("%s%s%s\n\n%s\n\n%s", pointText, strings.Repeat(" ", 30-2-len(pointText)-len(tagsText)), tagsText, style.BoldStyle.Render(card.Name), cardState))
}

if minimal {
Expand All @@ -52,6 +53,6 @@ func HalfCard(session *game.Session, guid string, active bool, baseHeight int, m

return cardStyle.
Height(baseHeight).
Render(fmt.Sprintf("%s\n\n%s\n\n%s", pointText, style.BoldStyle.Render(card.Name), cardState))
Render(fmt.Sprintf("%s%s%s\n\n%s\n\n%s", pointText, strings.Repeat(" ", 30-2-len(pointText)-len(tagsText)), tagsText, style.BoldStyle.Render(card.Name), cardState))

}
2 changes: 1 addition & 1 deletion ui/menus/gameview/gameview.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (m Model) fightEnemyView() string {
func (m Model) fightCardView() string {
fight := m.Session.GetFight()
var cardBoxes = lo.Map(fight.Hand, func(guid string, index int) string {
return components.HalfCard(m.Session, guid, index == m.selectedCard, m.fightCardViewHeight()/2, m.fightCardViewHeight()-1, len(fight.Hand)*40 >= m.Size.Width)
return components.HalfCard(m.Session, guid, index == m.selectedCard, m.fightCardViewHeight()/2, m.fightCardViewHeight()-1, len(fight.Hand)*35 >= m.Size.Width)
})

cardBoxes = lo.Map(cardBoxes, func(item string, i int) string {
Expand Down

0 comments on commit 2b961eb

Please sign in to comment.