Inheritance: MonoBehaviour
    private void Awake()
    {
        // Master
        MasterView viewMaster = Instantiate( masterView );
        viewMaster.Initialize( gameSetting.masterSetting );
        Master master = new Master( viewMaster );
        MasterAIControl masterControl = new MasterAIControl( master );

        // AI
        List<AIControl> AIControlList = new List<AIControl>();
        List<Character> AICharacter = new List<Character>();
        for ( int i = 0; i < AINumber; ++i )
        {
            CharacterView view = Instantiate( characterPrefab );
            view.Initialize( gameSetting.characterSetting );
            Character character = new Character( view );
            AIControl aiControl = new AIControl( gameSetting.AIControlSetting, character, master );
            AIControlList.Add( aiControl );
            AICharacter.Add( character );
        }

        // Player
        CharacterView playerView = Instantiate( characterPrefab );
        playerView.Initialize( gameSetting.characterSetting );
        Character player = new Character( playerView );
        PlayerControl playerControl = new PlayerControl( player, AICharacter );

        GameTime gameTime = new GameTime();
        controllerManager = new ControllerManager(playerControl, AIControlList, masterControl);
        gameManager = new GameManager( gameTime, controllerManager, player, AICharacter, master );

        successPanel.SetGameTime( gameTime );
    }
Exemple #2
0
    private void PlaceGameObject(Position pos, Vector3 position)
    {
        GameObject obj = (GameObject)Instantiate(activeGo);

        obj.name = activeGo.name + " - " + pos.ToString();
        SpriteRenderer sRenderer = obj.GetComponentInChildren <SpriteRenderer>();

        if (sRenderer != null)
        {
            sRenderer.sortingOrder = layer_index;
        }
        obj.transform.position = position;
        obj.transform.parent   = layers[layer_index].transform;
        objects.Add(pos, obj);
        Undo.RegisterCreatedObjectUndo(obj, "Create " + obj.name);

        AIControl aiControl = obj.GetComponent <AIControl>();

        if (aiControl != null)
        {
            pathObjects.Add(aiControl);
            pathCreation = true;
            path.Clear();
        }
    }
Exemple #3
0
    private void DrawPaths()
    {
        for (int i = 0; i < pathObjects.Count; i++)
        {
            if (pathObjects[i] != null)
            {
                AIControl aiControl = pathObjects[i].GetComponent <AIControl>();

                if (aiControl != null)
                {
                    if (aiControl.path.Length > 1)
                    {
                        for (int j = 0; j < aiControl.path.Length; j++)
                        {
                            Vector2 pathpoint = aiControl.path[j];

                            DrawRectangle(pathpoint, pathpoint, 0.1f, Color.yellow);
                            Gizmos.color = Color.red;

                            if (j < aiControl.path.Length - 1)
                            {
                                Gizmos.DrawLine(pathpoint, aiControl.path[j + 1]);
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #4
0
    void HitEnemy(Collider Monster)
    {
        if (Monster.name == "Boss")
        {
            bossControl = Monster.GetComponent <BossControl>();
            Vector3 hitDirection = playerControl.transform.position - bossControl.transform.position;
            hitDirection.Normalize();
            float angle = Mathf.Atan2(hitDirection.y, hitDirection.x) - Mathf.Deg2Rad * (bossControl.transform.eulerAngles.z);
            float dirX  = Mathf.Cos(angle);
            float dirY  = Mathf.Sin(angle);

            if (bossControl.isVulnerable ||
                dirX == 0 && dirY > 0 ||
                dirX > 0 && dirY > 0 && dirY / dirX > 1f / Mathf.Sqrt(3) ||
                dirX < 0 && dirY > 0 && dirY / dirX < -1f / Mathf.Sqrt(3))
            {
                bossControl.stats.health -= damage;
            }
            else
            {
                bossControl.hitInArmor = true;
            }
        }
        else
        {
            aiControl = Monster.gameObject.GetComponent <AIControl> ();
            if (transform.name != "MageFire2(Clone)")
            {
                aiControl.moveBack = 0.08f;
            }
            aiControl.hitDirection  = aiControl.transform.position - playerControl.transform.position;
            aiControl.stats.health -= damage;
        }
        Instantiate(FireHitParticle, new Vector3(transform.position.x, transform.position.y, -0.8f), transform.rotation);
    }
Exemple #5
0
    // Use this for initialization

    //-----------------------------------------------------------------------------------------------------------
    void Start()
    {
        attbutt    = GameObject.Find("fireButton");
        photonView = GetComponentInParent <PhotonView> ();
        aictrl     = GetComponent <AIControl> ();
        ismine     = GetComponent <PhotonView> ().isMine;
    }
Exemple #6
0
 void OnTriggerExit(Collider other)
 {
     if (other.tag == "Ai" || other.tag == "Dino")
     {
         AIControl aiControl = other.GetComponent <AIControl>();
         aiControl.ExitStraight();
     }
 }
Exemple #7
0
 void Start()
 {
     control = GetComponent <AIControl>();
     data    = GetComponent <TankData>();
     move    = GetComponent <TankMove>();
     attack  = GetComponent <TankAttack>();
     tf      = GetComponent <Transform>();
 }
Exemple #8
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     NPC = animator.gameObject;
     if (!AI)
     {
         AI = NPC.GetComponent <AIControl>();
     }
 }
Exemple #9
0
 /// <summary>
 /// Registers the AI in the level.
 /// </summary>
 private void Start()
 {
     bard           = GetComponent <AIBard>();
     control        = GetComponent <AIControl>();
     enabledRhythms = LevelManager.instance.EnabledRhythms;
     LevelControllerManager.instance.AddPlayer(control.player, control);
     InitializeAI();
 }
Exemple #10
0
 void Awake()
 {
     //Attaching scripts and objects.
     data    = GetComponent <TankData>();
     move    = GetComponent <TankMove>();
     tf      = GetComponent <Transform>();
     control = GetComponent <AIControl>();
 }
 void Update()
 {
     inDanger = enmDect.enemyDetect;
     if (closest_enemyPoint != null)
     {
         AIControl aiRed = closest_enemyPoint.GetComponent <AIControl>();
         targetEnemyInPrison = aiRed.inPrison;
     }
 }
Exemple #12
0
 // Use this for initialization
 void Start()
 {
     aictrl      = GetComponent <AIControl> ();
     flag        = GameObject.FindGameObjectWithTag("Flag");
     flagspawner = GameObject.FindGameObjectsWithTag("FlagSpawner");
     StateChange((int)States.SearchFlag);
     aictrl.UpdatePath();
     StartCoroutine("ScanPickups");
 }
 private void Awake()
 {
     playerController = FindObjectOfType <PlayerController>();
     aiControl        = FindObjectOfType <AIControl>();
     cardHand         = FindObjectOfType <CardHand>();
     cardCreator      = FindObjectOfType <CardSelector>();
     powerCounter     = FindObjectOfType <PowerCounter>();
     winScreen        = FindObjectOfType <WinScreen>();
 }
    //--

    // Use this for initialization
    void Start()
    {
        database = GameObject.Find("Inventory").GetComponent <ItemDatabase> ();
        pi       = GameObject.FindGameObjectWithTag("Player").GetComponent <player_interaction>();
        cq       = GameObject.FindGameObjectWithTag("Player").GetComponent <ClassQuest>();
        ps       = GameObject.FindGameObjectWithTag("UI_Player").GetComponent <PlayerUI_Script>();
        pb       = GameObject.FindGameObjectWithTag("Player").GetComponent <Player_battle>();
        kq       = GetComponent <KillQuest>();
        aic      = GetComponent <AIControl>();
    }
Exemple #15
0
    void OnTriggerEnter(Collider Monster)
    {
        if (Monster.name == "Boss")
        {
            if (Monster.tag == "Monsters" && transform.name == "MageFireR01")
            {
                BossControl bossControl = Monster.GetComponent <BossControl>();
                bossControl.stunTime = 3.5f;
            }
            else if (transform.name == "MageFireR02")
            {
                BossControl bossControl  = Monster.GetComponent <BossControl>();
                Vector3     hitDirection = GameObject.Find("Mage").transform.position - bossControl.transform.position;
                hitDirection.Normalize();
                float angle = Mathf.Atan2(hitDirection.y, hitDirection.x) - Mathf.Deg2Rad * (bossControl.transform.eulerAngles.z);
                float dirX  = Mathf.Cos(angle);
                float dirY  = Mathf.Sin(angle);

                if (bossControl.isVulnerable ||
                    dirX == 0 && dirY > 0 ||
                    dirX > 0 && dirY > 0 && dirY / dirX > 1f / Mathf.Sqrt(3) ||
                    dirX < 0 && dirY > 0 && dirY / dirX < -1f / Mathf.Sqrt(3))
                {
                    bossControl.stats.health -= 5f;
                }
                else
                {
                    bossControl.hitInArmor = true;
                }
            }
        }
        else
        {
            if (Monster.tag == "Monsters" && transform.name == "MageFireR01")
            {
                AIControl aiControl = Monster.GetComponent <AIControl>();
                aiControl.stunTime = 3.5f;
            }
            else if (transform.name == "MageFireR02")
            {
                if (Monster.tag == "Monsters")
                {
                    AIControl aiControl = Monster.GetComponent <AIControl>();
                    aiControl.stats.health -= 5f;
                }
                else if (Monster.gameObject.name == "TrainingDummy")
                {
                    Monster.GetComponent <Animator>().SetBool("tookDamage", true);
                    float rotZ = Mathf.Atan2(transform.position.y - Monster.transform.position.y, transform.position.x - Monster.transform.position.x) * Mathf.Rad2Deg;
                    Monster.transform.rotation = Quaternion.Euler(0f, 0f, rotZ - 180);
                }
            }
        }
    }
Exemple #16
0
    //---------------------------------------------------------------------------------------------------------------//

    void Awake()
    {
        // Setting up the references.
        speed      = 30f;
        playerCtrl = transform.root.GetComponent <PlayerControl>();
        if (PhotonNetwork.offlineMode)
        {
            off    = true;
            aictrl = transform.root.GetComponent <AIControl>();
        }
    }
Exemple #17
0
    //------------------------------------------------------------------------------------------------------------------------
    void Awake()
    {
        // Setting up the references.
        photonView = GetComponent <PhotonView> ();

        anim   = transform.root.gameObject.GetComponent <Animator> ();
        AICtrl = transform.root.GetComponent <AIControl> ();
        atcpro = GetComponent <AttackedProperties> ();
        ailo   = GetComponent <AILogic> ();
        //Set to default weapon: BareHand
        weaponInHeld = "BareHand";
    }
Exemple #18
0
 protected void AIReactToShot()
 {
     foreach (Collider other in Physics.OverlapSphere(transform.position, 20f))
     {
         if (other.tag == "Unit")
         {
             AIControl ai = other.GetComponent <AIControl>();
             if (ai.target == null)
             {
                 ai.TookDamage(this.transform.position - other.transform.position);
             }
         }
     }
 }
Exemple #19
0
    private void AssignPath()
    {
        if (pathObjects != null && pathObjects.Count > 0)
        {
            AIControl aiControl = pathObjects.Last().GetComponent <AIControl>();

            if (aiControl != null)
            {
                aiControl.path = path.ToArray();
            }
        }
        path.Clear();
        pathCreation = false;
    }
Exemple #20
0
        private static Boolean AIControl_OnTurnBegin_Prefix_TeamMatePlayerControl(AIControl __instance)
        {
            CharacterComponent character = __instance.CharacterComponent;

            if (character.IsTeamMate())
            {
                if (ChangeToPlayer(character))
                {
                    character.Controller.OnTurnBegin();
                    return(false);
                }
            }

            return(true);
        }
Exemple #21
0
    void AssignName()
    {
        int i = 1;

        foreach (GameObject plyr in player)
        {
            AIControl aictrl = plyr.GetComponent <AIControl> ();
            if (aictrl)
            {
                aictrl.name            = PlayerPrefs.GetString("Name" + i);
                aictrl.playerName.text = aictrl.name;
                i++;
            }
        }
        print("lengtj" + player.Length);
    }
Exemple #22
0
    // NOTE possibly add a snap to object ability in future
    private void Start()
    {
        //Spawner[] spawners = FindObjectsOfType<Spawner>();
        //foreach (Spawner spawner in spawners)
        //{
        //    if (spawner.cardType == CardType.Player)
        //    {
        //        playerSpawner = spawner;
        //    }
        //}

        turnSystem         = FindObjectOfType <TurnSystem>();
        aiControl          = FindObjectOfType <AIControl>();
        mageSpawner        = FindObjectOfType <Mage>();
        transform.position = new Vector3(mageSpawner.transform.position.x, mageSpawner.transform.position.y + InnitYOffset, mageSpawner.transform.position.z - InitZOffset);
    }
        private void Start()
        {
            enimies      = enimies + 1;                                                                             //Chaneded Here
            player       = GameObject.FindGameObjectWithTag("Player");
            playerHealth = player.GetComponent <PlayerStats>();
            animator     = GetComponent <Animator>();
            chest        = animator.GetBoneTransform(HumanBodyBones.Chest);
            source       = GetComponent <AudioSource>();
            navMeshAgent = GetComponent <NavMeshAgent>();
            aiControl    = GetComponent <AIControl>();
            vision       = GetComponentInChildren <NPCVision>();
            hitFXManager = GetComponent <HitFXManager>();
            states       = GetComponent <NPCStates>();

            visibilityCheckObject      = new GameObject();
            visibilityCheckObject.name = this.name + " visibilityCheckObject";
            visibilityCheckObject.AddComponent <SphereCollider>().radius  = 0.3f;
            visibilityCheckObject.GetComponent <SphereCollider>().enabled = false;

            foreach (Collider collider in GetComponentsInChildren <Collider>())
            {
                collider.enabled = false;
            }
            foreach (Rigidbody rigidbody in GetComponentsInChildren <Rigidbody>())
            {
                rigidbody.isKinematic = true;
            }

            GetComponent <Rigidbody>().isKinematic = false;
            GetComponent <Collider>().enabled      = true;

            StartCoroutine(CheckFriends());

            //Set own position as NavMesh target on start
            desiredPosition = transform.position;

            //Controller variables
            m_Rigidbody     = GetComponent <Rigidbody>();
            m_Capsule       = GetComponent <CapsuleCollider>();
            m_CapsuleHeight = m_Capsule.height;
            m_CapsuleCenter = m_Capsule.center;

            m_Rigidbody.constraints   = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
            m_OrigGroundCheckDistance = m_GroundCheckDistance;
        }
Exemple #24
0
    public void Update()
    {
        float delta = Time.deltaTime * speed;

        transform.Translate(dir * delta);
        RaycastHit hit;

        if (Physics.Raycast(transform.position, -dir, out hit, delta) && hit.transform.name != friendly)
        {
            Destroy(gameObject);
            AIControl ai        = hit.transform.GetComponent <AIControl>();
            Module    telporter = hit.transform.GetComponent <Module>();

            if (telporter != null)
            {
                telporter.TryCancelTeleport();
                return;
            }


            if (ai != null && ai.hp == 0 && !ai.dead)
            {
                ai.dead = true;
                ai.HandleDeath();
                return;
            }

            if (ai != null && ai.hp > 0)
            {
                ai.hp--;
                Pusher pusher = ai.transform.GetComponent <Pusher>();
                Lunge  lunge  = ai.transform.GetComponent <Lunge>();

                if (!lunge.enabled && !pusher.enabled)
                {
                    pusher.pushDir = dir;
                    pusher.enabled = true;
                }

                Instantiate(gore, hit.point, Quaternion.identity);
            }
        }
    }
Exemple #25
0
    /// <summary>
    /// Initializes the object.
    /// </summary>
    private void Awake()
    {
        PlayerControl[] playerControls = GameObject.FindObjectsOfType <PlayerControl>();
        players = new GameObject[playerControls.Length];
        for (int i = 0; i < playerControls.Length; i++)
        {
            players[i] = playerControls[i].gameObject;
        }

        float respawnTime = aiPrefab.GetComponent <PlayerLife>().respawnTime;

        Tune[] randomTuneChoices = aiPrefab.GetComponent <AIBard>().randomTuneChoices;

        foreach (GameObject player in players)
        {
            player.AddComponent <NavMeshAgent>();

            AIControl     aiControl     = player.AddComponent <AIControl>();
            PlayerControl playerControl = player.GetComponent <PlayerControl>();
            aiControl.player = playerControl.player;
            aiControl.speed  = playerControl.speed;

            AIBard     aiBard     = player.AddComponent <AIBard>();
            PlayerBard playerBard = player.GetComponent <PlayerBard>();
            aiBard.tunes             = new Tune[3];
            aiBard.instrumentSound   = playerBard.instrumentSound;
            aiBard.buttonPressDelay  = playerBard.buttonPressDelay;
            aiBard.volumeOverride    = playerBard.volumeOverride;
            aiBard.randomTuneChoices = randomTuneChoices;
            aiBard.randomizeTunes    = true;

            player.AddComponent <AdaptiveAI>();

            PlayerLife playerLife = player.GetComponent <PlayerLife>();
            if (playerLife.respawnTime == 0)
            {
                playerLife.respawnTime = respawnTime;
            }

            Destroy(playerControl);
            Destroy(playerBard);
        }
    }
Exemple #26
0
    void Destroy()
    {
        if (gameObject.tag == "Enemy")
        {
            OnEnemyKilled();
        }

        if (gameObject.tag == "Player")
        {
            AudioControl.PlayerDeath(); //Toistaa äänen
            StartCoroutine(DestroyPlayerWithSound());
        }

        if (rBody != null)
        {
            rBody.isKinematic = true;
        }

        if (deathEffect != null)
        {
            Vector2 spawnPosition = (Vector2)transform.position + Vector2.up * 0.5f * transform.localScale.y;
            deathEffect = (GameObject)Instantiate(deathEffect, spawnPosition, Quaternion.identity);
            Destroy(deathEffect, 0.5f);
            this.enabled = false;
        }

        AIControl aiControl = gameObject.GetComponent <AIControl>();

        if (aiControl != null)
        {
            if (Random.Range(0, 100) <= aiControl.lootChance)
            {
                ContainerControl containerController = GetComponent <ContainerControl>();

                if (containerController != null && containerController.pickup != null)
                {
                    containerController.SpawnPickup(transform.position);
                }
            }
        }
        Destroy(_gameObject);
    }
    GameObject findTargetEnemy(GameObject[] enemies)
    {
        GameObject closest  = null;       //you will return this as the person you find.
        float      distance = Mathf.Infinity;
        Vector3    position = transform.position;

        foreach (GameObject enemy in enemies)        //go through all players in map
        {
            var diff        = (enemy.transform.position - position);
            var curDistance = diff.sqrMagnitude;
            if (curDistance < distance)            //is this player closer than the last one?
            {
                //AIControl_Blue aiBlueCurrent = enemy.GetComponent<AIControl_Blue>();
                aiRedCurrent = enemy.GetComponent <AIControl>();
                //bool currentTargetEnemyInPrison = aiBlueCurrent.inPrison;
                currentTargetEnemyInPrison = aiRedCurrent.goPrison;
                //bool currentTargetEnemyGoPrison = aiBlueCurrent.goPrison;
                //if (!currentTargetEnemyInPrison && !currentTargetEnemyGoPrison)
                if (!currentTargetEnemyInPrison)
                {
                    closest  = enemy;                   //this is the closest player
                    distance = curDistance;             //set the closest distance
                }
            }
        }
        if (closest != null)
        {
            return(closest.gameObject);           //this is the closest player
        }
        else
        {
            if (winNotSet)
            {
                winNotSet    = false;
                winText.text = "Blue Win !";
                gameEndSource.Play();
                //return null;
            }
            return(null);
        }
    }
Exemple #28
0
    void Start()
    {
        //Attaching scripts and objects.
        data    = GetComponent <TankData>();
        attack  = GetComponent <TankAttack>();
        move    = GetComponent <TankMove>();
        control = GetComponent <AIControl>();
        tf      = GetComponent <Transform>();

        //Setting some variables.
        currentWaypoint = 0;
        closeEnough     = 1.0f;
        patrolForward   = true;

        hearingdistance = 25f;
        FOVangle        = 45.0f;
        inSightAngle    = 10.0f;

        healthRegen = 10;
        restTime    = 5;
    }
Exemple #29
0
    //......................................................................................................................
    void updateHudInfo()
    {
        int i = 0;

        foreach (GameObject plyr in player)
        {
            AIControl aictrl = plyr.GetComponent <AIControl> ();
            if (aictrl)
            {
                scoreInfo [i].text  = "" + aictrl.score;
                playerInfo [i].text = aictrl.name;
            }
            else
            {
                scoreInfo [i].text  = "" + PhotonNetwork.player.GetScore();
                playerInfo [i].text = PhotonNetwork.player.name;
            }
            i++;
        }
        round          = (int)room.customProperties ["Round"];
        roundInfo.text = "" + round;
    }
Exemple #30
0
    //Pemrosesan array nilai
    bool Reachable()
    {
        int[] TabInt;
        TabInt = new int[5];

        foreach (GameObject plyr in player)
        {
            AIControl aictrl = plyr.GetComponent <AIControl> ();
            int       x;
            if (aictrl)
            {
                x = aictrl.score;
            }
            else
            {
                x = PhotonNetwork.player.GetScore();
            }

            int i = 3;
            while (i >= 0 && x > TabInt [i])
            {
                TabInt [i + 1] = TabInt [i];
                i--;
            }
            i++;
            if (x > TabInt [i])
            {
                TabInt [i + 1] = TabInt [i];
                TabInt [i]     = x;
            }
            else
            {
                TabInt [i] = x;
            }
        }

        return((TabInt[0] - TabInt[1]) <= (10 - round));
    }
Exemple #31
0
    private void Awake()
    {
        // Master
        MasterView viewMaster = Instantiate(masterView);

        viewMaster.Initialize(gameSetting.masterSetting);
        Master          master        = new Master(viewMaster);
        MasterAIControl masterControl = new MasterAIControl(master);

        // AI
        List <AIControl> AIControlList = new List <AIControl>();
        List <Character> AICharacter   = new List <Character>();

        for (int i = 0; i < AINumber; ++i)
        {
            CharacterView view = Instantiate(characterPrefab);
            view.Initialize(gameSetting.characterSetting);
            Character character = new Character(view);
            AIControl aiControl = new AIControl(gameSetting.AIControlSetting, character, master);
            AIControlList.Add(aiControl);
            AICharacter.Add(character);
        }

        // Player
        CharacterView playerView = Instantiate(characterPrefab);

        playerView.Initialize(gameSetting.characterSetting);
        Character     player        = new Character(playerView);
        PlayerControl playerControl = new PlayerControl(player, AICharacter);

        GameTime gameTime = new GameTime();

        controllerManager = new ControllerManager(playerControl, AIControlList, masterControl);
        gameManager       = new GameManager(gameTime, controllerManager, player, AICharacter, master);

        successPanel.SetGameTime(gameTime);
    }