void onUpdate(GameObject obj, Healthbar bar)
 {
     if (inspector.setScriptsFrom(obj))
     {
         bar.SetHealth(inspector.getLives());
     }
 }
 /// <summary>set Debuginfo from given unit</summary>
 /// <param name="unit">lolsbarry</param>
 public void setFromUnit(GameObject unit)
 {
     if (i.setScriptsFrom(unit))
     {
         initialLives   = i.getInitialLives();
         currentLives   = i.getLives();
         defaultDammage = i.getDamage();
         attackTag      = i.getAttackTag();
         range          = i.getRange();
         unitType       = i.getScriptType();
         //needAction=i.getNeedAction();
     }
 }
Beispiel #3
0
    ///<summary>Check battle started and updates units to be set dead in certain condition. also updates number and battle indicator, debug infos</summary>
    public void Academy_Update()
    {
        if (battleStarted)
        {
            knightNumber = 0;
            enemyNumber  = 0;
            GameObject[] Units = inspector.getCurrentUnits();
            foreach (GameObject unit in Units)
            {
                if (inspector.setScriptsFrom(unit) && !inspector.isDead() && inspector.getLives() < 0 && !inspector.isDoneInProgress())
                {
                    inspector.setDead();
                }
            }
            GameObject[] UpdatedUnits = inspector.getCurrentUnits();
            for (int i = 0; i < UpdatedUnits.Length; i++)
            {
                if (inspector.setScriptsFrom(UpdatedUnits[i]) && !inspector.isDead())
                {
                    knightNumber += (inspector.getTag() == "Knight")?1:0;
                    enemyNumber  += (inspector.getTag() == "Enemy")?1:0;
                }
            }
        }

        /*
         * GameObject nowUnit=cam.getStickyUnit();
         * if(inspector.setScriptsFrom(nowUnit)) {
         *      DebugInner.setFromUnit(nowUnit);
         * }
         *
         * infoPanel.text = $@"Id:{inspector.InnerObject.GetInstanceID()}
         * Hp:{DebugInner.initialLives}/{DebugInner.currentLives}
         * Default Damage:{DebugInner.defaultDammage}
         * Attack Tag:{DebugInner.attackTag}
         * Range:{DebugInner.range}
         * Unit Type:{DebugInner.unitType}
         *
         * Total Damage:{DebugInner.totalDamage}
         * Pre Reward:{DebugInner.preReward}
         *
         * Knight Num:{knightNumber}
         * Enemy Num:{enemyNumber}
         * Episode:{AcademyInner.GetEpisodeCount()}
         * ";
         *
         */
    }
    public virtual bool DecideAttack(float?act)
    {
        //act will indicates special ability
        if (!sys.FirstWarnUseOfAttackFb)
        {
            Debug.LogWarning("No attack method implemented, use fallback method");
            sys.FirstWarnUseOfAttackFb = true;
        }
        bool attacking = false;

        if (act != null)
        {
            if (act >= 0)
            {
                float      minDistance = Mathf.Infinity;
                GameObject minUnit     = sys.EmptyUnit;
                foreach (GameObject enemy in inspector.getCurrentEnemys())
                {
                    if (enemy == this.gameObject)
                    {
                        continue;
                    }
                    if (inspector.setScriptsFrom(enemy) && !inspector.isDead())
                    {
                        float distanceToTarget = Vector3.Distance(this.transform.localPosition, enemy.transform.localPosition);
                        if (distanceToTarget <= DeprecatedAttackRange)
                        {
                            minUnit     = (distanceToTarget < minDistance)?enemy:minUnit;
                            minDistance = (distanceToTarget < minDistance)?distanceToTarget:minDistance;
                        }
                    }
                }
                if (minUnit.CompareTag("Enemy") || minUnit.CompareTag("Knight"))
                {
                    Vector3 currentTargetPosition = minUnit.transform.position;
                    currentTargetPosition.y = transform.position.y;
                    transform.LookAt(currentTargetPosition);
                    if (inspector.setScriptsFrom(minUnit))
                    {
                        inspector.setLives(inspector.getLives() - (Time.deltaTime * damage));
                        attacking = true;
                        test     += 1;
                        if (inspector.getLives() < 0)
                        {
                            print("Damaged opponent dead");
                            //inspector.printOnPanel($"{this.gameObject.GetInstanceID()}:Reward 0.5");
                            //AddReward(0.5f);
                        }
                    }
                    else
                    {
                        Debug.LogError("Invalid unit targetted.");
                    }
                }
            }
            else
            {
            }
        }
        return(attacking);
    }
Beispiel #5
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
    }