Class: RuneterraCards::Cost

Inherits:
Object
  • Object
show all
Defined in:
lib/runeterra_cards/cost.rb

Overview

Represents the cost of a CardSet, as wildcards or shards. To get the cost of a CardSet you need to call Metadata#cost_of, as rarity (and therefore cost) is a property of metadata.

A Cost object tells you how many wildcards would be needed to craft a CardSet, or alternatively how many shards would be needed. You can figure out the cost of a mixture of wildcards and shards by creating a new Cost object representing the wildcards to be spent, and subtracting that from the original Cost object.

Examples:

Getting the shard cost for a CardSet

cost = .cost_of(card_set)
cost.shards #=> 3000

Getting wildcard costs for a CardSet

cost = .cost_of(card_set)
cost.common #=> 3
cost.rare #=> 1
# etc

Getting remaining cost after spending some wildcards

cost = .cost_of(card_set)
cost.dust #=> 11500

wildcards_in_hand = Cost.new(10, 5, 3, 1)
remaining_cost = cost - wildcards_in_hand
remaining_cost.dust #=> 5100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(common, rare, epic, champion) ⇒ Cost

Returns a new instance of Cost.

Parameters:

  • common (Fixnum)
  • rare (Fixnum)
  • epic (Fixnum)
  • champion (Fixnum)


51
52
53
# File 'lib/runeterra_cards/cost.rb', line 51

def initialize(common, rare, epic, champion)
  @common, @rare, @epic, @champion = common, rare, epic, champion
end

Instance Attribute Details

#championFixnum (readonly)

The number of Champion wildcards needed

Returns:

  • (Fixnum)

    count



45
46
47
# File 'lib/runeterra_cards/cost.rb', line 45

def champion
  @champion
end

#commonFixnum (readonly)

The number of Common wildcards needed

Returns:

  • (Fixnum)

    count



33
34
35
# File 'lib/runeterra_cards/cost.rb', line 33

def common
  @common
end

#epicFixnum (readonly)

The number of Epic wildcards needed

Returns:

  • (Fixnum)

    count



41
42
43
# File 'lib/runeterra_cards/cost.rb', line 41

def epic
  @epic
end

#rareFixnum (readonly)

The number of Rare wildcards needed

Returns:

  • (Fixnum)

    count



37
38
39
# File 'lib/runeterra_cards/cost.rb', line 37

def rare
  @rare
end

Instance Method Details

#-(other) ⇒ Cost

Note:

This will not return negative values.

Subtracts another Cost from this one. Subtraction is performed by subtracting each wildcard type individually, not by operating on the shard count. The minimum value any wildcard will have is zero, so 5 - 7 = 0 for example.

Examples:

minuend    = Cost.new(9, 8, 5, 2)
subtrahend = Cost.new(7, 8, 2, 3)
result = minuend - subtrahend
result   #=> Cost.new(2, 0, 3, 0)

Parameters:

Returns:

  • (Cost)

    The remaining cost, with a floor of 0.



86
87
88
89
90
91
92
93
# File 'lib/runeterra_cards/cost.rb', line 86

def -(other)
  Cost.new(
    [common   - other.common,   0].max,
    [rare     - other.rare,     0].max,
    [epic     - other.epic,     0].max,
    [champion - other.champion, 0].max
  )
end

#==(other) ⇒ Boolean

Whether this Cost is equal to another. Equality means exactly the same number of each wildcard, not just the same shard count.

Parameters:

Returns:

  • (Boolean)

    equal?



68
69
70
71
72
73
# File 'lib/runeterra_cards/cost.rb', line 68

def ==(other)
  common.eql?(other.common) &&
    rare.eql?(other.rare) &&
    epic.eql?(other.epic) &&
    champion.eql?(other.champion)
end

#shardsFixnum

The number of shards needed. I.e. the equivalent amount of shards for all these wildcards.

Returns:

  • (Fixnum)

    shards



57
58
59
60
61
62
# File 'lib/runeterra_cards/cost.rb', line 57

def shards
  (common * 100) +
    (rare * 300) +
    (epic * 1200) +
    (champion * 3000)
end