<data>
	<behaviors>
		<!-- Templates -->
		<behaviorTemplate r_name="'behaviorTemplate'" r_enabled="1" r_behaviorAction="'none'"/>
		<behaviorTemplate r_name="'behaviorEffectTemplate'" r_template="'behaviorTemplate'" r_behaviorAction="'executeEffects'"/>
		<behaviorTemplate r_name="'behaviorCompositeTemplate'" r_template="'behaviorTemplate'" r_behaviorAction="'childBehavior'" r_childBehaviorIndex="0"/>

		<behaviorTemplate r_name="'waitEnemyTemplate'" r_template="'behaviorCompositeTemplate'" combatTimer="10" currentMoveTarget="null">
			<behavior r_name="'doNothing'" r_template="'behaviorTemplate'" r_enabled="!wanderingMonster" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_onSuccess="'doNothing'" r_onFailure="'setMoveTarget'"/>
			<behavior r_name="'setMoveTarget'" r_template="'behaviorEffectTemplate'" r_enabled="wanderingMonster" r_onSuccess="'move'" r_onFailure="'waitOnce'">
				<effect r_name="'setBehaviorMoveTarget'" r_template="{'mainSelfEffectTemplate','evaluationEffect'}" r_effect="currentMoveTarget=level.randomEmptySquare()"/>
			</behavior>
			<behavior r_name="'move'" r_template="'behaviorTemplate'" r_enabled="wanderingMonster&&(currentMoveTarget!=null)&&(currentMoveTarget!=square)" r_behaviorAction="'move'" rw_xTarget="currentMoveTarget.w_xCoord" rw_yTarget="currentMoveTarget.w_yCoord" r_onSuccess="'move'" r_onFailure="'waitOnce'"/>
			<behavior r_name="'waitOnce'" r_template="'behaviorTemplate'" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_onSuccess="'setMoveTarget'" r_onFailure="''"/>
		</behaviorTemplate>
		
		<behaviorTemplate r_name="'waitEnemyOrFollowTemplate'" r_template="'behaviorCompositeTemplate'" combatTimer="10">
			<behavior r_name="'additionalPower'" r_template="'behaviorTemplate'" r_enabled="length(additionalPowers)>0" r_behaviorAction="'usePower'" r_powerName="randomElement(additionalPowers)" r_powerTarget="'random'" r_onSuccess="'additionalPower'" r_onFailure="'followMaster'"/>
			<behavior r_name="'followMaster'" r_template="'behaviorTemplate'" r_behaviorAction="'follow'" r_followTarget="master" r_onSuccess="'additionalPower'" r_onFailure="(takeStair&&(attributeByName(master).w_levelIndex!=w_levelIndex))?'searchStair':'doNothing'"/>
			<behavior r_name="'searchStair'" r_template="'behaviorTemplate'"
								r_behaviorAction="'searchActivable'"
								r_activableCategory="'stair'"
								r_activableDisplayName="(attributeByName(master).w_levelIndex>w_levelIndex)?'downstair':'upstair'"
								r_mustSeeActivable="0"
								r_onSuccess="'followMaster'"
								r_onFailure="'doNothing'"/>
			<behavior r_name="'doNothing'" r_template="'behaviorTemplate'" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_onSuccess="'additionalPower'" r_onFailure="''"/>
		</behaviorTemplate>

		<behaviorTemplate r_name="'waitAllyTemplate'" r_template="'behaviorCompositeTemplate'" combatTimer="10">
			<behavior r_name="'doNothing'" r_template="'behaviorTemplate'" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_onSuccess="'checkVisibility'" r_onFailure="''"/>
			<behavior r_name="'checkVisibility'" r_template="'behaviorTemplate'" r_behaviorAction="'checkAlly'" r_onSuccess="'exit'" r_onFailure="'doNothing'"/>
			<behavior r_name="'exit'" r_template="'behaviorTemplate'" r_behaviorAction="'parentBehavior'" r_childSuccess="1" r_onSuccess="''" r_onFailure="''"/>
		</behaviorTemplate>

		<behaviorTemplate r_name="'combatTemplate'" r_template="'behaviorCompositeTemplate'" combatTimer="10" behaviorTimer="0">
			<behavior r_name="'setBehaviorTimer'" r_template="'behaviorEffectTemplate'" r_onSuccess="'additionalPower'" r_onFailure="''">
				<effect r_name="'setBehaviorTimerEffect'" r_template="{'mainSelfEffectTemplate','evaluationEffect'}" r_effect="behaviorTimer=combatTimer"/>
			</behavior>
			<behavior r_name="'checkDangerousTile'" r_template="'behaviorTemplate'" r_enabled="(knownTrapMoveCost>1)&&square.dangerousTile" r_onSuccess="'moveOnce'" r_onFailure="'additionalPower'"/>
			<behavior r_name="'additionalPower'" r_template="'behaviorTemplate'" r_enabled="length(additionalPowers)>0" r_behaviorAction="'usePower'" r_powerName="randomElement(additionalPowers)" r_powerTarget="'random'" r_onSuccess="'checkDangerousTile'" r_onFailure="'combat'"/>
			<behavior r_name="'combat'" r_template="'behaviorTemplate'" r_behaviorAction="'autoAttack'" r_onSuccess="'checkDangerousTile'" r_onFailure="(10>fatigue)?'rest':((behaviorTimer-->0)?'moveToLastObjective':'exit')"/>
			<behavior r_name="'rest'" r_template="'behaviorTemplate'" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_onSuccess="'checkDangerousTile'" r_onFailure="''"/>
			<behavior r_name="'moveToLastObjective'" r_template="'behaviorTemplate'" r_behaviorAction="'moveToLastObjective'" r_onSuccess="'checkDangerousTile'" r_onFailure="'rest'"/>
			<behavior r_name="'moveOnce'" r_template="'behaviorTemplate'" r_behaviorAction="'moveOnce'" r_onSuccess="'additionalPower'" r_onFailure="'additionalPower'"/>
			<behavior r_name="'exit'" r_template="'behaviorTemplate'" r_behaviorAction="'parentBehavior'" r_childSuccess="1" r_onSuccess="''" r_onFailure="''"/>
		</behaviorTemplate>

		<!-- Behaviors -->
		<behavior r_name="'behaviorHero'" r_template="'behaviorCompositeTemplate'">
			<behavior r_name="'waitInstruction'" r_template="'behaviorTemplate'" r_behaviorAction="'HMICommands'" r_onSuccess="'waitInstruction'" r_onFailure="''" r_onCustom="w_autoExplore?{{'enemyVisible','stopBehavior'},{'damage','stopBehavior'}}:{}">
				<event r_name="'onDamage'" r_template="'mainEventTemplate'" r_targetType="'attribute'" r_eventTarget="'hitPoints'">
					<effect r_name="'customBehavior'" r_template="'mainSelfEffectTemplate'" r_enabled="w_oldValue>w_newValue" r_type="'customBehaviorTrigger'" r_behaviorTrigger="'damage'" />
				</event>
			</behavior>
			<behavior r_name="'stopBehavior'" r_template="'behaviorEffectTemplate'" r_onSuccess="'waitInstruction'" r_onFailure="''">
				<effect r_name="'stopAll'" r_template="{'mainSelfEffectTemplate','controllerEffect'}" r_className="'CctlEffectHMICommands'" r_commandType="'cancel'" w_result="''"/>
			</behavior>
		</behavior>
			
		<behavior r_name="'behaviorOffensive'" r_template="'behaviorCompositeTemplate'" potentialTarget="square">
			<event r_name="'onDamage'" r_template="'mainEventTemplate'" r_targetType="'attribute'" r_eventTarget="'hitPoints'">
				<effect r_name="'setTargetAndWandering'" r_template="{'mainSelfEffectTemplate','evaluationEffect'}" r_effect="all({potentialTarget=(exists(actor)?actor.square:square),wanderingMonster=1})"/>
				<effect r_name="'customBehavior'" r_template="'mainSelfEffectTemplate'" r_type="'customBehaviorTrigger'" r_behaviorTrigger="'damage'" />
			</event>
			<behavior r_name="'checkVisibility'" r_template="'behaviorTemplate'" r_behaviorAction="'checkEnemy'" r_onSuccess="'combat'" r_onFailure="'waitEnemy'"/>
			<behavior r_name="'waitEnemy'" r_template="'waitEnemyTemplate'" r_onSuccess="'combat'" r_onFailure="''" r_onCustom="{{'enemyVisible','combat'},{'damage','lookForAttacker'}}"/>
			<behavior r_name="'combat'" r_template="'combatTemplate'" r_onSuccess="'waitEnemy'" r_onFailure="''"/>
			<behavior r_name="'lookForAttacker'" r_template="'behaviorTemplate'" r_behaviorAction="'moveNear'" rw_xTarget="potentialTarget.w_xCoord" rw_yTarget="potentialTarget.w_yCoord" r_onSuccess="'lookForAttacker'" r_onFailure="'waitEnemy'" r_onCustom="{{'enemyVisible','combat'}}"/>
		</behavior>
		<behavior r_name="'behaviorOffensiveFollower'" r_template="'behaviorCompositeTemplate'" master="'creator'" takeStair="0">
			<behavior r_name="'checkVisibility'" r_template="'behaviorTemplate'" r_behaviorAction="'checkEnemy'" r_onSuccess="'combat'" r_onFailure="'followMaster'"/>
			<behavior r_name="'followMaster'" r_template="'waitEnemyOrFollowTemplate'" r_enabled="exists(attributeByName(master))" r_onSuccess="'combat'" r_onFailure="'doNothing'" r_onCustom="{{'enemyVisible','combat'},{'damage','combat'}}"/>
			<behavior r_name="'combat'" r_template="'combatTemplate'" r_onSuccess="'followMaster'" r_onFailure="''" combatTimer="0"/>
			<behavior r_name="'doNothing'" r_template="'behaviorTemplate'" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_onSuccess="'checkVisibility'" r_onFailure="''"/>
		</behavior>
		<behavior r_name="'behaviorOffensiveHeroFollowerTemplate'" r_template="'behaviorOffensiveFollower'" master="'nextHero'"/>
		<behavior r_name="'behaviorOffensiveFollowerWithStair'" r_template="'behaviorOffensiveFollower'" takeStair="1"/>
		<behavior r_name="'behaviorFriendlyNpc'" r_template="'behaviorCompositeTemplate'">
			<behavior r_name="'waitForHero'" r_template="'waitAllyTemplate'" r_onSuccess="'heroArrived'" r_onFailure="''"/>
			<behavior r_name="'heroArrived'" r_template="'behaviorEffectTemplate'" r_onSuccess="toBeSaved?'searchExit':'followHero'" r_onFailure="''">
				<effect r_name="'log'" r_template="'logHeroArrived'"/>
			</behavior>
			<behavior r_name="'searchExit'" r_template="'behaviorTemplate'" r_behaviorAction="'searchActivable'" r_activableCategory="'stair'" r_activableDisplayName="'downstair'" r_mustSeeActivable="1" r_onSuccess="'searchExit'" r_onFailure="'followHero'"/>
			<behavior r_name="'followHero'" r_template="'behaviorTemplate'" r_behaviorAction="'follow'" r_followTarget="'nextHero'" r_onSuccess="toBeSaved?'searchExit':'followHero'" r_onFailure="'doNothing'"/>
			<behavior r_name="'doNothing'" r_template="'behaviorTemplate'" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_onSuccess="toBeSaved?'searchExit':'followHero'" r_onFailure="''"/>
		</behavior>
		
		<!-- Special Behaviors -->
		<behavior r_name="'behaviorConfused'" r_template="'behaviorCompositeTemplate'">
			<behavior r_name="'randomWalk'" r_template="'behaviorTemplate'" r_behaviorAction="'move'" rw_xTarget="square.w_xCoord+randomElement({-1,0,1})" rw_yTarget="square.w_yCoord+randomElement({-1,0,1})" r_onSuccess="(1D2==1)?'randomWalk':'doNothing'" r_onFailure="'doNothing'"/>
			<behavior r_name="'doNothing'" r_template="'behaviorTemplate'" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_onSuccess="(1D2==1)?'randomWalk':'doNothing'" r_onFailure="''"/>
		</behavior>
		<behavior r_name="'furyCombat'" r_template="'behaviorCompositeTemplate'">
			<behavior r_name="'combat'" r_template="'behaviorTemplate'" r_behaviorAction="'autoAttack'" r_onSuccess="'combat'" r_onFailure="'rest'"/>
			<behavior r_name="'rest'" r_template="'behaviorTemplate'" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_onSuccess="'combat'" r_onFailure="''"/>
		</behavior>
		<behavior r_name="'heroRestAndAutoExplore'" r_template="'behaviorCompositeTemplate'">
			<behavior r_name="'checkVisibility'" r_template="'behaviorTemplate'" r_behaviorAction="'checkEnemy'" r_onSuccess="'seeEnemy'" r_onFailure="'rest'"/>
			<behavior r_name="'rest'" r_template="'behaviorTemplate'" r_behaviorAction="'usePower'" r_powerName="'endTurn'" r_powerTarget="'self'" r_enabled="exhaustion>fatigue" r_onSuccess="'checkVisibility'" r_onFailure="'autoExplore'"/>
			<behavior r_name="'seeEnemy'" r_template="'behaviorEffectTemplate'" r_onSuccess="'stopBehavior'" r_onFailure="''">
				<effect r_name="'noExploration'" r_template="'manualLogTemplate'" text="text.logCannotNoExploreMonster"/>
			</behavior>
			<behavior r_name="'stopBehavior'" r_template="'behaviorEffectTemplate'" r_onSuccess="''" r_onFailure="''">
				<effect r_name="'updateBehavior'" r_template="{'mainSelfEffectTemplate','controllerEffect'}" r_className="'CctlEffectUpdateBehavior'" r_newBehavior="'behaviorHero'"/>
			</behavior>
			<behavior r_name="'autoExplore'" r_template="'behaviorEffectTemplate'" r_onSuccess="'stopBehavior'" r_onFailure="''">
				<effect r_name="'explore'" r_template="{'mainSelfEffectTemplate','controllerEffect'}" r_className="'CctlEffectHMICommands'" r_commandType="'autoExplore'" w_result="''"/>
			</behavior>
		</behavior>
	</behaviors>
</data>