Значительно изменил бд и генерацию так же добавил роли
This commit is contained in:
@@ -3,55 +3,29 @@
|
||||
repo = ClashDeckGenerator2::Repos::CardsRepo.new
|
||||
|
||||
CARD_TYPES = %w[troop spell building].freeze
|
||||
RARITIES = %w[common rare epic legendary champion].freeze
|
||||
RARITIES = %w[common rare epic legendary champion hero evolution].freeze
|
||||
|
||||
COMMON_CARDS = [
|
||||
# ========================
|
||||
# TROOPS
|
||||
# ========================
|
||||
{ name: "Skeletons", elixir_cost: 1, rarity: "common", type: "troop", is_meta: 1 },
|
||||
{ name: "Electro Spirit", elixir_cost: 1, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Fire Spirit", elixir_cost: 1, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Ice Spirit", elixir_cost: 1, rarity: "common", type: "troop", is_meta: 0 },
|
||||
# Подключаем файлы с картами
|
||||
require_relative "seeds/common"
|
||||
require_relative "seeds/rare"
|
||||
require_relative "seeds/epic"
|
||||
require_relative "seeds/legendary"
|
||||
require_relative "seeds/champion"
|
||||
require_relative "seeds/hero"
|
||||
require_relative "seeds/evo"
|
||||
|
||||
{ name: "Goblins", elixir_cost: 2, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Spear Goblins", elixir_cost: 2, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Bomber", elixir_cost: 2, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Bats", elixir_cost: 2, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Berserker", elixir_cost: 2, rarity: "common", type: "troop", is_meta: 0 },
|
||||
# Объединяем все карты
|
||||
CARDS = []
|
||||
CARDS.concat(COMMON_CARDS)
|
||||
CARDS.concat(RARE_CARDS)
|
||||
CARDS.concat(EPIC_CARDS)
|
||||
CARDS.concat(LEGENDARY_CARDS)
|
||||
CARDS.concat(CHAMPION_CARDS)
|
||||
CARDS.concat(HERO_CARDS)
|
||||
CARDS.concat(EVOLUTION_CARDS)
|
||||
|
||||
{ name: "Archers", elixir_cost: 3, rarity: "common", type: "troop", is_meta: 1 },
|
||||
{ name: "Knight", elixir_cost: 3, rarity: "common", type: "troop", is_meta: 1 },
|
||||
{ name: "Minions", elixir_cost: 3, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Goblin Gang", elixir_cost: 3, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Skeleton Barrel", elixir_cost: 3, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Firecracker", elixir_cost: 3, rarity: "common", type: "troop", is_meta: 1 },
|
||||
{ name: "Skeleton Dragons", elixir_cost: 4, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Barbarians", elixir_cost: 5, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Minion Horde", elixir_cost: 5, rarity: "common", type: "troop", is_meta: 1 },
|
||||
{ name: "Rascals", elixir_cost: 5, rarity: "common", type: "troop", is_meta: 1 },
|
||||
{ name: "Royal Giant", elixir_cost: 6, rarity: "common", type: "troop", is_meta: 1 },
|
||||
{ name: "Elite Barbarians", elixir_cost: 6, rarity: "common", type: "troop", is_meta: 0 },
|
||||
{ name: "Royal Recruits", elixir_cost: 7, rarity: "common", type: "troop", is_meta: 0 },
|
||||
|
||||
# ========================
|
||||
# SPELLS
|
||||
# ========================
|
||||
{ name: "Zap", elixir_cost: 2, rarity: "common", type: "spell", is_meta: 1 },
|
||||
{ name: "Giant Snowball", elixir_cost: 2, rarity: "common", type: "spell", is_meta: 0 },
|
||||
{ name: "Arrows", elixir_cost: 3, rarity: "common", type: "spell", is_meta: 0 },
|
||||
{ name: "Royal Delivery", elixir_cost: 3, rarity: "common", type: "spell", is_meta: 0 },
|
||||
|
||||
# ========================
|
||||
# BUILDINGS
|
||||
# ========================
|
||||
{ name: "Cannon", elixir_cost: 3, rarity: "common", type: "building", is_meta: 0 },
|
||||
{ name: "Mortar", elixir_cost: 4, rarity: "common", type: "building", is_meta: 0 },
|
||||
{ name: "Tesla", elixir_cost: 4, rarity: "common", type: "building", is_meta: 0 }
|
||||
].freeze
|
||||
|
||||
CARDS = COMMON_CARDS
|
||||
|
||||
# ВАЛИДАЦИЯ
|
||||
CARDS.each do |c|
|
||||
raise "Missing name" if c[:name].nil? || c[:name].strip.empty?
|
||||
raise "Missing elixir_cost for #{c[:name]}" if c[:elixir_cost].nil?
|
||||
@@ -62,10 +36,13 @@ CARDS.each do |c|
|
||||
raise "Unknown type: #{c[:type]} for #{c[:name]}" unless CARD_TYPES.include?(c[:type])
|
||||
end
|
||||
|
||||
# Проверка на дубликаты
|
||||
names = CARDS.map { |c| c[:name] }
|
||||
duplicates = names.group_by { |name| name }.select { |_k, v| v.size > 1 }.keys
|
||||
raise "Duplicate cards found: #{duplicates.join(', ')}" if duplicates.any?
|
||||
|
||||
|
||||
# ЗАПИСЬ В БАЗУ
|
||||
CARDS.each do |card|
|
||||
repo.create(card)
|
||||
end
|
||||
Reference in New Issue
Block a user