Skip to content
Permalink
Browse files

Merge pull request #659 from Manuel-777/economy-fixes

economy changes fixes
  • Loading branch information...
Manuel-777 committed Oct 26, 2019
2 parents ad0c23e + 7bf7a6f commit f8335dc74e16eaf531212a604d6c7ba80f1626b5
@@ -59,6 +59,7 @@ exports.EVENT_TO_NAME = {
WinEveryCard_20191005: "Win Every Card - Standard",
CompCons_Metagame_Challenge_20191004: "Metagame Challenge 10/19",

Brawl_Launch_20191024: "Brawl Launch",
Precon_Brawl_ELD: "Precon Brawl",
Lore_WAR1_Momir: "Ravnica at War I - Momir",
Lore_WAR2_Pauper: "Ravnica at War II - Pauper",
@@ -120,6 +121,7 @@ exports.EVENT_TO_FORMAT = {
WinEveryCard_20191005: "Standard",
CompCons_Metagame_Challenge_20191004: "Traditional Standard",

Brawl_Launch_20191024: "Brawl",
Precon_Brawl_ELD: "Brawl",
Lore_WAR1_Momir: "Momir",
Lore_WAR2_Pauper: "Pauper",
@@ -19,7 +19,8 @@ import {
onLabelInEventGetPlayerCoursesV2,
onLabelInDeckUpdateDeck,
onLabelInDeckUpdateDeckV3,
onLabelInventoryUpdated,
onLabelInventoryUpdatedV4,
onLabelPostMatchUpdate,
onLabelInPlayerInventoryGetPlayerInventory,
onLabelInPlayerInventoryGetPlayerCardsV3,
onLabelInProgressionGetPlayerProgress,
@@ -328,7 +329,12 @@ function entrySwitch(entry, json) {

case "Inventory.Updated":
json = entry.json();
onLabelInventoryUpdated(entry, json);
onLabelInventoryUpdatedV4(entry, json);
break;

case "PostMatch.Update":
json = entry.json();
onLabelPostMatchUpdate(entry, json);
break;

case "PlayerInventory.GetPlayerInventory":
@@ -849,7 +849,28 @@ function minifiedDelta(delta) {
}

// Called for all "Inventory.Updated" labels
export function onLabelInventoryUpdated(entry, transaction) {
export function onLabelInventoryUpdatedV4(entry, transaction) {
if (!transaction) return;

if (transaction.updates) {
// 2019-10-24 this section handles the log format released in Arena client 1857.738996
transaction.updates.forEach(update => {
const delta = { ...update };
if (update.context && update.context.source) {
// combine sub-context with parent context
delta.subContext = update.context; // preserve sub-context object data
delta.context = transaction.context + "." + update.context.source;
}
onLabelInventoryUpdated(entry, delta);
});
} else if (transaction.delta) {
// 2019-10-24 this section handles the log format prior to Arena client 1857.738996
onLabelInventoryUpdated(entry, transaction);
}
}

// 2019-10-24 DEPRECATED as of Arena client 1857.738996
function onLabelInventoryUpdated(entry, transaction) {
if (!transaction) return;

// Store this in case there are any future date parsing issues
@@ -875,6 +896,89 @@ export function onLabelInventoryUpdated(entry, transaction) {
return;
}

function inventoryUpdate(entry, update) {
// combine sub-context with parent context
let context = "PostMatch.Update";
if (update.context && update.context.source) {
// combine sub-context with parent context
context += "." + update.context.source;
if (update.context.sourceId && update.context.source === "QuestReward") {
context += "." + update.context.sourceId;
}
}
if (update.context && update.context.subSource) {
// combine sub-sub-context with parent context
context += "." + update.context.subSource;
}

// We use the original time string for the ID to ensure parsing does not alter it
// This will make the ID the same if parsing either changes or breaks
let id = sha1(entry.timestamp + context + JSON.stringify(update.delta));

let transaction = {
...update,
timestamp: entry.timestamp,
// Add missing data
date: parseWotcTimeFallback(entry.timestamp),
// Reduce the size for storage
delta: minifiedDelta(update.delta),
context,
subContext: update.context, // preserve sub-context object data
id: id
};

saveEconomyTransaction(transaction);
}

function trackUpdate(entry, trackUpdate) {
if (!trackUpdate) return;
const { trackName, trackTier, trackDiff, orbDiff } = trackUpdate;

if (trackDiff && trackDiff.inventoryUpdates) {
trackDiff.inventoryUpdates.forEach(update => {
const data = {
...update,
trackName,
trackTier
};
data.context.subSource = trackName;
inventoryUpdate(entry, data);
});
}

// For some reason, orbs live separately from all other inventory
if (
orbDiff &&
orbDiff.oldOrbCount &&
orbDiff.currentOrbCount &&
orbDiff.currentOrbCount - orbDiff.oldOrbCount
) {
const data = { trackName, trackTier, orbDiff };
inventoryUpdate(entry, data);
}
}

export function onLabelPostMatchUpdate(entry, json) {
if (!json) return;

json.questUpdate.forEach(quest => {
if (quest.inventoryUpdate) {
inventoryUpdate(entry, quest.inventoryUpdate);
}
});

json.dailyWinUpdates.forEach(update => {
inventoryUpdate(entry, update);
});

json.weeklyWinUpdates.forEach(update => {
inventoryUpdate(entry, update);
});

trackUpdate(entry, json.eppUpdate);
trackUpdate(entry, json.battlePassUpdate);
}

export function onLabelInPlayerInventoryGetPlayerInventory(entry, json) {
if (!json) return;
globals.logTime = parseWotcTimeFallback(entry.timestamp);
@@ -951,7 +1055,7 @@ export function onLabelInProgressionGetPlayerProgress(entry, json) {
globals.store.set("economy", economy);
}

//
// 2019-10-24 DEPRECATED as of Arena client version 1857.738996
export function onLabelTrackProgressUpdated(entry, json) {
if (!json) return;
// console.log(json);
@@ -1,3 +1,4 @@
import _ from "lodash";
import differenceInCalendarDays from "date-fns/differenceInCalendarDays";
import startOfDay from "date-fns/startOfDay";
import compareAsc from "date-fns/compareAsc";
@@ -56,25 +57,25 @@ class economyDay {
// These should match the full text of the event
const economyTransactionContextsMap = {
"Booster.Open": "Booster Open",
"Booster.Open.BoosterOpen": "Booster Open",
"Event.GrantCardPool": "Event Card Pool",
"Event.PayEntry": "Pay Event Entry",
"Event.PayEntry.EventPayEntry": "Pay Event Entry",
"Event.Season.Constructed.Payout": "Constructed Season Rewards",
"Event.Season.Limited.Payout": "Limited Season Rewards",
"PlayerReward.OnMatchCompletedDaily": "Player Rewards",
"PlayerReward.OnMatchCompletedDaily": "Match Rewards: Daily Wins",
PurchasedCosmetic: "Cosmetic Purchase",
"Quest.Completed": "Quest Completed",
"Quest Completed": "Match Rewards: Quest Reward",
Store: "Store Transaction",
"Store.Fulfillment": "Store Transaction",
"Store.Fulfillment.Chest": "Store Transaction",
"Store.Fulfillment.Chest.ProgressionRewards": "Store Transaction",
"Store.Fulfillment.Boosters": "Store Booster Purchase",
"Store.Fulfillment.Gems": "Store Gems Purchase",
"PlayerInventory.RedeemBulkWildcards": "Redeem Wildcard",
"WildCard.Redeem": "Redeem Wildcard",
"Vault.Complete": "Vault Opening",
"PlayerReward.OnMatchCompletedWeekly": "Weekly Rewards",
"PlayerReward.OnMatchCompletedWeekly": "Match Rewards: Weekly Wins",
"PlayerProgression.OrbSpend": "Orb Spend",
"Track.Progress": "Track Progress",
"Track.RewardTier.Updated": "Mastery Pass Purchase"
"Track Progress": "Match Rewards: Level Up",
"Track.RewardTier.Updated": "Mastery Pass Purchase",
"Player Rewards": "Match Rewards",
"Event Prize": "Event Rewards"
};

const trackCodeMap = {
@@ -103,7 +104,17 @@ function localDayDateFormat(date) {
}

function getReadableTrack(trackCode) {
return trackCodeMap[trackCode] || trackCode;
return trackCodeMap[trackCode] || getReadableCode(trackCode);
}

// quick and dirty generic pretty formatting
// "WhyDoesWotc.KeepChanging.Codes" => "Why Does Wotc: Keep Changing: Codes"
function getReadableCode(code) {
let result = "";
code.split(".").forEach(group => {
result += ": " + _.startCase(group);
});
return result.substring(2);
}

function getReadableQuest(questCode) {
@@ -162,26 +173,61 @@ function getPrettyContext(context, full = true) {
if (context.startsWith("Track.Progress")) {
const trackCode = context.substring(15);
return full
? `Track Progress: ${getReadableTrack(trackCode)}`
: "Track Progress";
? `Match Rewards: Level Up: ${getReadableTrack(trackCode)}`
: "Match Rewards";
}

if (context.startsWith("Event.Prize")) {
const eventCode = context.substring(12);
return full ? `Event Prize: ${getReadableEvent(eventCode)}` : "Event Prize";
return full
? `Event Rewards: ${getReadableEvent(eventCode)}`
: "Event Rewards";
}

if (context.endsWith("EventReward")) {
const eventCode = context.split(".")[0];
return full
? `Event Rewards: ${getReadableEvent(eventCode)}`
: "Event Rewards";
}

if (context.startsWith("PostMatch.Update")) {
const rewardCode = context.substring(17);
let readableReward = getReadableCode(rewardCode);
if (rewardCode.startsWith("BattlePassLevelUp")) {
const trackCode = rewardCode.substring(18);
readableReward = "Level Up: " + getReadableTrack(trackCode);
} else if (rewardCode.startsWith("QuestReward")) {
const questCode = rewardCode.substring(12);
readableReward = "Quest Reward: " + getReadableQuest(questCode);
}
return full ? `Match Rewards: ${readableReward}` : "Match Rewards";
}

if (context.startsWith("Quest.Completed")) {
const questCode = context.substring(16);
return full
? `Quest Completed: ${getReadableQuest(questCode)}`
: "Quest Completed";
? `Match Rewards: Quest Reward: ${getReadableQuest(questCode)}`
: "Match Rewards";
}

const pretty = economyTransactionContextsMap[context];
if (context.startsWith("Store.Fulfillment")) {
const storeCode = context.substring(18);
if (!storeCode || !full) {
return "Store Transaction";
}
return `Store Transaction: ${getReadableCode(storeCode)}`;
}

// If there's no valid pretty context, fallback on generic formatting
const pretty =
economyTransactionContextsMap[context] || getReadableCode(context);

if (!full && pretty.includes(":")) {
return pretty.split(":")[0];
}

// If there's no valid pretty context keep the code as is.
return pretty || context;
return pretty;
}

export function openEconomyTab(dataIndex = 25, scrollTop = 0) {
@@ -239,7 +285,7 @@ function renderData(container, index) {

// Track Progress txns are mostly redundant with inventory change txns
// Non-duplicate data (should be) only on txns with level changes
if (selectVal === "Track Progress") {
if (change.context.startsWith("Track.Progress")) {
if (!change.trackDiff) return rowsAdded;
const lvlDelta = Math.abs(
(change.trackDiff.currentLevel || 0) - (change.trackDiff.oldLevel || 0)

0 comments on commit f8335dc

Please sign in to comment.
You can’t perform that action at this time.