var deadImpA = { components: [
	{
		c: AudioSourceComponent,
		d: {
			autoPlay: "civilianDying",
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_FLOOR,
			sheet: "impA",
			name: "impA",
			defaultAnimationName: "dead",
		}
	},
	{
		c: BodyComponent
	},
	{
		c: AudioSourceComponent,
		d: {
			autoPlay: "dying",
		}
	},
	{
		c: ColliderComponent,
		d: {
			width: 1*0.7,
			height: 1*1.25
		}
	},
	{
		c: RigidBodyComponent,
		d: {
			isDynamic: true
		}
	},
]};

var deadImpB = { components: [
	{
		c: AudioSourceComponent,
		d: {
			autoPlay: "civilianDying",
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_FLOOR,
			sheet: "impB",
			name: "impB",
			defaultAnimationName: "dead",
		}
	},
	{
		c: BodyComponent
	},
	{
		c: AudioSourceComponent,
		d: {
			autoPlay: "dying",
		}
	},
	{
		c: ColliderComponent,
		d: {
			width: 1*0.7,
			height: 1*1.25
		}
	},
	{
		c: RigidBodyComponent,
		d: {
			isDynamic: true
		}
	},
]};

var aimingReticle = { components: [
	{
		c: TransformComponent,
		d: {
			scaleX: 0.6,
			scaleY: 0.6,
			ignoreParentRotation: true
			//x: 1.2,
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_IN_GAME_UI,
			sheet: "ingame-ui",
			name: "ui-reticle",
			alpha: 0.6
		}
	},
]};

var aimingLine = { components: [
	{
		c: TransformComponent,
		d: {
			scaleX: 2,
			scaleY: 3,
			y: -0.6,
			//x: 1.2,
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_IN_GAME_UI,
			sheet: "ingame-ui",
			name: "ui-reticle-line",
			alpha: 0.3,
			tint: 0xfc6565,
		}
	},
]};

var aimingReticleNull = { components: [
	{
		c: TransformComponent,
		d: {
			y: 1.8,
		//	ignoreParentRotation: true
			//x: 1.2,
		}
	},
], children: [
	aimingReticle,
	aimingLine
]};

// START MULTIPLAYER GOONS

var multiplayerGoonBase = { extend: goonBase, tag: "goon", components: [
	{
		c: DirectControlComponent,
		d: {
		}
	},
	{
		c: GamepadComponent,
		d: {
		}
	},
	{
		c: AIComponent,
		d: {
			brain: "directControlGoon",
		}
	},
	{
		c: SelectableComponent,
		d: {
			indicatorDefinition: { components: [{ c: TransformComponent }] }
		}
	},
	{
		c: InventoryComponent,
		d: {
			items: [
				"fistItem",
				"oldPistolItem",
				"handgunAmmoStarter",
				"uziAmmoStarter",
				"shotgunAmmoStarter",
			]
		}
	},


], children: [
	aimingReticleNull,
]};


var multiplayerGoonA = { extend: multiplayerGoonBase, components: [
	{
		c: TransformComponent
	},
	{
		c: SpriteComponent,
		d: {
			sheet:"goons",
			name: "goonA",
		}
	},
	{
		c: CharacterInfoComponent,
		d: {
			definition: characterInfo,
			name: "Joey"
		}
	},
]};

var multiplayerGoonB = { extend: multiplayerGoonBase, components: [
	{
		c: TransformComponent
	},
	{
		c: SpriteComponent,
		d: {
			sheet:"goonB",
			name: "goonB",
		}
	},
	{
		c: HealthComponent,
		d: {
			spawnAsBody: {
				base: ["deadGoonB"],
			},
		}
	},
	{
		c: CharacterInfoComponent,
		d: {
			definition: characterInfo,
			name: "Cramer"
		}
	},
]};

var multiplayerGoonC = { extend: multiplayerGoonBase, components: [
	{
		c: TransformComponent
	},
	{
		c: SpriteComponent,
		d: {
			sheet:"goonC",
			name: "goonC",
		}
	},
	{
		c: HealthComponent,
		d: {
			spawnAsBody: {
				base: ["deadGoonC"],
			},
		}
	},
	{
		c: CharacterInfoComponent,
		d: {
			definition: characterInfo,
			name: "Gregory"
		}
	},
]};

var multiplayerGoonD = { extend: multiplayerGoonBase, components: [
	{
		c: TransformComponent
	},
	{
		c: SpriteComponent,
		d: {
			sheet:"goonD",
			name: "goonD",
		}
	},
	{
		c: SteeringComponent,
		d: {
			currentMode: "walk",
			modes: {
				walk: {
					maxSpeed: 15.0,
					maxAngularSpeed: 160.0,
					stepInterval: 0.45,
				},
				run: {
					maxSpeed: 20.0,
					maxAngularSpeed: 160.0,
					stepInterval: 0.375,
				}
			},
		}
	},
	{
		c: HealthComponent,
		d: {
			spawnAsBody: {
				base: ["deadGoonD"],
			},
		}
	},
	{
		c: CharacterInfoComponent,
		d: {
			definition: characterInfo,
			name: "Melissa"
		}
	},
]};

// END MULTIPLAYER GOONS

// START DEATHMATCH GOONS

var deathmatchGoonBase = { extend: goonBase, tag: "goon", components: [
	{
		c: DirectControlComponent,
		d: {
		}
	},
	{
		c: GamepadComponent,
		d: {
		}
	},
	{
		c: AIComponent,
		d: {
			brain: "directControlGoon",
		}
	},
	{
		c: SelectableComponent,
		d: {
			indicatorDefinition: { components: [{ c: TransformComponent }] }
		}
	},
	{
		c: RespawnerComponent, d: {
			lives: 3,
			transferComponents: ['DirectControlComponent']
		}
	},
	{
		c: FragCounterComponent, d: {
		}
	},
	{
		c: InventoryComponent,
		d: {
			items: [
				"fistItem",
				"oldPistolItem",
				"handgunAmmoStarter",
				"uziAmmoStarter",
				"shotgunAmmoStarter",
			]
		}
	},


], children: [
	aimingReticleNull,
]};


var deathmatchGoonA = { extend: deathmatchGoonBase, components: [
	{
		c: TransformComponent
	},
	{
		c: SpriteComponent,
		d: {
			sheet:"goons",
			name: "goonA",
		}
	},
	{
		c: RespawnerComponent,
		d: {
			spawn: 'deathmatchGoonA'
		}
	},
	/*
	{
		c: InventoryComponent,
		d: {
			items: [
				"fistItem",
				"oldPistolItem",
				//"tntItem",
				//"wireCutterItem",
			]
		}
	},
	*/
	/*
	{
		c: FaceMenuComponent,
		d: {
			faceSpriteName: "goonA",
			name: "Joey"
		}
	},
	*/
	{
		c: CharacterInfoComponent,
		d: {
			definition: characterInfo,
			name: "Joey"
		}
	},
]};

var deathmatchGoonB = { extend: deathmatchGoonBase, components: [
	{
		c: TransformComponent
	},
	{
		c: SpriteComponent,
		d: {
			sheet:"goonB",
			name: "goonB",
		}
	},
	{
		c: RespawnerComponent,
		d: {
			spawn: 'deathmatchGoonB'
		}
	},
	{
		c: HealthComponent,
		d: {
			spawnAsBody: {
				base: ["deadGoonB"],
			},
		}
	},
	{
		c: CharacterInfoComponent,
		d: {
			definition: characterInfo,
			name: "Cramer"
		}
	},
]};

var deathmatchGoonC = { extend: deathmatchGoonBase, components: [
	{
		c: TransformComponent
	},
	{
		c: SpriteComponent,
		d: {
			sheet:"goonC",
			name: "goonC",
		}
	},
	{
		c: RespawnerComponent,
		d: {
			spawn: 'deathmatchGoonC'
		}
	},
	{
		c: HealthComponent,
		d: {
			spawnAsBody: {
				base: ["deadGoonC"],
			},
		}
	},
	{
		c: CharacterInfoComponent,
		d: {
			definition: characterInfo,
			name: "Gregory"
		}
	},
]};

var deathmatchGoonD = { extend: deathmatchGoonBase, components: [
	{
		c: TransformComponent
	},
	{
		c: SpriteComponent,
		d: {
			sheet:"goonD",
			name: "goonD",
		}
	},
	{
		c: SteeringComponent,
		d: {
			currentMode: "walk",
			modes: {
				walk: {
					maxSpeed: 15.0,
					maxAngularSpeed: 160.0,
					stepInterval: 0.45,
				},
				run: {
					maxSpeed: 20.0,
					maxAngularSpeed: 160.0,
					stepInterval: 0.375,
				}
			},
		}
	},
	{
		c: RespawnerComponent,
		d: {
			spawn: 'deathmatchGoonD'
		}
	},
	{
		c: HealthComponent,
		d: {
			spawnAsBody: {
				base: ["deadGoonD"],
			},
		}
	},
	{
		c: CharacterInfoComponent,
		d: {
			definition: characterInfo,
			name: "Melissa"
		}
	},
]};

// END DEATHMATCH GOONS

var demonBase = { extend: characterBase, components: [
	{
		c: HealthComponent,
	},
	{ // this is for fading in and out based on fog of war
		c: TweenerComponent,
		d: {
			duration: 0.5,
			component: "SpriteComponent",
			field: "alpha",
			firstValueFromTarget: true
		}
	},
	{
		c: FogOfWarTargetComponent,
		d: {
			dontHideIfHasComponent: "UserCommandComponent",
			visualMarkerDefinition: fogOfWarLowVisualThreatTarget,
			auralMarkerDefinition: fogOfWarLowAuralThreatTarget,
			// TODO: maybe this should be in FOVSystem / FOVComponent
			// We cannot disable AudioSourceComponent as then no walk sounds play
			// and therefore no auralMarkerDefinitions are spawned
			enableComponentsWhenVisible: [/*"AudioSourceComponent",*/ "HealthBarComponent"],
			componentParamsWhenVisible: {
				TweenerComponent: {
					values: [0.0, 1.0]
				}
			},
			componentParamsWhenInvisible: {
				TweenerComponent: {
					values: [1.0, 0.0]
				}
			},
			componentParamsWhenInvisibleButNotHidden: {
				TweenerComponent: {
					values: [1.0, 0.25]
				}
			}
		}
	},
	{
		c: AIComponent,
		d: {
			brain: "demon",
		}
	},
]};

var impA = { extend: demonBase, components: [
	{
		c: SpriteComponent,
		d: {
			sheet: "impA",
			name: "impA",
		}
	},
	{
		c: SteeringComponent,
		d: {
			currentMode: "walk",
			modes: {
				walk: {
					maxSpeed: 7.0,
					maxAngularSpeed: 160.0,
					stepInterval: 0.45,
				},
				run: {
					maxSpeed: 10,
					maxAngularSpeed: 160.0,
					stepInterval: 0.375,
				}
			}
		}
	},
	{
		c: AudioAIListenerComponent,
		d: {
			threshold: 0.25 // guards have pretty good hearing (But not as good as goons)
		}
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 100,
			radius: 4,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
		}
	},
	{
		c: InventoryComponent,
		d: {
			items: [
				"stickItem",
				"handgunAmmoPickup",
			]
		}
	},
	{
		c: HealthComponent,
		d: {
			maxHealth: 3,
			currentHealth: 3,
			spawnAsBody: {
				base: ["deadImpA"],
			},
		}
	},
]};

var tinyImpA = { extend: impA, components: [
	{
		c: TransformComponent,
		d: {
			scaleX: 0.6,
			scaleY: 0.6,
		}
	},
	{
		c: HealthComponent,
		d: {
			maxHealth: 1,
			currentHealth: 1,
		}
	},
	{
		c: ColliderComponent,
		d: {
			radius: 0.24 * 0.6,
		}
	},
	{
		c: InventoryComponent,
		d: {
			items: [
				"stickItem",
				"handgunAmmoPickup1",
			]
		}
	},
]};

var impB = { extend: demonBase, components: [
	{
		c: TransformComponent,
		d: {
			scaleX: 1.5,
			scaleY: 1.5,
		}
	},
	{
		c: ColliderComponent,
		d: {
			radius: 0.4,
		}
	},
	{
		c: SpriteComponent,
		d: {
			sheet: "impB",
			name: "impB",
		}
	},
	{
		c: SteeringComponent,
		d: {
			currentMode: "walk",
			modes: {
				walk: {
					maxSpeed: 6.0,
					maxAngularSpeed: 160.0,
					stepInterval: 0.45,
				},
				run: {
					maxSpeed: 7,
					maxAngularSpeed: 160.0,
					stepInterval: 0.375,
				}
			}
		}
	},
	{
		c: AudioAIListenerComponent,
		d: {
			threshold: 0.25 // guards have pretty good hearing (But not as good as goons)
		}
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 100,
			radius: 4,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
		}
	},
	{
		c: InventoryComponent,
		d: {
			items: [
				"stickItem",
				"shotgunAmmo2",
			]
		}
	},
	{
		c: HealthComponent,
		d: {
			maxHealth: 10,
			currentHealth: 10,
			spawnAsBody: {
				base: ["deadImpB"],
			},
		}
	},
]};

var impC = { extend: demonBase, components: [
	{
		c: TransformComponent,
		d: {
			scaleX: 3,
			scaleY: 3,
		}
	},
	{
		c: ColliderComponent,
		d: {
			radius: 0.8,
		}
	},
	{
		c: SpriteComponent,
		d: {
			sheet: "impB",
			name: "impB",
		}
	},
	{
		c: SteeringComponent,
		d: {
			currentMode: "walk",
			modes: {
				walk: {
					maxSpeed: 5.0,
					maxAngularSpeed: 160.0,
					stepInterval: 0.45,
				},
				run: {
					maxSpeed: 6,
					maxAngularSpeed: 160.0,
					stepInterval: 0.375,
				}
			}
		}
	},
	{
		c: AudioAIListenerComponent,
		d: {
			threshold: 0.25 // guards have pretty good hearing (But not as good as goons)
		}
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 120,
			radius: 4,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
		}
	},
	{
		c: InventoryComponent,
		d: {
			items: [
				"stickItem",
				"stolenLoot",
				"stolenLoot",
				"stolenLoot",
			]
		}
	},
	{
		c: HealthComponent,
		d: {
			maxHealth: 60,
			currentHealth: 60,
			spawnAsBody: {
				base: ["deadImpB"],
			},
		}
	},
]};

var portalBase = { extend: slowRandomSpawner, components: [
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OVERHEAD,
			sheet: "fxPortal",
			name: "portal",
			defaultAnimationName: "default",
			loop: true,
			fps: 30
		}
	},
	{
		c: HealthComponent,
		d: {
			currentHealth: 20,
			maxHealth: 20,
			spawnOnZeroHealth: {
				base: ["fxHitWindowADirectional"],
			},
			spawnAsBody: {
				base: ["explosionPortal"],
			},
		}
	},
	{
		c: HealthBarComponent,
		d: {
			onlyDrawIfNotFull: true,
		}
	},
	{
		c: ActionableComponent,
		d: {
			actionDefinitions: [ActionDefinitions.attack, ActionDefinitions.shoot],
		}
	},
	{
		c: ColliderComponent,
		d: {
			radius: 0.3,
			collisionGroup: CollisionCategoryDefinitions.CC_WALLS,
			collidesWith: [CollisionCategoryDefinitions.CC_BULLETS, CollisionCategoryDefinitions.CC_WALLS, CollisionCategoryDefinitions.CC_STATIC_OBSTACLE/*, CollisionCategoryDefinitions.CC_DOORS*/, CollisionCategoryDefinitions.CC_DYNAMIC_OBSTACLE, CollisionCategoryDefinitions.CC_AI_PATH_GENERATION_RAY, CollisionCategoryDefinitions.CC_PLANNING_TARGET, CollisionCategoryDefinitions.CC_OBJECTS, CollisionCategoryDefinitions.CC_LIGHT_DYNAMIC_OBSTACLE],
			senses: [CollisionCategoryDefinitions.CC_AVOIDANCE, CollisionCategoryDefinitions.CC_MOUSE, CollisionCategoryDefinitions.CC_HOTSPOTS, CollisionCategoryDefinitions.CC_PLANNING_TARGET, CollisionCategoryDefinitions.CC_DOORS]
		}
	},

	{
		c: FieldOfViewMarkerComponent,
	},
	{
		c: RigidBodyComponent,
		d: {
			isDynamic: false,
			density: 10,

		}
	},
	{
		c: InventoryComponent,
		d: {
			items: [
				"medkit",
			]
		}
	},
]};

//WAVE 1 - 3 imp spawners
var wave1Spawner = { extend: slowRandomSpawner, components: [
	{
		c: SpawnerComponent,
		d: {
			entityDefinitions: ["impASpawner"],
			maxInWorld: 1,
			timeLeft: 5,
			interval: 500,
		}
	},
]};

//WAVE 2 - 3 imp, 2 bigImp

var wave2Spawner = { extend: slowRandomSpawner, components: [
	{
		c: SpawnerComponent,
		d: {
			entityDefinitions: ["impBSpawner"],
			maxInWorld: 1,
			timeLeft: 30,
			interval: 500,
		}
	},
]};

//WAVE 3 - loads of everything

var wave3ASpawner = { extend: slowRandomSpawner, components: [
	{
		c: SpawnerComponent,
		d: {
			entityDefinitions: ["impBSpawner"],
			maxInWorld: 1,
			timeLeft: 60,
			interval: 300,
		}
	},
]};

var wave3BSpawner = { extend: slowRandomSpawner, components: [
	{
		c: SpawnerComponent,
		d: {
			entityDefinitions: ["tinyImpSpawner"],
			maxInWorld: 1,
			timeLeft: 60,
			interval: 120,
		}
	},
]};

//FINAL WAVE
var waveFinalSpawner = { extend: slowRandomSpawner, components: [
	{
		c: SpawnerComponent,
		d: {
			entityDefinitions: ["impCSpawner"],
			maxInWorld: 1,
			timeLeft: 90,
			interval: 300,
		}
	},
]};
//ENEMIES

var impASpawner = { extend: portalBase, components: [
	{
		c: SpawnerComponent,
		d: {
			entityDefinitions: ["impA"],
			maxInWorld: 2,
			minInterval: 2,
			maxInterval: 4
		}
	},
]};

var impBSpawner = { extend: portalBase, components: [
	{
		c: SpawnerComponent,
		d: {
			entityDefinitions: ["impB"],
			maxInWorld: 1,
			minInterval: 3,
			maxInterval: 5
		}
	},
]};

var impCSpawner = { extend: portalBase, components: [
	{
		c: SpawnerComponent,
		d: {
			entityDefinitions: ["impC"],
			maxInWorld: 1,
			interval: 20,
		}
	},
]};

var tinyImpSpawner = { extend: portalBase, components: [
	{
		c: SpawnerComponent,
		d: {
			entityDefinitions: ["tinyImpA"],
			maxInWorld: 5,
			interval: 1,
		}
	},
]};

