Example #1
0
        // --- END EVENTS

        public void InitProperty(Property prop)
        {
            // --- Create the "Pickup" for the property
            Globals.Colour col = new Globals.Colour(255, 255, 255);

            switch (prop.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; }

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

            prop.pickupHandle = API.createMarker(
                prop.Type == PropertyType.Service ? 2 : 20,
                prop.EnterPosition,
                new Vector3(0, 0, 0),
                prop.Type == PropertyType.Service ? new Vector3(180, 0, 0) : new Vector3(0, 0, 0),
                new Vector3(0.5f, 0.5f, 0.5f),
                col.a, col.r, col.g, col.b
                );

            // --- Create the label for the property
            bool isEnterable = prop.IsEnterable;

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

            if (prop.Type == PropertyType.Service)
            {
                col = new Globals.Colour(255, 255, 255);
            }

            prop.EnterPosition += new Vector3(0, 0, 0.5f);

            prop.labelHandle = API.createTextLabel(prop.Name, prop.EnterPosition, 7.0f, 0.85f);
            API.setTextLabelColor(prop.labelHandle, col.r, col.g, col.b, col.a);

            prop.EntranceColShape = API.createCylinderColShape(prop.EnterPosition, 1f, 1f);
            prop.ExitColShape     = API.createCylinderColShape(prop.ExitPosition, 1f, 1f);
        }
Example #2
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;
        }