示例#1
0
    // create and send a SpawnRequestForm
    IEnumerator SendSpawnRequest(int _laneNum, GameControl.Sides _side, int _selectedCreatureType)
    {
        try
        {
            Byte[] buffer = new Byte[bufferSize];

            // save variables to class sending through socket
            SpawnRequestForm spawnRequestForm = new SpawnRequestForm();
            spawnRequestForm.SetlaneNum(_laneNum);
            spawnRequestForm.SetSelectedCreatureType(_selectedCreatureType);
            spawnRequestForm.SetSide(_side);

            // create a JSON string with SpawnRequestForm instance
            string serverMessage = JsonUtility.ToJson(spawnRequestForm);
            buffer = Encoding.ASCII.GetBytes(serverMessage);
            serverControl.GetServerStream().Write(buffer, 0, buffer.Length);

            ClearBuffer(buffer);
        }
        catch (SocketException socketException)
        {
            Debug.Log("SocketException " + socketException.ToString());
        }

        yield return(null);
    }
示例#2
0
 public void SetMissile(Vector3 currentPosition, GameControl.Sides side, int laneNum)
 {
     this.gameObject.transform.position = currentPosition;
     this.side        = side;
     gameObject.tag   = "Lane" + laneNum;
     gameObject.layer = 15 - laneNum;
     if (this.side == GameControl.Sides.Hostile)
     {
         direction            = new Vector3(direction.x * -1, direction.y, direction.z);
         transform.localScale = new Vector3(-1.0f * transform.localScale.x, 1.0f * transform.localScale.y, 1.0f);
     }
 }
示例#3
0
 // spawn selected craeture in selected lane
 public void SpawnCreatureLane(int laneNum, GameControl.Sides side, int buttonNum)
 {
     if (playerCreatureNum == maxUnits)
     {
         // when player spawned too much creatures
         return;
     }
     else if (!UseMana(friendlyCreatureManaCost[buttonNum]))
     {
         // when insufficient mana to spawn such creature
         return;
     }
     playerCreatureNum++;
     SummonCreature(laneNum, side, buttonNum);
 }
示例#4
0
 // push creature called when a creature is spawned in a certain lane
 public void PushCreature(int laneNum, GameControl.Sides side, DefaultCreature newCreature)
 {
     if (side == GameControl.Sides.Friendly)
     {
         lock (lock_friendlyLanes)
         {
             //add the newCreature to friendly lanes in current laneNum
             friendlyLanes.creatureList[laneNum].Add(newCreature);
         }
     }
     else
     {
         lock (lock_hostileLanes)
         {
             //add the newCreature to hostile lanes in current laneNum
             hostileLanes.creatureList[laneNum].Add(newCreature);
         }
     }
 }
示例#5
0
    public virtual void SetCreature(Vector3 st, Vector3 ed, int _buttonNum, int lane, GameControl.Sides sideCheck)
    {
        InitCreature();
        laneNum          = lane;
        gameObject.tag   = "Lane" + lane;
        gameObject.layer = 15 - lane;
        side             = sideCheck;
        detectRange      = attackRange;
        maxHp            = hp;
        buttonNum        = _buttonNum;
        if (side == GameControl.Sides.Hostile)
        {
            speed.x *= -1;
            Enemy    = true;
            transform.localScale = new Vector2(transform.localScale.x * -1, transform.localScale.y);
        }

        MoveTo(st, ed);
    }
示例#6
0
 //pop creature called when a creature died in a certain lane
 public void PopCreature(int laneNum, GameControl.Sides side, DefaultCreature deadCreature)
 {
     spawnControl.OnUnitDeath();
     if (side == GameControl.Sides.Friendly)
     {
         //remove the deadCreature to friendly lanes in current laneNum
         lock (lock_friendlyLanes)
         {
             //remove the deadCreature to friendly lanes in current laneNum
             friendlyLanes.creatureList[laneNum].Remove(deadCreature);
         }
     }
     else
     {
         lock (lock_hostileLanes)
         {
             // remove the deadCreature to hostile lanes in current laneNum
             hostileLanes.creatureList[laneNum].Remove(deadCreature);
         }
     }
 }
示例#7
0
    // summon a creature in certain lane, instantiate in the scene
    public void SummonCreature(int laneNum, GameControl.Sides side, int buttonNum)
    {
        //spawn an actor through instantiate
        GameObject      newObject;
        DefaultCreature newCreature;

        if (side == GameControl.Sides.Friendly)
        {
            newObject = Instantiate <GameObject>(friendlyCreatureList[buttonNum]);
        }
        else
        {
            newObject = Instantiate <GameObject>(hostileCreatureList[buttonNum]);
        }

        // pass control instances to each of the creatures
        newCreature = newObject.GetComponent <DefaultCreature>();
        newCreature.SetGameControl(gameControl);
        newCreature.SetCombatControl(combatControl);

        // set start and end coordinates for spawning creature
        if (side == GameControl.Sides.Friendly)
        {
            startCoord[laneNum] -= new Vector3(0, 0, layerOffset);
            endCoord[laneNum]   -= new Vector3(0, 0, layerOffset);
            newCreature.SetCreature(startCoord[laneNum], endCoord[laneNum], buttonNum, laneNum, side);
        }
        else
        {
            startCoord[laneNum] -= new Vector3(0, 0, layerOffset);
            endCoord[laneNum]   -= new Vector3(0, 0, layerOffset);
            newCreature.SetCreature(endCoord[laneNum], startCoord[laneNum], buttonNum, laneNum, side);
        }

        // push creature into the list(side, lane) in combatControl
        combatControl.PushCreature(laneNum, side, newCreature);
    }
示例#8
0
 // search creatures in melee attack range
 public bool SearchCreature(Vector3 currentPosition, float attackRange, int laneNum, GameControl.Sides side)
 {
     //attack from friendly to hostile
     if (side == GameControl.Sides.Friendly)
     {
         lock (lock_hostileLanes)
         {
             //search creatures within attackrange of friendly lanes in current laneNum
             foreach (DefaultCreature currentCreature in hostileLanes.creatureList[laneNum])
             {
                 if (currentCreature.transform.position.x - currentPosition.x < attackRange)
                 {
                     return(true);
                 }
             }
         }
     }
     //attack from hostile to friendly
     else
     {
         lock (lock_friendlyLanes)
         {
             //search creatures within attackrange of hostile lanes in current laneNum
             foreach (DefaultCreature currentCreature in friendlyLanes.creatureList[laneNum])
             {
                 if (currentPosition.x - currentCreature.transform.position.x < attackRange)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
示例#9
0
    // spawn a missile that damage on hit
    public void MissileAttack(Vector3 currentPosition, GameObject projectile, int attackDamage, int laneNum, GameControl.Sides side)
    {
        GameObject     newObject  = Instantiate <GameObject>(projectile);
        DefaultMissile newMissile = newObject.GetComponent <DefaultMissile>();

        newMissile.SetMissile(currentPosition, side, laneNum);
    }
示例#10
0
    // heal performed to nearby allies on confronting hostile creature
    public void Heal(Vector3 currentPosition, float attackRange, int attackDamage, int laneNum, GameControl.Sides side)
    {
        //heal friendly creatures
        if (side == GameControl.Sides.Friendly)
        {
            lock (lock_friendlyLanes)
            {
                List <DefaultCreature> currentList = friendlyLanes.creatureList[laneNum];

                for (int i = currentList.Count - 1; i >= 0; i--)
                {
                    if (Mathf.Abs(currentList[i].transform.position.x - currentPosition.x) < attackRange)
                    {
                        currentList[i].DamageTaken(attackDamage, 0);
                    }
                }
            }
        }
        //heal hostile creatures
        else
        {
            lock (lock_hostileLanes)
            {
                List <DefaultCreature> currentList = hostileLanes.creatureList[laneNum];

                for (int i = currentList.Count - 1; i >= 0; i--)
                {
                    if (Mathf.Abs(currentList[i].transform.position.x - currentPosition.x) < attackRange)
                    {
                        currentList[i].DamageTaken(attackDamage, 0);
                    }
                }
            }
        }
    }
示例#11
0
 // attacks performed to each creature
 public void MeleeAttack(Vector3 currentPosition, float attackRange, int attackDamage, int size, int laneNum, GameControl.Sides side)
 {
     // attack from friendly to hostile
     if (side == GameControl.Sides.Friendly)
     {
         // used lock to stop creature unwanted destroys
         lock (lock_hostileLanes)
         {
             List <DefaultCreature> currentList = hostileLanes.creatureList[laneNum];
             // search creatures within attackrange of friendly lanes in current laneNum
             for (int i = currentList.Count - 1; i >= 0; i--)
             {
                 if (currentList[i].transform.position.x - currentPosition.x < attackRange)
                 {
                     currentList[i].DamageTaken(attackDamage, size);
                 }
             }
         }
     }
     // attack from hostile to friendly
     else
     {
         lock (lock_friendlyLanes)
         {
             List <DefaultCreature> currentList = friendlyLanes.creatureList[laneNum];
             //search creatures within attackrange of hostile lanes in current laneNum
             for (int i = currentList.Count - 1; i >= 0; i--)
             {
                 if (currentPosition.x - currentList[i].transform.position.x < attackRange)
                 {
                     currentList[i].DamageTaken(attackDamage, size);
                 }
             }
         }
     }
 }
示例#12
0
 public override void SetCreature(Vector3 st, Vector3 ed, int buttonNum, int lane, GameControl.Sides sideCheck)
 {
     base.SetCreature(st, ed, buttonNum, lane, sideCheck);
     attackDamage = healAmount * -1; //
 }