예제 #1
0
    void OnCollisionEnter(Collision other)
    {
        /////////////////TAKING DAMAGE FROM A HAZARD (COLLISION) /////////////////////////////////////////////////////////////////////////////////////

        HazardData hazardInfo = other.gameObject.GetComponent <HazardData>();

        if (hazardInfo != null && hazardInfo.enabled)
        {
            playerDamageTaker.TakeDamage(hazardInfo.damageToPlayer);
        }
    }
예제 #2
0
    public void Add(HazardData hazardData)
    {
        DebugEx.Log <Tile>($"Added hazard: {hazardData.name} to tile {_tile.name}.");

        Assert.IsFalse(_hazards.ContainsKey(hazardData.EffectTrigger), "Only one hazard of each trigger type is allowed.");

        var hazard = _tile.gameObject.AddComponent <Hazard>();

        hazard.Initialize(hazardData, _tile, _helper);
        hazard.Removed += OnHazardRemoved;

        _hazards.Add(hazard.Data.EffectTrigger, hazard);
    }
예제 #3
0
    void OnTriggerEnter(Collider other)
    {
        /////////////////DEALING DAMAGE TO AN ENEMY/////////////////////////////////////////////////////////////////////////////////////

        if (other.gameObject.CompareTag("Enemy"))
        {
            GameObject enemy = other.transform.parent.gameObject;
            while (enemy.GetComponent <IsEnemyCentral>() == null)
            {
                enemy = enemy.transform.parent.gameObject;
            }

            if (GameModeHandler.gamemode == GameModeHandler.GameMode.Battle)
            {
                float       damage      = GetDamageToEnemy();
                DamageTaker damageTaker = enemy.GetComponent <DamageTaker>();
                damageTaker.TakeDamage(damage);
            }
            else
            {
                BattleInfo battleInfo = enemy.GetComponent <BattleInfo>();
                battleController.InitiateBattle(enemy, battleInfo);
            }
        }

        /////////////////DEALING DAMAGE TO A PUNCHING BAG/////////////////////////////////////////////////////////////////////////////////////

        if (other.gameObject.CompareTag("PunchingBag"))
        {
            GameObject enemy = other.transform.parent.gameObject;
            while (enemy.GetComponent <DamageTaker>() == null)
            {
                enemy = enemy.transform.parent.gameObject;
            }                                                                                                //todo change how a punching bag takes damage?

            float       damage      = GetDamageToEnemy();
            DamageTaker damageTaker = enemy.GetComponent <DamageTaker>();
            damageTaker.TakeDamage(damage);
        }

        /////////////////TAKING DAMAGE FROM A HAZARD (TRIGGER) /////////////////////////////////////////////////////////////////////////////////////

        HazardData hazardInfo = other.gameObject.GetComponent <HazardData>(); //GETTING HIT BY A HAZARD

        if (hazardInfo != null && hazardInfo.enabled)
        {
            playerDamageTaker.TakeDamage(hazardInfo.damageToPlayer);
        }
    }
예제 #4
0
    public void Initialize(HazardData hazardData, Tile tile, Helper helper)
    {
        Data    = hazardData;
        Tile    = tile;
        _helper = helper;

        Assert.IsNotNull(Data.ViewPrototype, "View is missing.");
        var view = GameObject.Instantiate <HazardView>(Data.ViewPrototype);

        view.Initialize(this);

        _hazardHandler          = hazardData.EffectTrigger == HazardEffectTrigger.OnEnter ? new HazardOnEnterHandler(this) : new HazardHandler(this);
        _hazardHandler.Removed += OnHazardHandlerRemoved;

        _triggeredCount = new StateHandledValue <int>();

        _stateHandlers = new List <IStateHandler>();
        _stateHandlers.Add(_hazardHandler);
        _stateHandlers.Add(_triggeredCount);
    }
예제 #5
0
    void enableHazardProperties(bool status)
    {
        if (status == false)
        {
            foreach (GameObject thing in hittableGeometry)
            {
                HazardData hazardData = thing.GetComponent <HazardData>();
                thing.layer = 0;

                if (hazardData == null)
                {
                    Debug.LogError("No Hazard Data attached to some hittable geometry");
                }
                else
                {
                    thing.GetComponent <HazardData>().enabled = false;
                }
            }
        }
        else
        {
            foreach (GameObject thing in hittableGeometry)
            {
                HazardData hazardData = thing.GetComponent <HazardData>();
                thing.layer = 9;

                if (hazardData == null)
                {
                    Debug.LogError("No Hazard Data attached to some hittable geometry");
                }
                else
                {
                    thing.GetComponent <HazardData>().enabled = true;
                }
            }
        }
    }