Browse Source

Market now highlights offers which differ from the average price

TheSumm 6 years ago
parent
commit
da2762dac3

+ 14
- 9
modules/corelib/ui/uitable.lua View File

@@ -194,7 +194,7 @@ function UITable:removeHeader()
194 194
   end
195 195
 end
196 196
 
197
-function UITable:addRow(data, ref, height)
197
+function UITable:addRow(data, height)
198 198
   if not self.dataSpace then
199 199
     g_logger.error('UITable:addRow - table data space has not been set, cannot add rows.')
200 200
     return
@@ -206,7 +206,6 @@ function UITable:addRow(data, ref, height)
206 206
 
207 207
   local row = g_ui.createWidget(self.rowBaseStyle)
208 208
   row.table = self
209
-  if ref then row.ref = ref end
210 209
   if height then row:setHeight(height) end
211 210
 
212 211
   local rowId = #self.rows + 1
@@ -352,18 +351,24 @@ function UITable:setTableData(tableData)
352 351
   self.dataSpace:applyStyle({ height = self:getHeight()-headerHeight-self:getMarginTop() })
353 352
 end
354 353
 
355
-function UITable:setRowStyle(style)
354
+function UITable:setRowStyle(style, dontUpdate)
356 355
   self.rowBaseStyle = style
357
-  for _, row in pairs(self.rows) do
358
-    row:setStyle(style)
356
+
357
+  if not dontUpdate then
358
+    for _, row in pairs(self.rows) do
359
+      row:setStyle(style)
360
+    end
359 361
   end
360 362
 end
361 363
 
362
-function UITable:setColumnStyle(style)
364
+function UITable:setColumnStyle(style, dontUpdate)
363 365
   self.columBaseStyle = style
364
-  for _, columns in pairs(self.columns) do
365
-    for _, col in pairs(columns) do
366
-      col:setStyle(style)
366
+
367
+  if not dontUpdate then
368
+    for _, columns in pairs(self.columns) do
369
+      for _, col in pairs(columns) do
370
+        col:setStyle(style)
371
+      end
367 372
     end
368 373
   end
369 374
 end

+ 43
- 3
modules/game_market/market.lua View File

@@ -15,7 +15,6 @@
15 15
 
16 16
       * Extend information features
17 17
         - Hover over offers for purchase information (balance after transaction, etc)
18
-        - Display out of trend market offers based on their previous statistics (like cipsoft does)
19 18
   ]]
20 19
 
21 20
 Market = {}
@@ -72,6 +71,7 @@ information = {}
72 71
 currentItems = {}
73 72
 lastCreatedOffer = 0
74 73
 fee = 0
74
+averagePrice = 0
75 75
 
76 76
 loaded = false
77 77
 
@@ -180,7 +180,18 @@ local function addOffer(offer, offerType)
180 180
       {text = price},
181 181
       {text = string.gsub(os.date('%c', timestamp), " ", "  ")}
182 182
     }
183
-    buyOfferTable:addRow(data, id)
183
+
184
+    if offer.warn then
185
+      buyOfferTable:setColumnStyle('OfferTableWarningColumn', true)
186
+    end
187
+
188
+    local row = buyOfferTable:addRow(data)
189
+    row.ref = id
190
+
191
+    if offer.warn then
192
+      row:setTooltip(tr('This offer is 25%% below the average market price'))
193
+      buyOfferTable:setColumnStyle('OfferTableColumn', true)
194
+    end
184 195
   else
185 196
     local data = {
186 197
       {text = player},
@@ -189,7 +200,18 @@ local function addOffer(offer, offerType)
189 200
       {text = price},
190 201
       {text = string.gsub(os.date('%c', timestamp), " ", "  "), sortvalue = timestamp}
191 202
     }
192
-    sellOfferTable:addRow(data, id)
203
+
204
+    if offer.warn then
205
+      sellOfferTable:setColumnStyle('OfferTableWarningColumn', true)
206
+    end
207
+
208
+    local row = sellOfferTable:addRow(data)
209
+    row.ref = id
210
+
211
+    if offer.warn then
212
+      row:setTooltip(tr('This offer is 25%% above the average market price'))
213
+      sellOfferTable:setColumnStyle('OfferTableColumn', true)
214
+    end
193 215
   end
194 216
 
195 217
   buyOfferTable:toggleSorting(false)
@@ -204,12 +226,17 @@ local function mergeOffer(offer)
204 226
   if not offer then
205 227
     return false
206 228
   end
229
+
207 230
   local id = offer:getId()
208 231
   local offerType = offer:getType()
209 232
   local amount = offer:getAmount()
210 233
   local replaced = false
211 234
 
212 235
   if offerType == MarketAction.Buy then
236
+    if averagePrice > 0 then
237
+      offer.warn = offer:getPrice() <= averagePrice - math.floor(averagePrice / 4)
238
+    end
239
+
213 240
     for i = 1, #marketOffers[MarketAction.Buy] do
214 241
       local o = marketOffers[MarketAction.Buy][i]
215 242
       -- replace existing offer
@@ -222,6 +249,10 @@ local function mergeOffer(offer)
222 249
       table.insert(marketOffers[MarketAction.Buy], offer)
223 250
     end
224 251
   else
252
+    if averagePrice > 0 then
253
+      offer.warn = offer:getPrice() >= averagePrice + math.floor(averagePrice / 4)
254
+    end
255
+
225 256
     for i = 1, #marketOffers[MarketAction.Sell] do
226 257
       local o = marketOffers[MarketAction.Sell][i]
227 258
       -- replace existing offer
@@ -285,9 +316,11 @@ local function updateDetails(itemId, descriptions, purchaseStats, saleStats)
285 316
   if table.empty(saleStats) then
286 317
     sellStatsTable:addRow({{text = 'No information'}})
287 318
   else
319
+    local offerAmount = 0
288 320
     local transactions, totalPrice, highestPrice, lowestPrice = 0, 0, 0, 0
289 321
     for _, stat in pairs(saleStats) do
290 322
       if not stat:isNull() then
323
+        offerAmount = offerAmount + 1
291 324
         transactions = transactions + stat:getTransactions()
292 325
         totalPrice = totalPrice + stat:getTotalPrice()
293 326
         local newHigh = stat:getHighestPrice()
@@ -302,6 +335,12 @@ local function updateDetails(itemId, descriptions, purchaseStats, saleStats)
302 335
       end
303 336
     end
304 337
 
338
+    if offerAmount >= 5 and transactions >= 10 then
339
+      averagePrice = math.round(totalPrice / transactions)
340
+    else
341
+      averagePrice = 0
342
+    end
343
+
305 344
     sellStatsTable:addRow({{text = 'Total Transations:'}, {text = transactions}})
306 345
     sellStatsTable:addRow({{text = 'Highest Price:'}, {text = highestPrice}})
307 346
 
@@ -1081,6 +1120,7 @@ function Market.onMarketEnter(depotItems, offers, balance, vocation)
1081 1120
   end
1082 1121
 
1083 1122
   updateBalance(balance)
1123
+  averagePrice = 0
1084 1124
 
1085 1125
   information.totalOffers = offers
1086 1126
   local player = g_game.getLocalPlayer()

+ 3
- 0
modules/game_market/ui/marketoffers/itemoffers.otui View File

@@ -10,6 +10,9 @@ OfferTableColumn < TableColumn
10 10
   color: #cccccc
11 11
   width: 80
12 12
 
13
+OfferTableWarningColumn < OfferTableColumn
14
+  color: #e03d3d
15
+
13 16
 OfferTableHeaderRow < TableHeaderRow
14 17
   font: verdana-11px-monochrome
15 18
   color: #cccccc

Loading…
Cancel
Save