コード例 #1
0
    public override bool DecideAttack(float?act)
    {
        bool attacking = false;

        if (act != null)
        {
            if (act >= 0)
            {
                foreach (GameObject unit in HitboxComponent.GetCollideObjects())
                {
                    if (unit == null && !ReferenceEquals(unit, null))
                    {
                        HitboxComponent.RemoveObject(unit);
                        continue;
                    }
                    if (unit.CompareTag("Knight"))
                    {
                        if (inspector.setScriptsFrom(unit) && !inspector.isDead())
                        {
                            inspector.setLives(inspector.getLives() + (damage));
                            if (inspector.getLives() < 0)
                            {
                                HitboxComponent.RemoveObject(unit);
                            }
                            attacking = true;
                            if (sys.showeffects)
                            {
                                HealingParticle.Play();
                            }
                        }
                        else
                        {
                            Debug.LogWarning("Invalid Target Triggered.");
                        }
                    }
                }
                isPassedCooltime = false;
                StartCoroutine("Cooltime");
            }
        }
        rewardSys.UpdateAtAttackCheck(this, attacking);
        return(attacking);
    }
コード例 #2
0
    void FixedUpdate()
    {
        if (lives != lastLives && Academy.showeffects)
        {
            if (!DamagedParticle.isPlaying)
            {
                DamagedParticle.Play();
                //DamagedParticle.Simulate(Time.unscaledDeltaTime, true, false);
            }
            lastLives = lives;
        }

        //find closest enemy
        //ML:relating to moves
        if (currentTarget != null)
        {
            inspector.setScriptsFrom(currentTarget.gameObject);
            if (!inspector.isScriptValid() || inspector.isDead())
            {
                currentTarget = findCurrentTarget();
            }
        }
        else
        {
            currentTarget = findCurrentTarget();
        }


        //if character ran out of lives, it should die
        if (lives < 0 && !dead)
        {
            die();
        }
        else
        {
            if (Vector3.Distance(agent.destination, transform.position) <= agent.stoppingDistance && currentTarget != null)
            {
                int sign  = rnd.Next(0, 2) * 2 - 1;
                int sign2 = rnd.Next(0, 2) * 2 - 1;
                agent.destination = new Vector3(currentTarget.position.x + (float)gausianRand() * RandomRange * sign, currentTarget.position.y, currentTarget.position.z + (float)gausianRand() * RandomRange * sign2);
                agent.isStopped   = false;
            }
            else if (currentTarget == null)
            {
                agent.destination = getRandomPosition(area);
            }
            if (isPassedCooltime)              //&& (rnd.Next(0, 2) * 2 - 1)>0) {
            {
                foreach (GameObject unit in HitboxComponent.GetCollideObjects())
                {
                    if (unit == null && !ReferenceEquals(unit, null))
                    {
                        HitboxComponent.RemoveObject(unit);
                        continue;
                    }
                    if (unit.CompareTag("Knight"))
                    {
                        if (inspector.setScriptsFrom(unit) && !inspector.isDead())
                        {
                            inspector.setLives(inspector.getLives() - (damage));
                            if (inspector.getLives() < 0)
                            {
                                HitboxComponent.RemoveObject(unit);
                            }
                        }
                        else
                        {
                            Debug.LogWarning("Invalid Target Triggered.");
                        }
                    }
                }
                isPassedCooltime = false;
                StartCoroutine("Cooltime");
            }
        }
        //ML:relating to moves
    }