Esempio n. 1
0
 public void OnCollisionEnter(Collision collision)
 {
     if (!this.rigidBody)
     {
         return;
     }
     if (this.flintLock)
     {
         ArrowDamage componentInChildren = base.transform.GetComponentInChildren <ArrowDamage>();
         if (componentInChildren && componentInChildren.Live)
         {
             componentInChildren.CheckHit(collision.transform.position, collision.transform, collision.collider.isTrigger, collision.collider);
         }
     }
     this.calculateDamage(collision.gameObject);
     if ((collision.gameObject.CompareTag("Tree") || collision.gameObject.CompareTag("Stick") || collision.gameObject.layer == 17 || collision.gameObject.layer == 20 || collision.gameObject.layer == 25 || UnderfootSurfaceDetector.GetSurfaceType(collision.collider) != UnderfootSurfaceDetector.SurfaceType.None) && this.rigidBody.velocity.magnitude > this.speedThreshold)
     {
         if (!this.InWater && !this.effectDelay)
         {
             this.PlayEvent(this.rockOnTree);
         }
         if (!this.soundDelay)
         {
             this.enableSound();
             this.soundDelay = true;
         }
     }
     if ((collision.gameObject.CompareTag("TerrainMain") || collision.gameObject.layer == 26) && this.rigidBody.velocity.magnitude > this.speedThreshold)
     {
         if (!this.InWater && !this.effectDelay)
         {
             if (this.rockOnGround.Length > 0)
             {
                 this.PlayEvent(this.rockOnGround);
             }
             else
             {
                 this.PlayEvent(this.rockOnTree);
             }
         }
         if (!this.soundDelay)
         {
             this.enableSound();
             this.soundDelay = true;
         }
     }
     if (collision.gameObject.CompareTag("Float") && this.rigidBody.velocity.magnitude > this.speedThreshold)
     {
         if (!this.InWater && !this.effectDelay)
         {
             if (this.rockOnGround.Length > 0)
             {
                 this.PlayEvent(this.stickHitTree);
             }
             else
             {
                 this.PlayEvent(this.rockOnTree);
             }
         }
         if (!this.soundDelay)
         {
             this.enableSound();
             this.soundDelay = true;
         }
     }
 }
        public override void OnEvent(PlayerHitEnemy ev)
        {
            //this needed to be changed.
            //the command would send damage using hitReal - pure damage.
            //this made clients attack ignore armor and deal too much dmg
            if (!this.ValidateSender(ev, SenderTypes.Any))
            {
                return;
            }
            if (!ev.Target)
            {
                return;
            }
            if (ev.Hit == 0)
            {
                return;
            }
            try
            {
                if (EnemyHealth.CurrentAttacker == null)
                {
                    EnemyHealth.CurrentAttacker = ev.Target;
                }
                var packed = ev.Target.networkId.PackedValue;
                if (EnemyManager.hostDictionary.ContainsKey(packed))
                {
                    var enemy = EnemyManager.hostDictionary[packed];
                    if (ev.explosion)
                    {
                        enemy.HealthScript.Explosion(-1);
                    }
                    if (ev.Burn)
                    {
                        enemy.HealthScript.Burn();
                    }
                    if (ev.getAttackerType == DamageMath.SILENTattackerType)
                    {
                        //ghost hit
                        float damage = BitConverter.ToSingle(BitConverter.GetBytes(ev.Hit), 0);
                        enemy.HitPhysicalSilent(damage);
                    }
                    else if (ev.getAttackerType == DamageMath.SILENTattackerTypeMagic)
                    {
                        //ghost hit
                        float damage = BitConverter.ToSingle(BitConverter.GetBytes(ev.Hit), 0);
                        enemy.HitMagic(damage);
                    }
                    else if (ev.getAttackerType == DamageMath.PURE)
                    {
                        float damage = BitConverter.ToSingle(BitConverter.GetBytes(ev.Hit), 0);
                        enemy.HitPure(damage);
                    }
                    else
                    {
                        if (ev.Hit > 0)
                        {
                            float damage = ev.getAttackerType >= DamageMath.CONVERTEDFLOATattackerType ? BitConverter.ToSingle(BitConverter.GetBytes(ev.Hit), 0) : ev.Hit;
                            if (ev.getAttackerType >= DamageMath.CONVERTEDFLOATattackerType)
                            {
                                ev.getAttackerType -= DamageMath.CONVERTEDFLOATattackerType;
                            }
                            //just in case i ever need this
                            //this is how to get the player object which raised the event (ev.RaisedBy.UserData as BoltEntity)
                            enemy.HealthScript.getAttackDirection(ev.getAttackerType);
                            var attackerGO = (ev.RaisedBy.UserData as BoltEntity).gameObject;
                            enemy.setup.search.switchToNewTarget(attackerGO);
                            enemy.setup.hitReceiver.getAttackDirection(ev.getAttackDirection);
                            enemy.setup.hitReceiver.getCombo(ev.getCombo);
                            enemy.HealthScript.takeDamage(ev.takeDamage);
                            enemy.HealthScript.setSkinDamage(1);
                            enemy.HitPhysical(damage);
                        }
                        else
                        {
                            ModAPI.Console.Write("The good armor reduction");
                            enemy.ReduceArmor(-ev.Hit);
                        }
                    }
                    return;
                }

                //F**k all of this spaghetti below
                lb_Bird   component           = ev.Target.GetComponent <lb_Bird>();
                Fish      componentInChildren = ev.Target.GetComponentInChildren <Fish>();
                Transform transform;
                if (componentInChildren)
                {
                    transform = componentInChildren.transform;
                }
                else if (ev.Target.GetComponent <animalHealth>())
                {
                    transform = ev.Target.transform;
                }
                else if (component)
                {
                    transform = component.transform;
                }
                else
                {
                    EnemyHealth componentInChildren2 = ev.Target.GetComponentInChildren <EnemyHealth>();
                    transform = componentInChildren2 ? componentInChildren2.transform : ev.Target.transform.GetChild(0);
                }
                if (ev.getAttacker == 10 && ev.Weapon)
                {
                    ArrowDamage componentInChildren3 = ev.Weapon.GetComponentInChildren <ArrowDamage>();
                    if (componentInChildren3.Live)
                    {
                        arrowStickToTarget componentInChildren4 = transform.GetComponentInChildren <arrowStickToTarget>();
                        Transform          target = transform;
                        if (componentInChildren4)
                        {
                            target = componentInChildren4.transform;
                        }
                        componentInChildren3.CheckHit(Vector3.zero, target, false, transform.GetComponent <Collider>());
                    }
                }
                if (ev.explosion)
                {
                    transform.SendMessage("Explosion", -1, SendMessageOptions.DontRequireReceiver);
                }
                if (ev.HitHead)
                {
                    transform.SendMessage("HitHead", SendMessageOptions.DontRequireReceiver);
                }
                if (ev.getStealthAttack)
                {
                    transform.SendMessage("getStealthAttack", SendMessageOptions.DontRequireReceiver);
                }
                float dmg = ev.getAttackerType >= DamageMath.CONVERTEDFLOATattackerType ? BitConverter.ToSingle(BitConverter.GetBytes(ev.Hit), 0) : ev.Hit;
                if (ev.hitFallDown)
                {
                    mutantHitReceiver componentInChildren5 = transform.GetComponentInChildren <mutantHitReceiver>();
                    if (componentInChildren5)
                    {
                        componentInChildren5.sendHitFallDown(dmg);
                    }
                }
                else
                {
                    if (ev.Hit > 0)
                    {
                        transform.SendMessage("getAttacker", (ev.RaisedBy.UserData as BoltEntity).gameObject, SendMessageOptions.DontRequireReceiver);
                        transform.SendMessage("getAttackerType", ev.getAttackerType, SendMessageOptions.DontRequireReceiver);
                        transform.SendMessage("getAttackDirection", ev.getAttackDirection, SendMessageOptions.DontRequireReceiver);
                        transform.SendMessage("getCombo", ev.getCombo, SendMessageOptions.DontRequireReceiver);
                        transform.SendMessage("takeDamage", ev.takeDamage, SendMessageOptions.DontRequireReceiver);
                        transform.SendMessage("setSkinDamage", UnityEngine.Random.Range(0, 3), SendMessageOptions.DontRequireReceiver);
                        transform.SendMessage("ApplyAnimalSkinDamage", ev.getAttackDirection, SendMessageOptions.DontRequireReceiver);
                        transform.SendMessage("Hit", dmg, SendMessageOptions.DontRequireReceiver);
                        if (ev.HitAxe)
                        {
                            transform.SendMessage("HitAxe", SendMessageOptions.DontRequireReceiver);
                        }
                        if (ev.Burn)
                        {
                            transform.SendMessage("Burn", SendMessageOptions.DontRequireReceiver);
                        }
                    }
                    else
                    {
                        ModAPI.Console.Write("The bad armor reduction");
                        transform.SendMessage("ReduceArmor", -dmg, SendMessageOptions.DontRequireReceiver);
                    }
                }
            }
            finally
            {
                EnemyHealth.CurrentAttacker = null;
            }
        }