1
0
Fork 0

Renaming to StickyEffect

This commit is contained in:
Michaël Lemaire 2017-01-24 00:07:54 +01:00
parent a6990d9b91
commit 0a822e705e
16 changed files with 47 additions and 49 deletions

View file

@ -86,7 +86,7 @@ module SpaceTac.Game {
var result: string[] = []; var result: string[] = [];
this.target_effects.forEach(effect => { this.target_effects.forEach(effect => {
let suffix = this.blast ? `on all ships in ${this.blast}km of impact` : "on target"; let suffix = this.blast ? `on all ships in ${this.blast}km of impact` : "on target";
if (effect instanceof TemporaryEffect) { if (effect instanceof StickyEffect) {
suffix = `for ${effect.duration} turn${effect.duration > 1 ? "s" : ""} ${suffix}`; suffix = `for ${effect.duration} turn${effect.duration > 1 ? "s" : ""} ${suffix}`;
} }
result.push("- " + effect.getDescription() + " " + suffix); result.push("- " + effect.getDescription() + " " + suffix);

View file

@ -149,7 +149,7 @@ module SpaceTac.Game {
} }
// Convenience function to add a sticking effect on target // Convenience function to add a sticking effect on target
addTemporaryEffectOnTarget(effect: TemporaryEffect, min_value: number, max_value: number = null, addSticky(effect: StickyEffect, min_value: number, max_value: number = null,
min_duration: number = 1, max_duration: number = null): void { min_duration: number = 1, max_duration: number = null): void {
var template = new EffectTemplate(effect); var template = new EffectTemplate(effect);
template.addModifier("value", new IntegerRange(min_value, max_value)); template.addModifier("value", new IntegerRange(min_value, max_value));

View file

@ -119,15 +119,15 @@ module SpaceTac.Game.Specs {
expect(battle.log.events.length).toBe(0); expect(battle.log.events.length).toBe(0);
}); });
it("sets and logs temporary effects", function () { it("sets and logs sticky effects", function () {
var ship = new Ship(); var ship = new Ship();
var battle = new Battle(ship.fleet); var battle = new Battle(ship.fleet);
var effect = new TemporaryEffect("test", 2); var effect = new StickyEffect("test", 2);
ship.addTemporaryEffect(effect); ship.addStickyEffect(effect);
expect(ship.temporary_effects).toEqual([effect]); expect(ship.sticky_effects).toEqual([effect]);
expect(battle.log.events).toEqual([ expect(battle.log.events).toEqual([
new EffectAddedEvent(ship, effect) new EffectAddedEvent(ship, effect)
]); ]);
@ -136,25 +136,25 @@ module SpaceTac.Game.Specs {
battle.log.clear(); battle.log.clear();
ship.endTurn(); ship.endTurn();
expect(ship.temporary_effects).toEqual([new TemporaryEffect("test", 1)]); expect(ship.sticky_effects).toEqual([new StickyEffect("test", 1)]);
expect(battle.log.events).toEqual([ expect(battle.log.events).toEqual([
new EffectDurationChangedEvent(ship, new TemporaryEffect("test", 1), 2) new EffectDurationChangedEvent(ship, new StickyEffect("test", 1), 2)
]); ]);
ship.startTurn(); ship.startTurn();
battle.log.clear(); battle.log.clear();
ship.endTurn(); ship.endTurn();
expect(ship.temporary_effects).toEqual([]); expect(ship.sticky_effects).toEqual([]);
expect(battle.log.events).toEqual([ expect(battle.log.events).toEqual([
new EffectRemovedEvent(ship, new TemporaryEffect("test", 1)) new EffectRemovedEvent(ship, new StickyEffect("test", 1))
]); ]);
ship.startTurn(); ship.startTurn();
battle.log.clear(); battle.log.clear();
ship.endTurn(); ship.endTurn();
expect(ship.temporary_effects).toEqual([]); expect(ship.sticky_effects).toEqual([]);
expect(battle.log.events).toEqual([]); expect(battle.log.events).toEqual([]);
}); });

View file

@ -43,8 +43,8 @@ module SpaceTac.Game {
// Number of shield points (a shield can absorb some damage to protect the hull) // Number of shield points (a shield can absorb some damage to protect the hull)
shield: Attribute; shield: Attribute;
// Sticky temporary effects // Sticky effects that applies a given number of times
temporary_effects: TemporaryEffect[]; sticky_effects: StickyEffect[];
// Capabilities level // Capabilities level
cap_material: Attribute; cap_material: Attribute;
@ -86,7 +86,7 @@ module SpaceTac.Game {
this.cap_human = this.newAttribute(AttributeCode.Cap_Human); this.cap_human = this.newAttribute(AttributeCode.Cap_Human);
this.cap_time = this.newAttribute(AttributeCode.Cap_Time); this.cap_time = this.newAttribute(AttributeCode.Cap_Time);
this.cap_gravity = this.newAttribute(AttributeCode.Cap_Gravity); this.cap_gravity = this.newAttribute(AttributeCode.Cap_Gravity);
this.temporary_effects = []; this.sticky_effects = [];
this.slots = []; this.slots = [];
this.arena_x = 0; this.arena_x = 0;
@ -235,7 +235,7 @@ module SpaceTac.Game {
this.updateAttributes(); this.updateAttributes();
// Apply sticky effects // Apply sticky effects
this.temporary_effects.forEach((effect: TemporaryEffect) => { this.sticky_effects.forEach((effect: StickyEffect) => {
effect.singleApply(this, false); effect.singleApply(this, false);
}); });
} }
@ -253,7 +253,7 @@ module SpaceTac.Game {
// Decrement sticky effects duration // Decrement sticky effects duration
let removed_effects: EffectRemovedEvent[] = []; let removed_effects: EffectRemovedEvent[] = [];
this.temporary_effects = this.temporary_effects.filter((effect: TemporaryEffect): boolean => { this.sticky_effects = this.sticky_effects.filter((effect: StickyEffect): boolean => {
if (effect.duration <= 1) { if (effect.duration <= 1) {
removed_effects.push(new EffectRemovedEvent(this, effect)); removed_effects.push(new EffectRemovedEvent(this, effect));
return false; return false;
@ -261,17 +261,17 @@ module SpaceTac.Game {
return true; return true;
} }
}); });
this.temporary_effects.forEach(effect => { this.sticky_effects.forEach(effect => {
effect.duration -= 1; effect.duration -= 1;
this.addBattleEvent(new EffectDurationChangedEvent(this, effect, effect.duration + 1)); this.addBattleEvent(new EffectDurationChangedEvent(this, effect, effect.duration + 1));
}); });
removed_effects.forEach(effect => this.addBattleEvent(effect)); removed_effects.forEach(effect => this.addBattleEvent(effect));
} }
// Add a temporary effect // Add a sticky effect
// A copy of the effect will be used // A copy of the effect will be used
addTemporaryEffect(effect: TemporaryEffect, log: boolean = true): void { addStickyEffect(effect: StickyEffect, log: boolean = true): void {
this.temporary_effects.push(Tools.copyObject(effect)); this.sticky_effects.push(Tools.copyObject(effect));
if (log) { if (log) {
this.addBattleEvent(new EffectAddedEvent(this, effect)); this.addBattleEvent(new EffectAddedEvent(this, effect));
} }

View file

@ -1,9 +1,9 @@
/// <reference path="TemporaryEffect.ts"/> /// <reference path="StickyEffect.ts"/>
module SpaceTac.Game { module SpaceTac.Game {
// Hard limitation on attribute value // Hard limitation on attribute value
// For example, this could be used to slow a target by limiting its action points // For example, this could be used to slow a target by limiting its action points
export class AttributeLimitEffect extends TemporaryEffect { export class AttributeLimitEffect extends StickyEffect {
// Affected attribute // Affected attribute
attrcode: AttributeCode; attrcode: AttributeCode;

View file

@ -2,7 +2,7 @@
module SpaceTac.Game { module SpaceTac.Game {
// Base class for effects of actions // Base class for effects of actions
// Effects can be permanent or temporary (for a number of turns) // Effects are typically one shot, but sticky effects can be used to apply effects over a period
export class BaseEffect extends Serializable { export class BaseEffect extends Serializable {
// Identifier code for the type of effect // Identifier code for the type of effect
code: string; code: string;

View file

@ -2,7 +2,7 @@
module SpaceTac.Game { module SpaceTac.Game {
// Base class for actions that will stick to a target for a number of rounds // Base class for actions that will stick to a target for a number of rounds
export class TemporaryEffect extends BaseEffect { export class StickyEffect extends BaseEffect {
// Duration, in number of turns // Duration, in number of turns
duration: number; duration: number;
@ -14,7 +14,7 @@ module SpaceTac.Game {
} }
applyOnShip(ship: Ship): boolean { applyOnShip(ship: Ship): boolean {
ship.addTemporaryEffect(this); ship.addStickyEffect(this);
this.singleApply(ship, true); this.singleApply(ship, true);
return true; return true;
} }

View file

@ -10,13 +10,13 @@ module SpaceTac.Game.Specs {
spyOn(equipment.action, "canBeUsed").and.returnValue(true); spyOn(equipment.action, "canBeUsed").and.returnValue(true);
expect(target.ap_current.current).toBe(7); expect(target.ap_current.current).toBe(7);
expect(target.temporary_effects).toEqual([]); expect(target.sticky_effects).toEqual([]);
// Attribute is immediately limited // Attribute is immediately limited
equipment.action.apply(null, ship, Target.newFromShip(target)); equipment.action.apply(null, ship, Target.newFromShip(target));
expect(target.ap_current.current).toBe(4); expect(target.ap_current.current).toBe(4);
expect(target.temporary_effects).toEqual([ expect(target.sticky_effects).toEqual([
new AttributeLimitEffect(AttributeCode.AP, 1, 4) new AttributeLimitEffect(AttributeCode.AP, 1, 4)
]); ]);
@ -25,7 +25,7 @@ module SpaceTac.Game.Specs {
target.startTurn(); target.startTurn();
expect(target.ap_current.current).toBe(4); expect(target.ap_current.current).toBe(4);
expect(target.temporary_effects).toEqual([ expect(target.sticky_effects).toEqual([
new AttributeLimitEffect(AttributeCode.AP, 1, 4) new AttributeLimitEffect(AttributeCode.AP, 1, 4)
]); ]);
@ -33,7 +33,7 @@ module SpaceTac.Game.Specs {
target.endTurn(); target.endTurn();
expect(target.ap_current.current).toBe(6); expect(target.ap_current.current).toBe(6);
expect(target.temporary_effects).toEqual([]); expect(target.sticky_effects).toEqual([]);
}); });
}); });
} }

View file

@ -10,7 +10,7 @@ module SpaceTac.Game.Equipments {
this.ap_usage = new IntegerRange(4, 5); this.ap_usage = new IntegerRange(4, 5);
this.min_level = new IntegerRange(1, 3); this.min_level = new IntegerRange(1, 3);
this.addTemporaryEffectOnTarget(new AttributeLimitEffect(AttributeCode.AP), 4, 3, 1, 2); this.addSticky(new AttributeLimitEffect(AttributeCode.AP), 4, 3, 1, 2);
} }
} }
} }

View file

@ -1,12 +1,12 @@
/// <reference path="BaseLogEvent.ts"/> /// <reference path="BaseLogEvent.ts"/>
module SpaceTac.Game { module SpaceTac.Game {
// Event logged when a TemporaryEffect is added to a ship // Event logged when a sticky effect is added to a ship
export class EffectAddedEvent extends BaseLogEvent { export class EffectAddedEvent extends BaseLogEvent {
// Pointer to the effect // Pointer to the effect
effect: TemporaryEffect; effect: StickyEffect;
constructor(ship: Ship, effect: TemporaryEffect) { constructor(ship: Ship, effect: StickyEffect) {
super("effectadd", ship); super("effectadd", ship);
this.effect = effect; this.effect = effect;

View file

@ -1,15 +1,15 @@
/// <reference path="BaseLogEvent.ts"/> /// <reference path="BaseLogEvent.ts"/>
module SpaceTac.Game { module SpaceTac.Game {
// Event logged when a TemporaryEffect is added to a ship // Event logged when a sticky effect is added to a ship
export class EffectDurationChangedEvent extends BaseLogEvent { export class EffectDurationChangedEvent extends BaseLogEvent {
// Pointer to the effect // Pointer to the effect
effect: TemporaryEffect; effect: StickyEffect;
// Previous duration // Previous duration
previous: number; previous: number;
constructor(ship: Ship, effect: TemporaryEffect, previous: number) { constructor(ship: Ship, effect: StickyEffect, previous: number) {
super("effectduration", ship); super("effectduration", ship);
this.effect = effect; this.effect = effect;

View file

@ -1,12 +1,12 @@
/// <reference path="BaseLogEvent.ts"/> /// <reference path="BaseLogEvent.ts"/>
module SpaceTac.Game { module SpaceTac.Game {
// Event logged when a TemporaryEffect is removed from a ship // Event logged when a sticky effect is removed from a ship
export class EffectRemovedEvent extends BaseLogEvent { export class EffectRemovedEvent extends BaseLogEvent {
// Pointer to the effect // Pointer to the effect
effect: TemporaryEffect; effect: StickyEffect;
constructor(ship: Ship, effect: TemporaryEffect) { constructor(ship: Ship, effect: StickyEffect) {
super("effectdel", ship); super("effectdel", ship);
this.effect = effect; this.effect = effect;

View file

@ -142,7 +142,7 @@ module SpaceTac.View {
} }
} }
// Temporary effect on ship added, changed or removed // Sticky effect on ship added, changed or removed
private processEffectEvent(event: Game.BaseLogEvent): void { private processEffectEvent(event: Game.BaseLogEvent): void {
var item = this.view.ship_list.findItem(event.ship); var item = this.view.ship_list.findItem(event.ship);
if (item) { if (item) {

View file

@ -71,9 +71,9 @@ module SpaceTac.View {
// Update effects applied on the ship // Update effects applied on the ship
updateEffects() { updateEffects() {
this.active_effects.removeAll(true); this.active_effects.removeAll(true);
var count = this.ship.temporary_effects.length; var count = this.ship.sticky_effects.length;
var spacing = (8 * (count - 1) > 72) ? 72 / (count - 1) : 8; var spacing = (8 * (count - 1) > 72) ? 72 / (count - 1) : 8;
this.ship.temporary_effects.forEach((effect, index) => { this.ship.sticky_effects.forEach((effect, index) => {
var x = 46 - (count - 1) * spacing / 2 + index * spacing; var x = 46 - (count - 1) * spacing / 2 + index * spacing;
var badge = new Phaser.Image(this.game, x, 85, `battle-shiplist-effect-${effect.isBeneficial() ? "good" : "bad"}`); var badge = new Phaser.Image(this.game, x, 85, `battle-shiplist-effect-${effect.isBeneficial() ? "good" : "bad"}`);
badge.anchor.set(0.5, 0.5); badge.anchor.set(0.5, 0.5);

View file

@ -102,7 +102,7 @@ module SpaceTac.View {
this.attr_gravity.setText(ship.cap_gravity.current.toString()); this.attr_gravity.setText(ship.cap_gravity.current.toString());
this.attr_time.setText(ship.cap_time.current.toString()); this.attr_time.setText(ship.cap_time.current.toString());
this.active_effects.removeAll(true); this.active_effects.removeAll(true);
ship.temporary_effects.forEach((effect, index) => { ship.sticky_effects.forEach((effect, index) => {
this.addEffect(effect, index); this.addEffect(effect, index);
}); });
@ -112,8 +112,8 @@ module SpaceTac.View {
} }
} }
// Add a temporary effect display // Add a sticky effect display
addEffect(effect: Game.TemporaryEffect, index = 0) { addEffect(effect: Game.StickyEffect, index = 0) {
var effect_group = new Phaser.Image(this.game, 27, 243 + 60 * index, "battle-ship-tooltip-effect"); var effect_group = new Phaser.Image(this.game, 27, 243 + 60 * index, "battle-ship-tooltip-effect");
this.active_effects.addChild(effect_group); this.active_effects.addChild(effect_group);

View file

@ -14,9 +14,7 @@
"sourceMap": true, "sourceMap": true,
"target": "es5" "target": "es5"
}, },
"exclude": [ "include": [
"out", "src"
"coverage",
"node_modules"
] ]
} }