예제 #1
0
 // Use this for initialization
 void Start()
 {
     attack = PlayerAttackScript.ATTACK.MELEE;
     PlayerMovementScript.isMelee = true;
     StartCoroutine("att");
     //-ChargeBarUI.SetActive (false);
     characterstats = gameObject.GetComponent <CharacterStatsScript> ();
     xboxScript     = GetComponent <XboxPlayerControlScript> ();
 }
예제 #2
0
 public int CalDmgSkill(ATTACK type, double skillBonus, Status target, int skillStack)
 {
     if (type == ATTACK.PHYSICAL)
     {
         return((int)(ATK * skillBonus * _passiveBonusATK * _eventBonusDmg * _buffBonusATK * skillStack - target.getDEF() * _buffBonusDEF * _passiveBonusDEF));
     }
     else
     {
         return((int)(ATK * skillBonus * _passiveBonusMATK * _eventBonusDmg * _buffBonusMATK * skillStack - target.getMDEF() * _buffBonusMDEF * _passiveBonusMDEF));
     }
 }
예제 #3
0
 private void handleAttackSelection()
 {
     if (Input.GetKey(KeyCode.Alpha1))
     {
         ActiveAttack = ATTACK.MEELE;
         GetComponentInChildren <RocketLauncher>().Activate(false);
     }
     else if (Input.GetKey(KeyCode.Alpha2))
     {
         ActiveAttack = ATTACK.GUN;
         GetComponentInChildren <RocketLauncher>().Activate(true);
     }
     else if (Input.GetKey(KeyCode.Alpha3))
     {
         ActiveAttack = ATTACK.LASER;
         GetComponentInChildren <RocketLauncher>().Activate(false);
     }
     else if (Input.GetKey(KeyCode.LeftControl) && keyShifted == 0)
     {
         ActiveAttack = (ATTACK)(((int)ActiveAttack + 1) % 3);
         GetComponentInChildren <RocketLauncher>().Activate(false);
         keyShifted = 10;
     }
 }
예제 #4
0
파일: Entity.cs 프로젝트: kula1027/AD
    public void init(int entityCode_, int childCode_)
    {
        moveScript = gameObject.GetComponent<MOVE>();
        attackScript = gameObject.GetComponent<ATTACK>();
        skillManager = gameObject.GetComponent<SkillManager> ();
        buffManager = gameObject.GetComponent<Buffmanager>();
        entityCode = entityCode_;
        entityName = Config.name[entityCode];
        gameObject.name = entityName;
        fullHp = Config.fullHp[entityCode];
        currHp = fullHp;
        bonusDamage = 0;
        str = Config.str[entityCode];
        dex = Config.dex[entityCode];
        accuracyRate = dex * Config.accuracyRatePerDex;
        avoidRate = dex * Config.avoidRatePerDex;
        criticalRate = luck * Config.criticalRatePerLuck;
        absoluteAvoidRate = luck * Config.absoluteAvoidRatePerLuck;
        trapFindRate = intelligence * Config.trapFindRatePerIntelligence;
        cocktailSuccessRate = 0.5f + intelligence * Config.cocktailSuccessRatePerIntelligence;
        labeledAlcoholDropRate = 0.05f + luck * Config.labeledAlcoholDropRatePerLuck;
        rareItemDropRate = 0.1f + luck * Config.rareItemDropRatePerLuck;
        luckZeroDeathRate = Config.luckZeroDeathRate;
        if (dex <= 0){
            speedLevel = 1;
            countPerTurn = 8;
        }else if (dex > 0 && dex <= 30){
            speedLevel = 2;
            countPerTurn = 4;
        }else if (dex > 30 && dex <= 60){
            speedLevel = 3;
            countPerTurn = 2;
        }else if (dex >60){
            speedLevel = 4;
            countPerTurn = 1;
        }
        //Debug.Log (name + " : counterPerTurn == " + countPerTurn);
        intelligence = Config.intelligence[entityCode];
        luck = Config.luck[entityCode];
        fullMp = Config.fullMp;
        currMp = 0;
        bloodSuck = 0;
        isKoala = false;
        isStun = false;
        isOoC = false;
        drunkenType = Config.drunkenType[entityCode];
        turnCount = 0;
        range = Config.range[entityCode];
        sight = Config.sight[entityCode];
        regenHp = 0.2f;
        regenMp = -2;
        regenHpBuffer = 0;

        skillStandBy = -1;
        isSustain = false;
        alcoholStack = 0;

        transform.FindChild ("Image").GetComponent<SpriteRenderer> ().sortingOrder = ((int)transform.position.y);

        initChild (childCode_);
    }
 // Randomise attacking method
 void RandomiseAttack()
 {
     currentAttack = (ATTACK)Random.Range((int)ATTACK.A_CHARGE, (int)ATTACK.A_ROAR + 1);
 }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        BS = anim.GetCurrentAnimatorStateInfo(0);
        //anim.SetBool ("Aim", false);
        //anim.SetBool ("Shoot", false);
        if (BS.fullPathHash == Shoot)
        {
            anim.SetBool("Shoot", false);
        }
        if (Input.GetButton("X360_B") && !isAttack && !spinAttack)
        {
            attack = PlayerAttackScript.ATTACK.RANGE;
            anim.SetBool("Aim", true);
        }
        else if (Input.GetButton("X360_X"))
        {
            attack = PlayerAttackScript.ATTACK.MELEE;
        }

        if (RangeAttRate > 0.0f)
        {
            RangeAttRate -= Time.fixedDeltaTime;
        }
        if (MeleeAttRate > 0.0f)
        {
            MeleeAttRate -= Time.fixedDeltaTime;
        }
        if (MeleeAttRate <= 0.0f || RangeAttRate <= 0.0f)
        {
            isAttack = false;
        }
        if (AttackComboCancelTimer > 0.0f)
        {
            AttackComboCancelTimer -= Time.fixedDeltaTime;
        }
        else if (AttackComboCancelTimer <= ACCDuration)
        {
            numberofattack = 1;
        }

        if (Input.GetButton("X360_X") && !isAttack && !spinAttack && !XboxPlayerControlScript.isRoll && !isRange)
        {
            isMelee              = true;
            MeleeChargeDuration += Time.fixedDeltaTime;
            if (MeleeChargeDuration > 3.0f)
            {
                MeleeChargeDuration = 3.0f;
            }
        }
        if (Input.GetButton("X360_B") && !isAttack && !spinAttack && !XboxPlayerControlScript.isRoll && !isMelee)
        {
            isRange              = true;
            RangeChargeDuration += Time.fixedDeltaTime;
            if (RangeChargeDuration > 3.0f)
            {
                RangeChargeDuration = 3.0f;
            }
        }
        if (MeleeChargeDuration > TimeTakenToStartCharge)
        {
            isCharging = true;
            ChargeBarUI.GetComponent <ChargeBarScript> ().chargeDuration = MeleeChargeDuration;
            //ChargeBarUI.SetActive (true);
        }
        if (RangeChargeDuration > TimeTakenToStartCharge)
        {
            isCharging = true;
            ChargeBarUI.GetComponent <ChargeBarScript> ().chargeDuration = RangeChargeDuration;
        }
        else
        {
            ChargeBarUI.GetComponent <ChargeBarScript> ().ratio = 0.0f;
            isCharging = false;
            //ChargeBarUI.SetActive (false);
        }

        if (Input.GetButton("X360_B") && RangeChargeDuration > TimeTakenToStartCharge)
        {
            XboxPlayerControlScript.isStartCharged = true;
            anim.SetBool("Aim", true);
        }
        else
        {
            XboxPlayerControlScript.isStartCharged = false;
            anim.SetBool("Aim", false);
        }
        if (spinAttack)
        {
            //anim.SetBool("Spin",true);
            //anim.SetBool ("Run", false);
            isAttack           = true;
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, angle, 0), 10.0f);
            angle        += 10.0f;
            SpinDuration -= Time.fixedDeltaTime;
            if (SpinDuration <= 0.0f)
            {
                isMelee      = false;
                spinAttack   = false;
                isAttack     = false;
                SpinDuration = 0.0f;
                Destroy(temp_SpinAtt);
                temp_SpinAtt = null;
                anim.SetBool("Spin", false);
            }
        }
    }
예제 #7
0
    // Used to define this AI's logic
    void UpdateStates()
    {
        // if we are jumping, then don't do anything
        if (!isGrounded || isJumped)
        {
            // Are we falling?
            if (myRb2D.velocity.y < 0.0f)
            {
                isJumped = false;
                myAnimator.SetBool("mb_Fall", true);
            }
            if (!jumpSlowed)    // Have we slowed down the jumping yet?
            {
                // if we are close enough to the target, then stop, incase we overshoot
                if ((myRb2D.position.y >= moveTargetPos.y) && (moveTargetPos - myRb2D.position).sqrMagnitude < 2.0f)
                {
                    SlowJumpHorVel();
                }
            }

            // Update Timers
            switch (currentState)
            {
            case STATES.S_RUNAWAY:
            {
                fleeTimer -= Time.deltaTime;
                if (fleeTimer < 0.0f)
                {
                    currentState = STATES.S_EGG_DIFFERENTHEIGHT;
                    fleeTimer    = fleeTime;
                }
            }
            break;
            }

            return;
        }



        switch (currentState)
        {
        case STATES.S_EGG_SIMILARHEIGHT:
        {
            // If not yet grounded, return;
            if (!isGrounded)
            {
                return;
            }
            // Is a player in range?
            if (IsPlayerInRange())
            {
                return;
            }
            // Once too far, then change state
            float posDiff = transform.position.y - targetObject.transform.position.y;
            if (posDiff >= YPosDifference)
            {
                currentState = STATES.S_EGG_DIFFERENTHEIGHT;
                return;
            }


            // set the position of egg and move there
            SetNewObjectTarget(Egg.Instance.gameObject);
            // Check if we can attack depending on what attacking method
            float distance = (moveTargetPos - myRb2D.position).sqrMagnitude;
            switch (attackMethod)
            {
            case ATTACK.A_MELEE:
            {
                if (distance <= (meleeDistance * meleeDistance))
                {
                    currentState = STATES.S_MELEE_EGG;
                    StopVel();
                    myAnimator.SetBool("mb_Melee", true);
                    return;
                }
            }
            break;

            case ATTACK.A_SHOOT:
            {
                // check if we can shoot projectile at egg
                if (distance <= (maxShootingRange * maxShootingRange))
                {
                    currentState = STATES.S_SHOOT_EGG;
                    StopVel();
                    myAnimator.SetBool("mb_Shoot", true);
                    return;
                }
            }
            break;
            }


            // Move enemy
            if (!MoveWolf())
            {
                // If we don't find any platforms to jump to, then we turn back
                Vector2 platformEdgePos = FindNearestJumpPoint();
                if (platformEdgePos == Vector2.zero)
                {
                    // Walk back
                    //currentState = STATES.S_WALKBACK;
                    //TurnWolfAround();

                    // Check if we can attack using range
                }
                else
                {
                    // Set new target and jump there
                    moveTargetPos = platformEdgePos;
                    JumpWolf(moveTargetPos);
                }

                return;
            }
        }
        break;

        case STATES.S_EGG_DIFFERENTHEIGHT:
        {
            // Is a player in range?
            if (IsPlayerInRange())
            {
                return;
            }

            // set the target as egg
            SetNewObjectTarget(Egg.Instance.gameObject);
            // Move enemy
            if (!MoveWolf())
            {
                // Find platforms below
                Vector2 platformEdgePos = FindJumpPointBelow();
                if (platformEdgePos != Vector2.zero)
                {
                    if (!CanDrop())             // if our collider is too big, then need to move more before can drop
                    {
                        MoveWolf(false);
                        return;
                    }
                    // Set new target and jump there
                    SetNewPosTarget(platformEdgePos);
                    JumpWolf(moveTargetPos);
                    return;
                }
                else if (IsPlatformBelow())
                {
                    MoveWolf(false);
                }
            }

            // Once close enough Y pos,
            float posDiff = transform.position.y - targetObject.transform.position.y;
            if (posDiff < YPosDifference)
            {
                currentState = STATES.S_EGG_SIMILARHEIGHT;
                // Randomise the attacking method
                //attackMethod = (ATTACK)Random.Range((int)ATTACK.A_MELEE, (int)ATTACK.A_SHOOT + 1);
                return;
            }
            // if we are stuck, then we should go to one of the points
            posDiff = targetObject.transform.position.x - myRb2D.position.x;
            if (posDiff < 0.5f && posDiff > -0.5f)
            {
                currentState = STATES.S_EGG_ONTOP;
                // Go to the closest position from the egg WITH AN OFFSET
                moveTargetPos = groundCheckScript.platformStandingOn.GetClosestPosition(moveTargetPos);
                moveDirection = moveTargetPos - myRb2D.position;
            }
        }
        break;

        case STATES.S_EGG_ONTOP:        // When we enter this state, we should already have a target to move to
        {
            // Is a player in range?
            if (IsPlayerInRange())
            {
                return;
            }

            // Keep moving until we can't move anymore,
            // then jump
            if (!MoveWolf())
            {
                Vector2 platformEdgePos = FindJumpPointBelow();
                if (platformEdgePos != Vector2.zero)
                {
                    if (!CanDrop())             // if our collider is too big, then need to move more before can drop
                    {
                        MoveWolf(false);
                        return;
                    }
                    // Set new target and jump there
                    SetNewPosTarget(platformEdgePos);
                    JumpWolf(moveTargetPos);
                    currentState = STATES.S_EGG_DIFFERENTHEIGHT;
                    return;
                }
            }
        }
        break;

        case STATES.S_WALKBACK:
        {
            // Is a player in range?
            if (IsPlayerInRange())
            {
                return;
            }

            // Move enemy
            if (!MoveWolf())
            {
                TurnWolfAround();
                return;
            }
        }
        break;



        case STATES.S_MELEE_EGG:
        {
            // Check if done animation
            if (meleeDoneAnimation)
            {
                // Reset bool
                meleeDoneAnimation = false;

                // if we were hit by player
                if (playerAttackedWolf)
                {
                    // Is a player in range?
                    if (IsPlayerInRange())
                    {
                        SetNewObjectTarget(targetObject);
                    }
                    else
                    {
                        // Run to nearest platform edge, since no player
                        currentState = STATES.S_RUNAWAY;
                        SetNewPosTarget(groundCheckScript.platformStandingOn.GetFurtherestPosition(myRb2D.position));
                    }
                    myAnimator.SetBool("mb_Melee", false);
                    playerAttackedWolf = false;         // Reset attecked bool
                }
                //else
                //{
                //    // Found Player
                //    if (targetObject != null)
                //    {
                //        currentState = STATES.S_FOUNDPLAYER;
                //        myAnimator.SetBool("mb_Melee", false);
                //    }
                //}
            }
        }
        break;

        case STATES.S_SHOOT_EGG:
        {
            if (shootingDoneAnimation)
            {
                // Reset Bool
                shootingDoneAnimation = false;

                // if we were hit by player
                if (playerAttackedWolf)
                {
                    // Is a player in range?
                    if (IsPlayerInRange())          // We found a player in range, Might not be the one who fired the shot
                    {
                        SetNewObjectTarget(targetObject);
                    }
                    else
                    {
                        // Run to nearest platform edge, since no player
                        currentState = STATES.S_RUNAWAY;
                        SetNewPosTarget(groundCheckScript.platformStandingOn.GetClosestPosition(myRb2D.position));
                    }
                    myAnimator.SetBool("mb_Shoot", false);
                    playerAttackedWolf = false;         // Reset attecked bool
                }

                // Reset Animation State
                myAnimator.Play("squirrelWolf_Shoot", -1, 0f);
            }
        }
        break;


        case STATES.S_FOUNDPLAYER:      // Assume that targetObject here will always be player
        {
            // check if we can ATTACK player or need to walk there
            int chance = Random.Range(0, 2);

            // Flee from player
            if (chance == 0)
            {
                currentState = STATES.S_RUNAWAY;            // get the furtherest Point from the player on the platform we are standing on
                TurnWolfAround();
                switch (facingDirection)
                {
                case DIRECTION.D_LEFT:
                    SetNewPosTarget(groundCheckScript.platformStandingOn.GetLeftPoint());
                    break;

                case DIRECTION.D_RIGHT:
                    SetNewPosTarget(groundCheckScript.platformStandingOn.GetRightsPoint());
                    break;
                }
            }
            else
            {
                // Attack player
                currentState = STATES.S_WALK_PLAYER;
                SetNewObjectTarget(targetObject);
                // Randomise way of attacking
                //attackMethod = (ATTACK)Random.Range((int)ATTACK.A_MELEE, (int)ATTACK.A_SHOOT+1);
            }
        }
        break;

        case STATES.S_RUNAWAY:
        {
            // Reduce Timer
            fleeTimer -= Time.deltaTime;
            if (fleeTimer < 0.0f)
            {
                currentState = STATES.S_EGG_DIFFERENTHEIGHT;
                fleeTimer    = fleeTime;
                return;
            }

            // Check if we can jump up more
            Vector2 platformEdgePos = FindJumpPointAbove();
            if (platformEdgePos != Vector2.zero)
            {
                // Set new target and jump there
                SetNewPosTarget(platformEdgePos);
                JumpWolf(moveTargetPos);
                return;
            }

            // Move enemy Horizontal
            if (!MoveWolf())
            {
                // If we don't find any platforms to jump to, then we just stay put
                platformEdgePos = FindFurtherestJumpPoint();
                if (platformEdgePos == Vector2.zero)
                {
                    // Check if we can jump below?
                    platformEdgePos = FindJumpPointBelow();
                    if (platformEdgePos != Vector2.zero)
                    {
                        if (!CanDrop())             // if our collider is too big, then need to move more before can drop
                        {
                            MoveWolf(false);
                            return;
                        }
                        // Set new target and jump there
                        SetNewPosTarget(platformEdgePos);
                        JumpWolf_MinimumHeight(moveTargetPos, 0.7f);
                    }
                    else            // Just Stop moving
                    {
                        StopVel();
                    }
                }
                else
                {
                    // Set new target and jump there
                    SetNewPosTarget(platformEdgePos);
                    JumpWolf(moveTargetPos);
                    return;
                }
            }
        }
        break;

        case STATES.S_WALK_PLAYER:
        {
            // check if player object is out of range
            float playerDist = 0.0f;
            if (!IsTargetObjStillInRange(ref playerDist))
            {
                float posDiff = myRb2D.position.y - Egg.Instance.transform.position.y;
                if (posDiff < YPosDifference)
                {
                    currentState = STATES.S_EGG_SIMILARHEIGHT;
                }
                else
                {
                    currentState = STATES.S_EGG_DIFFERENTHEIGHT;
                }
                return;
            }


            // Walk towards player
            SetNewObjectTarget(targetObject);
            // What attack type are we using
            switch (attackMethod)
            {
            case ATTACK.A_MELEE:
            {
                // Move until we can't
                if (!MoveWolf())
                {
                    // Do we need to jump pass a platform?
                    Vector2 nextPos = FindNearestJumpPoint();
                    if (nextPos != Vector2.zero)
                    {
                        SetNewPosTarget(nextPos);
                        JumpWolf(moveTargetPos);
                        return;
                    }
                    // check if we can shoot projectile at player, since we can't melee
                    else if (playerDist <= (maxShootingRange * maxShootingRange))
                    {
                        currentState = STATES.S_SHOOT_PLAYER;
                        StopVel();
                        myAnimator.SetBool("mb_Shoot", true);
                        return;
                    }
                    else
                    {
                        currentState = STATES.S_EGG_DIFFERENTHEIGHT;
                    }
                }

                // check if we can melee the player
                if (playerDist < (meleeDistance * meleeDistance))
                {
                    currentState = STATES.S_MELEE_PLAYER;
                    StopVel();
                    myAnimator.SetBool("mb_Melee", true);
                    return;
                }
            }
            break;

            case ATTACK.A_SHOOT:
            {
                // check if we can shoot projectile at player
                if (playerDist <= (maxShootingRange * maxShootingRange))
                {
                    // Do we need to flip the enemy to face the player
                    FlipEnemy();
                    currentState = STATES.S_SHOOT_PLAYER;
                    StopVel();
                    myAnimator.SetBool("mb_Shoot", true);
                    return;
                }

                // Move until we can't
                if (!MoveWolf())
                {
                    // change attack method to melee since we can't shoot the player
                    attackMethod = ATTACK.A_MELEE;
                }
            }
            break;
            }
        }
        break;

        case STATES.S_SHOOT_PLAYER:
        {
            if (shootingDoneAnimation)
            {
                // Reset Bool
                shootingDoneAnimation = false;

                // Change State
                currentState = STATES.S_RUNAWAY;
                myAnimator.SetBool("mb_Shoot", false);
                TurnWolfAround();
                switch (facingDirection)
                {
                case DIRECTION.D_LEFT:
                    SetNewPosTarget(groundCheckScript.platformStandingOn.GetLeftPoint());
                    break;

                case DIRECTION.D_RIGHT:
                    SetNewPosTarget(groundCheckScript.platformStandingOn.GetRightsPoint());
                    break;
                }
            }
        }
        break;

        case STATES.S_MELEE_PLAYER:
        {
            // Check done animation
            if (meleeDoneAnimation)
            {
                // Reset bool
                meleeDoneAnimation = false;

                //// Is a player in range?
                //float temp = 0.0f;
                //if (!IsPlayerStillInRange(ref temp))
                //{
                //    currentState = STATES.S_EGG_DIFFERENTHEIGHT;
                //    myAnimator.SetBool("mb_Melee", false);
                //}

                currentState = STATES.S_RUNAWAY;
                myAnimator.SetBool("mb_Melee", false);
                TurnWolfAround();
                switch (facingDirection)
                {
                case DIRECTION.D_LEFT:
                    SetNewPosTarget(groundCheckScript.platformStandingOn.GetLeftPoint());
                    break;

                case DIRECTION.D_RIGHT:
                    SetNewPosTarget(groundCheckScript.platformStandingOn.GetRightsPoint());
                    break;
                }
            }
        }
        break;
        }
    }