var goonBase = { extend: characterBase, tag: "goon", components: [
	{
		c: FieldOfViewMarkerComponent,
		d: {
			// NPCs might not be able to see goons that are hiding in shadows
			calculateBrightness: true,
		}
	},
	{
		c: IntimidatorComponent,
		d: {
			range: 5.0,
			angle: 50.0,
			power: 0.3,
			equipmentTypes: ["weapon"],
			intimidatorIndicatorDefinition: intimidatorIndicator
		}
	},
	{
		c: SuspectComponent,
	},
	{
		c: TeamComponent,
		d: {
			name: "goons"
		}
	},
	{
		c: SteeringComponent,
		d: {
			currentMode: "walk",
			modes: {
				walk: {
					maxSpeed: 11.0,
					maxAngularSpeed: 160.0,
					stepInterval: 0.45,
				},
				run: {
					maxSpeed: 16.0,
					maxAngularSpeed: 160.0,
					stepInterval: 0.375,
				}
			},
			behaviors: {
				WallAndObstacleAvoidanceBehavior: {
					priority: 1.0,
					weight: 1.0,
					colliderRadius: 0.1,
					forwardFeelerSpeedScaleFactor: 15 * 1,
					sideFeelerDistanceFactor: 0.83,
					sideFeelerMinAngle: Math.PI / 64,
					sideFeelerMaxAngle: Math.PI / 8,
					sideFeelerMaxAngleCollisionCount: 20,
					collisionGroup: CollisionCategoryDefinitions.CC_CHARACTERS,
					collidesWith: [CollisionCategoryDefinitions.CC_WALLS, CollisionCategoryDefinitions.CC_STATIC_OBSTACLE/*, CollisionCategoryDefinitions.CC_DOORS*/]
				},
				WanderBehaviors: {
					priority: 3.0,
					weight: 1.0,
					wanderR: 0.24 * 1,
					wanderD: 1.41421 * 1,
					change: 0.3
				},
				SeekBehavior: {
					priority: 4.0,
					weight: 1.0,
				},
				ArriveBehavior: {
					priority: 5.0,
					weight: 1.0,
					decelerationFactor: 0.9
				},
				PathFollowingBehavior: {
					priority: 6.0,
					weight: 1.0,
					// These are still currently overridden by the PathFollowerComponent
					closeEnoughRadius: 0.10 * 1,
					slowDownRadius: 0.25 * 1,
				},
				AlignBehavior: {
					priority: 7.0,
					weight: 1.0,
				},
				FaceBehavior: {
					priority: 8.0,
					weight: 1.0,
				}
			}
		}
	},
	{
		c: AIPlanVisualizationComponent,
		d: {
			defaultStyle: {
				opacity: 0.10,
				thickness: 0.035,
				color: 0xAB907E,
			},
			styles: {
				UserCommandAINode: { // need to use the full path because of stupid
					opacity: 0.05,
					thickness: 0.02,
					color: 0xAB907E,
				}
			}
		}
	},
	{
		c: TransformComponent
	},
	{
		c: SkillComponent,
		d: {
			skills: [
				{ name: "lockpicking" },
				{ name: "demolition" },
				{ name: "electronics" },
				{ name: "shooting" }
			]
		}
	},
	{
		c: InventoryComponent,
	},
	{
		c: SpriterComponent,
		d: {
			spriterEntityName: "Character",
			// y-sorting might break some characters.
			// this hierarchy needs to be manually sorted
			layer: LayerDefinitions.LAYER_GOONS,
			sheet: "spriterCharacters",
			defaultCharMaps: ["goonNude"]
		}
	},
	{
		c: ColliderComponent,
		d: {
			senses: [
				CollisionCategoryDefinitions.CC_AVOIDANCE,
				CollisionCategoryDefinitions.CC_MOUSE,
				CollisionCategoryDefinitions.CC_HOTSPOTS,
				// Need to sense pickables, which are light dynamic obstacles
				CollisionCategoryDefinitions.CC_LIGHT_DYNAMIC_OBSTACLE,
				 // goons don't sense the planning target
			]
		}
	},
	{
		c: HealthComponent,
		d: {
			maxHealth: 5,
			currentHealth: 5,
			fatalDamageTypes: [
				"blunt",
				"bullet",
				"fire",
				"explosion",
				"acid",
				"drill",
			],
			spawnOnDamage: {
				base: [
					"bulletHitPersonAFlash"
				],
				fist: [
					"bulletHitPersonSmallBFlash",
					"bulletHitPersonSmallCFlash",
				],
				blunt: [
					"bulletHitPersonSmallBFlash",
					"bulletHitPersonSmallCFlash",
				],
			},
			spawnOnZeroHealth: {
				base: ["fxBloodmapA"],
				fist: [],
			},
			spawnAsBody: {
				base: ["deadGoon"],
			},
		}
	},
	{
		c: HealthBarComponent,
	},
	{
		c: AIComponent,
		d: {
			brain: "goon",
		}
	},
	{
		c: AudioAIListenerComponent,
		d: {
			threshold: 0
		}
	},
	{
		c: SpecialActionComponent,
		d: {
			actions: {
				use: {
					anims: ["use"],
				},
				poop: {
					anims: ["sit"],
					minDuration: 2,
					maxDuration: 15,
					showProgress: true
				},
				call: {
					anims: ["use"],
					minDuration: 2,
					maxDuration: 3,
					showProgress: true
				},
				waitingForOrdersAggressive: {
					anims: ["aim"],
					order: "random",
					minDuration: 2,
					maxDuration: 5,
					suspiciousness: 5.0,
				},
				waitingForOrders: {
					//anims: ["idle", "smoke"],
					order: "random",
					minDuration: 2,
					maxDuration: 5,
				},
				loot: {
					anims: ["use"],
					showProgress: true,
					suspiciousness: 1.0,
				},
				fiddleWithLock: {
					anims: ["use"],
					showProgress: true,
					suspiciousness: 2.0,
				},
				disguise: {
					anims: ["use"],
					showProgress: true,
					suspiciousness: 5.0,
					minDuration: 2,
					maxDuration: 2,
				}
			}
		}
	},
	{
		c: FogOfWarObserverComponent,
	},
	{
		c: FieldOfViewComponent,
		d: {
			fov: 360,
			radius: 16,
			nearRadius: 0,
			visionGroup: CollisionCategoryDefinitions.CC_VISION,
			obstructors: [CollisionCategoryDefinitions.CC_WALLS | CollisionCategoryDefinitions.CC_DOORS],
		}
	},
	{
		c: UserCommandComponent,
		d: {
			ownActionDefinitions: [ActionDefinitions.move],
			possibleActionTooltipDefinition: actionTooltip,
			actionIndicatorDefinition: actionIndicator,
			textNotificationDefinition: goonTextNotification,
			idleStateName: "goonWaitingForOrders",
			selectionIndicatorTag: "selectionIndicator",
			snapDistance: 0.3, // in meters
			reach: 0.75, // in meters
			characterMenuParameters: {
				menuDefinition: characterMenu,
				iconDefinition: characterMenuIconBase,
				holdToOpenTime: 0.0
			}
		},
	},
	{
		c: ClickableComponent
	},
	{
		c: SelectableComponent,
		d: {
			indicatorDefinition: selectionIndicator
		}
	},
	{
		c: CharacterInfoComponent,
		d: {
			definition: characterInfo,
			name: "Default"
		}
	},
	], children: [
	offscreenGoonIndicator,
]};

var goonSpawner = { components: [
	{
		c: GoonSpawnComponent,
	},
	{
		c: TransformComponent,
	},
]};

var goonFlyGuyA = { extend: goonBase, components: [
	{
		c: TransformComponent
	},
	{
		c: SpriteComponent,
		d: {
			sheet:"flyGuyA",
			name: "flyGuyA",
		}
	},
	{
		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: "FlyGuy"
		}
	},
], children: [
	characterShadow,
]};

var goonCensored = { components: [
	{
		c: TransformComponent,
		d: {
			ignoreParentRotation: true,
			scaleX: 0.5,
			scaleY: 0.3,
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_IN_GAME_UI,
			sheet: "tiles",
			name: "black",
			defaultAnimationName: "default",
			loop: true,
		}
	},

var goonA = { extend: goonSpawner, components:[
	{
		c:GoonSpawnComponent,
		d: {
			goonIndex: 0,
		}
	},
]};

var goonB = { extend: goonSpawner, components:[
	{
		c:GoonSpawnComponent,
		d: {
			goonIndex: 1,
		}
	},
]};

var goonC = { extend: goonSpawner, components:[
	{
		c:GoonSpawnComponent,
		d: {
			goonIndex: 2,
		}
	},
]};

var goonD = { extend: goonSpawner, components:[
	{
		c:GoonSpawnComponent,
		d: {
			goonIndex: 3,
		}
	},
]};

var goonE = { extend: goonSpawner, components:[
	{
		c:GoonSpawnComponent,
		d: {
			goonIndex: 4,
		}
	},
]};

var goonF = { extend: goonSpawner, components:[
	{
		c:GoonSpawnComponent,
		d: {
			goonIndex: 5,
		}
	},
]};

var goonInfo1 = { components: [
	{
		c: TransformComponent,
		d: {
			x: 1/2,
			y: 0,
			scaleX: 1,
			scaleY: 1,
			zIndex: -1
		}
	},
	{
		c: PixelTextComponent,
		d: {
			text: "This is your first \"Goon\"",
			align: TextAlign.left,
			spacing: -2,
			spaceWidth: 6,
			lineHeight: 60,
			fontDefinition: {
				layer: LayerDefinitions.LAYER_OVERHEAD,
				sheet: "fontGreasyStroke",
				scale: 1 / 3,
				tint: 0xe0b86c,
				alpha: 1
			}
		}
	},
	{
		c: TweenerComponent,
		d: {
			component: "PixelTextComponent",
			field: "alpha",
			duration: 1,
			values: [0, 0, 1, 1, 1, 1, 0],
			repeat: false,
		}
	},
	{
		c: CircuitComponent,
		d: {
			toggleComponents: ["PixelTextComponent", "TweenerComponent"],
			circuit: "goonInfo1"
		}
	},
]};

var goonInfo2 = { extend: goonInfo1, components: [
	{
		c: PixelTextComponent,
		d: {
			text: "You'll use many Goons like him\nto do your dirty work.",
		}
	},
	{
		c: TweenerComponent,
		d: {
			component: "PixelTextComponent",
			field: "alpha",
			duration: 1,
			values: [0, 0, 1, 1, 1, 1, 1, 1, 0],
			repeat: false,
		}
	},
	{
		c: CircuitComponent,
		d: {
			toggleComponents: ["PixelTextComponent", "TweenerComponent"],
			circuit: "goonInfo2"
		}
	},
]};

var goonInfo3 = { extend: goonInfo1, components: [
	{
		c: PixelTextComponent,
		d: {
			text: "First let's find your other goon \n who got stuck on the way",
		}
	},
	{
		c: TweenerComponent,
		d: {
			component: "PixelTextComponent",
			field: "alpha",
			duration: 1,
			values: [0, 0, 1, 1, 1, 1, 1, 1, 0],
			repeat: false,
		}
	},
	{
		c: CircuitComponent,
		d: {
			toggleComponents: ["PixelTextComponent", "TweenerComponent"],
			circuit: "goonInfo3"
		}
	},
]};

var goonInfoNull = { components: [
	{
		c: TransformComponent,
		d: {
			ignoreParentRotation: true,
		}
	},
], children: [
	goonInfo1,
	goonInfo2,
	goonInfo3
]};

var goonTutorial = { extend: goonA, components: [
	{
		c: TransformComponent
	},
], children: [
	goonInfoNull
]};

var disguiseBase = { components: [
	{
		c: TransformComponent,
	},
	{
		c: ColliderComponent,
		d: {
			collisionGroup: CollisionCategoryDefinitions.CC_OBJECTS,
			collidesWith: [CollisionCategoryDefinitions.CC_DYNAMIC_OBSTACLE, CollisionCategoryDefinitions.CC_WALLS, CollisionCategoryDefinitions.CC_STATIC_OBSTACLE, CollisionCategoryDefinitions.CC_DOORS],
			senses: [CollisionCategoryDefinitions.CC_PLANNING_TARGET],
			width: 1*0.7,
			height: 1*1.25
		}
	},
	{
		c: RigidBodyComponent,
		d: {
			isDynamic: true,
			density: 0.001,
		}
	},
	{
		c: IndicatorComponent,
		d: {
			iconDefinition: indicatorIconBase,
			aboveTextDefinition: indicatorAboveBase,
			belowTextDefinition: indicatorBelowBase,
		}
	},
	{
		c: LootableComponent,
		d: {
			lootingTime: 0,
			pickable: true
		}
	},
	{
		c: ItemComponent,
		d: {
			name: "Disguise",
			type: "disguise",
			lootable: true,
			equippable: false,
			inventorySpriteName: "ui-base-icon-disguise-guard",
			stackable: false,
		}
	},
	{
		c: DisguiseComponent,
		d:{
			duration: 1,
			disguiseCharMaps: ["guardA"],
		}
	},
	{
		c: ActionableComponent,
		d: {
			actionDefinitions: [ActionDefinitions.pickup],
		}
	},
	{
		c: SpriteComponent,
		d: {
			layer: LayerDefinitions.LAYER_FLOOR,
			sheet: "inventory",
			name: "itemPickableDisguiseGuard",
		}
	}
]};

var guardDisguise = { extend: disguiseBase, components: [
	{
		c: ItemComponent,
		d: {
			name: "guardUniform",
		},
	},
	{
		c: DisguiseComponent,
		d: {
			disguiseCharMaps: ["guardA"],
			suspiciousnessMultiplier: 0.1,
		}
	}
]};

var flyGuyDisguise = { extend: disguiseBase, components: [
	{
		c: ItemComponent,
		d: {
			name: "flyGuySuit",
		},
	},
	{
		c: DisguiseComponent,
		d: {
			disguiseCharMaps: ["flyGuyA"],
			suspiciousnessMultiplier: 0.03,
		}
	}
]};
