Skip to content

Commit

Permalink
Merge pull request #1007 from Bengejd/feature/wcl-innervates-pi
Browse files Browse the repository at this point in the history
Feature/wcl innervates & pi assignments
  • Loading branch information
lologarithm authored Jun 13, 2022
2 parents bf2d235 + 7d8a74c commit cbce2e0
Showing 1 changed file with 107 additions and 9 deletions.
116 changes: 107 additions & 9 deletions ui/raid/import_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,26 @@ class RaidWCLImporter extends Importer {
guild {
name faction {id}
}
table(fightIDs: [${fightID}], endTime: 99999999, dataType: Casts, killType: All, viewBy: Default)
playerDetails: table(fightIDs: [${fightID}], endTime: 99999999, dataType: Casts, killType: All, viewBy: Default)
fights(fightIDs: [${fightID}]) {
startTime, endTime, id, name
}
innervates: table(fightIDs: [${fightID}], dataType:Casts, endTime: 99999999, sourceClass: "Druid", abilityID: 29166),
powerInfusion: table(fightIDs: [${fightID}], dataType:Casts, endTime: 99999999, sourceClass: "Priest", abilityID: 10060)
}
}
}
`;

/*
INNERVATE BUFFS ARE UNUSED RIGHT NOW.
buffs: events(fightIDs: [${fightID}], dataType:Buffs, endTime: 99999999, abilityID: 29166) { data }
*/

const reportData = await this.queryWCL(reportDataQuery, token);

// Process the report data.
const wclData = reportData.data.reportData.report; // TODO: Typings?

const guildData = wclData.guild;
const playerData: wclPlayer[] = wclData.table.data.entries;
const playerData: wclPlayer[] = wclData.playerDetails.data.entries;
const innervateData: wclBuffCastsData[] = wclData.innervates.data.entries;
const powerInfusionData: wclBuffCastsData[] = wclData.powerInfusion.data.entries;

// Set up the general variables we need for import to be successful.
const fight: { startTime: number, endTime: number, id: number, name: string } = wclData.fights[0];
Expand Down Expand Up @@ -372,6 +371,25 @@ class RaidWCLImporter extends Importer {
const mappedPlayers = playerData
.map((wclPlayer) => new WCLSimPlayer(wclPlayer, this.simUI, faction));

const processBuffCastData = (buffCastData: wclBuffCastsData[]): { player: WCLSimPlayer, target: string }[] => {
const playerCasts: { player: WCLSimPlayer, target: string }[] = [];
if (buffCastData.length) {
buffCastData.forEach((cast) => {
const sourcePlayer = mappedPlayers.find((player) => player.name === cast.name);
const targetPlayer = mappedPlayers.find((player) => player.name === cast.targets[0].name);

// Buff bots do not get PI/Innervates.
if (sourcePlayer && targetPlayer && !targetPlayer.isBuffBot) {
playerCasts.push({ player: sourcePlayer, target: targetPlayer.name });
}
});
}
return playerCasts;
}

processBuffCastData(innervateData).forEach((cast) => cast.player.innervateTarget = cast.target);
processBuffCastData(powerInfusionData).forEach((cast) => cast.player.powerInfusionTarget = cast.target);

const wclPlayers: WCLSimPlayer[] = sortByProperty(sortByProperty(mappedPlayers, "type"), "sortPriority");

let raidIndex = 0;
Expand Down Expand Up @@ -545,7 +563,77 @@ class RaidWCLImporter extends Importer {
.map((player) => {
let raidParty = raid.parties.filter((party) => party.players.length < MAX_PARTY_SIZE)[0];
assignPlayerToParty(player, raidParty, true);
});
});

// Insert the innervate / PI buffs into the options for the raid.
wclPlayers
.filter((player) => player.innervateTarget || player.powerInfusionTarget)
.forEach((player) => {

const target: wclSimPlayer | undefined = wclPlayers.find((wclPlayer) => wclPlayer.name === player.innervateTarget || player.name === player.powerInfusionTarget);

if (!target) {
console.warn("Could not find target assignment player");
return;
}

const targetID: number = target.id;
const targetRaidIndex: number | undefined = wclIDtoRaidIndex.get(targetID);

if (!targetRaidIndex) {
console.warn(`Could not find ${target.name} raid index!`);
return;
}

if (player.isBuffBot) {
const playerID: number = player.id;
const playerRaidIndex: number | undefined = wclIDtoRaidIndex.get(playerID);
const buffBot = buffBots.find((buffBot) => buffBot.raidIndex === playerRaidIndex);
if (buffBot) {
if (player.innervateTarget && buffBot.innervateAssignment) {
buffBot.innervateAssignment.targetIndex = targetRaidIndex
} else if (player.powerInfusionTarget && buffBot.powerInfusionAssignment) {
buffBot.powerInfusionAssignment.targetIndex = targetRaidIndex
}
}
return;
}

// Regular players.

const raidParty = raid.parties.filter((party) => party.players.some((raidPlayer) => raidPlayer.name === player.name))[0];

if (!raidParty) {
console.warn("Could not find raiding party for player " + player.name);
return;
}

const raidPlayer = raidParty.players.find((raidPlayer) => raidPlayer.name === player.name);

if (!raidPlayer) {
console.warn("Could not find raid player " + player.name + " in raid party " + raidParty);
return;
}

const playerSpecName = raidPlayer.spec.oneofKind;

// @ts-ignore // TODO: Fix this so we don't have to ignore it.
const raiderSpecOptions = raidPlayer.spec[playerSpecName];

if (!targetRaidIndex) {
console.warn("Could not find raid index for target player " + target.name);
return;
} else if (!raiderSpecOptions) {
console.warn("Could not find raid player spec options for player " + player.name);
return;
}

if (player.innervateTarget) {
raiderSpecOptions.options.innervateTarget.targetIndex = targetRaidIndex
} else if (player.powerInfusionTarget) {
raiderSpecOptions.options.innervateTarget.targetIndex = targetRaidIndex
}
});

wclPlayers
.filter((player) => !player.partyAssigned)
Expand All @@ -555,7 +643,6 @@ class RaidWCLImporter extends Importer {

settings.blessings = makeDefaultBlessings(numPaladins);

this.simUI.clearRaid(TypedEvent.nextEventID());
this.simUI.fromProto(TypedEvent.nextEventID(), settings);
this.simUI.setBuffBots(TypedEvent.nextEventID(), buffBots);

Expand Down Expand Up @@ -585,6 +672,9 @@ class WCLSimPlayer implements wclSimPlayer {
public isBuffBot: boolean = false;
public sortPriority: number = 99;

public innervateTarget: string | undefined;
public powerInfusionTarget: string | undefined;

private simUI: RaidSimUI;
private spec: Spec;
private specType: string;
Expand Down Expand Up @@ -857,6 +947,14 @@ const buffBotNames: Record<string, string> = {
"RestorationShaman": "Resto Shaman",
};

interface wclBuffCastsData {
name: string;
targets: {
name: string;
type: string;
}[];
}

interface wclRateLimitData {
limitPerHour: number,
pointsSpentThisHour: number,
Expand Down

0 comments on commit cbce2e0

Please sign in to comment.