Ejemplo n.º 1
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;
            }
        }