main #48
@ -11,6 +11,11 @@ import {SimpleTemplateGamesystem} from "./templates/simpleGamesystem/SimpleTempl
|
|||||||
import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem";
|
import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem";
|
||||||
import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator";
|
import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator";
|
||||||
import {CharacterRelation} from "./characters/CharacterRelation";
|
import {CharacterRelation} from "./characters/CharacterRelation";
|
||||||
|
import {ItemGroup} from "./inventory/ItemGroup";
|
||||||
|
import {AbstractItemGroup} from "./inventory/AbstractItemGroup";
|
||||||
|
import {GameModelLoader} from "../../../../app/storage/loader/GameModelLoader";
|
||||||
|
import {ConcreteItemGroup} from "./inventory/ConcreteItemGroup";
|
||||||
|
import {Item} from "./inventory/Item";
|
||||||
|
|
||||||
export class GameModel {
|
export class GameModel {
|
||||||
gameModelName: string
|
gameModelName: string
|
||||||
@ -18,9 +23,63 @@ export class GameModel {
|
|||||||
gamesystems: Gamesystem<any, any>[] = [];
|
gamesystems: Gamesystem<any, any>[] = [];
|
||||||
scriptAccounts: ScriptAccount[] = [];
|
scriptAccounts: ScriptAccount[] = [];
|
||||||
characters: Character[] = []
|
characters: Character[] = []
|
||||||
|
itemgroups: ItemGroup[] = []
|
||||||
|
|
||||||
constructor(gameModelName: string) {
|
constructor(gameModelName: string) {
|
||||||
this.gameModelName = gameModelName;
|
this.gameModelName = gameModelName;
|
||||||
|
|
||||||
|
this.addAbstractItemgroup("Clothing", undefined);
|
||||||
|
this.addAbstractItemgroup("Inventory", undefined);
|
||||||
|
this.addConcreteItemgroup("Oberteil", GameModel.findItemgroupByName("Clothing", this.itemgroups)! as AbstractItemGroup);
|
||||||
|
this.addConcreteItemgroup("Hose", GameModel.findItemgroupByName("Clothing", this.itemgroups)! as AbstractItemGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
addAbstractItemgroup(groupName: string, parentgroup: AbstractItemGroup | undefined) {
|
||||||
|
//Ensure that Itemgroup does not exist
|
||||||
|
if(parentgroup == undefined) {
|
||||||
|
if(GameModel.findItemgroupByName(groupName, this.itemgroups) == undefined) {
|
||||||
|
this.itemgroups.push(new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(GameModel.findItemgroupByName(groupName, parentgroup.children) == undefined) {
|
||||||
|
parentgroup.addChildItemgroup(new AbstractItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addConcreteItemgroup(groupName: string, parentgroup: AbstractItemGroup) {
|
||||||
|
//Ensure that Itemgroup does not exist
|
||||||
|
if(parentgroup == undefined) {
|
||||||
|
if(GameModel.findItemgroupByName(groupName, this.itemgroups) == undefined) {
|
||||||
|
this.itemgroups.push(new ConcreteItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(GameModel.findItemgroupByName(groupName, parentgroup.children) == undefined) {
|
||||||
|
parentgroup.addChildItemgroup(new ConcreteItemGroup(groupName, "", ModelComponentType.ITEMGROUP));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addItem(itemName: string, conceteItemgroupName: string) {
|
||||||
|
const itemgroup = GameModel.findItemgroupByName(conceteItemgroupName, this.itemgroups);
|
||||||
|
if(itemgroup instanceof ConcreteItemGroup) {
|
||||||
|
itemgroup.addItem(new Item(itemName, "", ModelComponentType.ITEM ))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static findItemgroupByName(name: string, itemgroups: ItemGroup[]) {
|
||||||
|
const itemgroupQueue: ItemGroup[] = itemgroups.concat();
|
||||||
|
while(itemgroupQueue.length > 0 ) {
|
||||||
|
const currentItemgroup = itemgroupQueue.shift()!;
|
||||||
|
|
||||||
|
if(currentItemgroup.componentName === name) {
|
||||||
|
return currentItemgroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currentItemgroup instanceof AbstractItemGroup) {
|
||||||
|
currentItemgroup.children.forEach(itemgroup => itemgroupQueue.push(itemgroup));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addGamesystem(gamesystem: Gamesystem<any, any>) {
|
addGamesystem(gamesystem: Gamesystem<any, any>) {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
export enum ModelComponentType {
|
export enum ModelComponentType {
|
||||||
SCRIPTACCOUNT,
|
SCRIPTACCOUNT,
|
||||||
GAMESYTEM,
|
GAMESYTEM,
|
||||||
CHARACTER
|
CHARACTER,
|
||||||
|
ITEMGROUP,
|
||||||
|
ITEM
|
||||||
|
|
||||||
}
|
}
|
||||||
|
10
src/app/project/game-model/inventory/AbstractItemGroup.ts
Normal file
10
src/app/project/game-model/inventory/AbstractItemGroup.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import {ItemGroup} from "./ItemGroup";
|
||||||
|
|
||||||
|
export class AbstractItemGroup extends ItemGroup {
|
||||||
|
|
||||||
|
children: ItemGroup[] = [];
|
||||||
|
|
||||||
|
addChildItemgroup(itemGroup: ItemGroup) {
|
||||||
|
this.children.push(itemGroup)
|
||||||
|
}
|
||||||
|
}
|
17
src/app/project/game-model/inventory/ConcreteItemGroup.ts
Normal file
17
src/app/project/game-model/inventory/ConcreteItemGroup.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import {ItemGroup} from "./ItemGroup";
|
||||||
|
import {Item} from "./Item";
|
||||||
|
|
||||||
|
export class ConcreteItemGroup extends ItemGroup {
|
||||||
|
|
||||||
|
items: Item[] = [];
|
||||||
|
|
||||||
|
addItem(item: Item) {
|
||||||
|
if(this.findItemByName(item.componentName) == undefined) {
|
||||||
|
this.items.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
findItemByName(itemName: string) {
|
||||||
|
return this.items.find(item => item.componentName === itemName);
|
||||||
|
}
|
||||||
|
}
|
7
src/app/project/game-model/inventory/Item.ts
Normal file
7
src/app/project/game-model/inventory/Item.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import {ModelComponent} from "../ModelComponent";
|
||||||
|
import {ItemGroup} from "./ItemGroup";
|
||||||
|
|
||||||
|
export class Item extends ModelComponent {
|
||||||
|
|
||||||
|
inheritedGroups: ItemGroup[] = []
|
||||||
|
}
|
7
src/app/project/game-model/inventory/ItemGroup.ts
Normal file
7
src/app/project/game-model/inventory/ItemGroup.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import {ModelComponent} from "../ModelComponent";
|
||||||
|
import {ItemQuality} from "./ItemQuality";
|
||||||
|
|
||||||
|
export abstract class ItemGroup extends ModelComponent {
|
||||||
|
|
||||||
|
requiredItemQualities: ItemQuality[] = []
|
||||||
|
}
|
10
src/app/project/game-model/inventory/ItemQuality.ts
Normal file
10
src/app/project/game-model/inventory/ItemQuality.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export class ItemQuality {
|
||||||
|
|
||||||
|
key: string
|
||||||
|
value: number
|
||||||
|
|
||||||
|
constructor(key: string, value: number) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user