-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ccf4bbc
Showing
41 changed files
with
3,397 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
|
||
const { createCanvas } = require("canvas"); | ||
const Discord = require("discord.js"); | ||
const { readdirSync } = require("fs"); | ||
const { DiscordInstance } = require("../utils/boilerplate/Discord_Boilerplate"); | ||
const { workingDir } = require("../utils/helpers"); | ||
const { TownRegistry } = require("../utils/registers"); | ||
/** | ||
* | ||
* @param {Discord.Interaction} interaction | ||
* @param {DiscordInstance} discordInstance | ||
*/ | ||
|
||
module.exports = async function (interaction, discordInstance) { | ||
const townRegistry = discordInstance.fetchFromCache("townRegistry")().TownRegistry; | ||
if (interaction.options.getSubcommand() === "property_list") { | ||
let towns = readdirSync(workingDir() + "/" + TownRegistry.table).map(v => { | ||
const townName = v.replace(".town", ""); | ||
const npcRegistry = discordInstance.fetchFromCache("npcRegistry")(); | ||
if (townName == "") { | ||
interaction.editReply("This town does not exist."); | ||
return; | ||
} | ||
const currentTown = townRegistry.get(townName) | ||
if (currentTown == undefined) { | ||
interaction.editReply("This town does not exist."); | ||
return; | ||
} | ||
const currentTownInfo = currentTown.getData(); | ||
const houseArray = currentTownInfo.houseArray; | ||
const homesLeft = houseArray.filter((value) => value.owner == null); | ||
const occupied = houseArray.filter((value) => value.owner != null); | ||
const message = | ||
`town: ${townName} | ||
inhabitants: ${(houseArray.length - homesLeft.length)} | ||
homes left: ${homesLeft.length + | ||
((occupied.length == 0) ? "" : occupied.map(value => { | ||
return ( | ||
`\nproperty ID: ${value.id} | ||
owned by: ${(typeof value.owner === typeof 0) ? | ||
`${npcRegistry.getFromID(value.owner)["name"]} | ||
type: ${npcRegistry.getFromID(value.owner)["type"]}` | ||
: discordInstance.getClient().users.cache.get(value.owner).username}`) | ||
})) | ||
} | ||
` | ||
return message; | ||
}) | ||
interaction.editReply({ content: towns.join("\n") }) | ||
return; | ||
} | ||
const textureAtlas = discordInstance.fetchFromCache("textureAtlas")(); | ||
const npcRegistry = discordInstance.fetchFromCache("npcRegistry")(); | ||
if(interaction.options.getSubcommand() === "buy_property"){ | ||
|
||
const townName = interaction.options.getString("town"); | ||
|
||
const currentTown = townRegistry.get(townName) | ||
if(currentTown == undefined){ | ||
interaction.editReply("town "+townName+" does not exist."); | ||
return; | ||
} | ||
|
||
const canvas = createCanvas(540, 540); | ||
const ctx = canvas.getContext("2d"); | ||
ctx.font = "10px Morris Roman"; | ||
|
||
const townImg = textureAtlas.getPrecachedTexture(currentTown.townName).texture; | ||
const houseAvailable = textureAtlas.getPrecachedTexture("town_icon_house_available").texture; | ||
const houseYouOwn = textureAtlas.getPrecachedTexture("town_icon_house_player_owned").texture; | ||
const houseOccupied = textureAtlas.getPrecachedTexture("town_icon_house_occuplied").texture; | ||
const houseShop = textureAtlas.getPrecachedTexture("town_icon_shop").texture; | ||
|
||
ctx.drawImage(townImg, 0, 0); | ||
for (let info of currentTown.getData().houseArray) { | ||
if (info.owner == null) { | ||
ctx.drawImage(houseAvailable, info.x, info.y, 30, 30); | ||
ctx.fillText( | ||
"available", | ||
info.x + 10 - "available".length, | ||
info.y + -5 | ||
); | ||
ctx.fillText( | ||
"ID: " + info.id.toString(), | ||
info.x + 10 - ("ID: " + info.id.toString()).length, | ||
info.y + 45 | ||
); | ||
} else if (info.owner == interaction.user.id) { | ||
ctx.drawImage(houseYouOwn, info.x, info.y, 30, 30); | ||
ctx.fillText( | ||
interaction.user.username, | ||
info.x - interaction.user.username.length, | ||
info.y + -5 | ||
); | ||
ctx.fillText( | ||
"ID: " + info.id.toString(), | ||
info.x + 10 - ("ID: " + info.id.toString()).length, | ||
info.y + 45 | ||
); | ||
} else { | ||
let clientUsername; | ||
if (typeof info.owner == typeof "") { | ||
clientUsername = (discordInstance.getClient().users.cache.get(info.owner)).username; | ||
ctx.drawImage(houseOccupied, info.x, info.y, 30, 30); | ||
} else { | ||
//console.log(info.owner) | ||
let ThisNPC = npcRegistry.getFromID(info.owner); | ||
if(ThisNPC){ | ||
clientUsername = ThisNPC.name; | ||
if (ThisNPC.type == "shopkeeper") { | ||
ctx.drawImage(houseShop, info.x, info.y, 30, 30); | ||
} else { | ||
ctx.drawImage(houseOccupied, info.x, info.y, 30, 30); | ||
} | ||
} else { | ||
clientUsername = "ERROR"; | ||
ctx.drawImage(textureAtlas.getPrecachedTexture("ERROR"), info.x, info.y, 30, 30); | ||
} | ||
} | ||
|
||
ctx.fillText( | ||
clientUsername, | ||
info.x - clientUsername.length, | ||
info.y + -5 | ||
); | ||
ctx.fillText( | ||
"ID: " + info.id.toString(), | ||
info.x + 10 - ("ID: " + info.id.toString()).length, | ||
info.y + 45 | ||
); | ||
} | ||
} | ||
|
||
const attachment = new Discord.AttachmentBuilder(); | ||
attachment.setFile((canvas.toBuffer())); | ||
attachment.setName(townName+".png"); | ||
interaction.editReply({files:[attachment]}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const { TextInputStyle } = require("discord.js"); | ||
const Discord = require("discord.js"); | ||
const { readdirSync } = require("fs"); | ||
const { DiscordInstance } = require("../utils/boilerplate/Discord_Boilerplate"); | ||
const { Player } = require("../utils/datainstancer"); | ||
const { workingDir } = require("../utils/helpers"); | ||
const { TownRegistry } = require("../utils/registers"); | ||
const TownGenerator = require("../utils/towngenerator"); | ||
/** | ||
* | ||
* @param {Discord.CommandInteraction} interaction | ||
* @param {DiscordInstance} discordInstance | ||
*/ | ||
|
||
module.exports = async function(interaction,discordInstance){ | ||
if (!interaction.isCommand()) return; | ||
|
||
let plr = new Player(interaction.user.id); | ||
|
||
if(interaction.options.getSubcommand() === "create"){ | ||
if(plr.getData().characters >= plr.getData().maxCharacter) return interaction.reply("You already have the max amount of characters") | ||
const modal = new Discord.ModalBuilder() | ||
.setCustomId('myModal') | ||
.setTitle('Create your character!'); | ||
|
||
const characterNameInput = new Discord.TextInputBuilder() | ||
.setCustomId('characterNameInput') | ||
.setMinLength(3) | ||
.setMaxLength(28) | ||
// The label is the prompt the user sees for this input | ||
.setLabel("What's your character's name") | ||
// Short means only a single line of text | ||
.setStyle(TextInputStyle.Short); | ||
|
||
const firstActionRow = new Discord.ActionRowBuilder().addComponents(characterNameInput); | ||
|
||
const characterDescriptionInput = new Discord.TextInputBuilder() | ||
.setCustomId('characterDescriptionInput') | ||
.setLabel("A short description of your character.") | ||
.setMaxLength(255) | ||
// Paragraph means multiple lines of text. | ||
.setStyle(TextInputStyle.Paragraph); | ||
|
||
const secondActionRow = new Discord.ActionRowBuilder().addComponents(characterDescriptionInput); | ||
|
||
modal.addComponents(firstActionRow, secondActionRow); | ||
|
||
await interaction.showModal(modal); | ||
discordInstance.fetchFromCache("characterCreationCache")[interaction.user.id] = {stage:0, name:"", description: "", race: null, gender: null, class: null, location: null}; | ||
} | ||
|
||
if(interaction.options.getSubcommand() === "list") { | ||
if(plr.playerCharacters.CharacterRegistry.getRegistry().length == 0) return interaction.reply("You don't have any characters") | ||
|
||
let characterIterator = Object.entries(plr.playerCharacters.CharacterRegistry.getRegistry()).map(([key,characterI])=>{ | ||
const character = characterI.getData(); | ||
return {name:key, value: ` | ||
ID: ${character.characterID} | ||
Character: ${character.name} | ||
Description: ${character.description} | ||
Class: ${character.class} | ||
Race: ${character.race} | ||
Gender: ${character.gender} | ||
Gold: ${character.gold} | ||
`} | ||
}); | ||
|
||
const exampleEmbed = new Discord.EmbedBuilder() | ||
.setTitle("Your Characters") | ||
.setAuthor({ name: interaction.user.username, iconURL: interaction.user.avatarURL() }) | ||
.setDescription('This shows you all your characters in a list.') | ||
.addFields(...characterIterator) | ||
|
||
interaction.reply({embeds:[exampleEmbed]}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const Discord = require("discord.js"); | ||
const { readdirSync } = require("fs"); | ||
const { DiscordInstance } = require("../utils/boilerplate/Discord_Boilerplate"); | ||
const { workingDir } = require("../utils/helpers"); | ||
const { TownRegistry } = require("../utils/registers"); | ||
const TownGenerator = require("../utils/towngenerator"); | ||
/** | ||
* | ||
* @param {Discord.CommandInteraction} interaction | ||
* @param {DiscordInstance} discordInstance | ||
*/ | ||
|
||
module.exports = async function(interaction,discordInstance){ | ||
if (!interaction.isCommand()) return; | ||
if(interaction.user.id !== "105357779807535104") return interaction.reply("You do not have permission to generate towns.") | ||
await interaction.deferReply(); | ||
|
||
const npcRegistry = discordInstance.fetchFromCache("npcRegistry")(); | ||
const townRegistry = discordInstance.fetchFromCache("townRegistry")(); | ||
const itemRegistry = discordInstance.fetchFromCache("itemRegistry")(); | ||
const textureAtlas = discordInstance.fetchFromCache("textureAtlas")(); | ||
|
||
if(interaction.options.getSubcommand() === "generate_town"){ | ||
const townGenerator = new TownGenerator(); | ||
townGenerator.generateTown(npcRegistry, textureAtlas, itemRegistry,townRegistry).then(obj=>{ | ||
const attachment = new Discord.AttachmentBuilder(); | ||
attachment.setFile((obj.canvas.toBuffer())); | ||
attachment.setName(obj.name+".png"); | ||
interaction.editReply({files:[attachment]}); | ||
}); | ||
} | ||
|
||
if(interaction.options.getSubcommand() === "regenerate_town_map"){ | ||
const townName = interaction.options.getString("town"); | ||
|
||
if(townName == "") { | ||
interaction.editReply("This town does not exist."); | ||
return; | ||
} | ||
const townRegistry = discordInstance.fetchFromCache("townRegistry")().TownRegistry; | ||
const currentTown = townRegistry.get(townName) | ||
if(currentTown == undefined){ | ||
interaction.editReply("This town does not exist2."); | ||
return; | ||
} | ||
|
||
TownGenerator.regenerateTown(currentTown,textureAtlas).then(canvas=>{ | ||
const attachment = new Discord.AttachmentBuilder(); | ||
attachment.setFile((canvas.toBuffer())); | ||
attachment.setName(townName+".png"); | ||
interaction.editReply({files:[attachment]}); | ||
}); | ||
} | ||
|
||
if(interaction.options.getSubcommand() === "regenerate_all_town_maps"){ | ||
|
||
|
||
let towns = readdirSync(workingDir()+"/"+TownRegistry.table).map(v=>v.replace(".town","")) | ||
|
||
for(const townName of towns){ | ||
const townRegistry = discordInstance.fetchFromCache("townRegistry")().TownRegistry; | ||
const currentTown = townRegistry.get(townName) | ||
if(currentTown == undefined){ | ||
interaction.editReply("town "+townName+" does not exist."); | ||
} | ||
TownGenerator.regenerateTown(currentTown,textureAtlas); | ||
} | ||
interaction.editReply("All towns regenerated."); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const Discord = require("discord.js"); | ||
const { existsSync, readFileSync, readdirSync } = require("fs"); | ||
const { DiscordInstance } = require("../utils/boilerplate/Discord_Boilerplate"); | ||
const { Town } = require("../utils/datainstancer"); | ||
const { workingDir } = require("../utils/helpers"); | ||
const { TownRegistry } = require("../utils/registers"); | ||
const TownGenerator = require("../utils/towngenerator"); | ||
const buyProperty = require("./buyProperty"); | ||
/** | ||
* | ||
* @param {Discord.Interaction} interaction | ||
* @param {DiscordInstance} discordInstance | ||
*/ | ||
|
||
module.exports = async function(interaction,discordInstance){ | ||
if (!interaction.isCommand()) return; | ||
await interaction.deferReply(); | ||
if(interaction.options.getSubcommand() === "show"){ | ||
const townName = interaction.options.getString("town"); | ||
|
||
if(townName == "") { | ||
interaction.editReply("This town does not exist."); | ||
return; | ||
} | ||
const townRegistry = discordInstance.fetchFromCache("townRegistry")().TownRegistry; | ||
const currentTown = townRegistry.get(townName) | ||
if(currentTown == undefined){ | ||
interaction.editReply("This town does not exist."); | ||
return; | ||
} | ||
|
||
const attachment = new Discord.AttachmentBuilder(); | ||
attachment.setFile(readFileSync(__dirname+"/."+currentTown.getData().townImage)); | ||
attachment.setName(townName+".png") | ||
interaction.editReply({files:[attachment]}); | ||
} | ||
if(interaction.options.getSubcommand() === "list"){ | ||
let towns = readdirSync(workingDir()+"/"+TownRegistry.table).map(v=>v.replace(".town","")) | ||
interaction.editReply(towns.join("\n")); | ||
} | ||
buyProperty(interaction,discordInstance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.