GetPortalOutingPoint() private static method

private static GetPortalOutingPoint ( Vector2 objectSize, Vector2 portalPosition, float portalAngle, int &bonusX, int &bonusY ) : Vector2
objectSize Vector2
portalPosition Vector2
portalAngle float
bonusX int
bonusY int
return Vector2
コード例 #1
0
        public static void TryGoingThroughPortals(Entity ent)
        {
            float   collisionPoint = 0.0f;
            Vector2 velocity       = ent.velocity;
            int     width          = ent.width;
            int     height         = ent.height;
            int     gravDir        = 1;

            if (ent is Player)
            {
                gravDir = (int)((Player)ent).gravDir;
            }
            for (int index1 = 0; index1 < PortalHelper.FoundPortals.GetLength(0); ++index1)
            {
                if (PortalHelper.FoundPortals[index1, 0] != -1 && PortalHelper.FoundPortals[index1, 1] != -1 && (!(ent is Player) || index1 < PortalHelper.PortalCooldownForPlayers.Length && PortalHelper.PortalCooldownForPlayers[index1] <= 0) && (!(ent is NPC) || index1 < PortalHelper.PortalCooldownForNPCs.Length && PortalHelper.PortalCooldownForNPCs[index1] <= 0))
                {
                    for (int index2 = 0; index2 < 2; ++index2)
                    {
                        Projectile projectile1 = Main.projectile[PortalHelper.FoundPortals[index1, index2]];
                        Vector2    start;
                        Vector2    end;
                        PortalHelper.GetPortalEdges(projectile1.Center, projectile1.ai[0], out start, out end);
                        if (Collision.CheckAABBvLineCollision(ent.position + ent.velocity, ent.Size, start, end, 2f, ref collisionPoint))
                        {
                            Projectile projectile2 = Main.projectile[PortalHelper.FoundPortals[index1, 1 - index2]];
                            float      num1        = ent.Hitbox.Distance(projectile1.Center);
                            int        bonusX;
                            int        bonusY;
                            Vector2    newPos    = PortalHelper.GetPortalOutingPoint(ent.Size, projectile2.Center, projectile2.ai[0], out bonusX, out bonusY) + Vector2.Normalize(new Vector2((float)bonusX, (float)bonusY)) * num1;
                            Vector2    Velocity1 = Vector2.UnitX * 16f;
                            if (!(Collision.TileCollision(newPos - Velocity1, Velocity1, width, height, true, true, gravDir) != Velocity1))
                            {
                                Vector2 Velocity2 = -Vector2.UnitX * 16f;
                                if (!(Collision.TileCollision(newPos - Velocity2, Velocity2, width, height, true, true, gravDir) != Velocity2))
                                {
                                    Vector2 Velocity3 = Vector2.UnitY * 16f;
                                    if (!(Collision.TileCollision(newPos - Velocity3, Velocity3, width, height, true, true, gravDir) != Velocity3))
                                    {
                                        Vector2 Velocity4 = -Vector2.UnitY * 16f;
                                        if (!(Collision.TileCollision(newPos - Velocity4, Velocity4, width, height, true, true, gravDir) != Velocity4))
                                        {
                                            float num2 = 0.1f;
                                            if (bonusY == -gravDir)
                                            {
                                                num2 = 0.1f;
                                            }
                                            if (ent.velocity == Vector2.Zero)
                                            {
                                                ent.velocity = (projectile1.ai[0] - 1.570796f).ToRotationVector2() * num2;
                                            }
                                            if ((double)ent.velocity.Length() < (double)num2)
                                            {
                                                ent.velocity.Normalize();
                                                ent.velocity *= num2;
                                            }
                                            Vector2 vec = Vector2.Normalize(new Vector2((float)bonusX, (float)bonusY));
                                            if (vec.HasNaNs() || vec == Vector2.Zero)
                                            {
                                                vec = Vector2.UnitX * (float)ent.direction;
                                            }
                                            ent.velocity = vec * ent.velocity.Length();
                                            if (bonusY == -gravDir && Math.Sign(ent.velocity.Y) != -gravDir || (double)Math.Abs(ent.velocity.Y) < 0.100000001490116)
                                            {
                                                ent.velocity.Y = (float)-gravDir * 0.1f;
                                            }
                                            int extraInfo = (int)((double)(projectile2.owner * 2) + (double)projectile2.ai[1]);
                                            int num3      = extraInfo + (extraInfo % 2 == 0 ? 1 : -1);
                                            if (ent is Player)
                                            {
                                                Player player = (Player)ent;
                                                player.lastPortalColorIndex = num3;
                                                player.Teleport(newPos, 4, extraInfo);
                                                if (Main.netMode == 1)
                                                {
                                                    NetMessage.SendData(96, -1, -1, (NetworkText)null, player.whoAmI, newPos.X, newPos.Y, (float)extraInfo, 0, 0, 0);
                                                    NetMessage.SendData(13, -1, -1, (NetworkText)null, player.whoAmI, 0.0f, 0.0f, 0.0f, 0, 0, 0);
                                                }
                                                PortalHelper.PortalCooldownForPlayers[index1] = 10;
                                                return;
                                            }
                                            if (!(ent is NPC))
                                            {
                                                return;
                                            }
                                            NPC npc = (NPC)ent;
                                            npc.lastPortalColorIndex = num3;
                                            npc.Teleport(newPos, 4, extraInfo);
                                            if (Main.netMode == 1)
                                            {
                                                NetMessage.SendData(100, -1, -1, (NetworkText)null, npc.whoAmI, newPos.X, newPos.Y, (float)extraInfo, 0, 0, 0);
                                                NetMessage.SendData(23, -1, -1, (NetworkText)null, npc.whoAmI, 0.0f, 0.0f, 0.0f, 0, 0, 0);
                                            }
                                            PortalHelper.PortalCooldownForPlayers[index1] = 10;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public static void TryGoingThroughPortals(Entity ent)
        {
            Vector2 vector2;
            Vector2 vector21;
            int     num;
            int     num1;
            float   single   = 0f;
            Vector2 vector22 = ent.velocity;
            int     num2     = ent.width;
            int     num3     = ent.height;
            int     num4     = 1;

            if (ent is Player)
            {
                num4 = (int)((Player)ent).gravDir;
            }
            for (int i = 0; i < PortalHelper.FoundPortals.GetLength(0); i++)
            {
                if (PortalHelper.FoundPortals[i, 0] != -1 && PortalHelper.FoundPortals[i, 1] != -1 && (!(ent is Player) || PortalHelper.PortalCooldownForPlayers[i] <= 0) && (!(ent is NPC) || PortalHelper.PortalCooldownForNPCs[i] <= 0))
                {
                    for (int j = 0; j < 2; j++)
                    {
                        Projectile projectile = Main.projectile[PortalHelper.FoundPortals[i, j]];
                        PortalHelper.GetPortalEdges(projectile.Center, projectile.ai[0], out vector2, out vector21);
                        if (Collision.CheckAABBvLineCollision(ent.position + ent.velocity, ent.Size, vector2, vector21, 2f, ref single))
                        {
                            Projectile projectile1       = Main.projectile[PortalHelper.FoundPortals[i, 1 - j]];
                            float      single1           = ent.Hitbox.Distance(projectile.Center);
                            Vector2    portalOutingPoint = PortalHelper.GetPortalOutingPoint(ent.Size, projectile1.Center, projectile1.ai[0], out num, out num1) + (Vector2.Normalize(new Vector2((float)num, (float)num1)) * single1);
                            Vector2    unitX             = Vector2.UnitX * 16f;
                            if (Collision.TileCollision(portalOutingPoint - unitX, unitX, num2, num3, false, false, num4) == unitX)
                            {
                                unitX = -Vector2.UnitX * 16f;
                                if (Collision.TileCollision(portalOutingPoint - unitX, unitX, num2, num3, false, false, num4) == unitX)
                                {
                                    unitX = Vector2.UnitY * 16f;
                                    if (Collision.TileCollision(portalOutingPoint - unitX, unitX, num2, num3, false, false, num4) == unitX)
                                    {
                                        unitX = -Vector2.UnitY * 16f;
                                        if (Collision.TileCollision(portalOutingPoint - unitX, unitX, num2, num3, false, false, num4) == unitX)
                                        {
                                            float single2 = 0.1f;
                                            if (num1 == -num4)
                                            {
                                                single2 = 0.1f;
                                            }
                                            if (ent.velocity == Vector2.Zero)
                                            {
                                                ent.velocity = (projectile.ai[0] - 1.57079637f).ToRotationVector2() * single2;
                                            }
                                            if (ent.velocity.Length() < single2)
                                            {
                                                ent.velocity.Normalize();
                                                Entity entity = ent;
                                                entity.velocity = entity.velocity * single2;
                                            }
                                            Vector2 unitX1 = Vector2.Normalize(new Vector2((float)num, (float)num1));
                                            if (unitX1.HasNaNs() || unitX1 == Vector2.Zero)
                                            {
                                                unitX1 = Vector2.UnitX * (float)ent.direction;
                                            }
                                            ent.velocity = unitX1 * ent.velocity.Length();
                                            if (num1 == -num4 && Math.Sign(ent.velocity.Y) != -num4 || Math.Abs(ent.velocity.Y) < 0.1f)
                                            {
                                                ent.velocity.Y = (float)(-num4) * 0.1f;
                                            }
                                            int num5 = (int)((float)(projectile1.owner * 2) + projectile1.ai[1]);
                                            int num6 = num5 + (num5 % 2 == 0 ? 1 : -1);
                                            if (ent is Player)
                                            {
                                                Player player = (Player)ent;
                                                player.lastPortalColorIndex = num6;
                                                player.Teleport(portalOutingPoint, 4, num5);
                                                if (Main.netMode == 1)
                                                {
                                                    NetMessage.SendData(96, -1, -1, "", player.whoAmI, portalOutingPoint.X, portalOutingPoint.Y, (float)num5, 0, 0, 0);
                                                    NetMessage.SendData(13, -1, -1, "", player.whoAmI, 0f, 0f, 0f, 0, 0, 0);
                                                }
                                                PortalHelper.PortalCooldownForPlayers[i] = 10;
                                                return;
                                            }
                                            if (ent is NPC)
                                            {
                                                NPC nPC = (NPC)ent;
                                                nPC.lastPortalColorIndex = num6;
                                                nPC.Teleport(portalOutingPoint, 4, num5);
                                                if (Main.netMode == 1)
                                                {
                                                    NetMessage.SendData(100, -1, -1, "", nPC.whoAmI, portalOutingPoint.X, portalOutingPoint.Y, (float)num5, 0, 0, 0);
                                                    NetMessage.SendData(23, -1, -1, "", nPC.whoAmI, 0f, 0f, 0f, 0, 0, 0);
                                                }
                                                PortalHelper.PortalCooldownForPlayers[i] = 10;
                                            }
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: PortalHelper.cs プロジェクト: xiongyaya/Terraria
        public static void TryGoingThroughPortals(Entity ent)
        {
            float   collisionPoint = 0.0f;
            Vector2 velocity       = ent.velocity;
            int     width          = ent.width;
            int     height         = ent.height;
            int     gravDir        = 1;

            if (ent is Player)
            {
                gravDir = (int)((Player)ent).gravDir;
            }
            for (int index1 = 0; index1 < PortalHelper.FoundPortals.GetLength(0); ++index1)
            {
                if (PortalHelper.FoundPortals[index1, 0] != -1 && PortalHelper.FoundPortals[index1, 1] != -1 && (!(ent is Player) || index1 < PortalHelper.PortalCooldownForPlayers.Length && PortalHelper.PortalCooldownForPlayers[index1] <= 0) && (!(ent is NPC) || index1 < PortalHelper.PortalCooldownForNPCs.Length && PortalHelper.PortalCooldownForNPCs[index1] <= 0))
                {
                    for (int index2 = 0; index2 < 2; ++index2)
                    {
                        Projectile projectile1 = Main.projectile[PortalHelper.FoundPortals[index1, index2]];
                        Vector2    start;
                        Vector2    end;
                        PortalHelper.GetPortalEdges(projectile1.Center, projectile1.ai[0], out start, out end);
                        if (Collision.CheckAABBvLineCollision(Vector2.op_Addition(ent.position, ent.velocity), ent.Size, start, end, 2f, ref collisionPoint))
                        {
                            Projectile projectile2 = Main.projectile[PortalHelper.FoundPortals[index1, 1 - index2]];
                            float      num1        = ent.Hitbox.Distance(projectile1.Center);
                            int        bonusX;
                            int        bonusY;
                            Vector2    newPos    = Vector2.op_Addition(PortalHelper.GetPortalOutingPoint(ent.Size, projectile2.Center, projectile2.ai[0], out bonusX, out bonusY), Vector2.op_Multiply(Vector2.Normalize(new Vector2((float)bonusX, (float)bonusY)), num1));
                            Vector2    Velocity1 = Vector2.op_Multiply(Vector2.get_UnitX(), 16f);
                            if (!Vector2.op_Inequality(Collision.TileCollision(Vector2.op_Subtraction(newPos, Velocity1), Velocity1, width, height, true, true, gravDir), Velocity1))
                            {
                                Vector2 Velocity2 = Vector2.op_Multiply(Vector2.op_UnaryNegation(Vector2.get_UnitX()), 16f);
                                if (!Vector2.op_Inequality(Collision.TileCollision(Vector2.op_Subtraction(newPos, Velocity2), Velocity2, width, height, true, true, gravDir), Velocity2))
                                {
                                    Vector2 Velocity3 = Vector2.op_Multiply(Vector2.get_UnitY(), 16f);
                                    if (!Vector2.op_Inequality(Collision.TileCollision(Vector2.op_Subtraction(newPos, Velocity3), Velocity3, width, height, true, true, gravDir), Velocity3))
                                    {
                                        Vector2 Velocity4 = Vector2.op_Multiply(Vector2.op_UnaryNegation(Vector2.get_UnitY()), 16f);
                                        if (!Vector2.op_Inequality(Collision.TileCollision(Vector2.op_Subtraction(newPos, Velocity4), Velocity4, width, height, true, true, gravDir), Velocity4))
                                        {
                                            float num2 = 0.1f;
                                            if (bonusY == -gravDir)
                                            {
                                                num2 = 0.1f;
                                            }
                                            if (Vector2.op_Equality(ent.velocity, Vector2.get_Zero()))
                                            {
                                                ent.velocity = Vector2.op_Multiply((projectile1.ai[0] - 1.570796f).ToRotationVector2(), num2);
                                            }
                                            // ISSUE: explicit reference operation
                                            if ((double)((Vector2)@ent.velocity).Length() < (double)num2)
                                            {
                                                // ISSUE: explicit reference operation
                                                ((Vector2)@ent.velocity).Normalize();
                                                Entity  entity  = ent;
                                                Vector2 vector2 = Vector2.op_Multiply(entity.velocity, num2);
                                                entity.velocity = vector2;
                                            }
                                            Vector2 vec = Vector2.Normalize(new Vector2((float)bonusX, (float)bonusY));
                                            if (vec.HasNaNs() || Vector2.op_Equality(vec, Vector2.get_Zero()))
                                            {
                                                vec = Vector2.op_Multiply(Vector2.get_UnitX(), (float)ent.direction);
                                            }
                                            // ISSUE: explicit reference operation
                                            ent.velocity = Vector2.op_Multiply(vec, ((Vector2)@ent.velocity).Length());
                                            if (bonusY == -gravDir && Math.Sign((float)ent.velocity.Y) != -gravDir || (double)Math.Abs((float)ent.velocity.Y) < 0.100000001490116)
                                            {
                                                ent.velocity.Y = (__Null)((double)-gravDir * 0.100000001490116);
                                            }
                                            int extraInfo = (int)((double)(projectile2.owner * 2) + (double)projectile2.ai[1]);
                                            int num3      = extraInfo + (extraInfo % 2 == 0 ? 1 : -1);
                                            if (ent is Player)
                                            {
                                                Player player = (Player)ent;
                                                player.lastPortalColorIndex = num3;
                                                player.Teleport(newPos, 4, extraInfo);
                                                if (Main.netMode == 1)
                                                {
                                                    NetMessage.SendData(96, -1, -1, (NetworkText)null, player.whoAmI, (float)newPos.X, (float)newPos.Y, (float)extraInfo, 0, 0, 0);
                                                    NetMessage.SendData(13, -1, -1, (NetworkText)null, player.whoAmI, 0.0f, 0.0f, 0.0f, 0, 0, 0);
                                                }
                                                PortalHelper.PortalCooldownForPlayers[index1] = 10;
                                                return;
                                            }
                                            if (!(ent is NPC))
                                            {
                                                return;
                                            }
                                            NPC npc = (NPC)ent;
                                            npc.lastPortalColorIndex = num3;
                                            npc.Teleport(newPos, 4, extraInfo);
                                            if (Main.netMode == 1)
                                            {
                                                NetMessage.SendData(100, -1, -1, (NetworkText)null, npc.whoAmI, (float)newPos.X, (float)newPos.Y, (float)extraInfo, 0, 0, 0);
                                                NetMessage.SendData(23, -1, -1, (NetworkText)null, npc.whoAmI, 0.0f, 0.0f, 0.0f, 0, 0, 0);
                                            }
                                            PortalHelper.PortalCooldownForPlayers[index1] = 10;
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: PortalHelper.cs プロジェクト: windlex/mylualib
        // Token: 0x06000F1F RID: 3871 RVA: 0x003F1218 File Offset: 0x003EF418
        public static void TryGoingThroughPortals(Entity ent)
        {
            float   num      = 0f;
            Vector2 arg_0C_0 = ent.velocity;
            int     width    = ent.width;
            int     height   = ent.height;
            int     num2     = 1;

            if (ent is Player)
            {
                num2 = (int)((Player)ent).gravDir;
            }
            for (int i = 0; i < PortalHelper.FoundPortals.GetLength(0); i++)
            {
                if (PortalHelper.FoundPortals[i, 0] != -1 && PortalHelper.FoundPortals[i, 1] != -1 && (!(ent is Player) || (i < PortalHelper.PortalCooldownForPlayers.Length && PortalHelper.PortalCooldownForPlayers[i] <= 0)) && (!(ent is NPC) || (i < PortalHelper.PortalCooldownForNPCs.Length && PortalHelper.PortalCooldownForNPCs[i] <= 0)))
                {
                    for (int j = 0; j < 2; j++)
                    {
                        Projectile projectile = Main.projectile[PortalHelper.FoundPortals[i, j]];
                        Vector2    lineStart;
                        Vector2    lineEnd;
                        PortalHelper.GetPortalEdges(projectile.Center, projectile.ai[0], out lineStart, out lineEnd);
                        if (Collision.CheckAABBvLineCollision(ent.position + ent.velocity, ent.Size, lineStart, lineEnd, 2f, ref num))
                        {
                            Projectile projectile2 = Main.projectile[PortalHelper.FoundPortals[i, 1 - j]];
                            float      scaleFactor = ent.Hitbox.Distance(projectile.Center);
                            int        num3;
                            int        num4;
                            Vector2    vector  = PortalHelper.GetPortalOutingPoint(ent.Size, projectile2.Center, projectile2.ai[0], out num3, out num4) + Vector2.Normalize(new Vector2((float)num3, (float)num4)) * scaleFactor;
                            Vector2    vector2 = Vector2.UnitX * 16f;
                            if (!(Collision.TileCollision(vector - vector2, vector2, width, height, true, true, num2) != vector2))
                            {
                                vector2 = -Vector2.UnitX * 16f;
                                if (!(Collision.TileCollision(vector - vector2, vector2, width, height, true, true, num2) != vector2))
                                {
                                    vector2 = Vector2.UnitY * 16f;
                                    if (!(Collision.TileCollision(vector - vector2, vector2, width, height, true, true, num2) != vector2))
                                    {
                                        vector2 = -Vector2.UnitY * 16f;
                                        if (!(Collision.TileCollision(vector - vector2, vector2, width, height, true, true, num2) != vector2))
                                        {
                                            float num5 = 0.1f;
                                            if (num4 == -num2)
                                            {
                                                num5 = 0.1f;
                                            }
                                            if (ent.velocity == Vector2.Zero)
                                            {
                                                ent.velocity = (projectile.ai[0] - 1.57079637f).ToRotationVector2() * num5;
                                            }
                                            if (ent.velocity.Length() < num5)
                                            {
                                                ent.velocity.Normalize();
                                                ent.velocity *= num5;
                                            }
                                            Vector2 vector3 = Vector2.Normalize(new Vector2((float)num3, (float)num4));
                                            if (vector3.HasNaNs() || vector3 == Vector2.Zero)
                                            {
                                                vector3 = Vector2.UnitX * (float)ent.direction;
                                            }
                                            ent.velocity = vector3 * ent.velocity.Length();
                                            if ((num4 == -num2 && Math.Sign(ent.velocity.Y) != -num2) || Math.Abs(ent.velocity.Y) < 0.1f)
                                            {
                                                ent.velocity.Y = (float)(-(float)num2) * 0.1f;
                                            }
                                            int num6 = (int)((float)(projectile2.owner * 2) + projectile2.ai[1]);
                                            int lastPortalColorIndex = num6 + ((num6 % 2 == 0) ? 1 : -1);
                                            if (ent is Player)
                                            {
                                                Player player = (Player)ent;
                                                player.lastPortalColorIndex = lastPortalColorIndex;
                                                player.Teleport(vector, 4, num6);
                                                if (Main.netMode == 1)
                                                {
                                                    NetMessage.SendData(96, -1, -1, null, player.whoAmI, vector.X, vector.Y, (float)num6, 0, 0, 0);
                                                    NetMessage.SendData(13, -1, -1, null, player.whoAmI, 0f, 0f, 0f, 0, 0, 0);
                                                }
                                                PortalHelper.PortalCooldownForPlayers[i] = 10;
                                                return;
                                            }
                                            if (ent is NPC)
                                            {
                                                NPC nPC = (NPC)ent;
                                                nPC.lastPortalColorIndex = lastPortalColorIndex;
                                                nPC.Teleport(vector, 4, num6);
                                                if (Main.netMode == 1)
                                                {
                                                    NetMessage.SendData(100, -1, -1, null, nPC.whoAmI, vector.X, vector.Y, (float)num6, 0, 0, 0);
                                                    NetMessage.SendData(23, -1, -1, null, nPC.whoAmI, 0f, 0f, 0f, 0, 0, 0);
                                                }
                                                PortalHelper.PortalCooldownForPlayers[i] = 10;
                                            }
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }