상속: MonoBehaviour
예제 #1
0
    // 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;
        }
        }
    }
예제 #2
0
    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();
    }
예제 #3
0
    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;
        }
    }
예제 #4
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();
 }
예제 #5
0
    // 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();
    }
예제 #6
0
 private void OnEnable()
 {
     ai          = GetComponentInParent <AiBehaviour>();
     newChaseObj = Instantiate(AiChaseObj);
     ai.OnStart  = newChaseObj;
     ai.OnExit   = newChaseObj;
     //  ai.ChangeBase(newChaseObj);
 }
예제 #7
0
    // 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;
        }
        }
    }
예제 #8
0
 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;
 }
예제 #9
0
 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;
 }
예제 #10
0
        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);
        }
예제 #11
0
    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);
    }
예제 #12
0
    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 override void Start()
 {
     if (waitForTrigger)
     {
         aiBehaviour         = GetComponent <AiBehaviour>();
         backupAiBehaviour   = aiBehaviour;
         aiBehaviour.enabled = false;
         aiBehaviour         = null;
     }
     base.Start();
 }
예제 #14
0
 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);
    }
예제 #18
0
    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");
		}
	}
예제 #20
0
    /// <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();
        }
    }
예제 #21
0
    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");
        }
    }
예제 #24
0
    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;
        }
    }
예제 #25
0
    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;
        }
    }
예제 #26
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();
 }
예제 #27
0
	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;
	}
예제 #28
0
 public void InitAiAcontroller(UnitData data)
 {
     actor       = GetComponent <Unit> ();
     aiBehaviour = data.aiBehaviour;
 }
예제 #29
0
 public BoolParamDrawer(AiBehaviour blackboard)
 {
     _mainPropertyName = "_boolParameters";
     _keyName          = "Bool Parameter";
     InitParamList(blackboard);
 }
예제 #30
0
 public FloatParamDrawer(AiBehaviour blackboard)
 {
     _mainPropertyName = "_floatParameters";
     _keyName          = "Float Parameter";
     InitParamList(blackboard);
 }
예제 #31
0
 // Evaluate the needs network
 void EvaluateNeeds(CharacterStats s, AiBehaviour ab, List <Output> Results)
 {
     ab.Network.AddFitness(s.GetStat("happiness"));
 }
예제 #32
0
 public IntParamDrawer(AiBehaviour blackboard)
 {
     _mainPropertyName = "_intParameters";
     _keyName = "Int Parameter";
     InitParamList(blackboard);
 }
예제 #33
0
 public StringParamDrawer(AiBehaviour blackboard)
 {
     _mainPropertyName = "_stringParameters";
     _keyName          = "String Parameter";
     InitParamList(blackboard);
 }
예제 #34
0
 public StringParamDrawer(AiBehaviour blackboard)
 {
     _mainPropertyName = "_stringParameters";
     _keyName = "String Parameter";
     InitParamList(blackboard);
 }
예제 #35
0
 private void OnProjectChange()
 {
     if (Selection.activeObject == null && Selection.activeGameObject == null) {
         _treeDrawer = null;
         _target = null;
         _statusBar.Blackboard = null;
         _paramPanel.Blackboard = null;
     }
     if (_target == null) {
         Init();
     }
 }