Skip to content

Commit

Permalink
Improve wealth breakdown
Browse files Browse the repository at this point in the history
  • Loading branch information
axelberardino committed Aug 11, 2019
1 parent 706e98d commit fb3ce5d
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 14 deletions.
1 change: 0 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ go get -u github.com/gin-gonic/gin

TODO
More rigourous item description generation
Wealth improvements
Shop id for the link after shop generation
Don't hardcode account passwords!
2 changes: 1 addition & 1 deletion data/template/parts/helpers.js.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
imgThumbnail.src = 'https://web.poecdn.com/image/Art/2DItems/Currency/CurrencyAddModToRare.png?scale=1&w=1&h=1&v=1745ebafbd533b6f91bccf588ab5efc5'
break;
}
txtThumbnail.innerHTML = 'x' + words[1];
txtThumbnail.innerHTML = '<small>x</small>' + words[1];
}
}

Expand Down
2 changes: 1 addition & 1 deletion data/template/parts/item.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
data-desc="{{ template "itemtext" $item }}"
onclick="openModal('item-{{ .Id }}', '{{ .Name }}', '{{ .Type }}')">
<div id="item-{{ .Id }}-currency" class="item-price" style="display: none;">
<img id="item-{{ .Id }}-currency-img" src="" />
<img id="item-{{ .Id }}-currency-img" class="thumbnail" src="" />
<span id="item-{{ .Id }}-currency-span">xx</span>
</div>
<div class="socketPopups"></div>
Expand Down
26 changes: 25 additions & 1 deletion data/template/parts/style.css.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,10 @@
position: absolute;
bottom: 0px;
left: 0px;
size: 5px;
display: inline-block;
}
.thumbnail {
size: 5px;
width: 20px;
height: 20px;
}
Expand All @@ -368,5 +370,27 @@
.sockets {
z-index: 3;
}
#wealth {
font-family: "FontinSmallCaps",Verdana,Arial,Helvetica,sans-serif;
background-color: black;
border: 1px solid #3a2317;
padding: 10px;
max-width: 600px;
white-space: nowrap;
margin: 0;
}
.thumbnail:before,
.thumbnail_before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
#wealth .thumbnail {
top: 1px;
}
img {
vertical-align: middle;
}
</style>
{{ end }}
10 changes: 8 additions & 2 deletions data/template/profile.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{{ define "profile" }}
{{ template "header" }}

<div><b>Wealth:</b> {{ .Wealth }} </div>
<div id="wealth">
<b>Estimated wealth:</b><img class="thumbnail" src="https://web.poecdn.com/image/Art/2DItems/Currency/CurrencyRerollRare.png?scale=1&amp;w=1&amp;h=1&amp;v=c60aa876dd6bab31174df91b1da1b4f9"><small>x</small>{{ .Wealth.EstimatedChaos }} (with
<img class="thumbnail" src="https://web.poecdn.com/image/Art/2DItems/Currency/CurrencyAddModToRare.png?scale=1&w=1&h=1&v=1745ebafbd533b6f91bccf588ab5efc5"><small>x</small>{{ .Wealth.NbExa }}
<img class="thumbnail" src="https://web.poecdn.com/image/Art/2DItems/Currency/CurrencyRerollRare.png?scale=1&amp;w=1&amp;h=1&amp;v=c60aa876dd6bab31174df91b1da1b4f9"><small>x</small>{{ .Wealth.NbChaos }}
<img class="thumbnail" src="https://web.poecdn.com/image/Art/2DItems/Currency/CurrencyUpgradeToRare.png?scale=1&w=1&h=1&v=89c110be97333995522c7b2c29cae728"><small>x</small>{{ .Wealth.NbAlch }}
)
</div>
<div id="shop" class="box">
<button class="button" onclick="generateShop()">Generate items shop</button>
<button class="button" onclick="exportShop()">Export shop</button>
Expand All @@ -12,7 +18,7 @@
</span>
</label>
<span id="merge-box">
<input type="checkbox" id="merge" name="merge" checked="checked" onclick="onMergeChange()">
<input type="checkbox" id="merge" name="merge" checked="checked" onclick="onMergeChange(this)">
<label for="merge">Merge</label>
</span>
<select id="highlight" class="dropdown" onchange="highlightItems(this.value)">
Expand Down
43 changes: 37 additions & 6 deletions inventory/wealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,47 @@ func getCount(properties []ItemProperty) int {
return 0
}

// WealthBreakdown holds total wealth and its details.
type WealthBreakdown struct {
EstimatedChaos int
NbAlch int
NbChaos int
NbExa int
}

// ComputeWealth computes the wealth in chaos orbs contained in a stash.
func ComputeWealth(stashTabs []*StashTab) int {
var chaos float64
func ComputeWealth(stashTabs []*StashTab, characters []*CharacterInventory) WealthBreakdown {
var wealth WealthBreakdown
var estimate float64

compute := func(item *Item) {
nb := getCount(item.Properties)
switch item.Type {
case "Orb of Alchemy":
wealth.NbAlch += nb
case "Chaos Orb":
wealth.NbChaos += nb
case "Exalted Orb":
wealth.NbExa += nb
}
if value, ok := CurrencyExchangeRate[item.Type]; ok {
estimate += float64(nb) * value
}
}

// Get currencies in stash.
for _, tab := range stashTabs {
for _, item := range tab.Items {
if value, ok := CurrencyExchangeRate[item.Type]; ok {
chaos += float64(getCount(item.Properties)) * value
}
compute(&item)
}
}
// Get currencies in inventories.
for _, character := range characters {
for _, item := range character.Items {
compute(item)
}
}

return int(chaos)
wealth.EstimatedChaos = int(estimate)
return wealth
}
4 changes: 2 additions & 2 deletions scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type ScrapedData struct {
Characters []*inventory.CharacterInventory
Skills []*inventory.CharacterSkills
Stash []*inventory.StashTab
Wealth int
Wealth inventory.WealthBreakdown
}

// NewScraper returns a configured scraper.
Expand Down Expand Up @@ -159,7 +159,7 @@ func (s *Scraper) ScrapEverything() (*ScrapedData, error) {
return nil, errStash
}
data.Stash = stash
data.Wealth = inventory.ComputeWealth(data.Stash)
data.Wealth = inventory.ComputeWealth(data.Stash, data.Characters)

return data, nil
}

0 comments on commit fb3ce5d

Please sign in to comment.