Пример #1
0
    public void CmdAddNewPlayer(GameObject ply, GameObject netWorkAssitant)
    {
        netWorkAssitant assitant = netWorkAssitant.GetComponent <netWorkAssitant> ();           // create a new network assitant ONLY way to access our structure.

        if (assitant != null)
        {
            assitant.playerManager.Add(new plyStore(ply));                                                                      // add the player into the class structure.

            /**
             * int counter = 0;
             *
             * // testing, this prints out when ever someone Joins the server basically.
             * while(counter < assitant.playerManager.Count){
             *
             *
             *      print (assitant.playerManager[counter].ply.gameObject.tag);
             *
             *      counter ++;
             * }
             **/
            //isPlayerManagerEmpty = false; I will use this later I just dont want a Warning in console!
        }
    }
    /**
     * castSpell():
     *
     * this function actually casts the current spell it wishes to cast.
     * will look through all the boolean spell types and choose which one to cast.
     *
     * return: Nothing void.
     *
     */
    public void castSpell()
    {
        // check the timer, is it time to cast the next firemeteor?
        if (fireBoulderCasted == true)
        {
            if (this.GetComponent <fireBoulder> ().attackTime != 0)
            {
                // if not, lets keep subtracting by in game time.
                this.GetComponent <fireBoulder> ().attackTime -= Time.deltaTime;

                if (this.GetComponent <fireBoulder> ().attackTime <= 0)
                {
                    // safety net if statement, meaning that we went below 0, reset it to 0.
                    this.GetComponent <fireBoulder> ().attackTime = 0;
                }
            }


            // now that it is time to cast, cast our spell and make sure that it can only be casted as many times as we want to cast it.
            if (this.GetComponent <fireBoulder> ().attackTime == 0 && this.GetComponent <fireBoulder> ().numFireBallSpawned < numberFireBallsToSpawn)
            {
                netWorkAssitant players = plyController.GetComponent <netWorkAssitant> ();

                for (int i = 0; i < players.playerManager.Count; i++)
                {
                    if (players.playerManager[i].ply != null)
                    {
                        Physics2D.IgnoreLayerCollision(this.gameObject.GetComponent <fireBoulder>().returnProjectileLayer(), players.playerManager[i].ply.layer, false);
                    }
                }



                this.GetComponent <fireBoulder> ().CmdCast(this.gameObject.transform.position);

                // if we casted all our fire meteors!
            }
            else if (this.GetComponent <fireBoulder> ().numFireBallSpawned == numberFireBallsToSpawn)
            {
                // reset our counter.
                this.GetComponent <fireBoulder> ().numFireBallSpawned = 0;
                // we have now casted the spell!
                fireBoulderCasted = false;
            }
            // is it time to cast some death puddles?
        }
        else if (waterPuddlesCasted == true)
        {
            // aquire all the spawn points around the map were death puddles can spawn.
            GameObject [] puddleSpawn = GameObject.FindGameObjectWithTag("deathPudMan").GetComponent <deathPudManager> ().returnPuddleSpawnPoints();

            // get the positions of each puddle.
            Vector2 [] pudPos = new Vector2[puddleSpawn.Length];

            for (int i = 0; i < puddleSpawn.Length; i++)
            {
                Vector2 PPos = new Vector2(puddleSpawn [i].gameObject.transform.position.x, puddleSpawn [i].gameObject.transform.position.y);

                pudPos [i] = PPos;
            }

            // randomly select how many puddles to spawn.
            numberWaterPuddlestoSpawn = Random.Range(0, 16);

            // cast the spell.
            this.gameObject.GetComponent <puddleOfDoom> ().CmdCast(pudPos);


            // re-shuffle which the spawn points in the array.
            GameObject.FindGameObjectWithTag("deathPudMan").GetComponent <deathPudManager> ().randomizeLocation();

            // cast a protective rock wall.
        }
        else if (castRockWall == true)
        {
            // check the time before we set the casting of this ability
            // to false. We want to ensure the rock walls are around for a little bit.
            if (rockWallTimer == 0)
            {
                int counter = 0;

                while (counter < rockWallPosition.Length)
                {
                    rockWallPosition [counter].SetActive(true);


                    counter++;
                }

                rockWallTimer = 3.0f;

                // once we finished casting the, count down until we reach 0 on the timer.
            }
            else
            {
                if (rockWallTimer != 0)
                {
                    rockWallTimer -= Time.deltaTime;

                    if (rockWallTimer <= 0)
                    {
                        rockWallTimer = 0;
                    }
                }

                // once we are at 0, lets hide the rock walls and finish casting this spell .
                if (rockWallTimer == 0)
                {
                    int k = 0;
                    while (k < rockWallPosition.Length)
                    {
                        rockWallPosition [k].SetActive(false);


                        k++;
                    }

                    castRockWall = false;
                }
            }



            // change the AI attack speed.
        }
        else if (castAttackSpeed == true)
        {
            // how many times have we fired?
            // we want to make the spell look like it has been increased!
            if (newSpeedTimeFired < cycles)
            {
                // wait the timer before attacking the player again.
                if (this.gameObject.GetComponent <basicAttackAI> ().attackTime != 0)
                {
                    this.gameObject.GetComponent <basicAttackAI> ().attackTime -= Time.deltaTime;

                    if (this.gameObject.GetComponent <basicAttackAI> ().attackTime <= 0)
                    {
                        this.gameObject.GetComponent <basicAttackAI> ().attackTime = 0;
                    }
                }


                // once the cooldown has finished being calculated lets fire a shot at the player.
                if (this.gameObject.GetComponent <basicAttackAI> ().attackTime == 0)
                {
                    newSpeedTimeFired++;

                    float x = plyController.GetComponent <netWorkAssitant> ().playerManager [playerSpotted].ply.gameObject.transform.position.x;
                    float y = plyController.GetComponent <netWorkAssitant> ().playerManager [playerSpotted].ply.gameObject.transform.position.y;

                    Vector2 myTarget = new Vector2(x, y);
                    Vector2 myPos    = this.gameObject.transform.position;


                    this.gameObject.GetComponent <basicAttackAI> ().CmdCast(myPos, myTarget, true);
                }
            }
            else
            {
                // once we are done, set this spell to false, because we are done casting.

                castAttackSpeed   = false;
                newSpeedTimeFired = 0;
            }
        }
    }