public override object Clone()
        {
            var clone = (IItemInstance)base.Clone();

            ServerItemRegistry.Register(clone.ID, clone);
            return(clone);
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
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);
                }
            }
        }