Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
fix(rogue): item stacking now works properly
Browse files Browse the repository at this point in the history
closes #71
  • Loading branch information
seiyria committed Dec 19, 2015
1 parent a704325 commit 1af0708
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/js/rogue/content/items/_special.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ export class Gold extends Special {
};
super(opts);
this.goldValue = num;
this.name = `${this.goldValue} gold`;
this.realName = `${this.goldValue} gold`;
}
}

export class Corpse extends Comestible {
constructor(opts = { monsterName: 'unknown' }) {
super(opts);
this.name = `corpse of ${opts.monsterName}`;
this.realName = `corpse of ${opts.monsterName}`;
}
}

export class StoneOfSelyk extends Gem {
constructor() {
super({ glyph: { fg: SpecialGlyphColors.Selyk } });
this.name = `Stone of Selyk`;
this.realName = `Stone of Selyk`;
}
}

export class SelykCellarKey extends Tool {
constructor() {
super({ glyph: { fg: SpecialGlyphColors.Selyk } });
this.name = `Selyk's Cellar Key`;
this.realName = `Selyk's Cellar Key`;
}
}
6 changes: 3 additions & 3 deletions src/js/rogue/content/items/foods.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { rarity } from '../../constants/decorators';
export class Ration extends Comestible {
constructor(opts) {
super(opts);
this.name = 'ration';
this.realName = 'ration';
}
}

@rarity(75)
export class Apple extends Comestible {
constructor(opts) {
super(opts);
this.name = 'apple';
this.realName = 'apple';
}
}

@rarity(75)
export class Carrot extends Comestible {
constructor(opts) {
super(opts);
this.name = 'carrot';
this.realName = 'carrot';
}
}
14 changes: 10 additions & 4 deletions src/js/rogue/definitions/character.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,18 @@ export default class Character extends Entity {

// region Inventory functions (stacking, add, remove, etc)
tryToStack(item) {
if(!item.charges) return;
if(!item.canStack) return;
let didStack = false;
_.each(this.inventory, (testItem) => {
if(testItem.getType() !== item.getType()) return;
if(testItem.buc !== item.buc || testItem.enchantment !== item.enchantment) return;
testItem.charges += item.charges;
if(didStack) return;

if(testItem.name !== item.name ||
testItem.buc !== item.buc ||
testItem.enchantment !== item.enchantment) return;

if(!testItem.charges) testItem.charges = 1;

testItem.charges += item.charges ? item.charges : 1;
didStack = true;
});
return didStack;
Expand Down
11 changes: 4 additions & 7 deletions src/js/rogue/definitions/equipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import Materials from '../constants/materials';
import { rarity, material } from '../constants/decorators';

class Equipment extends Item {
get name() {
let name = !this.isIdentified() && this.fakeName ? this.fakeName : this.realName;
if(!name) name = this.getCanonName();
const enchant = this.enchantment ? `+${this.enchantment} ${name}` : name;
const buc = this.bucName !== 'uncursed' ? `${this.bucName} ${enchant}` : enchant;
return buc;
}
}

export class Special extends Item {}
Expand All @@ -24,6 +17,7 @@ export class Comestible extends Item {
opts.autoRemove = true;
opts.symbol = Glyphs.Comestible;
super(opts);
this.canStack = true;
}
}

Expand Down Expand Up @@ -118,6 +112,7 @@ export class Gem extends Item {
opts.symbol = Glyphs.Gem;
super(opts);
this.realName = this.fakeName = `${this.getCanonName()}`;
this.canStack = true;
}
}

Expand All @@ -128,6 +123,7 @@ export class Scroll extends Item {
opts.symbol = Glyphs.Scroll;
super(opts);
this.realName = this.fakeName = `${this.getCanonName()}`;
this.canStack = true;
}
}

Expand Down Expand Up @@ -161,6 +157,7 @@ export class Potion extends Equipment {
const fake = this.pickFakeName(Fakes.Potion);
this.color = fake;
this.fakeName = `${fake} potion`;
this.canStack = true;
}
use(entity, extra) {
super.use(entity, extra);
Expand Down
9 changes: 9 additions & 0 deletions src/js/rogue/definitions/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import Log from '../lib/logger';
import MessageQueue, { MessageTypes } from '../display/message-handler';

export class Item extends Abstract {

get name() {
let name = !this.isIdentified() && this.fakeName ? this.fakeName : this.realName;
if(!name) name = this.getCanonName();
const enchant = this.enchantment ? `+${this.enchantment} ${name}` : name;
const buc = this.bucName !== 'uncursed' ? `${this.bucName} ${enchant}` : enchant;
return buc;
}

constructor(opts) {
super(opts);
opts.glyph = _.extend({ fg: GetColor(), key: opts.symbol }, opts.glyph);
Expand Down

0 comments on commit 1af0708

Please sign in to comment.