Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Implement Basic Stats #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 84 additions & 25 deletions lib/entity.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

// TODO have Entity inherit from Fabric.Vector
const crypto = require('crypto');

function Entity (entity) {
Expand All @@ -10,16 +9,39 @@ function Entity (entity) {
this.type = entity.type || 'Unknown';
this.name = entity.name || this.id;

this.experience = 0;
this.EXP = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid changing the name of properties on templates, since other parts of the program most likely depend on them. Also, as a general rule, try to keep all properties human-friendly — there's no need to shorten variable names in modern languages!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I'll change it back to this.experience

this.statPoints = 15;

this.equipment = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scanned over the rest of the file; is equipment just being removed? Same feedback as earlier comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't intend to remove equipment completely, that may have been something I was trying to accomplish but meant to undo.

armor: null,
weapon: null
this.stats = {
attack: 0,
agility: 0,
vitality: 0,
invocation: 0,
influence: 0,
shielding: 0,
smarts: 0,
willpower: 0,
charm: 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, that's a lot of different stats! Let's coordinate out-of-band to go over the player experience.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's potential for slimming the amount down. Or at least subdividing them to make them reader-friendly (original subdivisions were physical, magical, and mental).

};

this.stats = {
strength: 0,
luck: 0
this.derrivedStats = {
damage: 0,
hp: 0,
mDamage: 0,
enchantments: 0,
mHP: 0,
library: 0,
ap: 0,
summons: 0
};

this.cardLibrary = {
attackCards: 0,
itemCards: 0,
summonCards: 0,
spellCards: 0,
enchantCards: 0,
leylineCards: 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two new properties seem like they should be simplified and variable names thought about a bit more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are meant to be "maximum" variables, so the names should likely be changed to represent this, or they should be condensed -- or maximums removed entirely. Not sure.

};

this.effects = {};
Expand All @@ -29,29 +51,66 @@ function Entity (entity) {
return this;
}

Object.defineProperty(Entity.prototype, 'level', {
Copy link
Member

@martindale martindale Apr 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to stick around, as it's used elsewhere.

get: function level () {
if (this.experience) {
return Math.floor(Math.log(this.experience / 10));
} else {
return 0;
}
Object.defineProperty(Entity.prototype, 'attack', {
get: function attack () {
Entity.derrivedStats.damage = Entity.stats.attack;

return Entity.stats.attack;
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to use Object.defineProperty() if the value isn't calculated on the fly. Just do something like this:

Suggested change
});
this.attack = `foo`;

If you're just looking for the raw statistic, you can remove these entirely.


Object.defineProperty(Entity.prototype, 'agility', {
get: function agility () {
return Entity.stats.agility;
}
});

Object.defineProperty(Entity.prototype, 'vitality', {
get: function vitality () {
Entity.derrivedStats.hp = (Entity.stats.vitality * 10);
return this.stats.vitality;
}
});

Object.defineProperty(Entity.prototype, 'invocation', {
get: function invocation () {
Entity.derrivedStats.mDamage = Entity.stats.invocation;
return this.stats.invocation;
}
});

Object.defineProperty(Entity.prototype, 'influence', {
get: function influence () {
Entity.derrivedStats.enchantments = 1 + (Entity.stats.influence);
return this.stats.influence;
}
});

Object.defineProperty(Entity.prototype, 'shielding', {
get: function shielding () {
Entity.derrivedStats.mhp = 1 + ((Entity.stats.shielding) * 5);
return this.stats.shielding;
}
});

Object.defineProperty(Entity.prototype, 'smarts', {
get: function smarts () {
Entity.derrivedStats.library = 10 + ((Entity.stats.smarts) * 5);
return this.stats.smarts;
}
});

Object.defineProperty(Entity.prototype, 'strength', {
get: function strength () {
return this.stats.strength;
Object.defineProperty(Entity.prototype, 'willpower', {
get: function willpower () {
Entity.derrivedStats.ap = 1 + Entity.stats.willpower;
return this.stats.willpower;
}
});

Object.defineProperty(Entity.prototype, 'luck', {
get: function luck () {
if (this.effects && this.effects.blessed) {
return this.stats.luck * 2;
} else {
return this.stats.luck;
}
Object.defineProperty(Entity.prototype, 'charm', {
get: function charm () {
Entity.derrivedStats.summons = 1 + Entity.stats.charm;
return this.stats.charm;
}
});

Expand Down