Ejemplo n.º 1
0
 protected void CheckHealth()
 {
     if (currentHealth <= 0)
     {
         currentState = CHARACTER_STATE.CHARACTER_DEAD;
     }
 }
Ejemplo n.º 2
0
    public virtual void Attack()
    {
        var battleController = FindObjectOfType <BattleController>();
        var enemy            = battleController.GetRandomEnemy(partyType);

        if (enemy != null && CanAttack(battleController))
        {
            //Set our selves to attack
            characterState = CHARACTER_STATE.Attacking;

            //Animate our attack
            animator.SetBool("Attack", true);

            var dmg = CalculateDamage(enemy);

            //TODO: determine if we are attacking or casting a spell. (pass the info to CalculateDamage)
            enemy.TakeDamage(dmg);

            //log the dmg
            if (log)
            {
                Debug.Log(data.displayName + " attacks " + enemy.data.displayName + " for " + dmg + " damage.");
            }
        }
    }
Ejemplo n.º 3
0
    public void ChangeState(int stateID)
    {
        if (!_stateList.ContainsKey(stateID))
        {
            Debug.LogError("State를 찾을 수 없습니다.");
            return;
        }

        State <T> newState = _stateList[stateID];

        if (newState == null)
        {
            return;
        }

        if (_curState == newState)
        {
            return;
        }

        if (_curState != null)
        {
            _curState.Exit(_owner);
        }

        newState.Enter(_owner);

        _curState   = newState;
        _curStateID = (CHARACTER_STATE)stateID;
    }
Ejemplo n.º 4
0
        public void ChangeState(CHARACTER_STATE newState)
        {
            currentCharacterState = newState;

            switch (currentCharacterState)
            {
            case CHARACTER_STATE.RESPAWNING:

                if (iRespawning != null)
                {
                    StopCoroutine(iRespawning);
                    iRespawning = null;
                }

                iRespawning = StartCoroutine(IRespawn());

                break;

            case CHARACTER_STATE.INDESTRUCTIBLE:
                break;

            default:
                break;
            }
        }
Ejemplo n.º 5
0
    //Called at the end of the animation via trigger
    public void AttackAimFinished()
    {
        animator.SetBool("Attack", false);

        //Not sure about this done now go back to idle
        characterState = CHARACTER_STATE.Idle;

        //This could be terrible ask some 1
        routine = StartCoroutine("AttackLoop");
    }
Ejemplo n.º 6
0
    public void SetFainted()
    {
        characterState = CHARACTER_STATE.Fainted;

        classDisplayImage.sprite = Utils.LoadSprite("tombstone", SPITE_LOCATIONS.PARTY_MEMBERS);

        //Shouldn't be attacking if dead :)
        if (routine != null)
        {
            animator.SetBool("Attack", false);

            StopCoroutine(routine);
            routine = null;
        }
    }
Ejemplo n.º 7
0
    //Attack the target if they're close enough
    protected void AIAttack()
    {
        if (targetObject == null)
        {
            isAttacking   = false;
            agent.enabled = true;
            currentState  = CHARACTER_STATE.CHARACTER_WANDER;
        }

        if (AICheckWeaponRange())
        {
            if (isAttacking && targetObject != null)
            {
                attackTimer += Time.deltaTime;

                if (attackTimer >= attackCooldownTime)
                {
                    //Attack the target
                    AudioSource.PlayClipAtPoint(Resources.Load("Sound/Sound_Combat") as AudioClip, transform.position);
                    animator.SetTrigger("Melee Right Attack 01");

                    if (targetObject.GetComponent <Character>())
                    {
                        DealDamage(targetObject.GetComponent <Character>());
                    }
                    else if (targetObject.GetComponent <BaseBuilding>())
                    {
                        DamageBuilding(targetObject.GetComponent <BaseBuilding>());
                    }
                    attackTimer = 0;
                }
            }
            else if (!isAttacking && targetObject != null)
            {
                //Set attacking to true, start attack timer, stop navigation
                isAttacking   = true;
                agent.enabled = false;
            }
        }
        else
        {
            isAttacking   = false;
            agent.enabled = true;
            currentState  = CHARACTER_STATE.CHARACTER_MOVING;
        }
    }
Ejemplo n.º 8
0
    // Use this for initialization
    public void Init(CharacterData _char, Party.PartyType type)
    {
        partyType = type;
        data      = _char;

        //HealthBar.onValueChanged.AddListener(OnHealthChanged);
        //ArmorBar.onValueChanged.AddListener(OnArmorChanged);
        //ResourceBar.onValueChanged.AddListener(OnResourceChanged);

        if (data != null)
        {
            characterState    = CHARACTER_STATE.Idle;
            Name.text         = data.displayName;
            HealthBar.value   = (data.health / data.maxHealth);
            ArmorBar.value    = (data.armor / data.maxArmor);
            ResourceBar.value = (data.resource / data.maxResource);
            SetDisplayImage();
        }
    }
Ejemplo n.º 9
0
    //If there's no target set, find a target, then set the destination using the NavMeshAgent
    protected virtual void AIMoveToTarget()
    {
        if (targetObject == null)
        {
            currentState = CHARACTER_STATE.CHARACTER_WANDER;
            //Debug.Log ("Target is null");
            AIFindTarget();

            return;
        }

        if (targetObject != null)
        {
            targetPosition = targetObject.transform.position;

            agent.SetDestination(targetPosition);

            currentState = CHARACTER_STATE.CHARACTER_MOVING;


            if (targetObject.GetComponent <BaseBuilding> () && AICheckRange())
            {
                if (targetObject.GetComponent <BaseBuilding> ().IsBuilt() == false)
                {
                    currentState = CHARACTER_STATE.CHARACTER_BUILDING;
                }
                else
                {
                    targetObject = null;
                    currentState = CHARACTER_STATE.CHARACTER_WANDER;
                }
            }
            else if (targetObject.GetComponent <Character> () && AICheckWeaponRange())
            {
                currentState = CHARACTER_STATE.CHARACTER_ATTACKING;
            }
            else if (targetObject.GetComponent <ResourceTile> () && AICheckRange())
            {
                currentState = CHARACTER_STATE.CHARACTER_COLLECTING;
            }
        }
    }
Ejemplo n.º 10
0
    public void Move(string direction)
    {
        walking = true;

        switch(direction) {
        case "left":
            currentWalkDir = CHARACTER_STATE.MoveLeft;
            break;
        case "right":
            currentWalkDir = CHARACTER_STATE.MoveRight;
            break;
        case "up":
            currentWalkDir = CHARACTER_STATE.MoveForward;
            break;
        case "down":
            currentWalkDir = CHARACTER_STATE.MoveBackward;
            break;
        default:
            walking = false;
            break;
        }
    }
Ejemplo n.º 11
0
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);
            stream.SendNext((int)contr.currentState);
            stream.SendNext("Nasko");
        }
        else
        {
            realPosition = (Vector3)(stream.ReceiveNext());
            realRotation = (Quaternion)(stream.ReceiveNext());
            CHARACTER_STATE st = (CHARACTER_STATE)stream.ReceiveNext();
            if (!photonView.isMine)
            {
                print ("Animation state: " + st.ToString());
                currentState = st;
            }

            playerName = (string)stream.ReceiveNext();

        }
    }
Ejemplo n.º 12
0
 private void fireStateChangeEvent(CHARACTER_STATE newState)
 {
     if(playerStateHandlerEvent != null) {
         playerStateHandlerEvent(newState);
     }
 }
Ejemplo n.º 13
0
    private bool checkStateTransitionValidity(CHARACTER_STATE newState)
    {
        bool result = false;

        switch(currentState) {
        case CHARACTER_STATE.Idle:
            result = true;
            break;
        case CHARACTER_STATE.MoveForward:
            result = true;
            break;
        case CHARACTER_STATE.MoveBackward:
            result = true;
            break;
        case CHARACTER_STATE.MoveLeft:
            result = true;
            break;
        case CHARACTER_STATE.MoveRight:
            result = true;
            break;
        case CHARACTER_STATE.MoveTopLeftDiagonal:
            result = true;
            break;
        case CHARACTER_STATE.MoveTopRightDiagonal:
            result = true;
            break;
        case CHARACTER_STATE.MoveBotLeftDiagonal:
            result = true;
            break;
        case CHARACTER_STATE.MoveBotRightDiagonal:
            result = true;
            break;
        case CHARACTER_STATE.Attacking:
            result = true;
            break;
        case CHARACTER_STATE.Jumping:
            result = true;
            break;
        default:
            break;
        }

        return result;
    }
Ejemplo n.º 14
0
    private bool checkStateChangeValidity(CHARACTER_STATE newState)
    {
        bool result = false;

        switch(newState) {
        case CHARACTER_STATE.Idle:
            result = true;
            break;
        case CHARACTER_STATE.MoveForward:
            result = true;
            break;
        case CHARACTER_STATE.MoveBackward:
            result = true;
            break;
        case CHARACTER_STATE.MoveLeft:
            result = true;
            break;
        case CHARACTER_STATE.MoveRight:
            result = true;
            break;
        case CHARACTER_STATE.MoveTopLeftDiagonal:
            result = true;
            break;
        case CHARACTER_STATE.MoveTopRightDiagonal:
            result = true;
            break;
        case CHARACTER_STATE.MoveBotLeftDiagonal:
            result = true;
            break;
        case CHARACTER_STATE.MoveBotRightDiagonal:
            result = true;
            break;
        case CHARACTER_STATE.Attacking:
            //if(playerStateController.stateDelayTimer[(int)CHARACTER_STATE.Attacking] < Time.time) {
                result = true;
            //}
            break;
        case CHARACTER_STATE.Jumping:
            result = true;
            break;
        default:
            break;
        }

        return result;
    }
Ejemplo n.º 15
0
    private void KeyInputs()
    {
        //Shoot
        if (Input.GetMouseButton(0))
        {
            if (canShoot)
            {
                Shoot();
                canShoot = false;
            }
        }
        {
            if (!canShoot)
            {
                fireRateTimer += Time.deltaTime * BerserkShootSpeedModifier;

                if (fireRateTimer >= WeaponsEquipped[CurrentWeapon].SecondsBetweenShots)
                {
                    canShoot      = true;
                    fireRateTimer = 0;
                }
            }
        }

        //Switching weapons
        if (Input.GetAxis("Mouse ScrollWheel") > 0f) //forward
        {
            if (CurrentWeapon + 1 == WeaponsEquipped.Count)
            {
                //Wrap around
                CurrentWeapon = 0;
            }
            else
            {
                ++CurrentWeapon;
            }

            playerWeapon.GetComponent <Image>().sprite = WeaponsEquipped[CurrentWeapon].WeaponSprite;
        }
        else if (Input.GetAxis("Mouse ScrollWheel") < 0f) //backwards
        {
            if (CurrentWeapon == 0)
            {
                //Wrap around
                CurrentWeapon = WeaponsEquipped.Count - 1;
            }
            else
            {
                --CurrentWeapon;
            }

            playerWeapon.GetComponent <Image>().sprite = WeaponsEquipped[CurrentWeapon].WeaponSprite;
        }

        //Movement
        if (Input.GetKey(KeyCode.W))
        {
            generalMovementScript.moveUp(characterTexture, characterMovementSpeed);
        }

        if (Input.GetKey(KeyCode.A))
        {
            if (gameObject.GetComponent <RectTransform>().localPosition.x > theCanvas.transform.position.x - (theCanvas.GetComponent <RectTransform>().rect.width * 0.5f))
            {
                generalMovementScript.moveLeft(characterTexture, characterMovementSpeed * BerserkMovementModifer);
                animator.SetInteger("states", 0);
            }
        }
        if (Input.GetKey(KeyCode.D))
        {
            //If character is out of left dead zone
            if (gameObject.transform.position.x >= theCanvas.transform.position.x)
            {
                //Move all other objects in the scene
                for (int i = 0; i < theCanvas.transform.childCount; ++i)
                {
                    GameObject theGameObject = theCanvas.transform.GetChild(i).gameObject;

                    //If the gameobject is UI layer or the character object
                    if (theGameObject.layer == 5 || theGameObject.tag == "MainCharacter")
                    {
                        continue;
                    }

                    generalMovementScript.moveLeft(theGameObject, characterMovementSpeed * BerserkMovementModifer);
                }
            }
            else //Move the character
            {
                generalMovementScript.moveRight(characterTexture, characterMovementSpeed * BerserkMovementModifer);
            }

            animator.SetInteger("states", 0);
        }
        if (Input.GetKeyDown(KeyCode.Space) && canJump)
        {
            GetComponent <Rigidbody2D>().AddForce(Vector2.up * 400);
            canJump = false;
        }

        //Update Character States
        if (characterState == CHARACTER_STATE.CHARACTERSTATE_INVINCIBLE)
        {
            InvincibilityTimer += Time.deltaTime;

            if (InvincibilityTimer >= InvincibilityTimeLimit)
            {
                InvincibilityTimer = 0;
                characterState     = CHARACTER_STATE.CHARACTERSTATE_NORMAL;
            }
        }
    }
Ejemplo n.º 16
0
    //Collision
    void OnTriggerEnter2D(Collider2D other)
    {
        switch (other.gameObject.tag)
        {
        case "GenericBullet":
        {
            if (other.gameObject.GetComponent <BulletObject>().CanHitPlayer)
            {
                Destroy(other.gameObject);

                if (characterState == CHARACTER_STATE.CHARACTERSTATE_NORMAL)
                {
                    DecreaseCharacterHealth(other.gameObject.GetComponent <BulletObject>().BulletDamage *BerserkDamageModifier);

                    if (characterHealth <= 0)
                    {
                        SceneManager.LoadScene("GameOver");
                    }
                }
            }

            goto default;
        }

        case "Ground":
        {
            if (Physics2D.GetIgnoreCollision(gameObject.GetComponent <Collider2D>(), other.gameObject.GetComponent <Collider2D>()))
            {
                Physics2D.IgnoreCollision(gameObject.GetComponent <Collider2D>(), other.gameObject.GetComponent <Collider2D>(), false);
            }

            goto default;
        }

        case "InvincibilityPowerup":
        {
            if (characterState == CHARACTER_STATE.CHARACTERSTATE_INVINCIBLE)
            {
                //If player already invincible, reset the timer
                InvincibilityTimer = InvincibilityTimeLimit;
                return;
            }

            characterState = CHARACTER_STATE.CHARACTERSTATE_INVINCIBLE;
            Destroy(other.gameObject);

            //Create a shield around player
            GameObject shield      = Instantiate(Resources.Load("shield") as GameObject, gameObject.transform.position, gameObject.transform.rotation, gameObject.transform);
            Image      shieldImage = shield.GetComponent <Image>();
            var        tempcolour  = shieldImage.color;
            tempcolour.a      = 0.5f;
            shieldImage.color = tempcolour;

            goto default;
        }

        case "HealthPowerup":
        {
            if (characterHealth >= characterHealthLimit)
            {
                return;
            }

            IncreaseCharacterHealth(20);

            if (characterHealth > characterHealthLimit)
            {
                characterHealth = characterHealthLimit;
            }

            Destroy(other.gameObject);

            goto default;
        }

        case "BerserkPowerup":
        {
            if (isBerserk)
            {
                return;
            }

            isBerserk            = true;
            spriteRenderer.color = BerserkColour;
            Destroy(other.gameObject);

            //Modifiers
            BerserkDamageModifier     = 0.75f;
            BerserkMovementModifer    = 1.25f;
            BerserkShootSpeedModifier = 1.25f;

            goto default;
        }

        case "fall":
        {
            SceneManager.LoadScene("GameOver");
            break;
        }

        case "Weapon":
        {
            Destroy(other.gameObject);

            //Check if player already has the weapon
            foreach (WeaponBase Weapon in WeaponsEquipped)
            {
                if (Weapon.WeaponName == other.name)
                {
                    return;
                }
            }

            if (other.name == "LMG")
            {
                WeaponsEquipped.Add(new LMG());
            }
            else if (other.name == "Minigun")
            {
                WeaponsEquipped.Add(new Minigun());
            }
            else if (other.name == "Pistol")
            {
                WeaponsEquipped.Add(new Pistol());
            }
            else if (other.name == "Revolver")
            {
                WeaponsEquipped.Add(new Revolver());
            }
            else if (other.name == "Rifle")
            {
                WeaponsEquipped.Add(new Rifle());
            }
            else if (other.name == "AK47")
            {
                WeaponsEquipped.Add(new AK47());
            }
            else if (other.name == "Carbine")
            {
                WeaponsEquipped.Add(new Carbine());
            }
            else if (other.name == "RPG")
            {
                WeaponsEquipped.Add(new RPG());
            }

            //Equip the newly picked up weapon
            CurrentWeapon = WeaponsEquipped.Count - 1;

            break;
        }

        case "LevelEnd":
        {
            SceneTransition sceneTransition = new SceneTransition();
            sceneTransition.Tolevelend();
            break;
        }

        default:
            break;
        }

        if (other.gameObject.name == "IgnoreCollisionTrigger")
        {
            if (!Physics2D.GetIgnoreCollision(gameObject.GetComponent <Collider2D>(), other.gameObject.transform.parent.GetComponent <Collider2D>()))
            {
                Physics2D.IgnoreCollision(gameObject.GetComponent <Collider2D>(), other.gameObject.transform.parent.GetComponent <Collider2D>());
            }
        }
        if (other.gameObject.tag == "Checkpoint")
        {
            respawnpoint = other.transform.position;
            Destroy(other.gameObject);
            lol++;
            PlayerPrefs.SetFloat("savecheckpoint", lol);
            PlayerPrefs.SetFloat("respawnhere", respawnpoint.x);
            PlayerPrefs.SetFloat("respawnhere1", respawnpoint.y);
        }
    }
Ejemplo n.º 17
0
    // Update is called once per frame
    public void MainCharacterUpdate()
    {
        animator.SetInteger("states", 1);
        //charhealth.text = "Health : " + characterHealth.ToString() + "/" + "100";
        moneytext.text = "Score : " + money.ToString();
        //Debug.Log("THIS IS THE THINGY " + PlayerPrefs.GetFloat("respawntocheckpoint"));
        //Debug.Log("WHERE THE PLAYER IS GOING TO SPAWN " + respawnpoint);
        //Debug.Log("THE CHARACTER POSITION" + transform.position);

        //-------PROBLEMATIC CODE------//

        //----------------------------//

        //Crosshair snap to mouse position
        Vector3 screenPoint = Input.mousePosition;

        screenPoint.z = 10.0f; //distance of the plane from the camera
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(screenPoint);

        gameObject.transform.GetChild(0).transform.position = mousePos;
        //Character faces direction of crosshair
        if (mousePos.x < gameObject.transform.position.x && !facingLeft)
        {
            gameObject.transform.right = -gameObject.transform.right;
            facingLeft = true;
        }
        else if (mousePos.x > gameObject.transform.position.x && facingLeft)
        {
            gameObject.transform.right = -gameObject.transform.right;
            facingLeft = false;
        }

        //Weapon Rot
        Vector3 normalizedDir = (mousePos - gameObject.transform.position).normalized;

        normalizedDir.z = 0;
        playerWeapon.up = normalizedDir;

        KeyInputs();

        //Update bullets shot by player
        foreach (GameObject BulletObj in BulletList)
        {
            if (!BulletObj || !BulletObj.activeSelf)
            {
                BulletList.Remove(BulletObj);
                continue;
            }

            if (BulletObj.activeSelf)
            {
                if (BulletObj.tag == "GenericBullet")
                {
                    BulletObj.GetComponent <BulletObject>().BulletObjectUpdate();
                }
                else if (BulletObj.tag == "GenericRocket")
                {
                    BulletObj.GetComponent <RocketObject>().RocketObjectUpdate();
                }
            }

            //Check if out of screen
            if (BulletObj.transform.position.x > theCanvas.transform.localPosition.x + Screen.width || BulletObj.transform.position.x < theCanvas.transform.localPosition.x - Screen.width ||
                BulletObj.transform.position.y > theCanvas.transform.localPosition.y + Screen.height || BulletObj.transform.position.y < theCanvas.transform.localPosition.y - Screen.height)
            {
                Destroy(BulletObj);
            }
        }

        //Update Character States
        if (characterState == CHARACTER_STATE.CHARACTERSTATE_INVINCIBLE)
        {
            InvincibilityTimer += Time.deltaTime;

            if (InvincibilityTimer >= InvincibilityTimeLimit)
            {
                InvincibilityTimer = 0;
                characterState     = CHARACTER_STATE.CHARACTERSTATE_NORMAL;
                Destroy(gameObject.transform.Find("shield(Clone)").gameObject);
            }
        }
        if (isBerserk)
        {
            BerserkTimer += Time.deltaTime;

            if (BerserkTimer >= BerserkTimeLimit)
            {
                BerserkTimer         = 0;
                isBerserk            = false;
                spriteRenderer.color = defaultColour;

                //Modifiers
                BerserkDamageModifier = BerserkMovementModifer = BerserkShootSpeedModifier = 1;
            }
        }
    }
Ejemplo n.º 18
0
 protected void AddState(CHARACTER_STATE stateID, State <T> state)
 {
     _stateManager.AddState((int)stateID, state);
 }
Ejemplo n.º 19
0
 ///<summary>
 ///상태 변경 함수
 ///</summary>
 ///
 public void ChangeState(CHARACTER_STATE state)
 {
     _stateManager.ChangeState((int)state);
 }
Ejemplo n.º 20
0
    private void onStateChanged(CHARACTER_STATE newState)
    {
        if(dead) return;

        if(currentState == newState) {
            return;
        }

        if(!checkStateChangeValidity(newState)) {
            return;
        }

        if(!checkStateTransitionValidity(newState)) {
            return;
        }

        switch(newState) {
        case CHARACTER_STATE.Idle:
            playerAnim.playIdleAnimation();
            break;
        case CHARACTER_STATE.MoveForward:
            playerAnim.playMoveForwardAnimation();
            break;
        case CHARACTER_STATE.MoveBackward:
            playerAnim.playMoveBackwardAnimation();
            break;
        case CHARACTER_STATE.MoveLeft:
            playerAnim.playMoveForwardAnimation();
            break;
        case CHARACTER_STATE.MoveRight:
            playerAnim.playMoveForwardAnimation();
            break;
        case CHARACTER_STATE.MoveTopLeftDiagonal:
            playerAnim.playMoveForwardAnimation();
            break;
        case CHARACTER_STATE.MoveTopRightDiagonal:
            playerAnim.playMoveForwardAnimation();
            break;
        case CHARACTER_STATE.MoveBotLeftDiagonal:
            playerAnim.playMoveBackwardAnimation();
            break;
        case CHARACTER_STATE.MoveBotRightDiagonal:
            playerAnim.playMoveBackwardAnimation();
            break;
        case CHARACTER_STATE.Attacking:
            playerAnim.playAttackAnimation();
            playerStateController.stateDelayTimer[(int)CHARACTER_STATE.Attacking] = Time.time + fireRate;
            break;
        case CHARACTER_STATE.Jumping:
            playerAnim.playJumpAnimation();
            playerStateController.stateDelayTimer[(int)CHARACTER_STATE.Jumping] = Time.time + 1.0f;
            break;
        default:
            break;
        }

        currentState = newState;
    }
Ejemplo n.º 21
0
    public void Activate()
    {
        characterState = CHARACTER_STATE.Idle;

        StartCoroutine("StartingDelay");
    }