示例#1
0
        public void OnDamage(object sender, TShockAPI.GetDataHandlers.PlayerDamageEventArgs args)
        {
            Region r = TShock.Regions.GetTopRegion(
                TShock.Regions.InAreaRegion((int)Main.player[args.ID].position.X / 16, (int)Main.player[args.ID].position.Y / 16));

            if (r != null)
            {
                FlaggedRegion reg = regionManager.getRegion(r.Name);
                if (reg != null)
                {
                    List <Flags> flags = reg.getFlags();
                    if (flags.Contains(Flags.HEALONDAMAGE))
                    {
                        int heal   = 0;
                        int damage = Math.Max(args.Damage * (args.Critical ? 2 : 1) -
                                              (int)(Math.Round(Main.player[args.ID].statDefense * .5)), 1);

                        var items = TShock.Utils.GetItemByIdOrName("heart");
                        while (heal < damage)
                        {
                            Utilities.GiveItem(items[0].name, (int)Main.player[args.ID].position.X, (int)Main.player[args.ID].position.Y, items[0].width,
                                               items[0].height, items[0].type, 1, items[0].prefix, args.ID, Main.player[args.ID].velocity);
                            heal += 20;
                        }
                    }
                }
            }
        }
示例#2
0
        private void OnUpdate(EventArgs args)
        {
            lock ( players )
            {
                foreach (RegionPlayer ply in players)
                {
                    if (ply != null)
                    {
                        ply.Update();
                    }
                }
            }

            DateTime now = DateTime.Now;

            if ((now - lastUpdate).TotalSeconds > 0)
            {
                lastUpdate = now;
                lock (Main.npc)
                {
                    foreach (NPC npc in Main.npc)
                    {
                        if (!npc.active)
                        {
                            continue;
                        }

                        Region r = TShock.Regions.GetTopRegion(
                            TShock.Regions.InAreaRegion((int)npc.position.X / 16, (int)npc.position.Y / 16));
                        if (r != null)
                        {
                            FlaggedRegion reg = regions.getRegion(r.Name);
                            if (reg != null)
                            {
                                List <Flags> flags = reg.getFlags();
                                if (flags.Contains(Flags.MOBKILL))
                                {
                                    npc.StrikeNPC(9999, 0f, 0);
                                    NetMessage.SendData(23, -1, -1, "", npc.whoAmI, 0f, 0f, 0f, 0);
                                }
                                else if (flags.Contains(Flags.NOMOB))
                                {
                                    npc.active = false;
                                    NetMessage.SendData(23, -1, -1, "", npc.whoAmI, 0f, 0f, 0f, 0);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        private void ViewFlags(CommandArgs args)
        {
            if (args.Parameters.Count == 1)
            {
                FlaggedRegion region = regions.getRegion(args.Parameters[0]);
                if (region == null)
                {
                    args.Player.SendErrorMessage("Region '{0}' is not a region flag defined region.", args.Parameters[0]);
                    return;
                }

                string flags = string.Join(", ", region.getFlags().Select(f => f.ToString()));
                args.Player.SendInfoMessage("Flags for '{0} are: {1}", region.getRegion().Name, flags);
                return;
            }

            args.Player.SendErrorMessage("Usage: /regview[/rv] [region name] - Views the flags on a given region.");
        }
示例#4
0
        public void OnNPCStrike(object sender, TShockAPI.GetDataHandlers.NPCStrikeEventArgs args)
        {
            Region r = TShock.Regions.GetTopRegion(
                TShock.Regions.InAreaRegion((int)Main.npc[args.ID].position.X / 16, (int)Main.npc[args.ID].position.Y / 16));

            if (r != null)
            {
                FlaggedRegion reg = regionManager.getRegion(r.Name);
                if (reg != null)
                {
                    List <Flags> flags = reg.getFlags();
                    if (flags.Contains(Flags.GODMOB))
                    {
                        args.Handled           = true;
                        Main.npc[args.ID].life = Main.npc[args.ID].lifeMax;
                        NetMessage.SendData(23, -1, -1, "", args.ID, 0f, 0f, 0f, 0);
                    }
                }
            }
        }
示例#5
0
        public void Update()
        {
            e = new SendDataEventArgs();
            DateTime now = DateTime.Now;

            Region r = TShock.Regions.GetTopRegion(TShock.Regions.InAreaRegion(player.TileX, player.TileY));

            bool inPVPZone   = false;
            bool inNoPVPZone = false;

            bool warning = ((now - lastWarned).TotalSeconds >= 5);

            if (r != null)
            {
                FlaggedRegion reg = regionManager.getRegion(r.Name);
                if (reg != null)
                {
                    List <Flags> flags = reg.getFlags();
                    if (flags.Contains(Flags.PRIVATE) && !player.Group.HasPermission("enter." + r.Name + "")) // && !r.HasPermissionToBuildInRegion(player))
                    {
                        Vector2 pos = positions.getpos();
                        player.Teleport((int)pos.X, (int)pos.Y);
                        if (warning)
                        {
                            player.SendMessage(String.Format("[SYSTEM] You can't enter '{0}' at your level!", r.Name), Color.OrangeRed);
                            lastWarned = now;
                        }
                    }
                    List <string> bannedItems = new List <string>();
                    if (flags.Contains(Flags.ITEMBAN) && InvalidInventory(reg.getBannedItems(), out bannedItems) && !player.Group.HasPermission("rf.ibpass"))
                    {
                        Vector2 pos  = positions.getpos();
                        Vector2 diff = pos - player.TPlayer.position;

                        if (((diff.X * diff.X) + (diff.Y * diff.Y)) > (100 * 100))
                        {
                            player.Teleport((int)pos.X, (int)pos.Y);
                        }

                        else
                        {
                            player.Spawn(Main.spawnTileX, Main.spawnTileY);
                        }

                        if (warning)
                        {
                            player.SendMessage(String.Format("The following are banned in that area: {0}", string.Join(",", bannedItems)), Color.Red);
                            lastWarned = now;
                        }
                    }
                    if (flags.Contains(Flags.DEATH) && !r.HasPermissionToBuildInRegion(player))
                    {
                        NetMessage.SendData((int)PacketTypes.PlayerDamage, -1, -1, " died Indiana Jone's style.", player.Index, 0, 999999,
                                            (float)0);
                        if (warning)
                        {
                            player.SendMessage("You just stumbled into a death trap... no pun intended.", Color.Yellow);
                            lastWarned = now;
                        }
                    }
                    if (flags.Contains(Flags.PVP))
                    {
                        if (!player.TPlayer.hostile)
                        {
                            player.SendMessage("[ARENA] PvP Enabled.", Color.Red);
                        }
                        if (e.MsgId == PacketTypes.ChatText && !e.Handled)
                        {
                            if (e.number2 == 255 && e.number3 == 255 && e.number4 == 255)
                            {
                                if (e.text.Contains("has enabled PvP!") || e.text.Contains("has disabled PvP!"))
                                {
                                    e.Handled = true;
                                }
                            }
                        }
                        player.TPlayer.hostile = true;
                        player.SendData(PacketTypes.TogglePvp);
                        NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index);
                        inPVPZone = true;
                        forcedPVP = true;
                    }
                    if (flags.Contains(Flags.NOPVP))
                    {
                        if (player.TPlayer.hostile)
                        {
                            player.SendMessage("[SAFE] PvP Disabled.", Color.Red);
                        }
                        if (e.MsgId == PacketTypes.ChatText && !e.Handled)
                        {
                            if (e.number2 == 255 && e.number3 == 255 && e.number4 == 255)
                            {
                                if (e.text.Contains("has enabled PvP!") || e.text.Contains("has disabled PvP!"))
                                {
                                    e.Handled = true;
                                }
                            }
                        }
                        player.TPlayer.hostile = false;
                        player.SendData(PacketTypes.TogglePvp);
                        NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index);
                        inNoPVPZone = true;
                        removedPVP  = true;
                    }
                    if (flags.Contains(Flags.HURT))
                    {
                        if ((now - lastDamageUpdate).TotalSeconds > 0)
                        {
                            lastDamageUpdate = now;
                            if (reg.getDPS() > 0)
                            {
                                int damage = (player.TPlayer.statDefense / 2) + reg.getDPS();
                                NetMessage.SendData((int)PacketTypes.PlayerDamage, -1, -1, " died a slow, horrible death.", player.Index, 0, damage,
                                                    (float)0);
                            }
                        }
                    }
                    if (flags.Contains(Flags.HEAL) && reg.getHPS() > 0)
                    {
                        if ((now - lastHealUpdate).TotalSeconds >= reg.getHPS())
                        {
                            lastHealUpdate = now;
                            var    items = TShock.Utils.GetItemByIdOrName("heart");
                            Player ply   = player.TPlayer;
                            Utils.GiveItem(items[0].name, (int)ply.position.X, (int)ply.position.Y, items[0].width,
                                           items[0].height, items[0].type, 1, items[0].prefix, player.Index, ply.velocity);
                        }
                    }
                }
            }

            if (!inPVPZone && forcedPVP)
            {
                forcedPVP = false;
                player.TPlayer.hostile = false;
                player.SendData(PacketTypes.TogglePvp);
                NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index);
                player.SendMessage("[FREE] PvP can be toggled.", Color.MediumSeaGreen);
            }

            if (!inNoPVPZone && removedPVP)
            {
                removedPVP             = false;
                player.TPlayer.hostile = false;
                player.SendData(PacketTypes.TogglePvp);
                NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index);
                player.SendMessage("[FREE] PvP can be toggled.", Color.MediumSeaGreen);
            }

            if ((now - lastUpdate).TotalSeconds > 1)
            {
                positions.enqueue(player.TPlayer.position);
                lastUpdate = now;
            }
        }
示例#6
0
        public void Update()
        {
            DateTime now = DateTime.Now;

            Region r = TShock.Regions.GetTopRegion(TShock.Regions.InAreaRegion(player.TileX, player.TileY));

            bool inPVPZone       = false;
            bool inNoPVPZone     = false;
            bool inTempGroupZone = false;

            bool warning = ((now - lastWarned).TotalSeconds > 5);

            if (r != null)
            {
                FlaggedRegion reg = regionManager.getRegion(r.Name);
                if (reg != null)
                {
                    List <Flags> flags = reg.getFlags();
                    if (flags.Contains(Flags.PRIVATE) && !r.HasPermissionToBuildInRegion(player))
                    {
                        Vector2 pos = positions.getTP();
                        player.Teleport((int)pos.X, (int)pos.Y);
                        if (warning)
                        {
                            player.SendMessage("You are barred from entering that region.", Color.Red);
                            lastWarned = now;
                        }
                    }
                    List <string> bannedItems = new List <string>();
                    if (flags.Contains(Flags.ITEMBAN) && InvalidInventory(reg.getItembans(), out bannedItems))
                    {
                        Vector2 pos  = positions.getTP();
                        Vector2 diff = pos - player.TPlayer.position;
                        if (((diff.X * diff.X) + (diff.Y * diff.Y)) > (100 * 100))
                        {
                            player.Teleport((int)pos.X, (int)pos.Y);
                        }
                        else
                        {
                            player.Spawn(Main.spawnTileX, Main.spawnTileY);
                        }


                        if (warning)
                        {
                            player.SendMessage(String.Format("The following are banned in that area: {0}", string.Join(",", bannedItems)), Color.Red);
                            lastWarned = now;
                        }
                    }
                    if (flags.Contains(Flags.DEATH) && !r.HasPermissionToBuildInRegion(player))
                    {
                        NetMessage.SendData((int)PacketTypes.PlayerDamage, -1, -1, " died Indiana Jone's style.", player.Index, 0, 999999,
                                            (float)0);
                        if (warning)
                        {
                            player.SendMessage("You just stumbled into a death trap... no pun intended.", Color.Yellow);
                            lastWarned = now;
                        }
                    }
                    if (flags.Contains(Flags.PVP))
                    {
                        if (!player.TPlayer.hostile)
                        {
                            player.SendMessage("PVP arena entered, pvp enabled.", Color.Green);
                        }

                        player.TPlayer.hostile = true;
                        player.SendData(PacketTypes.TogglePvp);
                        NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index);
                        inPVPZone = true;
                        forcedPVP = true;
                    }
                    if (flags.Contains(Flags.NOPVP))
                    {
                        if (player.TPlayer.hostile)
                        {
                            player.SendMessage("PVP free area entered, pvp disabled.", Color.Green);
                        }

                        player.TPlayer.hostile = false;
                        player.SendData(PacketTypes.TogglePvp);
                        NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index);
                        inNoPVPZone = true;
                        removedPVP  = true;
                    }
                    if (flags.Contains(Flags.HURT))
                    {
                        if ((now - lastDamageUpdate).TotalSeconds > 0)
                        {
                            lastDamageUpdate = now;
                            if (reg.getDPS() > 0)
                            {
                                int damage = (player.TPlayer.statDefense / 2) + reg.getDPS();
                                NetMessage.SendData((int)PacketTypes.PlayerDamage, -1, -1, " died a slow, horrible death.", player.Index, 0, damage,
                                                    (float)0);
                            }
                        }
                    }
                    if (flags.Contains(Flags.HEAL) && reg.getHPS() > 0)
                    {
                        if ((now - lastHealUpdate).TotalSeconds >= reg.getHPS())
                        {
                            lastHealUpdate = now;
                            var    items = TShock.Utils.GetItemByIdOrName("heart");
                            Player ply   = player.TPlayer;
                            Utilities.GiveItem(items[0].name, (int)ply.position.X, (int)ply.position.Y, items[0].width,
                                               items[0].height, items[0].type, 1, items[0].prefix, player.Index, ply.velocity);
                        }
                    }
                    if (flags.Contains(Flags.TEMPGROUP))
                    {
                        if (player.Group != reg.getTempGroup())
                        {
                            player.Group = reg.getTempGroup();
                            tempGroup    = true;
                            player.SendInfoMessage("Your group has been changed to {0}.", player.Group);
                        }
                        inTempGroupZone = true;
                    }
                }
            }

            if (!inPVPZone && forcedPVP)
            {
                forcedPVP = false;
                player.TPlayer.hostile = false;
                player.SendData(PacketTypes.TogglePvp);
                NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index);
                player.SendMessage("PVP arena left, pvp disabled.", Color.Green);
            }

            if (!inNoPVPZone && removedPVP)
            {
                removedPVP             = false;
                player.TPlayer.hostile = false;
                player.SendData(PacketTypes.TogglePvp);
                NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index);
                player.SendMessage("PVP free area left, pvp disabled.", Color.Green);
            }

            if (!inTempGroupZone && tempGroup)
            {
                if (player.Group != OriginalGroup)
                {
                    player.Group = OriginalGroup;
                    player.SendInfoMessage("Your group has been changed back to {0}.", player.Group);
                }
                tempGroup = false;
            }

            if ((now - lastUpdate).TotalSeconds > 1)
            {
                positions.enqueue(player.TPlayer.position);
                lastUpdate = now;
            }
        }