Added random shops in the universe
This commit is contained in:
parent
33ec46e27a
commit
658960743b
2
TODO
2
TODO
|
@ -6,6 +6,7 @@
|
|||
* Character sheet: when transferring to another ship, if the item can't be equipped (unmatched requirements), the transfer is cancelled instead of trying cargo
|
||||
* Character sheet: effective skill is sometimes not updated when upgrading base skill
|
||||
* Menu: end appear animation when a button is clicked
|
||||
* Menu: allow to delete cloud saves
|
||||
* Add permanent effects to ship models to ease balancing
|
||||
* Find incentives to move from starting position
|
||||
* Fix targetting not resetting when using action shortcuts
|
||||
|
@ -41,7 +42,6 @@
|
|||
* AI: evaluate based on simulated list of effects
|
||||
* Map: restore fog of war
|
||||
* Map: add information on current star/location + information on hovered location
|
||||
* Map: generate random shops
|
||||
* Map: remove jump links that cross the radius of other systems
|
||||
* Map: disable interaction (zoom, selection) while moving/jumping
|
||||
* Menu: fix background stars aggregating at right side when the game is not focused
|
||||
|
|
|
@ -82,7 +82,7 @@ module TS.SpaceTac.Specs {
|
|||
expect(session.getBattle()).toBeNull();
|
||||
let start_location = nn(session.player.fleet.location);
|
||||
expect(start_location.shop).not.toBeNull();
|
||||
expect(nn(start_location.shop).stock.length).toBe(50);
|
||||
expect(nn(start_location.shop).getStock().length).toBeGreaterThan(20);
|
||||
expect(start_location.encounter).toBeNull();
|
||||
expect(start_location.encounter_gen).toBe(true);
|
||||
});
|
||||
|
|
|
@ -2,14 +2,12 @@ module TS.SpaceTac.Specs {
|
|||
describe("Shop", () => {
|
||||
it("generates a stock", () => {
|
||||
let shop = new Shop();
|
||||
expect(shop.stock.length).toBe(0);
|
||||
|
||||
shop.generateStock(8, 1);
|
||||
expect(shop.stock.length).toBe(8);
|
||||
expect((<any>shop).stock.length).toBe(0);
|
||||
expect(shop.getStock().length).toBeGreaterThan(20);
|
||||
});
|
||||
|
||||
it("buys and sells items", function () {
|
||||
let shop = new Shop();
|
||||
let shop = <any>new Shop();
|
||||
let equ1 = new Equipment(SlotType.Shield, "shield");
|
||||
equ1.price = 50;
|
||||
let equ2 = new Equipment(SlotType.Hull, "hull");
|
||||
|
|
|
@ -3,24 +3,51 @@ module TS.SpaceTac {
|
|||
* A shop is a place to buy/sell equipments
|
||||
*/
|
||||
export class Shop {
|
||||
// Average level of equipment
|
||||
private level: number
|
||||
|
||||
// Approximative number of equipments
|
||||
private count: number
|
||||
|
||||
// Equipment in stock
|
||||
stock: Equipment[] = [];
|
||||
private stock: Equipment[]
|
||||
|
||||
// Random generator
|
||||
private random: RandomGenerator
|
||||
|
||||
constructor(level = 1, stock: Equipment[] = [], count = 40) {
|
||||
this.level = level;
|
||||
this.stock = stock;
|
||||
this.count = count;
|
||||
this.random = new RandomGenerator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available stock to display
|
||||
*/
|
||||
getStock() {
|
||||
if (this.stock.length < this.count * 0.5) {
|
||||
let count = this.random.randInt(Math.floor(this.count * 0.8), Math.ceil(this.count * 1.2));
|
||||
this.stock = this.stock.concat(this.generateStock(count - this.stock.length, this.level, this.random));
|
||||
this.sortStock();
|
||||
}
|
||||
|
||||
return this.stock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random stock
|
||||
*
|
||||
* *level* is the preferential level, but equipment around it may be generated
|
||||
*/
|
||||
generateStock(items: number, level: number, random = RandomGenerator.global) {
|
||||
private generateStock(items: number, level: number, random = RandomGenerator.global): Equipment[] {
|
||||
let generator = new LootGenerator(random);
|
||||
|
||||
this.stock = nna(range(items).map(() => {
|
||||
return nna(range(items).map(() => {
|
||||
let equlevel = random.weighted(range(level + 3).map(i => i + 1).map(i => (i > level) ? 1 : i)) + 1;
|
||||
let quality = random.weighted([1, 7, 2]);
|
||||
return generator.generate(equlevel, quality);
|
||||
}));
|
||||
|
||||
this.sortStock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,11 +47,8 @@ module TS.SpaceTac {
|
|||
/**
|
||||
* Add a shop in this location
|
||||
*/
|
||||
addShop(generate_items = 0) {
|
||||
this.shop = new Shop();
|
||||
if (generate_items) {
|
||||
this.shop.generateStock(generate_items, 1);
|
||||
}
|
||||
addShop(level = this.star.level) {
|
||||
this.shop = new Shop(level);
|
||||
}
|
||||
|
||||
// Set the jump destination of a WARP location
|
||||
|
|
|
@ -29,6 +29,8 @@ module TS.SpaceTac {
|
|||
});
|
||||
|
||||
this.setEncounterLevels();
|
||||
|
||||
this.addShops();
|
||||
}
|
||||
|
||||
// Generate a given number of stars, not too crowded
|
||||
|
@ -174,6 +176,19 @@ module TS.SpaceTac {
|
|||
this.stars.forEach(star => star.level = Math.round(star.level));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add random shops
|
||||
*/
|
||||
addShops(): void {
|
||||
this.stars.forEach(star => {
|
||||
star.locations.forEach(location => {
|
||||
if (this.random.random() > 0.6) {
|
||||
location.addShop(star.level);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a good start location
|
||||
*/
|
||||
|
|
|
@ -326,7 +326,7 @@ module TS.SpaceTac.UI {
|
|||
* Change the page displayed in loot/shop section
|
||||
*/
|
||||
paginate(offset: number) {
|
||||
let items = this.shop ? this.shop.stock : this.loot_items;
|
||||
let items = this.shop ? this.shop.getStock() : this.loot_items;
|
||||
this.loot_page = clamp(this.loot_page + offset, 0, 1 + Math.floor(items.length / 12));
|
||||
this.refresh();
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ module TS.SpaceTac.UI {
|
|||
this.loot_slots.removeAll(true);
|
||||
|
||||
let info = CharacterSheet.getSlotPositions(12, 588, 354, 196, 196);
|
||||
let items = this.shop ? this.shop.stock : this.loot_items;
|
||||
let items = this.shop ? this.shop.getStock() : this.loot_items;
|
||||
range(per_page).forEach(idx => {
|
||||
let loot_slot = this.shop ? new CharacterShopSlot(this, info.positions[idx].x, info.positions[idx].y) : new CharacterLootSlot(this, info.positions[idx].x, info.positions[idx].y);
|
||||
loot_slot.scale.set(info.scaling, info.scaling);
|
||||
|
|
|
@ -14,8 +14,7 @@ module TS.SpaceTac.UI.Specs {
|
|||
ship.addCargo(equ1)
|
||||
|
||||
let equ2 = new Equipment(SlotType.Weapon, "equ2");
|
||||
let shop = new Shop();
|
||||
shop.stock = [equ2];
|
||||
let shop = <any>new Shop(1, [equ2], 0);
|
||||
spyOn(shop, "getPrice").and.returnValue(120);
|
||||
sheet.setShop(shop);
|
||||
sheet.show(ship);
|
||||
|
|
|
@ -7,7 +7,7 @@ module TS.SpaceTac.UI {
|
|||
export class CharacterShopSlot extends CharacterLootSlot {
|
||||
addEquipment(equipment: CharacterEquipment, source: CharacterEquipmentContainer | null, test: boolean): boolean {
|
||||
let shop = this.sheet.shop;
|
||||
if (shop && !contains(shop.stock, equipment.item)) {
|
||||
if (shop && !contains(shop.getStock(), equipment.item)) {
|
||||
if (test) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -20,7 +20,7 @@ module TS.SpaceTac.UI {
|
|||
|
||||
removeEquipment(equipment: CharacterEquipment, destination: CharacterEquipmentContainer | null, test: boolean): boolean {
|
||||
let shop = this.sheet.shop;
|
||||
if (shop && contains(shop.stock, equipment.item)) {
|
||||
if (shop && contains(shop.getStock(), equipment.item)) {
|
||||
let price = shop.getPrice(equipment.item);
|
||||
if (test) {
|
||||
return price <= this.sheet.fleet.credits;
|
||||
|
|
Loading…
Reference in a new issue