Exemplo n.º 1
0
 public void Add(Zone zone) => Zones.Add(zone);
Exemplo n.º 2
0
 public void Remove(Zone zone) => Zones.Remove(zone);
Exemplo n.º 3
0
        void ExecuteZone(Zone zone, BasePlayer player)
        {
            bool addPlayer = false;
            bool addOne    = false;

            switch (zone.Method)
            {
            case Methods.Always:
                if (zone.Amount != -1)
                {
                    if (zone.Amount != zone.Players.Count)
                    {
                        addPlayer = true;
                    }
                    else
                    {
                        return;
                    }
                }
                break;

            case Methods.PerPlayer:
            {
                if (zone.Amount != -1)
                {
                    if (zone.Players.Count > 0)
                    {
                        bool found = false;

                        foreach (ZonePlayer zp in zone.Players)
                        {
                            if (zp.UserId == player.userID)
                            {
                                found = true;

                                if (zp.Count == zone.Amount)
                                {
                                    return;
                                }
                                else
                                {
                                    zp.Count++;
                                }

                                break;
                            }
                        }

                        if (!found)
                        {
                            addPlayer = true;
                            addOne    = true;
                        }
                    }
                    else
                    {
                        addPlayer = true;
                        addOne    = true;
                    }
                }
                else
                {
                    if (zone.Players.Count > 0)
                    {
                        foreach (ZonePlayer zp in zone.Players)
                        {
                            if (zp.UserId == player.userID)
                            {
                                return;
                            }
                        }

                        addPlayer = true;
                    }
                    else
                    {
                        addPlayer = true;
                    }
                }
            }
            break;

            case Methods.PerDay:
                // TODO: per day
                break;

            case Methods.PerGameDay:
                // TODO: per game day
                break;
            }

            if (addPlayer)
            {
                zone.Add(new ZonePlayer {
                    UserId = player.userID, Count = addOne ? 1 : 0
                });
            }

            foreach (string s in zone.Commands)
            {
                string command = s.Replace("$player.id", player.userID.ToString())
                                 .Replace("$player.name", player.displayName)
                                 .Replace("$player.xyz", player.transform.position.x + " " + player.transform.position.y + " " + player.transform.position.z)
                                 .Replace("$player.x", player.transform.position.x.ToString())
                                 .Replace("$player.y", player.transform.position.y.ToString())
                                 .Replace("$player.z", player.transform.position.z.ToString());

                if (command.StartsWith("sayto", StringComparison.CurrentCultureIgnoreCase))
                {
                    PrintToChat(player, command.Substring(6));
                }

                rust.RunServerCommand(command);
            }
        }