/**
 * This is the part of the alarm that makes a sound and flashes
 */
var alarmUpActive = { components: [
	{
		c: AudioSourceComponent,
		d: {
			autoPlay: "alarm",
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_IN_GAME_UI,
			sheet: "tiles",
			name: "alarmWall",
			defaultAnimationName: "up",
			loop: true,
		}
	},
]};

/**
 * This is the alarm box on the wall
 */
var alarmUp = { components: [
	{
		c: AIComponent,
		d: {
			reactions: [
				{
					name: "activateAlarm",
					triggers: [
						{
							name: "globalFlagChanged",
							params: {
								flagName: "alarm",
								newState: true
							}
						}
					],
					steps: [
						{
							name: "spawnEntityDefinition",
							params: {
								definitions: ["alarmUpActive"]
							}
						},
					]
				}
			]
		}
	}
]};

var alarmLeftActive = { components: [
	{
		c: AudioSourceComponent,
		d: {
			autoPlay: "alarm",
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_IN_GAME_UI,
			sheet: "tiles",
			name: "alarmWall",
			defaultAnimationName: "left",
			loop: true,
		}
	},
]};

/**
 g This is the alarm box on the wall
 */

var alarmLeft = { components: [
	{
		c: AIComponent,
		d: {
			reactions: [
				{
					name: "activateAlarm",
					triggers: [
						{
							name: "globalFlagChanged",
							params: {
								flagName: "alarm",
								newState: true
							}
						}
					],
					steps: [
						{
							name: "spawnEntityDefinition",
							params: {
								definitions: ["alarmLeftActive"]
							}
						},
					]
				}
			]
		}
	}
]};

var alarmRightActive = { components: [
	{
		c: AudioSourceComponent,
		d: {
			autoPlay: "alarm",
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_IN_GAME_UI,
			sheet: "tiles",
			name: "alarmWall",
			defaultAnimationName: "right",
			loop: true,
		}
	},
]};

/**
 * This is the alarm box on the wall
 */
var alarmRight = { components: [
	{
		c: AIComponent,
		d: {
			reactions: [
				{
					name: "activateAlarm",
					triggers: [
						{
							name: "globalFlagChanged",
							params: {
								flagName: "alarm",
								newState: true
							}
						}
					],
					steps: [
						{
							name: "spawnEntityDefinition",
							params: {
								definitions: ["alarmRightActive"]
							}
						},
					]
				}
			]
		}
	}
]};

var securityMonitorPlainScreen = { components: [
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OBJECTS,
			sheet: "tiles",
			name: "securityMonitorPlainScreen",
			loop: false,
		}
	},
	{
		c: TweenerComponent,
		d: {
			component: "SpriteComponent",
			field: "alpha",
			duration: 0.2,
			values: [0.05, 0.3, 0.09, 0.087, 0.09, 0.3],
			repeat: true
		}
	},
	{
		c: TransformComponent,
		d: {
		}
	},
]};

var securityMonitorNiceScreen = { components: [
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OBJECTS,
			sheet: "tiles",
			name: "securityMonitorNiceScreen",
			loop: false,
		}
	},
	{
		c: TweenerComponent,
		d: {
			component: "SpriteComponent",
			field: "alpha",
			duration: 0.2,
			values: [0.05, 0.3, 0.09, 0.087, 0.09, 0.3],
			repeat: true
		}
	},
	{
		c: TransformComponent,
		d: {
		}
	},
]};



var securityBlinker = { components: [
	{
		c: TransformComponent,
		d: {
			x: 14 / 128,
			y: -31 / 128,
			zIndex: 1
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OBJECTS,
			sheet: "tiles",
			name: "securityBlinker",
			defaultAnimationName: "idle",
		}
	},
]};

var securityMonitorCanSeeArea = { components: [
	{
		c: TransformComponent,
		d: {
			x: 80 / 128,
			zIndex: 1
		}
	},
	{
		c: ColliderComponent,
		d: {
			radius: 1,
			collisionGroup: CollisionCategoryDefinitions.CC_HOTSPOTS,
			collidesWith: [],
			senses: [
				CollisionCategoryDefinitions.CC_CHARACTERS,
				CollisionCategoryDefinitions.CC_PLANNING_TARGET
			]
		}
	},
	{
		c: RigidBodyComponent,
		d: {
			isDynamic: false,
			isSensor: true,
			dynamicFriction: 0,
			density: 0,
		}
	},
	{
		c: HotspotComponent,
		d: {
			name: "canSeeCameras",
		}
	},
]};

var securityMonitorPlain = { components: [
	{
		c: TransformComponent,
		d: {
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OBJECTS,
			sheet: "tiles",
			name: "securityMonitorPlainWhole",
			defaultAnimationName: "idle",
			loop: false,
		}
	},
	{
		c: IndicatorComponent,
		d: {
			iconDefinition: indicatorIconBase,
			aboveTextDefinition: indicatorAboveBase,
			belowTextDefinition: indicatorBelowBase,
			overwriteAbove: "Security monitor",
		}
	},
], children: [
	lightTelevision,
	securityMonitorPlainScreen,
	securityBlinker,
	securityMonitorCanSeeArea
]};

var securityMonitorNice = { components: [
	{
		c: TransformComponent,
		d: {
		}
	},
/*	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OBJECTS,
			sheet: "tiles",
			name: "securityMonitorPlainWhole",
			defaultAnimationName: "idle",
			loop: false,
		}
	}, */
	{
		c: IndicatorComponent,
		d: {
			iconDefinition: indicatorIconBase,
			aboveTextDefinition: indicatorAboveBase,
			belowTextDefinition: indicatorBelowBase,
			overwriteAbove: "Security monitor",
		}
	},
], children: [
	lightTelevision,
	securityMonitorNiceScreen,
	securityBlinker,
	securityMonitorCanSeeArea
]};

var alarmButtonAOn = { components: [
	{
	c: TransformComponent,
	d: {
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OBJECTS,
			sheet: "tiles",
			name: "alarmButtonA",
			defaultAnimationName: "alarm",
			loop: true,
			zIndex: 1,
		}
	},
	{
		c: TweenerComponent,
		d: {
			enabled: true,
			component: "SpriteComponent",
			field: "alpha",
			duration: 0.05,
			values: [1.0, 0.75, 0.5, 0.25, 0, 1],
			repeat: true
		}
	},
]};

var alarmButtonA = { components: [
	{
		c: TransformComponent,
		d: {
		}
	},
], children: [
	alarmButtonAOn,
	{ extend: hotspotBase, components: [
			{
				c: TransformComponent,
				d: {
					x: 0.0,
					y: -0.5
				}
			},
			{
				c: ColliderComponent,
				d: {
					radius: 0.25
				}
			},
			{
				c: HotspotComponent,
				d: {
					category: "button",
					group: "alarm",
					facing: 0
				}
			},
			{
				c: ActionableComponent,
				d: {
					actionDefinitions: [ActionDefinitions.callPolice],
				}
			},
		]
	}
]};

var securityCameraBaseBlink = { components: [
	{
		c: TransformComponent,
		d: {
			zIndex: 1
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OVERHEAD,
			sheet: "tiles",
			name: "securityCamera",
			defaultAnimationName: "lightOnly",
			alpha: 0,
		}
	},
	{
		c: TweenerComponent,
		d: {
			component: "SpriteComponent",
			field: "alpha",
			duration: 0.2,
			values: [0.0, 1.0, 0.0],
			repeat: true,
		}
	}
]};

var securityCameraBaseDead = { extend: lightObstacleBase, components: [
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OBJECTS,
			sheet: "tiles",
			name: "securityCamera",
			defaultAnimationName: "dead",
			tint: 0x414141
		}
	},
	{
		c: ColliderComponent,
		d: {
			radius: 0.05
		}
	},
	{
		c: SuspicionIncreaserComponent,
		d:{
			increaseAmount: 0.3,
		}
	},
]};


var securityCameraBase = { components: [
	{
		c: TransformComponent
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 65,
			radius: 2,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
			group: "cameras",
		}
	},
	{
		c: LOSVisualizationComponent,
		d: {
			colorNotSeeing: 0x8888ff,
			colorSeeing: 0xff8888,
			// Do not update on every frame as this it's so expensive
			isStatic: true,
		}
	},
	{
		c: HealthComponent,
		d: {
			currentHealth: 0.5,
			maxHealth: 0.5,
			spawnOnDamage: {
				base: ["fxHitElectric"],
			},
			spawnAsBody: {
				base: ["securityCameraBaseDead"],
			},
		}
	},
	{
		c: ActionableComponent,
		d: {
			actionDefinitions: [ActionDefinitions.shoot],
		}
	},
	{
		c: ColliderComponent,
		d: {
			radius: 0.1 * 1,
			collisionGroup: CollisionCategoryDefinitions.CC_CHARACTERS,
			collidesWith: [CollisionCategoryDefinitions.CC_BULLETS],
			senses: [CollisionCategoryDefinitions.CC_MOUSE, CollisionCategoryDefinitions.CC_HOTSPOTS, CollisionCategoryDefinitions.CC_PLANNING_TARGET]
		}
	},
	{
		c: FieldOfViewMarkerComponent,
	},
	{
		c: RigidBodyComponent,
		d: {
			isDynamic: true,
			density: 1,

		}
	},
], children: [
	securityCameraBaseBlink
]};

var securityCameraSafe = { extend: securityCameraBase, components: [
	{
		c: TransformComponent
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 65,
			radius: 3,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
			group: "cameras",
		}
	},
]};

var securityCameraEntrance = { extend: securityCameraBase, components: [
	{
		c: TransformComponent
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 45,
			radius: 5,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
			group: "cameras",
		}
	},
]};

var securityCameraHideout = { extend: securityCameraBase, components: [
	{
		c: TransformComponent
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 85,
			radius: 4.7,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
			group: "cameras",
		}
	},
]};

var securityCamera60 = { extend: securityCameraBase, components: [
	{
		c: TransformComponent
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 60,
			radius: 6,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
			group: "cameras",
		}
	},
]};

var securityCamera60turningNull = { extend: securityCameraBase, components: [
	{
		c: TransformComponent,
		d: {
		}
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 60,
			radius: 6,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
			group: "cameras",
		}
	},
	{
		c: LOSVisualizationComponent,
		d: {
			colorNotSeeing: 0x8888ff,
			colorSeeing: 0xff8888,
			isStatic: false,
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OVERHEAD,
			sheet: "tiles",
			name: "securityCamera",
			defaultAnimationName: "off",
			alpha: 1,
		}
	},
	{
		c: TweenerComponent,
		d: {
			component: "TransformComponent",
			field: "localRotation",
			duration: 6,
			values: [0 , -Math.PI / 3,0 ,Math.PI / 3 ,0],
			repeat: true
		}
	},
]};

var securityCamera60turning = { components: [
	{
		c: TransformComponent,
		d: {
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_BG,
			sheet: "tiles",
			name: "securityCamera",
			defaultAnimationName: "off",
		}
	},
], children: [
	securityCamera60turningNull,
]};

var securityCamera60Circuit = { extend: securityCameraBase, components: [
	{
		c: TransformComponent
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 60,
			radius: 6,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
			group: "cameras",
		}
	},
	{
		c: CircuitComponent,
		d: {
			toggleComponents: ["FieldOfViewComponent", "LOSVisualizationComponent", "TweenerComponent"],
			onSpawnDefinition: "buzzEffect",
		},
	},
]};

var securityCamera60turningCircuitNull = { extend: securityCameraBase, components: [
	{
		c: TransformComponent,
		d: {
		}
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 60,
			radius: 6,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
			group: "cameras",
		}
	},
	{
		c: LOSVisualizationComponent,
		d: {
			colorNotSeeing: 0x8888ff,
			colorSeeing: 0xff8888,
			isStatic: false,
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_OVERHEAD,
			sheet: "tiles",
			name: "securityCamera",
			defaultAnimationName: "off",
			alpha: 1,
		}
	},
	{
		c: TweenerComponent,
		d: {
			component: "TransformComponent",
			field: "localRotation",
			duration: 6,
			values: [0 , -Math.PI / 3,0 ,Math.PI / 3 ,0],
			repeat: true
		}
	},
	{
		c: CircuitComponent,
		d: {
			toggleComponents: ["FieldOfViewComponent", "LOSVisualizationComponent", "TweenerComponent"],
		//	onSpawnDefinition: "buzzEffect",
			circuit: "camerasA",
		},
	},
]};

var securityCamera60turningCircuit = { components: [
	{
		c: TransformComponent,
		d: {
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_BG,
			sheet: "tiles",
			name: "securityCamera",
			defaultAnimationName: "off",
		}
	},
], children: [
	securityCamera60turningCircuitNull,
]};
