Beispiel #1
0
        public static Duck ToDuck(this IAmADuck rc, bool aliveOnly = true)
        {
            if (rc == null)
            {
                return(null);
            }

            Duck duck = null;

            if (rc is TrappedDuck)
            {
                duck = ((TrappedDuck)rc).captureDuck;
            }
            else if (rc is RagdollPart)
            {
                duck = ((RagdollPart)rc).doll.captureDuck;
            }
            else if (rc is Ragdoll)
            {
                duck = ((Ragdoll)rc).captureDuck;
            }
            else if (rc is Duck)
            {
                duck = (Duck)rc;
            }

            if (aliveOnly && duck.dead)
            {
                return(null);
            }
            return(duck);
        }
Beispiel #2
0
        private void DoZapping()
        {
            foreach (KeyValuePair <Duck, ZapState> p in zapState)
            {
                p.Value.Cooldown();
            }

            Vec2     hit;
            IAmADuck duck = Level.current.CollisionRay <IAmADuck>(barrelPosition, barrelPosition + barrelVector * ZapRange, out hit);

            Duck current = duck.ToDuck();

            if (current != null)
            {
                ZapState state = GetZapState(current);

                switch (state.Increase())
                {
                case ZapResult.Slowdown:
                    current.vSpeed *= SlowdownFactor;
                    current.hSpeed *= SlowdownFactor;
                    break;

                case ZapResult.Zap:
                    if (!current.dead)
                    {
                        current.Zap(this);
                    }
                    current.Swear();
                    break;

                case ZapResult.Death:
                    current.Destroy(new DTIncinerate(this));
                    state.Clear();
                    break;
                }
            }
        }
Beispiel #3
0
 // Token: 0x06000CCA RID: 3274
 public override void Update()
 {
     base.Update();
     if (this._swordSwing.finished)
     {
         this._swordSwing.speed = 0f;
     }
     if (this._hitWait > 0)
     {
         this._hitWait--;
     }
     this._framesExisting++;
     if (this._framesExisting > 100)
     {
         this._framesExisting = 100;
     }
     if (Math.Abs(this.hSpeed) + Math.Abs(this.vSpeed) > 4f && this._framesExisting > 10)
     {
         this._wasLifted = true;
     }
     if (this.owner != null)
     {
         this._hold              = -0.4f;
         this._wasLifted         = true;
         this.center             = new Vec2(4f, 21f);
         this._framesSinceThrown = 0;
     }
     else
     {
         if (this._framesSinceThrown == 1)
         {
             this._throwSpin = Maths.RadToDeg(this.angle) - 90f;
             this._hold      = 0f;
             this._swing     = 0f;
         }
         if (this._wasLifted)
         {
             base.angleDegrees = 90f + this._throwSpin;
             this.center       = new Vec2(4f, 11f);
         }
         this._volatile = false;
         bool spinning    = false;
         bool againstWall = false;
         if (Math.Abs(this.hSpeed) + Math.Abs(this.vSpeed) > 2f || !base.grounded)
         {
             if (!base.grounded && Level.CheckRect <Block>(this.position + new Vec2(-6f, -6f), this.position + new Vec2(6f, -2f), null) != null)
             {
                 againstWall = true;
                 if (this.vSpeed > 4f)
                 {
                     this._volatile = true;
                 }
             }
             if (!againstWall && !this._grounded && Level.CheckPoint <IPlatform>(this.position + new Vec2(0f, 8f), null, null) == null)
             {
                 if (this.hSpeed > 0f)
                 {
                     this._throwSpin += (Math.Abs(this.hSpeed) + Math.Abs(this.vSpeed)) * 2f + 4f;
                 }
                 else
                 {
                     this._throwSpin -= (Math.Abs(this.hSpeed) + Math.Abs(this.vSpeed)) * 2f + 4f;
                 }
                 spinning = true;
             }
         }
         if (this._framesExisting > 15 && Math.Abs(this.hSpeed) + Math.Abs(this.vSpeed) > 3f)
         {
             this._volatile = true;
         }
         if (!spinning || againstWall)
         {
             this._throwSpin %= 360f;
             if (againstWall)
             {
                 if (Math.Abs(this._throwSpin - 90f) < Math.Abs(this._throwSpin + 90f))
                 {
                     this._throwSpin = Lerp.Float(this._throwSpin, 90f, 16f);
                 }
                 else
                 {
                     this._throwSpin = Lerp.Float(-90f, 0f, 16f);
                 }
             }
             else if (this._throwSpin > 90f && this._throwSpin < 270f)
             {
                 this._throwSpin = Lerp.Float(this._throwSpin, 180f, 14f);
             }
             else
             {
                 if (this._throwSpin > 180f)
                 {
                     this._throwSpin -= 360f;
                 }
                 else if (this._throwSpin < -180f)
                 {
                     this._throwSpin += 360f;
                 }
                 this._throwSpin = Lerp.Float(this._throwSpin, 0f, 14f);
             }
         }
         if (this._volatile && this._hitWait == 0)
         {
             (this.Offset(base.barrelOffset) - this.position).Normalize();
             this.Offset(base.barrelOffset);
             bool rebound = false;
             foreach (Thing thing in Level.current.things[typeof(Sword)])
             {
                 Sword s = (Sword)thing;
                 if (s != this && s.owner != null && s._crouchStance && !s._jabStance && !s._jabStance && ((this.hSpeed > 0f && s.x > base.x - 4f) || (this.hSpeed < 0f && s.x < base.x + 4f)) && Collision.LineIntersect(this.barrelStartPos, base.barrelPosition, s.barrelStartPos, s.barrelPosition))
                 {
                     this.Shing();
                     s.Shing();
                     s.owner.hSpeed += (float)this.offDir * 1f;
                     s.owner.vSpeed -= 1f;
                     rebound         = true;
                     this._hitWait   = 4;
                     this.hSpeed     = -this.hSpeed * 0.6f;
                 }
             }
             int waitFrames = 12;
             if (!rebound)
             {
                 foreach (Thing thing2 in Level.current.things[typeof(Chainsaw)])
                 {
                     Chainsaw s2 = (Chainsaw)thing2;
                     if (s2.owner != null && s2.throttle && Collision.LineIntersect(this.barrelStartPos, base.barrelPosition, s2.barrelStartPos, s2.barrelPosition))
                     {
                         this.Shing();
                         s2.Shing(this);
                         s2.owner.hSpeed += (float)this.offDir * 1f;
                         s2.owner.vSpeed -= 1f;
                         rebound          = true;
                         this.hSpeed      = -this.hSpeed * 0.6f;
                         this._hitWait    = 4;
                         if (Recorder.currentRecording != null)
                         {
                             Recorder.currentRecording.LogBonus();
                         }
                     }
                 }
                 if (!rebound)
                 {
                     Helmet helmetHit = Level.CheckLine <Helmet>(this.barrelStartPos, base.barrelPosition, null);
                     if (helmetHit != null && helmetHit.equippedDuck != null && (helmetHit.owner != base.prevOwner || (int)this._framesSinceThrown > waitFrames))
                     {
                         this.hSpeed = -this.hSpeed * 0.6f;
                         this.Shing();
                         rebound       = true;
                         this._hitWait = 4;
                     }
                     else
                     {
                         ChestPlate chestHit = Level.CheckLine <ChestPlate>(this.barrelStartPos, base.barrelPosition, null);
                         if (chestHit != null && chestHit.equippedDuck != null && (chestHit.owner != base.prevOwner || (int)this._framesSinceThrown > waitFrames))
                         {
                             this.hSpeed = -this.hSpeed * 0.6f;
                             this.Shing();
                             rebound       = true;
                             this._hitWait = 4;
                         }
                     }
                 }
             }
             if (!rebound && base.isServerForObject)
             {
                 foreach (IAmADuck d in Level.CheckLineAll <IAmADuck>(this.barrelStartPos, base.barrelPosition))
                 {
                     if (d != base.duck)
                     {
                         MaterialThing realThing = d as MaterialThing;
                         if (realThing != null && (realThing != base.prevOwner || (int)this._framesSinceThrown > waitFrames))
                         {
                             realThing.Destroy(new DTImpale(this));
                             if (Recorder.currentRecording != null)
                             {
                                 Recorder.currentRecording.LogBonus();
                             }
                         }
                     }
                 }
             }
         }
     }
     if (this.owner == null)
     {
         this._swinging     = false;
         this._jabStance    = false;
         this._crouchStance = false;
         this._pullBack     = false;
         this._swung        = false;
         this._shing        = false;
         this._swing        = 0f;
         this._swingPress   = false;
         this._slamStance   = false;
         this._unslam       = 0;
     }
     if (base.isServerForObject)
     {
         if (this._unslam > 1)
         {
             this._unslam--;
             this._slamStance = true;
         }
         else if (this._unslam == 1)
         {
             this._unslam     = 0;
             this._slamStance = false;
         }
         if (this._pullBack)
         {
             if (base.duck != null)
             {
                 if (this._jabStance)
                 {
                     this._pullBack = false;
                     this._swinging = true;
                 }
                 else
                 {
                     this._swinging = true;
                     this._pullBack = false;
                 }
             }
         }
         else if (this._swinging)
         {
             if (this._jabStance)
             {
                 this._addOffsetX = MathHelper.Lerp(this._addOffsetX, 3f, 0.4f);
                 if (this._addOffsetX > 2f && !this.action)
                 {
                     this._swinging = false;
                 }
             }
             else if (base.raised)
             {
                 this._swing = MathHelper.Lerp(this._swing, -2.8f, 0.2f);
                 if (this._swing < -2.4f && !this.action)
                 {
                     this._swinging = false;
                     this._swing    = 1.8f;
                 }
             }
             else
             {
                 this._swing = MathHelper.Lerp(this._swing, 2.1f, 0.4f);
                 if (this._swing > 1.8f && !this.action)
                 {
                     this._swinging = false;
                     this._swing    = 1.8f;
                 }
             }
         }
         else
         {
             if (!this._swinging && (!this._swingPress || this._shing || (this._jabStance && this._addOffsetX < 1f) || (!this._jabStance && this._swing < 1.6f)))
             {
                 if (this._jabStance)
                 {
                     this._swing = MathHelper.Lerp(this._swing, 1.75f, 0.4f);
                     if (this._swing > 1.55f)
                     {
                         this._swing = 1.55f;
                         this._shing = false;
                         this._swung = false;
                     }
                     this._addOffsetX = MathHelper.Lerp(this._addOffsetX, -12f, 0.45f);
                     if (this._addOffsetX < -12f)
                     {
                         this._addOffsetX = -12f;
                     }
                     this._addOffsetY = MathHelper.Lerp(this._addOffsetY, -4f, 0.35f);
                     if (this._addOffsetX < -3f)
                     {
                         this._addOffsetY = -3f;
                     }
                 }
                 else if (this._slamStance)
                 {
                     this._swing = MathHelper.Lerp(this._swing, 3.14f, 0.8f);
                     if (this._swing > 3.1f && this._unslam == 0)
                     {
                         this._swing = 3.14f;
                         this._shing = false;
                         this._swung = true;
                     }
                     this._addOffsetX = MathHelper.Lerp(this._addOffsetX, -5f, 0.45f);
                     if (this._addOffsetX < -4.6f)
                     {
                         this._addOffsetX = -5f;
                     }
                     this._addOffsetY = MathHelper.Lerp(this._addOffsetY, -6f, 0.35f);
                     if (this._addOffsetX < -5.5f)
                     {
                         this._addOffsetY = -6f;
                     }
                 }
                 else
                 {
                     this._swing      = MathHelper.Lerp(this._swing, -0.22f, 0.36f);
                     this._addOffsetX = MathHelper.Lerp(this._addOffsetX, 1f, 0.2f);
                     if (this._addOffsetX > 0f)
                     {
                         this._addOffsetX = 0f;
                     }
                     this._addOffsetY = MathHelper.Lerp(this._addOffsetY, 1f, 0.2f);
                     if (this._addOffsetY > 0f)
                     {
                         this._addOffsetY = 0f;
                     }
                 }
             }
             if ((this._swing < 0f || this._jabStance) && this._swing < 0f)
             {
                 this._swing = 0f;
                 this._shing = false;
                 this._swung = false;
             }
         }
     }
     if (base.duck != null)
     {
         this.collisionOffset = new Vec2(-4f, 0f);
         this.collisionSize   = new Vec2(4f, 4f);
         if (this._crouchStance && !this._jabStance)
         {
             this.collisionOffset = new Vec2(-2f, -19f);
             this.collisionSize   = new Vec2(4f, 16f);
             this.thickness       = 3f;
         }
         this._swingPress = false;
         if (!this._pullBack && !this._swinging)
         {
             this._crouchStance = false;
             this._jabStance    = false;
             if (base.duck.crouch)
             {
                 if (!this._pullBack && !this._swinging && base.duck.inputProfile.Down((this.offDir > 0) ? "LEFT" : "RIGHT"))
                 {
                     this._jabStance = true;
                 }
                 this._crouchStance = true;
             }
             if (!this._crouchStance || this._jabStance)
             {
                 this._slamStance = false;
             }
         }
         if (!this._crouchStance)
         {
             this._hold       = -0.4f;
             this.handOffset  = new Vec2(this._addOffsetX, this._addOffsetY);
             this._holdOffset = new Vec2(-4f + this._addOffsetX, 4f + this._addOffsetY);
         }
         else
         {
             this._hold       = 0f;
             this._holdOffset = new Vec2(0f + this._addOffsetX, 4f + this._addOffsetY);
             this.handOffset  = new Vec2(3f + this._addOffsetX, this._addOffsetY);
         }
     }
     else
     {
         this.collisionOffset = new Vec2(-2f, -16f);
         this.collisionSize   = new Vec2(4f, 18f);
         if (this._wasLifted)
         {
             this.collisionOffset = new Vec2(-4f, -2f);
             this.collisionSize   = new Vec2(8f, 4f);
         }
         this.thickness = 0f;
     }
     if ((this._swung || this._swinging) && !this._shing)
     {
         (this.Offset(base.barrelOffset) - this.position).Normalize();
         this.Offset(base.barrelOffset);
         IEnumerable <IAmADuck> hit2 = Level.CheckLineAll <IAmADuck>(this.barrelStartPos, base.barrelPosition);
         Block wallHit = Level.CheckLine <Block>(this.barrelStartPos, base.barrelPosition, null);
         if (wallHit != null && !this._slamStance)
         {
             if (this.offDir < 0 && wallHit.x > base.x)
             {
                 wallHit = null;
             }
             else if (this.offDir > 0 && wallHit.x < base.x)
             {
                 wallHit = null;
             }
         }
         bool clashed = false;
         if (wallHit != null)
         {
             this.Shing();
             if (this._slamStance)
             {
                 this._swung       = false;
                 this._unslam      = 20;
                 this.owner.vSpeed = -5f;
             }
             if (wallHit is Window)
             {
                 wallHit.Destroy(new DTImpact(this));
             }
         }
         else if (!this._jabStance && !this._slamStance)
         {
             Thing ignore = null;
             if (base.duck != null)
             {
                 ignore = base.duck.GetEquipment(typeof(Helmet));
             }
             Vec2            barrel   = base.barrelPosition + base.barrelVector * 3f;
             Vec2            p3       = new Vec2((this.position.x < barrel.x) ? this.position.x : barrel.x, (this.position.y < barrel.y) ? this.position.y : barrel.y);
             Vec2            p2       = new Vec2((this.position.x > barrel.x) ? this.position.x : barrel.x, (this.position.y > barrel.y) ? this.position.y : barrel.y);
             QuadLaserBullet laserHit = Level.CheckRect <QuadLaserBullet>(p3, p2, null);
             if (laserHit != null)
             {
                 this.Shing();
                 base.Fondle(laserHit);
                 laserHit.safeFrames = 8;
                 laserHit.safeDuck   = base.duck;
                 Vec2  travel = laserHit.travel;
                 float mag    = travel.length;
                 float mul    = 1f;
                 if (this.offDir > 0 && travel.x < 0f)
                 {
                     mul = 1.5f;
                 }
                 else if (this.offDir < 0 && travel.x > 0f)
                 {
                     mul = 1.5f;
                 }
                 if (this.offDir > 0)
                 {
                     travel = new Vec2(mag * mul, 0f);
                 }
                 else
                 {
                     travel = new Vec2(-mag * mul, 0f);
                 }
                 laserHit.travel = travel;
             }
             else
             {
                 Helmet helmetHit2 = Level.CheckLine <Helmet>(this.barrelStartPos, base.barrelPosition, ignore);
                 if (helmetHit2 != null && helmetHit2.equippedDuck != null)
                 {
                     this.Shing();
                     helmetHit2.owner.hSpeed     += (float)this.offDir * 3f;
                     helmetHit2.owner.vSpeed     -= 2f;
                     helmetHit2.duck.crippleTimer = 1f;
                     helmetHit2.Hurt(0.53f);
                     clashed = true;
                 }
                 else
                 {
                     if (base.duck != null)
                     {
                         ignore = base.duck.GetEquipment(typeof(ChestPlate));
                     }
                     ChestPlate chestHit2 = Level.CheckLine <ChestPlate>(this.barrelStartPos, base.barrelPosition, ignore);
                     if (chestHit2 != null && chestHit2.equippedDuck != null)
                     {
                         this.Shing();
                         chestHit2.owner.hSpeed     += (float)this.offDir * 3f;
                         chestHit2.owner.vSpeed     -= 2f;
                         chestHit2.duck.crippleTimer = 1f;
                         chestHit2.Hurt(0.53f);
                         clashed = true;
                     }
                 }
             }
         }
         if (!clashed)
         {
             foreach (Thing thing3 in Level.current.things[typeof(Sword)])
             {
                 Sword s3 = (Sword)thing3;
                 if (s3 != this && s3.duck != null && !this._jabStance && !s3._jabStance && base.duck != null && Collision.LineIntersect(this.barrelStartPos, base.barrelPosition, s3.barrelStartPos, s3.barrelPosition))
                 {
                     this.Shing();
                     s3.Shing();
                     s3.owner.hSpeed       += (float)this.offDir * 3f;
                     s3.owner.vSpeed       -= 2f;
                     base.duck.hSpeed      += -(float)this.offDir * 3f;
                     base.duck.vSpeed      -= 2f;
                     s3.duck.crippleTimer   = 1f;
                     base.duck.crippleTimer = 1f;
                     clashed = true;
                 }
             }
         }
         if (clashed)
         {
             return;
         }
         using (IEnumerator <IAmADuck> enumerator5 = hit2.GetEnumerator())
         {
             while (enumerator5.MoveNext())
             {
                 IAmADuck d2 = enumerator5.Current;
                 if (d2 != base.duck)
                 {
                     MaterialThing realThing2 = d2 as MaterialThing;
                     if (realThing2 != null)
                     {
                         realThing2.Destroy(new DTImpale(this));
                     }
                 }
             }
             return;
         }
     }
     if (this._crouchStance && base.duck != null)
     {
         foreach (IAmADuck d3 in Level.CheckLineAll <IAmADuck>(this.barrelStartPos, base.barrelPosition))
         {
             if (d3 != base.duck)
             {
                 MaterialThing realThing3 = d3 as MaterialThing;
                 if (realThing3 != null)
                 {
                     if (realThing3.vSpeed > 0.5f && realThing3.bottom < this.position.y - 8f && realThing3.left < base.barrelPosition.x && realThing3.right > base.barrelPosition.x)
                     {
                         realThing3.Destroy(new DTImpale(this));
                     }
                     else if (!this._jabStance && !realThing3.destroyed && ((this.offDir > 0 && realThing3.x > base.duck.x) || (this.offDir < 0 && realThing3.x < base.duck.x)))
                     {
                         if (realThing3 is Duck)
                         {
                             (realThing3 as Duck).crippleTimer = 1f;
                         }
                         else if ((base.duck.x > realThing3.x && realThing3.hSpeed > 1.5f) || (base.duck.x < realThing3.x && realThing3.hSpeed < -1.5f))
                         {
                             realThing3.Destroy(new DTImpale(this));
                         }
                         base.Fondle(realThing3);
                         realThing3.hSpeed = (float)this.offDir * 3f;
                         realThing3.vSpeed = -2f;
                     }
                 }
             }
         }
     }
 }