示例#1
0
 public void GiveThing(Holdable h)
 {
     this.holdObject       = h;
     this.holdObject.owner = (Thing)this;
     this.holdObject.solid = false;
 }
示例#2
0
 private void BreakHoverBond()
 {
     this._hoverItem.gravMultiplier = 1f;
     this._hoverItem = (Holdable)null;
 }
示例#3
0
 public override void Update()
 {
     if ((double)this.hitWait > 0.0)
     {
         this.hitWait -= 0.1f;
     }
     else
     {
         this.hitWait = 0.0f;
     }
     this._alternate                = !this._alternate;
     this._scanner.alpha            = (float)(0.400000005960464 + (double)this._wave.normalized * 0.600000023841858);
     this._projector.alpha          = (float)(0.400000005960464 + (double)this._wave.normalized * 0.600000023841858) * this._projectorAlpha;
     this._currentProjection.alpha  = (float)(0.400000005960464 + (double)this._projectionFlashWave.normalized * 0.600000023841858);
     this._currentProjection.alpha -= this._glitch * 3f;
     this._currentProjection.alpha *= this._projectorAlpha;
     this._double = Maths.CountDown(this._double, 0.15f);
     this._glitch = Maths.CountDown(this._glitch, 0.1f);
     if ((double)Rando.Float(1f) < 0.00999999977648258)
     {
         this._glitch = 0.3f;
         this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
         this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
         this._projectorGlitch.flipH  = (double)Rando.Float(1f) > 0.5;
     }
     if ((double)Rando.Float(1f) < 0.00499999988824129)
     {
         this._glitch = 0.3f;
         this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
         this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
         this._projectorGlitch.flipH  = (double)Rando.Float(1f) > 0.5;
         this._useWave = !this._useWave;
     }
     if ((double)Rando.Float(1f) < 0.00800000037997961)
     {
         this._glitch = 0.3f;
         this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
         this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
         this._projectorGlitch.flipH  = (double)Rando.Float(1f) > 0.5;
         this._useWave = !this._useWave;
         this._double  = 0.6f + Rando.Float(0.6f);
     }
     this._close.Clear();
     if (this._hoverItem != null && this._hoverItem.owner != null)
     {
         this.BreakHoverBond();
     }
     if (this._hoverItem == null)
     {
         Holdable holdable = Level.Nearest <Holdable>(this.x, this.y);
         if (holdable != null && holdable.owner == null && (holdable != null && holdable.canPickUp) && ((double)holdable.bottom <= (double)this.top && (double)Math.Abs(holdable.hSpeed) + (double)Math.Abs(holdable.vSpeed) < 2.0))
         {
             float num = 999f;
             if (holdable != null)
             {
                 num = (this.position - holdable.position).length;
             }
             if ((double)num < 24.0)
             {
                 this._hoverItem = holdable;
             }
         }
     }
     else if ((double)Math.Abs(this._hoverItem.hSpeed) + (double)Math.Abs(this._hoverItem.vSpeed) > 2.0 || (double)(this._hoverItem.position - this.position).length > 25.0)
     {
         this.BreakHoverBond();
     }
     else
     {
         this._hoverItem.position       = Lerp.Vec2Smooth(this._hoverItem.position, this.position + new Vec2(0.0f, (float)(-12.0 - (double)this._hoverItem.collisionSize.y / 2.0 + (double)(float)this._projectionWave * 2.0)), 0.2f);
         this._hoverItem.vSpeed         = 0.0f;
         this._hoverItem.gravMultiplier = 0.0f;
     }
     foreach (Duck duck in this._level.things[typeof(Duck)])
     {
         if (!duck.dead && (double)(duck.position - this.position).length < 64.0)
         {
             this._close.Add(duck.profile);
             this._closeGlitch = false;
         }
     }
     this._closeWait = Maths.CountDown(this._closeWait, 0.05f);
     for (int index = 0; index < this._close.Count; ++index)
     {
         if (this._close.Count == 1)
         {
             this._closeIndex = 0;
         }
         else if (this._close.Count > 1 && index == this._closeIndex && (double)this._closeWait <= 0.0)
         {
             this._closeIndex             = (this._closeIndex + 1) % this._close.Count;
             this._closeWait              = 1f;
             this._glitch                 = 0.3f;
             this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
             this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
             this._projectorGlitch.flipH  = (double)Rando.Float(1f) > 0.5;
             this._useWave                = !this._useWave;
             this._double                 = 0.6f + Rando.Float(0.6f);
             break;
         }
     }
     if (this._closeIndex >= this._close.Count)
     {
         this._closeIndex = 0;
     }
     if (this._close.Count == 0)
     {
         if (!this._closeGlitch)
         {
             this._closeWait = 1f;
             this._glitch    = 0.3f;
             this._projectorGlitch.xscale = 0.8f + Rando.Float(0.7f);
             this._projectorGlitch.yscale = 0.6f + Rando.Float(0.5f);
             this._projectorGlitch.flipH  = (double)Rando.Float(1f) > 0.5;
             this._useWave     = !this._useWave;
             this._double      = 0.6f + Rando.Float(0.6f);
             this._closeGlitch = true;
         }
         this._projectorAlpha    = Maths.CountDown(this._projectorAlpha, 0.1f);
         this._currentProjection = this._none;
     }
     else
     {
         StoredItem storedItem = PurpleBlock.GetStoredItem(this._close[this._closeIndex]);
         this._currentProjection = storedItem.sprite != null ? (!this._served.Contains(this._close[this._closeIndex]) ? storedItem.sprite : (this._alternate ? storedItem.sprite : this._none)) : this._none;
         this._projectorAlpha    = Maths.CountUp(this._projectorAlpha, 0.1f);
     }
     this._projectorGlitch.alpha = this._glitch * this._projectorAlpha;
     base.Update();
 }
示例#4
0
        public override void Update()
        {
            this._waveMult = Lerp.Float(this._waveMult, 0.0f, 0.1f);
            if (this.isServerForObject)
            {
                this._magnetActive = this.action;
            }
            else if (this._magnetActive)
            {
                this._waveMult = 1f;
            }
            if ((double)this._beamSound.Volume > 0.00999999977648258 && this._beamSound.State != SoundState.Playing)
            {
                this._beamSound.Play();
            }
            else if ((double)this._beamSound.Volume < 0.00999999977648258 && this._beamSound.State == SoundState.Playing)
            {
                this._beamSound.Stop();
            }
            this._beamSound.Volume = Maths.LerpTowards(this._beamSound.Volume, this._magnetActive ? 0.1f : 0.0f, 0.1f);
            Vec2 p1_1 = this.Offset(this.barrelOffset);

            if (this._magnetActive && this.duck != null && this.duck.holdObject == this)
            {
                foreach (MagnaLine line in this._lines)
                {
                    line.Update();
                    line.show = true;
                    float num = this._ammoType.range;
                    if (this._hasRay)
                    {
                        num = (this.barrelPosition - this._rayHit).length;
                    }
                    line.dist = num;
                }
                if (this._grabbed == null && this._stuck == null)
                {
                    Holdable holdable1   = (Holdable)null;
                    float    val1        = 0.0f;
                    Vec2     normalized1 = this.barrelVector.Rotate(Maths.DegToRad(90f), Vec2.Zero).normalized;
                    for (int index = 0; index < 3; ++index)
                    {
                        Vec2 p1_2 = p1_1;
                        if (index == 0)
                        {
                            p1_2 += normalized1 * 8f;
                        }
                        else if (index == 2)
                        {
                            p1_2 -= normalized1 * 8f;
                        }
                        foreach (Holdable holdable2 in Level.CheckLineAll <Holdable>(p1_2, p1_2 + this.barrelVector * this._ammoType.range))
                        {
                            if (holdable2 != this && holdable2 != this.owner && (holdable2.owner != this.owner && holdable2.physicsMaterial == PhysicsMaterial.Metal) && (holdable2.duck == null || !(holdable2.duck.holdObject is MagnetGun)))
                            {
                                float length = (holdable2.position - p1_1).length;
                                if (holdable1 == null || (double)length < (double)val1)
                                {
                                    val1      = length;
                                    holdable1 = holdable2;
                                }
                            }
                        }
                    }
                    this._hasRay = false;
                    if (holdable1 != null && Level.CheckLine <Block>(p1_1, holdable1.position) == null)
                    {
                        float num = (float)((1.0 - (double)Math.Min(val1, this._ammoType.range) / (double)this._ammoType.range) * 0.800000011920929);
                        if (holdable1.owner is Duck duck && !(duck.holdObject is MagnetGun) && (double)num > 0.300000011920929)
                        {
                            if (!(holdable1 is Equipment) || holdable1.equippedDuck == null)
                            {
                                duck.ThrowItem(false);
                                duck = (Duck)null;
                            }
                            else if (holdable1 is TinfoilHat)
                            {
                                duck.Unequip(holdable1 as Equipment);
                                duck = (Duck)null;
                            }
                        }
                        Vec2 normalized2 = (p1_1 - holdable1.position).normalized;
                        // TODO if (duck != null && holdable1 is Equipment)
                        if (false)
                        {
                            if (duck.ragdoll != null)
                            {
                                duck.ragdoll.makeActive = true;
                                return;
                            }
                            if (!(holdable1.owner.realObject is Duck) && Network.isActive)
                            {
                                return;
                            }
                            holdable1.owner.realObject.hSpeed += normalized2.x * num;
                            holdable1.owner.realObject.vSpeed += (float)((double)normalized2.y * (double)num * 4.0);
                            if ((holdable1.owner.realObject as PhysicsObject).grounded && (double)holdable1.owner.realObject.vSpeed > 0.0)
                            {
                                holdable1.owner.realObject.vSpeed = 0.0f;
                            }
                        }
                        else
                        {
                            this.Fondle((Thing)holdable1);
                            holdable1.hSpeed += normalized2.x * num;
                            holdable1.vSpeed += (float)((double)normalized2.y * (double)num * 4.0);
                            if (holdable1.grounded && (double)holdable1.vSpeed > 0.0)
                            {
                                holdable1.vSpeed = 0.0f;
                            }
                        }
                        this._hasRay = true;
                        this._rayHit = holdable1.position;
                        if (this.isServerForObject && (double)val1 < 20.0)
                        {
                            if (holdable1 is Equipment && holdable1.duck != null)
                            {
                                this._grabbed = holdable1.owner.realObject;
                                holdable1.duck.immobilized = true;
                                holdable1.duck.gripped     = true;
                                holdable1.duck.ThrowItem();
                                if (!(holdable1.owner.realObject is Duck))
                                {
                                    holdable1.owner.realObject.owner = this.owner;
                                    Thing.SuperFondle(holdable1.owner.realObject, DuckNetwork.localConnection);
                                }
                            }
                            else
                            {
                                this._grabbed   = (Thing)holdable1;
                                holdable1.owner = this.owner;
                                if (holdable1 is Grenade)
                                {
                                    (holdable1 as Grenade).OnPressAction();
                                }
                            }
                            this.attachIndex += 1;
                        }
                    }
                    else if (this.isServerForObject && this._stuck == null && ((double)Math.Abs(this.angle) < 0.0500000007450581 || (double)Math.Abs(this.angle) > 1.5))
                    {
                        Vec2 position = this.owner.position;
                        if (this.duck.sliding)
                        {
                            position.y += 4f;
                        }
                        Vec2  hitPos;
                        Block block = Level.CheckRay <Block>(position, position + this.barrelVector * this._ammoType.range, out hitPos);
                        this._hasRay = true;
                        this._rayHit = hitPos;
                        if (block != null && block.physicsMaterial == PhysicsMaterial.Metal)
                        {
                            float num    = (float)((1.0 - (double)Math.Min((block.position - position).length, this._ammoType.range) / (double)this._ammoType.range) * 0.800000011920929);
                            Vec2  vec2   = hitPos - this.duck.position;
                            float length = vec2.length;
                            vec2.Normalize();
                            this.owner.hSpeed += vec2.x * num;
                            this.owner.vSpeed += vec2.y * num;
                            if ((double)length < 20.0)
                            {
                                this._stuck       = block;
                                this._stickPos    = hitPos;
                                this._stickNormal = -this.barrelVector;
                                this.attachIndex += 1;
                            }
                        }
                    }
                }
            }
            else
            {
                if (this.isServerForObject)
                {
                    if (this._grabbed != null)
                    {
                        this._grabbed.angle = 0.0f;
                        if (this._grabbed is Holdable grabbed)
                        {
                            grabbed.owner = (Thing)null;
                            grabbed.ReturnToWorld();
                            this.ReturnItemToWorld((Thing)grabbed);
                        }
                        if (this._grabbed is Duck grabbed2)
                        {
                            grabbed2.immobilized  = false;
                            grabbed2.gripped      = false;
                            grabbed2.crippleTimer = 1f;
                        }
                        this._grabbed.visible       = true;
                        this._grabbed.enablePhysics = true;
                        this._grabbed.hSpeed        = this.barrelVector.x * 5f;
                        this._grabbed.vSpeed        = this.barrelVector.y * 5f;
                        this._grabbed       = (Thing)null;
                        this._collisionSize = new Vec2(14f, this._collisionSize.y);
                    }
                    if (this._stuck != null)
                    {
                        this._stuck = (Block)null;
                        if (this.owner != null && !this._raised)
                        {
                            this.duck._groundValid = 6;
                        }
                    }
                }
                foreach (MagnaLine line in this._lines)
                {
                    line.show = false;
                }
            }
            if (Network.isActive)
            {
                if (this._grabbed != null)
                {
                    if (this._grabbed is TrappedDuck && this._grabbed.connection != this.connection)
                    {
                        this._grabbed = (Thing)(this._grabbed as TrappedDuck)._duckOwner;
                        if (this._grabbed != null)
                        {
                            Duck grabbed2 = this._grabbed as Duck;
                            grabbed2.immobilized = true;
                            grabbed2.gripped     = true;
                            grabbed2.ThrowItem();
                            grabbed2._trapped = (TrappedDuck)null;
                        }
                    }
                    if (this._grabbed is Duck grabbed)
                    {
                        grabbed.isGrabbedByMagnet = true;
                        if (this.isServerForObject)
                        {
                            this.Fondle((Thing)grabbed);
                            this.Fondle((Thing)grabbed.holdObject);
                            foreach (Thing t in grabbed._equipment)
                            {
                                this.Fondle(t);
                            }
                            this.Fondle((Thing)grabbed._ragdollInstance);
                            this.Fondle((Thing)grabbed._trappedInstance);
                            this.Fondle((Thing)grabbed._cookedInstance);
                        }
                    }
                }
                if (this._grabbed == null && this._prevGrabDuck != null && this._prevGrabDuck is Duck)
                {
                    (this._prevGrabDuck as Duck).isGrabbedByMagnet = false;
                }
                this._prevGrabDuck = this._grabbed;
            }
            if (this._grabbed != null && this.owner != null)
            {
                if (this.isServerForObject)
                {
                    this.Fondle(this._grabbed);
                }
                this._grabbed.hSpeed        = this.owner.hSpeed;
                this._grabbed.vSpeed        = this.owner.vSpeed;
                this._grabbed.angle         = this.angle;
                this._grabbed.visible       = false;
                this._grabbed.offDir        = this.offDir;
                this._grabbed.enablePhysics = false;
                this._collisionSize         = new Vec2(16f + this._grabbed.width, this._collisionSize.y);
                if (this._grabbed is Duck grabbed)
                {
                    grabbed.grounded = true;
                    grabbed.sliding  = false;
                    grabbed.crouch   = false;
                }
                else
                {
                    this._grabbed.owner = (Thing)this;
                }
            }
            if (this.localAttachIndex < this.attachIndex)
            {
                for (int index = 0; index < 2; ++index)
                {
                    Level.Add((Thing)SmallSmoke.New(p1_1.x + Rando.Float(-1f, 1f), p1_1.y + Rando.Float(-1f, 1f)));
                }
                SFX.Play("grappleHook");
                for (int index = 0; index < 6; ++index)
                {
                    Level.Add((Thing)Spark.New(p1_1.x - this.barrelVector.x * 2f + Rando.Float(-1f, 1f), p1_1.y - this.barrelVector.y * 2f + Rando.Float(-1f, 1f), this.barrelVector + new Vec2(Rando.Float(-1f, 1f), Rando.Float(-1f, 1f))));
                }
                this.localAttachIndex = this.attachIndex;
            }
            if (this.isServerForObject)
            {
                if (this._magnetActive && this._raised && (this.duck != null && !this.duck.grounded) && this._grabbed == null)
                {
                    this._keepRaised = true;
                }
                else
                {
                    this._keepRaised = false;
                }
                if (this._stuck != null && this.duck != null)
                {
                    if ((double)this._stickPos.y < (double)this.owner.position.y - 8.0)
                    {
                        this.owner.position = this._stickPos + this._stickNormal * 12f;
                        this._raised        = true;
                        this._keepRaised    = true;
                    }
                    else
                    {
                        this.owner.position = this._stickPos + this._stickNormal * 16f;
                        this._raised        = false;
                        this._keepRaised    = false;
                    }
                    this.owner.hSpeed  = this.owner.vSpeed = 0.0f;
                    this.duck.moveLock = true;
                }
                else if (this._stuck == null && this.duck != null)
                {
                    this.duck.moveLock = false;
                }
                if (this.owner == null && this.prevOwner != null)
                {
                    if (this.prevOwner is Duck prevOwner)
                    {
                        prevOwner.moveLock = false;
                    }
                    this._prevOwner = (Thing)null;
                }
            }
            base.Update();
        }