Пример #1
0
        //[ServerCallback]
        public void OnTriggerUsed(Character character, TriggerEventData eventData)
        {
            if (!PhotonNetwork.LocalPlayer.IsMasterClient)
            {
                return;
            }

            var bridge = character.GetComponent <PUN2ActionsBridge>();

            if (character is Player && bridge != null)
            {
                var inst  = ItemFactory.CreateInstance(itemDefinition, System.Guid.NewGuid());
                var added = bridge.inventoryPlayer.itemCollectionGroup.Add(inst, amount);
                if (added.error != null)
                {
                    // Something went wrong, remove item from registry to avoid cluttering it with un-used items.
                    ServerItemRegistry.UnRegister(inst.ID);
                    ItemRegistry.UnRegister(inst.ID);

                    // TODO: Notify client why pickup failed

                    DevdogLogger.LogError($"[PUN2][Interaction] PUN2ItemPickup.OnTriggerUsed: {added.error}", this);
                }
                else
                {
                    // Action went succesful, destroy pickup source
                    //NetworkServer.Destroy(gameObject);
                    //PhotonNetwork.Destroy(gameObject);
                    //GameObject.Destroy(gameObject);

                    bridge.photonView.RPC(nameof(bridge.Cmd_RequestUnUseTrigger), PhotonNetwork.MasterClient, this.photonView.ViewID);
                    PhotonNetwork.Destroy(gameObject);
                }
            }
        }
Пример #2
0
        public virtual object Clone()
        {
            var clone = (UnityItemInstance)MemberwiseClone();

            clone.ID = System.Guid.NewGuid();
            ItemRegistry.Register(clone.ID, clone);
            return(clone);
        }
        public IItemInstance CreateInstance <TDefinition>(TDefinition itemDefinition, System.Guid guid)
            where TDefinition : IItemDefinition
        {
            ConstructorInfo info;

            if (_instanceLookupDictionary.TryGetValue(itemDefinition.GetType(), out info))
            {
                var inst = (IItemInstance)info.Invoke(new object[] { guid, itemDefinition });
                ItemRegistry.Register(inst.ID, inst);

                return(inst);
            }

            throw new ArgumentException("No instance type found for definition " + itemDefinition.GetType());
        }
Пример #4
0
        public void OnTriggerUsed(Character character, TriggerEventData eventData)
        {
            var inventoryOwner = character.GetComponent <IInventoryCollectionOwner>();

            if (character is Player && inventoryOwner != null)
            {
                var inst  = ItemFactory.CreateInstance(itemDefinition, System.Guid.NewGuid());
                var added = inventoryOwner.itemCollectionGroup.Add(inst, amount);
                if (added.error != null)
                {
                    // TODO: Notify why pickup failed
                    ItemRegistry.UnRegister(inst.ID);
                }
                else
                {
                    // Action went succesful, destroy pickup source
                    Destroy(gameObject);
                }
            }
        }
Пример #5
0
        public IItemInstance CreateInstance <TDefinition>(TDefinition itemDefinition, System.Guid guid)
            where TDefinition : IItemDefinition
        {
            ConstructorInfo info;

            if (_instanceLookupDictionary.TryGetValue(itemDefinition.GetType(), out info))
            {
                var inst = (IItemInstance)info.Invoke(new object[] { guid, itemDefinition });
                ItemRegistry.Register(inst.ID, inst);

                // On hosts (server+client) a client shouldn't overwrite the instance in the server registry.
                if (ServerItemRegistry.Contains(inst.ID) == false)
                {
                    ServerItemRegistry.Register(inst.ID, inst);
                }

                return(inst);
            }

            throw new ArgumentException("No instance type found for definition " + itemDefinition.GetType());
        }
Пример #6
0
        public void OnTriggerUsed(Character character, TriggerEventData eventData)
        {
            var bridge = character.GetComponent <UNetActionsBridge>();

            if (character is Player && bridge != null)
            {
                var inst  = ItemFactory.CreateInstance(itemDefinition, System.Guid.NewGuid());
                var added = bridge.inventoryPlayer.itemCollectionGroup.Add(inst, amount);
                if (added.error != null)
                {
                    // Something went wrong, remove item from registry to avoid cluttering it with un-used items.
                    ServerItemRegistry.UnRegister(inst.ID);
                    ItemRegistry.UnRegister(inst.ID);

                    // TODO: Notify client why pickup failed
                }
                else
                {
                    // Action went succesful, destroy pickup source
                    NetworkServer.Destroy(gameObject);
                }
            }
        }