Card system explanation #2

Closed
opened 2026-06-04 14:22:49 +02:00 by fbouju · 1 comment
Owner

Every card definition is the the res://scripts/globals/card_database.gd script.

it must follow a scrict template

Template

{
"id": "lucky_catch",
"title": "Lucky Catch",
"description": "blabla",
"max_level": 5,
"effects": {
	"duplicateFishCatching": 0.05
  }
}
"effects": {
	"duplicateFishCatching": 0.05
}

The name of the effect must match EXACTLY the name of the variable located in GameGlobals you want to change.

Calculation of the stats

Everything said here is in : res://scripts/globals/game_globals.gd

Every cards owned by the player live in the playerDeck dictionnary :

@onready var playerDeck: Dictionary = {} #Maps a card id to a level (smelly_lure: 3)

When a card in selected, it fires the function :

func applyCard(id: String) -> void:
	# Add or get the card in the deck and add one level to it
	playerDeck[id] = playerDeck.get(id, 0) + 1
	# Recompute all the stats from scratch
	recompute_stats()
  • the function adds the card to the playerDeck if it doesn't exist and adds a level if it does.
  • then every stats are recalculated each time with the playerDeck

The recompute is done by taking the base stats and adding all the card effects contained in the playerDeck :

func recompute_stats() -> void:
	# reset to base and recompute all stats with the current player deck
	dayLengthMultiplier        = 1.0
	fishSpawnMultiplier        = 1.0
	fishScaleMultiplier        = 1.0
	lureRadiusMultiplier       = 1.0
	reelingDistanceMultiplier  = 1
	fishFleeDistanceMultiplier = 1.0
	fishingLineMaxLength       = 96.0
	fishingLineHealth          = 1
	fishingLineMaxHealth       = 1
	piranhaSpawnRate           = 10.0
	piranhaSpawnable           = true
	duplicateFishCatching      = 0.0

	# apply every card in the player deck
	for id in playerDeck:
		var card = CardDatabase.get_card(id) # get the card info from database
		if card.is_empty():
			continue
		var level = playerDeck[id] # get current level of the card in the player deck
		for stat in card.effects: # for each effet in the card
			print(card.title, " ", stat, " +", card.effects[stat], " ", level)
			print("Before: ", stat, " ", get(stat))
			# this is messy i probably confusing but works for now
			# set the variable with the name of the stat in card effect to => get(baseStat) + card.effect[stat] * level
			set(stat, get(stat) + card.effects[stat] * level) 
			print("After: ", stat, " ", get(stat))
Every card definition is the the `res://scripts/globals/card_database.gd` script. **it must follow a scrict template** ## Template ``` json { "id": "lucky_catch", "title": "Lucky Catch", "description": "blabla", "max_level": 5, "effects": { "duplicateFishCatching": 0.05 } } ``` ```json "effects": { "duplicateFishCatching": 0.05 } ``` The name of the effect must match **EXACTLY** the name of the variable located in `GameGlobals` you want to change. ## Calculation of the stats **Everything said here is in :** `res://scripts/globals/game_globals.gd` Every cards owned by the player live in the playerDeck dictionnary : ```gd @onready var playerDeck: Dictionary = {} #Maps a card id to a level (smelly_lure: 3) ``` When a card in selected, it fires the function : ```gd func applyCard(id: String) -> void: # Add or get the card in the deck and add one level to it playerDeck[id] = playerDeck.get(id, 0) + 1 # Recompute all the stats from scratch recompute_stats() ``` - the function adds the card to the playerDeck if it doesn't exist and adds a level if it does. - **then every stats are recalculated each time with the playerDeck** The recompute is done by taking the base stats and adding all the card effects contained in the playerDeck : ```gd func recompute_stats() -> void: # reset to base and recompute all stats with the current player deck dayLengthMultiplier = 1.0 fishSpawnMultiplier = 1.0 fishScaleMultiplier = 1.0 lureRadiusMultiplier = 1.0 reelingDistanceMultiplier = 1 fishFleeDistanceMultiplier = 1.0 fishingLineMaxLength = 96.0 fishingLineHealth = 1 fishingLineMaxHealth = 1 piranhaSpawnRate = 10.0 piranhaSpawnable = true duplicateFishCatching = 0.0 # apply every card in the player deck for id in playerDeck: var card = CardDatabase.get_card(id) # get the card info from database if card.is_empty(): continue var level = playerDeck[id] # get current level of the card in the player deck for stat in card.effects: # for each effet in the card print(card.title, " ", stat, " +", card.effects[stat], " ", level) print("Before: ", stat, " ", get(stat)) # this is messy i probably confusing but works for now # set the variable with the name of the stat in card effect to => get(baseStat) + card.effect[stat] * level set(stat, get(stat) + card.effects[stat] * level) print("After: ", stat, " ", get(stat)) ```
fbouju changed title from Adding a Card in the card database to Card system explanation 2026-06-04 14:23:18 +02:00
Author
Owner

You can obviously change things around if needed ! The way it's handled is not the best mdr

You can obviously change things around if needed ! The way it's handled is not the best mdr
fbouju added reference cards 2026-06-04 16:14:40 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
abgit/UGJ128#2
No description provided.