From 477b51bd9f8d87d6e880761359422b6bc5422ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 22 Apr 2015 22:03:59 +0200 Subject: [PATCH] Added display of temporary effects in ship list (no graphics yet) --- TODO | 3 ++- src/app/game/LootTemplate.ts | 2 +- src/app/game/effects/AttributeLimitEffect.ts | 6 ++++- src/app/game/effects/AttributeMaxEffect.ts | 4 ++++ src/app/game/effects/AttributeValueEffect.ts | 4 ++++ src/app/game/effects/TemporaryEffect.ts | 5 ++++ .../game/events/EffectDurationChangedEvent.ts | 2 +- src/app/view/battle/EffectDisplay.ts | 15 ++++++++++++ src/app/view/battle/LogProcessor.ts | 13 ++++++++++ src/app/view/battle/ShipListItem.ts | 24 +++++++++++++------ 10 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 src/app/view/battle/EffectDisplay.ts diff --git a/TODO b/TODO index 76ae6a3..25fbb83 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ -* Display active effects on ships * Add a cheat system, to use for development (win battle, revive killed ship ...) * Add a defeat screen (game over for now) * Add a victory screen, with looting * Add retreat from battle +* Refactor the tooltip system to use it more +* Flash ship icons that receive damage \ No newline at end of file diff --git a/src/app/game/LootTemplate.ts b/src/app/game/LootTemplate.ts index d42a91c..29b688d 100644 --- a/src/app/game/LootTemplate.ts +++ b/src/app/game/LootTemplate.ts @@ -155,7 +155,7 @@ module SpaceTac.Game { min_duration: number = 1, max_duration: number = null): void { var template = new EffectTemplate(effect); template.addModifier("value", new Range(min_value, max_value)); - template.addModifier("duration", new Range(min_duration, max_duration)); + template.addModifier("duration", new IntegerRange(min_duration, max_duration)); this.target_effects.push(template); } diff --git a/src/app/game/effects/AttributeLimitEffect.ts b/src/app/game/effects/AttributeLimitEffect.ts index 32b8dfe..54f8ff7 100644 --- a/src/app/game/effects/AttributeLimitEffect.ts +++ b/src/app/game/effects/AttributeLimitEffect.ts @@ -25,5 +25,9 @@ module SpaceTac.Game { ship.setAttribute(ship.attributes.getRawAttr(this.attrcode), this.value); } } - } + + getFullCode(): string { + return this.code + "-" + AttributeCode[this.attrcode].toLowerCase().replace("_", ""); + } + } } diff --git a/src/app/game/effects/AttributeMaxEffect.ts b/src/app/game/effects/AttributeMaxEffect.ts index 5209e6a..af1185c 100644 --- a/src/app/game/effects/AttributeMaxEffect.ts +++ b/src/app/game/effects/AttributeMaxEffect.ts @@ -18,5 +18,9 @@ module SpaceTac.Game { this.attrcode = attrcode; this.value = value; } + + getFullCode(): string { + return this.code + "-" + AttributeCode[this.attrcode].toLowerCase().replace("_", ""); + } } } diff --git a/src/app/game/effects/AttributeValueEffect.ts b/src/app/game/effects/AttributeValueEffect.ts index 86027d9..c919fe4 100644 --- a/src/app/game/effects/AttributeValueEffect.ts +++ b/src/app/game/effects/AttributeValueEffect.ts @@ -18,5 +18,9 @@ module SpaceTac.Game { this.attrcode = attrcode; this.value = value; } + + getFullCode(): string { + return this.code + "-" + AttributeCode[this.attrcode].toLowerCase().replace("_", ""); + } } } diff --git a/src/app/game/effects/TemporaryEffect.ts b/src/app/game/effects/TemporaryEffect.ts index 451e89a..1e1bfe6 100644 --- a/src/app/game/effects/TemporaryEffect.ts +++ b/src/app/game/effects/TemporaryEffect.ts @@ -26,5 +26,10 @@ module SpaceTac.Game { singleApply(ship: Ship, on_stick: boolean): void { // Abstract } + + // Get a full code, that can be used to identify this effect (for example: "attrlimit-aprecovery") + getFullCode(): string { + return this.code; + } } } diff --git a/src/app/game/events/EffectDurationChangedEvent.ts b/src/app/game/events/EffectDurationChangedEvent.ts index c846b15..124e1ef 100644 --- a/src/app/game/events/EffectDurationChangedEvent.ts +++ b/src/app/game/events/EffectDurationChangedEvent.ts @@ -12,7 +12,7 @@ module SpaceTac.Game { previous: number; constructor(ship: Ship, effect: TemporaryEffect, previous: number) { - super("effectadd", ship); + super("effectduration", ship); this.effect = effect; this.previous = previous; diff --git a/src/app/view/battle/EffectDisplay.ts b/src/app/view/battle/EffectDisplay.ts new file mode 100644 index 0000000..f698035 --- /dev/null +++ b/src/app/view/battle/EffectDisplay.ts @@ -0,0 +1,15 @@ +module SpaceTac.View { + "use strict"; + + // Icon to display an effect currently applied on a ship + export class EffectDisplay extends Phaser.Image { + constructor(game: Phaser.Game, effect: Game.TemporaryEffect) { + var key = "battle-effect-" + effect.getFullCode(); + super(game, 115, 22, key, 0); + + var style = {font: "bold 12px Arial", fill: "#d0d020"}; + var duration = new Phaser.Text(this.game, 0, 0, effect.duration.toString(), style); + this.addChild(duration); + } + } +} diff --git a/src/app/view/battle/LogProcessor.ts b/src/app/view/battle/LogProcessor.ts index c803fac..431be1c 100644 --- a/src/app/view/battle/LogProcessor.ts +++ b/src/app/view/battle/LogProcessor.ts @@ -54,6 +54,11 @@ module SpaceTac.View { case "endbattle": this.processEndBattleEvent(event); break; + case "effectadd": + case "effectduration": + case "effectdel": + this.processEffectEvent(event); + break; } } @@ -141,5 +146,13 @@ module SpaceTac.View { // TODO Game over ? } } + + // Temporary effect on ship added, changed or removed + private processEffectEvent(event: Game.BaseLogEvent): void { + var item = this.view.ship_list.findItem(event.ship); + if (item) { + item.updateEffects(); + } + } } } diff --git a/src/app/view/battle/ShipListItem.ts b/src/app/view/battle/ShipListItem.ts index 161d4bc..7c6e1db 100644 --- a/src/app/view/battle/ShipListItem.ts +++ b/src/app/view/battle/ShipListItem.ts @@ -30,6 +30,9 @@ module SpaceTac.View { // Enemy indicator layer_enemy: Phaser.Image; + // Active effects group + active_effects: Phaser.Group; + // Create a ship button for the battle ship list constructor(list: ShipList, x: number, y: number, ship: Game.Ship, owned: boolean) { this.ship = ship; @@ -61,23 +64,32 @@ module SpaceTac.View { this.layer_hover.visible = false; this.addChild(this.layer_hover); - this.hull = ValueBar.newStyled(list.battleview.game, "battle-shiplist-hull", 76, 23); + this.hull = ValueBar.newStyled(list.battleview.game, "battle-shiplist-hull", 76, 26); this.addChild(this.hull); - this.shield = ValueBar.newStyled(list.battleview.game, "battle-shiplist-shield", 76, 35); + this.shield = ValueBar.newStyled(list.battleview.game, "battle-shiplist-shield", 76, 44); this.addChild(this.shield); - this.ap = ValueBar.newStyled(list.battleview.game, "battle-shiplist-ap", 76, 47); - this.addChild(this.ap); + this.active_effects = new Phaser.Group(this.game); + this.addChild(this.active_effects); this.updateAttributes(); + this.updateEffects(); } // Update attributes from associated ship updateAttributes() { this.attributeChanged(this.ship.hull); this.attributeChanged(this.ship.shield); - this.attributeChanged(this.ship.ap_current); + } + + // Update effects applied on the ship + updateEffects() { + this.active_effects.removeAll(true); + this.ship.temporary_effects.forEach((effect: Game.TemporaryEffect) => { + var icon = new EffectDisplay(this.game, effect); + this.active_effects.addChild(icon); + }); } // Called when an attribute for this ship changed through the battle log @@ -86,8 +98,6 @@ module SpaceTac.View { this.hull.setValue(attribute.current, attribute.maximal); } else if (attribute.code === Game.AttributeCode.Shield) { this.shield.setValue(attribute.current, attribute.maximal); - } else if (attribute.code === Game.AttributeCode.AP) { - this.ap.setValue(attribute.current, attribute.maximal); } }