예제 #1
0
    public void lootDrop()
    {
        Vector2 position = parentScript.gameObject.transform.position;

        string[] rawInput = { "EFFECT gold boop 1 -1 1", "EFFECT experience boop 1 -1 1" };
        parentScript.DispenseObject(parentScript.drop, position, new Vector3(), 0f, rawInput, "powerup");
    }
예제 #2
0
    // Update is called once per frame
    public void Update()
    {
        attackDelay.Update();
        attackDelay.setMax(parentScript.stats["attackSpeed"].getCompoundValue());
        if (parentScript.stats["health"] != null)
        {
            if (parentScript.stats["health"].getCompoundValue() <= 0)
            {
                death();
            }
        }
        Debug.Log("Hp:" + parentScript.stats["health"].getCompoundValue() + "Delay:" + attackDelay.getTimer() + "/" + attackDelay.getMax());
        float X = Input.GetAxis("Horizontal");
        float Y = Input.GetAxis("Vertical");

        direction = new Vector2(X, Y);
        if (Input.GetMouseButton(0) && attackDelay.isActive() && parentScript.stats["health"].getCompoundValue() > 0)
        {
            Vector2  target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2  position = parentScript.gameObject.transform.position;
            Vector2  shootVector = (target - position).normalized;
            string[] rawInput = { "EFFECT damage boop 1 -1 1" };
            float    angle = 0, diff = 0;
            int      cnter = Mathf.RoundToInt(parentScript.stats["rangedCount"].getCompoundValue());
            if (cnter <= 1)
            { //Barem jedan projektil
                cnter = 1;
            }
            else   //Izracunaj kuteve
            {
                diff        = Mathf.Abs(parentScript.stats["rangedSpread"].getCompoundValue() / (parentScript.stats["rangedCount"].getCompoundValue() - 1));
                angle       = GameDefaults.vectToAngle(shootVector);
                angle      -= Mathf.Abs(parentScript.stats["rangedSpread"].getCompoundValue() / 2);
                shootVector = GameDefaults.angleToVect(angle);
                //Debug.LogWarning("Angle:" + angle.ToString());
            }
            for (int i = 0; i < cnter; i++)
            {
                parentScript.DispenseObject(parentScript.projectileOptions[0], position, shootVector, 20f, rawInput);
                angle += diff;
                //if (cnter % 2 == 0 && cnter==2) angle += diff;
                shootVector = GameDefaults.angleToVect(angle);
                //Debug.LogWarning("ShootVector:" + target.ToString() + "-" + position.ToString() + "=" + shootVector.ToString());
            }
            if (spriteAnimator != null)
            {
                spriteAnimator.attack = true;
            }
            attackDelay.reset();
        }
    }
예제 #3
0
파일: RangedAI.cs 프로젝트: nmotocic/PPiJ
    // Update is called once per frame
    void Update()
    {
        alarm.Update();
        //Init
        var     my_pos = transform.position;
        Vector3 target;
        //Pick target
        var targetObject = GameObject.FindGameObjectWithTag(targetObjectTag);

        if (targetObject == null) //Mouse
        {
            target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }
        else //Player
        {
            target = targetObject.transform.position;
        }
        //Update animation
        updateAnimation(Mathf.Sign(my_pos.x - target.x));
        target.z = 0;

        if (AiDefaults.getCircleSight(my_pos, projectileObject.GetComponent <CircleCollider2D>().radius, target, true) && state == 0)
        {   //Target obstructed
            setDestination(target, agent);
            rbody2d.velocity = new Vector2(0, 0);
        }
        else
        {                   //State machine
            //Pick state
            if (state != 0) // Stop moving if winding up an attack
            {
                setDestination(my_pos, agent);
            }
            else //Move
            {
                setDestination(target, agent);
                rbody2d.velocity = new Vector2(0, 0);
            }
            //Hurt
            if (state == GameDefaults.hitState())
            {
                if (alarm.isActive())
                {
                    state = 0;
                }
                danger = false;
            }
            //Death
            else if (state == GameDefaults.deatState())
            {
                //Drop stuff, get removed
                danger = false;
                if (alarm.getMax() != GameDefaults.corpseTimeout())
                {
                    alarm.setMax(GameDefaults.corpseTimeout());
                }
                if (alarm.isActive())
                {
                    GameObject.Destroy(gameObject);
                }
            }

            //--------------------------Attacking
            if (state != GameDefaults.deatState())
            {
                if (Vector2.Distance(my_pos, target) <= attackTriggerRange && state == 0)
                { //Prep attack
                    setDestination(my_pos, agent);
                    state     = 1;
                    targetDir = -(my_pos - target);
                    targetDir.Normalize();
                    startPos = my_pos;
                    //Alarm
                    alarm.setMax(attackWindup);
                    alarm.reset();
                }
                else if (state == 1 && alarm.isActive()) //Wait for alarm
                {                                        //Attack - shoot
                    eScript.DispenseObject(projectileObject, my_pos, targetDir, attackSpeed);
                    //Alarm
                    state = 2;
                    alarm.setMax(attackDuration);
                    alarm.reset();
                }
                else if ((state == 2 & alarm.isActive()))
                { //Attack over - stop
                    rbody2d.velocity = new Vector2(0, 0);
                    state            = 3;
                    alarm.setMax(attackCooldown);
                    alarm.reset();
                }
                else if ((state == 3 & alarm.isActive()))
                { //Attack over - stop
                    state = 0;
                }
                //--------------------------Attacking
            }
        }
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        if (permaBuff)
        {
            buff = true;
        }
        alarm.Update();
        aiTimer.Update();
        //Init
        var     my_pos = transform.position;
        Vector3 target;
        //Pick target
        var targetObject = GameObject.FindGameObjectWithTag(targetObjectTag);

        if (targetObject == null) //Mouse
        {
            target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }
        else //Player
        {
            target = targetObject.transform.position;
        }
        //Update animation
        updateAnimation(Mathf.Sign(my_pos.x - target.x));
        target.z = 0;
        //Reset idle
        if (state == 5 && alarm.isActive())
        {
            state = 0;
        }
        //Reset attack alarm
        if (attackType != 0 && state == 0)
        {
            attackType = 0;
            aiTimer.reset();
        }

        //LoS
        if (state == 0 && AiDefaults.getLineSight(my_pos, target))
        {   //Target obstructed
            setDestination(target, agent);
            rbody2d.velocity = new Vector2(0, 0);
        }
        else
        {                   //State machine
            //Pick state
            if (state == 0) // Move
            {
                setDestination(target, agent);
                rbody2d.velocity = new Vector2(0, 0);
            }
            else //Move
            {
            }

            //Hurt
            if (state == GameDefaults.hitState())
            {
                if (alarm.isActive())
                {
                    state = 0;
                }
                danger = false;
            }
            //Death
            else if (state == GameDefaults.deatState())
            {
                //Drop stuff, get removed
                danger = false;
                GameObject.Destroy(myBuff);
                myBuff = null;
            }

            //--------------------------Attacking
            //Pick attack
            if (Vector2.Distance(my_pos, target) <= autoTriggerAtackDist && state == 0 && attackType == 0) //Attack player immediately
            {
                pickAttack();
                while (attackType == -1 || attackType == 4)
                {
                    pickAttack();
                }
                Debug.Log("Picked attack:" + attackType.ToString());
            }
            else if (aiTimer.isActive() && attackType == 0 && state == 0)
            {
                pickAttack();
                while (buff && attackType == 4)
                {
                    pickAttack();
                }
                Debug.Log("Picked attack:" + attackType.ToString());
            }
            //Attacks
            if (attackType > 0)
            {
                //attackType = 4;
                //Dash
                if (attackType == 1)
                {
                    //Windup
                    if (state == 0)
                    {
                        state = 1;
                        alarm.setMax(dashWindup);
                        alarm.reset();
                        //Stop moving
                        setDestination(my_pos, agent);
                    }
                    //Start
                    else if (state == 1 && alarm.isActive())
                    {
                        state  = 2;
                        danger = true;
                        //Set agent speeds
                        if (buff)
                        {
                            agent.speed        = dashSpeed * 1.5f;
                            agent.angularSpeed = dashAngular * 4f;
                            agent.acceleration = dashAccel * 4f;
                            setDestination(target, agent);
                            buff = false;
                            if (myBuff != null)
                            {
                                myBuff.GetComponent <AI_Effect>().deActivate();
                            }
                            alarm.setMax(dashDuration / 2);
                            alarm.reset();
                        }
                        else
                        {
                            agent.speed        = dashSpeed;
                            agent.angularSpeed = dashAngular;
                            agent.acceleration = dashAccel;
                            setDestination(target, agent);
                            alarm.setMax(dashDuration);
                            alarm.reset();
                        }
                    }
                    //End
                    else if ((state == 2) && (alarm.isActive() || !danger))
                    {
                        setState(3); //Stab state
                        alarm.setMax(dashCooldown / 2);
                        alarm.reset();
                        danger = false;
                    }
                    //Cooldown
                    else if ((state == 3) && (alarm.isActive()))
                    {
                        state = 5; //IdleState
                        alarm.reset();
                    }
                }
                //Slash
                else if (attackType == 2)
                {
                    targetDir = -(my_pos - target);
                    targetDir.Normalize();
                    if (state == 0)
                    {
                        state = 1;
                        alarm.setMax(slashWindup);
                        alarm.reset();
                        //Stop moving
                        setDestination(my_pos, agent);

                        if (buff)
                        {
                            attackCombo = 2;
                            buff        = false;
                            if (myBuff != null)
                            {
                                myBuff.GetComponent <AI_Effect>().deActivate();
                            }
                        }
                        else
                        {
                            attackCombo = 0;
                        }
                    }
                    //Start
                    else if (state == 1 && alarm.isActive())
                    {
                        state = 2;
                        alarm.setMax(slashDuration);
                        alarm.reset();
                        eScript.DispenseObject(slashProjectile, my_pos, targetDir, slashProjectileSpeed);
                    }
                    //Swing
                    else if ((state == 2) && (alarm.isActive()))
                    {
                        if (attackCombo > 0)
                        { //Moar swings
                            attackCombo--;
                            state = 1;
                            alarm.setMax(slashWindup / 6);
                            alarm.reset();
                        }
                        else
                        { //Cooldown
                            state = 5;
                            alarm.setMax(slashCooldown);
                            alarm.reset();
                        }
                    }
                }
                //Spin
                else if (attackType == 3)
                {
                    if (state == 0)
                    {
                        state = 1;
                        alarm.setMax(spinWindup);
                        alarm.reset();
                        //Stop moving
                        setDestination(my_pos, agent);
                    }
                    //Start
                    else if (state == 1 && alarm.isActive())
                    {
                        state = 2;
                        alarm.setMax(spinInterval);
                        alarm.reset();

                        if (buff)
                        {
                            attackCombo = spinProjectiles;
                            buff        = false;
                            if (myBuff != null)
                            {
                                myBuff.GetComponent <AI_Effect>().deActivate();
                            }
                            attackCount = 4;
                        }
                        else
                        {
                            attackCombo = spinProjectiles;
                            attackCount = 1;
                        }
                    }
                    //Spin and launch
                    else if ((state == 2) && (alarm.isActive()))
                    {
                        if (attackCombo > 0)
                        { //Keep launching
                            state = 2;
                            alarm.setMax(spinInterval);
                            alarm.reset();
                            attackCombo--;
                            for (int i = 0; i < attackCount; i++)
                            {
                                Vector2 randVector = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
                                randVector.Normalize();
                                eScript.DispenseObject(slashProjectile, my_pos, randVector, slashProjectileSpeed);
                            }
                        }
                        else
                        { //Cooldown
                            state = 3;
                            alarm.setMax(spinCooldown / 3);
                            alarm.reset();
                        }
                    }
                    else if (state == 3 && alarm.isActive())
                    {
                        state = 5;
                        alarm.setMax(2 * spinCooldown / 3);
                        alarm.reset();
                    }
                }
                //Buff
                else if (attackType == 4)
                {
                    if (state == 0)
                    {
                        state = 1;
                        alarm.setMax(slamWindup);
                        alarm.reset();
                        //Stop moving
                        setDestination(my_pos, agent);
                    }
                    //Slam
                    else if (state == 1 && alarm.isActive())
                    {
                        state = 2;
                        alarm.setMax(slamDuration);
                        alarm.reset();
                        //Launch 4 projectiles
                        eScript.DispenseObject(slashProjectile, my_pos, Vector2.down, slashProjectileSpeed);
                        eScript.DispenseObject(slashProjectile, my_pos, Vector2.up, slashProjectileSpeed);
                        eScript.DispenseObject(slashProjectile, my_pos, Vector2.left, slashProjectileSpeed);
                        eScript.DispenseObject(slashProjectile, my_pos, Vector2.right, slashProjectileSpeed);
                        buff = true;
                        if (myBuff != null)
                        {
                            myBuff.GetComponent <AI_Effect>().activate();
                        }
                    }
                    //Slam done
                    else if ((state == 2) && (alarm.isActive()))
                    {
                        state = 5;
                        alarm.setMax(slamCooldown);
                        alarm.reset();
                    }
                }
            }
        }
    }