コード例 #1
0
        private void LoadObjects()
        {
            Console.Write("Loading objects..");
            var request = new FetchAllObjectsRequest {
                ChunkSize = 10000
            };

            using (var call = MruV.Objects.FetchAllObjects(request))
            {
                while (true)
                {
                    var next = call.ResponseStream.MoveNext();
                    next.Wait();
                    if (next.Result == false)
                    {
                        break;
                    }

                    Console.Write(".");
                    foreach (var currentObject in call.ResponseStream.Current.Objects)
                    {
                        var o             = currentObject.Value;
                        var dynamicObject = new MruDynamicObject((uint)currentObject.Key, (int)o.Model,
                                                                 new Vector3(o.X, o.Y, o.Z),
                                                                 new Vector3(o.Rx, o.Ry, o.Rz),
                                                                 o.WorldId, o.InteriorId, null, o.StreamDistance, o.DrawDistance,
                                                                 null, o.Priority, o.EstateId); // TODO: o.PlayerId i o.AreaId

                        foreach (var material in o.Materials)
                        {
                            dynamicObject.SetMaterial((int)material.Key, material.Value.ModelId,
                                                      material.Value.TxdName, material.Value.TextureName, material.Value.MaterialColor);
                        }

                        foreach (var materialText in o.MaterialTexts)
                        {
                            var mt = materialText.Value;
                            dynamicObject.SetMaterialText((int)materialText.Key, mt.Text,
                                                          (ObjectMaterialSize)mt.MaterialSize,
                                                          mt.FontFace, (int)mt.FontSize, mt.Bold, mt.FontColor, mt.BackColor,
                                                          (ObjectMaterialTextAlign)mt.TextAlignment);
                        }

                        ObjectsIDs[currentObject.Key] = dynamicObject;
                    }
                }
            }
            Console.WriteLine("\nObjects loaded.");
        }
コード例 #2
0
 private static void MultiSelect(Player sender, [Parameter(typeof(ListParamType))] List <int> objectIds = null)
 {
     if (objectIds?.Count > 0)
     {
         sender.SendClientMessage($"Wybrałeś obiekty: {String.Join(", ", objectIds)}");
         foreach (var objectId in objectIds)
         {
             sender.ObjectEditor.SelectObject((MruDynamicObject)MruDynamicObject.Find(objectId));
         }
         return;
     }
     sender.SendClientMessage(
         "Wybierz obiekty, które chcesz edytować. Wpisz komendę /o cancel aby anulować wybór obiektów.");
     sender.ObjectEditor.MultiSelectMode();
 }
コード例 #3
0
        public void OnSelected(MruDynamicObject o, PlayerSelectEventArgs e)
        {
            if (_objectEditorState != ObjectEditorState.MultiSelect && _selectedObjects.Contains(o))
            {
                _selectedObjects.Remove(o);
            }

            switch (_objectEditorState)
            {
            case ObjectEditorState.Edit:
                _player.SendClientMessage($"Wybrałeś obiekt: {o}");
                foreach (var selectedObject in _selectedObjects)
                {
                    _selectedObjectsPositions[selectedObject] = selectedObject.Position;
                }

                o.Edit(_player);
                o.Mark();
                break;

            case ObjectEditorState.Delete:
                _player.SendClientMessage($"Usunąłeś obiekt {o}");
                foreach (var selectedObject in _selectedObjects)
                {
                    selectedObject.ApiDelete();
                }

                _selectedObjects.Clear();
                o.ApiDelete();
                _objectEditorState = ObjectEditorState.Delete;
                break;

            case ObjectEditorState.Clone:
                _player.SendClientMessage($"Sklonowałeś obiekt: {o}");
                var oldSelected = _selectedObjects;
                _selectedObjects = new HashSet <MruDynamicObject>();
                foreach (var selectedObject in oldSelected)
                {
                    selectedObject.UnMark();
                    var c = new MruDynamicObject(selectedObject);
                    _selectedObjectsPositions[c] = c.Position;
                    SelectObject(c);
                }

                var clone = new MruDynamicObject(o);
                _objectEditorState = ObjectEditorState.Edit;
                clone.Edit(e.Player);
                break;

            case ObjectEditorState.MultiSelect:
                if (_selectedObjects.Contains(o))
                {
                    _player.SendClientMessage($"Usunąłeś obiekt {o} z zaznaczeń");
                    UnSelectObject(o);
                }
                else
                {
                    _player.SendClientMessage($"Dodałeś obiekt {o} do zaznaczeń");
                    SelectObject(o);
                }

                MultiSelectMode();
                break;
            }
        }
コード例 #4
0
 public void UnSelectObject(MruDynamicObject o)
 {
     _selectedObjects.Remove(o);
     o.UnMark();
 }
コード例 #5
0
 public void SelectObject(MruDynamicObject o)
 {
     _selectedObjects.Add(o);
     o.Mark();
 }
コード例 #6
0
 public void CreateGateMode(MruDynamicObject o)
 {
     _objectEditorState = ObjectEditorState.CreateGate;
     o.Edit(_player);
 }
コード例 #7
0
 public void EditObjectMode(MruDynamicObject o)
 {
     _objectEditorState = ObjectEditorState.Edit;
     o.Edit(_player);
 }
コード例 #8
0
        public void OnEdited(MruDynamicObject o, PlayerEditEventArgs e)
        {
            if (_objectEditorState == ObjectEditorState.Edit)
            {
                if (e.Response == EditObjectResponse.Update)
                {
                    foreach (var selectedObject in _selectedObjects)
                    {
                        selectedObject.Position = _selectedObjectsPositions[selectedObject] + (e.Position - o.Position);
                    }
                    return;
                }

                if (e.Response == EditObjectResponse.Final)
                {
                    e.Player.SendClientMessage($"Edytowałeś obiekt: {o}");
                    foreach (var selectedObject in _selectedObjects)
                    {
                        selectedObject.Position = _selectedObjectsPositions[selectedObject] + (e.Position - o.Position);
                        selectedObject.ApiSave();
                    }

                    o.Position = e.Position;
                    o.ApiSave();
                }
                else if (e.Response == EditObjectResponse.Cancel)
                {
                    e.Player.SendClientMessage($"Anulowałeś edycję obiektu: {o}");
                    foreach (var selectedObject in _selectedObjects)
                    {
                        selectedObject.Position = _selectedObjectsPositions[selectedObject];
                    }
                    o.UnMark();
                    o.Position = o.Position;
                }

                _objectEditorState = ObjectEditorState.None;
                _selectedObjectsPositions.Clear();
                o.UnMark();
            }
            else if (_objectEditorState == ObjectEditorState.CreateGate)
            {
                switch (e.Response)
                {
                case EditObjectResponse.Update:
                    break;

                case EditObjectResponse.Final:
                    //2nd step - set opened position
                    o.Position = e.Position;
                    _player.SendClientMessage("Ustaw pozycję otwartej bramy.");

                    break;

                case EditObjectResponse.Cancel:
                    //destroy object
                    e.Player.SendClientMessage("Anulowałeś tworzenie bramy.");
                    o.ApiDelete();
                    break;
                }
            }
            else if (_objectEditorState == ObjectEditorState.CreateGate2NdState)
            {
                switch (e.Response)
                {
                case EditObjectResponse.Update:
                    break;

                case EditObjectResponse.Final:
                    //3nd step - gate params & save gate to API
                    MruV.Gates.CreateGateAsync(new CreateGateRequest()
                    {
                        Name = "Gate",
                        Spot = new Spot()
                        {
                            Name    = "Gate Spot",
                            Message = "",
                            Icon    = 0,
                            Marker  = 0,
                            Int     = _player.Interior,
                            Vw      = _player.VirtualWorld,
                            X       = _player.Position.X,
                            Y       = _player.Position.Y,
                            Z       = _player.Position.Z,
                        },
                        GateObjects =
                        {
                            new MovableObject()
                            {
                                Object = o,
                                States =
                                {
                                    new State()
                                    {
                                        Name            = "Closed",
                                        X               = o.Position.X,
                                        Y               = o.Position.Y,
                                        Z               = o.Position.Z,
                                        Rx              = o.Rotation.X,
                                        Ry              = o.Rotation.Y,
                                        Rz              = o.Rotation.Z,
                                        TransitionSpeed = 2.5f
                                    },
                                    new State()
                                    {
                                        Name            = "Opened",
                                        X               = e.Position.X,
                                        Y               = e.Position.Y,
                                        Z               = e.Position.Z,
                                        Rx              = e.Rotation.X,
                                        Ry              = e.Rotation.Y,
                                        Rz              = e.Rotation.Z,
                                        TransitionSpeed = 2.5f
                                    }
                                }
                            }
                        }
                    });
                    o.Position = o.Position;
                    break;

                case EditObjectResponse.Cancel:
                    e.Player.SendClientMessage("Anulowałeś tworzenie bramy.");
                    o.ApiDelete();
                    break;
                }
            }
        }