Example #1
0
 void SetRotation()
 {
     if (Power)
     {
         Rotation    += RotationSpeed;
         npc.rotation = Rotation;
     }
     else
     {
         while (Rotation - 36.0f >= 0.0f)
         {
             Rotation -= 36.0f;
         }
         if (Rotation != 0.0f)
         {
             Rotation -= (RotationSpeed * 2.0f);
             Vector2 velocity = Helper2.VelocityFPTP(npc.Center, Helper2.RandomPositin(new Vector2(npc.Center.X - 250, npc.Center.Y - 250), new Vector2(npc.Center.X + 250, npc.Center.Y + 250)), PowerLaserSpeed);
             int     i        = Projectile.NewProjectile(npc.Center.X, npc.Center.Y, velocity.X, velocity.Y, ShootType, PowerLaserDamage, PowerLaserKB);
             Main.projectile[i].tileCollide = false;
         }
         if (Rotation < 0.0f)
         {
             Rotation = 0.0f;
         }
         npc.rotation = Rotation;
     }
 }
Example #2
0
        public virtual void ObjectsAreReused()
        {
            Helper1 helper1 = new Helper1();
            Helper2 helper2 = new Helper2()
            {
                Helper = helper1
            };

            List <Helper2> source = new List <Helper2>()
            {
                helper2,
                helper2,
            };

            var target = GetClone(source, 3);

            Assert.NotNull(target);
            Assert.Equal(target.Count, source.Count);

            Assert.NotSame(target, source);

            Assert.NotSame(target[0], source[0]);
            Assert.NotSame(target[0], helper1);
            Assert.NotSame(target[0].Helper, source[0].Helper);
            Assert.NotSame(target[0].Helper, helper2);

            Assert.NotSame(target[1], source[1]);
            Assert.NotSame(target[1], helper1);
            Assert.NotSame(target[1].Helper, source[1].Helper);
            Assert.NotSame(target[1].Helper, helper2);

            Assert.Same(target[0], target[1]);
            Assert.Same(target[0].Helper, target[1].Helper);
        }
Example #3
0
 void Shoot()
 {
     if (Helper2.GetNearestPlayer(npc) != -1)
     {
         npc.target = Helper2.GetNearestPlayer(npc);
         Vector2 velocity = Helper2.VelocityFPTP(npc.Center, Main.player[npc.target].Center, (Power) ? PowerLaserSpeed : NormalLaserSpeed);
         int     i        = Projectile.NewProjectile(npc.Center.X, npc.Center.Y, velocity.X, velocity.Y, ShootType, (Power) ? PowerLaserDamage : NormalLaserDamage, (Power) ? PowerLaserKB : NormalLaserKB);
         Main.projectile[i].tileCollide = false;
         Main.projectile[i].friendly    = false;
     }
 }
Example #4
0
        public void CompositeClassNoDependenciesRegistered_CallContainerResolveMethod_ShouldThrowFailedToCreateInstanceException()
        {
            //Arrange
            IContainer          container     = new Container();
            Helper1             help1         = new Helper1();
            Helper2             help2         = new Helper2();
            ICompositeItemWrong compositeItem = new CompositeItemWrong(help1, help2);

            container.Register <ICompositeItemWrong, CompositeItemWrong>();

            //Act
            Exception ex = Assert.Throws <FailedToCreateInstanceException>(() => container.Resolve <ICompositeItemWrong>());

            //Assert
            Assert.Equal("Can't create instance of type CompositeItemWrong", ex.Message);
        }
Example #5
0
        public void RegisterType_TwoDifferentImplementationsTwoDifferentInterfaces_TypesAreRegisteredAndResolved()
        {
            //Arrange
            IContainer container = new Container();
            Helper1    help1     = new Helper1();
            Helper2    help2     = new Helper2();

            //Act
            container.Register <IHelper1, Helper1>();
            container.Register <IHelper2, Helper2>();
            var actualType1 = container.Resolve <IHelper1>();
            var actualType2 = container.Resolve <IHelper2>();

            //Assert
            Assert.IsType(help1.GetType(), actualType1);
            Assert.IsType(help2.GetType(), actualType2);
        }
Example #6
0
        public virtual void SimpleClass()
        {
            Helper2 source = new Helper2()
            {
                Helper = new Helper1()
                {
                    PropOne = RandGen.GenerateInt()
                }
            };

            Helper2 dest = GetClone(source, 2);

            Assert.NotNull(dest);
            Assert.NotNull(dest.Helper);
            Assert.NotSame(dest.Helper, source.Helper);
            Assert.Equal(dest.Helper.PropOne, source.Helper.PropOne);
        }
Example #7
0
        public void RegisterType_OneInterfaceTwoDifferentImplementations_TypesAreRegisteredAndResolvedByType()
        {
            //Arrange
            Container container = new Container();
            IHelper1  help1     = new Helper1();
            IHelper1  help2     = new Helper2();

            //Act
            container.Register <IHelper1, Helper1>();
            container.Register <IHelper1, Helper2>();
            List <object> actualTypes = container.ResolveAll(typeof(IHelper1)).ToList();

            //Assert
            Assert.NotNull(actualTypes);
            Assert.Equal(help1.GetType().FullName, actualTypes[0].GetType().FullName);
            Assert.Equal(help2.GetType().FullName, actualTypes[1].GetType().FullName);
        }
Example #8
0
        public void RegisterCompositeType_CallContainer_TypesAreRegisteredAndResolvedbyType()
        {
            //Arrange
            IContainer     container     = new Container();
            Helper1        help1         = new Helper1();
            Helper2        help2         = new Helper2();
            ICompositeItem compositeItem = new CompositeItem(help1, help2);


            //Act
            container.Register <IHelper1, Helper1>();
            container.Register <IHelper2, Helper2>();
            container.Register <ICompositeItem, CompositeItem>();
            var actualType = container.Resolve(typeof(ICompositeItem));

            //Assert
            Assert.IsType(compositeItem.GetType(), actualType);
        }
Example #9
0
 void Shoot()
 {
     npc.target = Helper2.GetNearestPlayer(npc);
     if (npc.target != -1)
     {
         Vector2 velocity   = Helper2.VelocityFPTP(npc.Center, Main.player[npc.target].Center, NormalBulletSpeed);
         int     spread     = 95;
         float   spreadMult = 0.075f;
         for (int l = 0; l < 2; l++)
         {
             velocity.X = velocity.X + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
             velocity.Y = velocity.Y + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
             int i = Projectile.NewProjectile(npc.Center.X, npc.Center.Y, velocity.X, velocity.Y, NormalShootType, NormalBulletDamage, NormalBulletKB);
             Main.projectile[i].hostile  = true;
             Main.projectile[i].friendly = false;
         }
     }
 }
Example #10
0
 void Shoot()
 {
     npc.target = Helper2.GetNearestPlayer(npc);
     if (npc.target != -1)
     {
         Vector2 velocity   = Helper2.VelocityFPTP(npc.Center, new Vector2(Main.player[npc.target].Center.X, Main.player[npc.target].Center.Y + 20), 0.0f);
         int     spread     = 65;
         float   spreadMult = 0.05f;
         for (int l = 0; l < 2; l++)
         {
             velocity.X = velocity.X + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
             velocity.Y = velocity.Y + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
             int i = Projectile.NewProjectile(npc.Center.X, npc.Center.Y + 20, velocity.X, velocity.Y, ShootType, PowerLaserDamage, PowerLaserKB);
             Main.projectile[i].hostile     = true;
             Main.projectile[i].friendly    = false;
             Main.projectile[i].tileCollide = false;
         }
     }
 }
Example #11
0
    void zmqSubThread()
    {
        while (app_exit_sub == false && subscriber != null)
        {
            try
            {
                Msg msg = new Msg();
                msg.InitEmpty();
                bool dresult = subscriber.TryReceive(ref msg, new TimeSpan(0, 0, 0, 0, 10));

                if (dresult)
                {
                    last_read_time = Helper2.getCurrentTimeSpan();

                    //if (typeof(SUBTYPE) == typeof(RawData))
                    //{
                    //    get_raw_bytes = msg.Data;
                    //}
                    //else
                    //{
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(msg.Data);
                    SUBTYPE result            = Serializer.Deserialize <SUBTYPE>(ms);
                    get = result;
                    //}

                    if (app_exit_sub == false)
                    {
                        state = NetworkState.CONNECTED;
                        updateSetupStatus(true);
                        dataTrigger();
                    }
                }
            }
            catch
            {
            }
        }
    }
Example #12
0
        public override void AI()
        {
            npc.TargetClosest(true);
            npc.spriteDirection = npc.direction;
            Player player = Main.player[npc.target];

            if (player.dead || !player.active)
            {
                npc.TargetClosest(false);
                npc.active = false;
            }
            Timer++;
            if (Timer >= 0)
            {
                if ((int)(Main.time % 90) == 0)
                {
                    Vector2 Velocity   = Helper2.VelocityFPTP(npc.Center, new Vector2(Main.player[npc.target].Center.X, Main.player[npc.target].Center.Y + 20), 10);
                    int     Spread     = 65;
                    float   SpreadMult = 0.05f;
                    Velocity.X = Velocity.X + (float)Main.rand.Next(-Spread, Spread + 1) * SpreadMult;
                    Velocity.Y = Velocity.Y + (float)Main.rand.Next(-Spread, Spread + 1) * SpreadMult;
                    int i = Projectile.NewProjectile(npc.Center.X, npc.Center.Y + 20, Velocity.X, Velocity.Y, 258, ShootDamage, ShootKnockback);
                    Main.projectile[i].hostile     = true;
                    Main.projectile[i].friendly    = true;
                    Main.projectile[i].tileCollide = false;
                }
            }
            if (Timer >= 0 && Timer <= 1000)             //flight
            {
                Vector2 StartPosition = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
                float   DirectionX    = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2) - StartPosition.X;
                float   DirectionY    = (float)(Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - 120) - StartPosition.Y;
                float   Length        = (float)Math.Sqrt(DirectionX * DirectionX + DirectionY * DirectionY);
                float   Num           = Speed / Length;
                DirectionX = DirectionX * Num;
                DirectionY = DirectionY * Num;
                if (npc.velocity.X < DirectionX)
                {
                    npc.velocity.X = npc.velocity.X + Acceleration;
                    if (npc.velocity.X < 0 && DirectionX > 0)
                    {
                        npc.velocity.X = npc.velocity.X + Acceleration;
                    }
                }
                else if (npc.velocity.X > DirectionX)
                {
                    npc.velocity.X = npc.velocity.X - Acceleration;
                    if (npc.velocity.X > 0 && DirectionX < 0)
                    {
                        npc.velocity.X = npc.velocity.X - Acceleration;
                    }
                }
                if (npc.velocity.Y < DirectionY)
                {
                    npc.velocity.Y = npc.velocity.Y + Acceleration;
                    if (npc.velocity.Y < 0 && DirectionY > 0)
                    {
                        npc.velocity.Y = npc.velocity.Y + Acceleration;
                    }
                }
                else if (npc.velocity.Y > DirectionY)
                {
                    npc.velocity.Y = npc.velocity.Y - Acceleration;
                    if (npc.velocity.Y > 0 && DirectionY < 0)
                    {
                        npc.velocity.Y = npc.velocity.Y - Acceleration;
                    }
                }
                if (Main.rand.Next(36) == 1)
                {
                    Vector2 StartPosition2 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2));
                    float   AndasRotation  = (float)Math.Atan2(StartPosition2.Y - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), StartPosition2.X - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(AndasRotation) * 18) * -1;
                    npc.velocity.Y = (float)(Math.Sin(AndasRotation) * 18) * -1;
                    npc.netUpdate  = true;
                }
            }

            if (Timer == 700)
            {
                for (int i = 0; i < 50; i++)
                {
                    int dust = Dust.NewDust(npc.position, npc.width, npc.height, 6);
                    Main.dust[dust].scale     = 1.5f;
                    Main.dust[dust].noGravity = true;
                    Main.dust[dust].velocity *= 0f;
                    Main.dust[dust].velocity *= 0f;
                }
                DoAndasShoot();
                npc.position.X = (Main.player[npc.target].position.X - 500) + Main.rand.Next(1000);
                npc.position.Y = (Main.player[npc.target].position.Y - 500) + Main.rand.Next(1000);
            }


            if (Timer == 850)
            {
                for (int i = 0; i < 50; i++)
                {
                    int dust = Dust.NewDust(npc.position, npc.width, npc.height, 6);
                    Main.dust[dust].scale     = 1.5f;
                    Main.dust[dust].noGravity = true;
                    Main.dust[dust].velocity *= 0f;
                    Main.dust[dust].velocity *= 0f;
                }
                DoAndasShoot();
                npc.position.X = (Main.player[npc.target].position.X - 500) + Main.rand.Next(1000);
                npc.position.Y = (Main.player[npc.target].position.Y - 500) + Main.rand.Next(1000);
            }


            if (Timer == 1000)
            {
                for (int i = 0; i < 50; i++)
                {
                    int dust = Dust.NewDust(npc.position, npc.width, npc.height, 6);
                    Main.dust[dust].scale     = 1.5f;
                    Main.dust[dust].noGravity = true;
                    Main.dust[dust].velocity *= 0f;
                    Main.dust[dust].velocity *= 0f;
                }
                DoAndasShoot();
                npc.position.X = (Main.player[npc.target].position.X - 500) + Main.rand.Next(1000);
                npc.position.Y = (Main.player[npc.target].position.Y - 500) + Main.rand.Next(1000);
            }

            if (Timer == 1150)
            {
                for (int i = 0; i < 50; i++)
                {
                    int dust = Dust.NewDust(npc.position, npc.width, npc.height, 6);
                    Main.dust[dust].scale     = 1.5f;
                    Main.dust[dust].noGravity = true;
                    Main.dust[dust].velocity *= 0f;
                    Main.dust[dust].velocity *= 0f;
                }
                DoAndasShoot();
                npc.position.X = (Main.player[npc.target].position.X - 500) + Main.rand.Next(1000);
                npc.position.Y = (Main.player[npc.target].position.Y - 500) + Main.rand.Next(1000);
            }

            if (Timer == 1300)
            {
                for (int i = 0; i < 50; i++)
                {
                    int dust = Dust.NewDust(npc.position, npc.width, npc.height, 6);
                    Main.dust[dust].scale     = 1.5f;
                    Main.dust[dust].noGravity = true;
                    Main.dust[dust].velocity *= 0f;
                    Main.dust[dust].velocity *= 0f;
                }
                DoAndasShoot();
                npc.position.X = (Main.player[npc.target].position.X - 500) + Main.rand.Next(1000);
                npc.position.Y = (Main.player[npc.target].position.Y - 500) + Main.rand.Next(1000);
            }

            if (Timer > 1300)
            {
                Timer = 0;
            }
        }
Example #13
0
 /// <summary>
 ///     Расшифровывает строку в кодировке Base64, возвращает string
 /// </summary>
 /// <param name="EncodedText">Зашифрованный текст в формате Base64</param>
 /// <param name="Pass">Пароль для дешифровки</param>
 /// <returns></returns>
 public string Decode(string EncodedText, string Pass)
 {
     return(Helper2.Decrypt(Helper1.Decrypt(EncodedText), Pass));
 }
Example #14
0
        public void Setup()
        {
            _null = null;

            _simpleClass = new Helper1()
            {
                PropOne   = RandGen.GenerateInt(),
                PropTwo   = RandGen.GenerateInt(),
                PropThree = RandGen.GenerateInt(),
            };

            _complexClass = new Helper2()
            {
                Helper = new Helper1()
                {
                    PropOne   = RandGen.GenerateInt(),
                    PropTwo   = RandGen.GenerateInt(),
                    PropThree = RandGen.GenerateInt(),
                    PropFour  = RandGen.GenerateInt(),
                    PropFive  = RandGen.GenerateInt(),
                    PropSix   = RandGen.GenerateInt(),
                    PropSeven = RandGen.GenerateInt(),
                    PropEight = RandGen.GenerateInt(),
                    PropNine  = RandGen.GenerateInt(),
                    PropTen   = RandGen.GenerateInt()
                }
            };

            _inheritListClass = new Helper3 <Helper1>()
            {
                PropOne = RandGen.GenerateInt()
            };

            for (int i = 0; i < 10000; i++)
            {
                _inheritListClass.Add(new Helper1()
                {
                    PropOne = RandGen.GenerateInt()
                });
            }
            ;

            _inheritListInt = new Helper3 <int>();

            for (int i = 0; i < 10000; i++)
            {
                _inheritListInt.Add(RandGen.GenerateInt());
            }
            ;

            _grandChildClass = GrandChildClassHelper.Generate();

            _listSimpleClasses = new List <Helper1>();

            for (int i = 0; i < 10000; i++)
            {
                _listSimpleClasses.Add(new Helper1()
                {
                    PropOne   = RandGen.GenerateInt(),
                    PropTwo   = RandGen.GenerateInt(),
                    PropThree = RandGen.GenerateInt(),
                });
            }

            _listComplexClasses = new List <Helper2>();

            for (int i = 0; i < 10000; i++)
            {
                _listComplexClasses.Add(new Helper2()
                {
                    Helper = new Helper1()
                    {
                        PropOne   = RandGen.GenerateInt(),
                        PropTwo   = RandGen.GenerateInt(),
                        PropThree = RandGen.GenerateInt(),
                    }
                });
            }

            _listInterfaces = new List <MyTmpInterface>();

            for (int i = 0; i < 10000; i++)
            {
                _listInterfaces.Add(new Helper1());
                _listInterfaces.Add(new Helper1_1());
            }

            _listSimpleStructs = new List <HelperStruct1>();

            for (int i = 0; i < 10000; i++)
            {
                _listSimpleStructs.Add(new HelperStruct1()
                {
                    PropOne   = RandGen.GenerateInt(),
                    PropTwo   = RandGen.GenerateInt(),
                    PropThree = RandGen.GenerateInt(),
                });
            }

            _listComplexStructs = new List <HelperStruct2>();

            for (int i = 0; i < 10000; i++)
            {
                _listComplexStructs.Add(new HelperStruct2()
                {
                    Helper = new HelperStruct1()
                    {
                        PropOne   = RandGen.GenerateInt(),
                        PropTwo   = RandGen.GenerateInt(),
                        PropThree = RandGen.GenerateInt(),
                    }
                });
            }

            _dictOfStructs = new Dictionary <HelperStruct1, HelperStruct1>();

            for (int i = 0; i < 10000; i++)
            {
                _dictOfStructs.Add(
                    new HelperStruct1()
                {
                    PropOne   = RandGen.GenerateInt(),
                    PropTwo   = RandGen.GenerateInt(),
                    PropThree = RandGen.GenerateInt()
                },
                    new HelperStruct1()
                {
                    PropOne   = RandGen.GenerateInt(),
                    PropTwo   = RandGen.GenerateInt(),
                    PropThree = RandGen.GenerateInt()
                });
            }

            _dictOfClasses = new Dictionary <Helper1, Helper1>();

            for (int i = 0; i < 10000; i++)
            {
                _dictOfClasses.Add(
                    new Helper1()
                {
                    PropOne   = RandGen.GenerateInt(),
                    PropTwo   = RandGen.GenerateInt(),
                    PropThree = RandGen.GenerateInt()
                },
                    new Helper1()
                {
                    PropOne   = RandGen.GenerateInt(),
                    PropTwo   = RandGen.GenerateInt(),
                    PropThree = RandGen.GenerateInt()
                });
            }

            _dictOfInt = new Dictionary <int, int>();

            for (int i = 0; i < 10000; i++)
            {
                _dictOfInt.Add(i, RandGen.GenerateInt());
            }

            _listSimpleClassesAsInterfaces = _listSimpleClasses
                                             .OfType <MyTmpInterface>()
                                             .ToList();

            _listSimpleClassesAsObjects = _listSimpleClasses
                                          .Cast <object>()
                                          .ToList();
        }
Example #15
0
        public override void AI()
        {
            npc.position += npc.velocity * 1.7f;
            if (Main.rand.Next(500) == 0 && Main.expertMode)
            {
                for (int i = 0; i < 50; i++)
                {
                    int dust = Dust.NewDust(npc.position, npc.width, npc.height, 6);
                    Main.dust[dust].scale     = 1.5f;
                    Main.dust[dust].noGravity = true;
                    Main.dust[dust].velocity *= 0f;
                    Main.dust[dust].velocity *= 0f;
                }
                npc.position.X = (Main.player[npc.target].position.X - 250) + Main.rand.Next(500);
                npc.position.Y = (Main.player[npc.target].position.Y - 250) + Main.rand.Next(500);
            }

            if (Main.rand.Next(500) == 0 && !Main.expertMode)
            {
                npc.TargetClosest(true);
                Vector2 vector142 = new Vector2(npc.Center.X, npc.Center.Y);
                float   num1243   = Main.player[npc.target].Center.X - vector142.X;
                float   num1244   = Main.player[npc.target].Center.Y - vector142.Y;
                float   num1245   = (float)Math.Sqrt((double)(num1243 * num1243 + num1244 * num1244));
                if (npc.ai[1] == 0f)
                {
                    if (Main.netMode != 1)
                    {
                        npc.localAI[1] += 1f;
                        if (npc.localAI[1] >= (float)(120 + Main.rand.Next(200)))
                        {
                            npc.localAI[1] = 0f;
                            npc.TargetClosest(true);
                            int num1249 = 0;
                            int num1250;
                            int num1251;
                            while (true)
                            {
                                num1249++;
                                num1250  = (int)Main.player[npc.target].Center.X / 16;
                                num1251  = (int)Main.player[npc.target].Center.Y / 16;
                                num1250 += Main.rand.Next(-50, 51);
                                num1251 += Main.rand.Next(-50, 51);
                                if (!WorldGen.SolidTile(num1250, num1251) && Collision.CanHit(new Vector2((float)(num1250 * 16), (float)(num1251 * 16)), 1, 1, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height))
                                {
                                    break;
                                }
                                if (num1249 > 100)
                                {
                                    //return;
                                }
                            }
                            npc.ai[1]     = 1f;
                            npc.ai[2]     = (float)num1250;
                            npc.ai[3]     = (float)num1251;
                            npc.netUpdate = true;
                            //return;
                        }
                    }
                }
                else if (npc.ai[1] == 1f)
                {
                    npc.alpha += 3;
                    if (npc.alpha >= 255)
                    {
                        npc.alpha      = 255;
                        npc.position.X = npc.ai[2] * 16f - (float)(npc.width / 2);
                        npc.position.Y = npc.ai[3] * 16f - (float)(npc.height / 2);
                        npc.ai[1]      = 2f;
                        //return;
                    }
                }
                else if (npc.ai[1] == 2f)
                {
                    npc.alpha -= 3;
                    if (npc.alpha <= 0)
                    {
                        npc.alpha = 0;
                        npc.ai[1] = 0f;
                        //return;
                    }
                }
            }

            if (NPC.AnyNPCs(mod.NPCType("SoulofHope")) || NPC.AnyNPCs(mod.NPCType("SoulofTrust")))
            {
                npc.dontTakeDamage = true;
            }
            if (NPC.AnyNPCs(mod.NPCType("SoulofHope")) || NPC.AnyNPCs(mod.NPCType("SoulofTrust")))
            {
                npc.dontTakeDamage = false;
            }

            if (Main.expertMode && Main.rand.Next(4500) == 0)
            {
                NPC.NewNPC((int)npc.position.X - 100, (int)npc.position.Y - 50, 418);
                NPC.NewNPC((int)npc.position.X + 100, (int)npc.position.Y - 50, 418);
            }

            if (Main.rand.Next(2) == 0)
            {
                int num706 = Dust.NewDust(npc.position, npc.width, npc.height, 6, 0f, 0f, 200, npc.color, 0.5f);
                Main.dust[num706].velocity *= 0.6f;
            }


            if (npc.target != -1 && !RunAway)                                                             //если(пнс.цель не варно -1 И не убегать)
            {
                if (!Main.player[npc.target].active)                                                      //если (не мой.игрок[нпс.цель].активный)
                {
                    if (Helper2.GetNearestAlivePlayer(npc) == -1)                                         //если (Помощьник.ПолучитьКоординатыИгрока(нпс) присвоить -1)
                    {
                        RunAway = true;                                                                   //Убегает = да
                    }
                    else                                                                                  //или
                    {
                        if (Main.player[Helper2.GetNearestAlivePlayer(npc)].Distance(npc.Center) > 2500f) //если(Мой.игрок[Помощьник.ПолучитьКоординатыИгрока(нпс)].Дистанция(нпс.Центр) больше 2500фунтов)
                        {
                            RunAway = true;                                                               //Убегает = да
                        }
                        else                                                                              //или...
                        {
                            npc.target = Helper2.GetNearestAlivePlayer(npc);                              //нпс.цель равно Помощьник.ПолучитьКоординатыИгрока(нпс)
                        }
                    }
                }
            }
            if (Main.dayTime || RunAway || npc.localAI[3] == 1)                                                               //если(Мой.День или Убегать или нпс.местный ИИ 3 к 1)
            {
                npc.localAI[3] = 1;                                                                                           //нпс.местный ИИ[3] равен 3
                if (Main.npc[(int)npc.ai[2]].type == mod.NPCType("SoulofHope") && Main.npc[(int)npc.ai[2]].active == true)    //если(Мой.нпс[(значение)нпс.ИИ[2]].тип равен мод.НПС Тип("МОБ") и Мой.нпс[(значение)нпс.ИИ[2]].активен равен да)
                {
                    Main.npc[(int)npc.ai[2]].localAI[3] = 1;                                                                  //Мой.нпс[(значение)нпс.ИИ[2]].местный ИИ[3] варно 1
                }
                if (Main.npc[(int)npc.ai[3]].type == mod.NPCType("SoulofTruth") && Main.npc[(int)npc.ai[3]].active == true)   //если(Мой.нпс[(значение)нпс.ИИ[2]].тип равен мод.НПС Тип("МОБ") и Мой.нпс[(значение)нпс.ИИ[2]].активен равен да)
                {
                    Main.npc[(int)npc.ai[3]].localAI[3] = 1;                                                                  //Мой.нпс[(значение)нпс.ИИ[2]].местный ИИ[3] варно 1
                }
                npc.life    += 11;                                                                                            //нпс.жизнь прибавить
                npc.aiStyle  = 0;                                                                                             //нпс.ИИ Стиль - 0
                npc.rotation = 0;
                npc.velocity = Helper2.VelocityFPTP(npc.Center, new Vector2(npc.Center.X, npc.Center.Y - 4815162342), 30.0f); //нпс.поворот = Помощьник.ПоворотФПТП(нпс.Центр, новый Вектор2(нпс.Центр.X, нпс.Центр.Y - 4815162342))
                CreateDust();
                return;
            }
            if (StateFlag)
            {
                if (
                    !((Main.npc[(int)npc.ai[2]].type == mod.NPCType("SoulofHope") && Main.npc[(int)npc.ai[2]].active == true)) ||
                    !((Main.npc[(int)npc.ai[3]].type == mod.NPCType("SoulofTruth") && Main.npc[(int)npc.ai[3]].active == true))
                    )
                {
                    StateFlag = false;
                    OnlyPower = true;
                }
            }
            if (OnlyPower)
            {
                SetStage(true);
            }
            else
            {
                CurrentPower += Step;
                if (CurrentPower <= 0 || CurrentPower >= PowerTime)
                {
                    Step *= -1;
                    SetStage(!Power);
                }
            }
            SetRotation();
            CreateDust();
            TimeToShoot--;
            if (TimeToShoot <= 0 && !Power)
            {
                TimeToShoot = NormalShootRate;
                Shoot();
                return;
            }
            if (TimeToShoot <= 0 && Power)
            {
                TimeToShoot = PowerShootRate;
                npc.target  = Helper2.GetNearestPlayer(npc);
                if (npc.target != -1)
                {
                    for (int a = 0; a < 5; a++)
                    {
                        Vector2 velocity   = Helper2.VelocityFPTP(npc.Center, Main.player[npc.target].Center, PowerBulletSpeed);
                        int     spread     = 65;
                        float   spreadMult = 0.05f;
                        velocity.X = velocity.X + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
                        velocity.Y = velocity.Y + (float)Main.rand.Next(-spread, spread + 1) * spreadMult;
                        int i = Projectile.NewProjectile(npc.Center.X, npc.Center.Y, velocity.X, velocity.Y, PowerShootType, PowerBulletDamage, PowerBulletKB);
                        Main.projectile[i].hostile  = true;
                        Main.projectile[i].friendly = true;
                    }
                }
                return;
            }
        }
Example #16
0
    /// <summary>
    /// Main networking timer
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Main_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        #region  TimeCalculations

        ulong time = Helper2.getCurrentTimeSpan();
        last_read_dt = (ulong)Math.Abs((long)(time - last_read_time));

        if (last_read_dt > stream_timeout)
        {
            read_timeout_error = true;
        }
        else
        {
            read_timeout_error = false;
        }

        last_write_dt = (ulong)Math.Abs((long)(last_write_time2 - last_write_time1));

        if (last_write_dt > stream_timeout)
        {
            write_timeout_error = true;
        }
        else
        {
            write_timeout_error = false;
        }

        if (last_write_dt > stream_timeout)
        {
            last_write_dt = stream_timeout;
        }
        if (last_read_dt > stream_timeout)
        {
            last_read_dt = stream_timeout;
        }

        status_index++;
        if (status_index % 2 == 0)
        {
            if (!string.IsNullOrEmpty(remote_ip) && is_ping_enabled)
            {
                ping.SendAsync(remote_ip, ping_timeout_sec, null);
            }
        }

        #endregion

        if (state == NetworkState.CONNECTED || state == NetworkState.CONNECTING)
        {
            timeoutChecker();
        }
        else if (state == NetworkState.SETUP)
        {
            setup();
        }
        else if (state == NetworkState.IDLE)
        {
        }
        else if (state == NetworkState.DISCONNECTED)
        {
            state = NetworkState.IDLE;
        }
    }
Example #17
0
        public override void AI()
        {
            npc.position += npc.velocity * 1.7f;
            if (Main.rand.Next(500) == 0 && Main.expertMode)
            {
                for (int i = 0; i < 50; i++)
                {
                    int dust = Dust.NewDust(npc.position, npc.width, npc.height, 5);
                    Main.dust[dust].scale     = 1.5f;
                    Main.dust[dust].noGravity = true;
                    Main.dust[dust].velocity *= 0f;
                    Main.dust[dust].velocity *= 0f;
                }
                npc.position.X = (Main.player[npc.target].position.X - 250) + Main.rand.Next(500);
                npc.position.Y = (Main.player[npc.target].position.Y - 250) + Main.rand.Next(500);
            }

            if (Main.rand.Next(500) == 0 && !Main.expertMode)
            {
                npc.TargetClosest(true);
                Vector2 vector142 = new Vector2(npc.Center.X, npc.Center.Y);
                float   num1243   = Main.player[npc.target].Center.X - vector142.X;
                float   num1244   = Main.player[npc.target].Center.Y - vector142.Y;
                float   num1245   = (float)Math.Sqrt((double)(num1243 * num1243 + num1244 * num1244));
                if (npc.ai[1] == 0f)
                {
                    if (Main.netMode != 1)
                    {
                        npc.localAI[1] += 1f;
                        if (npc.localAI[1] >= (float)(120 + Main.rand.Next(200)))
                        {
                            npc.localAI[1] = 0f;
                            npc.TargetClosest(true);
                            int num1249 = 0;
                            int num1250;
                            int num1251;
                            while (true)
                            {
                                num1249++;
                                num1250  = (int)Main.player[npc.target].Center.X / 16;
                                num1251  = (int)Main.player[npc.target].Center.Y / 16;
                                num1250 += Main.rand.Next(-50, 51);
                                num1251 += Main.rand.Next(-50, 51);
                                if (!WorldGen.SolidTile(num1250, num1251) && Collision.CanHit(new Vector2((float)(num1250 * 16), (float)(num1251 * 16)), 1, 1, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height))
                                {
                                    break;
                                }
                                if (num1249 > 100)
                                {
                                    //return;
                                }
                            }
                            npc.ai[1]     = 1f;
                            npc.ai[2]     = (float)num1250;
                            npc.ai[3]     = (float)num1251;
                            npc.netUpdate = true;
                            //return;
                        }
                    }
                }
                else if (npc.ai[1] == 1f)
                {
                    npc.alpha += 3;
                    if (npc.alpha >= 255)
                    {
                        npc.alpha      = 255;
                        npc.position.X = npc.ai[2] * 16f - (float)(npc.width / 2);
                        npc.position.Y = npc.ai[3] * 16f - (float)(npc.height / 2);
                        npc.ai[1]      = 2f;
                        //return;
                    }
                }
                else if (npc.ai[1] == 2f)
                {
                    npc.alpha -= 3;
                    if (npc.alpha <= 0)
                    {
                        npc.alpha = 0;
                        npc.ai[1] = 0f;
                        //return;
                    }
                }
            }

            if (Main.rand.Next(2500) == 0)
            {
                NPC.NewNPC((int)npc.position.X - 150, (int)npc.position.Y - 50, 420);
                NPC.NewNPC((int)npc.position.X + 150, (int)npc.position.Y - 50, 420);
            }

            if (npc.target != -1 && !RunAway)
            {
                if (!Main.player[npc.target].active)
                {
                    if (Helper2.GetNearestAlivePlayer(npc) == -1)
                    {
                        RunAway = true;
                    }
                    else
                    {
                        if (Main.player[Helper2.GetNearestAlivePlayer(npc)].Distance(npc.Center) > 2500f)
                        {
                            RunAway = true;
                        }
                        else
                        {
                            npc.target = Helper2.GetNearestAlivePlayer(npc);
                        }
                    }
                }
            }
            if (Main.dayTime || RunAway || npc.localAI[3] == 1)
            {
                npc.localAI[3] = 1;
                if (Main.npc[(int)npc.ai[2]].type == mod.NPCType("SoulofTrust") && Main.npc[(int)npc.ai[2]].active == true)
                {
                    Main.npc[(int)npc.ai[2]].localAI[3] = 1;
                }
                if (Main.npc[(int)npc.ai[3]].type == mod.NPCType("SoulofTruth") && Main.npc[(int)npc.ai[3]].active == true)
                {
                    Main.npc[(int)npc.ai[3]].localAI[3] = 1;
                }
                npc.life    += 11;
                npc.aiStyle  = 0;
                npc.rotation = 0;
                npc.velocity = Helper2.VelocityFPTP(npc.Center, new Vector2(npc.Center.X, npc.Center.Y - 4815162342), 30.0f);
                CreateDust();
                return;
            }
            if (StateFlag)
            {
                if (
                    !((Main.npc[(int)npc.ai[2]].type == mod.NPCType("SoulofTrust") && Main.npc[(int)npc.ai[2]].active == true)) ||
                    !((Main.npc[(int)npc.ai[3]].type == mod.NPCType("SoulofTruth") && Main.npc[(int)npc.ai[3]].active == true))
                    )
                {
                    StateFlag = false;
                    OnlyPower = true;
                }
            }
            if (OnlyPower)
            {
                SetStage(true);
            }
            else
            {
                SetStage(Main.player[Helper2.GetNearestPlayer(npc)].Distance(npc.Center) <= DistantionToPower);
            }
            SetRotation();
            CreateDust();
            TimeToShoot--;
            if (TimeToShoot <= 0)
            {
                TimeToShoot = (Power) ? PowerShootRate : NormalShootRate;
                Shoot();
            }
        }
Example #18
0
 /// <summary>
 ///     Шифрует строку с помощью пароля и некоторых алгоритмов шифрования. Возвращает строку в кодировке Base64
 /// </summary>
 /// <param name="Text">Входной текст</param>
 /// <param name="Pass">Пароль для шифровки</param>
 /// <returns></returns>
 public string Encode(string Text, string Pass)
 {
     return(Helper2.Encrypt(Helper1.Encrypt(Text), Pass));
 }