Skip to content

Commit

Permalink
Hide level-locked skills from use skill dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexx committed Apr 8, 2019
1 parent 760cdb4 commit 261df20
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
11 changes: 5 additions & 6 deletions src/client/dialogs/SpamSkillDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Alert, Picker, StyleSheet, Text, TouchableOpacity } from "react-native"
import { Input } from "../controls/Input";
import { BaseInputDialog } from "./BaseInputDialog";

import { getClassSkills, getSkillById, SkillId, spamSkill } from "../../skills/useSkill";
import { getUserSkills, SkillId, spamSkill } from "../../skills/useSkill";
import LastUsedSkillStore from "../../store/LastUsedSkillStore";
import IHabiticaData from "../../userData/IHabiticaData";

Expand All @@ -15,9 +15,9 @@ interface ISpamSkillDialogProps {
}

interface ISpamSkillDialogState {
skillOptions: Array<{ id: string, name: string }>;
skillInput?: SkillId | "placeholder";
usesInput?: string;
skillOptions: Array<{ id: string, name: string }>;
doneLoading?: boolean;
isResolvedMessage?: string;
}
Expand All @@ -37,7 +37,7 @@ export class SpamSkillDialog extends Component<ISpamSkillDialogProps, ISpamSkill
LastUsedSkillStore.clear();
} else {
newState.skillInput = await LastUsedSkillStore.get() || "placeholder";
const classSkills = getClassSkills(userData.stats.class);
const classSkills = getUserSkills(userData);
if (newState.skillInput === "placeholder") {
newState.skillOptions = this.state.skillOptions.concat(classSkills);
} else {
Expand Down Expand Up @@ -114,9 +114,8 @@ export class SpamSkillDialog extends Component<ISpamSkillDialogProps, ISpamSkill
}

this.setState({ doneLoading: false });
const skill = getSkillById(skillInput);
this.setState({ doneLoading: true, isResolvedMessage: await spamSkill(skill.id, count) });
LastUsedSkillStore.set(skill.id);
this.setState({ doneLoading: true, isResolvedMessage: await spamSkill(skillInput, count) });
LastUsedSkillStore.set(skillInput);
}
}

Expand Down
53 changes: 25 additions & 28 deletions src/skills/useSkill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { callHabApi } from "../requests/HabiticaRequest";
import { HabiticaClass } from "../userData/IHabiticaData";
import IHabiticaData, { HabiticaClass } from "../userData/IHabiticaData";
import { getUserData } from "../userData/userData";


Expand All @@ -15,18 +15,18 @@ function callSkillApi(skill: SkillId, habitId: string): Promise<any> {
* @param count The number of times to perform the skill. Will run until out of mana if set to -1, which is the default.
*/
export async function spamSkill(skillId: SkillId, count = -1): Promise<any> {
const skill = getSkillById(skillId);
const skill = skills.find(sk => sk.id === skillId)!;
let habitId = "";
if (skill.habit !== "none") {
const habits = (await getUserData()).tasks.habits.sort((a: any, b: any) => a.value - b.value);
habitId = skill.habit === "lowest" ? habits[0].id : habits[habits.length - 1].id;
}

return new Promise<string | undefined> (async (resolve) => {
return new Promise<string> (async (resolve) => {
let i = 0;
let run = true;
while ((count === -1 || i < count) && run) {
await callSkillApi(skillId, habitId).catch(e => {
await callSkillApi(skill.id, habitId).catch(e => {
let customMessage = "";
if (e.message === "Not enough mana.") {
customMessage = i > 0
Expand Down Expand Up @@ -64,36 +64,33 @@ export type SkillId =
"brightness" |
"healAll";

export interface ISkill {
interface ISkill {
id: SkillId;
name: string;
habit: "lowest" | "highest" | "none";
class: HabiticaClass;
unlockLevel: 11 | 12 | 13 | 14;
}

export const skills: ISkill[] = [
{ id: "fireball", name: "Burst of Flames", habit: "highest", class: "wizard" },
{ id: "mpheal", name: "Ethereal Surge", habit: "none", class: "wizard" },
{ id: "earth", name: "Earthquake", habit: "none", class: "wizard" },
{ id: "frost", name: "Chilling Frost", habit: "none", class: "wizard" },
{ id: "smash", name: "Brutal Smash", habit: "lowest", class: "warrior" },
{ id: "defensiveStance", name: "Defensive Stance", habit: "none", class: "warrior" },
{ id: "valorousPresence", name: "Valorous Presence", habit: "none", class: "warrior" },
{ id: "intimidate", name: "Intimidating Gaze", habit: "none", class: "warrior" },
{ id: "pickPocket", name: "Pickpocket", habit: "highest", class: "rogue" },
{ id: "backStab", name: "Backstab", habit: "highest", class: "rogue" },
{ id: "toolsOfTrade", name: "Tools of the Trade", habit: "none", class: "rogue" },
{ id: "stealth", name: "Stealth", habit: "none", class: "rogue" },
{ id: "heal", name: "Healing Light", habit: "none", class: "healer" },
{ id: "protectAura", name: "Protective Aura", habit: "none", class: "healer" },
{ id: "brightness", name: "Searing Brightness", habit: "none", class: "healer" },
{ id: "healAll", name: "Blessing", habit: "none", class: "healer" },
const skills: ISkill[] = [
{ id: "fireball", name: "Burst of Flames", habit: "highest", class: "wizard", unlockLevel: 11 },
{ id: "mpheal", name: "Ethereal Surge", habit: "none", class: "wizard", unlockLevel: 12 },
{ id: "earth", name: "Earthquake", habit: "none", class: "wizard", unlockLevel: 13 },
{ id: "frost", name: "Chilling Frost", habit: "none", class: "wizard", unlockLevel: 14 },
{ id: "smash", name: "Brutal Smash", habit: "lowest", class: "warrior", unlockLevel: 11 },
{ id: "defensiveStance", name: "Defensive Stance", habit: "none", class: "warrior", unlockLevel: 12 },
{ id: "valorousPresence", name: "Valorous Presence", habit: "none", class: "warrior", unlockLevel: 13 },
{ id: "intimidate", name: "Intimidating Gaze", habit: "none", class: "warrior", unlockLevel: 14 },
{ id: "pickPocket", name: "Pickpocket", habit: "highest", class: "rogue", unlockLevel: 11 },
{ id: "backStab", name: "Backstab", habit: "highest", class: "rogue", unlockLevel: 12 },
{ id: "toolsOfTrade", name: "Tools of the Trade", habit: "none", class: "rogue", unlockLevel: 13 },
{ id: "stealth", name: "Stealth", habit: "none", class: "rogue", unlockLevel: 14 },
{ id: "heal", name: "Healing Light", habit: "none", class: "healer", unlockLevel: 11 },
{ id: "brightness", name: "Searing Brightness", habit: "none", class: "healer", unlockLevel: 12 },
{ id: "protectAura", name: "Protective Aura", habit: "none", class: "healer", unlockLevel: 13 },
{ id: "healAll", name: "Blessing", habit: "none", class: "healer", unlockLevel: 14 },
];

export function getSkillById(skillId: SkillId): ISkill {
return skills.find(skill => skill.id === skillId)!;
}

export function getClassSkills(habiticaClass: HabiticaClass): ISkill[] {
return skills.filter(skill => skill.class === habiticaClass);
export function getUserSkills(userData: IHabiticaData): ISkill[] {
return skills.filter(skill => skill.class === userData.stats.class && skill.unlockLevel <= userData.stats.lvl);
}

0 comments on commit 261df20

Please sign in to comment.