add gem selling and leveling
This commit is contained in:
parent
cec7dbb493
commit
b819bb8719
@ -7,20 +7,23 @@
|
|||||||
"textures": [],
|
"textures": [],
|
||||||
"cantCombineWith": [],
|
"cantCombineWith": [],
|
||||||
"specialCombine": [],
|
"specialCombine": [],
|
||||||
|
"initialGemValue": 10,
|
||||||
"genericImprovements": [
|
"genericImprovements": [
|
||||||
{
|
{
|
||||||
"damageUp": 2,
|
"damageUp": 2,
|
||||||
"attackSpeedUp": 100,
|
"attackSpeedUp": 100,
|
||||||
"rangeUp": 0.5,
|
"rangeUp": 0.5,
|
||||||
"timeToLiveUp": 0,
|
"timeToLiveUp": 0,
|
||||||
"pierceUp": 1
|
"pierceUp": 1,
|
||||||
|
"gemValueUp": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"damageUp": 2,
|
"damageUp": 2,
|
||||||
"attackSpeedUp": 100,
|
"attackSpeedUp": 100,
|
||||||
"rangeUp": 0.5,
|
"rangeUp": 0.5,
|
||||||
"timeToLiveUp": 0,
|
"timeToLiveUp": 0,
|
||||||
"pierceUp": 1
|
"pierceUp": 1,
|
||||||
|
"gemValueUp": 10
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"gemResistanceModifications": [
|
"gemResistanceModifications": [
|
||||||
@ -48,20 +51,23 @@
|
|||||||
"textures": [],
|
"textures": [],
|
||||||
"cantCombineWith": [],
|
"cantCombineWith": [],
|
||||||
"specialCombine": [],
|
"specialCombine": [],
|
||||||
|
"initialGemValue": 10,
|
||||||
"genericImprovements": [
|
"genericImprovements": [
|
||||||
{
|
{
|
||||||
"damageUp": 2,
|
"damageUp": 2,
|
||||||
"attackSpeedUp": 100,
|
"attackSpeedUp": 100,
|
||||||
"rangeUp": 0.5,
|
"rangeUp": 0.5,
|
||||||
"timeToLiveUp": 0,
|
"timeToLiveUp": 0,
|
||||||
"pierceUp": 1
|
"pierceUp": 1,
|
||||||
|
"gemValueUp": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"damageUp": 2,
|
"damageUp": 2,
|
||||||
"attackSpeedUp": 100,
|
"attackSpeedUp": 100,
|
||||||
"rangeUp": 0.5,
|
"rangeUp": 0.5,
|
||||||
"timeToLiveUp": 0,
|
"timeToLiveUp": 0,
|
||||||
"pierceUp": 1
|
"pierceUp": 1,
|
||||||
|
"gemValueUp": 10
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"gemResistanceModifications": [
|
"gemResistanceModifications": [
|
||||||
@ -89,27 +95,31 @@
|
|||||||
"textures": [],
|
"textures": [],
|
||||||
"cantCombineWith": [],
|
"cantCombineWith": [],
|
||||||
"specialCombine": [],
|
"specialCombine": [],
|
||||||
|
"initialGemValue": 10,
|
||||||
"genericImprovements": [
|
"genericImprovements": [
|
||||||
{
|
{
|
||||||
"damageUp": 2,
|
"damageUp": 2,
|
||||||
"attackSpeedUp": 100,
|
"attackSpeedUp": 100,
|
||||||
"rangeUp": 0.5,
|
"rangeUp": 0.5,
|
||||||
"timeToLiveUp": 0,
|
"timeToLiveUp": 0,
|
||||||
"pierceUp": 1
|
"pierceUp": 1,
|
||||||
|
"gemValueUp": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"damageUp": 2,
|
"damageUp": 2,
|
||||||
"attackSpeedUp": 100,
|
"attackSpeedUp": 100,
|
||||||
"rangeUp": 0,
|
"rangeUp": 0,
|
||||||
"timeToLiveUp": 0,
|
"timeToLiveUp": 0,
|
||||||
"pierceUp": 1
|
"pierceUp": 1,
|
||||||
|
"gemValueUp": 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"damageUp": 2,
|
"damageUp": 2,
|
||||||
"attackSpeedUp": 100,
|
"attackSpeedUp": 100,
|
||||||
"rangeUp": 0,
|
"rangeUp": 0,
|
||||||
"timeToLiveUp": 0,
|
"timeToLiveUp": 0,
|
||||||
"pierceUp": 1
|
"pierceUp": 1,
|
||||||
|
"gemValueUp": 10
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"gemResistanceModifications": [
|
"gemResistanceModifications": [
|
||||||
@ -144,20 +154,23 @@
|
|||||||
"textures": [],
|
"textures": [],
|
||||||
"cantCombineWith": [],
|
"cantCombineWith": [],
|
||||||
"specialCombine": [],
|
"specialCombine": [],
|
||||||
|
"initialGemValue": 10,
|
||||||
"genericImprovements": [
|
"genericImprovements": [
|
||||||
{
|
{
|
||||||
"damageUp": 2,
|
"damageUp": 2,
|
||||||
"attackSpeedUp": 100,
|
"attackSpeedUp": 100,
|
||||||
"rangeUp": 0.5,
|
"rangeUp": 0.5,
|
||||||
"timeToLiveUp": 0,
|
"timeToLiveUp": 0,
|
||||||
"pierceUp": 1
|
"pierceUp": 1,
|
||||||
|
"gemValueUp": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"damageUp": 2,
|
"damageUp": 2,
|
||||||
"attackSpeedUp": 100,
|
"attackSpeedUp": 100,
|
||||||
"rangeUp": 0.5,
|
"rangeUp": 0.5,
|
||||||
"timeToLiveUp": 0,
|
"timeToLiveUp": 0,
|
||||||
"pierceUp": 1
|
"pierceUp": 1,
|
||||||
|
"gemValueUp": 10
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"gemResistanceModifications": [
|
"gemResistanceModifications": [
|
||||||
|
@ -78,6 +78,7 @@ export type GemDefinition = {
|
|||||||
textures: PIXI.Texture[];
|
textures: PIXI.Texture[];
|
||||||
cantCombineWith: GemType[];
|
cantCombineWith: GemType[];
|
||||||
specialCombine: GemType[];
|
specialCombine: GemType[];
|
||||||
|
initialGemValue: number;
|
||||||
genericImprovements: GenericGemImprovement[];
|
genericImprovements: GenericGemImprovement[];
|
||||||
gemResistanceModifications: CreepResistancesDefinition[];
|
gemResistanceModifications: CreepResistancesDefinition[];
|
||||||
};
|
};
|
||||||
@ -88,6 +89,7 @@ export type GenericGemImprovement = {
|
|||||||
rangeUp: number;
|
rangeUp: number;
|
||||||
timeToLiveUp: number;
|
timeToLiveUp: number;
|
||||||
pierceUp: number;
|
pierceUp: number;
|
||||||
|
gemValueUp: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PathDefinition = [[row: number, column: number]];
|
export type PathDefinition = [[row: number, column: number]];
|
||||||
|
@ -25,6 +25,7 @@ export default class Gem {
|
|||||||
rangeUp: 0,
|
rangeUp: 0,
|
||||||
timeToLiveUp: 0,
|
timeToLiveUp: 0,
|
||||||
pierceUp: 0,
|
pierceUp: 0,
|
||||||
|
gemValueUp: 0,
|
||||||
};
|
};
|
||||||
for (let i = 0; i < this.level; i++) {
|
for (let i = 0; i < this.level; i++) {
|
||||||
const item = this.definition.genericImprovements[i];
|
const item = this.definition.genericImprovements[i];
|
||||||
@ -33,10 +34,19 @@ export default class Gem {
|
|||||||
totalGemImprovement.rangeUp += item.rangeUp;
|
totalGemImprovement.rangeUp += item.rangeUp;
|
||||||
totalGemImprovement.timeToLiveUp += item.timeToLiveUp;
|
totalGemImprovement.timeToLiveUp += item.timeToLiveUp;
|
||||||
totalGemImprovement.pierceUp += item.pierceUp;
|
totalGemImprovement.pierceUp += item.pierceUp;
|
||||||
|
totalGemImprovement.gemValueUp += item.gemValueUp;
|
||||||
}
|
}
|
||||||
return totalGemImprovement;
|
return totalGemImprovement;
|
||||||
}
|
}
|
||||||
public currentGemResistanceModifications() {
|
public currentGemResistanceModifications() {
|
||||||
return this.definition.gemResistanceModifications[this.level - 1];
|
return this.definition.gemResistanceModifications[this.level - 1];
|
||||||
}
|
}
|
||||||
|
public isMaxLevel() {
|
||||||
|
return this.level == this.definition.totalLevels;
|
||||||
|
}
|
||||||
|
public levelUp(howMuch) {
|
||||||
|
if (!howMuch) howMuch = 1;
|
||||||
|
this.level += howMuch;
|
||||||
|
this.texture = this.definition.textures[this.level - 1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,22 @@ export default class GemTab extends GuiObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public pointerMoveEvent() {
|
public pointerMoveEvent() {
|
||||||
if (!this.isDragAndDroppingGem || !Engine.GameScene.towerPanel.isShown || !this.dragAndDroppingGem) return;
|
if (!this.isDragAndDroppingGem || !this.dragAndDroppingGem) return;
|
||||||
this.dragAndDroppingGem.container.x = Engine.MouseX - 32;
|
this.dragAndDroppingGem.container.x = Engine.MouseX - 32;
|
||||||
this.dragAndDroppingGem.container.y = Engine.MouseY - 32;
|
this.dragAndDroppingGem.container.y = Engine.MouseY - 32;
|
||||||
}
|
}
|
||||||
|
private isOverlappingGemsmith(me: VisualGemSlot, other: VisualGemSlot, otherParent: PIXI.Container) {
|
||||||
|
let ddbb = me.copyContainerToBB();
|
||||||
|
let vb = other.copyContainerToBB();
|
||||||
|
let x = otherParent.x + vb.x + Engine.GameScene.sidebar.container.x;
|
||||||
|
let y = otherParent.y + vb.y + Engine.GameScene.sidebar.container.y;
|
||||||
|
|
||||||
|
let vgbb = new PIXI.Rectangle(x, y, vb.width, vb.height);
|
||||||
|
// console.log(ddbb, vgbb, ddbb.getBounds().intersects(vgbb));
|
||||||
|
if (ddbb.getBounds().intersects(vgbb)) {
|
||||||
|
if (other && other.gem == null) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
public RebuildInventoryVisual() {
|
public RebuildInventoryVisual() {
|
||||||
this.vGems.forEach((vGem) => vGem.destroy());
|
this.vGems.forEach((vGem) => vGem.destroy());
|
||||||
this.vGems = [];
|
this.vGems = [];
|
||||||
@ -112,7 +124,6 @@ export default class GemTab extends GuiObject {
|
|||||||
this.selectingGemTowerObject.SlotGem(takenGem, this.selectingGemSlotIndex);
|
this.selectingGemTowerObject.SlotGem(takenGem, this.selectingGemSlotIndex);
|
||||||
this.RebuildInventoryVisual();
|
this.RebuildInventoryVisual();
|
||||||
} else {
|
} else {
|
||||||
if (!Engine.GameScene.towerPanel.isShown) return;
|
|
||||||
// initialise drag and drop
|
// initialise drag and drop
|
||||||
this.isDragAndDroppingGem = true;
|
this.isDragAndDroppingGem = true;
|
||||||
this.dragAndDroppingGem = vGem;
|
this.dragAndDroppingGem = vGem;
|
||||||
@ -124,6 +135,63 @@ export default class GemTab extends GuiObject {
|
|||||||
vGem.container.onpointerup = () => {
|
vGem.container.onpointerup = () => {
|
||||||
if (this.isSelectingGem) return;
|
if (this.isSelectingGem) return;
|
||||||
let overlapping = null;
|
let overlapping = null;
|
||||||
|
let wantToSell = this.isOverlappingGemsmith(
|
||||||
|
this.dragAndDroppingGem,
|
||||||
|
Engine.GameScene.sidebar.gemsmith.sellVGem,
|
||||||
|
Engine.GameScene.sidebar.gemsmith.container
|
||||||
|
);
|
||||||
|
if (wantToSell) {
|
||||||
|
let sellFor =
|
||||||
|
this.dragAndDroppingGem.gem.definition.initialGemValue +
|
||||||
|
this.dragAndDroppingGem.gem.currentGemImprovement().gemValueUp;
|
||||||
|
Engine.GameScene.MissionStats.earnGold(Math.ceil(sellFor * 0.8));
|
||||||
|
Engine.NotificationManager.Notify(
|
||||||
|
`Sold Lv. ${this.dragAndDroppingGem.gem.level} ${
|
||||||
|
this.dragAndDroppingGem.gem.definition.name
|
||||||
|
} for ${Math.ceil(sellFor * 0.8)} gold.`,
|
||||||
|
'info'
|
||||||
|
);
|
||||||
|
Engine.GameScene.MissionStats.takeGem(this.dragAndDroppingGem.gem);
|
||||||
|
this.isDragAndDroppingGem = false;
|
||||||
|
this.dragAndDroppingGem = null;
|
||||||
|
this.RebuildInventoryVisual();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let wantToUpgrade = this.isOverlappingGemsmith(
|
||||||
|
this.dragAndDroppingGem,
|
||||||
|
Engine.GameScene.sidebar.gemsmith.upgradeVGem,
|
||||||
|
Engine.GameScene.sidebar.gemsmith.container
|
||||||
|
);
|
||||||
|
if (wantToUpgrade) {
|
||||||
|
if (this.dragAndDroppingGem.gem.isMaxLevel())
|
||||||
|
Engine.NotificationManager.Notify('Gem is max level.', 'warn');
|
||||||
|
else {
|
||||||
|
let cost =
|
||||||
|
this.dragAndDroppingGem.gem.definition.genericImprovements[
|
||||||
|
this.dragAndDroppingGem.gem.level
|
||||||
|
].gemValueUp;
|
||||||
|
if (Engine.GameScene.MissionStats.hasEnoughGold(cost)) {
|
||||||
|
Engine.GameScene.MissionStats.spendGold(cost);
|
||||||
|
this.dragAndDroppingGem.gem.levelUp(1);
|
||||||
|
Engine.NotificationManager.Notify(
|
||||||
|
`Spent ${cost} gold to upgrade ${this.dragAndDroppingGem.gem.definition.name} Lv. ${
|
||||||
|
this.dragAndDroppingGem.gem.level - 1
|
||||||
|
} -> Lv. ${this.dragAndDroppingGem.gem.level}!`,
|
||||||
|
'warn'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Engine.NotificationManager.Notify(
|
||||||
|
"You don't have enough, you need " + cost + ' gold to upgrade this gem.',
|
||||||
|
'warn'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.isDragAndDroppingGem = false;
|
||||||
|
this.dragAndDroppingGem = null;
|
||||||
|
this.RebuildInventoryVisual();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
Engine.GameScene.towerPanel.vGems.forEach((internVG) => {
|
Engine.GameScene.towerPanel.vGems.forEach((internVG) => {
|
||||||
if (overlapping || !this.dragAndDroppingGem) return;
|
if (overlapping || !this.dragAndDroppingGem) return;
|
||||||
let ddbb = this.dragAndDroppingGem.copyContainerToBB();
|
let ddbb = this.dragAndDroppingGem.copyContainerToBB();
|
||||||
@ -132,7 +200,7 @@ export default class GemTab extends GuiObject {
|
|||||||
let y = Engine.GameScene.towerPanel.container.y + vb.y;
|
let y = Engine.GameScene.towerPanel.container.y + vb.y;
|
||||||
|
|
||||||
let vgbb = new PIXI.Rectangle(x, y, vb.width, vb.height);
|
let vgbb = new PIXI.Rectangle(x, y, vb.width, vb.height);
|
||||||
console.log(ddbb, vgbb, ddbb.getBounds().intersects(vgbb));
|
// console.log(ddbb, vgbb, ddbb.getBounds().intersects(vgbb));
|
||||||
if (ddbb.getBounds().intersects(vgbb)) {
|
if (ddbb.getBounds().intersects(vgbb)) {
|
||||||
if (internVG && internVG.gem == null) overlapping = internVG;
|
if (internVG && internVG.gem == null) overlapping = internVG;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ export default class Gemsmith extends GuiObject {
|
|||||||
public sellVGem: VisualGemSlot;
|
public sellVGem: VisualGemSlot;
|
||||||
public upgradeVGem: VisualGemSlot;
|
public upgradeVGem: VisualGemSlot;
|
||||||
|
|
||||||
|
// ! NOTE: Gemsmith logic is contained within GemTab.ts
|
||||||
constructor(bounds: PIXI.Rectangle) {
|
constructor(bounds: PIXI.Rectangle) {
|
||||||
super(false);
|
super(false);
|
||||||
this.bounds = bounds;
|
this.bounds = bounds;
|
||||||
|
@ -179,7 +179,9 @@ export default class Tooltip extends GuiObject {
|
|||||||
this.gemDescriptionText.alpha = 1;
|
this.gemDescriptionText.alpha = 1;
|
||||||
|
|
||||||
this.titleText.text = `Lv. ${gem.level} ` + gem.definition.name;
|
this.titleText.text = `Lv. ${gem.level} ` + gem.definition.name;
|
||||||
this.gemDescriptionText.text = gem.definition.description;
|
this.gemDescriptionText.text =
|
||||||
|
`Valued at ${gem.definition.initialGemValue + gem.currentGemImprovement().gemValueUp} gold. ` +
|
||||||
|
gem.definition.description;
|
||||||
}
|
}
|
||||||
public Show(x, y) {
|
public Show(x, y) {
|
||||||
this.container.alpha = 1;
|
this.container.alpha = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user