Example #1
0
        public override void RandomUpdate(int i, int j)
        {
            // TODO check this net message after jopo does the example bush
            //if (Main.netMode == 1)
            //    NetMessage.SendTileSquare(Main.myPlayer, i, j, 1);
            Tile tile = Main.tile[i, j];

            if (tile.frameX == 36 && ErilipahTile.OffScreen(i, j))
            {
                WorldGen.KillTile(i, j);
            }

            if (tile.frameX == 0 && tile.frameY == 0)
            {
                tile.frameX = 36;
                if (Main.tile[i + 1, j].type == Type)
                {
                    Main.tile[i + 1, j].frameX = 54;
                }

                Burst(i, j);
            }

            if (Main.netMode == 2 /*Sync to clients when run on the server*/)
            {
                NetMessage.SendTileSquare(-1, i, j, 2, TileChangeType.None);
            }
        }
Example #2
0
        public override void AI()
        {
            const float speed       = 5f;
            const int   chooseLeave = 30;
            const int   finishSnuff = 100;

            if (npc.target == -1 || npc.target == 255)
            {
                npc.target = npc.FindClosestPlayer();
            }

            bool invalidTorch = Torch == Point.Zero || !IsLight(Torch.X, Torch.Y);
            bool shouldLeave  = npc.life < 30 || npc.ai[2] < -chooseLeave;

            if (shouldLeave || invalidTorch)
            {
                if (npc.ai[2] > 0)
                {
                    npc.ai[2] = 0;
                }
                npc.ai[2]--;

                if (shouldLeave)
                {
                    npc.netUpdate = true;
                    Leave();
                }
                else
                {
                    npc.netUpdate = true;
                    npc.velocity /= 2;
                    Torch         = FindTorch();
                }
            }
            else
            {
                float dist = Vector2.Distance(npc.Center, Torch.ToWorldCoordinates());
                if (dist > 3)
                {
                    float distToSpeed = MathHelper.Lerp(speed, speed / 4, 1 - dist / 300f);
                    npc.velocity = npc.DirectionTo(Torch.ToWorldCoordinates()) * Math.Min(10, distToSpeed);
                }
                else
                {
                    if (npc.ai[2] < 0)
                    {
                        npc.ai[2] = 0;
                    }

                    // Increase faster the more there are focused on this boi
                    for (int i = 0; i < Main.maxNPCs; i++)
                    {
                        if (Main.npc[i].active && Main.npc[i].type == npc.type && Vector2.Distance(Main.npc[i].Center, npc.Center) < 6)
                        {
                            npc.ai[2]++;
                        }
                    }

                    npc.velocity = Vector2.Zero;
                    npc.Center   = Torch.ToWorldCoordinates();

                    if (npc.ai[2] % 20 == 0)
                    {
                        Main.PlaySound(SoundID.LiquidsHoneyLava, npc.Center);
                    }

                    if (npc.ai[2] > finishSnuff)
                    {
                        npc.ai[2] = 0;
                        ErilipahTile.Snuff(Torch.X, Torch.Y, true);
                    }
                }
            }

            SpewDust();
        }