Ejemplo n.º 1
0
 public void getController(string entityType, Vector2 direction, float speed = 0)
 {
     if (direction == null)
     {
         direction = Vector2.zero;
     }
     rb2d = gameObject.GetComponent <Rigidbody2D>();
     if (rb2d == null)
     {
         rb2d = gameObject.AddComponent <Rigidbody2D>();
     }
     if (entityType != null)
     {
         if (entityType.Equals("player"))
         {
             controller = new PlayerController(this, speed);
         }
         else if (entityType.Equals("projectile"))
         {
             controller = new ProjectileController(this, direction, speed);
         }
         else if (entityType.Equals("powerup"))
         {
             controller = new PowerupController(this);
         }
         else if (entityType.Equals("enemy"))
         {
             controller = new EnemyController(this);
         }
     }
     else
     {
         if (gameObject.CompareTag(GameDefaults.Player()))
         {
             controller = new PlayerController(this, speed);
         }
         else if (gameObject.CompareTag(GameDefaults.Projectile()))
         {
             controller = new ProjectileController(this, direction, speed);
         }
         else if (gameObject.CompareTag(GameDefaults.Powerup()))
         {
             controller = new PowerupController(this);
         }
         else if (gameObject.CompareTag(GameDefaults.Enemy()))
         {
             controller = new EnemyController(this);
         }
     }
 }
Ejemplo n.º 2
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        GameObject   other   = collision.gameObject;
        EntityScript otherES = other.GetComponent <EntityScript>();

        //Debug.Log(gameObject + "-->" + other);
        if (gameObject.CompareTag(GameDefaults.Projectile()) && (other.CompareTag(GameDefaults.Obstruction())))
        {
            Destroy(gameObject);
            return;
        }
        if (gameObject.CompareTag(GameDefaults.Projectile()) && other.CompareTag(GameDefaults.Projectile()))
        {
            return;
        }
        if (gameObject.CompareTag(GameDefaults.Powerup()) && !other.CompareTag(GameDefaults.Player()))
        {
            return;
        }
        if (other.CompareTag(GameDefaults.Powerup()))
        {
            return;
        }
        if (other.CompareTag(GameDefaults.Obstruction()))
        {
            return;
        }

        if (otherES != null)
        {
            if (parent != null)
            {
                if (other.gameObject.CompareTag(parent.tag) || otherES.parent != null && otherES.parent.gameObject.CompareTag(gameObject.tag))
                {
                    return;
                }
            }

            foreach (string effect in impactEffects.Keys)
            {
                //Debug.Log(effect);
                if (effect.Equals("damage"))
                {
                    if (gameObject.CompareTag(GameDefaults.Enemy()))
                    {
                        if (!gameObject.GetComponent <AiScriptBase>().isDangerous())
                        {
                            continue;
                        }
                        else
                        {
                            gameObject.GetComponent <AiScriptBase>().setDanger(false);
                        }
                    }
                    if (!otherES.stats.ContainsKey("health"))
                    {
                        continue;
                    }

                    float x = impactEffects["damage"].value;
                    if (otherES.stats.ContainsKey("armor"))
                    {
                        FloatStat FSA = otherES.stats["armor"];
                        if (FSA.getCompoundValue() >= 100)
                        {
                            x = 0;
                        }
                        else
                        {
                            x = Mathf.Max(x - FSA.getCompoundValue(), 1f);
                        }
                    }
                    FloatStat FSH = otherES.stats["health"];
                    otherES.controller.damage((int)x);
                    FSH.ChangeWithFactor("baseValue", 0 - x);
                    FSH = new FloatStat("health", Mathf.RoundToInt(FSH.getCompoundValue()));
                }
                else if (effect.Equals("healthBoost"))
                {
                    if (!otherES.stats.ContainsKey("health"))
                    {
                        continue;
                    }

                    float     x   = impactEffects["health"].value;
                    FloatStat FSH = otherES.stats["health"];

                    FSH.ChangeWithFactor("baseValue", x);
                }
                else
                {
                    FSQI effectData = impactEffects[effect];
                    Debug.Log(otherES.stats.ContainsKey(effect).ToString() + effect);
                    if (!otherES.stats.ContainsKey(effect))
                    {
                        continue;
                    }
                    effectData.ApplyTo(otherES);
                }
            }
        }
        if (gameObject.CompareTag(GameDefaults.Powerup()) && other.CompareTag(GameDefaults.Player()))
        {
            Destroy(gameObject);
            return;
        }
        //Stari kod
        if (true) //Unity ima ugrađene tagove i layere, zasto si stvarao svoje?
        {
            //Projectile collisions
            if (gameObject.CompareTag(GameDefaults.Projectile()))
            {
                //Obstruction
                if (other.CompareTag(GameDefaults.Obstruction()))
                {
                    Destroy(gameObject);
                    return;
                }
                if (parent != null && !parent.CompareTag(other.gameObject.tag))
                {
                    controller.OnTriggerEnter2D(collision);
                    GameObject.Destroy(gameObject);

                    // Wake up any script that is attached to the enemy + navmesh
                    var otherChaser = other.GetComponent <AiScriptBase>();
                    if (otherChaser != null && !otherChaser.enabled)
                    {
                        otherChaser.enabled = true;
                        other.GetComponent <NavMeshAgent>().enabled = true;
                    }
                }
            }
            //Enemy coll
            else if (gameObject.CompareTag(GameDefaults.Enemy()))
            {
                //Obstruction
                if (other.CompareTag(GameDefaults.Obstruction()))
                {
                    //Zid
                }
                //Enemy
                else if (other.CompareTag(GameDefaults.Enemy()))
                {
                    //var es = other.gameObject.GetComponent<EntityScript>();
                }
                //Player
                else if (other.gameObject.CompareTag(GameDefaults.Player()))
                {
                    if (controller != null && collision != null)
                    {
                        controller.OnTriggerEnter2D(collision);
                    }
                }
            }
            else if (gameObject.CompareTag(GameDefaults.Player()))
            {
                if (other.gameObject.CompareTag(GameDefaults.LevelExit()))
                {
                    if (controller != null && collision != null)
                    {
                        controller.OnTriggerEnter2D(collision);
                    }
                }
            }
        }
    }