// Evaluate the masster network void EvaluateMaster(CharacterStats s, AiBehaviour ab, List <Output> Results) { switch (Results[Results.Count - 1].ID) { // Idle case 0: { if (s.GetStat("anger") > 0) { ab.Network.AddFitness(-1); } else { ab.Network.AddFitness(1); } break; } // Combat case 1: { if (s.GetStat("anger") > 0) { ab.Network.AddFitness(1); } else { ab.Network.AddFitness(-1); } break; } } }
public void BeginEncounter(Campaign owner, EncounterDescriptor descriptor) { this.owner = owner; this.descriptor = descriptor; // setup opponent opponentStats = gameObject.AddComponent <VesselStats>(); InitialiseOpponentStats(); opponentStatus = gameObject.AddComponent <VesselStatus>(); InitialiseOpponentStatus(); // activate page pageEncounter = (PageEncounter)Game.Instance.pageManager.PushPage("Encounter"); // disable input pageEncounter.IsInputEnabled = false; // initialise health bars pageEncounter.healthBarPlayer.SetFill(owner.playerStatus.GetHealthPercentage()); pageEncounter.healthBarOpponent.SetFill(opponentStatus.GetHealthPercentage()); // setup vessel encounters playerEncounter = new VesselEncounter(true, "player", this, owner.gameBalance, pageEncounter.playerVisuals, owner.playerStats, owner.playerStatus, descriptor.playerModifiers); opponentEncounter = new VesselEncounter(false, "opponent", this, owner.gameBalance, pageEncounter.opponentVisuals, opponentStats, opponentStatus, descriptor.enemyModifiers); VesselEncounter.SetOpponents(playerEncounter, opponentEncounter); opponentAiBehaviour = Instantiate(descriptor.enemyAiBehaviour, transform); // start BeginPlayerTurn(); }
public void HostalizseAI() { if (behaviour != AiBehaviour.Patrol) { Debug.Log("changing to patrol"); behaviour = AiBehaviour.Patrol; } patrollingScript.speed = patrollingScript.startSpeed; sRenderer.color = startColor; if (patrollingScript.isMimic == true) { patrollingScript.mimic = true; graphics.tag = "killTag"; } if (grumpyScript != null) { grumpyScript.enabled = true; grumpyScript.canSee = true; grumpyScript.relaxing = false; grumpyScript.isSpooked = false; } if (turncoatScript != null) { turncoatScript.enabled = true; } }
private void Init() { if (_statusBar == null) { _statusBar = new StatusBarDrawer(); } if (_paramPanel == null) { _paramPanel = new ParamPanelDrawer(); } _cursorChangeRect = new Rect(_currentViewWidth, 0f, 5f, position.height); if (Selection.activeObject is AiBehaviour && EditorUtility.IsPersistent(Selection.activeObject)) { _target = (AiBehaviour)Selection.activeObject; _statusBar.Blackboard = _target; _paramPanel.Blackboard = _target; _treeDrawer = new TreeDrawer(_statusBar.CurrentTree); _statusBar.OnSelectedAiTree += _treeDrawer.RebuildTreeView; } else if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponent <AiController>() != null && Selection.activeGameObject.GetComponent <AiController>().Behaviour != null) { _target = Selection.activeGameObject.GetComponent <AiController>().Behaviour; _statusBar.Blackboard = _target; _paramPanel.Blackboard = _target; _treeDrawer = new TreeDrawer(_statusBar.CurrentTree); _statusBar.OnSelectedAiTree += _treeDrawer.RebuildTreeView; } Repaint(); }
// Finds a new network to display in the current scene // dir dictates wether to cycle forwards, backwards or to rebuild the current network graph void FindNewNetwork(int dir) { // Get a list of all current networks List <AiBehaviour> tempBehaviors = NetworkTrainingScript.Instance.GetBehaviours(); // Destruct the current network Destructor(); // Add the direction to the currentNetwork ID CurrentBehaviorkID += dir; if (CurrentBehaviorkID > tempBehaviors.Count - 1) { CurrentBehaviorkID = 0; } else if (CurrentBehaviorkID < 0) { CurrentBehaviorkID = tempBehaviors.Count - 1; } // Using the new networkId, get the new network CurrentBehavior = tempBehaviors[CurrentBehaviorkID]; // Initialize the graph with the new network InitializeGraph(); }
private void OnEnable() { ai = GetComponentInParent <AiBehaviour>(); newChaseObj = Instantiate(AiChaseObj); ai.OnStart = newChaseObj; ai.OnExit = newChaseObj; // ai.ChangeBase(newChaseObj); }
// Evaluate the combat network void EvaluateCombat(CharacterStats s, AiBehaviour ab, List <Output> Results) { switch (Results[Results.Count - 1].ID) { // Attack case 0: { // If the bot is attacking give them a point if (s.GetStat("rcount") < 5) { ab.Network.AddFitness(5); } else { // unless they should be dodging ab.Network.AddFitness(-5); } break; } // Dodge case 1: { // If the bot is dodging correctly give them 5 points if (s.GetStat("rcount") > 5) { ab.Network.AddFitness(5); } else { ab.Network.AddFitness(-10); } break; } // Wait case 2: { if (s.GetStat("rcount") < 5) { // If the bot is low on stamina and waiting give them 5 points if (s.GetStat("stamina") < 2) { ab.Network.AddFitness(5); } else // Otherwise take away a point { ab.Network.AddFitness(-10); } } else { ab.Network.AddFitness(-10); } break; } } }
protected void InitParamList(AiBehaviour blackboard) { _serializedObject = new SerializedObject(blackboard); var p = _serializedObject.FindProperty("_parameters").FindPropertyRelative(_mainPropertyName); _list = new ReorderableList(_serializedObject, p.FindPropertyRelative(_keysPropertyName), true, true, true, true); _list.drawHeaderCallback += DrawHeader; _list.onAddCallback += Add; _list.onRemoveCallback += Remove; _list.drawElementCallback += DrawElement; }
public static ANode CreateNode(Type nodeType, AiBehaviour blackboard) { ANode n = ScriptableObject.CreateInstance(nodeType) as ANode; n.name = n.GetType().Name; n.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(n, blackboard); EditorUtility.SetDirty(n); AssetDatabase.SaveAssets(); return n; }
protected override string OnInit() { chalkboard = new NCBlackboardBridge(blackboard); Debug.Assert(aiBehaviourTemplate != null, "You must provide a behaviour for the AiBehaviourRunner to run in " + agent.name); aiBehaviour = ScriptableObject.Instantiate <AiBehaviour>(aiBehaviourTemplate); // TODO: capture errors in the behaviour initalization and pass them on to NodeCanvas return(null); }
public static ANode CreateNode(Type nodeType, AiBehaviour blackboard) { ANode n = ScriptableObject.CreateInstance(nodeType) as ANode; n.name = n.GetType().Name; n.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(n, blackboard); EditorUtility.SetDirty(n); AssetDatabase.SaveAssets(); return(n); }
public override void Start() { if (waitForTrigger) { aiBehaviour = GetComponent <AiBehaviour>(); backupAiBehaviour = aiBehaviour; aiBehaviour.enabled = false; aiBehaviour = null; } base.Start(); }
private void OnProjectChange() { if (Selection.activeObject == null && Selection.activeGameObject == null) { _treeDrawer = null; _target = null; _statusBar.Blackboard = null; _paramPanel.Blackboard = null; } if (_target == null) { Init(); } }
/// <summary> /// Returns true if behaviour was changed successfully, false otherwise. /// </summary> private bool TryChangeBehaviour(AiBehaviour behaviour, float transitionTime) { try { ChangeBehaviour(behaviour, transitionTime); return(true); } catch (InvalidOperationException e) { Debug.LogError("Failed to change behaviour. " + e.Message); return(false); } }
private BaseBehaviour GetBehaviour(AiBehaviour behaviour) { if (behaviour == AiBehaviour.Patrolling) { return(_patrolAi); } if (behaviour == AiBehaviour.Pursuing) { return(_pursueAi); } if (behaviour == AiBehaviour.Exploring) { return(_exploreAi); } throw new InvalidOperationException("Enemy " + transform.name + " does not have behaviour " + behaviour); }
private bool HasBehaviour(AiBehaviour behaviour) { if (behaviour == AiBehaviour.Patrolling) { return(_patrolAi != null); } if (behaviour == AiBehaviour.Pursuing) { return(_pursueAi != null); } if (behaviour == AiBehaviour.Exploring) { return(_exploreAi != null); } return(false); }
public IEnumerator Incapacitate() { /*Vector3 originalSize = transform.localScale; * Vector3 scaleDown = originalSize; * scaleDown.y = 0.5f; * transform.localScale = scaleDown;*/ AkSoundEngine.PostEvent("HatmanJump", gameObject); anim.SetBool("incapacitated", true); incapacitated = true; yield return(new WaitForSeconds(incapacitateTime)); //transform.localScale = originalSize; behaviour = AiBehaviour.Patrol; anim.SetBool("incapacitated", false); incapacitated = false; StopCoroutine("Incapacitate"); }
// Use this for initialization void Start () { m_Seeker = GetComponent<AiKSeek>(); m_Arriver = GetComponent<AiKArrive>(); if (m_Graph == null) { Debug.LogError("Graph missing from agent"); } if (m_Target == null) { Debug.LogError("Target missing from agent"); } if (m_Seeker == null) { Debug.LogError("Seek AiBehaviour missing from agent"); } if (m_Arriver == null) { Debug.LogError("Arrive AiBehaviour missing from agent"); } }
/// <summary> /// Called from the Dungeon manager, in the SpawnAI Function /// This function will set up the ai, with the provided sprite, animator, stats, and moveset /// </summary> public void InitializeAi(EntityData p_entityType) { m_entityType = p_entityType; m_entityContainer.m_entityVisualManager.AssignEntityData(p_entityType); m_path = null; m_currentNode = null; m_entityContainer.Reinitialize(p_entityType); m_currentTarget = null; m_currentBehaviour = AiBehaviour.Idle; m_path = null; m_currentNode = null; m_currentTargetPrediction = null; if (m_dungeonManager != null) { m_restart = true; NewPath(); } }
void Update() { switch (behaviour) { case AiBehaviour.Patrol: patrollingScript.isPatrolling = true; break; case AiBehaviour.Agro: patrollingScript.isPatrolling = false; Debug.Log("Agroed!"); behaviour = AiBehaviour.Chase; break; case AiBehaviour.Chase: patrollingScript.isPatrolling = false; heatSeekingScript.isSeeking = true; break; } }
private void ChangeBehaviour(AiBehaviour behaviour, float transitionTime) { if (_activeAi != null) { _activeAi.End(); } // Stop movement prior to behaviour change, or else enemy will move towards its // old movement direction during the wait period. _motor.StopUntilResumed(); // Set new behaviour _activeAi = GetBehaviour(behaviour); _activeAi.Begin(); _activeBehaviour = behaviour; // Simulate transition to new behaviour by waiting for a short time Wait(transitionTime); }
// Use this for initialization void Start() { m_Seeker = GetComponent <AiKSeek>(); m_Arriver = GetComponent <AiKArrive>(); if (m_Graph == null) { Debug.LogError("Graph missing from agent"); } if (m_Target == null) { Debug.LogError("Target missing from agent"); } if (m_Seeker == null) { Debug.LogError("Seek AiBehaviour missing from agent"); } if (m_Arriver == null) { Debug.LogError("Arrive AiBehaviour missing from agent"); } }
public void CheckCurrentBehaviour() { bool findNewPath = false; if (m_currentTarget != null) { if (!CanSeeTarget()) { findNewPath = true; m_currentTarget = SearchForNewTarget(); } } else { m_currentTarget = SearchForNewTarget(); if (m_currentTarget != null) { m_currentBehaviour = AiBehaviour.Attack; NewPath(); } } if (m_currentTarget == null) { m_currentBehaviour = AiBehaviour.Idle; if (findNewPath) { m_currentTargetPos = m_path[m_path.Count - 1].worldPosition; NewPath(m_path.Count > 1); } } else { m_currentBehaviour = AiBehaviour.Attack; } }
public virtual void Start() { defaultAction.moveTarget = Vector3.positiveInfinity; moveController = GetComponent <IEnemyMoveController2D>(); aiBehaviour = GetComponent <AiBehaviour>(); animator = GetComponent <Animator>(); spriteRenderer = GetComponent <SpriteRenderer>(); hitBox = GetComponentInChildren <HitBox>(); if (aiBehaviour && aiBehaviour.enabled) { aiBehaviour.defaultAction = defaultAction; currentAction = aiBehaviour.GetCurrentAction(); } else { currentAction = defaultAction; } boxCollider = GetComponent <BoxCollider2D>(); hurtBox = GetComponent <HurtBox>(); if (!hurtBox) { // search in children hurtBox = transform.GetComponentInChildren <HurtBox>(); } // init ENEMY state currentState = new EnemyIdleState(this); if (randomDelaySeconds > 0) { delayTime = Random.Range(0F, randomDelaySeconds); animator.speed = 0; } }
private void Init() { if (_statusBar == null) { _statusBar = new StatusBarDrawer(); } if (_paramPanel == null) { _paramPanel = new ParamPanelDrawer(); } _cursorChangeRect = new Rect(_currentViewWidth, 0f, 5f, position.height); if (Selection.activeObject is AiBehaviour && EditorUtility.IsPersistent(Selection.activeObject)) { _target = (AiBehaviour)Selection.activeObject; _statusBar.Blackboard = _target; _paramPanel.Blackboard = _target; _treeDrawer = new TreeDrawer(_statusBar.CurrentTree); _statusBar.OnSelectedAiTree += _treeDrawer.RebuildTreeView; } else if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponent<AiController>() != null && Selection.activeGameObject.GetComponent<AiController>().Behaviour != null) { _target = Selection.activeGameObject.GetComponent<AiController>().Behaviour; _statusBar.Blackboard = _target; _paramPanel.Blackboard = _target; _treeDrawer = new TreeDrawer(_statusBar.CurrentTree); _statusBar.OnSelectedAiTree += _treeDrawer.RebuildTreeView; } Repaint(); }
public void StartGame() { levelWidth = short.Parse(levelSizeInput.text); levelLength = levelWidth; terrainCount = short.Parse(terrainCountInput.text); numberOfForts = (short)(terrainCount/2); numberOfMountains = (short)(terrainCount-numberOfForts); numberOfEnemies = short.Parse(enemyCountInput.text); attackText.text = attackInput.text; defenceText.text = defenceInput.text; PlayerStats.attack = short.Parse(attackInput.text); PlayerStats.defence = short.Parse(defenceInput.text); GameObject.Find("Start Screen").SetActive(false); aiBehaviour = GameObject.Find("AI Player").GetComponent<AiBehaviour>(); aiBehaviour.enabled = true; GenerateLevel(); SpawnPlayer(); SpawnEnemies(); playerTurn = true; }
public void InitAiAcontroller(UnitData data) { actor = GetComponent <Unit> (); aiBehaviour = data.aiBehaviour; }
public BoolParamDrawer(AiBehaviour blackboard) { _mainPropertyName = "_boolParameters"; _keyName = "Bool Parameter"; InitParamList(blackboard); }
public FloatParamDrawer(AiBehaviour blackboard) { _mainPropertyName = "_floatParameters"; _keyName = "Float Parameter"; InitParamList(blackboard); }
// Evaluate the needs network void EvaluateNeeds(CharacterStats s, AiBehaviour ab, List <Output> Results) { ab.Network.AddFitness(s.GetStat("happiness")); }
public IntParamDrawer(AiBehaviour blackboard) { _mainPropertyName = "_intParameters"; _keyName = "Int Parameter"; InitParamList(blackboard); }
public StringParamDrawer(AiBehaviour blackboard) { _mainPropertyName = "_stringParameters"; _keyName = "String Parameter"; InitParamList(blackboard); }