Esempio n. 1
0
        Task removeLastArena()
        {
            return(Task.Run(() => {
                TShockAPI.DB.Region region = TShock.Regions.GetRegionByName(getArena());
                int x = region.Area.Location.X, y = region.Area.Location.Y, w = region.Area.Width, h = region.Area.Height;
                for (int i = x; i <= x + w; i++)
                {
                    for (int j = y; j <= y + h; j++)
                    {
                        Main.tile[i, j] = new Tile();

                        TSPlayer.All.SendTileSquare(i, j);
                    }
                }
            }));
        }
Esempio n. 2
0
        void onNPCAIUpdate(NpcAiUpdateEventArgs args)
        {
            if (args.Npc.boss && getArena() != "0")
            {
                Point point = new Point();
                point.X = (int)args.Npc.position.ToTileCoordinates().X;
                point.Y = (int)args.Npc.position.ToTileCoordinates().Y;

                TShockAPI.DB.Region region = TShock.Regions.GetRegionByName(getArena());

                Polygon b1 = new Polygon();
                Polygon b2 = new Polygon();

                Polygon boundary = new Polygon(new float[] { region.Area.X, region.Area.Y, region.Area.X + region.Area.Width, region.Area.Y, region.Area.X + region.Area.Width, region.Area.Y + region.Area.Height, region.Area.X, region.Area.Y + region.Area.Height });
                Polygon p        = new Polygon(new float[] { point.X, point.Y, point.X + 1, point.Y, point.X + 1, point.Y + 1, point.X, point.Y + 1 });
                Intersector.MinimumTranslationVector mtv = new Intersector.MinimumTranslationVector();
                if (Intersector.OverlapConvexPolygons(boundary, p, mtv))
                {
                    TSPlayer.All.SendErrorMessage($"Boss out of range (normal [{mtv.normal.X},{mtv.normal.Y}])");
                    args.Npc.position.X += mtv.normal.X * (mtv.depth * 2);
                    args.Npc.position.Y += mtv.normal.Y * (mtv.depth * 2);
                    args.Npc.netUpdate   = true;
                    args.Npc.netUpdate2  = true;
                }

                /*if (!region.Area.Contains(Main.player[args.Npc.target].position.ToTileCoordinates()))
                 * {
                 *  args.Npc.velocity.X = 0;
                 *  args.Npc.velocity.Y = 0;
                 *  args.Npc.target = -1;
                 * }
                 *
                 * int inside = 0;
                 *
                 * TShock.Players.ForEach((plr) =>
                 *  {
                 *      if (plr.IsLoggedIn && region.Area.Contains(plr.LastNetPosition.ToTileCoordinates()))
                 *      {
                 *          inside++;
                 *      }
                 *  }
                 * );
                 *
                 * if (inside <= 0)
                 *  args.Npc.active = false;*/
            }
        }
Esempio n. 3
0
        private void refreshTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            bool anyRegions = false;

            // Check for regions that have changed.
            lock (players) {
                foreach (Player player in players)
                {
                    bool refreshFlag = false;

                    for (int i = 0; i < player.regions.Count; i++)
                    {
                        Region region = player.regions[i];
                        TShockAPI.DB.Region tRegion = TShock.Regions.GetRegionByName(region.name);

                        if (tRegion == null)
                        {
                            // The region was removed.
                            refreshFlag = true;
                            region.refresh(player.TSPlayer);
                            player.regions.RemoveAt(i--);
                        }
                        else
                        {
                            Rectangle newArea = tRegion.Area;
                            if (!region.command && (!player.viewingNearby || !isPlayerNearby(player.TSPlayer, region.area)))
                            {
                                // The player is no longer near the region.
                                refreshFlag = true;
                                region.refresh(player.TSPlayer);
                                player.regions.RemoveAt(i--);
                            }
                            else
                            if (newArea != region.area)
                            {
                                // The region was resized.
                                if (newArea.Width < 0 || newArea.Height < 0)
                                {
                                    refreshFlag = true;
                                    region.refresh(player.TSPlayer);
                                    player.regions.RemoveAt(i--);
                                }
                                else
                                {
                                    anyRegions  = true;
                                    refreshFlag = true;
                                    region.refresh(player.TSPlayer);
                                    region.area = newArea;
                                    region.calculateArea(player.TSPlayer);
                                }
                            }
                            else
                            {
                                anyRegions = true;
                            }
                        }
                    }

                    if (player.viewingNearby)
                    {
                        anyRegions = true;

                        // Search for nearby regions
                        foreach (TShockAPI.DB.Region tRegion in TShock.Regions.Regions)
                        {
                            if (tRegion.WorldID == Main.worldID.ToString() && tRegion.Area.Width >= 0 && tRegion.Area.Height >= 0)
                            {
                                if (isPlayerNearby(player.TSPlayer, tRegion.Area))
                                {
                                    if (!player.regions.Any(r => r.name == tRegion.Name))
                                    {
                                        refreshFlag = true;
                                        Region region = new Region(tRegion.Name, tRegion.Area, false);
                                        region.calculateArea(player.TSPlayer);
                                        player.regions.Add(region);
#if !SILENT
                                        player.TSPlayer.SendMessage("You see region " + region.name + ".", textColour[region.colour - 13]);
#endif
                                    }
                                }
                            }
                        }
                    }

                    if (refreshFlag)
                    {
                        foreach (Region region in player.regions)
                        {
                            region.setFakeTiles();
                        }
                        foreach (Region region in player.regions)
                        {
                            region.refresh(player.TSPlayer);
                        }
                        foreach (Region region in player.regions.Reverse <Region>())
                        {
                            region.unsetFakeTiles();
                        }
                    }
                }
            }

            if (anyRegions)
            {
                refreshTimer.Interval = 7000;
                refreshTimer.Enabled  = true;
            }
        }
Esempio n. 4
0
        private void commandView(CommandArgs args)
        {
            TShockAPI.DB.Region        tRegion = null;
            List <TShockAPI.DB.Region> matches = new List <TShockAPI.DB.Region>();

            if (args.Parameters.Count < 1)
            {
                args.Player.SendErrorMessage("Usage: /regionview <region name>");
                return;
            }

            // Find the specified region.
            for (int pass = 1; pass <= 3 && tRegion == null && matches.Count == 0; pass++)
            {
                foreach (TShockAPI.DB.Region _tRegion in TShock.Regions.Regions)
                {
                    switch (pass)
                    {
                    case 1:      // Pass 1: exact match
                        if (_tRegion.Name == args.Parameters[0])
                        {
                            tRegion = _tRegion;
                            break;
                        }
                        else if (_tRegion.Name.Equals(args.Parameters[0], StringComparison.OrdinalIgnoreCase))
                        {
                            matches.Add(_tRegion);
                        }
                        break;

                    case 2:      // Pass 2: case-sensitive partial match
                        if (_tRegion.Name.StartsWith(args.Parameters[0]))
                        {
                            matches.Add(_tRegion);
                        }
                        break;

                    case 3:      // Pass 3: case-insensitive partial match
                        if (_tRegion.Name.StartsWith(args.Parameters[0], StringComparison.OrdinalIgnoreCase))
                        {
                            matches.Add(_tRegion);
                        }
                        break;
                    }
                    if (tRegion != null)
                    {
                        break;
                    }
                }
            }

            if (tRegion == null)
            {
                if (matches.Count == 1)
                {
                    tRegion = matches[0];
                }
                else if (matches.Count == 0)
                {
                    args.Player.SendErrorMessage("No such region exists.");
                    return;
                }
                else if (matches.Count > 5)
                {
                    args.Player.SendErrorMessage("Multiple matching regions were found: {0} and {1} more. Please be more specific.", string.Join(", ", matches.Take(5).Select(r => r.Name)), matches.Count - 5);
                    return;
                }
                else if (matches.Count > 1)
                {
                    args.Player.SendErrorMessage("Multiple matching regions were found: {0}. Please be more specific.", string.Join(", ", matches.Select(r => r.Name)));
                    return;
                }
            }

            if (tRegion.Area.Width < 0 || tRegion.Area.Height < 0)
            {
                args.Player.SendErrorMessage("Region {0} contains no tiles. (Found dimensions: {1} × {2})\nUse [c/FF8080:/region resize] to fix it.", tRegion.Name, tRegion.Area.Width, tRegion.Area.Height);
                return;
            }

            lock (players) {
                Player player = findPlayer(args.Player.Index);
                if (player == null)
                {
                    return;
                }

                // Register this region.
                Region region = player.regions.FirstOrDefault(r => r.name == tRegion.Name);
                if (region == null)
                {
                    region = new Region(tRegion.Name, tRegion.Area);
                }
                else
                {
                    player.regions.Remove(region);
                }

                foreach (Region _region in player.regions)
                {
                    _region.setFakeTiles();
                }
                if (region.showArea != region.area)
                {
                    region.refresh(player.TSPlayer);
                }
                player.regions.Add(region);
                region.calculateArea(args.Player);
                region.setFakeTiles();
                region.refresh(player.TSPlayer);

                foreach (Region _region in player.regions.Reverse <Region>())
                {
                    _region.unsetFakeTiles();
                }

                string message = "You are now viewing " + region.name + ".";
                // Show how large the region is if it's large.
                if (tRegion.Area.Width >= Region.MaximumSize || tRegion.Area.Height >= Region.MaximumSize)
                {
                    int num; int num2;
                    if (tRegion.Area.Bottom < args.Player.TileY)
                    {
                        num      = args.Player.TileY - tRegion.Area.Bottom;
                        message += " Borders are " + num + (num == 1 ? " tile" : " tiles") + " above you";
                    }
                    else if (tRegion.Area.Top > args.Player.TileY)
                    {
                        num      = tRegion.Area.Top - args.Player.TileY;
                        message += " Borders are " + (tRegion.Area.Top - args.Player.TileY) + (num == 1 ? " tile" : " tiles") + " below you";
                    }
                    else
                    {
                        num      = args.Player.TileY - tRegion.Area.Top;
                        num2     = tRegion.Area.Bottom - args.Player.TileY;
                        message += " Borders are " + (args.Player.TileY - tRegion.Area.Top) + (num == 1 ? " tile" : " tiles") + " above, " +
                                   (tRegion.Area.Bottom - args.Player.TileY) + (num2 == 1 ? " tile" : " tiles") + " below you";
                    }
                    if (tRegion.Area.Right < args.Player.TileX)
                    {
                        num      = args.Player.TileX - tRegion.Area.Right;
                        message += ", " + (args.Player.TileX - tRegion.Area.Right) + (num == 1 ? " tile" : " tiles") + " west of you.";
                    }
                    else if (tRegion.Area.Left > args.Player.TileX)
                    {
                        num      = tRegion.Area.Left - args.Player.TileX;
                        message += ", " + (tRegion.Area.Left - args.Player.TileX) + (num == 1 ? " tile" : " tiles") + " east of you.";
                    }
                    else
                    {
                        num      = args.Player.TileX - tRegion.Area.Left;
                        num2     = tRegion.Area.Right - args.Player.TileX;
                        message += ", " + (args.Player.TileX - tRegion.Area.Left) + (num == 1 ? " tile" : " tiles") + " west, " +
                                   (tRegion.Area.Right - args.Player.TileX) + (num2 == 1 ? " tile" : " tiles") + " east of you.";
                    }
                }
                args.Player.SendMessage(message, textColour[region.colour - 13]);

                refreshTimer.Interval = 7000;
                refreshTimer.Enabled  = true;
            }
        }
Esempio n. 5
0
        void setArena(CommandArgs args)
        {
            if (args.Parameters.Count <= 0)
            {
                args.Player.SendWarningMessage("type '/setarena help' - for more info");
                return;
            }
            var token = args.Parameters[0];

            switch (token)
            {
            case "remove":
                if (getArena() != "0")
                {
                    TShockAPI.DB.Region _region = TShock.Regions.GetRegionByName(getArena());
                    removeLastArena().ContinueWith((d) => {
                        removeArena();
                        args.Player.SendSuccessMessage("Arena has been removed successfully");
                    });
                }
                else
                {
                    args.Player.SendWarningMessage("Arena is not yet set");
                }
                break;

            case "this":
                TShockAPI.DB.Region region_ = args.Player.CurrentRegion;
                if (region_ != null)
                {
                    if (region_.Owner == args.Player.Name)
                    {
                        if (getArena() != "0")
                        {
                            removeLastArena().ContinueWith((d1) => {
                                removeArena();
                                generateArena(region_.Area.Location.X, region_.Area.Location.Y, region_.Area.Width, region_.Area.Height).ContinueWith((d2) => {
                                    saveArena(region_.Name);
                                    args.Player.SendSuccessMessage("Arena has been set successfully");
                                });
                            });
                        }
                        else
                        {
                            generateArena(region_.Area.Location.X, region_.Area.Location.Y, region_.Area.Width, region_.Area.Height).ContinueWith((d) => {
                                saveArena(region_.Name);
                                args.Player.SendSuccessMessage("Arena has been set successfully");
                            });
                        }
                    }
                    else
                    {
                        args.Player.SendWarningMessage("This is not your region man!");
                    }
                }
                else
                {
                    args.Player.SendErrorMessage("You are not currently standing in a region.");
                }
                break;

            case "check":
                if (getArena() == "0")
                {
                    args.Player.SendWarningMessage("arena not set");
                    if (args.Player.CurrentRegion != null)
                    {
                        if (args.Player.CurrentRegion.Owner == args.Player.Name)
                        {
                            args.Player.SendInfoMessage($"but you are currently standing in [{args.Player.CurrentRegion.Name}] region. If you want to set this region just type /setarena this");
                        }
                    }
                    break;
                }

                if (args.Player.CurrentRegion != null)
                {
                    args.Player.SendInfoMessage($"Region: {args.Player.CurrentRegion.Name}");
                    if (args.Player.CurrentRegion.Name == getArena())
                    {
                        args.Player.SendInfoMessage("You're inside the arena");
                    }
                    else
                    {
                        args.Player.SendWarningMessage("You're outside the arena");
                    }
                }
                else
                {
                    args.Player.SendWarningMessage("Your not in a Region");
                }
                break;

            case "help":
                args.Player.SendInfoMessage("Before using this command, make sure to use the House Region plugin and you must have a valid Region.\n\n" +
                                            "/setarena regionname - setting the arena region for bossfight\n" +
                                            "/setarena check - checks if the region has been set\n" +
                                            "/setarena remove - removes arena platforms if it has been set\n" +
                                            "/setarena help - show help information");
                break;

            default:
                TShockAPI.DB.Region region = TShock.Regions.GetRegionByName(token);
                if (region != null)
                {
                    if (region.Owner == args.Player.Name)
                    {
                        if (getArena() != "0")
                        {
                            removeLastArena().ContinueWith((d1) => {
                                removeArena();
                                generateArena(region.Area.Location.X, region.Area.Location.Y, region.Area.Width, region.Area.Height).ContinueWith((d2) => {
                                    saveArena(token);
                                    args.Player.SendSuccessMessage("Arena has been set successfully");
                                });
                            });
                        }
                        else
                        {
                            generateArena(region.Area.Location.X, region.Area.Location.Y, region.Area.Width, region.Area.Height).ContinueWith((d) => {
                                saveArena(token);
                                args.Player.SendSuccessMessage("Arena has been set successfully");
                            });
                        }
                    }
                    else
                    {
                        args.Player.SendWarningMessage($"Region [{token}] is not yours");
                    }
                }
                else
                {
                    args.Player.SendErrorMessage($"Region [{token}] not found, please create a region using /house def");
                }
                break;
            }
        }
Esempio n. 6
0
 public void ABStoggle(CommandArgs args)
 {
     BossToggle = !BossToggle;
     if (BossToggle == true)
     {
         foreach (TShockAPI.DB.Region reg in TShock.Regions.ListAllRegions(Main.worldID.ToString()))
         {
             if (reg.Name == "arena") { arenaregion = reg; }
         }
         if (arenaregion.Name != "arena") { TShockAPI.TShock.Utils.Broadcast("Error: Region 'arena' is not defined.", Color.Red); BossToggle = false; }
     }
     args.Player.SendMessage("Boss battles now: "+ ((BossToggle)?"Enabled":"Disabled"));
     BossTimer = configObj.BossTimer;
 }
Esempio n. 7
0
 private void startBossBattle()
 {
     NPC npc = new NPC();
     arenaregion = TShock.Regions.GetRegionByName("arena");
     int arenaX = arenaregion.Area.X + (arenaregion.Area.Width / 2);
     int arenaY = arenaregion.Area.Y + (arenaregion.Area.Height / 2);
     string broadcastString = "Boss selected:";
     BossSet bossSet = configObj.BossList[rndGen.Next(0, configObj.BossList.Count)];
     foreach (BossObj b in bossSet.bosses)
     {
         npc = TShockAPI.TShock.Utils.GetNPCById(b.id);
         TSPlayer.Server.SpawnNPC(npc.type, npc.name, b.amt, arenaX, arenaY, 30, 30);
         broadcastString += " " + b.amt + "x " + npc.name + " +";
     }
     broadcastString = broadcastString.Remove(broadcastString.Length - 2);
     TShockAPI.TShock.Utils.Broadcast(broadcastString, Color.Aquamarine);
     for (int i = 0; i < Main.npc.Length; i++)
     {
         if (Main.npc[i].boss) bossList.Add(Main.npc[i]);
     }
 }
Esempio n. 8
0
 private void spawnMinions()
 {
     //TODO: num of henchmen based on players in arena, spawn life when boss is at half health.
     NPC npc = new NPC();
     npc = TShockAPI.TShock.Utils.GetNPCById(configObj.MinionsList[rndGen.Next(0, configObj.MinionsList.Length)]);
     arenaregion = TShock.Regions.GetRegionByName("arena");
     int arenaX = arenaregion.Area.X + (arenaregion.Area.Width / 2);
     int arenaY = arenaregion.Area.Y + (arenaregion.Area.Height / 2);
     int henchmenNumber = rndGen.Next(configObj.MinionsMinMax[0], configObj.MinionsMinMax[1] + 1);
     TSPlayer.Server.SpawnNPC(npc.type, npc.name, henchmenNumber, arenaX, arenaY, 30, 30);
     if (configObj.MinionsAnnounce) { TShockAPI.TShock.Utils.Broadcast("Spawning Boss Minions: " + henchmenNumber + "x " + npc.name + "!", Color.SteelBlue); }
 }