Skip to content

Commit

Permalink
Bug 738325: Players can now loot all items stacked on the same cell
Browse files Browse the repository at this point in the history
  • Loading branch information
sork committed Mar 23, 2012
1 parent bc991a3 commit 8d5bc6a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
5 changes: 0 additions & 5 deletions client/js/character.js
Expand Up @@ -248,11 +248,6 @@ define(['entity', 'transition', 'timer'], function(Entity, Transition, Timer) {
onStep: function(callback) {
this.step_callback = callback;
},

/*
onBlocked: function(callback) {
this.blocked_callback = callback;
},*/

isMoving: function() {
return !(this.path === null);
Expand Down
34 changes: 28 additions & 6 deletions client/js/game.js
Expand Up @@ -448,7 +448,7 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT

removeItem: function(item) {
if(item) {
this.itemGrid[item.gridY][item.gridX] = null;
this.removeFromItemGrid(item, item.gridX, item.gridY);
this.removeFromRenderingGrid(item, item.gridX, item.gridY);
delete this.entities[item.id];
} else {
Expand Down Expand Up @@ -494,7 +494,7 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
for(var i=0; i < this.map.height; i += 1) {
this.itemGrid[i] = [];
for(var j=0; j < this.map.width; j += 1) {
this.itemGrid[i][j] = null;
this.itemGrid[i][j] = {};
}
}
log.info("Initialized the item grid.");
Expand Down Expand Up @@ -538,6 +538,12 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
delete this.entityGrid[y][x][entity.id];
}
},

removeFromItemGrid: function(item, x, y) {
if(item && this.itemGrid[y][x][item.id]) {
delete this.itemGrid[y][x][item.id];
}
},

removeFromPathingGrid: function(x, y) {
this.pathingGrid[y][x] = 0;
Expand Down Expand Up @@ -596,7 +602,7 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
}
}
if(entity instanceof Item) {
this.itemGrid[y][x] = entity;
this.itemGrid[y][x][entity.id] = entity;
}

this.addToRenderingGrid(entity, x, y);
Expand Down Expand Up @@ -1705,11 +1711,11 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
}

var entities = this.entityGrid[y][x],
entity;
entity = null;
if(_.size(entities) > 0) {
entity = entities[_.keys(entities)[0]];
} else {
entity = this.itemGrid[y][x];
entity = this.getItemAt(x, y);
}
return entity;
},
Expand Down Expand Up @@ -1742,7 +1748,23 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
if(this.map.isOutOfBounds(x, y) || !this.itemGrid) {
return null;
}
return this.itemGrid[y][x];
var items = this.itemGrid[y][x],
item = null;

if(_.size(items) > 0) {
// If there are potions/burgers stacked with equipment items on the same tile, always get expendable items first.
_.each(items, function(i) {
if(Types.isExpendableItem(i.kind)) {
item = i;
};
});

// Else, get the first item of the stack
if(!item) {
item = items[_.keys(items)[0]];
}
}
return item;
},

/**
Expand Down
10 changes: 6 additions & 4 deletions shared/js/gametypes.js
Expand Up @@ -56,8 +56,6 @@ Types = {
PLATEARMOR: 24,
REDARMOR: 25,
GOLDENARMOR: 26,
//PLATESHIELD: 27,
//PLATECLOAK: 28,

// Objects
FLASK: 35,
Expand Down Expand Up @@ -178,8 +176,6 @@ Types.rankedArmors = [
Types.Entities.LEATHERARMOR,
Types.Entities.MAILARMOR,
Types.Entities.PLATEARMOR,
//Types.Entities.PLATECLOAK,
//Types.Entities.PLATESHIELD,
Types.Entities.REDARMOR,
Types.Entities.GOLDENARMOR
];
Expand Down Expand Up @@ -235,6 +231,12 @@ Types.isHealingItem = function(kind) {
|| kind === Types.Entities.BURGER;
};

Types.isExpendableItem = function(kind) {
return Types.isHealingItem(kind)
|| kind === Types.Entities.FIREPOTION
|| kind === Types.Entities.CAKE;
};

Types.getKindFromString = function(kind) {
if(kind in kinds) {
return kinds[kind][0];
Expand Down

0 comments on commit 8d5bc6a

Please sign in to comment.