예제 #1
0
 public EntityDamageEventArgs(EntityBase entity, short damage, Client damagedBy, DamageCause cause)
     : base(entity)
 {
     Damage = damage;
     DamagedBy = damagedBy;
     Cause = cause;
 }
예제 #2
0
    void kill(DamageCause COD = DamageCause.Default)
    {
        print (gameObject.name + " suffered a death by " + COD.ToString());

        if (GetComponent<ShootingEnemy>() != null) {
            GetComponent<ShootingEnemy>().weapon.Drop ();
            GameObject ammo = GameObject.CreatePrimitive(PrimitiveType.Cube);
            ammo.name = "DroppedAmmo";
            ammo.transform.Translate(transform.position);
            ammo.transform.Translate(0f,0.5f,0f);
            ammo.AddComponent(typeof(AmmoPickup));
            ammo.GetComponent<AmmoPickup>().ammoType = GetComponent<ShootingEnemy>().ammoType;//GetComponent<ShootingEnemy>().ammo
            ammo.GetComponent<AmmoPickup>().Bullets = GetComponent<ShootingEnemy>().ammo[(int)GetComponent<ShootingEnemy>().ammoType];
        }

        List<Enemy> es = PathfindingEnemy.listEnemies();
        es.Remove(thisEnemy);
        PathfindingEnemy.setTargets(PathfindingEnemy.listEnemies());
        foreach (Enemy e in PathfindingEnemy.targets) {
            if (e is PathfindingEnemy || e is ShootingEnemy) {
                (e as PathfindingEnemy).checkTarget();
                print ("Calling checkTarget on " + e.name);
            }
        }
        Complete();
        gameObject.SetActive(false);
    }
예제 #3
0
파일: Health.cs 프로젝트: wow4all/Scripts
 public static string getMsg(DamageCause cause)
 {
     switch (cause) {
     case DamageCause.Blowback :
         return "You died of blowback. Some grenade launchers will cause you massive harm if you are standing too close to the a wall.";
     case DamageCause.EnemyHit :
         return "You were shot by an enemy. Watch for enemy fire, and make use of cover.";
     case DamageCause.Shot :
         return "You got shot down. Make sure to check your flank.";
     case DamageCause.Poisoned :
         return "You died of a poison. Try to get the antidote next time.";
     case DamageCause.Explosion :
         return "You were killed by an explosion. Watch for grenades and barrels";
     case DamageCause.VehicularMisadventure :
         return "You drove into something less likely to yield than yourself. Watch out.";
     case DamageCause.RunDown :
         return "You got hit by a car. Avoid being too far from something very solid.";
     case DamageCause.Radiation :
         return "Most water is radioactive. Try to avoid it.";
     case DamageCause.Fire :
         return "You burned to death.";
     case DamageCause.KineticInjury :
         return "You giot hit to death. Avoid letting things hit you very hard by standing in cover.";
     }
     return "";
 }
예제 #4
0
 public float damage(float damage, DamageCause COD = DamageCause.Default)
 {
     if (Health > damage) {
         Health -= damage;
     } else {
         Health = 0;
         kill (COD);
     }
     if (playSounds) audio.PlayOneShot(painSounds[(int)(Random.value * (painSounds.Length-1))]);
     return damage;
 }
예제 #5
0
    public float damageAsCombatant(float health, Enemy shooter, DamageCause COD = DamageCause.Shot)
    {
        damage(health, COD);
        if (GetComponent<PathfindingEnemy>()!=null){
            GetComponent<PathfindingEnemy>().setTarget(shooter, AlertingMethod.Shot);
            print ("Alerted PathfindingEnemy");
        } else {
            print ("Failed to alert PathfindingEnemy");
        }

        print ("Shot by someone!");

        return health;
    }
예제 #6
0
        public override void TakeHit(Entity source, Item tool, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (Entity.Level is GameLevel level)
            {
                level.HandleDamage(source, Entity, tool, damage, cause);
            }

            //Void damage should be handled this way regardless of location
            if (cause == DamageCause.Void)
            {
                PlayerLocation spawnLocation = (PlayerLocation)Entity.Level.SpawnPoint.Clone();
                spawnLocation.Y += 1;                 //Spawn slightly above the spawn block

                ((SkyPlayer)Entity).Teleport(spawnLocation);
            }
        }
예제 #7
0
        public override void TakeHit(Entity source, Item tool, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (Entity.Level is OpenLevel lvl)
            {
                int h = Health;
                EntityDamageEvent damageEvent = new EntityDamageEvent(base.Entity, source,
                                                                      cause, h, h - damage);
                lvl.EventDispatcher.DispatchEvent(damageEvent);
                if (damageEvent.IsCancelled)
                {
                    return;
                }
            }

            base.TakeHit(source, tool, damage, cause);
        }
예제 #8
0
 public float damage(float damage, DamageCause COD = DamageCause.Default)
 {
     if (Health > damage)
     {
         Health -= damage;
     }
     else
     {
         Health = 0;
         kill(COD);
     }
     if (playSounds)
     {
         audio.PlayOneShot(painSounds[(int)(Random.value * (painSounds.Length - 1))]);
     }
     return(damage);
 }
예제 #9
0
    public float damageAsCombatant(float health, Enemy shooter, DamageCause COD = DamageCause.Shot)
    {
        damage(health, COD);
        if (GetComponent <PathfindingEnemy>() != null)
        {
            GetComponent <PathfindingEnemy>().setTarget(shooter, AlertingMethod.Shot);
            print("Alerted PathfindingEnemy");
        }
        else
        {
            print("Failed to alert PathfindingEnemy");
        }

        print("Shot by someone!");

        return(health);
    }
예제 #10
0
    public void damage(int damage, DamageCause cause)
    {
        this.health -= damage;

        if (cause == DamageCause.FALL)
        {
            Debug.Log("Вы упали и потеряли " + damage + " здоровья");
            Color color = damageBackground.color;
            color.a = 0.3F;
            damageBackground.color = color;
        }
        else
        {
            Color color = damageBackground.color;
            color.a = 0.2F;
            damageBackground.color = color;
        }
    }
예제 #11
0
    /// <summary>
    /// Use this for receive damage local and sync for all other
    /// </summary>
    public void GetDamage(float damage, string t_from, DamageCause cause, Vector3 direction, int weapon_ID = 0)
    {
        float m_TotalDamage = damage + multiplier;

        DamageData e = new DamageData();

        e.Damage     = m_TotalDamage;
        e.Direction  = direction;
        e.Cause      = cause;
        e.isHeadShot = TakeHeatShot;
        e.GunID      = weapon_ID;
        e.From       = t_from;

        if (HealtScript != null)
        {
            HealtScript.GetDamage(e);
        }
    }
예제 #12
0
        public virtual void Damage(DamageCause cause, short damageAmount, IEntityBase hitBy = null, params object[] args)
        {
            if (damageAmount <= 0)
            {
                World.Logger.Log(LogLevel.Warning, string.Format("Invalid damage {0} of type {1} caused by {2} to {3}({4})", damageAmount, cause, (hitBy == null ? "null" : hitBy.EntityId.ToString()), Name, EntityId));
                return;
            }
            lock (_damageLock)
            {
                if (World.WorldTicks - LastDamageTick < 10)
                {
                    return;
                }
                LastDamageTick = World.WorldTicks;
                EntityDamageEventArgs e = new EntityDamageEventArgs(this, damageAmount, hitBy, cause);
                Server.PluginManager.CallEvent(Event.EntityDamage, e);
                if (e.EventCanceled)
                {
                    return;
                }
                damageAmount = e.Damage;
                hitBy        = e.DamagedBy as EntityBase;
                // Debug
                if (hitBy is Player)
                {
                    var       hitByPlayer = hitBy as Player;
                    ItemStack itemHeld    = hitByPlayer.Inventory.ActiveItem;
                    hitByPlayer.Client.SendMessage("You hit a " + Name + " with a " + itemHeld.Type + " dealing " +
                                                   damageAmount + " damage.");
                }

                Health -= damageAmount;
                SendUpdateOnDamage();

                // TODO: Entity Knockback

                if (Health <= 0)
                {
                    HandleDeath(hitBy as EntityBase);
                }
            }
        }
예제 #13
0
 /// <summary>3
 /// Deal damage to player.ss
 /// </summary>
 /// <param name='damage'>
 /// the amount of damage received.
 /// </param>
 /// <returns>
 /// Whether the player survived.
 /// </returns>
 public bool Damage(float damage, DamageCause COD = DamageCause.Default)
 {
     lastInjury = Time.time;
     if (playSounds)
     {
         painSoundSource.PlayOneShot(painSounds[(int)(Random.value * (painSounds.Length - 1))]);
     }
     fader.SetScreenOverlayColor(fadeColor);
     fader.StartFade(transparent, fadeTime);
     lastCOD = COD;
     if (damage >= HealthLevel)
     {
         Die();
         return(false);
     }
     else
     {
         HealthLevel = HealthLevel - damage;
         return(true);
     }
 }
예제 #14
0
    public static string getMsg(DamageCause cause)
    {
        switch (cause)
        {
        case DamageCause.Blowback:
            return("You died of blowback. Some grenade launchers will cause you massive harm if you are standing too close to the a wall.");

        case DamageCause.EnemyHit:
            return("You were shot by an enemy. Watch for enemy fire, and make use of cover.");

        case DamageCause.Shot:
            return("You got shot down. Make sure to check your flank.");

        case DamageCause.Poisoned:
            return("You died of a poison. Try to get the antidote next time.");

        case DamageCause.Explosion:
            return("You were killed by an explosion. Watch for grenades and barrels");

        case DamageCause.VehicularMisadventure:
            return("You drove into something less likely to yield than yourself. Watch out.");

        case DamageCause.RunDown:
            return("You got hit by a car. Avoid being too far from something very solid.");

        case DamageCause.Radiation:
            return("Most water is radioactive. Try to avoid it.");

        case DamageCause.Fire:
            return("You burned to death.");

        case DamageCause.KineticInjury:
            return("You giot hit to death. Avoid letting things hit you very hard by standing in cover.");
        }
        return("");
    }
예제 #15
0
        public void TakeHit(Player source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (LastDamageCause == DamageCause.Unknown)
            {
                LastDamageCause = cause;
            }

            LastDamageSource = source;

            Health -= damage;

            if (Entity == null)
            {
                return;
            }

            var player = Entity as Player;

            if (player != null)
            {
                player.SendHealth();
                player.BroadcastEntityAnimation(Animations.TakeDamage);
            }
        }
예제 #16
0
        protected virtual double CalculateDamageReducationFromEnchantments(Entity source, Item armor, Item tool, DamageCause cause)
        {
            if (armor == null)
            {
                return(0);
            }
            if (armor.ExtraData == null)
            {
                return(0);
            }

            double reduction = 0;

            {
                var enchantings = armor.GetEnchantings();
                foreach (var enchanting in enchantings)
                {
                    double typeModifier = 0;

                    EnchantingType enchantingType = enchanting.Id;
                    switch (enchantingType)
                    {
                    case EnchantingType.Protection:
                        typeModifier = 1;
                        break;

                    case EnchantingType.FireProtection:
                        if (cause == DamageCause.FireTick)
                        {
                            typeModifier = 2;
                        }
                        break;

                    case EnchantingType.BlastProtection:
                        // Not handled right now
                        //typeModifier = 2;
                        break;

                    case EnchantingType.ProjectileProtection:
                        if (source is Arrow)
                        {
                            typeModifier = 2;
                        }
                        break;

                    case EnchantingType.FeatherFalling:
                        if (cause == DamageCause.Fall)
                        {
                            typeModifier = 3;
                        }
                        break;

                    case EnchantingType.Thorns:
                        // Refactor: Make damage to the attacker (!)
                        break;

                    case EnchantingType.Respiration:
                        // HealthManager air-ticks
                        break;

                    case EnchantingType.DepthStrider:
                        break;

                    case EnchantingType.AquaAffinity:
                        break;

                    case EnchantingType.Sharpness:
                        break;

                    case EnchantingType.Smite:
                        break;

                    case EnchantingType.BaneOfArthropods:
                        break;

                    case EnchantingType.Knockback:
                        // Need to deal with for all knockbacks
                        break;

                    case EnchantingType.FireAspect:
                        // Set target on fire. Need to deal with in "take hit" perhaps?
                        break;

                    case EnchantingType.Looting:
                        break;

                    case EnchantingType.Efficiency:
                        break;

                    case EnchantingType.SilkTouch:
                        break;

                    case EnchantingType.Durability:
                        break;

                    case EnchantingType.Fortune:
                        break;

                    case EnchantingType.Power:
                        break;

                    case EnchantingType.Punch:
                        break;

                    case EnchantingType.Flame:
                        break;

                    case EnchantingType.Infinity:
                        break;

                    case EnchantingType.LuckOfTheSea:
                        break;

                    case EnchantingType.Lure:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    reduction += enchanting.Level * typeModifier;
                }
            }

            return(reduction);
        }
예제 #17
0
 public override void TakeHit(Entity source, Item tool, int damage = 1, DamageCause cause = DamageCause.Unknown)
 {
 }
예제 #18
0
        public virtual double CalculatePlayerDamage(Entity source, Player target, Item tool, double damage, DamageCause cause)
        {
            double originalDamage = damage;
            double armorValue     = 0;
            double epfValue       = 0;

            {
                {
                    Item armorPiece = target.Inventory.Helmet;
                    switch (armorPiece.ItemMaterial)
                    {
                    case ItemMaterial.Leather:
                        armorValue += 1;
                        break;

                    case ItemMaterial.Gold:
                        armorValue += 2;
                        break;

                    case ItemMaterial.Chain:
                        armorValue += 2;
                        break;

                    case ItemMaterial.Iron:
                        armorValue += 2;
                        break;

                    case ItemMaterial.Diamond:
                        armorValue += 3;
                        break;
                    }
                    epfValue += CalculateDamageReducationFromEnchantments(source, armorPiece, tool, cause);
                }

                {
                    Item armorPiece = target.Inventory.Chest;
                    switch (armorPiece.ItemMaterial)
                    {
                    case ItemMaterial.Leather:
                        armorValue += 3;
                        break;

                    case ItemMaterial.Gold:
                        armorValue += 5;
                        break;

                    case ItemMaterial.Chain:
                        armorValue += 5;
                        break;

                    case ItemMaterial.Iron:
                        armorValue += 6;
                        break;

                    case ItemMaterial.Diamond:
                        armorValue += 8;
                        break;
                    }
                    epfValue += CalculateDamageReducationFromEnchantments(source, armorPiece, tool, cause);
                }

                {
                    Item armorPiece = target.Inventory.Leggings;
                    switch (armorPiece.ItemMaterial)
                    {
                    case ItemMaterial.Leather:
                        armorValue += 2;
                        break;

                    case ItemMaterial.Gold:
                        armorValue += 3;
                        break;

                    case ItemMaterial.Chain:
                        armorValue += 4;
                        break;

                    case ItemMaterial.Iron:
                        armorValue += 5;
                        break;

                    case ItemMaterial.Diamond:
                        armorValue += 6;
                        break;
                    }
                    epfValue += CalculateDamageReducationFromEnchantments(source, armorPiece, tool, cause);
                }

                {
                    Item armorPiece = target.Inventory.Boots;
                    switch (armorPiece.ItemMaterial)
                    {
                    case ItemMaterial.Leather:
                        armorValue += 1;
                        break;

                    case ItemMaterial.Gold:
                        armorValue += 1;
                        break;

                    case ItemMaterial.Chain:
                        armorValue += 1;
                        break;

                    case ItemMaterial.Iron:
                        armorValue += 2;
                        break;

                    case ItemMaterial.Diamond:
                        armorValue += 3;
                        break;
                    }
                    epfValue += CalculateDamageReducationFromEnchantments(source, armorPiece, tool, cause);
                }
            }

            damage = damage * (1 - Math.Max(armorValue / 5, armorValue - damage / 2) / 25);

            epfValue = Math.Min(20, epfValue);
            damage   = damage * (1 - epfValue / 25);


            Log.Debug($"Original Damage={originalDamage:F1} Redused Damage={damage:F1}, Armor Value={armorValue:F1}, EPF {epfValue:F1}");
            return((int)damage);

            //armorValue *= 0.04; // Each armor point represent 4% reduction
            //return (int) Math.Floor(damage*(1.0 - armorValue));
        }
예제 #19
0
파일: Player.cs 프로젝트: TheaP/c-raft
 /// <summary>
 /// Updates nearby players when Client is hurt.
 /// </summary>
 /// <param name="cause"></param>
 /// <param name="damageAmount"></param>
 /// <param name="hitBy">The Client hurting the current Client.</param>
 /// <param name="args">First argument should always be the damage amount.</param>
 public override void Damage(DamageCause cause, short damageAmount, IEntityBase hitBy = null, params object[] args)
 {
     if (GameMode == GameMode.Creative)
         return;
     // Armor can't reduce suffocation, fire burn, drowning, starving, magic, generic and falling-in-void damage
     if (cause != DamageCause.Suffocation && cause != DamageCause.Drowning && cause != DamageCause.FireBurn && cause != DamageCause.Void)
         damageAmount = ApplyArmorReduction(damageAmount);
     Exhaustion += 300;
     base.Damage(cause, damageAmount, hitBy, args);
 }
예제 #20
0
 public EntityDamageEventArgs(IEntityBase entity, short damage, IEntityBase damagedBy, DamageCause cause)
     : base(entity)
 {
     Damage    = damage;
     DamagedBy = damagedBy;
     Cause     = cause;
 }
예제 #21
0
 public virtual void HandleDamage(GameLevel gameLevel, Entity source, Entity target, Item item, int damage, DamageCause damageCause)
 {
 }
예제 #22
0
 public override void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
 {
     base.TakeHit(source, 0, cause);
 }
예제 #23
0
파일: BossBar.cs 프로젝트: rdcpe/xCoreSplit
 public override void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
 {
     //base.TakeHit(source, 0, cause);
 }
예제 #24
0
        public void TakeHit(Classes.Player source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (LastDamageCause == DamageCause.Unknown) LastDamageCause = cause;

            LastDamageSource = source;

            //Untested code below, should work fine, however this is not sure yet.
            //	int Damage = ItemFactory.GetItem(sourcePlayer.Inventory.ItemInHand.Value.Id).GetDamage();
            //	Health -= Damage - Entity.Armour;

            Health -= damage;
            if (Player != null)
                Player.SendHealth();
            new Animation(Player.Wrapper) { AnimationId = 1, TargetPlayer = Player }.Broadcast();
        }
예제 #25
0
 public void Trigger(DamageCause damageCause)
 {
     _life.DealDamage(damageCause.damage);
 }
예제 #26
0
 public virtual void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
 {
     TakeHit(source, null, damage, cause);
 }
예제 #27
0
        public virtual void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (!Entity.Level.IsSurvival) return;

            if (CooldownTick > 0) return;

            LastDamageSource = source;
            LastDamageCause = cause;

            Health -= damage*10;
            if (Health < 0) Health = 0;

            var player = Entity as Player;
            if (player != null)
            {
                player.HungerManager.IncreaseExhaustion(0.3f);

                player.SendUpdateAttributes();
                player.BroadcastEntityEvent();
            }
            else
            {
                Entity.Level.RelayBroadcast(new McpeEntityEvent
                {
                    entityId = Entity.EntityId,
                    eventId = (byte) (Health <= 0 ? 3 : 2)
                });
            }

            if (source != null)
            {
                double dx = source.KnownPosition.X - Entity.KnownPosition.X;

                Random rand = new Random();
                double dz;
                for (dz = source.KnownPosition.Z - Entity.KnownPosition.Z; dx*dx + dz*dz < 0.00010; dz = (rand.NextDouble() - rand.NextDouble())*0.01D)
                {
                    dx = (rand.NextDouble() - rand.NextDouble())*0.01D;
                }

                double knockbackForce = Math.Sqrt(dx*dx + dz*dz);
                float knockbackMultiplier = 0.4F;

                //this.motX /= 2.0D;
                //this.motY /= 2.0D;
                //this.motZ /= 2.0D;
                double motX = 0;
                motX -= dx/knockbackForce*knockbackMultiplier;
                double motY = knockbackMultiplier;
                double motZ = 0;
                motZ -= dz/knockbackForce*knockbackMultiplier;
                if (motY > 0.4)
                {
                    motY = 0.4;
                }
                Entity.Knockback(new Vector3(motX, motY, motZ));
            }

            CooldownTick = 10;

            OnPlayerTakeHit(new HealthEventArgs(this, source, Entity));
        }
예제 #28
0
 public EntityDamageEvent(IEntity damagee, DamageCause cause, int damage)
     : base(damagee)
 {
     this.cause  = cause;
     this.damage = damage;
 }
예제 #29
0
        public virtual void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            var player = Entity as Player;

            if (player != null && player.GameMode != GameMode.Survival)
            {
                return;
            }


            if (CooldownTick > 0)
            {
                return;
            }

            LastDamageSource = source;
            LastDamageCause  = cause;

            Health -= damage * 10;
            if (Health < 0)
            {
                Health = 0;
            }

            if (player != null)
            {
                player.HungerManager.IncreaseExhaustion(0.3f);

                player.SendUpdateAttributes();
                player.BroadcastEntityEvent();
            }
            else
            {
                var msg = McpeEntityEvent.CreateObject();
                msg.entityId = Entity.EntityId;
                msg.eventId  = (byte)(Health <= 0 ? 3 : 2);
                Entity.Level.RelayBroadcast(msg);
            }

            if (source != null)
            {
                double dx = source.KnownPosition.X - Entity.KnownPosition.X;

                Random rand = new Random();
                double dz;
                for (dz = source.KnownPosition.Z - Entity.KnownPosition.Z; dx *dx + dz *dz < 0.00010; dz = (rand.NextDouble() - rand.NextDouble()) * 0.01D)
                {
                    dx = (rand.NextDouble() - rand.NextDouble()) * 0.01D;
                }

                double knockbackForce      = Math.Sqrt(dx * dx + dz * dz);
                float  knockbackMultiplier = 0.4F;

                //this.motX /= 2.0D;
                //this.motY /= 2.0D;
                //this.motZ /= 2.0D;
                double motX = 0;
                motX -= dx / knockbackForce * knockbackMultiplier;
                double motY = knockbackMultiplier;
                double motZ = 0;
                motZ -= dz / knockbackForce * knockbackMultiplier;
                if (motY > 0.4)
                {
                    motY = 0.4;
                }
                Entity.Knockback(new Vector3(motX, motY, motZ));
            }

            CooldownTick = 10;

            OnPlayerTakeHit(new HealthEventArgs(this, source, Entity));
        }
예제 #30
0
        public override void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (!(source is Player))
            {
                return;
            }

            // Pets must die in void or they get stuck forever :-(
            if (cause == DamageCause.Void)
            {
                base.TakeHit(source, damage, cause);
                return;                 // Love denied!
            }

            int size = Entity.Level.Random.Next(0, 3);             // The size of the hearts

            Pet pet = Entity as Pet;

            if (pet != null)
            {
                if (pet.AttackTarget != null)
                {
                    return;
                }

                // He is still angry, better not pet him right now.
                if (!pet.IsInRage && IsOnFire && pet.Level.Random.Next(10) == 0)
                {
                    pet.AttackTarget = (Player)source;
                    pet.RageTick     = 20 * 3;
                    return;
                }

                // Only owner do petting with my pet!
                if (pet.Owner == source)
                {
                    // Don't trust animals!
                    if (pet.Level.Random.Next(500) == 0)
                    {
                        pet.AttackTarget = (Player)source;
                        pet.RageTick     = 20 * 2;
                        return;
                    }

                    Particle particle = new HeartParticle(pet.Level, size);
                    particle.Position = Entity.KnownPosition.ToVector3() + new Vector3(0, (float)(Entity.Height + 0.85d), 0);
                    particle.Spawn();
                }
                else
                {
                    // HAHA Steal IT!
                    if (pet.Level.Random.Next(50) == 0)
                    {
                        pet.Owner        = (Player)source;
                        pet.AttackTarget = null;
                        pet.RageTick     = 0;
                        return;
                    }

                    // Don't trust animals!
                    if (pet.Level.Random.Next(30) == 0)
                    {
                        pet.AttackTarget = (Player)source;
                        pet.RageTick     = 20 * 3;
                        return;
                    }
                }
            }
        }
예제 #31
0
        public void HandleDamage(Entity source, Entity target, Item item, int damage, DamageCause damageCause)
        {
            if (!(target is SkyPlayer))
            {
                return;
            }

            CurrentState.HandleDamage(this, source, target, item, damage, damageCause);
        }
예제 #32
0
파일: Player.cs 프로젝트: MrGenga/MiNET
		public virtual void BroadcastDeathMessage(Player player, DamageCause lastDamageCause)
		{
			string deathMessage = string.Format(HealthManager.GetDescription(lastDamageCause), Username, player == null ? "" : player.Username);
			Level.BroadcastMessage(deathMessage, type: McpeText.TypeRaw);
			Log.Debug(deathMessage);
		}
    /// <summary>
    /// Called This when player Die Logic
    /// </summary>
    void Die(string killer, bool isHeat, DamageCause cause, int gunID, Vector3 hitPos, Player sender)
    {
        dead = true;
        m_CharacterController.enabled = false;
        if (!isMine)
        {
            BodyManager.Ragdolled(hitPos);// convert into ragdoll the remote player
        }
        else
        {
            Transform ngr = (bl_GameData.Instance.DropGunOnDeath) ? null : PlayerSync.NetGunsRoot;
            BodyManager.SetLocalRagdoll(hitPos, ngr, m_CharacterController.velocity);
        }
        for (int i = 0; i < transform.childCount; i++)
        {
            transform.GetChild(i).gameObject.SetActive(false);
        }
        string weapon = cause.ToString();

        if (cause == DamageCause.Player || cause == DamageCause.Bot || cause == DamageCause.Explosion)
        {
            weapon = bl_GameData.Instance.GetWeapon(gunID).Name;
        }
        //Spawn ragdoll
        if (!isMine)// when player is not ours
        {
            if (m_LastShot == LocalName)
            {
                AddKill(isHeat, weapon, gunID);
            }
            if (!isOneTeamMode)
            {
                if (photonView.Owner.GetPlayerTeam() == PhotonNetwork.LocalPlayer.GetPlayerTeam())
                {
                    GameObject di = bl_ObjectPooling.Instance.Instantiate("deathicon", transform.position, transform.rotation);
                    di.GetComponent <bl_ClampIcon>().SetTempIcon(DeathIcon, DeathIconShowTime, 20);
                }
            }
        }
        else//when is our
        {
            AddDeath();
            //show kill cam
            BodyManager.gameObject.name = "YOU";
            GameObject kc = Instantiate(KillCamPrefab, transform.position, transform.rotation) as GameObject;
            kc.GetComponent <bl_KillCam>().SetTarget(sender, cause, killer, BodyManager.PelvisBone);
            bl_UIReferences.Instance.OnKillCam(true, killer, gunID);
            BodyManager.KillCameraCache = kc;
#if ELIM
            bl_Elimination.Instance.OnLocalDeath(kc.GetComponent <bl_KillCam>());
#endif
            if (killer == LocalName)
            {
#if LOCALIZATION
                if (cause == DamageCause.FallDamage)
                {
                    bl_EventHandler.KillEvent(LocalName, string.Empty, bl_Localization.Instance.GetText(20), myTeam, 5, 20);
                }
                else
                {
                    bl_EventHandler.KillEvent(LocalName, string.Empty, bl_Localization.Instance.GetText(19), myTeam, 5, 20);
                }
#else
                if (cause == DamageCause.FallDamage)
                {
                    bl_EventHandler.KillEvent(LocalName, string.Empty, bl_GameTexts.DeathByFall, myTeam, 5, 20);
                }
                else
                {
                    bl_EventHandler.KillEvent(LocalName, string.Empty, bl_GameTexts.CommittedSuicide, myTeam, 5, 20);
                }
#endif
            }
            if (bl_GameData.Instance.DropGunOnDeath)
            {
                GunManager.ThrwoCurrent(true);
            }
            if (cause == DamageCause.Bot)
            {
                bl_EventHandler.KillEvent(killer, gameObject.name, weapon, myTeam, 5, 20);
                bl_AIMananger.Instance.SetBotKill(killer);
            }
            StartCoroutine(DestroyThis());
        }
    }
예제 #34
0
        public virtual void Damage(DamageCause cause, short damageAmount, IEntityBase hitBy = null, params object[] args)
        {
            if (damageAmount <= 0)
            {
                World.Logger.Log(LogLevel.Warning, string.Format("Invalid damage {0} of type {1} caused by {2} to {3}({4})", damageAmount, cause, (hitBy == null ? "null" : hitBy.EntityId.ToString()), Name, EntityId));
                return;
            }
            lock (_damageLock)
            {
                if (World.WorldTicks - LastDamageTick < 10)
                    return;
                LastDamageTick = World.WorldTicks;
                EntityDamageEventArgs e = new EntityDamageEventArgs(this, damageAmount, hitBy, cause);
                Server.PluginManager.CallEvent(Event.EntityDamage, e);
                if (e.EventCanceled) return;
                damageAmount = e.Damage;
                hitBy = e.DamagedBy as EntityBase;
                // Debug
                if (hitBy is Player)
                {
                    var hitByPlayer = hitBy as Player;
                    var itemHeld = hitByPlayer.Inventory.ActiveItem;
                    hitByPlayer.Client.SendMessage("You hit a " + Name + " with a " + itemHeld.Type + " dealing " +
                                                   damageAmount + " damage.");
                }

                Health -= damageAmount;
                SendUpdateOnDamage();

                // TODO: Entity Knockback

                if (Health <= 0)
                    HandleDeath(hitBy as EntityBase);
            }
        }
예제 #35
0
        public override void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (!(source is Player))
            {
                return;
            }

            // Pets must die in void or they get stuck forever :-(
            if (cause == DamageCause.Void)
            {
                base.TakeHit(source, damage, cause);
                return;                 // Love denied!
            }

            int size = Entity.Level.Random.Next(0, 3);             // The size of the hearts

            Pet pet = Entity as Pet;

            if (pet != null)
            {
                if (pet.AttackTarget != null)
                {
                    return;
                }

                // He is still angry, better not pet him right now.
                if (!pet.IsInRage && IsOnFire && pet.Level.Random.Next(10) == 0)
                {
                    pet.AttackTarget = (Player)source;
                    pet.RageTick     = 20 * 3;
                    return;
                }

                // Only owner do petting with my pet!
                if (pet.Owner == source)
                {
                    // Don't trust animals!
                    if (pet.Level.Random.Next(500) == 0)
                    {
                        pet.AttackTarget = (Player)source;
                        pet.RageTick     = 20 * 2;
                        return;
                    }

                    pet.Level.RelayBroadcast(new McpeLevelEvent
                    {
                        eventId = 0x4000 | 15,
                        x       = Entity.KnownPosition.X,
                        y       = (float)(Entity.KnownPosition.Y + Entity.Height + 0.85d),
                        z       = Entity.KnownPosition.Z,
                        data    = size
                    });
                }
                else
                {
                    // HAHA Steal IT!
                    if (pet.Level.Random.Next(50) == 0)
                    {
                        pet.Owner        = (Player)source;
                        pet.AttackTarget = null;
                        pet.RageTick     = 0;
                        return;
                    }

                    // Don't trust animals!
                    if (pet.Level.Random.Next(30) == 0)
                    {
                        pet.AttackTarget = (Player)source;
                        pet.RageTick     = 20 * 3;
                        return;
                    }
                }
            }
        }
예제 #36
0
        public override void HandleDamage(GameLevel gameLevel, Entity source, Entity target, Item item, int damage, DamageCause damageCause)
        {
            if (!(target is SkyPlayer) || ((SkyPlayer)target).IsGameSpectator)
            {
                return;
            }

            if (source is GunProjectile arrow && arrow.Shooter is SkyPlayer)
            {
                SkyPlayer shooter = (SkyPlayer)arrow.Shooter;

                //Ensure this player is alive
                if (!shooter.IsGameSpectator)
                {
                    KillPlayer((MurderLevel)gameLevel, (SkyPlayer)target);
                }
            }
    void SyncDamage(float damage, string killer, DamageCause cause, Vector3 m_direction, bool isHeatShot, int weaponID, Player m_sender)
    {
        if (dead || isProtectionEnable)
        {
            return;
        }

        if (DamageEnabled)
        {
            if (health > 0)
            {
                if (isMine)
                {
                    damageAlphaValue += (damage + ((maxHealth - health) * (Time.deltaTime * Mathf.PI))) * 0.2f;
                    bl_EventHandler.PlayerLocalShakeEvent(ShakeAmount, ShakeTime);
                    if (Indicator != null)
                    {
                        Indicator.AttackFrom(m_direction);
                    }
                    TimeToRegenerate = StartRegenerateIn;
                }
                else
                {
                    if (m_sender != null)
                    {
                        if (m_sender.NickName == LocalName)
                        {
                            bl_UCrosshair.Instance.OnHit();
                        }
                    }
                }
            }
            if (cause != DamageCause.FallDamage && cause != DamageCause.Fire)
            {
                if (HitsSound.Length > 0)//Audio effect of hit
                {
                    AudioSource.PlayClipAtPoint(HitsSound[Random.Range(0, HitsSound.Length)], transform.position, 1.0f);
                }
            }
            else
            {
                AudioSource.PlayClipAtPoint(InjuredSounds[Random.Range(0, InjuredSounds.Length)], transform.position, 1.0f);
            }
        }
        if (health > 0)
        {
            m_LastShot = killer;
            health    -= damage;
            if (!isMine)
            {
                PlayerSync.m_PlayerAnimation.OnGetHit();
            }
            else
            {
                UpdateUI();
            }
        }

        if (health <= 0)
        {
            health = 0.0f;
            Die(m_LastShot, isHeatShot, cause, weaponID, m_direction, m_sender);

            if (isMine)
            {
                bl_GameManager.isAlive = false;
                bl_EventHandler.PlayerLocalDeathEvent();
            }
        }
    }
예제 #38
0
 public override void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
 {
     Entity.DespawnEntity();
 }
예제 #39
0
        public void TakeHit(Player source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (LastDamageCause == DamageCause.Unknown) LastDamageCause = cause;

            LastDamageSource = source;

            Health -= damage;

            if (Entity == null) return;

            var player = Entity as Player;
            if (player != null)
            {
                player.SendHealth();
                player.PlayerAnimation(Animations.TakeDamage);
            }
        }
예제 #40
0
        /// <summary>
        /// Updates nearby players when Client is hurt.
        /// </summary>
        /// <param name="cause"></param>
        /// <param name="hitBy">The Client hurting the current Client.</param>
        /// <param name="args">First argument should always be the damage amount.</param>
        public void DamageClient(DamageCause cause, EntityBase hitBy = null, params object[] args)
        {
            //event start
            EntityDamageEventArgs entevent = new EntityDamageEventArgs(_Player, Convert.ToInt16(args[0]), null, cause);
            _Player.Server.PluginManager.CallEvent(Event.ENTITY_DAMAGE, entevent);
            if (_Player.GameMode == 1) { entevent.EventCanceled = true; }
            if (entevent.EventCanceled) return;
            //event end

            switch (cause)
            {
                case DamageCause.BlockExplosion:
                    break;
                case DamageCause.Contact:
                    break;
                case DamageCause.Drowning:
                    break;
                case DamageCause.EntityAttack:
                    if (hitBy != null)
                    {

                    }
                    break;
                case DamageCause.EntityExplosion:
                    break;
                case DamageCause.Fall:
                    if (args.Length > 0)
                    {
                        _Player.Health -= Convert.ToInt16(args[0]);
                    }
                    break;
                case DamageCause.Fire:
                    break;
                case DamageCause.FireBurn:
                    break;
                case DamageCause.Lava:
                    break;
                case DamageCause.Lightning:
                    break;
                case DamageCause.Projectile:
                    break;
                case DamageCause.Suffocation:
                    break;
                case DamageCause.Void:
                    break;
                default:
                    _Player.Health -= 1;
                    break;

            }

            SendPacket(new UpdateHealthPacket
            {
                Health = _Player.Health,
                Food = Owner.Food,
                FoodSaturation = Owner.FoodSaturation,
            });

            foreach (Client c in _Player.Server.GetNearbyPlayers(_Player.World, new AbsWorldCoords(_Player.Position.X, _Player.Position.Y, _Player.Position.Z)))
            {
                if (c == this)
                    continue;

                c.SendPacket(new AnimationPacket // Hurt Animation
                {
                    Animation = 2,
                    PlayerId = _Player.EntityId
                });

                c.SendPacket(new EntityStatusPacket // Hurt Action
                {
                    EntityId = _Player.EntityId,
                    EntityStatus = 2
                });
            }

            if (_Player.Health == 0)
                _Player.HandleDeath(hitBy);
        }
예제 #41
0
        public virtual void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (!Entity.Level.IsSurvival)
            {
                return;
            }

            if (CooldownTick > 0)
            {
                return;
            }

            LastDamageSource = source;
            LastDamageCause  = cause;

            Health -= damage * 10;
            if (Health < 0)
            {
                Health = 0;
            }

            var player = Entity as Player;

            if (player != null)
            {
                //if (player.Username.Equals("gurun") && cause != DamageCause.Void)
                //{
                //	Health = 200;
                //	return;
                //}

                //if (cause != DamageCause.Void && player.KnownPosition.DistanceTo(player.SpawnPosition) < 7)
                //{
                //	Health = 200;
                //	return;
                //}


                player.SendSetHealth();
                player.BroadcastEntityEvent();
            }
            else
            {
                Entity.Level.RelayBroadcast(new McpeEntityEvent
                {
                    entityId = Entity.EntityId,
                    eventId  = (byte)(Health <= 0 ? 3 : 2)
                });
            }

            if (source != null)
            {
                double dx = source.KnownPosition.X - Entity.KnownPosition.X;

                Random rand = new Random();
                double dz;
                for (dz = source.KnownPosition.Z - Entity.KnownPosition.Z; dx *dx + dz *dz < 0.00010; dz = (rand.NextDouble() - rand.NextDouble()) * 0.01D)
                {
                    dx = (rand.NextDouble() - rand.NextDouble()) * 0.01D;
                }

                double knockbackForce      = Math.Sqrt(dx * dx + dz * dz);
                float  knockbackMultiplier = 0.4F;

                //this.motX /= 2.0D;
                //this.motY /= 2.0D;
                //this.motZ /= 2.0D;
                double motX = 0;
                motX -= dx / knockbackForce * knockbackMultiplier;
                double motY = knockbackMultiplier;
                double motZ = 0;
                motZ -= dz / knockbackForce * knockbackMultiplier;
                if (motY > 0.4)
                {
                    motY = 0.4;
                }
                Entity.Knockback(new Vector3(motX, motY, motZ));
            }

            CooldownTick = 10;

            OnPlayerTakeHit(new HealthEventArgs(this, source, Entity));
        }
예제 #42
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="entity">The entity that has been damaged</param>
 /// <param name="source">The source of the of the damage</param>
 /// <param name="cause">The cause of the damage</param>
 /// <param name="previousHealth">The entity's previous health value</param>
 /// <param name="newHealth">The entity's new health value</param>
 public EntityDamageEvent(MiNET.Entities.Entity entity, MiNET.Entities.Entity source, DamageCause cause, int previousHealth, int newHealth) : base(entity)
 {
     Cause          = cause;
     PreviousHealth = previousHealth;
     NewHealth      = newHealth;
     Attacker       = source;
 }
예제 #43
0
        public virtual void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            var player = Entity as Player;
            if (player != null && player.GameMode != GameMode.Survival) return;

            if (CooldownTick > 0) return;

            LastDamageSource = source;
            LastDamageCause = cause;

            Health -= damage*10;
            if (Health < 0)
            {
                OnPlayerTakeHit(new HealthEventArgs(this, source, Entity));
                Health = 0;
                Kill();
                return;
            }

            if (player != null)
            {
                player.HungerManager.IncreaseExhaustion(0.3f);

                player.SendUpdateAttributes();
                player.BroadcastEntityEvent();
            }
            else
            {
                var msg = McpeEntityEvent.CreateObject();
                msg.entityId = Entity.EntityId;
                msg.eventId = (byte) (Health <= 0 ? 3 : 2);
                Entity.Level.RelayBroadcast(msg);
            }

            if (source != null)
            {
                DoKnockback(source);
            }

            CooldownTick = 10;

            OnPlayerTakeHit(new HealthEventArgs(this, source, Entity));
        }
예제 #44
0
        public virtual void TakeHit(Entity source, Item tool, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            var player = Entity as Player;

            if (player == null || player.GameMode != GameMode.Survival || player.GameMode == GameMode.Spectator)
            {
                return;
            }


            if (CooldownTick > 0)
            {
                return;
            }

            LastDamageSource = source;
            LastDamageCause  = cause;
            if (Absorption > 0)
            {
                float abs = Absorption * 10;
                abs = abs - damage;
                if (abs < 0)
                {
                    Absorption = 0;
                    damage     = Math.Abs((int)Math.Floor(abs));
                }
                else
                {
                    Absorption = abs / 10f;
                    damage     = 0;
                }
            }

            if (cause == DamageCause.Starving)
            {
                if (Entity.Level.Difficulty <= Difficulty.Easy && Hearts <= 10)
                {
                    return;
                }
                if (Entity.Level.Difficulty <= Difficulty.Normal && Hearts <= 1)
                {
                    return;
                }
            }

            Health -= damage * 10;
            if (Health < 0)
            {
                OnPlayerTakeHit(new HealthEventArgs(this, source, Entity));
                Health = 0;
                Kill();
                return;
            }

            if (player != null)
            {
                player.HungerManager.IncreaseExhaustion(0.3f);

                player.SendUpdateAttributes();
            }

            Entity.BroadcastEntityEvent();

            if (source != null)
            {
                DoKnockback(source, tool);
            }

            CooldownTick = 10;

            OnPlayerTakeHit(new HealthEventArgs(this, source, Entity));
        }
예제 #45
0
파일: Health.cs 프로젝트: wow4all/Scripts
 /// <summary>3
 /// Deal damage to player.ss
 /// </summary>
 /// <param name='damage'>
 /// the amount of damage received.
 /// </param>
 /// <returns>
 /// Whether the player survived.
 /// </returns>
 public bool Damage(float damage, DamageCause COD = DamageCause.Default)
 {
     lastInjury = Time.time;
     if (playSounds) painSoundSource.PlayOneShot(painSounds[(int)(Random.value * (painSounds.Length-1))]);
     fader.SetScreenOverlayColor(fadeColor);
     fader.StartFade(transparent, fadeTime);
     lastCOD = COD;
     if (damage >= HealthLevel) {
         Die ();
         return false;
     } else {
         HealthLevel = HealthLevel - damage;
         return true;
     }
 }
예제 #46
0
        public virtual void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
        {
            if (!Entity.Level.IsSurvival) return;

            if (CooldownTick > 0) return;

            LastDamageSource = source;
            LastDamageCause = cause;

            Health -= damage*10;
            if (Health < 0) Health = 0;

            var player = Entity as Player;
            if (player != null)
            {
                //if (player.Username.Equals("gurun") && cause != DamageCause.Void)
                //{
                //	Health = 200;
                //	return;
                //}

                //if (cause != DamageCause.Void && player.KnownPosition.DistanceTo(player.SpawnPosition) < 7)
                //{
                //	Health = 200;
                //	return;
                //}

                player.SendSetHealth();
                player.BroadcastEntityEvent();
            }
            else
            {
                Entity.Level.RelayBroadcast(new McpeEntityEvent
                {
                    entityId = Entity.EntityId,
                    eventId = (byte) (Health <= 0 ? 3 : 2)
                });
            }

            if (source != null)
            {
                double dx = source.KnownPosition.X - Entity.KnownPosition.X;

                Random rand = new Random();
                double dz;
                for (dz = source.KnownPosition.Z - Entity.KnownPosition.Z; dx*dx + dz*dz < 0.00010; dz = (rand.NextDouble() - rand.NextDouble())*0.01D)
                {
                    dx = (rand.NextDouble() - rand.NextDouble())*0.01D;
                }

                double knockbackForce = Math.Sqrt(dx*dx + dz*dz);
                float knockbackMultiplier = 0.4F;

                //this.motX /= 2.0D;
                //this.motY /= 2.0D;
                //this.motZ /= 2.0D;
                double motX = 0;
                motX -= dx/knockbackForce*knockbackMultiplier;
                double motY = knockbackMultiplier;
                double motZ = 0;
                motZ -= dz/knockbackForce*knockbackMultiplier;
                if (motY > 0.4)
                {
                    motY = 0.4;
                }
                Entity.Knockback(new Vector3(motX, motY, motZ));
            }

            CooldownTick = 10;

            OnPlayerTakeHit(new HealthEventArgs(this, source, Entity));
        }
예제 #47
0
		public override void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown)
		{
			if (!(source is Player)) return;

			// Pets must die in void or they get stuck forever :-(
			if (cause == DamageCause.Void)
			{
				base.TakeHit(source, damage, cause);
				return; // Love denied!
			}

			int size = Entity.Level.Random.Next(0, 3); // The size of the hearts

			Pet pet = Entity as Pet;
			if (pet != null)
			{
				if (pet.AttackTarget != null) return;

				// He is still angry, better not pet him right now.
				if (!pet.IsInRage && IsOnFire && pet.Level.Random.Next(10) == 0)
				{
					pet.AttackTarget = (Player) source;
					pet.RageTick = 20*3;
					return;
				}

				// Only owner do petting with my pet!
				if (pet.Owner == source)
				{
					// Don't trust animals!
					if (pet.Level.Random.Next(500) == 0)
					{
						pet.AttackTarget = (Player) source;
						pet.RageTick = 20*2;
						return;
					}

					pet.Level.RelayBroadcast(new McpeLevelEvent
					{
						eventId = 0x4000 | 14,
						x = Entity.KnownPosition.X,
						y = Entity.KnownPosition.Y + 0.85f,
						z = Entity.KnownPosition.Z,
						data = size
					});
				}
				else
				{
					// HAHA Steal IT!
					if (pet.Level.Random.Next(50) == 0)
					{
						pet.Owner = (Player) source;
						pet.AttackTarget = null;
						pet.RageTick = 0;
						return;
					}

					// Don't trust animals!
					if (pet.Level.Random.Next(30) == 0)
					{
						pet.AttackTarget = (Player) source;
						pet.RageTick = 20*3;
						return;
					}
				}
			}
		}