1
0
Fork 0

Add equipment price depreciation by using it

This commit is contained in:
Michaël Lemaire 2017-04-24 19:59:16 +02:00
parent 5a5be8addc
commit 2fb696544f
11 changed files with 182 additions and 14 deletions

1
TODO
View file

@ -4,7 +4,6 @@
* Character sheet: paginate loot and shop items
* Character sheet: improve eye-catching for shop and loot section
* Character sheet: equipping an item without the requirements make it disappear
* Shops: add price depreciation by item's previous usage
* Add permanent effects to ship models to ease balancing
* Ships should start battle in formation to force them to move
* Fix targetting not resetting when using action shortcuts

View file

@ -170,6 +170,40 @@ module TS.SpaceTac {
expect((<EndBattleEvent>battle.log.events[0]).outcome.winner).toBe(fleet2);
});
it("wear down equipment at the end of battle", function () {
let fleet1 = new Fleet();
let ship1a = fleet1.addShip();
let equ1a = TestTools.addWeapon(ship1a);
let ship1b = fleet1.addShip();
let equ1b = TestTools.addWeapon(ship1b);
let fleet2 = new Fleet();
let ship2a = fleet2.addShip();
let equ2a = TestTools.addWeapon(ship2a);
let eng2a = TestTools.addEngine(ship2a, 50);
let battle = new Battle(fleet1, fleet2);
battle.start();
expect(equ1a.wear).toBe(0);
expect(equ1b.wear).toBe(0);
expect(equ2a.wear).toBe(0);
expect(eng2a.wear).toBe(0);
range(8).forEach(() => battle.advanceToNextShip());
expect(equ1a.wear).toBe(0);
expect(equ1b.wear).toBe(0);
expect(equ2a.wear).toBe(0);
expect(eng2a.wear).toBe(0);
battle.endBattle(null);
expect(equ1a.wear).toBe(3);
expect(equ1b.wear).toBe(3);
expect(equ2a.wear).toBe(3);
expect(eng2a.wear).toBe(3);
});
it("handles a draw in end battle", function () {
var fleet1 = new Fleet();
var fleet2 = new Fleet();

View file

@ -128,8 +128,18 @@ module TS.SpaceTac {
return imaterialize(ifilter(this.iships(), ship => (ship.alive || !alive_only) && Target.newFromShip(ship).getDistanceTo(center) <= radius));
}
// Ends a battle and sets the outcome
/**
* Ends a battle and sets the outcome
*/
endBattle(winner: Fleet | null, log = true) {
// Wear down equipment
iforeach(this.iships(), ship => {
ship.listEquipment().forEach(equipment => {
equipment.addWear(this.turn);
});
});
// Prepare broadcast
this.ended = true;
this.outcome = new BattleOutcome(winner);
if (log && this.log) {

View file

@ -77,5 +77,36 @@ module TS.SpaceTac.Specs {
equipment.requirements["skill_electronics"] = 4;
expect(equipment.getMinimumLevel()).toBe(3);
});
it("weighs the price, taking wear into account", function () {
let equipment = new Equipment();
expect(equipment.getPrice()).toBe(0);
equipment.price = 100;
expect(equipment.getPrice()).toBe(100);
equipment.addWear(1);
expect(equipment.getPrice()).toBe(99);
equipment.addWear(10);
expect(equipment.getPrice()).toBe(90);
equipment.addWear(89);
expect(equipment.getPrice()).toBe(50);
equipment.addWear(400);
expect(equipment.getPrice()).toBe(16);
});
it("builds a full textual description", function () {
let equipment = new Equipment();
equipment.name = "Super Equipment";
equipment.requirements["skill_gravity"] = 2;
equipment.effects.push(new AttributeEffect("skill_time", 3));
equipment.wear = 50;
let result = equipment.getFullDescription();
expect(result).toEqual("Second hand\n\nRequires:\n- gravity skill 2\n\nWhen equipped:\n- time skill +3");
});
});
}

View file

@ -45,8 +45,8 @@ module TS.SpaceTac {
// Action available when equipped
action = new BaseAction("nothing", "Do nothing", false)
// Usage made of this equipment (will lower the sell price)
usage: number
// Equipment wear due to usage in battles (will lower the sell price)
wear = 0
// Basic constructor
constructor(slot: SlotType | null = null, code = "equipment") {
@ -88,6 +88,9 @@ module TS.SpaceTac {
if (requirements.length > 0) {
description = "Requires:\n" + requirements.join("\n") + "\n\n" + description;
}
if (this.wear > 0) {
description = (this.wear >= 100 ? "Worn" : "Second hand") + "\n\n" + description;
}
return description;
}
@ -105,7 +108,7 @@ module TS.SpaceTac {
* Get the equipment price value.
*/
getPrice(): number {
return this.price;
return Math.floor(this.price * 100 / (100 + this.wear));
}
/**
@ -156,5 +159,12 @@ module TS.SpaceTac {
return parts.length > 0 ? parts.join("\n\n") : "does nothing";
}
/**
* Add equipment wear
*/
addWear(factor: number): void {
this.wear += factor;
}
}
}

View file

@ -103,14 +103,13 @@ module TS.SpaceTac.Specs {
var battle = new Battle(fleet);
var ship = new Ship(fleet);
ship.setAttribute("hull_capacity", 50);
ship.setAttribute("shield_capacity", 100);
TestTools.setShipHP(ship, 150, 400);
ship.restoreHealth();
battle.log.clear();
ship.addDamage(10, 20);
expect(ship.values.hull.get()).toEqual(40);
expect(ship.values.shield.get()).toEqual(80);
expect(ship.values.hull.get()).toEqual(140);
expect(ship.values.shield.get()).toEqual(380);
expect(battle.log.events.length).toBe(3);
expect(battle.log.events[0]).toEqual(new ValueChangeEvent(ship, ship.values.shield, -20));
expect(battle.log.events[1]).toEqual(new ValueChangeEvent(ship, ship.values.hull, -10));
@ -119,9 +118,14 @@ module TS.SpaceTac.Specs {
battle.log.clear();
ship.addDamage(15, 25, false);
expect(ship.values.hull.get()).toEqual(25);
expect(ship.values.shield.get()).toEqual(55);
expect(ship.values.hull.get()).toEqual(125);
expect(ship.values.shield.get()).toEqual(355);
expect(battle.log.events.length).toBe(0);
ship.addDamage(125, 355, false);
expect(ship.values.hull.get()).toEqual(0);
expect(ship.values.shield.get()).toEqual(0);
expect(ship.alive).toBe(false);
});
it("sets and logs sticky effects", function () {

View file

@ -444,10 +444,19 @@ module TS.SpaceTac {
}
}
// Apply damages to hull and/or shield
/**
* Apply damages to hull and/or shield
*
* Also apply wear to impacted equipment
*/
addDamage(hull: number, shield: number, log: boolean = true): void {
this.setValue("shield", -shield, true, log);
this.setValue("hull", -hull, true, log);
if (shield > 0) {
this.setValue("shield", -shield, true, log);
}
if (hull > 0) {
this.setValue("hull", -hull, true, log);
}
if (log) {
this.addBattleEvent(new DamageEvent(this, hull, shield));

View file

@ -25,5 +25,20 @@ module TS.SpaceTac {
expect(action.checkCannotBeApplied(ship)).toBe("not enough power");
});
it("wears down equipment and power generators", function () {
let ship = new Ship();
TestTools.setShipAP(ship, 10);
let power = ship.listEquipment(SlotType.Power)[0];
let equipment = new Equipment(SlotType.Weapon);
let action = new BaseAction("test", "Test", false, equipment);
expect(power.wear).toBe(0);
expect(equipment.wear).toBe(0);
action.apply(ship, null);
expect(power.wear).toBe(1);
expect(equipment.wear).toBe(1);
});
});
}

View file

@ -106,6 +106,11 @@ module TS.SpaceTac {
return false;
}
if (this.equipment) {
this.equipment.addWear(1);
ship.listEquipment(SlotType.Power).forEach(equipment => equipment.addWear(1));
}
this.customApply(ship, checked_target);
return true;
} else {

View file

@ -0,0 +1,43 @@
module TS.SpaceTac.Specs {
describe("DamageEffect", function () {
it("applies damage and wear", function () {
var ship = new Ship();
TestTools.setShipHP(ship, 150, 400);
let hull = ship.listEquipment(SlotType.Hull)[0];
let shield = ship.listEquipment(SlotType.Shield)[0];
ship.restoreHealth();
expect(ship.getValue("hull")).toEqual(150);
expect(ship.getValue("shield")).toEqual(400);
expect(hull.wear).toBe(0);
expect(shield.wear).toBe(0);
new DamageEffect(50).applyOnShip(ship);
expect(ship.getValue("hull")).toEqual(150);
expect(ship.getValue("shield")).toEqual(350);
expect(hull.wear).toBe(0);
expect(shield.wear).toBe(1);
new DamageEffect(250).applyOnShip(ship);
expect(ship.getValue("hull")).toEqual(150);
expect(ship.getValue("shield")).toEqual(100);
expect(hull.wear).toBe(0);
expect(shield.wear).toBe(4);
new DamageEffect(201).applyOnShip(ship);
expect(ship.getValue("hull")).toEqual(49);
expect(ship.getValue("shield")).toEqual(0);
expect(hull.wear).toBe(2);
expect(shield.wear).toBe(5);
expect(ship.alive).toBe(true);
new DamageEffect(8000).applyOnShip(ship);
expect(ship.getValue("hull")).toEqual(0);
expect(ship.getValue("shield")).toEqual(0);
expect(hull.wear).toBe(3);
expect(shield.wear).toBe(5);
expect(ship.alive).toBe(false);
});
});
}

View file

@ -44,8 +44,16 @@ module TS.SpaceTac {
applyOnShip(ship: Ship): boolean {
let [shield, hull] = this.getEffectiveDamage(ship);
ship.addDamage(hull, shield);
if (shield > 0) {
ship.listEquipment(SlotType.Shield).forEach(equipment => equipment.addWear(Math.ceil(shield * 0.01)));
}
if (hull > 0) {
ship.listEquipment(SlotType.Hull).forEach(equipment => equipment.addWear(Math.ceil(hull * 0.01)));
}
return true;
}