示例#1
0
    private void MoveInTargetDirection(Vector2 direction)
    {
        direction.Normalize();
        float movementVelocity = MovingObjectStats.GetMovementVelocityForObject(gameObject);

        body.velocity = new Vector2(direction.x * movementVelocity, direction.y * movementVelocity);
    }
示例#2
0
    void Update()
    {
        try {
            if (!MovingObjectStats.IsObjectAlive(_endTransform.gameObject))
            {
                Destroy(gameObject);
                return;
            }

            if (Vector3.Equals(gameObject.transform.position, _endTransform.position))
            {
                if (_onArrival != null)
                {
                    _onArrival();
                }
            }

            gameObject.transform.position = Vector3.MoveTowards(
                gameObject.transform.position,
                _endTransform.position,
                _velocity * Time.deltaTime);
        }
        catch (Exception) {
            // is target destroyed?
            Destroy(gameObject);
        }
    }
示例#3
0
    public static void StartAttackColldownForObject(GameObject obj)
    {
        MovingObjectStats objectStats = getMovingObjectStats(obj);

        if (objectStats != null)
        {
            objectStats.attackCooldownTimestamp = Time.time + objectStats.attackCooldown;
        }
    }
示例#4
0
    public static float GetObjectPriority(GameObject obj)
    {
        MovingObjectStats objectStats = getMovingObjectStats(obj);

        if (objectStats != null)
        {
            return(objectStats.priority);
        }

        return(1.0f);
    }
    float GetObjectPriorityStat(GameObject obj)
    {
        return(MovingObjectStats.GetObjectPriority(obj));

        /*MovingObjectStats objectStats = GetComponent<MovingObjectStats> ();
         * if (objectStats != null) {
         *      return objectStats.priority;
         * }
         *
         * return 1.0f;*/
    }
示例#6
0
    public static int GetMaxHealthForObject(GameObject obj)
    {
        MovingObjectStats objectStats = getMovingObjectStats(obj);

        if (objectStats != null)
        {
            return(objectStats.maxHealth);
        }

        return(100);
    }
示例#7
0
    public static float GetAttackActionTimeForObject(GameObject obj)
    {
        MovingObjectStats objectStats = getMovingObjectStats(obj);

        if (objectStats != null)
        {
            return(objectStats.attackActionTime);
        }

        return(1.0f);
    }
示例#8
0
    public static float GetAttackColldownForObject(GameObject obj)
    {
        MovingObjectStats objectStats = getMovingObjectStats(obj);

        if (objectStats != null)
        {
            return(objectStats.attackCooldown);
        }

        return(1.0f);
    }
示例#9
0
    public static int GetAttackDamageForObject(GameObject obj)
    {
        MovingObjectStats objectStats = getMovingObjectStats(obj);

        if (objectStats != null)
        {
            return(objectStats.attackDamage);
        }

        return(1);
    }
示例#10
0
    public static float GetMovementVelocityForObject(GameObject obj)
    {
        MovingObjectStats objectStats = getMovingObjectStats(obj);

        if (objectStats != null)
        {
            return(objectStats.movementVelocity);
        }

        return(1.0f);
    }
示例#11
0
    public static MovingObjectStats getMovingObjectStats(GameObject obj)
    {
        MovingObjectStats stats = obj.GetComponent <MovingObjectStats> ();

        if (stats != null && stats._redirectStats != null)
        {
            stats = stats._redirectStats;
        }

        return(stats);
    }
示例#12
0
    public static bool IsInAttackCooldown(GameObject obj)
    {
        MovingObjectStats objectStats = getMovingObjectStats(obj);

        if (objectStats != null)
        {
            return(objectStats.attackCooldownTimestamp > Time.time);
        }

        return(false);
    }
示例#13
0
    public static bool DealDamageFromObjectToObject(GameObject attackingObject, GameObject damagedObject)
    {
        MovingObjectStats damagedObj = getMovingObjectStats(damagedObject);

        if (damagedObj != null)
        {
            int damage = MovingObjectStats.GetAttackDamageForObject(attackingObject);
            return(damagedObj.DealDamage(damage));
        }

        return(false);
    }
示例#14
0
    // Use this for initialization
    void Start()
    {
        healthBarWidth = healthBar.sizeDelta.x;

        maxHealth     = MovingObjectStats.GetMaxHealthForObject(gameObject);
        currentHealth = maxHealth;

        if (isLocalPlayer)
        {
            spawnPoints = FindObjectsOfType <NetworkStartPosition> ();
        }
    }
示例#15
0
    public AttackRequest(float priority, AttackAI ai, GameObject targetObject) : base(priority)
    {
        attackAI       = ai;
        objectToAttack = targetObject;

        // check if we are in range
        float  attackRange = MovingObjectStats.GetAttackRangeForObject(ai.gameObject);
        MoveAI moveAI      = ai.GetComponent <MoveAI> ();

        fgoRequest = new FollowGameObjectRequest(0.5f, moveAI, attackRange);
        fgoRequest.targetObject = objectToAttack;
    }
示例#16
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.layer != gameObject.transform.parent.gameObject.layer)
     {
         MovingObjectStats stats = other.GetComponent <MovingObjectStats> ();
         if (stats != null)
         {
             collidersInside.Add(other);
             setChanged = true;
         }
     }
 }
示例#17
0
    public void AttackParticleEffect(GameObject objectToAttack)
    {
        particleEffect = Instantiate(attackParticleEffect, transform.position, transform.rotation);
        Shot shot = particleEffect.AddComponent <Shot>();

        float attackParticleEffectVelocity = Vector3.Distance(objectToAttack.transform.position, gameObject.transform.position) / MovingObjectStats.GetAttackActionTimeForObject(gameObject);

        shot.Startup(objectToAttack.transform, attackParticleEffectVelocity, () => {
            MovingObjectStats.DealDamageFromObjectToObject(gameObject, objectToAttack);
            Destroy(shot.gameObject);
        });
        attackParticleEffect.layer = this.gameObject.layer;
    }
示例#18
0
    void StartAttack()
    {
        if (MovingObjectStats.IsInAttackCooldown(attackAI.gameObject))
        {
            //Debug.Log (attackAI.gameObject.name + " In cooldown");
        }
        else
        {
            //Debug.Log (attackAI.gameObject.name + " Attack");

            attackAI.AttackParticleEffect(objectToAttack);
            attackFinishTimestamp = Time.time + MovingObjectStats.GetAttackActionTimeForObject(attackAI.gameObject);
            MovingObjectStats.StartAttackColldownForObject(attackAI.gameObject);
        }
    }
 public override MoveRequest GetRequest()
 {
     if (gameObjectToFollow == null)
     {
         return(null);
     }
     else
     {
         float attackRange = MovingObjectStats.GetAttackRangeForObject(gameObject);
         FollowGameObjectRequest request = new FollowGameObjectRequest(0.5f, this, attackRange);
         request.targetObject = gameObjectToFollow;
         if (request.IsInRange())
         {
             return(null);
         }
         return(request);
     }
 }
    public override bool TickAction()
    {
        if (!MovingObjectStats.IsObjectAlive(targetObject))
        {
            moveAI.ResetMovementTarget();
            return(false);
        }

        if (!IsInRange())
        {
            moveAI.SetMovementTarget(targetObject.transform.position);
            return(true);
        }
        else
        {
            moveAI.ResetMovementTarget();
            return(false);
        }
    }
示例#21
0
    public bool TakeDamage(int amount)
    {
        if (!isServer)
        {
            return(false);
        }

        //Reduce Health by the amount of damage
        currentHealth -= amount;

        Instantiate(takeDamageParticleEffect, transform.position, transform.rotation);

        if (currentHealth <= 0)
        {
            Instantiate(dieParticleEffect, transform.position, transform.rotation);

            if (this.gameObject.tag == "Player_Combined")
            {
                this.gameObject.GetComponent <PlayerController2D> ().CmdHop();
            }
            else
            {
                if (destroyOnDeath)
                {
                    Helpers.DestroyObject(gameObject);
                }
                else
                {
                    maxHealth     = MovingObjectStats.GetMaxHealthForObject(gameObject);
                    currentHealth = maxHealth;

                    RpcRespawn();
                }

                return(true);
            }
        }

        return(false);
    }
示例#22
0
 void OnChangeHealth(int currentHealth)
 {
     maxHealth           = MovingObjectStats.GetMaxHealthForObject(gameObject);
     healthBar.sizeDelta = new Vector2(((float)currentHealth) / ((float)maxHealth) * healthBarWidth, healthBar.sizeDelta.y);
     healthBar.transform.parent.gameObject.SetActive(currentHealth != maxHealth);
 }
示例#23
0
    public void CmdHop()
    {
        hopped = !hopped;
        if (hopped)
        {
            GameObject[] golem1s = GameObject.FindGameObjectsWithTag("Golem_1");
            GameObject[] golem2s = GameObject.FindGameObjectsWithTag("Golem_2");

            List <GameObject> golemList = new List <GameObject> ();
            foreach (GameObject golem in golem1s)
            {
                if (golem.layer == gameObject.layer)
                {
                    golemList.Add(golem);
                }
            }
            foreach (GameObject golem in golem2s)
            {
                if (golem.layer == gameObject.layer)
                {
                    golemList.Add(golem);
                }
            }

            foreach (GameObject golem in golemList)
            {
                if (canHopGolem1 == true)
                {
                    if (golem.tag == "Golem_1")
                    {
                        donkeyGolem = golem;

                        //change tag
                        gameObject.tag = "Player_Combined";

                        //Change Sprite and scale to the combined object
                        gameObject.GetComponent <SpriteRenderer> ().sprite = gobzillaSprite;
                        gameObject.transform.localScale = new Vector3(6.5f, 6.5f, 6.5f);

                        MovingObjectStats alternateStats = gameObject.GetComponent <GotanMovingObjectStats> ();
                        gameObject.GetComponent <MovingObjectStats> ().SetSedirectStats(alternateStats);

                        //store current health on a temporary variable
                        storeTempHealth = gameObject.GetComponent <Health> ().currentHealth;

                        //get health from Golem and assign it to Player
                        gameObject.GetComponent <Health> ().currentHealth = golem.GetComponent <Health> ().currentHealth;

                        golem.SetActive(false);

                        //change animator to the combined player animator
                        anim.runtimeAnimatorController = Resources.Load("GobzillaController") as RuntimeAnimatorController;


                        hopButton.GetComponent <Button> ().interactable = true;

                        hoppedGolem1 = true;
                    }
                }

                if (canHopGolem2 == true)
                {
                    if (golem.tag == "Golem_2")
                    {
                        donkeyGolem = golem;

                        //change tag
                        gameObject.tag = "Player_Combined";

                        //Change Sprite and scale to the combined object
                        gameObject.GetComponent <SpriteRenderer> ().sprite = gobzillaSprite;
                        gameObject.transform.localScale = new Vector3(6.5f, 6.5f, 6.5f);

                        MovingObjectStats alternateStats = gameObject.GetComponent <GotanMovingObjectStats> ();
                        gameObject.GetComponent <MovingObjectStats> ().SetSedirectStats(alternateStats);

                        //store current health on a temporary variable
                        storeTempHealth = gameObject.GetComponent <Health> ().currentHealth;

                        //get health from Golem and assign it to Player
                        gameObject.GetComponent <Health> ().currentHealth = golem.GetComponent <Health> ().currentHealth;

                        golem.SetActive(false);

                        //change animator to the combined player animator
                        anim.runtimeAnimatorController = Resources.Load("GobzillaController") as RuntimeAnimatorController;

                        hopButton.GetComponent <Button> ().interactable = true;

                        hoppedGolem2 = true;
                    }
                }
            }
        }
        else
        {
            gameObject.GetComponent <SpriteRenderer> ().sprite = goblinSprite;
            gameObject.transform.localScale = new Vector3(6.5f, 6.5f, 5.0f);

            donkeyGolem.SetActive(true);
            //get health from player and reassign to goelm
            donkeyGolem.GetComponent <Health>().currentHealth = gameObject.GetComponent <Health>().currentHealth;

            Vector3 newPosition = transform.position + new Vector3(5.0f, 0.0f, 0.0f);
            donkeyGolem.transform.position = newPosition;

            gameObject.GetComponent <MovingObjectStats> ().SetSedirectStats(null);

            //reassign old health to the Goblin
            gameObject.GetComponent <Health> ().currentHealth = storeTempHealth;

            hopButton.GetComponent <Button> ().interactable = false;

            //change animator to the player animator
            anim.runtimeAnimatorController = Resources.Load("PlayerController") as RuntimeAnimatorController;


            hoppedGolem1 = false;
            hoppedGolem2 = false;
            donkeyGolem  = null;

            //change tag
            gameObject.tag = "Player";
        }
    }
示例#24
0
 public void SetSedirectStats(MovingObjectStats redirect)
 {
     _redirectStats = redirect;
 }