Exemplo n.º 1
0
 public void LodgeInCreature(SharedPhysics.CollisionResult result, bool eu)
 {
     stuckInObject = result.obj;
     ChangeMode(Mode.StuckInCreature);
     if (result.chunk != null)
     {
         stuckInChunkIndex = result.chunk.index;
         if (arrowDamageBonus > 0.9f && room.GetTile(room.GetTilePosition(stuckInChunk.pos) + throwDir).Terrain == Room.Tile.TerrainType.Solid && room.GetTile(stuckInChunk.pos).Terrain == Room.Tile.TerrainType.Air)
         {
             stuckInWall = room.MiddleOfTile(stuckInChunk.pos) + throwDir.ToVector2() * (10f - stuckInChunk.rad);
             stuckInChunk.MoveFromOutsideMyUpdate(eu, stuckInWall.Value);
             stuckRotation    = Custom.VecToDeg(rotation);
             stuckBodyPart    = -1;
             pinToWallCounter = 300;
         }
         else if (stuckBodyPart == -1)
         {
             stuckRotation = Custom.Angle(throwDir.ToVector2(), stuckInChunk.Rotation);
         }
         base.firstChunk.MoveWithOtherObject(eu, stuckInChunk, new Vector2(0f, 0f));
         Debug.Log("Add arrow to creature chunk " + stuckInChunk.index);
         new AbstractPhysicalObject.AbstractSpearStick(abstractPhysicalObject, (result.obj as Creature).abstractCreature, stuckInChunkIndex, stuckBodyPart, stuckRotation);
     }
     else if (result.onAppendagePos != null)
     {
         stuckInChunkIndex = 0;
         stuckInAppendage  = result.onAppendagePos;
         stuckRotation     = Custom.VecToDeg(rotation) - Custom.VecToDeg(stuckInAppendage.appendage.OnAppendageDirection(stuckInAppendage));
         Debug.Log("Add arrow to creature Appendage");
         new AbstractPhysicalObject.AbstractSpearAppendageStick(abstractPhysicalObject, (result.obj as Creature).abstractCreature, result.onAppendagePos.appendage.appIndex, result.onAppendagePos.prevSegment, result.onAppendagePos.distanceToNext, stuckRotation);
     }
     if (room.BeingViewed)
     {
         for (int i = 0; i < 8; i++)
         {
             room.AddObject(new WaterDrip(result.collisionPoint, -base.firstChunk.vel * Random.value * 0.5f + Custom.DegToVec(360f * Random.value) * base.firstChunk.vel.magnitude * Random.value * 0.5f, waterColor: false));
         }
     }
 }
Exemplo n.º 2
0
        public bool NetHit(PhysicalObject hit, BodyChunk chunk)
        {
            if (hit == null)
            {
                return(false);
            }
            bool flag = false;

            if (this.abstractPhysicalObject.world.game.IsArenaSession && this.abstractPhysicalObject.world.game.GetArenaGameSession.GameTypeSetup.spearHitScore != 0 && this.thrownBy != null && this.thrownBy is Player && hit is Creature)
            {
                flag = true;
                if ((hit as Creature).State is HealthState && ((hit as Creature).State as HealthState).health <= 0f)
                {
                    flag = false;
                }
                else if (!((hit as Creature).State is HealthState) && (hit as Creature).State.dead)
                {
                    flag = false;
                }
            }
            if (hit is Creature)
            {
                (hit as Creature).Violence(base.firstChunk, new Vector2?(base.firstChunk.vel * base.firstChunk.mass * 2f), chunk, null, Creature.DamageType.Stab, this.spearDamageBonus, 20f);
            }
            else if (chunk != null)
            {
                chunk.vel += this.firstChunk.vel * this.firstChunk.mass / chunk.mass;
            }
            if (hit is Creature && (hit as Creature).SpearStick(this, Mathf.Lerp(0.55f, 0.62f, UnityEngine.Random.value), chunk, null, base.firstChunk.vel))
            {
                this.room.PlaySound(SoundID.Spear_Stick_In_Creature, base.firstChunk);
                this.stuckInObject = hit;
                this.ChangeMode(Weapon.Mode.StuckInCreature);
                if (chunk != null)
                {
                    this.stuckInChunkIndex = chunk.index;
                    if (this.spearDamageBonus > 0.9f && this.room.GetTile(this.room.GetTilePosition(this.stuckInChunk.pos) + this.throwDir).Terrain == Room.Tile.TerrainType.Solid && this.room.GetTile(this.stuckInChunk.pos).Terrain == Room.Tile.TerrainType.Air)
                    {
                        this.stuckInWall      = new Vector2?(this.room.MiddleOfTile(this.stuckInChunk.pos) + this.throwDir.ToVector2() * (10f - this.stuckInChunk.rad));
                        this.stuckRotation    = Custom.VecToDeg(this.rotation);
                        this.stuckBodyPart    = -1;
                        this.pinToWallCounter = 300;
                    }
                    else if (this.stuckBodyPart == -1)
                    {
                        this.stuckRotation = Custom.Angle(this.throwDir.ToVector2(), this.stuckInChunk.Rotation);
                    }
                    new AbstractPhysicalObject.AbstractSpearStick(this.abstractPhysicalObject, (hit as Creature).abstractCreature, this.stuckInChunkIndex, this.stuckBodyPart, this.stuckRotation);
                }
                if (flag)
                {
                    this.abstractPhysicalObject.world.game.GetArenaGameSession.PlayerLandSpear(this.thrownBy as Player, this.stuckInObject as Creature);
                }
                return(true);
            }
            this.room.PlaySound(SoundID.Spear_Bounce_Off_Creauture_Shell, base.firstChunk);
            this.vibrate = 20;
            this.ChangeMode(Weapon.Mode.Free);
            base.firstChunk.vel = base.firstChunk.vel * -0.5f + Custom.DegToVec(UnityEngine.Random.value * 360f) * Mathf.Lerp(0.1f, 0.4f, UnityEngine.Random.value) * base.firstChunk.vel.magnitude;
            this.SetRandomSpin();
            return(false);
        }
Exemplo n.º 3
0
        public override void Update(bool eu)
        {
            base.Update(eu);
            soundLoop.sound = SoundID.None;
            if (base.firstChunk.vel.magnitude > 5f)
            {
                if (base.mode == Mode.Thrown)
                {
                    soundLoop.sound = SoundID.Spear_Thrown_Through_Air_LOOP;
                }
                else if (base.mode == Mode.Free)
                {
                    soundLoop.sound = SoundID.Spear_Spinning_Through_Air_LOOP;
                }
                soundLoop.Volume = Mathf.InverseLerp(5f, 15f, base.firstChunk.vel.magnitude);
            }
            soundLoop.Update();

            lastPivotAtTip = pivotAtTip;
            pivotAtTip     = base.mode == Mode.Thrown || base.mode == Mode.StuckInCreature;



            if (addPoles && room.readyForAI)
            {
                if (abstractArrow.stuckInWallCycles >= 0)
                {
                    room.GetTile(stuckInWall.Value).horizontalBeam = true;
                    for (int i = -1; i < 2; i += 2)
                    {
                        if (!room.GetTile(stuckInWall.Value + new Vector2(20f * (float)i, 0f)).Solid)
                        {
                            room.GetTile(stuckInWall.Value + new Vector2(20f * (float)i, 0f)).horizontalBeam = true;
                        }
                    }
                }
                else
                {
                    room.GetTile(stuckInWall.Value).verticalBeam = true;
                    for (int j = -1; j < 2; j += 2)
                    {
                        if (!room.GetTile(stuckInWall.Value + new Vector2(0f, 20f * (float)j)).Solid)
                        {
                            room.GetTile(stuckInWall.Value + new Vector2(0f, 20f * (float)j)).verticalBeam = true;
                        }
                    }
                }
                addPoles = false;
            }

            switch (base.mode)
            {
            case Mode.Free:
                if (spinning)
                {
                    if (Custom.DistLess(base.firstChunk.pos, base.firstChunk.lastPos, 4f * room.gravity))
                    {
                        stillCounter++;
                    }
                    else
                    {
                        stillCounter = 0;
                    }
                    if (base.firstChunk.ContactPoint.y < 0 || stillCounter > 20)
                    {
                        spinning             = false;
                        rotationSpeed        = 0f;
                        rotation             = Custom.DegToVec(Mathf.Lerp(-45, 45f, Random.value) + 180f);
                        base.firstChunk.vel *= 0f;
                        room.PlaySound(SoundID.Spear_Stick_In_Ground, base.firstChunk);
                    }
                }
                else if (!Custom.DistLess(base.firstChunk.lastPos, base.firstChunk.pos, 6f))
                {
                    SetRandomSpin();
                }
                break;

            case Mode.Thrown:
            {
                base.rotation = firstChunk.vel.normalized;
                if (!Custom.DistLess(thrownPos, base.firstChunk.pos, 560f * Mathf.Max(1f, arrowDamageBonus)) || !(base.firstChunk.ContactPoint == throwDir) || room.GetTile(base.firstChunk.pos).Terrain != 0 || room.GetTile(base.firstChunk.pos + throwDir.ToVector2() * 20f).Terrain != Room.Tile.TerrainType.Solid || ((!Custom.DistLess(thrownPos, base.firstChunk.pos, 140f) && !alwaysStickInWalls)))
                {
                    break;
                }

                bool willStickIntoWall = true;

                foreach (AbstractWorldEntity entity in room.abstractRoom.entities)
                {
                    if (entity is AbstractArrow && (entity as AbstractArrow).realizedObject != null && ((entity as AbstractArrow).realizedObject as Weapon).mode == Mode.StuckInWall && entity.pos.Tile == abstractPhysicalObject.pos.Tile)
                    {
                        willStickIntoWall = false;
                        break;
                    }
                }

                if (willStickIntoWall)
                {
                    for (int k = 0; k < room.roomSettings.placedObjects.Count; k++)
                    {
                        if (room.roomSettings.placedObjects[k].type == PlacedObject.Type.NoSpearStickZone && Custom.DistLess(room.MiddleOfTile(base.firstChunk.pos), room.roomSettings.placedObjects[k].pos, (room.roomSettings.placedObjects[k].data as PlacedObject.ResizableObjectData).Rad))
                        {
                            willStickIntoWall = false;
                            break;
                        }
                    }
                }

                if (willStickIntoWall)
                {
                    stuckInWall = room.MiddleOfTile(base.firstChunk.pos);
                    vibrate     = 10;
                    rotation    = lastRotation;
                    ChangeMode(Mode.StuckInWall);
                    room.PlaySound(SoundID.Spear_Stick_In_Wall, base.firstChunk);
                    base.firstChunk.collideWithTerrain = false;
                }
                break;
            }

            case Mode.StuckInCreature:
                if (!stuckInWall.HasValue)
                {
                    if (stuckInAppendage != null)
                    {
                        setRotation         = Custom.DegToVec(stuckRotation + Custom.VecToDeg(stuckInAppendage.appendage.OnAppendageDirection(stuckInAppendage)));
                        base.firstChunk.pos = stuckInAppendage.appendage.OnAppendagePosition(stuckInAppendage);
                    }
                    else
                    {
                        base.firstChunk.vel = stuckInChunk.vel;
                        if (stuckBodyPart == -1 || !room.BeingViewed || (stuckInChunk.owner as Creature).BodyPartByIndex(stuckBodyPart) == null)
                        {
                            setRotation = Custom.DegToVec(stuckRotation + Custom.VecToDeg(stuckInChunk.Rotation));
                            base.firstChunk.MoveWithOtherObject(eu, stuckInChunk, new Vector2(0f, 0f));
                        }
                        else
                        {
                            setRotation = Custom.DegToVec(stuckRotation + Custom.AimFromOneVectorToAnother(stuckInChunk.pos, (stuckInChunk.owner as Creature).BodyPartByIndex(stuckBodyPart).pos));
                            base.firstChunk.MoveWithOtherObject(eu, stuckInChunk, Vector2.Lerp(stuckInChunk.pos, (stuckInChunk.owner as Creature).BodyPartByIndex(stuckBodyPart).pos, 0.5f) - stuckInChunk.pos);
                        }
                    }
                }
                else
                {
                    if (pinToWallCounter > 0)
                    {
                        pinToWallCounter--;
                    }
                    if (stuckInChunk.vel.magnitude * stuckInChunk.mass > Custom.LerpMap(pinToWallCounter, 160f, 0f, 7f, 2f))
                    {
                        setRotation = (Custom.DegToVec(stuckRotation) + Vector2.ClampMagnitude(stuckInChunk.vel * stuckInChunk.mass * 0.005f, 0.1f)).normalized;
                    }
                    else
                    {
                        setRotation = Custom.DegToVec(stuckRotation);
                    }
                    base.firstChunk.vel *= 0f;
                    base.firstChunk.pos  = stuckInWall.Value;
                    if ((stuckInChunk.owner is Creature && (stuckInChunk.owner as Creature).enteringShortCut.HasValue) || (pinToWallCounter < 160 && Random.value < 0.025f && stuckInChunk.vel.magnitude > Custom.LerpMap(pinToWallCounter, 160f, 0f, 140f, 30f / (1f + stuckInChunk.owner.TotalMass * 0.2f))))
                    {
                        stuckRotation = Custom.Angle(setRotation.Value, stuckInChunk.Rotation);
                        stuckInWall   = null;
                    }
                    else
                    {
                        stuckInChunk.MoveFromOutsideMyUpdate(eu, stuckInWall.Value);
                        stuckInChunk.vel *= 0f;
                    }
                }
                if (stuckInChunk.owner.slatedForDeletetion)
                {
                    ChangeMode(Mode.Free);
                }
                break;

            case Mode.StuckInWall:
                base.firstChunk.pos  = stuckInWall.Value;
                base.firstChunk.vel *= 0f;
                break;
            }

            for (int i = abstractPhysicalObject.stuckObjects.Count - 1; i >= 0; i--)
            {
                if (abstractPhysicalObject.stuckObjects[i] is AbstractPhysicalObject.ImpaledOnSpearStick)
                {
                    if (abstractPhysicalObject.stuckObjects[i].B.realizedObject != null && (abstractPhysicalObject.stuckObjects[i].B.realizedObject.slatedForDeletetion || abstractPhysicalObject.stuckObjects[i].B.realizedObject.grabbedBy.Count > 0))
                    {
                        abstractPhysicalObject.stuckObjects[i].Deactivate();
                    }
                    else if (abstractPhysicalObject.stuckObjects[i].B.realizedObject != null && abstractPhysicalObject.stuckObjects[i].B.realizedObject.room == room)
                    {
                        abstractPhysicalObject.stuckObjects[i].B.realizedObject.firstChunk.MoveFromOutsideMyUpdate(eu, base.firstChunk.pos + rotation * Custom.LerpMap((abstractPhysicalObject.stuckObjects[i] as AbstractPhysicalObject.ImpaledOnSpearStick).onSpearPosition, 0f, 4f, 15f, -15f));
                        abstractPhysicalObject.stuckObjects[i].B.realizedObject.firstChunk.vel *= 0f;
                    }
                }
            }
        }