{"size": 1258, "ext": "js", "max_stars_repo_path": "js/entities/effect.js", "max_stars_repo_name": "pjk21/js-rogue", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "js/entities/effect.js", "max_issues_repo_name": "pjk21/js-rogue", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "js/entities/effect.js", "max_forks_repo_name": "pjk21/js-rogue", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.2962962963, "max_line_length": 106, "alphanum_fraction": 0.6581875994}
Core.Effect = function(properties) {
	properties = properties || {};
	
	this.name = properties.name || '';
	
	if (properties.duration) {
		if (typeof properties.duration === 'number') {
			this.duration = properties.duration;
		}
		else if (typeof properties.duration === 'object') {
			this.duration = Core.getRandomNumber(properties.duration.min, properties.duration.max);
		}
	}
	
	this._onApply = properties.onApply || undefined;
	this._onRemove = properties.onRemove || undefined;

	this._onTurnEnd = properties.onTurnEnd || undefined;
};

Core.Effect.prototype = {
	getName: function() {
		return this.name;
	},
	
	apply: function(entity) {
		Core.MessageLog.add('%s has been afflicted with %s!'.format(entity.getName(), this.name), 'warning');
		
		if (this._onApply) {
			this._onApply.call(this, entity);
		}
	},
	
	remove: function(entity) {
		if (this._onRemove) {
			this._onRemove.call(this, entity);
		}
	},
	
	endTurn: function(entity) {
		if (this.duration) {
			this.duration--;
			
			if (this.duration === 0) {
				entity.removeEffect(this.name);
				Core.MessageLog.add('%s is no longer afflicted with %s.'.format(entity.getName(), this.name), 'info');
			}
		}
		
		if (this._onTurnEnd) {
			this._onTurnEnd.call(this, entity);
		}
	}
};