const InventoryList = require("./InventoryList"); const LEVELS = require("../Data/levels"); const GUILD_MAXIMUM_REQUESTS_SIZE = 100; const ECONOMY = [1, 2]; const globalRequests = {}; class Guild { constructor(info) { this.id = info.id; this.topic = `g${info.id}`; this.name = info.name; this.tag = info.tag; this.description = info.description; this.ownerID = info.ownerID; this.bank = new GuildBank(); this.taxRates = info.taxRates; this.experiencePoints = info.experiencePoints ?? 0; this.level = LEVELS.guildLevel(this.experiencePoints) ?? 1; this.size = 0; this.sizeMaximum = 30; this.members = []; this.requests = []; this.diplomacy = {}; this.timestamps = info.timestamps; this.bank.depositTax({ categoryID: 1, id: 1, amount: 0 }); this.bank.depositTax({ categoryID: 1, id: 2, amount: 0 }); }; levelUpdate(amount) { this.experiencePoints += amount; if (this.level >= 25) return -1; const newLevel = LEVELS.guildLevel(this.experiencePoints); if (newLevel !== this.level) { if (newLevel > 25) this.level = 25; else this.level = newLevel; return this.level; }; return -1; } isLeader(playerID) { return this.ownerID === playerID; } hasRequested(playerID) { const isRequestPresent = this.requests.some(r => r.playerID === playerID); return isRequestPresent; } setPermission(playerID, permission) { const member = this.members.find(m => m.id === playerID); if (!member) return; member.permission = permission; } addRequest(playerID, message) { //if (this.requestSize >= GUILD_MAXIMUM_REQUESTS_SIZE) return; if (globalRequests[playerID] >= 8) return; console.info(globalRequests[playerID], "request count for player", playerID); if (globalRequests[playerID]) globalRequests[playerID]++; else globalRequests[playerID] = 1; const request = { playerID, message }; this.requests.push(request); return true; } removeRequest(playerID) { if (globalRequests[playerID]) globalRequests[playerID]--; this.requests = this.requests.filter(r => r.playerID !== playerID); } isMember(playerID) { return this.members.find(member => member.id === playerID) ? true : false; } getMember(playerID) { return this.members.find(member => member.id === playerID); } addMember(member) { if (this.size >= this.sizeMaximum) return; if (this.isMember(member.id)) return; this.removeRequest(member.id); this.members.push(member); delete globalRequests[member.id]; this.size++; return true; } removeMember(playerID) { this.size--; this.members = this.members.filter(member => member.id !== playerID); } }; class GuildBank { constructor(info) { this.list = new InventoryList(); this.deposits = []; }; depositTax(resource) { if (!ECONOMY.includes(resource.id)) return; this.list.accumulateItem(resource.id, resource); } }; module.exports = Guild;