Пример #1
0
        public override void Process(NetMessage msg)
        {
            var ComponentType    = msg.ComponentType;
            var InteractionType  = msg.InteractionType;
            var ProcessorObject  = msg.ProcessorObject;
            var Intent           = msg.Intent;
            var TargetObject     = msg.TargetObject;
            var UsedObject       = msg.UsedObject;
            var TargetBodyPart   = msg.TargetBodyPart;
            var TargetVector     = msg.TargetVector;
            var MouseButtonState = msg.MouseButtonState;
            var IsAltUsed        = msg.IsAltUsed;
            var Storage          = msg.Storage;
            var SlotIndex        = msg.SlotIndex;
            var NamedSlot        = msg.NamedSlot;
            var connectionPointA = msg.connectionPointA;
            var connectionPointB = msg.connectionPointB;
            var RequestedOption  = msg.RequestedOption;

            var performer = SentByPlayer.GameObject;

            if (SentByPlayer == null || SentByPlayer.Script == null)
            {
                return;
            }

            if (SentByPlayer.Script.DynamicItemStorage == null)
            {
                if (InteractionType == typeof(AiActivate))
                {
                    LoadMultipleObjects(new uint[] { TargetObject, ProcessorObject });
                    var targetObj    = NetworkObjects[0];
                    var processorObj = NetworkObjects[1];

                    var interaction = new AiActivate(performer, null, targetObj, Intent, msg.ClickTypes);
                    ProcessInteraction(interaction, processorObj, ComponentType);
                }

                return;
            }

            if (InteractionType == typeof(PositionalHandApply))
            {
                //look up item in active hand slot
                var clientStorage = SentByPlayer.Script.DynamicItemStorage;
                var usedSlot      = clientStorage.GetActiveHandSlot();
                var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
                LoadMultipleObjects(new uint[] {
                    TargetObject, ProcessorObject
                });
                var targetObj    = NetworkObjects[0];
                var processorObj = NetworkObjects[1];
                CheckMatrixSync(ref targetObj);
                CheckMatrixSync(ref processorObj);

                var interaction = PositionalHandApply.ByClient(performer, usedObject, targetObj, TargetVector, usedSlot, Intent, TargetBodyPart);
                ProcessInteraction(interaction, processorObj, ComponentType);
            }
            else if (InteractionType == typeof(HandApply))
            {
                var clientStorage = SentByPlayer.Script.DynamicItemStorage;
                var usedSlot      = clientStorage.GetActiveHandSlot();
                var usedObject    = clientStorage.GetActiveHandSlot()?.ItemObject;
                LoadMultipleObjects(new uint[] {
                    TargetObject, ProcessorObject
                });
                var targetObj    = NetworkObjects[0];
                var processorObj = NetworkObjects[1];
                CheckMatrixSync(ref targetObj);
                CheckMatrixSync(ref processorObj);

                var interaction = HandApply.ByClient(performer, usedObject, targetObj, TargetBodyPart, usedSlot, Intent, IsAltUsed);
                ProcessInteraction(interaction, processorObj, ComponentType);
            }
            else if (InteractionType == typeof(AimApply))
            {
                var clientStorage = SentByPlayer.Script.DynamicItemStorage;
                var usedSlot      = clientStorage.GetActiveHandSlot();
                var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
                LoadNetworkObject(ProcessorObject);
                var processorObj = NetworkObject;
                CheckMatrixSync(ref processorObj);

                var interaction = AimApply.ByClient(performer, TargetVector, usedObject, usedSlot, MouseButtonState, Intent);
                ProcessInteraction(interaction, processorObj, ComponentType);
            }
            else if (InteractionType == typeof(MouseDrop))
            {
                LoadMultipleObjects(new uint[] { UsedObject,
                                                 TargetObject, ProcessorObject });

                var usedObj      = NetworkObjects[0];
                var targetObj    = NetworkObjects[1];
                var processorObj = NetworkObjects[2];
                CheckMatrixSync(ref targetObj);
                CheckMatrixSync(ref processorObj);

                var interaction = MouseDrop.ByClient(performer, usedObj, targetObj, Intent);
                ProcessInteraction(interaction, processorObj, ComponentType);
            }
            else if (InteractionType == typeof(HandActivate))
            {
                LoadNetworkObject(ProcessorObject);

                var processorObj = NetworkObject;
                CheckMatrixSync(ref processorObj);

                var performerObj = SentByPlayer.GameObject;
                //look up item in active hand slot
                var clientStorage = SentByPlayer.Script.DynamicItemStorage;
                var usedSlot      = clientStorage.GetActiveHandSlot();
                var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
                var interaction   = HandActivate.ByClient(performer, usedObject, usedSlot, Intent);
                ProcessInteraction(interaction, processorObj, ComponentType);
            }
            else if (InteractionType == typeof(InventoryApply))
            {
                LoadMultipleObjects(new uint[] { ProcessorObject, UsedObject,
                                                 Storage });
                var processorObj = NetworkObjects[0];
                var usedObj      = NetworkObjects[1];
                var storageObj   = NetworkObjects[2];
                CheckMatrixSync(ref processorObj);

                ItemSlot targetSlot = null;
                if (SlotIndex == -1)
                {
                    targetSlot = ItemSlot.GetNamed(storageObj.GetComponents <ItemStorage>()[msg.StorageIndexOnGameObject], NamedSlot);
                }
                else
                {
                    targetSlot = ItemSlot.GetIndexed(storageObj.GetComponents <ItemStorage>()[msg.StorageIndexOnGameObject], SlotIndex);
                }

                //if used object is null, then empty hand was used
                ItemSlot fromSlot = null;
                if (usedObj == null)
                {
                    fromSlot = SentByPlayer.Script.DynamicItemStorage.GetActiveHandSlot();
                }
                else
                {
                    fromSlot = usedObj.GetComponent <Pickupable>().ItemSlot;
                }
                var interaction = InventoryApply.ByClient(performer, targetSlot, fromSlot, Intent, IsAltUsed);
                ProcessInteraction(interaction, processorObj, ComponentType);
            }
            else if (InteractionType == typeof(TileApply))
            {
                var clientStorage = SentByPlayer.Script.DynamicItemStorage;
                var usedSlot      = clientStorage.GetActiveHandSlot();
                var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
                LoadNetworkObject(ProcessorObject);
                var processorObj = NetworkObject;
                CheckMatrixSync(ref processorObj);

                processorObj.GetComponent <InteractableTiles>().ServerProcessInteraction(SentByPlayer.GameObject,
                                                                                         TargetVector, processorObj, usedSlot, usedObject, Intent,
                                                                                         TileApply.ApplyType.HandApply);
            }
            else if (InteractionType == typeof(TileMouseDrop))
            {
                LoadMultipleObjects(new uint[] { UsedObject,
                                                 ProcessorObject });

                var usedObj      = NetworkObjects[0];
                var processorObj = NetworkObjects[1];
                CheckMatrixSync(ref processorObj);

                processorObj.GetComponent <InteractableTiles>().ServerProcessInteraction(SentByPlayer.GameObject,
                                                                                         TargetVector, processorObj, null, usedObj, Intent,
                                                                                         TileApply.ApplyType.MouseDrop);
            }
            else if (InteractionType == typeof(ConnectionApply))
            {
                //look up item in active hand slot
                var clientStorage = SentByPlayer.Script.DynamicItemStorage;
                var usedSlot      = clientStorage.GetActiveHandSlot();
                var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
                LoadMultipleObjects(new uint[] {
                    TargetObject, ProcessorObject
                });
                var targetObj    = NetworkObjects[0];
                var processorObj = NetworkObjects[1];
                CheckMatrixSync(ref targetObj);
                CheckMatrixSync(ref processorObj);

                var interaction = ConnectionApply.ByClient(performer, usedObject, targetObj, connectionPointA, connectionPointB, TargetVector, usedSlot, Intent);
                ProcessInteraction(interaction, processorObj, ComponentType);
            }
            else if (InteractionType == typeof(ContextMenuApply))
            {
                LoadMultipleObjects(new uint[] { TargetObject, ProcessorObject });
                var clientStorage = SentByPlayer.Script.DynamicItemStorage;
                var usedObj       = clientStorage.GetActiveHandSlot().ItemObject;
                var targetObj     = NetworkObjects[0];
                var processorObj  = NetworkObjects[1];
                CheckMatrixSync(ref targetObj);
                CheckMatrixSync(ref processorObj);

                var interaction = ContextMenuApply.ByClient(performer, usedObj, targetObj, RequestedOption, Intent);
                ProcessInteraction(interaction, processorObj, ComponentType);
            }
        }
Пример #2
0
    public override void Process()
    {
        var performer = SentByPlayer.GameObject;

        if (SentByPlayer == null || SentByPlayer.Script == null || SentByPlayer.Script.ItemStorage == null)
        {
            return;
        }

        if (InteractionType == typeof(PositionalHandApply))
        {
            //look up item in active hand slot
            var clientStorage = SentByPlayer.Script.ItemStorage;
            var usedSlot      = clientStorage.GetActiveHandSlot();
            var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
            LoadMultipleObjects(new uint[] {
                TargetObject, ProcessorObject
            });
            var targetObj    = NetworkObjects[0];
            var processorObj = NetworkObjects[1];
            var interaction  = PositionalHandApply.ByClient(performer, usedObject, targetObj, TargetVector, usedSlot, Intent, TargetBodyPart);
            ProcessInteraction(interaction, processorObj);
        }
        else if (InteractionType == typeof(HandApply))
        {
            var clientStorage = SentByPlayer.Script.ItemStorage;
            var usedSlot      = clientStorage.GetActiveHandSlot();
            var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
            LoadMultipleObjects(new uint[] {
                TargetObject, ProcessorObject
            });
            var targetObj    = NetworkObjects[0];
            var processorObj = NetworkObjects[1];
            var interaction  = HandApply.ByClient(performer, usedObject, targetObj, TargetBodyPart, usedSlot, Intent, IsAltUsed);
            ProcessInteraction(interaction, processorObj);
        }
        else if (InteractionType == typeof(AimApply))
        {
            var clientStorage = SentByPlayer.Script.ItemStorage;
            var usedSlot      = clientStorage.GetActiveHandSlot();
            var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
            LoadNetworkObject(ProcessorObject);
            var processorObj = NetworkObject;
            var interaction  = AimApply.ByClient(performer, TargetVector, usedObject, usedSlot, MouseButtonState, Intent);
            ProcessInteraction(interaction, processorObj);
        }
        else if (InteractionType == typeof(MouseDrop))
        {
            LoadMultipleObjects(new uint[] { UsedObject,
                                             TargetObject, ProcessorObject });
            var usedObj      = NetworkObjects[0];
            var targetObj    = NetworkObjects[1];
            var processorObj = NetworkObjects[2];
            var interaction  = MouseDrop.ByClient(performer, usedObj, targetObj, Intent);
            ProcessInteraction(interaction, processorObj);
        }
        else if (InteractionType == typeof(HandActivate))
        {
            LoadNetworkObject(ProcessorObject);

            var processorObj = NetworkObject;
            var performerObj = SentByPlayer.GameObject;
            //look up item in active hand slot
            var clientStorage = SentByPlayer.Script.ItemStorage;
            var usedSlot      = clientStorage.GetActiveHandSlot();
            var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
            var interaction   = HandActivate.ByClient(performer, usedObject, usedSlot, Intent);
            ProcessInteraction(interaction, processorObj);
        }
        else if (InteractionType == typeof(InventoryApply))
        {
            LoadMultipleObjects(new uint[] { ProcessorObject, UsedObject,
                                             Storage });
            var processorObj = NetworkObjects[0];
            var usedObj      = NetworkObjects[1];
            var storageObj   = NetworkObjects[2];

            ItemSlot targetSlot = null;
            if (SlotIndex == -1)
            {
                targetSlot = ItemSlot.GetNamed(storageObj.GetComponent <ItemStorage>(), NamedSlot);
            }
            else
            {
                targetSlot = ItemSlot.GetIndexed(storageObj.GetComponent <ItemStorage>(), SlotIndex);
            }

            //if used object is null, then empty hand was used
            ItemSlot fromSlot = null;
            if (usedObj == null)
            {
                fromSlot = SentByPlayer.Script.ItemStorage.GetActiveHandSlot();
            }
            else
            {
                fromSlot = usedObj.GetComponent <Pickupable>().ItemSlot;
            }
            var interaction = InventoryApply.ByClient(performer, targetSlot, fromSlot, Intent, IsAltUsed);
            ProcessInteraction(interaction, processorObj);
        }
        else if (InteractionType == typeof(TileApply))
        {
            var clientStorage = SentByPlayer.Script.ItemStorage;
            var usedSlot      = clientStorage.GetActiveHandSlot();
            var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
            LoadNetworkObject(ProcessorObject);
            var processorObj = NetworkObject;
            processorObj.GetComponent <InteractableTiles>().ServerProcessInteraction(SentByPlayer.GameObject,
                                                                                     TargetVector, processorObj, usedSlot, usedObject, Intent,
                                                                                     TileApply.ApplyType.HandApply);
        }
        else if (InteractionType == typeof(TileMouseDrop))
        {
            LoadMultipleObjects(new uint[] { UsedObject,
                                             ProcessorObject });

            var usedObj      = NetworkObjects[0];
            var processorObj = NetworkObjects[1];
            processorObj.GetComponent <InteractableTiles>().ServerProcessInteraction(SentByPlayer.GameObject,
                                                                                     TargetVector, processorObj, null, usedObj, Intent,
                                                                                     TileApply.ApplyType.MouseDrop);
        }
        else if (InteractionType == typeof(ConnectionApply))
        {
            //look up item in active hand slot
            var clientStorage = SentByPlayer.Script.ItemStorage;
            var usedSlot      = clientStorage.GetActiveHandSlot();
            var usedObject    = clientStorage.GetActiveHandSlot().ItemObject;
            LoadMultipleObjects(new uint[] {
                TargetObject, ProcessorObject
            });
            var targetObj    = NetworkObjects[0];
            var processorObj = NetworkObjects[1];
            var interaction  = ConnectionApply.ByClient(performer, usedObject, targetObj, connectionPointA, connectionPointB, TargetVector, usedSlot, Intent);
            ProcessInteraction(interaction, processorObj);
        }
        else if (InteractionType == typeof(ContextMenuApply))
        {
            LoadMultipleObjects(new uint[] { TargetObject, ProcessorObject });
            var clientStorage = SentByPlayer.Script.ItemStorage;
            var usedObj       = clientStorage.GetActiveHandSlot().ItemObject;
            var targetObj     = NetworkObjects[0];
            var processorObj  = NetworkObjects[1];

            var interaction = ContextMenuApply.ByClient(performer, usedObj, targetObj, RequestedOption, Intent);
            ProcessInteraction(interaction, processorObj);
        }
    }