Пример #1
0
        public void DeleteProperty(Client sender, int id = -1)
        {
            Player user = Player.PlayerData[sender];

            if (!(user.MasterAccount.AdminLevel >= 4))
            {
                Message.NotAuthorised(sender); return;
            }
            if (id == -1)
            {
                Message.Syntax(sender, "/aproperty delete [ID] (ID must be valid, /getpropertyid or /propertylookup)"); return;
            }
            if (id > PropertyManager.Properties.Count)
            {
                API.SendErrorNotification(sender, "Could not find property at ID: " + id); return;
            }

            Property propertyToDelete = PropertyManager.Properties[(id - 1)];

            if (propertyToDelete == null)
            {
                API.SendErrorNotification(sender, "Could not find property at ID: " + id); return;
            }

            PropertyManager mng = new PropertyManager();

            mng.DeleteAllPropertyKeys(id);

            PropertyRepository.DeleteProperty(propertyToDelete);
            return;
        }
Пример #2
0
        // ------- Non CMDs

        public void CreateProperty(Client sender, int type = -1, string name = "")
        {
            Player user = Player.PlayerData[sender];

            if (!(user.MasterAccount.AdminLevel >= 4))
            {
                Message.NotAuthorised(sender); return;
            }

            // --- Handle Command Parameter checking
            if ((type < 0 || type > 2) || name == "")
            {
                Message.Syntax(sender, "/aproperty create [Type] [Name] (Types: 0 - General | 1 - Residential | 2 - Commercial | 3 - Industrial)");
                return;
            }

            if (PropertyRepository.GetPropertyByPropertyName(name) != null)
            {
                API.SendErrorNotification(sender, "That property name already exists");
                return;
            }

            // --- Create the property
            //Property newProperty = new Property();
            //newProperty.Type = (PropertyType)type; // Cast int to PropertyType
            //newProperty.Name = name;
            //newProperty.EnterPosition = sender.position;

            //PropertyManager mng = new PropertyManager();
            //mng.InitProperty(newProperty);

            //// --- Add to Entities
            //PropertyManager.Properties.Add(newProperty);
            //await PropertyRepository.AddNewProperty(newProperty);
        }
Пример #3
0
        private async void OnResourceStart()
        {
            Properties = await PropertyRepository.GetAllProperties();

            Businesses = await PropertyRepository.GetAllBusinesses();

            foreach (Property prop in Properties)
            {
                InitProperty(prop);
            }

            foreach (Business bus in Businesses)
            {
                BusinessManager.ConfigureBusiness(bus);
            }

            RegisterDoormanagerDoors();

            API.createMarker(20, new Vector3(-248.1604f, 6212.266f, 31.5), new Vector3(0, 0, 0), new Vector3(0, 0, 0),
                             new Vector3(0.5, 0.5, 0.5), 255, 25, 159, 235, 0);

            API.createTextLabel("Helmuts Autos", new Vector3(-248.1604f, 6212.266f, 32), 8, 0.85f);

            LoadPropertyMaps();
        }
Пример #4
0
        public async void EditBusiness(Client sender, int id = -1, string field = "", string value = "")
        {
            Player user = Player.PlayerData[sender];

            if (!(user.MasterAccount.AdminLevel >= 4))
            {
                Message.NotAuthorised(sender); return;
            }
            if (field == "" && value == "")
            {
                EditBusinessCommandUsage(sender);
                return;
            }

            Property        propertyToEdit = null;
            PropertyManager mng            = new PropertyManager();

            if (id == -1)
            {
                float minRange = 2.5f;
                propertyToEdit = mng.GetClosestPropertyToLocation(sender.position, minRange);
                id             = propertyToEdit.Id;
            }
            else
            {
                if (id > PropertyManager.Properties.Count)
                {
                    API.shared.SendErrorNotification(sender, "Error: Could not find business"); return;
                }
                propertyToEdit = PropertyManager.Properties[id - 1];
            }

            Business bizzToEdit = null;

            if (bizzToEdit == null)
            {
                API.shared.SendErrorNotification(sender, "Error: Could not find business"); return;
            }

            if (field == "Subtype")
            {
                if (Int32.Parse(value) >= 0)
                {
                    bizzToEdit.SubType = (BusinessType)Int32.Parse(value);
                    Message.Info(sender, "You have set " + bizzToEdit.Name + "'s subtype to " + bizzToEdit.SubType);
                }
            }

            await PropertyRepository.UpdateAsync(bizzToEdit);
        }
Пример #5
0
        public async void SetInteriorCommand(Client sender, int num = -1, string name = "")
        {
            Player user = Player.PlayerData[sender];

            if (!(user.MasterAccount.AdminLevel >= 4))
            {
                Message.NotAuthorised(sender); return;
            }

            if (name == "")
            {
                Message.Syntax(sender, "/setinterior [ID (-1 for closest)] [Name]"); return;
            }

            PropertyManager mng = new PropertyManager();
            Property        prop;

            prop = num == -1 ? mng.GetClosestPropertyToLocation(sender.position, 2.0f) : PropertyManager.Properties[num];

            int     Dimension   = prop.Id;
            Vector3 interiorPos = new Vector3();

            interiorPos = GetInteriorCoordinatesFromName(name);
            if (interiorPos.Equals(new Vector3()))
            {
                Message.Syntax(sender, "Cannot find interior: " + name); return;
            }

            prop.IsEnterable  = true;
            prop.ExitPosition = interiorPos;
            prop.Dimension    = Dimension;

            API.setTextLabelColor(prop.labelHandle, 100, 223, 0, 255);
            API.SendWarningNotification(sender, ("You have edited " + prop.Name + "'s ExitPos to: " + interiorPos.ToString() + " (Dimension: " + prop.Id + ")"));

            await PropertyRepository.UpdateAsync(prop);
        }
Пример #6
0
        public async void EditProperty(Client sender, int id = -1, string field = "", string value = "", string val2 = "")
        {
            Player user = Player.PlayerData[sender];

            if (!(user.MasterAccount.AdminLevel >= 4))
            {
                Message.NotAuthorised(sender); return;
            }
            if (field == "" && value == "")
            {
                PropertyCommandUsage(sender);
                return;
            }

            Property        propertyToEdit = null;
            PropertyManager mng            = new PropertyManager();

            if (id == -1)
            {
                float minRange = 2.5f;
                propertyToEdit = mng.GetClosestPropertyToLocation(sender.position, minRange);
                if (propertyToEdit == null)
                {
                    API.SendErrorNotification(sender, "Error: Could not find property"); return;
                }
                id = propertyToEdit.Id;
            }
            else
            {
                if (id > PropertyManager.Properties.Count)
                {
                    API.SendErrorNotification(sender, "Error: Could not find property"); return;
                }
                propertyToEdit = PropertyManager.Properties[id - 1];
            }

            // --- Property is valid, found and ready to edit

            if (field == "Name")
            {
                value += (" " + val2);

                propertyToEdit.Name = value;
                API.setTextLabelText(propertyToEdit.labelHandle, value);
            }

            if (field == "Type")
            {
                PropertyType typeID = ((PropertyType)Int32.Parse(value));
                if (!mng.IsValidTypeID(typeID))
                {
                    PropertyCommandUsage(sender); return;
                }

                propertyToEdit.Type = typeID;

                Globals.Colour col = new Globals.Colour(255, 255, 255);
                switch (typeID)
                {
                case PropertyType.General:    { col = Property.generalColour; break; }

                case PropertyType.Residential: { col = Property.residentialColour; break; }

                case PropertyType.Commericial: { col = Property.commercialColour; break; }

                case PropertyType.Industrial: { col = Property.industrialColour; break; }
                }

                API.setMarkerColor(propertyToEdit.pickupHandle, col.a, col.r, col.g, col.b);
                API.SendWarningNotification(sender, ("You have edited " + propertyToEdit.Name + "'s type ID to: " + propertyToEdit.Type));
            }

            if (field == "Owner")
            {
                if (val2 == "")
                {
                    PropertyCommandUsage(sender); return;
                }

                int val = Int32.Parse(val2);
                int TYPE_PLAYER = 0; int TYPE_COMPANY = 1;
                if (val != TYPE_PLAYER && val != TYPE_COMPANY)
                {
                    PropertyCommandUsage(sender); return;
                }

                // -- Delete all property keys
                mng.DeleteAllPropertyKeys(id);

                // -- Create a new key and give it to X
                if (val == TYPE_PLAYER)
                {
                    Player    recipient = Player.GetPlayerData(value);
                    Inventory key       = null;

                    propertyToEdit.OwnerId = recipient.Id;

                    // --- If the player is online, we should handle it
                    if (API.isPlayerConnected(recipient.Client))   // -- Check may be redundant. Added as extra security
                    {
                        key = new Inventory()
                        {
                            Name     = propertyToEdit.Name + " key",
                            Type     = InventoryType.PropertyKey,
                            Value    = propertyToEdit.Id + "," + Globals.GetUniqueString(),
                            Quantity = 1,
                            OwnerId  = recipient.Id,
                        };
                        recipient.Inventory.Add(key);
                    }
                    else
                    {
                        API.SendErrorNotification(sender, "Player could not be found, use their full name with underscores");
                    }
                    InventoryRepository.AddNewInventoryItem(key);
                    key.Id = InventoryRepository.GetInventoryItemOfTypeByValue(InventoryType.PropertyKey, key.Value).Id;
                    API.SendWarningNotification(sender, "You have set the Owner of " + propertyToEdit.Name + " to " + recipient.Username);
                }
                else if (val == TYPE_COMPANY)
                {
                    // If Faction give to all high ranks? or just highest? or give to admin to give to faction member
                    API.SendErrorNotification(sender, "Not implemented yet");
                }
                return;
            }

            if (field == "EnterPos")
            {
                Vector3        pos = sender.position;
                Globals.Colour col = new Globals.Colour(255, 255, 255);

                switch (propertyToEdit.Type)
                {
                case PropertyType.General:     { col = Property.generalColour;     break; }

                case PropertyType.Residential: { col = Property.residentialColour; break; }

                case PropertyType.Commericial:  { col = Property.commercialColour;  break; }

                case PropertyType.Industrial:  { col = Property.industrialColour;  break; }
                }

                API.deleteEntity(propertyToEdit.pickupHandle);
                propertyToEdit.pickupHandle = API.createMarker(20, pos, new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(0.5, 0.5, 0.5),
                                                               col.a, col.r, col.g, col.b);

                bool isEnterable = propertyToEdit.IsEnterable;
                col = new Globals.Colour(
                    isEnterable ? 100 : 223,
                    isEnterable ? 223 : 58,
                    isEnterable ? 0 : 0
                    );

                API.deleteEntity(propertyToEdit.labelHandle);
                Vector3 lablePos = pos.Copy(); lablePos.Z += 0.5f;
                propertyToEdit.labelHandle = API.createTextLabel(propertyToEdit.Name, lablePos, 25.0f, 0.75f);
                API.setTextLabelColor(propertyToEdit.labelHandle, col.r, col.g, col.b, col.a);

                propertyToEdit.EnterPosition = pos;
                API.SendWarningNotification(sender, ("You have edited " + propertyToEdit.Name + "'s EnterPos to: " + pos.ToString()));
            }

            if (field == "ExitPos")
            {
                if (value == "-1")
                {
                    propertyToEdit.IsEnterable  = false;
                    propertyToEdit.ExitPosition = new Vector3(0, 0, 0);
                    propertyToEdit.Dimension    = 0;

                    API.setTextLabelColor(propertyToEdit.labelHandle, 223, 58, 0, 255);
                    API.SendWarningNotification(sender, ("You have removed " + propertyToEdit.Name + "'s ExitPos"));
                }
                else
                {
                    propertyToEdit.IsEnterable  = true;
                    propertyToEdit.ExitPosition = sender.position;
                    propertyToEdit.Dimension    = propertyToEdit.Id;

                    API.setTextLabelColor(propertyToEdit.labelHandle, 100, 223, 0, 255);
                    API.SendWarningNotification(sender, ("You have edited " + propertyToEdit.Name + "'s ExitPos to: " + sender.position.ToString() + " (Dimension: " + propertyToEdit.Id + ")"));
                }
            }

            if (field == "Dimension")
            {
                int dimension = Int32.Parse(value);

                if ((int)dimension < 0)
                {
                    PropertyCommandUsage(sender); return;
                }

                propertyToEdit.Dimension = dimension;
                API.SendWarningNotification(sender, ("You have edited " + propertyToEdit.Name + "'s type Dimension: " + dimension));
            }

            await PropertyRepository.UpdateAsync(propertyToEdit);

            return;
        }
        public async static void PropertyCommand(Client sender, string option = "")
        {
            if (option == "")
            {
                Message.Syntax(sender, "/property [Option] (lock, inventory)"); return;
            }

            Player          player = Player.PlayerData[sender];
            PropertyManager mng    = new PropertyManager();
            bool            isLockingDoorManagerDoors = false;
            Property        assumedProp = ((player.Dimension == 0) ? mng.GetClosestPropertyToLocation(sender.position, 2.0f) : null);

            if (assumedProp == null && player.Dimension != 0)
            {
                assumedProp = mng.GetPropertyByDimension(player.Dimension);
            }
            if (assumedProp == null)
            {
                if ((assumedProp = mng.GetClosestPropertyToLocationByDoors(sender.position, 2.0f)) != null)
                {
                    isLockingDoorManagerDoors = true;
                }
            }

            if (assumedProp == null)
            {
                Message.Syntax(sender, "You are not close enough to a property"); return;
            }

            if (option.ToLower() == "lock")
            {
                if (player.Dimension != 0 && (sender.position.DistanceTo(assumedProp.ExitPosition) > 2.0f))
                {
                    Message.Syntax(sender, "You are not close enough to the door"); return; // Range check
                }

                string    nameMatched = assumedProp.Name + " key";
                Inventory keyItem     = player.Inventory.FirstOrDefault(i => i.Name == nameMatched);


                if (keyItem == null)
                {
                    Message.Syntax(sender, "You do not have the correct key for this property"); return;
                }

                assumedProp.IsLocked = !assumedProp.IsLocked;
                API.shared.SendCloseMessage(sender, 15.0f, "~#C2A2DA~", API.shared.getPlayerName(sender) + " " + "places a key inside the lock of the door for " + assumedProp.Name + " and " + (assumedProp.IsLocked ? "locks" : "unlocks") + " it.");

                if (isLockingDoorManagerDoors)
                {
                    foreach (int t in assumedProp.DoormanagerDoors)
                    {
                        API.shared.exported.doormanager.setDoorState(t, assumedProp.IsLocked, 0);
                    }
                }

                await PropertyRepository.UpdateAsync(assumedProp);

                return;
            }

            if (option.ToLower() == "inventory")
            {
                Property p = assumedProp;
                if (p.Inventory == null)
                {
                    Message.Syntax(sender, "This property does not have an inventory. Please consult an administrator"); return;
                }

                API.shared.triggerClientEvent(sender, "showPlayerInventory", string.Join(",", p.Inventory.Select(e => e.Id).ToList()),
                                              string.Join(",", p.Inventory.Select(e => e.Name).ToList()), string.Join(".", p.Inventory.Select(e => Inventory.GetInventoryImage[e.Type]).ToList()),
                                              string.Join(",", p.Inventory.Select(e => e.Quantity).ToList())
                                              );
                return;
            }
        }