Exemple #1
0
    // Start is called before the first frame
    void Start()
    {
        gridClass    = aStaar.GetComponent <Grid>();
        pathfinder   = aStaar.GetComponent <Pathfinding>();
        lastPosition = enemy.transform.position;
        localGrid    = gridClass.grid;

        playerStats = player.GetComponent <UnitStats>();
        enemyStats  = enemy.GetComponent <UnitStats>();

        ps = enemyWeapon.GetComponent <PlayParticle>();

        coverList   = new List <GameObject>();
        enemyUnits  = new List <GameObject>();
        playerUnits = new List <GameObject>();

        for (int i = 0; i < allPlayerUnits.transform.childCount; i++)
        {
            playerUnits.Add(allPlayerUnits.transform.GetChild(i).gameObject);
        }

        for (int i = 0; i < allEnemyUnits.transform.childCount; i++)
        {
            enemyUnits.Add(allEnemyUnits.transform.GetChild(i).gameObject);
        }


        for (int i = 0; i < allCover.transform.childCount; i++)
        {
            coverList.Add(allCover.transform.GetChild(i).gameObject);
        }
    }
 //Play the correct particle
 public void OnPlayParticle(PlayParticle evt)
 {
     if (evt.PlayerIndex == PlayerIndex)
     {
         if (evt.ParticleType == "Block")
         {
             Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/Guard_Counter"), transform);
             Destroy(blockBubble);
         }
         else if (evt.ParticleType == "Tech")
         {
             Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/TechRoll"), transform);
         }
         else if (evt.ParticleType == "BlockBubble")
         {
             if (blockBubble == null)
             {
                 blockBubble = Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/Guard"), transform) as GameObject;
             }
             else
             {
                 Destroy(blockBubble);
             }
         }
     }
     else if (evt.ParticleType == "Strike")
     {
         if (evt.Health % 2 == 0)
         {
             Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/Attacks_Break"), transform);
         }
         else
         {
             Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/Attacks_Normal"), transform);
         }
     }
     else if (evt.ParticleType == "Grab")
     {
         if (evt.Health % 2 == 0)
         {
             Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/Kick_Break"), transform);
         }
         else
         {
             Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/Kick_Normal"), transform);
         }
     }
     else if (evt.ParticleType == "Counter")
     {
         if (evt.Health % 2 == 0)
         {
             Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/Counter_Break"), transform);
         }
         else
         {
             Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/Counter_Normal"), transform);
         }
         Instantiate(Resources.Load("Prefabs/PalmmyEffect/BattleEffect/Player" + (PlayerIndex + 1) + "/CounterText"), UIcanvas.transform);
     }
 }
Exemple #3
0
 // Start is called before the first frame update
 void Start()
 {
     UNITS      = this.transform.gameObject;
     actionTime = false;
     pathfinder = aStaar.GetComponent <Pathfinding>();
     yourStats  = transform.GetChild(0).gameObject.GetComponent <UnitStats>();
     playerMove = logicManage.GetComponent <playermovement>();
     ps         = svd.GetComponent <PlayParticle>();
     unit       = UNITS.transform.GetChild(0).gameObject;
     moveDone   = true;
     missed.SetActive(false);
 }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        if ((Input.GetButtonDown("next") && !actionTime && moveDone && manager.get_turn()) || (manager.switchAlly))
        {
            print("CHANGING ACTION");
            if (currentUnit == UNITS.transform.childCount - 1)
            {
                currentUnit = 0;
            }
            else
            {
                currentUnit++;
            }

            if (UNITS.transform.childCount > 0)
            {
                unit = UNITS.transform.GetChild(currentUnit).gameObject;
            }
            yourStats          = unit.GetComponent <UnitStats>();
            svd                = unit.transform.GetChild(2).gameObject;
            ps                 = svd.GetComponent <PlayParticle>();
            manager.switchAlly = false;
            manager.switchDestroy();
            return;
        }


        if (Input.GetButtonDown("prev") && !actionTime && moveDone && manager.get_turn())
        {
            print("CHANGING ACTION");

            if (currentUnit == 0)
            {
                currentUnit = UNITS.transform.childCount - 1;
            }
            else
            {
                currentUnit--;
            }

            unit      = UNITS.transform.GetChild(currentUnit).gameObject;
            yourStats = unit.GetComponent <UnitStats>();
            svd       = unit.transform.GetChild(2).gameObject;
            ps        = svd.GetComponent <PlayParticle>();
            return;
        }


        //right click to shoot at target

        if (actionTime)
        {
            if (Input.GetButtonDown("Fire2"))
            {
                RaycastHit hit;

                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity))
                {
                    //layer 10 is an enemy and raycast from this player to the enemy also succeeds
                    if (hit.collider.gameObject.layer == 10)
                    {
                        tgt = hit.collider.gameObject;
                        RaycastHit hit2;

                        //another raycast from this position to the enemy to check line of sight
                        if (Physics.Raycast(unit.transform.position, (tgt.transform.position - unit.transform.position), out hit2, Mathf.Infinity))
                        {
                            //attack code
                            if (hit2.collider.gameObject.layer == 10)
                            {
                                unit.transform.LookAt(tgt.transform);
                                //call particle scripts
                                //Debug.Log(ps);
                                ps.playParticle();
                                //wait after shooting

                                enemyStats = tgt.GetComponent <UnitStats>();
                                float hitChance  = yourStats.accuracy - enemyStats.evasion;
                                bool  RNGSuccess = Random.Range(0.0f, 101.0f) <= hitChance;
                                //Debug.Log("hit chance is " + hitChance);
                                if (RNGSuccess)
                                {
                                    // Debug.Log("you hit the enemy for " + yourStats.weaponDamage + " damage.");
                                    enemyStats.takeDamage(yourStats.weaponDamage);
                                    //Debug.Log("enemey health is " + enemyStats.health);
                                }
                                else
                                {
                                    missed.SetActive(true);
                                }
                                //prevent second shot
                                actionTime = false;
                                StartCoroutine(ExampleCoroutine());
                            }
                        }
                        //rotate the player to shoot at the enemy
                        //calculate hit chance
                        //shoot
                    }
                }
            }
            if (Input.GetButtonDown("Jump"))
            {
                pathfinder.setAction(false);
                manager.set_turn(false);
                actionTime = false;
                playerMove.playerActionDone = true;
            }
        }
    }
    PlayParticle playParticle; // 声明一个代理

    /// <summary>
    /// 构造函数,给代理赋值
    /// </summary>
    /// <param name="pp"></param>
    public PlayAnim(PlayParticle pp)
    {
        this.playParticle = pp;
    }
Exemple #6
0
    public void Decision_Tree()
    {
        //check if player is visible
        if (!performedAction)
        {
            enemy        = enemyUnits[Random.Range(0, enemyUnits.Count)];
            enemyStats   = enemy.GetComponent <UnitStats>();
            player       = playerUnits[Random.Range(0, playerUnits.Count)];
            playerStats  = player.GetComponent <UnitStats>();
            lastPosition = enemy.transform.position;
            enemyWeapon  = enemy.transform.GetChild(0).gameObject;
            ps           = enemyWeapon.GetComponent <PlayParticle>();
        }

        RaycastHit hitPlayer;

        if (!performedAction && enemy != null && Physics.Raycast(enemy.transform.position, (player.transform.position - enemy.transform.position), out hitPlayer, Mathf.Infinity))
        {
            //i can see the player
            if (hitPlayer.collider.gameObject.layer == 11)
            {
                //Debug.Log("SEE PLAYER");
                float maxDistCover = maxDistance * .75f;
                //loop through pieces of cover to find min
                float      minDist    = Mathf.Infinity;
                GameObject closestObj = null;
                foreach (GameObject child in coverList)
                {
                    //Debug.Log("FINDING COVER");
                    float dist = Vector3.Distance(child.transform.position, enemy.transform.position);
                    if (dist < minDist)
                    {
                        closestObj = child;
                        minDist    = dist;
                    }
                }
                //Debug.Log(closestObj.transform);
                //the cover must be close enough
                if (closestObj != null && minDist <= maxDistance)
                {
                    //Debug.Log("FINDING HOTSPOT");
                    //pass in the "ideal" cover hotspot(furthest from the player)
                    Transform child0 = closestObj.transform.GetChild(0);
                    Transform child1 = closestObj.transform.GetChild(1);

                    float dist = Vector3.Distance(child0.position, player.transform.position);

                    closestObj = child0.gameObject;

                    if (dist < Vector3.Distance(child1.position, player.transform.position))
                    {
                        closestObj = child1.gameObject;
                    }

                    //Debug.Log("MOVING");
                    //Debug.Log(closestObj.transform);

                    foreach (GameObject obj in enemyUnits)
                    {
                        if (obj != enemy)
                        {
                            if (obj.transform.position.x - closestObj.transform.position.x < 2.0f && obj.transform.position.z - closestObj.transform.position.z < 2.0f)
                            {
                                closestObj = player;
                                break;
                            }
                        }
                    }

                    AI_To_Dest(closestObj);
                }
                else
                {
                    //Debug.Log("START SHOOTING");
                    enemy.transform.LookAt(player.transform);
                    ps.playParticle();
                    float hitChance  = enemyStats.accuracy - enemyStats.evasion;
                    bool  RNGSuccess = Random.Range(0.0f, 101.0f) <= hitChance;
                    if (RNGSuccess)
                    {
                        playerStats.takeDamage(enemyStats.weaponDamage);
                    }
                    performedAction = true;
                    waiting         = true;
                    StartCoroutine(ExampleCoroutine());
                    //no cover found, start shooting
                }
            }
            //i cannot see the player so i move towards players location
            else
            {
                AI_To_Dest(player);
            }
        }
    }