Beispiel #1
0
    void OnTriggerStay(Collider other)
    {
        if (other != null && other.gameObject.tag == "Player" && other.gameObject.GetComponent <PlayerMover>().space&& time <= Time.time && other is CapsuleCollider)
        {
            float newHealth = HealthWriter.Data.health - 25f;
            time = Time.time + 1;

            if (newHealth <= 0)
            {
                var update = new Health.Update();
                update.SetHealth(100f);
                HealthWriter.Send(update);
                other.gameObject.GetComponent <ScoresPlayer> ().addScores(25f);
                GetComponent <ScoresPlayer> ().reset();
                rigidbody.MovePosition(new Vector3(0f, 1f, 0f));
                var pos            = rigidbody.position;
                var positionUpdate = new Position.Update()
                                     .SetCoords(new Coordinates(pos.x, pos.y, pos.z));
                PositionWriter.Send(positionUpdate);
                var update2 = new Death.Update();
                update2.SetDeath(true);
                DeathWriter.Send(update2);
            }
            else
            {
                var update = new Health.Update();
                update.SetHealth(newHealth);
                HealthWriter.Send(update);
                other.gameObject.GetComponent <ScoresPlayer> ().addScores(25f);
            }
        }
    }
Beispiel #2
0
 private void Die()
 {
     playerInfo.Send(new PlayerInfo.Update().SetIsAlive(false));
     health.Send(new Health.Update().SetCanBeChanged(false));
     flammableInterface.SelfExtinguish(flammable, false);
     spells.Send(new Spells.Update().SetCooldowns(new Map <SpellType, float> {
         { SpellType.LIGHTNING, 0f }, { SpellType.RAIN, 0f }
     }).SetCanCastSpells(false));
 }
 private void Die()
 {
     playerInfo.Send(new PlayerInfo.Update().SetIsAlive(false));
     health.Send(new Health.Update().SetCanBeChanged(false));
     flammable.Send(new Flammable.Update().SetIsOnFire(false).SetCanBeIgnited(false));
     spells.Send(new Spells.Update().SetCooldowns(new Map <SpellType, float> {
         { SpellType.LIGHTNING, 0f }, { SpellType.RAIN, 0f }
     }).SetCanCastSpells(false));
 }
Beispiel #4
0
        public void OnAffectUpdated(Affectable.Update update)
        {
            int damage = 0;

            for (var i = 0; i < update.takenDamage.Count; ++i)
            {
                damage += 1;
            }
            if (damage > 0)
            {
                HealthWriter.Send(new Health.Update().SetValue(HealthWriter.Data.value - damage));
            }
        }
        // note: the "other" game object is the cannonball
        private void OnTriggerEnter(Collider other)
        {
            if (HealthWriter == null)
            {
                return;
            }

            if (HealthWriter.Data.currentHealth <= 0)
            {
                return;
            }

            if (other != null && other.gameObject.tag == SimulationSettings.CannonballTag)
            {
                // for now, just do some logging
                // Debug.LogWarning("Collision detected with " + gameObject.EntityId());
                int newHealth = HealthWriter.Data.currentHealth - 250;
                HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));

                // Notify firer
                if (newHealth <= 0)
                {
                    var firerEntityId = other.GetComponent <Cannons.DestroyCannonball> ().firerEntityId.Value;
                    AwardPointsForKill(firerEntityId);
                }
            }
        }
Beispiel #6
0
 public static void SetCurrentHealth(this Health.Writer health, int newHealth)
 {
     if (health.Data.canBeChanged)
     {
         health.Send(new Health.Update().SetCurrentHealth(Mathf.Max(newHealth, 0)));
     }
 }
Beispiel #7
0
        private void AwardHealth()
        {
            int currentHealth = HealthWriter.Data.health;

            HealthWriter.Send(new Health.Update().SetHealth(currentHealth
                                                            + SimulationSettings.PlayerKillHealthAward));
        }
Beispiel #8
0
        private void OnTriggerEnter(Collider other)
        {
            if (HealthWriter == null)
            {
                return;
            }

            // Ignore collision if this player is already dead
            if (HealthWriter.Data.currentHealth <= 0)
            {
                return;
            }

            if (other != null && (other.gameObject.tag == "Bullet" || other.gameObject.tag == "BulletAlien" || other.gameObject.tag == "Shield"))
            {
                // Reduce health of this entity when hit
                //Debug.LogError("Collision detected with " + gameObject.EntityId());
                // Reduce health of this entity when hit
                int newHealth = HealthWriter.Data.currentHealth - 100;
                HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));
                //Destroy (other.gameObject);
                if (newHealth <= 0)
                {
                    Debug.LogError("---");
                    Debug.LogError(other.GetComponent <Guns.DestroyBullet>().firerEntityId.Value.Id);
                    AwardPointsForKill(new EntityId(other.GetComponent <Guns.DestroyBullet>().firerEntityId.Value.Id));
                }
            }
        }
Beispiel #9
0
 public static void AddCurrentHealthDelta(this Health.Writer health, int delta)
 {
     if (health.Data.canBeChanged)
     {
         if (health.TryingToDecreaseHealthBelowZero(delta))
         {
             return;
         }
         health.Send(new Health.Update().SetCurrentHealth(Mathf.Max(health.Data.currentHealth + delta, 0)));
     }
 }
Beispiel #10
0
    private void OnTriggerEnter(Collider other)
    {
        if (HealthWriter == null)
        {
            return;
        }

        if (HealthWriter.Data.currentHealth <= 0)
        {
            return;
        }

        if (other != null && other.gameObject.tag == "FireBall")
        {
            int newHealth = HealthWriter.Data.currentHealth - 25;
            HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));
        }
        if (other != null && other.gameObject.tag == "MagicBall")
        {
            int newHealth = HealthWriter.Data.currentHealth - 15;
            HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));
        }
        if (other != null && other.gameObject.tag == "SnowBall")
        {
            int newHealth = HealthWriter.Data.currentHealth - 10;
            HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));
        }
        if (other != null && other.gameObject.tag == "EnergyBall")
        {
            int newHealth = HealthWriter.Data.currentHealth - 20;
            HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));
        }

        if (other != null && other.gameObject.tag == "HP")
        {
            int newHealth = HealthWriter.Data.currentHealth + 50;
            HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));
        }
    }
Beispiel #11
0
        void FixedUpdate()
        {
            int actualHealth = HealthWriter.Data.currentHealth;

            if (actualHealth <= 0)
            {
                HealthWriter.Send(new Health.Update().SetCurrentHealth(1000));
                rigidbody.position = positionArray[Random.Range(0, 4)];
                var pos = rigidbody.position;
                //Debug.LogError ("respawn in position: " + pos.x + "," + pos.y + "," + pos.z);
                var positionUpdate = new Position.Update()
                                     .SetCoords(new Coordinates(pos.x, pos.y, pos.z));
                PositionWriter.Send(positionUpdate);
            }
        }
Beispiel #12
0
        void FixedUpdate()
        {
            int actualHealth = HealthWriter.Data.currentHealth;

            if (actualHealth == 0)
            {
                rigidbody.position = new Vector3(0f, 0f, 0f);
                var pos = rigidbody.position;
                //Debug.LogError ("respawn in position: " + pos.x + "," + pos.y + "," + pos.z);
                var positionUpdate = new Position.Update()
                                     .SetCoords(new Coordinates(pos.x, pos.y, pos.z));
                PositionWriter.Send(positionUpdate);
                HealthWriter.Send(new Health.Update().SetCurrentHealth(1000));
            }
        }
Beispiel #13
0
        private void Respawn()
        {
            // Initialise player
            isDead = false;

            SizeWriter.Send(new Size.Update()
                            .SetSizeMultiplier(1.0F));

            HealthWriter.Send(new Health.Update()
                              .SetHealth(SimulationSettings.PlayerSpawnHealth));

            // Respawn character
            inputHandler.Respawn();

            // Regain controls
            inputHandler.HasControl(true);
        }
 private void OnTriggerEnter(Collider other)
 {
     if (HealthWriter == null)
     {
         return;
     }
     if (HealthWriter.Data.currentHealth <= 0)
     {
         return;
     }
     if (other != null && other.gameObject.tag == SimulationSettings.CannonballTag)
     {
         int newHealth = HealthWriter.Data.currentHealth - 250;
         HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));
         if (newHealth <= 0)
         {
             AwardPointsForKill(new EntityId(other.GetComponent <Cannons.DestroyCannonball>().firerEntityId.Value.Id));
         }
     }
 }
Beispiel #15
0
        private void OnTriggerEnter(Collider other)
        {
            if (HealthWriter == null)
            {
                return;
            }

            // Ignore collision if this player is already dead
            if (HealthWriter.Data.currentHealth <= 0)
            {
                return;
            }

            if (other != null && (other.gameObject.tag == "Bullet" || other.gameObject.tag == "Shield"))
            {
                int newHealth = HealthWriter.Data.currentHealth - 250;

                HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));
            }
        }
Beispiel #16
0
 public static void SetCanBeChanged(this Health.Writer health, bool canBeChanged)
 {
     health.Send(new Health.Update().SetCanBeChanged(canBeChanged));
 }
        private void OnTriggerEnter(Collider other)
        {
            /*
             * Unity's OnTriggerEnter runs even if the MonoBehaviour is disabled, so non-authoritative UnityWorkers
             * must be protected against null writers
             */
            if (HealthWriter == null)
            {
                return;
            }

            // Ignore collision if this player is already dead
            if (HealthWriter.Data.health <= 0)
            {
                return;
            }

            if (other != null &&
                (other.gameObject.CompareTag("Sword") ||
                 other.gameObject.CompareTag("Projectile")))
            {
                //Debug.LogError(other.gameObject.GetComponent<Rigidbody>().velocity.magnitude);

                //if(other.gameObject.GetComponent<Rigidbody>().velocity.magnitude < 1) {
                //    return;
                //}

                // Reduce health of this entity when hit
                int newHealth = HealthWriter.Data.health
                                - SimulationSettings.PlayerSwordDamage;

                HealthWriter.Send(new Health.Update().SetHealth(newHealth));

                int  pointsToAward = SimulationSettings.PlayerHitPointAward;
                bool isKill        = false;

                if (newHealth <= 0)
                {
                    isKill         = true;
                    pointsToAward += SimulationSettings.PlayerKillPointAward;
                }

                AwardPointsToPlayer(pointsToAward,
                                    isKill,
                                    other
                                    .GetComponent <WorkerItemHandler>()
                                    .playerId);
            }

            if (other != null &&
                (other.gameObject.CompareTag("Sword") ||
                 other.gameObject.CompareTag("Shield")))
            {
                Debug.LogError(rb);

                Vector3 direction =
                    gameObject.transform.position
                    - other.gameObject.transform.position;

                direction.y = Mathf.Abs(direction.y);

                Vector3.Normalize(direction);

                rb.AddForce(direction * 15, ForceMode.Impulse);
            }
        }
Beispiel #18
0
        private void OnSuicide(Suicide suicide)
        {
            int newHealth = HealthWriter.Data.currentHealth - 1000;

            HealthWriter.Send(new Health.Update().SetCurrentHealth(newHealth));
        }
Beispiel #19
0
 public void SetCanBeChanged(bool canBeChanged)
 {
     health.Send(new Health.Update().SetCanBeChanged(canBeChanged));
 }