UNPKG

programming-game

Version:

The client for programming game, an mmorpg that you interact with entirely through code.

286 lines (285 loc) 10.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getHandlers = void 0; var types_1 = require("./types"); var utils_1 = require("./utils"); var getHandlers = function (player) { var handlers = { /** * Update the role that you intend to play when grouping with other players. */ setRole: function (role) { return { type: types_1.IntentType.setRole, role: role }; }, /** * Move to and attack a unit. */ attack: function (target) { return { type: types_1.IntentType.attack, target: target.id }; }, /** * Attempt to harvest resources from a tree or mining node. */ harvest: function (target) { return { type: types_1.IntentType.harvest, target: target.id, }; }, /** * Move to the specified position. * @param position {Position} The position to move to. */ move: function (position) { return { type: types_1.IntentType.move, position: position }; }, /** * Respawn a your character after death. * * Respawning will place your character at the nearest respawn point, but you'll lose all your items and equipment. */ respawn: function () { return { type: types_1.IntentType.respawn }; }, /** * Concentrate and restore your mana more quickly than normal. */ summonMana: function () { return { type: types_1.IntentType.summonMana }; }, /** * Attempt to eat an item from your inventory. */ eat: function (item) { return { type: types_1.IntentType.eat, item: item, save: (player.inventory[item] || 0) - 1, }; }, /** * Cast a spell at an optional target. * * Spells require that the appropriate spell stone is equipped in your spellbook AND that you have enough spell slots in your equipment. */ cast: function (spell, target) { return { type: types_1.IntentType.cast, spell: spell, target: target === null || target === void 0 ? void 0 : target.id }; }, /** * Sell items from your inventory to an NPC or player. */ sell: function (opt) { return { type: types_1.IntentType.sellItems, items: (0, utils_1.entries)(opt.items).reduce(function (acc, _a) { var item = _a[0], amount = _a[1]; var until = (player.inventory[item] || 0) - (amount || 0); acc[item] = until; return acc; }, {}), to: opt.to.id, }; }, /** * Buy items from an NPC or player. * * The target unit must have the items available to sell, and listed in their trades. */ buy: function (opts) { return { type: types_1.IntentType.buyItems, items: (0, utils_1.entries)(opts.items).reduce(function (acc, _a) { var item = _a[0], amount = _a[1]; if (!amount) return acc; var until = amount + (player.inventory[item] || 0); if (amount) { acc[item] = until; } return acc; }, {}), from: opts.from.id, }; }, /** * Use an item from your inventory, optionally you can use the item on a target unit instead of yourself. */ use: function (item, target) { return { type: types_1.IntentType.use, item: item, until: (player.inventory[item] || 0) - 1, target: target === null || target === void 0 ? void 0 : target.id, }; }, /** * Announce to the world that you are seeking a party. */ seekParty: function () { return { type: types_1.IntentType.seekParty }; }, /** * Invite the specified player id to join your party. */ inviteToParty: function (playerId) { return { type: types_1.IntentType.inviteToParty, playerId: playerId }; }, /** * Leave your current party. */ leaveParty: function () { return { type: types_1.IntentType.leaveParty }; }, /** * Accept a party invitation from the specified player id. * * This is a noop if the player hasn't invited you to a party. */ acceptPartyInvite: function (playerId) { return { type: types_1.IntentType.acceptPartyInvite, playerId: playerId }; }, /** * Decline a party invitation from the specified player id. */ declinePartyInvite: function (playerId) { return { type: types_1.IntentType.declinePartyInvite, playerId: playerId }; }, /** * Equip a piece of equipment into the specified slot. * * The item must be in your inventory. */ equip: function (item, slot) { return { type: types_1.IntentType.equip, item: item, slot: slot }; }, /** * Return a piece of equipment from your equipment back into your inventory. */ unequip: function (slot) { return { type: types_1.IntentType.unequip, slot: slot }; }, /** * Attempt to craft an item using materials from your inventory. */ craft: function (item, from) { return { type: types_1.IntentType.craft, item: item, from: from }; }, /** * Consumes TP to use a weapon skill on a target. * * Some weapon skills may require additional options. */ useWeaponSkill: function (specifics) { if (specifics.skill === "misdirectingShot") { return { type: types_1.IntentType.weaponSkill, skill: specifics.skill, target: specifics.target.id, options: { to: specifics.target.id, }, }; } return { type: types_1.IntentType.weaponSkill, skill: specifics.skill, target: specifics.target.id, }; }, /** * Drop items from your inventory onto the ground. */ drop: function (_a) { var item = _a.item, amount = _a.amount; return { type: types_1.IntentType.drop, item: item, until: (player.inventory[item] || 0) - amount, }; }, /** * Update the list of items that you are buying an selling as well as their prices. */ setTrade: function (trades) { return { type: types_1.IntentType.setTrade, trades: trades, }; }, /** * Accept a quest from an NPC. */ acceptQuest: function (npc, questId) { return { type: types_1.IntentType.acceptQuest, npcId: npc.id, questId: questId }; }, /** * Remove a quest from your active quests and free up a slot in your quest log. */ abandonQuest: function (questId) { return { type: types_1.IntentType.abandonQuest, questId: questId }; }, /** * Turn in a completed quest to an NPC. */ turnInQuest: function (npc, questId) { return { type: types_1.IntentType.turnInQuest, npcId: npc.id, questId: questId }; }, /** * Withdraw items from a storage NPC to your inventory. * * The specified NPC MUST be a banker. */ withdraw: function (npc, items) { var until = {}; (0, utils_1.entries)(items).forEach(function (_a) { var item = _a[0], _b = _a[1], amount = _b === void 0 ? 0 : _b; var charAmount = player.storage[item] || 0; until[item] = charAmount - amount; }); return { type: types_1.IntentType.withdraw, npcId: npc.id, until: until, }; }, /** * Deposit items from your inventory into a storage NPC. * * The specified NPC MUST be a banker. */ deposit: function (npc, items) { var until = {}; (0, utils_1.entries)(items).forEach(function (_a) { var item = _a[0], _b = _a[1], amount = _b === void 0 ? 0 : _b; var charAmount = player.inventory[item] || 0; until[item] = charAmount - amount; }); return { type: types_1.IntentType.deposit, npcId: npc.id, until: until, }; }, /** * Equips the specified spell stone from your inventory into your spellbook. * * You MUST have an open slot if your spellbook, and the spell stone must be in your inventory. */ equipSpell: function (spell) { return { type: types_1.IntentType.equipSpell, spell: spell, }; }, /** * Unequips the first spell in the player's spellbook, and returns it to your inventory. */ unequipSpell: function () { return { type: types_1.IntentType.unequipSpell, }; }, }; return handlers; }; exports.getHandlers = getHandlers;