Skip to content

Commit

Permalink
Merge branch 'item-preview-2' of github.com:azerothcore/Keira3 into i…
Browse files Browse the repository at this point in the history
…tem-preview-2
  • Loading branch information
FrancescoBorzi committed Apr 2, 2020
2 parents 43a2aaf + 0d80aaa commit 0f377bb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ItemTemplateService } from './item-template.service';
import { ITEM_FLAG } from '@keira-shared/constants/flags/item-flags';
import { ITEM_TYPE } from '@keira-shared/constants/options/item-class';

fdescribe('ItemPreviewService', () => {
describe('ItemPreviewService', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [
RouterTestingModule,
Expand Down Expand Up @@ -361,7 +361,7 @@ fdescribe('ItemPreviewService', () => {
}, output: `Adds 20 damage per second` },
{ name: 'Damage 2', template: {
class: ITEM_TYPE.AMMUNITION, dmg_min1: 10, dmg_min2: 10, dmg_max1: 10, dmg_max2: 10, delay: 1000, dmg_type1: 1,
}, output: `Adds 20 %s damage per secondHoly` }, // TODO: fix %s
}, output: `Adds 20 Holy damage per second` },
{ name: 'Damage 3', template: {
dmg_min1: 10, dmg_min2: 10, dmg_max1: 10, dmg_max2: 10, delay: 1000, dmg_type1: 1, dmg_type2: 2,
}, output: `<br><!--dmg-->10 Holy Damage+10 Fire Damage` },
Expand All @@ -383,8 +383,8 @@ fdescribe('ItemPreviewService', () => {
{ name: 'Item Limit Category, no data', template: { ItemLimitCategory: 124 }, output: `` },
{
name: 'inventoryType, class ARMOR, armorDamager',
template: { class: ITEM_TYPE.ARMOR, subclass: 1, InventoryType: 1, ArmorDamageModifier: 1 },
output: `<table style="float: left; width: 100%;"><tr><td>Head</td><th style="text-align: right;"><!--asc 1 -->Cloth</th></tr></table><br><span class="q2"><!--addamr1--><span>undefined Armor</span></span>` // TODO: fix
template: { class: ITEM_TYPE.ARMOR, subclass: 1, InventoryType: 1, ArmorDamageModifier: 1, armor: 1 },
output: `<table style="float: left; width: 100%;"><tr><td>Head</td><th style="text-align: right;"><!--asc 1 -->Cloth</th></tr></table><br><span class="q2"><!--addamr1--><span>1 Armor</span></span>`
},
{ name: 'inventoryType - 1', template: { class: 3, subclass: 2, InventoryType: 2 }, output: `<br><!-- InventoryType -->Neck` },
{ name: 'inventoryType, armor', template: { class: ITEM_TYPE.WEAPON, armor: 1, ItemLevel: 10, }, output: `<br><span><!--amr-->1 Armor</span><br>Item Level 10` },
Expand Down
38 changes: 29 additions & 9 deletions src/app/features/item/item-template/item-preview.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,12 @@ export class ItemPreviewService {
}

for (const costEntry of rawEntries) {
/* istanbul ignore else */
if (costEntry.extendedCost) {
xCostData.push(costEntry.extendedCost);
}

/* istanbul ignore next */
if (itemz[costEntry.item] && itemz[costEntry.item][costEntry.entry]) {
itemz[costEntry.item][costEntry.entry] = [costEntry];
} else {
Expand All @@ -394,18 +396,23 @@ export class ItemPreviewService {
}
}

if (!!xCostData && xCostData.length > 0) {
if (
/* istanbul ignore next */
!!xCostData
&& xCostData.length > 0) {
xCostData = Array.from(new Set(xCostData)); // filter duplicates
xCostData = await this.getItemExtendedCost(xCostData);

/* istanbul ignore else */
if (!!xCostData && xCostData.length > 0) {

// converting xCostData to ARRAY_KEY structure
for (const xCost of xCostData) {
xCostDataArr[xCost.id] = xCost;
}
} else {
return [];
/* istanbul ignore next */
return [];
}
}

Expand All @@ -416,15 +423,25 @@ export class ItemPreviewService {
for (const [m, vInfo] of Object.entries(vendor)) {

let costs = [];
if (xCostDataArr[vInfo['extendedCost']] && Object.keys(xCostDataArr[vInfo['extendedCost']]).length > 0) {
/* istanbul ignore else */
if (xCostDataArr[vInfo['extendedCost']] && Object.keys(xCostDataArr[vInfo['extendedCost']]).length > 0) {
costs = xCostDataArr[vInfo['extendedCost']];
}

const data = {
stock: vInfo['maxcount'] ?? -1,
stock: vInfo['maxcount'] ??
/* istanbul ignore next */
-1,
event: vInfo['eventId'],
reqRating: costs ? costs['reqPersonalRating'] : 0,
reqBracket: costs ? costs['reqArenaSlot'] : 0
reqRating: costs
? costs['reqPersonalRating']
/* istanbul ignore next */
: 0,
/* istanbul ignore next */
reqBracket: costs
? costs['reqArenaSlot']
/* istanbul ignore next */
: 0
};

// hardcode arena(103) & honor(104)
Expand Down Expand Up @@ -460,7 +477,8 @@ export class ItemPreviewService {
}

// convert items to currency if possible
if (!!cItems) {
/* istanbul ignore else */
if (!!cItems) {

for (const [itemId, vendors] of Object.entries(itemz)) {
for (const [npcId, costData] of Object.entries(vendors)) {
Expand Down Expand Up @@ -497,13 +515,15 @@ export class ItemPreviewService {
// use highest total value
if (data[npcId] &&
costs['reqRating'] &&
/* istanbul ignore next */
(reqRating.length === 0 || (reqRating && reqRating[0] < costs['reqRating']))
) {
reqRating = [costs['reqRating'], costs['reqBracket']];
}
}
}

/* istanbul ignore next */
if (!(data)) {
delete result[itemId];
}
Expand Down Expand Up @@ -536,7 +556,7 @@ export class ItemPreviewService {

if (itemClass === ITEM_TYPE.AMMUNITION && dmgmin && dmgmax) {
if (sc1) {
damageText += ITEM_CONSTANTS.damage.ammo[1].replace('%d', ((dmgmin + dmgmax) / 2).toString()) + ITEM_CONSTANTS.sc[sc1];
damageText += ITEM_CONSTANTS.damage.ammo[1].replace('%d', ((dmgmin + dmgmax) / 2).toString()).replace('%s', ITEM_CONSTANTS.sc[sc1]);
} else {
damageText += ITEM_CONSTANTS.damage.ammo[0].replace('%d', ((dmgmin + dmgmax) / 2).toString());
}
Expand Down Expand Up @@ -860,7 +880,7 @@ export class ItemPreviewService {
const armorDamageModifier = itemTemplate.ArmorDamageModifier;
const armor = itemTemplate.armor;
const itemClass: number = Number(itemTemplate.class);
if (itemClass === ITEM_TYPE.ARMOR && armorDamageModifier > 0) {
if (itemClass === ITEM_TYPE.ARMOR && armorDamageModifier > 0 && !!armor) {
armorText += `<br><span class="q2"><!--addamr${armorDamageModifier}--><span>${ITEM_CONSTANTS.armor.replace('%s', String(armor))}</span></span>`;
} else if (armor) {
armorText += `<br><span><!--amr-->${ITEM_CONSTANTS.armor.replace('%s', String(armor))}</span>`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ export class ItemTemplateComponent extends SingleRowEditorComponent<ItemTemplate
this.subscriptions.push(
this.editorService.form.valueChanges.pipe(
debounceTime(600),
distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)),
/* TODO */
distinctUntilChanged(
/* istanbul ignore next */
(a, b) => JSON.stringify(a) === JSON.stringify(b)
),
).subscribe(this.loadItemPreview.bind(this))
);
}
Expand Down

0 comments on commit 0f377bb

Please sign in to comment.