public NetIndex4(int index = 1, bool zeroSpecial = false) { this._index = index; this._zeroSpecial = zeroSpecial; this.max = NetIndex4.MaxForBits(4); if (this._zeroSpecial) { return; } ++this.max; }
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(); }