Beispiel #1
0
        private void Server_CreateCollection()
        {
            if (_isPlayerCollection)
            {
                var bridge = GetComponent <UNetActionsBridge>();
                if (bridge == null)
                {
                    _logger.Error($"Trying to sync collection to client, but no {nameof(UNetActionsBridge)} found on object!", this);
                    return;
                }

                var guid = System.Guid.NewGuid();
                collection = bridge.Server_AddCollectionToServerAndClient(new AddCollectionMessage()
                {
                    owner          = _identity,
                    collectionName = _collectionName,
                    collectionGuid = guid,
                    slotCount      = (ushort)slotCount,
                });

                bridge.Server_SetCollectionPermissionOnServerAndClient(new SetCollectionPermissionMessage()
                {
                    collectionGuid = guid,
                    permission     = _permission
                });
            }
            else
            {
                collection = UNetCollectionUtility.CreateServerItemCollection(_slotCount, _collectionName, System.Guid.NewGuid(), _identity);
            }
        }
        // TODO: Consider separating into client and server replicators.



        public void TargetRpc_AddCollection(NetworkConnection target, AddCollectionMessage data)
        {
            var collection = UNetActionsBridge.collectionFinder.GetClientCollection(data.collectionGuid);

            if (collection == null)
            {
                collection = UNetCollectionUtility.CreateClientItemCollection(data.slotCount, data.collectionName, data.collectionGuid, data.owner, bridge);
            }
        }
        private void Server_CreateCollection()
        {
            if (_isPlayerCollection)
            {
                var bridge = GetComponent <UNetActionsBridge>();
                if (bridge == null)
                {
                    _logger.Error($"Trying to sync collection to client, but no {nameof(UNetActionsBridge)} found on object!", this);
                    return;
                }

                var guid = System.Guid.NewGuid();
                collection = bridge.Server_AddEquipmentCollectionToServerAndClient(new AddEquipmentCollectionMessage()
                {
                    owner          = _identity,
                    collectionName = _collectionName,
                    collectionGuid = guid,
                    slots          = _slots.Select(o => new EquipmentSlotDataMessage()
                    {
                        equipmentTypeGuids = o.equipmentTypes.Select(j => new GuidMessage()
                        {
                            bytes = j.ID.ToByteArray()
                        }).ToArray(),
                    }).ToArray()
                });

                bridge.Server_SetCollectionPermissionOnServerAndClient(new SetCollectionPermissionMessage()
                {
                    collectionGuid = guid,
                    permission     = _permission
                });
            }
            else
            {
                var equippableCharacter = GetComponent <IEquippableCharacter <IEquippableItemInstance> >();
//                var restoreItemsToGroup = GetComponent<IInventoryCollectionOwner>().itemCollectionGroup;
                collection = UNetCollectionUtility.CreateServerEquipmentCollection(_collectionName, System.Guid.NewGuid(), _identity, _slots.Select(o => o.ToSlotInstance(equippableCharacter)).ToArray(), equippableCharacter);
            }
        }