Esempio n. 1
0
        public static UNetServerEquipmentCollection <IEquippableItemInstance> CreateServerEquipmentCollection(
            string collectionName,
            System.Guid collectionGuid,
            NetworkIdentity owner,
            EquipmentCollectionSlot <IEquippableItemInstance>[] slots,
            IEquippableCharacter <IEquippableItemInstance> character)
        {
            var collection = new UNetServerEquipmentCollection <IEquippableItemInstance>(owner, 0, character)
            {
                collectionName = collectionName,
                ID             = collectionGuid
            };

            collection.slots = slots;
            for (int i = 0; i < collection.slots.Length; i++)
            {
                collection.slots[i].collection = collection;
                collection.slots[i].index      = i;
            }

            collection.Server_Register();

            // The server's owner object always has read/write permission.
            UNetPermissionsRegistry.collections.SetPermission(collection, owner, ReadWritePermission.ReadWrite);

            _logger.Log($"[Server] Created and registered equipment collection with name {collection.collectionName} and guid {collection.ID} for netID: {owner.netId}", collection);
            return(collection);
        }
        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);
            }
        }