Skip to content

Commit

Permalink
Fix static resources not showing enchanted ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeldruck committed Jan 4, 2024
1 parent 406e8b5 commit 6de873a
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 80 deletions.
5 changes: 2 additions & 3 deletions scripts/Drawings/HarvestablesDrawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class HarvestablesDrawing extends DrawingUtils {
{
draw = "Logs_" + harvestableOne.tier + "_" + harvestableOne.charges;
}

else if (type >= 6 && type <= 10)
{
draw = "rock_" + harvestableOne.tier + "_" + harvestableOne.charges;
Expand All @@ -72,7 +71,7 @@ export class HarvestablesDrawing extends DrawingUtils {
draw = "ore_" + harvestableOne.tier + "_" + harvestableOne.charges;
}

if (draw == undefined)
if (draw === undefined)
continue;

/*if (this.settings.harvestingFiber && (type >= 11 && type <= 14)) {
Expand Down Expand Up @@ -105,7 +104,7 @@ export class HarvestablesDrawing extends DrawingUtils {
// Change Resources to Animals/LHarvestables (living harvestables)
this.DrawCustomImage(ctx, point.x, point.y, draw, "Resources", 50);

// ???
// TODO
/*if (this.settings.harvestingSize) {
this.drawText(point.x, point.y +25 + 10, harvestableOne.size, ctx);
Expand Down
99 changes: 57 additions & 42 deletions scripts/Drawings/MobsDrawing.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,83 @@
export class MobsDrawing extends DrawingUtils {


constructor(Settings) {

export class MobsDrawing extends DrawingUtils
{
constructor(Settings)
{
super(Settings);

}

interpolate(mobs, mists , lpX, lpY, t) {








for (const mobOne of mobs) {
interpolate(mobs, mists, lpX, lpY, t)
{
for (const mobOne of mobs)
{
const hX = -1 * mobOne.posX + lpX;
const hY = mobOne.posY - lpY;
if (mobOne.hY == 0 && mobOne.hX == 0) {

if (mobOne.hY == 0 && mobOne.hX == 0)
{
mobOne.hX = hX;
mobOne.hY = hY;

}

mobOne.hX = this.lerp(mobOne.hX, hX, t);
mobOne.hY = this.lerp(mobOne.hY, hY, t);
}

for (const mistOne of mists) {
for (const mistOne of mists)
{
const hX = -1 * mistOne.posX + lpX;
const hY = mistOne.posY - lpY;
if (mistOne.hY == 0 && mistOne.hX == 0) {

if (mistOne.hY == 0 && mistOne.hX == 0)
{
mistOne.hX = hX;
mistOne.hY = hY;

}

mistOne.hX = this.lerp(mistOne.hX, hX, t);
mistOne.hY = this.lerp(mistOne.hY, hY, t);
}





}

invalidate(ctx, mobs, mists)
{
for (const mobOne of mobs)
{
if (mobOne.type == 3 && !this.settings.mobBoss)
if (mobOne.type == EnemyType.Boss && !this.settings.bossEnemies)
{
continue;
}
else if(mobOne.type == 4 && !this.settings.drones)
else if (mobOne.type == EnemyType.Drone && !this.settings.doneEnemies)
{
continue;
}
else
{
if (!this.settings.mobEnchants[mobOne.enchantmentLevel])
{
continue;
}
if (mobOne.type == 0 || mobOne.type == 1 && !this.settings.mobTiers[mobOne.tier - 1])
// TODO
// Check tier and enchant for each type
/*if (mobOne.type == 0 || mobOne.type == 1 && !this.settings.mobTiers[mobOne.tier - 1])
{
continue;
}
if (!this.settings.mobEnchants[mobOne.enchantmentLevel])
{
continue;
}*/
}


const point = this.transformPoint(mobOne.hX, mobOne.hY);

if (mobOne.type == 1)
if (mobOne.type == EnemyType.LivingSkinnable)
{
// Change folder to animals
this.DrawCustomImage(ctx, point.x, point.y, "hide_" + mobOne.tier + "_" + mobOne.enchantmentLevel, "Resources", 40);
}
else if (mobOne.type == 0)
else if (mobOne.type == EnemyType.LivingHarvestable)
{
if (myString.includes("wood"))
// Change folder to animals
if (mobOne.name.includes("wood"))
{
this.DrawCustomImage(ctx, point.x, point.y, "Logs_" + mobOne.tier + "_" + mobOne.enchantmentLevel, "Resources", 40);
}
Expand All @@ -87,17 +86,20 @@ export class MobsDrawing extends DrawingUtils {
this.DrawCustomImage(ctx, point.x, point.y, mobOne.name + "_" + mobOne.tier + "_" + mobOne.enchantmentLevel, "Resources", 40);
}
}
else if (mobOne.type == 3)
else if (mobOne.type == EnemyType.Boss)
{
// Change folder to enemies
this.DrawCustomImage(ctx, point.x, point.y, this.name, "Resources", 40);

}
else if (mobOne.type == 4)
else if (mobOne.type == EnemyType.Drone)
{
// Change folder to enemies
this.DrawCustomImage(ctx, point.x, point.y, "droneicon", "Resources", 40);
}
else
{
// TODO
if (mobOne.enchantmentLevel == 1)
{
this.drawFilledCircle(ctx, point.x, point.y, 15, "green");
Expand All @@ -120,31 +122,44 @@ export class MobsDrawing extends DrawingUtils {
}
}

let drawHp = false;
let drawId = false;

if (this.settings.mobHp)
if (mobOne.type == EnemyType.LivingHarvestable || mobOne.type == EnemyType.LivingSkinnable)
{
const textWidth = ctx.measureText(mobOne.health).width;
drawHp = this.settings.livingResourcesHp;
drawId = this.settings.livingResourcesID;
}
else
{
drawHp = this.settings.enemiesHP;
drawId = this.settings.enemiesID;
}

if (drawHp)
{
const textWidth = ctx.measureText(mobOne.health).width;
this.drawTextItems(point.x - textWidth /2, point.y + 24, mobOne.health, ctx, "12px", "yellow");
}

if (this.settings.mobDevMode)
if (drawId)
{
this.drawText(point.x, point.y - 20, mobOne.typeId, ctx);
}
}

/* Mist portals */
for (const mistsOne of mists)
{
if (!this.settings.mistEnchants[mistsOne.enchant])
{
continue;
}

if (this.settings.mistSolo && mistsOne.type == 0 || this.settings.mistDuo == true && mistsOne.type == 1)
if ((this.settings.mistSolo && mistsOne.type == 0) || (this.settings.mistDuo == true && mistsOne.type == 1))
{
// Change image folder
const point = this.transformPoint(mistsOne.hX, mistsOne.hY);

this.DrawCustomImage(ctx, point.x, point.y, "mist_" + mistsOne.enchant, "Resources", 30);
}
}
Expand Down
99 changes: 64 additions & 35 deletions scripts/Handlers/HarvestablesHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
class Harvestable {
constructor(id, type, tier, posX, posY, charges, size) {
const HarvestableType =
{
Fiber: 'Fiber',
Hide: 'Hide',
Log: 'Log',
Ore: 'Ore',
Rock: 'Rock'
};

class Harvestable
{
constructor(id, type, tier, posX, posY, charges, size)
{
this.id = id;
this.type = type;
this.tier = tier;
Expand All @@ -12,28 +23,18 @@
this.size = size;
}

setCharges(charges) {
setCharges(charges)
{
this.charges = charges;
}
}

const HarvestableType =
{
Fiber: 'Fiber',
Hide: 'Hide',
Log: 'Log',
Ore: 'Ore',
Rock: 'Rock'
};

class HarvestablesHandler
{
constructor(settings)
{
this.harvestableList = [];
this.settings = settings;


}

addHarvestable(id, type, tier, posX, posY, charges, size)
Expand Down Expand Up @@ -74,18 +75,58 @@ class HarvestablesHandler
}


const index = this.harvestableList.findIndex((item) => item.id === id);
var harvestable = this.harvestableList.find((item) => item.id === id);

if (index === -1)
if (!harvestable)
{
const h = new Harvestable(id, type, tier, posX, posY, charges, size);
this.harvestableList.push(h);
//console.log("New Harvestable: " + h.toString());
}
else // ???
else // update
{
harvestable.setCharges(charges);
}
}

UpdateHarvestable(id, type, tier, posX, posY, charges, size)
{
switch (this.GetStringType(type))
{
case HarvestableType.Fiber:
if (!this.settings.harvestingFiberTiers[tier - 1] || !this.settings.harvestingFiberEnchants[charges]) return;
break;

case HarvestableType.Hide:
if (!this.settings.harvestingHideTiers[tier - 1] || !this.settings.harvestingHideEnchants[charges]) return;
break;

case HarvestableType.Log:
if (!this.settings.harvestingLogTiers[tier - 1] || !this.settings.harvestingLogEnchants[charges]) return;
break;

case HarvestableType.Ore:
if (!this.settings.harvestingOreTiers[tier - 1] || !this.settings.harvestingOreEnchants[charges]) return;
break;

case HarvestableType.Rock:
if (!this.settings.harvestingRockTiers[tier - 1] || !this.settings.harvestingRockEnchants[charges]) return;
break;

default:
return;
}

var harvestable = this.harvestableList.find((item) => item.id === id);

if (!harvestable)
{
this.harvestableList[index].setCharges(charges);
this.addHarvestable(id, type, tier, posX, posY, charges, size);
return;
}

harvestable.charges = charges;
harvestable.size = size;
}

harvestFinished( Parameters)
Expand All @@ -100,28 +141,16 @@ class HarvestablesHandler

// Normally work with everything
// Good
newHarvestableObject(id, Parameters) // From dead monster harvestable
newHarvestableObject(id, Parameters) // Update
{
const type = Parameters[5];
const tier = Parameters[7];
const location = Parameters[8];

let enchant = 0;
let size = 0;

try
{
size = Parameters[10];
}
catch (ignored) { }

try
{
enchant = Parameters[11];
}
catch (ignored) { }
let enchant = Parameters[11] === undefined ? 0 : Parameters[11];
let size = Parameters[10] === undefined ? 0 : Parameters[10];

this.addHarvestable(id, type, tier, location[0], location[1], enchant, size);
this.UpdateHarvestable(id, type, tier, location[0], location[1], enchant, size);
}

base64ToArrayBuffer(base64)
Expand All @@ -139,7 +168,7 @@ class HarvestablesHandler

// Normally work with everything
// Good
newSimpleHarvestableObject(Parameters) // Static harvestable objects
newSimpleHarvestableObject(Parameters) // New
{
const a0 = Parameters[0];

Expand Down

0 comments on commit 6de873a

Please sign in to comment.