Skip to content

Commit

Permalink
feat: alt.magic
Browse files Browse the repository at this point in the history
  • Loading branch information
Alorel committed Nov 25, 2022
1 parent 26c694e commit 01846c2
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 0 deletions.
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default function (opts) {
}),
prod && iifeWrapPlugin({
vars: [
'AltMagicConsumptionID',
'Array',
'Boolean',
'console',
Expand Down
1 change: 1 addition & 0 deletions src/actions/actions.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import './core/equip-item-action.mjs';
import './core/sell-item-action.mjs';
import './core/switch-equipment-set-action.mjs';
import './start-skill/agility.mjs';
import './start-skill/alt-magic.mjs';
import './start-skill/astrology.mjs';
import './start-skill/cooking.mjs';
import './start-skill/crafting.mjs';
Expand Down
1 change: 1 addition & 0 deletions src/actions/start-skill/agility.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AgilityAction extends SkillAction<{}, Agility> {
/** @inheritDoc */
public override execute(): Observable<void> {
return new Observable(subscriber => {
this.skill.stop();
this.skill.start();
nextComplete(subscriber);
});
Expand Down
118 changes: 118 additions & 0 deletions src/actions/start-skill/alt-magic.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import type {AltMagicSpell, FoodItem, Item, SingleProductArtisanSkillRecipe} from 'melvor';
import {asyncScheduler, Observable, scheduled} from 'rxjs';
import {defineAction} from '../../lib/api.mjs';
import {InternalCategory} from '../../lib/registries/action-registry.mjs';
import {namespace} from '../../manifest.json';

const magic = game.altMagic;

interface Props {
bar?: SingleProductArtisanSkillRecipe;

food?: FoodItem;

item?: Item;

junk?: Item;

recipe: AltMagicSpell;

superGem?: Item;
}

defineAction<Props>({
category: InternalCategory.START_SKILL,
execute: ({bar, food, junk, item, recipe, superGem}) => (
scheduled(
new Observable<void>(subscriber => {
magic.selectSpellOnClick(recipe);
magic.stop();

switch (recipe.specialCost.type) {
case AltMagicConsumptionID.AnyItem:
magic.selectItemOnClick(item!);
break;
case AltMagicConsumptionID.AnyNormalFood:
magic.selectItemOnClick(food!);
break;
case AltMagicConsumptionID.JunkItem:
magic.selectItemOnClick(junk!);
break;
case AltMagicConsumptionID.BarIngredientsWithoutCoal:
case AltMagicConsumptionID.BarIngredientsWithCoal:
magic.selectBarOnClick(bar!);
break;
case AltMagicConsumptionID.AnySuperiorGem:
magic.selectItemOnClick(superGem!);
}

magic.castButtonOnClick();

subscriber.complete();
}),
asyncScheduler
)
),
label: 'Alt Magic',
localID: 'startAltMagic',
media: magic.media,
namespace,
options: [
{
label: 'Spell',
localID: 'recipe',
registry: 'altMagic.actions',
required: true,
type: 'MediaItem',
},
{
label: 'Bar',
localID: 'bar',
mediaFilter: ({category}: SingleProductArtisanSkillRecipe) => category.id === 'melvorD:Bars',
registry: 'smithing.actions',
required: true,
showIf: ({recipe}: Props) => {
const t = recipe?.specialCost.type;

return t === AltMagicConsumptionID.BarIngredientsWithoutCoal
|| t === AltMagicConsumptionID.BarIngredientsWithCoal;
},
type: 'MediaItem',
},
{
label: 'Item',
localID: 'junk',
mediaFilter: ({type}: Item) => type === 'Junk',
registry: 'items',
required: true,
showIf: ({recipe}: Props) => recipe?.specialCost.type === AltMagicConsumptionID.JunkItem,
type: 'MediaItem',
},
{
label: 'Item',
localID: 'item',
registry: 'items',
required: true,
showIf: ({recipe}: Props) => recipe?.specialCost.type === AltMagicConsumptionID.AnyItem,
type: 'MediaItem',
},
{
label: 'Gem',
localID: 'superGem',
mediaFilter: ({type}: Item) => type === 'Superior Gem',
registry: 'items',
required: true,
showIf: ({recipe}: Props) => recipe?.specialCost.type === AltMagicConsumptionID.AnySuperiorGem,
type: 'MediaItem',
},
{
label: 'Food',
localID: 'food',
mediaFilter: ({localID, type}: Item) => type === 'Food' && !localID.endsWith('_Perfect'),
registry: 'items',
required: true,
showIf: ({recipe}: Props) => recipe?.specialCost.type === AltMagicConsumptionID.AnyNormalFood,
type: 'MediaItem',
},
],
});
54 changes: 54 additions & 0 deletions types/melvor/game.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,52 @@ export class ArtisanSkill<T> extends GatheringSkill<T> {
export class SingleProductArtisanSkillRecipe extends CategorizedArtisanRecipe {
}

export enum AltMagicConsumptionID {
AnyItem = -1,
AnyNormalFood = -7,
AnySuperiorGem = -6,
BarIngredientsWithCoal = -3,
BarIngredientsWithoutCoal = -4,
JunkItem = -2,
None = -5,
}

interface RuneRequirement {
item: Item;

quantity: number;
}

export class BaseSpell extends NamespacedObject {
level: number;

requirements: any[];

runesRequired: RuneRequirement[];
}

export class AltMagicSpell extends BaseSpell {
runesRequiredAlt: RuneRequirement[];

specialCost: AltMagicSpecialCost;
}

export interface AltMagicSpecialCost {
quantity: number;

type: AltMagicConsumptionID;
}

export class AltMagic extends CraftingSkill<AltMagicSpell> {
castButtonOnClick(): void;

selectBarOnClick(smithingRecipe: SingleProductArtisanSkillRecipe): void;

selectItemOnClick(item: Item): void;

selectSpellOnClick(spell: AltMagicSpell): void;
}

export const enum EquipSlotType {
Amulet = 'Amulet',
Boots = 'Boots',
Expand Down Expand Up @@ -343,9 +389,11 @@ export class Summoning extends ArtisanSkill<SummoningRecipe> {
}

export class Smithing extends ArtisanSkill<SingleProductArtisanSkillRecipe> {
categories: NamespaceRegistry<SkillCategory>;
}

export class CategorizedArtisanRecipe extends ArtisanSkillRecipe {
category: SkillCategory;
}

export class ArtisanSkillRecipe extends BasicSkillRecipe {
Expand Down Expand Up @@ -376,6 +424,10 @@ export class EquipmentItem extends Item {
validSlots: EquipSlotType[];
}

export class FoodItem extends Item {

}

export class Item extends NamespacedObject {
_media: string;

Expand Down Expand Up @@ -539,6 +591,8 @@ export class Game {

agility: Agility;

altMagic: AltMagic;

astrology: Astrology;

bank: Bank;
Expand Down
1 change: 1 addition & 0 deletions types/melvor/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare const NamespaceRegistry: typeof import('./index').NamespaceRegistry;
declare const NamespacedObject: typeof import('./index').NamespacedObject;
declare const EquipmentItem: typeof import('./index').EquipmentItem;
declare const SkillWithMastery: typeof import('./index').SkillWithMastery;
declare const AltMagicConsumptionID: typeof import('./index').AltMagicConsumptionID;

declare const ctx: import('./index').ModContext;
declare const ui: import('./index').UiContext;
Expand Down

0 comments on commit 01846c2

Please sign in to comment.