Skip to content

Commit beea296

Browse files
committed
feat: Start combat actions
1 parent 64a7e93 commit beea296

File tree

7 files changed

+129
-8
lines changed

7 files changed

+129
-8
lines changed

rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ function mkIifeWrap() {
102102
vars: [
103103
'AltMagicConsumptionID',
104104
'Array',
105+
'AttackTypeID',
105106
'Bank',
106107
'Boolean',
107108
'cdnMedia',
109+
'CombatManager',
108110
'console',
109111
'document',
110112
'Error',

src/actions/combat/activate-spell-actions.mts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ const mkAction = ({media, registry, ...init}: Init) => {
5050
return out;
5151
};
5252

53-
/* eslint-disable no-new */
54-
5553
mkAction({
5654
label: 'Cast Standard spell',
5755
localID: 'castStdSpell',

src/actions/combat/index.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ import '../../option-types/option-types.mjs';
22
import './activate-prayer-action.mjs';
33
import './activate-spell-actions.mjs';
44
import './set-attack-style-action.mjs';
5+
import './start-combat-actions.mjs';
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import type {CombatArea, Dungeon, Game, NamespaceRegistry} from 'melvor';
2+
import type {TypedKeys} from 'mod-util/typed-keys';
3+
import {InternalCategory} from '../../lib/registries/action-registry.mjs';
4+
import {EMPTY_ARR} from '../../lib/util.mjs';
5+
import {defineLocalAction} from '../../lib/util/define-local.mjs';
6+
import type {ActionNodeDefinition, NodeOption} from '../../public_api';
7+
8+
interface Props {
9+
area: CombatArea;
10+
11+
/** Index in the area's monsters array */
12+
mob?: number;
13+
}
14+
15+
interface Init extends Omit<ActionNodeDefinition<Props>, 'namespace' | 'category' | 'options' | 'execContext'> {
16+
extraOpts?: NodeOption[];
17+
18+
optionLabel: string;
19+
20+
registry: TypedKeys<Game, NamespaceRegistry<CombatArea>>;
21+
}
22+
23+
type This = ReturnType<typeof mkAction>;
24+
25+
function execMob(this: This, {area, mob}: Props) {
26+
game.stopActiveAction();
27+
game.combat.selectMonster(area.monsters[mob!], area);
28+
}
29+
30+
const mkAction = ({extraOpts, registry, optionLabel, ...init}: Init) => {
31+
const def: Pick<ActionNodeDefinition<Props>, 'category' | 'options'> = {
32+
category: InternalCategory.COMBAT,
33+
options: [
34+
{
35+
label: optionLabel,
36+
localID: 'area',
37+
registry,
38+
required: true,
39+
type: 'MediaItem',
40+
},
41+
...(extraOpts || []),
42+
],
43+
};
44+
45+
const out = {
46+
...def,
47+
...init,
48+
} as const;
49+
50+
defineLocalAction(out);
51+
52+
return out;
53+
};
54+
55+
const areaMobOption: [NodeOption] = [{
56+
getAltCostItems: (area: CombatArea) => area.monsters as any[] || EMPTY_ARR,
57+
label: 'Monster',
58+
localID: 'mob',
59+
recipeOption: 'area',
60+
required: true,
61+
showIf: ({area}: Props) => Boolean(area),
62+
type: 'AltRecipeCost',
63+
}];
64+
65+
mkAction({
66+
execute: execMob,
67+
extraOpts: areaMobOption,
68+
label: 'Start Combat Area',
69+
localID: 'startCombatStd',
70+
media: game.combat.media,
71+
optionLabel: 'Area',
72+
registry: 'combatAreas',
73+
});
74+
75+
mkAction({
76+
execute: execMob,
77+
extraOpts: areaMobOption,
78+
label: 'Start Slayer Area',
79+
localID: 'startCombatSlayer',
80+
media: game.slayer.media,
81+
optionLabel: 'Area',
82+
registry: 'slayerAreas',
83+
});
84+
85+
mkAction({
86+
execute({area}) {
87+
game.stopActiveAction();
88+
game.combat.selectDungeon(area as Dungeon);
89+
},
90+
label: 'Start Dungeon',
91+
localID: 'startCombatDung',
92+
media: cdnMedia('assets/media/skills/combat/dungeon.svg'),
93+
optionLabel: 'Dungeon',
94+
registry: 'dungeons',
95+
});

types/melvor/game/combat.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ export class CombatSkill extends Skill {
3030

3131
}
3232

33+
export class CombatArea extends NamespacedObject {
34+
monsters: Monster[];
35+
get media(): string;
36+
}
37+
38+
export class SlayerArea extends CombatArea {
39+
40+
}
41+
42+
export class Dungeon extends CombatArea {
43+
44+
}
45+
3346
export class Enemy extends Character {
3447
attackType: Exclude<keyof typeof AttackTypeID, 'random' | 'unset'>;
3548

types/melvor/game/core.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ActivePrayer, CombatSpell, SpecialAttack} from 'melvor';
1+
import {ActivePrayer, CombatArea, CombatSpell, Dungeon, SlayerArea, SpecialAttack} from 'melvor';
22
import type {Monster} from './combat';
33
import {Attack, AttackStyle} from './combat';
44
import type {EquipmentItem, Item} from './item';
@@ -148,6 +148,7 @@ export interface Namespace {
148148
}
149149

150150
export class Game {
151+
151152
activeAction?: Skill;
152153

153154
agility: Agility;
@@ -170,6 +171,8 @@ export class Game {
170171

171172
combat: CombatManager;
172173

174+
combatAreas: NamespaceRegistry<CombatArea>;
175+
173176
cooking: Cooking;
174177

175178
crafting: Crafting;
@@ -178,6 +181,8 @@ export class Game {
178181

179182
curseSpells: NamespaceRegistry<CombatSpell>;
180183

184+
dungeons: NamespaceRegistry<Dungeon>;
185+
181186
emptyEquipmentItem: EquipmentItem;
182187

183188
firemaking: Firemaking;
@@ -212,6 +217,10 @@ export class Game {
212217

213218
skills: NamespaceRegistry<Skill>;
214219

220+
slayer: Skill;
221+
222+
slayerAreas: NamespaceRegistry<SlayerArea>;
223+
215224
slayerCoins: SlayerCoins;
216225

217226
smithing: Smithing;

types/melvor/game/misc.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
import {Enemy} from 'melvor/game/combat';
1+
import {CombatArea, Dungeon, Enemy, Monster} from 'melvor/game/combat';
22
import type {NamespaceRegistry} from './core';
33
import type {Item, PotionItem} from './item';
44
import type {Skill} from './skilling';
55
import type {Player} from './toon';
66

77
export class CombatManager {
8-
isActive: boolean;
98

109
enemy: Enemy;
1110

11+
isActive: boolean;
12+
1213
player: Player;
1314

15+
get media(): string;
16+
17+
selectMonster(monster: Monster, area: CombatArea): void;
18+
selectDungeon(dungeon: Dungeon): void;
19+
1420
spawnEnemy(): void;
1521
}
1622

@@ -54,8 +60,6 @@ export interface Requirement {
5460
[k: string]: any;
5561
}
5662

57-
58-
5963
export class Page extends NamespacedObject {
6064
canBeDefault: boolean;
6165

@@ -68,7 +72,6 @@ export class Page extends NamespacedObject {
6872
get media(): string;
6973
}
7074

71-
7275
export class ShopPurchase extends NamespacedObject {
7376
public allowQuantityPurchase: boolean;
7477

0 commit comments

Comments
 (0)