Example #1
0
    public override void OnTriggerEnter2D(Collider2D other)
    {
        if (Source == null || other.gameObject == Source || _triggered)
        {
            return;
        }

        if (other.gameObject.layer == LayerMask.NameToLayer("Walls"))
        {
            m_Anim.SetTrigger(m_collideHash);
            _triggered = true;
        }
        else
        {
            Enemy enemy = other.gameObject.GetComponent <Enemy>();
            if (enemy != null)
            {
                //    m_Anim.SetTrigger(m_collideHash);
                //    enemy.Hit(HitDamage);
                //    _triggered = true;
                //}


                /*if (Source.GetComponent<Player>().IsAttackLongCasted())
                 *  enemy.Hit(MagicShotLongAttackDamageValue);
                 * else*/
                enemy.Hit(HitDamage);


                if (enemy.IsBumpable)
                {
                    enemy.Bump(this.transform.position, BumpForce);
                }
                m_Anim.SetTrigger(m_collideHash);
                _triggered = true;
            }

            BushScript otherBushScript = other.gameObject.GetComponent <BushScript>();
            if (otherBushScript != null)
            {
                otherBushScript.hit();
                m_Anim.SetTrigger(m_collideHash);
                _triggered = true;
            }
        }
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        Player player = other.gameObject.GetComponent <Player> ();

        if (player != null && player.m_BeingHit == false)
        {
            if (player._isInCounterTime)
            {
                m_IATest.startCounter();
            }
            else
            {
                Vector2      dir = other.bounds.center - transform.position;
                RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, 200f, LayerMask.GetMask("Player"));

                if (m_IATest.IsAttackLongCasted())
                {
                    player.Hit(m_IATest, LongAttackDamageValue, StaminaConsomation);
                }
                else
                {
                    player.Hit(m_IATest, DamageValue, StaminaConsomation);
                }

                Instantiate(HitPrefab, hit.point, Quaternion.identity);
            }
        }

        BushScript otherBushScript = other.gameObject.GetComponent <BushScript>();

        if (otherBushScript != null)
        {
            Vector2      dir = other.bounds.center - transform.position;
            RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, 200f, LayerMask.GetMask("Objects"));
            Instantiate(HitPrefab, hit.point, Quaternion.identity);

            otherBushScript.hit();
        }
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        Enemy enemy = other.gameObject.GetComponent <Enemy> ();

        if (enemy != null)
        {
            Vector2      dir = other.bounds.center - transform.position;
            RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, 200f, LayerMask.GetMask("Enemy"));
            m_Camera.setShake(0.5f, 5);

            if (enemy.m_BeingHit == false)
            {
                m_Player.DoHitEnemy(enemy);

                ImpactFeedback impact = m_ImpactFeedbackManager.getUsableImpact();
                if (impact != null)
                {
                    impact.pop(hit.point);
                }
            }

            dir.Normalize();
            enemy.GetComponent <Rigidbody2D>().AddForceAtPosition(BumpForce * dir, hit.point);
        }

        BushScript otherBushScript = other.gameObject.GetComponent <BushScript>();

        if (otherBushScript != null)
        {
            Vector2        dir    = other.bounds.center - transform.position;
            RaycastHit2D   hit    = Physics2D.Raycast(transform.position, dir, 200f, LayerMask.GetMask("Objects"));
            ImpactFeedback impact = m_ImpactFeedbackManager.getUsableImpact();
            impact.pop(hit.point);

            otherBushScript.hit();
        }
    }
Example #4
0
    public WorldData(ControllerScript controller)
    {
        time = controller.time;
        ambientTemperature = controller.ambientTemperature;
        playerTemperature  = controller.playerTemperature;
        currentSeason      = controller.currentSeason;
        currentDay         = controller.currentDay;
        currentDayInSeason = controller.currentDayInSeason;
        health             = controller.playerInventoryScript.GetComponent <PlayerScript> ().health;
        hunger             = controller.playerInventoryScript.GetComponent <PlayerScript> ().hunger;
        happiness          = controller.playerInventoryScript.GetComponent <PlayerScript> ().happiness;

        droppedItems   = new SaveSystem.MyDroppedItem[controller.GetComponent <SaveSystemScript>().items.Length];
        terrains       = new SaveSystem.MyTerrain[controller.GetComponent <SaveSystemScript> ().terrains.Length];
        buildings      = new SaveSystem.Buildings.BasicBuildingSaveProperties[controller.GetComponent <SaveSystemScript>().buildings.Length];
        mobs           = new SaveSystem.Mobs.BasicMobAttributes[controller.GetComponent <SaveSystemScript>().mobs.Length];
        playerPosition = new MyVector3(controller.playerInventoryScript.transform.position);

        playerInventory = new SerializedInventoryItem[controller.playerInventoryScript.playerInventory.Length];
        for (int i = 0; i < playerInventory.Length; i++)
        {
            playerInventory [i] = controller.playerInventoryScript.playerInventory [i].convertToSave();
        }
        for (int i = 0; i < droppedItems.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().items [i] != null)
            {
                droppedItems [i] = new SaveSystem.MyDroppedItem(controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.name, controller.GetComponent <SaveSystemScript> ().items [i].transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue.quantity, new MyVector3(controller.GetComponent <SaveSystemScript> ().items [i].transform.position));
            }
        }

        for (int i = 0; i < terrains.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().terrains [i] != null)
            {
                GameObject terrain = controller.GetComponent <SaveSystemScript> ().terrains [i];
                terrains [i] = new SaveSystem.MyTerrain(terrain.GetComponent <TerrainScript> ().terrainName, terrain.transform.position);
            }
        }
        for (int i = 0; i < mobs.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().mobs [i] != null)
            {
                GameObject mob = controller.GetComponent <SaveSystemScript> ().mobs [i];
                if (mob.GetComponent <PassiveFourLegs> () != null)
                {
                    mobs [i] = new SaveSystem.Mobs.BasicMobAttributes(mob.GetComponent <PassiveFourLegs>().mobName, mob.GetComponent <PassiveFourLegs> ().health, mob.GetComponent <PassiveFourLegs> ().maxHealth, mob.transform.position, mob.transform.eulerAngles);
                }
                else if (mob.GetComponent <Sheep> () != null)
                {
                    mobs [i] = new SaveSystem.Mobs.Sheep(mob.GetComponent <Sheep>().mobName, mob.GetComponent <Sheep> ().health, mob.GetComponent <Sheep> ().maxHealth, mob.transform.position, mob.transform.eulerAngles);
                }
            }
        }
        for (int i = 0; i < buildings.Length; i++)
        {
            if (controller.GetComponent <SaveSystemScript> ().buildings [i] != null)
            {
                GameObject building = controller.GetComponent <SaveSystemScript> ().buildings [i];

                TreeScript       treeScript        = null;
                BoulderScript    boulderScript     = null;
                GrassScript      grassScript       = null;
                BushScript       bushScript        = null;
                BerryBushScript  berryBushScript   = null;
                FireScript       fireScript        = null;
                GroundFoodScript naturalFoodScript = null;

                if (building.GetComponent <TreeScript> () != null)
                {
                    treeScript = building.GetComponent <TreeScript> ();
                }
                if (building.GetComponent <BoulderScript> () != null)
                {
                    boulderScript = building.GetComponent <BoulderScript> ();
                }
                if (building.GetComponent <GrassScript> () != null)
                {
                    grassScript = building.GetComponent <GrassScript> ();
                }
                if (building.GetComponent <BushScript> () != null)
                {
                    bushScript = building.GetComponent <BushScript> ();
                }
                if (building.GetComponent <BerryBushScript> () != null)
                {
                    berryBushScript = building.GetComponent <BerryBushScript> ();
                }
                if (building.GetComponent <FireScript> () != null)
                {
                    fireScript = building.GetComponent <FireScript> ();
                }
                if (building.GetComponent <GroundFoodScript> () != null)
                {
                    naturalFoodScript = building.GetComponent <GroundFoodScript> ();
                }

                if (treeScript != null || boulderScript != null)
                {
                    //natural barriers
                    if (treeScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalBarriers("tree", treeScript.transform.position, treeScript.transform.eulerAngles, treeScript.health);
                    }
                    else if (boulderScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalBarriers("boulder", boulderScript.transform.position, boulderScript.transform.eulerAngles, boulderScript.health);
                    }
                }
                else if (grassScript != null || bushScript != null || berryBushScript != null)
                {
                    if (grassScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalCrops("grassPatch", grassScript.transform.position, grassScript.transform.eulerAngles, grassScript.cut, grassScript.growTimer);
                    }
                    if (bushScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalCrops("bush", bushScript.transform.position, bushScript.transform.eulerAngles, bushScript.cut, bushScript.growTimer);
                    }
                    else if (berryBushScript != null)
                    {
                        buildings [i] = new SaveSystem.Buildings.NaturalCrops("berryBush", berryBushScript.transform.position, berryBushScript.transform.eulerAngles, berryBushScript.cut, berryBushScript.growTimer);
                    }
                }
                else if (fireScript != null)
                {
                    buildings [i] = new SaveSystem.Buildings.Campfire("campfire", fireScript.transform.position, fireScript.transform.eulerAngles, fireScript.fuel);
                }
                else if (naturalFoodScript != null)
                {
                    buildings [i] = new SaveSystem.Buildings.BasicBuildingSaveProperties(naturalFoodScript.buildingIDName, naturalFoodScript.transform.position, naturalFoodScript.transform.eulerAngles);
                }
            }
        }
    }