Skip to content

Commit

Permalink
Added disabledInBackpack
Browse files Browse the repository at this point in the history
added disabledInBackpack option for items, it prevents passive bonuses from being applied if the item is in the backpack of its owner unit
  • Loading branch information
VietnamNeko committed May 13, 2021
1 parent 9980aff commit a5831d7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
12 changes: 10 additions & 2 deletions engine/core/IgeEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3930,7 +3930,11 @@ var IgeEntity = IgeObject.extend({
//remove all passive attributes applyed to this unit
unit._stats.itemIds.forEach(function (itemId) {
if (itemId) {
unit.updateStats(itemId, true);
var item = ige.$(itemId);
if(item._stats.slotIndex < unit._stats.inventorySize || item._stats.disabledInBackpack != true){
unit.updateStats(itemId, true);
}

}
});
}
Expand All @@ -3944,7 +3948,11 @@ var IgeEntity = IgeObject.extend({
//add all passive attributes applyed to this unit
unit._stats.itemIds.forEach(function (itemId) {
if (itemId) {
unit.updateStats(itemId);
var item = ige.$(itemId);
if(item._stats.slotIndex < unit._stats.inventorySize || item._stats.disabledInBackpack != true){
unit.updateStats(itemId);
}

}
});
}
Expand Down
16 changes: 16 additions & 0 deletions server/ServerNetworkEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,17 @@ var ServerNetworkEvents = {
) {
fromItem.streamUpdateData([{ slotIndex: parseInt(data.to) }]);
toItem.streamUpdateData([{ slotIndex: parseInt(data.from) }]);
if(fromItem.disabledInBackpack == true && data.from + 1 <= unit._stats.inventorySize && data.to + 1 > unit._stats.inventorySize){
unit.updateStats(fromItem.id(), true)
}else if(fromItem.disabledInBackpack == true && data.to + 1 <= unit._stats.inventorySize && data.from + 1 > unit._stats.inventorySize){
unit.updateStats(fromItem.id())
}

if(toItem.disabledInBackpack == true && data.to + 1 <= unit._stats.inventorySize && data.from + 1 > unit._stats.inventorySize){
unit.updateStats(toItem.id(), true)
}else if(toItem.disabledInBackpack == true && data.from + 1 <= unit._stats.inventorySize && data.to + 1 > unit._stats.inventorySize){
unit.updateStats(toItem.id())
}
var temp = itemIds[data.from];
itemIds[data.from] = itemIds[data.to];
itemIds[data.to] = temp;
Expand All @@ -517,6 +528,11 @@ var ServerNetworkEvents = {
)
) {
fromItem.streamUpdateData([{ slotIndex: parseInt(data.to) }]);
if(fromItem.disabledInBackpack == true && data.from + 1 <= unit._stats.inventorySize && data.to + 1 > unit._stats.inventorySize){
unit.updateStats(fromItem.id(), true)
}else if(fromItem.disabledInBackpack == true && data.to + 1 <= unit._stats.inventorySize && data.from + 1 > unit._stats.inventorySize){
unit.updateStats(fromItem.id())
}
itemIds[data.to] = itemIds[data.from];
itemIds[data.from] = undefined;
}
Expand Down
5 changes: 4 additions & 1 deletion src/gameClasses/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,10 @@ var Item = IgeEntityBox2d.extend({
var ownerUnit = ige.$(this._stats.ownerUnitId)
if (ownerUnit) {
// remove its passive attributes from its ownerUnit unit.
ownerUnit.updateStats(this.id(), true);
if(this._stats.slotIndex < ownerUnit._stats.inventorySize || this._stats.disabledInBackpack != true){
ownerUnit.updateStats(this.id(), true);
}

if (ownerUnit.inventory) {
ownerUnit.inventory.removeItemByItemId(this.id());
}
Expand Down
17 changes: 13 additions & 4 deletions src/gameClasses/Unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,10 @@ var Unit = IgeEntityBox2d.extend({
var item = ige.$(itemId);
if (item) {
// removing passive attributes
self.updateStats(itemId, true);
if(item._stats.slotIndex < this._stats.inventorySize || item._stats.disabledInBackpack != true){
self.updateStats(itemId, true);
}


// if the new unit type cannot carry the item, then remove it.
if (self.canCarryItem(item._stats) == false) {
Expand All @@ -798,7 +801,9 @@ var Unit = IgeEntityBox2d.extend({
}

// adding back passive attributes
self.updateStats(itemId);
if(item._stats.slotIndex < this._stats.inventorySize || item._stats.disabledInBackpack != true){
self.updateStats(itemId);
}
}
}

Expand Down Expand Up @@ -1036,7 +1041,9 @@ var Unit = IgeEntityBox2d.extend({
{quantity: itemData.quantity},
{slotIndex: slotIndex }
])
self.updateStats(item.id())
if(item._stats.slotIndex < self._stats.inventorySize || item._stats.disabledInBackpack != true){
self.updateStats(item.id())
}

if (slotIndex == self._stats.currentItemIndex) {
item.setState('selected');
Expand Down Expand Up @@ -1234,7 +1241,9 @@ var Unit = IgeEntityBox2d.extend({
}

self.inventory.removeItem(itemIndex, item.id());
self.updateStats(item.id(), true);
if(item._stats.slotIndex < this._stats.inventorySize || item._stats.disabledInBackpack != true){
self.updateStats(item.id(), true)
}
self.detachEntity(item.id());

ige.trigger && ige.trigger.fire("unitDroppedAnItem", {
Expand Down

0 comments on commit a5831d7

Please sign in to comment.