Inheritance: MonoBehaviour
Example #1
0
        static public void Register(World w, Vector2 initPosiiton)
        {
            Entity e = w.CreateEntity()
                       .AddComponent <Sprite>()
                       .AddComponent <Flammable>()
                       .AddComponent <Health>()
                       .AddComponent <Transform>();

            Transform t = e.GetComponent <Transform>();

            t.position = initPosiiton;

            Sprite s = e.GetComponent <Sprite>();

            s.texture = World.content.Load <Texture2D>("bush");
            s.size    = new Vector2(16, 16);
            s.scale   = 4;

            Flammable flammable = e.GetComponent <Flammable>();

            flammable.isOnFire = false;
            flammable.percentChanceToSpread = 10;

            Health health = e.GetComponent <Health>();

            health.current = 100;
            health.total   = 100;
        }
 public void AddFuel(Flammable fuel)
 {
     if (showDebug)
     {
         Debug.Log(base.name + " Add Fuel ");
     }
     if (flammableList.Contains(fuel))
     {
         return;
     }
     flammableList.Add(fuel);
     flammbleElementCount++;
     if (isHot)
     {
         if (showDebug)
         {
             Debug.Log(base.name + " Going to change the colour of the fuel ");
         }
         FlammableScriptHeatColourChange1 component = fuel.GetComponent <FlammableScriptHeatColourChange1>();
         if (component != null)
         {
             component.Ignite();
         }
     }
     UpdateValue();
 }
Example #3
0
    public void Burning()
    {
        if (active)
        {
            // Get all surrounding objects
            Collider[] closeObjects = Physics.OverlapSphere(
                transform.position * Random.Range(0.6f, 1.3f),
                parent.radius * Random.Range(0.2f, 1.0f));

            foreach (Collider obj in closeObjects)
            {
                // Check if it collides with itself
                if (obj.collider != transform.collider && obj.collider != parent.collider)
                {
                    Flammable flammable = obj.GetComponent <Flammable>();
                    FireCell  cell      = obj.GetComponent <FireCell>();

                    // Is it a FireCell?
                    if (cell != null)
                    {
                        cell.FireDamage();
                    }
                    // Is it a Flammable?
                    else if (flammable != null)
                    {
                        flammable.RespondToFire();
                    }
                }
            }
        }
    }
Example #4
0
 void Awake()
 {
     Initialize(MaterialTypes.Wood);
     _flammable     = gameObject.AddComponent <Flammable>();
     _flammableType = Resources.Load <FlammableTypeSO>("FlammableWood");
     _flammable.Initialize(this, _flammableType);
 }
Example #5
0
    void Update()
    {
        if (fireTimer > 0)
        {
            if (!infinite)
            {
                fireTimer -= Time.deltaTime;
            }

            if (fireTimer <= 0)
            {
                StopBurning();
            }

            fireSpreadTimer += Time.deltaTime;
            if (fireSpreadTimer > spreadInterval)
            {
                print("Spread fire!");
                fireSpreadTimer = 0f;
                Collider[] nearbyColliders = Physics.OverlapSphere(transform.position, fireSpreadRadius);
                foreach (Collider colliderToMakeBurn in nearbyColliders)
                {
                    Flammable flammable = colliderToMakeBurn.GetComponent <Flammable>();
                    if (flammable != null && flammable.gameObject != gameObject && !flammable.IsBurning())
                    {
                        flammable.StartBurning();
                    }
                }
            }
        }
    }
Example #6
0
        public override WIListOption GetListOption(IItemOfInterest targetObject)
        {
            base.GetListOption(targetObject);

            UsedFireStarter = false;

            if (Player.Local.Tool.IsEquipped && Player.Local.Tool.worlditem.Is <FireStarter>())
            {
                UsedFireStarter = true;
            }

            Flammable flammable = null;

            if (targetObject.worlditem.Is <Flammable>(out flammable))
            {
                if (flammable.IsOnFire && flammable.CanBeExtinguished)
                {
                    mListOption.OptionText      = "Extinguish Fire";
                    mListOption.NegateIcon      = true;
                    Usage.ProgressDialogMessage = "Extinguishing fire...";
                }
                else if (flammable.CanBeIgnited)
                {
                    mListOption.OptionText      = DisplayName;
                    mListOption.NegateIcon      = false;
                    Usage.ProgressDialogMessage = "Starting fire...";
                }
            }
            return(mListOption);
        }
Example #7
0
    void OnTriggerStay(Collider other)
    {
        GameObject intruder   = other.gameObject;
        Flammable  flammable  = intruder.GetComponent <Flammable>();
        PureEnergy pureEnergy = intruder.GetComponent <PureEnergy>();

        if (flammable != null && flammable.state != Flammable.State.Burning)
        {
            source.Remove(intruder);
        }
        if (pureEnergy != null && pureEnergy.duration <= 0)
        {
            source.Remove(intruder);
        }
        if (flammable != null && flammable.state == Flammable.State.Burning && (!source.Remove(intruder)))
        {
            source.Add(intruder);
        }
        else if (flammable != null && flammable.state == Flammable.State.Burning)
        {
            source.Add(intruder);
        }
        if (source.Count == 0)
        {
            TurnOff();
        }
        else
        {
            TurnOn();
        }
    }
 public override void Execute(Entity[] entities, World w)
 {
     Parallel.ForEach(entities, (entity) =>
     {
         Health h    = entity.GetComponent <Health>();
         Flammable f = entity.GetComponent <Flammable>();
         h.current  -= f.damagePerUpdate;
     });
 }
Example #9
0
    void OnCollisionEnter(Collision collision)
    {
        Flammable flammable = collision.gameObject.GetComponent <Flammable> ();

        if (flammable != null)
        {
            flammable.SetOnFire(collision.contacts [0].point);
        }
    }
Example #10
0
    void OnTriggerEnter(Collider collider)
    {
        Flammable flammable = collider.gameObject.GetComponent("Flammable") as Flammable;

        if (flammable != null && flammable.onFire)
        {
            flammable.onFire = false;
        }
    }
Example #11
0
    private void OnParticleCollision(GameObject other)
    {
        Flammable flammable = other.GetComponent <Flammable>();

        if (flammable)
        {
            flammable.Burn();
        }
    }
Example #12
0
    void OnParticleCollision(GameObject other)
    {
        Flammable objectOnFire = other.GetComponent <Flammable> ();

        if (objectOnFire != null)
        {
            // Function returns a bool if the enemy was ignited
            objectOnFire.Ignited();
        }
    }
Example #13
0
    public void Instantiate(Flammable parent)
    {
        this.parent = parent;

        // Follow the parent
        transform.parent = parent.transform;

        // Set the hp to default values
        flammableHp = parent.fullFlammableHp;
        fireHp      = parent.fullFireHp;
    }
Example #14
0
 virtual protected void Awake()
 {
     flammable    = GetComponent <Flammable>();
     freezable    = GetComponent <FrostBite>();
     electracuted = GetComponent <Electracuted>();
     squash       = GetComponent <SquashEffect>();
     speed        = GetComponent <TestEnemy>().maxSpeed;
     audioSource  = GetComponent <AudioSource>();
     meshRenderer = GetComponentInChildren <Renderer>();
     MusicController.PlayBattleMusic();
     MusicController.numEnemies++;
 }
 private void OnEnable()
 {
     if (showDebug)
     {
         Debug.Log(base.name + " OnEnable ");
     }
     all.Add(this);
     if (update == null)
     {
         update = Coroutines.StartGlobalCoroutine(ProcessUpdates());
     }
     flammbleSettings = GetComponent <Flammable>();
 }
Example #16
0
 // Use this for initialization
 protected override void Start()
 {
     base.Start();
     iFrames            = false;
     tRail              = GetComponent <TrailRenderer>();
     meshRen            = GetComponent <SkinnedMeshRenderer>();
     afterImages        = transform.Find("front1").GetComponent <AfterImages>();
     healthSlider.value = currentHealth = startingHealth;
     manaSlider.value   = currentMana = startingMana;
     audioSource        = GetComponent <AudioSource>();
     flammable          = GetComponent <Flammable>();
     anim   = GetComponent <Animator>();
     weapon = GetComponentInChildren <HammerWeapon>();
 }
Example #17
0
    public void add(Flammable flammable, bool isABody)
    {
        pigs.Add(flammable);
        flammable.name = (isABody
                             ? "Body"
                             : "Soul") +
                         " (" + levelStats.bodyCount + ")";

        if (isABody)
        {
            levelStats.bodyCount++;
            gameStats.bodyCount++;
        }
    }
Example #18
0
    // Start is called before the first frame update
    void Start()
    {
        flammable = GetComponentInParent <Flammable>();
        if (!flammable)
        {
            Debug.Log("Error! Could not find flammable component");
        }

        // no need to render as this is only a trigger
        GetComponent <MeshRenderer>().enabled = false;

        GetComponent <SphereCollider>().isTrigger = true;
        GetComponent <SphereCollider>().enabled   = true;
    }
Example #19
0
        public override int GetHashCode()
        {
            var hashCode = -81208087;

            hashCode = hashCode * -1521134295 + Color.GetHashCode();
            hashCode = hashCode * -1521134295 + PushReaction.GetHashCode();
            hashCode = hashCode * -1521134295 + BlocksMovement.GetHashCode();
            hashCode = hashCode * -1521134295 + Flammable.GetHashCode();
            hashCode = hashCode * -1521134295 + RequiresNoTool.GetHashCode();
            hashCode = hashCode * -1521134295 + Liquid.GetHashCode();
            hashCode = hashCode * -1521134295 + Opaque.GetHashCode();
            hashCode = hashCode * -1521134295 + Replaceable.GetHashCode();
            hashCode = hashCode * -1521134295 + Solid.GetHashCode();
            return(hashCode);
        }
Example #20
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        Flammable flammable = collider.gameObject.GetComponentInChildren <Flammable>();

        if (flammable && flammable.IsOnFire())
        {
            Instantiate(waterSplashPrefab, transform.position, Quaternion.identity, transform.parent);
            SoundManager.Play(waterHitSound);
            Destroy(gameObject);
        }
        else if (collider.gameObject.GetComponent <Car>() || collider.gameObject.GetComponent <Propane>())
        {
            collider.gameObject.GetComponent <Rigidbody2D>().velocity = body.velocity / 2;
        }
    }
Example #21
0
        private void OnEnter(GameObject other)
        {
            Flame component = other.GetComponent <Flame>();

            if (component != null)
            {
                heat.SetValue(heat.value + component.isHot.value);
            }
            Flammable component2 = other.GetComponent <Flammable>();

            if ((bool)component2)
            {
                heat.SetValue(heat.value + component2.output.value);
            }
        }
Example #22
0
    // Use this for initialization
    void Awake()
    {
        flammable    = GetComponent <Flammable>();
        freezable    = GetComponent <FrostBite>();
        electracuted = GetComponent <Electracuted>();
        squash       = GetComponent <SquashEffect>();
        //speed = GetComponent<TestEnemy>().maxSpeed;
        audioSource   = GetComponent <AudioSource>();
        healthSlider  = Instantiate(canvasPrefab, transform, false).GetComponentInChildren <Slider>();
        rbody         = GetComponent <Rigidbody>();
        meshRenderer  = GetComponentInChildren <Renderer>();
        puzzleHandler = GameObject.Find("World").GetComponent <PuzzleHandler>();

        AddMe();
    }
Example #23
0
    // When we have collided with an object, check if it is on fire and catch on fire if it is.
    void OnTriggerEnter(Collider collider)
    {
        Flammable flammable = collider.gameObject.GetComponent("Flammable") as Flammable;

        if (flammable != null && flammable.onFire)
        {
            onFire = true;
            if (Fire != null)
            {
//				Fire.gameObject.transform.Find("InnerCore").gameObject.particleEmitter.maxEnergy = 0.5f;
//				Fire.gameObject.transform.Find("OuterCore").gameObject.particleEmitter.maxEnergy = 1;
//				Fire.gameObject.transform.Find("Smoke").gameObject.particleEmitter.maxEnergy = 6;
//				Fire.gameObject.transform.Find("Lightsource").gameObject.light.range = 6;
            }
        }
    }
Example #24
0
        public override float GetScore()
        {
            Collider2D[] colliders = Physics2D.OverlapCircleAll(manager.transform.position, 2f);
            for (int i = 0; i < colliders.Length; i++)
            {
                Flammable flammable = colliders[i].GetComponent <Flammable>();
                if (flammable)
                {
                    if (flammable.IsBurned || flammable.IsBurning)
                    {
                        continue;
                    }
                    possibleTarget = flammable;
                    return(100f); //TODO
                }
            }
            return(0f);

            //TODO: below would be for running and putting fire
            //List<Flammable> flammables = blackboard.Flammables;
            //Vector2 playerPos = blackboard.Player.transform.position;
            //float minDistance = float.MaxValue;
            //float maxDistance = 0;
            //float singleScore = 0;
            //for(int i = 0; i < flammables.Count; i++)
            //{
            //    Flammable current = flammables[i];
            //    if(current != null && current.enabled)
            //    {
            //        if(current.IsBurned || current.IsBurning)
            //        {
            //            continue;
            //        }
            //        singleScore = (playerPos - (Vector2)current.transform.position).sqrMagnitude;
            //        if(singleScore < minDistance)
            //        {
            //            minDistance = singleScore;
            //            possibleTarget = current;
            //        }
            //        else if(singleScore > maxDistance)
            //        {
            //            maxDistance = singleScore;
            //        }
            //    }
            //}
            //return maxDistance / minDistance;
        }
Example #25
0
    public void OnTriggerEnter(Collider other)
    {
        if (showDebug)
        {
            Debug.Log(base.name + " Entered Range " + other.name);
        }
        FlammableScriptHeatSource1 component = other.gameObject.GetComponent <FlammableScriptHeatSource1>();

        if ((bool)component)
        {
            if (showDebug)
            {
                Debug.Log(base.name + " Pass on the Heat ");
            }
            component.Ignite();
        }
        FlammableScriptHeatColourChange1 component2 = other.gameObject.GetComponent <FlammableScriptHeatColourChange1>();

        if (component2 != null && ignited)
        {
            if (showDebug)
            {
                Debug.Log(base.name + " The other thing here is supposed to change colour");
            }
            component2.Ignite();
        }
        Flammable component3 = other.gameObject.GetComponent <Flammable>();

        if ((bool)component3)
        {
            if (showDebug)
            {
                Debug.Log(base.name + " The other thing is flammable , its supposed to get hot ");
            }
            component3.heat = 1f;
        }
        Flame component4 = other.gameObject.GetComponent <Flame>();

        if ((bool)component4)
        {
            if (showDebug)
            {
                Debug.Log(base.name + " The other thing is flammable , its supposed to get hot ");
            }
            component4.Ignite();
        }
    }
Example #26
0
    private void SpreadFireFlammable(Vector3Int startPos, int floor)
    {
        Queue <Vector3Int>   searchQueue   = new Queue <Vector3Int>();
        HashSet <Vector3Int> searchHistory = new HashSet <Vector3Int>();

        searchQueue.Enqueue(startPos);
        searchHistory.Add(startPos);

        while (searchQueue.Count > 0)
        {
            Vector3Int pos = searchQueue.Dequeue();
            Vector3Int nPos;

            Flammable flammable = GetFlammable(pos, floor);
            flammable.CatchFire();
            CreateFire(pos, floor);

            nPos = pos + Vector3Int.up;
            if (flammable.isConnectedUp && !searchHistory.Contains(nPos))
            {
                searchQueue.Enqueue(nPos);
                searchHistory.Add(nPos);
            }

            nPos = pos + Vector3Int.down;
            if (flammable.isConnectedDown && !searchHistory.Contains(nPos))
            {
                searchQueue.Enqueue(nPos);
                searchHistory.Add(nPos);
            }

            nPos = pos + Vector3Int.left;
            if (flammable.isConnectedLeft && !searchHistory.Contains(nPos))
            {
                searchQueue.Enqueue(nPos);
                searchHistory.Add(nPos);
            }

            nPos = pos + Vector3Int.right;
            if (flammable.isConnectedRight && !searchHistory.Contains(nPos))
            {
                searchQueue.Enqueue(nPos);
                searchHistory.Add(nPos);
            }
        }
    }
    private void TryBurn( )
    {
        if (!isBurning)
        {
            return;
        }

        RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, burnRadius, Vector2.zero, 0f);
        foreach (var hit in hits)
        {
            Flammable other = hit.transform.gameObject.GetComponent <Flammable>( );
            if (other && Random.Range(0f, 1f) <= burnChance)
            {
                other.Set(damage);
            }
        }

        Invoke(nameof(TryBurn), tryBurnTick);
    }
Example #28
0
 void Start()
 {
     RaycastHit2D[] results = Physics2D.CircleCastAll(transform.position, EXPLOSION_RADIUS, Vector2.zero, 0);
     foreach (RaycastHit2D result in results)
     {
         Flammable flammable = result.collider.gameObject.GetComponent <Flammable>();
         if (flammable)
         {
             flammable.SetOnFire();
         }
         Mortal mortal = result.collider.gameObject.GetComponent <Mortal>();
         if (mortal)
         {
             mortal.Damage(gameObject.tag, EXPLOSION_DAMAGE);
         }
     }
     Camera.main.gameObject.GetComponent <CameraHelper>().Shake();
     SoundManager.Play(explosionSound);
 }
 public void RemoveFuel(Flammable fuel)
 {
     if (showDebug)
     {
         Debug.Log(base.name + " Remove fuel ");
     }
     flammableList.Remove(fuel);
     flammbleElementCount--;
     if (isHot)
     {
         FlammableScriptHeatColourChange1 component = fuel.GetComponent <FlammableScriptHeatColourChange1>();
         component.Extinguish();
         if (flammableList.Count == 0 && flameList.Count == 0)
         {
             isHot = false;
         }
     }
     UpdateValue();
 }
Example #30
0
 void Explode()
 {
     Instantiate(explodeParticle, transform.position, transform.rotation);
     Collider[] colliders = Physics.OverlapSphere(transform.position, explodeRadius);
     for (int i = 0; i < colliders.Length; i++)
     {
         Rigidbody rb = colliders[i].GetComponent <Rigidbody>();
         Flammable fm = colliders[i].GetComponent <Flammable>();
         if (rb != null)
         {
             rb.AddExplosionForce(1500f, transform.position, explodeRadius);
         }
         if (fm != null)
         {
             fm.Fire(10f);
         }
     }
     Destroy(gameObject);
 }