Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Add combining and mixing potions #362

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,664 changes: 8,627 additions & 37 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 30 additions & 11 deletions src/engine/action/pipe/item-on-item.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@ import { ActionHook, getActionHooks, questHookFilter, ActionPipe, RunnableHooks


/**
* Defines an item-on-item action hook.
* Defines an item-on-item action hook via object list.
*/
export interface ItemOnItemActionHook extends ActionHook<ItemOnItemAction, itemOnItemActionHandler> {
export interface ItemOnItemActionHookViaList extends ActionHook<ItemOnItemAction, itemOnItemActionHandler> {
// The item pairs being used. Each item can be used on the other, so item order does not matter.
acceptItems: never;
items: { item1: number, item2?: number }[];
}

/**
* Defines an item-on-item action hook via accept function.
*/
export interface ItemOnItemActionHookViaFunc extends ActionHook<ItemOnItemAction, itemOnItemActionHandler> {
acceptItems: (item1: number, item2: number) => boolean;
items: never;
}

export type ItemOnItemActionHook = ItemOnItemActionHookViaList | ItemOnItemActionHookViaFunc;

// Hook Type guards
const isHookViaList = (obj: any): obj is ItemOnItemActionHookViaList => 'items' in obj;
const isHookViaFunc = (obj: any): obj is ItemOnItemActionHookViaFunc => 'acceptItems' in obj;


/**
* The item-on-item action hook handler function to be called when the hook's conditions are met.
Expand Down Expand Up @@ -51,32 +66,36 @@ export interface ItemOnItemAction {
*/
const itemOnItemActionPipe = (player: Player, usedItem: Item, usedSlot: number, usedWidgetId: number,
usedWithItem: Item, usedWithSlot: number, usedWithWidgetId: number): RunnableHooks<ItemOnItemAction> => {
if(player.busy) {
if (player.busy) {
return;
}

// Find all item on item action plugins that match this action
let matchingHooks = getActionHooks<ItemOnItemActionHook>('item_on_item', plugin => {
if(questHookFilter(player, plugin)) {
if (questHookFilter(player, plugin)) {
const used = usedItem.itemId;
const usedWith = usedWithItem.itemId;

return (plugin.items.some(({ item1, item2 }) => {
const items = [ item1, item2 ];
return items.includes(used) && items.includes(usedWith);
}));
if (isHookViaFunc(plugin)) {
return plugin.acceptItems(used, usedWith);
} else if (isHookViaList(plugin)) {
return (plugin.items.some(({ item1, item2 }) => {
const items = [item1, item2];
return items.includes(used) && items.includes(usedWith);
}));
}
}

return false;
});

const questActions = matchingHooks.filter(plugin => plugin.questRequirement !== undefined);

if(questActions.length !== 0) {
if (questActions.length !== 0) {
matchingHooks = questActions;
}

if(matchingHooks.length === 0) {
if (matchingHooks.length === 0) {
player.outgoingPackets.chatboxMessage(
`Unhandled item on item interaction: ${usedItem.itemId} on ${usedWithItem.itemId}`);
return null;
Expand All @@ -95,4 +114,4 @@ const itemOnItemActionPipe = (player: Player, usedItem: Item, usedSlot: number,
/**
* Item-on-item action pipe definition.
*/
export default [ 'item_on_item', itemOnItemActionPipe ] as ActionPipe;
export default ['item_on_item', itemOnItemActionPipe] as ActionPipe;
Loading