@@ -322,7 +322,7 @@ define([ | |||||
item.factions.forEach((f, i) => { | item.factions.forEach((f, i) => { | ||||
let htmlF = f.name + ': ' + f.tierName; | let htmlF = f.name + ': ' + f.tierName; | ||||
if (f.noEquip) | |||||
if (f.tier > window.player.reputation.getTier(f.id)) | |||||
htmlF = '<font class="color-red">' + htmlF + '</font>'; | htmlF = '<font class="color-red">' + htmlF + '</font>'; | ||||
htmlFactions += htmlF; | htmlFactions += htmlF; | ||||
@@ -93,7 +93,7 @@ define([ | |||||
noAfford = (~~(item.worth * this.itemList.markup) > window.player.trade.gold); | noAfford = (~~(item.worth * this.itemList.markup) > window.player.trade.gold); | ||||
if (!noAfford && item.factions) | if (!noAfford && item.factions) | ||||
noAfford = item.factions.some(f => f.noEquip); | |||||
noAfford = item.factions.some(f => f.tier > window.player.reputation.getTier(f.id)); | |||||
if (noAfford) | if (noAfford) | ||||
$('<div class="no-afford"></div>').appendTo(itemEl); | $('<div class="no-afford"></div>').appendTo(itemEl); | ||||
@@ -59,19 +59,18 @@ define([ | |||||
}, | }, | ||||
equipItemErrors: function (item) { | equipItemErrors: function (item) { | ||||
let errors = []; | |||||
let stats = this.obj.stats.values; | |||||
const { obj: { reputation, stats: { values: statValues } } } = this; | |||||
if (item.level > stats.level) | |||||
const errors = []; | |||||
if (item.level > statValues.level) | |||||
errors.push('level'); | errors.push('level'); | ||||
if (item.requires && item.requires[0] && stats[item.requires[0].stat] < item.requires[0].value) | |||||
if (item.requires && item.requires[0] && statValues[item.requires[0].stat] < item.requires[0].value) | |||||
errors.push('stats'); | errors.push('stats'); | ||||
if (item.factions) { | |||||
if (item.factions.some(f => f.noEquip)) | |||||
errors.push('faction'); | |||||
} | |||||
if (item.factions?.some(f => reputation.getTier(f.id) < f.tier)) | |||||
errors.push('faction'); | |||||
return errors; | return errors; | ||||
}, | }, | ||||
@@ -29,6 +29,10 @@ define([ | |||||
events.emit('onGetReputations', this.list); | events.emit('onGetReputations', this.list); | ||||
} | } | ||||
}, | |||||
getTier: function (factionId) { | |||||
return this.factions.find(f => f.id === factionId)?.tier ?? 3; | |||||
} | } | ||||
}; | }; | ||||
}); | }); |
@@ -1,16 +1,21 @@ | |||||
//System | |||||
const events = require('../misc/events'); | |||||
//External Helpers | |||||
let generator = require('../items/generator'); | let generator = require('../items/generator'); | ||||
let salvager = require('../items/salvager'); | let salvager = require('../items/salvager'); | ||||
let classes = require('../config/spirits'); | let classes = require('../config/spirits'); | ||||
let factions = require('../config/factions'); | let factions = require('../config/factions'); | ||||
let itemEffects = require('../items/itemEffects'); | let itemEffects = require('../items/itemEffects'); | ||||
const events = require('../misc/events'); | |||||
const { isItemStackable } = require('./inventory/helpers'); | |||||
//Helpers | |||||
const simplifyItem = require('./inventory/simplifyItem'); | |||||
const getItem = require('./inventory/getItem'); | const getItem = require('./inventory/getItem'); | ||||
const dropBag = require('./inventory/dropBag'); | const dropBag = require('./inventory/dropBag'); | ||||
const useItem = require('./inventory/useItem'); | const useItem = require('./inventory/useItem'); | ||||
const { isItemStackable } = require('./inventory/helpers'); | |||||
//Component | |||||
module.exports = { | module.exports = { | ||||
type: 'inventory', | type: 'inventory', | ||||
@@ -91,44 +96,7 @@ module.exports = { | |||||
}, | }, | ||||
simplifyItem: function (item) { | simplifyItem: function (item) { | ||||
let result = extend({}, item); | |||||
if (result.effects) { | |||||
result.effects = result.effects.map(e => ({ | |||||
factionId: e.factionId || null, | |||||
text: e.text || null, | |||||
properties: e.properties || null, | |||||
type: e.type || null, | |||||
rolls: e.rolls || null | |||||
})); | |||||
} | |||||
let reputation = this.obj.reputation; | |||||
if (result.factions) { | |||||
result.factions = result.factions.map(function (f) { | |||||
let res = { | |||||
id: f.id, | |||||
tier: f.tier, | |||||
tierName: ['Hated', 'Hostile', 'Unfriendly', 'Neutral', 'Friendly', 'Honored', 'Revered', 'Exalted'][f.tier] | |||||
}; | |||||
if (reputation) { | |||||
let faction = reputation.getBlueprint(f.id); | |||||
let factionTier = reputation.getTier(f.id); | |||||
let noEquip = null; | |||||
if (factionTier < f.tier) | |||||
noEquip = true; | |||||
res.name = faction.name; | |||||
res.noEquip = noEquip; | |||||
} | |||||
return res; | |||||
}, this); | |||||
} | |||||
return result; | |||||
return simplifyItem(this, item); | |||||
}, | }, | ||||
update: function () { | update: function () { | ||||
@@ -722,25 +690,21 @@ module.exports = { | |||||
}, | }, | ||||
equipItemErrors: function (item) { | equipItemErrors: function (item) { | ||||
let errors = []; | |||||
const { obj: { player, stats: { values: statValues }, reputation } } = this; | |||||
if (!this.obj.player) | |||||
return []; | |||||
const errors = []; | |||||
let stats = this.obj.stats.values; | |||||
if (!player) | |||||
return errors; | |||||
if (item.level > stats.level) | |||||
if (item.level > statValues.level) | |||||
errors.push('level'); | errors.push('level'); | ||||
if ((item.requires) && (stats[item.requires[0].stat] < item.requires[0].value)) | |||||
if (item.requires && statValues[item.requires[0].stat] < item.requires[0].value) | |||||
errors.push(item.requires[0].stat); | errors.push(item.requires[0].stat); | ||||
if (item.factions) { | |||||
if (item.factions.some(function (f) { | |||||
return f.noEquip; | |||||
})) | |||||
errors.push('faction'); | |||||
} | |||||
if (item.factions?.some(f => reputation.getTier(f.id) < f.tier)) | |||||
errors.push('faction'); | |||||
return errors; | return errors; | ||||
}, | }, | ||||
@@ -0,0 +1,37 @@ | |||||
//Helpers | |||||
const { getFactionBlueprint } = require('../../config/factions/helpers'); | |||||
//Internals | |||||
const tierNames = ['Hated', 'Hostile', 'Unfriendly', 'Neutral', 'Friendly', 'Honored', 'Revered', 'Exalted']; | |||||
//Method | |||||
const simplifyItem = (cpnInventory, item) => { | |||||
const result = extend({}, item); | |||||
if (result.effects) { | |||||
result.effects = result.effects.map(e => ({ | |||||
factionId: e.factionId ?? null, | |||||
text: e.text ?? null, | |||||
properties: e.properties ?? null, | |||||
type: e.type ?? null, | |||||
rolls: e.rolls ?? null | |||||
})); | |||||
} | |||||
if (result.factions) { | |||||
result.factions = result.factions.map(f => { | |||||
const res = { | |||||
id: f.id, | |||||
tier: f.tier, | |||||
tierName: tierNames[f.tier], | |||||
name: getFactionBlueprint(f.id).name | |||||
}; | |||||
return res; | |||||
}); | |||||
} | |||||
return result; | |||||
}; | |||||
module.exports = simplifyItem; |
@@ -144,7 +144,7 @@ module.exports = { | |||||
//Are we too far from home? | //Are we too far from home? | ||||
let distanceFromHome = Math.max(abs(this.originX - obj.x), abs(this.originY - obj.y)); | let distanceFromHome = Math.max(abs(this.originX - obj.x), abs(this.originY - obj.y)); | ||||
if (distanceFromHome > this.maxChaseDistance || (distanceFromHome > this.walkDistance && !target)) | |||||
if (distanceFromHome > this.maxChaseDistance || (distanceFromHome > this.walkDistance && !target && !this.patrol)) | |||||
this.goHome = true; | this.goHome = true; | ||||
else if (target && target !== obj && (!obj.follower || obj.follower.master !== target)) { | else if (target && target !== obj && (!obj.follower || obj.follower.master !== target)) { | ||||
//If we just started attacking, patrols need to know where home is | //If we just started attacking, patrols need to know where home is | ||||
@@ -1,6 +1,7 @@ | |||||
let factionBase = require('../config/factionBase'); | |||||
let factions = require('../config/factions'); | |||||
//Helpers | |||||
const { getFactionBlueprint } = require('../config/factions/helpers'); | |||||
//Component | |||||
module.exports = { | module.exports = { | ||||
type: 'reputation', | type: 'reputation', | ||||
@@ -13,7 +14,7 @@ module.exports = { | |||||
delete blueprint.list; | delete blueprint.list; | ||||
list.forEach(function (l) { | list.forEach(function (l) { | ||||
let bpt = this.getBlueprint(l.id); | |||||
let bpt = getFactionBlueprint(l.id); | |||||
if (!bpt) | if (!bpt) | ||||
return; | return; | ||||
@@ -27,25 +28,6 @@ module.exports = { | |||||
}, this); | }, this); | ||||
}, | }, | ||||
getBlueprint: function (factionId) { | |||||
if (this.factions[factionId]) | |||||
return this.factions[factionId]; | |||||
let factionBlueprint = null; | |||||
try { | |||||
factionBlueprint = factions.getFaction(factionId); | |||||
} catch (e) {} | |||||
if (!factionBlueprint) | |||||
return; | |||||
factionBlueprint = extend({}, factionBase, factionBlueprint); | |||||
this.factions[factionBlueprint.id] = factionBlueprint; | |||||
return factionBlueprint; | |||||
}, | |||||
getTier: function (factionId) { | getTier: function (factionId) { | ||||
let faction = this.list.find(l => l.id === factionId); | let faction = this.list.find(l => l.id === factionId); | ||||
if (!faction) { | if (!faction) { | ||||
@@ -53,9 +35,7 @@ module.exports = { | |||||
faction = this.list.find(l => l.id === factionId); | faction = this.list.find(l => l.id === factionId); | ||||
} | } | ||||
return (faction || { | |||||
tier: 3 | |||||
}).tier; | |||||
return faction?.tier ?? 3; | |||||
}, | }, | ||||
canEquipItem: function (item) { | canEquipItem: function (item) { | ||||
@@ -71,7 +51,7 @@ module.exports = { | |||||
}, | }, | ||||
calculateTier: function (factionId) { | calculateTier: function (factionId) { | ||||
let blueprint = this.getBlueprint(factionId); | |||||
let blueprint = getFactionBlueprint(factionId); | |||||
let faction = this.list.find(l => l.id === factionId); | let faction = this.list.find(l => l.id === factionId); | ||||
let rep = faction.rep; | let rep = faction.rep; | ||||
@@ -99,7 +79,7 @@ module.exports = { | |||||
getReputation: function (factionId, gain) { | getReputation: function (factionId, gain) { | ||||
let fullSync = false; | let fullSync = false; | ||||
let blueprint = this.getBlueprint(factionId); | |||||
let blueprint = getFactionBlueprint(factionId); | |||||
let faction = this.list.find(l => l.id === factionId); | let faction = this.list.find(l => l.id === factionId); | ||||
if (!faction) { | if (!faction) { | ||||
@@ -147,7 +127,7 @@ module.exports = { | |||||
if (this.list.some(l => l.id === factionId)) | if (this.list.some(l => l.id === factionId)) | ||||
return; | return; | ||||
let blueprint = this.getBlueprint(factionId); | |||||
let blueprint = getFactionBlueprint(factionId); | |||||
if (!blueprint) | if (!blueprint) | ||||
return; | return; | ||||
@@ -185,7 +165,7 @@ module.exports = { | |||||
let sendList = this.list | let sendList = this.list | ||||
.map(function (l) { | .map(function (l) { | ||||
let result = {}; | let result = {}; | ||||
let blueprint = this.getBlueprint(l.id); | |||||
let blueprint = getFactionBlueprint(l.id); | |||||
extend(result, l, blueprint); | extend(result, l, blueprint); | ||||
return result; | return result; | ||||
@@ -206,7 +186,7 @@ module.exports = { | |||||
}; | }; | ||||
if (full) { | if (full) { | ||||
let blueprint = this.getBlueprint(factionId); | |||||
let blueprint = getFactionBlueprint(factionId); | |||||
extend(faction, l, blueprint); | extend(faction, l, blueprint); | ||||
} | } | ||||
@@ -0,0 +1,30 @@ | |||||
//Imports | |||||
let factionBase = require('../factionBase'); | |||||
let factions = require('../factions'); | |||||
//Internals | |||||
const cache = {}; | |||||
//Method | |||||
const getFactionBlueprint = factionId => { | |||||
if (cache[factionId]) | |||||
return cache[factionId]; | |||||
let res = null; | |||||
try { | |||||
res = factions.getFaction(factionId); | |||||
} catch (e) {} | |||||
if (!res) | |||||
return; | |||||
res = extend({}, factionBase, res); | |||||
cache[factionId] = res; | |||||
return res; | |||||
}; | |||||
module.exports = { | |||||
getFactionBlueprint | |||||
}; |