public override void Process(ConstructionAmountChanged amountChanged)
        {
            Console.WriteLine("Processing ConstructionAmountChanged " + amountChanged.Guid + " " + amountChanged.PlayerId + " " + amountChanged.ConstructionAmount);

            Optional <GameObject> opGameObject = GuidHelper.GetObjectFrom(amountChanged.Guid);

            if (opGameObject.IsPresent())
            {
                GameObject    constructing  = opGameObject.Get();
                Constructable constructable = constructing.GetComponent <Constructable>();
                constructable.constructedAmount = amountChanged.ConstructionAmount;

                packetSender.AddSuppressedPacketType(typeof(ConstructionAmountChanged));
                constructable.Construct();
                packetSender.RemoveSuppressedPacketType(typeof(ConstructionAmountChanged));
            }
        }
        public override void Process(ItemContainerRemove packet)
        {
            Optional <GameObject> opOwner = GuidHelper.GetObjectFrom(packet.OwnerGuid);
            Optional <GameObject> opItem  = GuidHelper.GetObjectFrom(packet.ItemGuid);

            if (opOwner.IsPresent() && opItem.IsPresent())
            {
                GameObject owner = opOwner.Get();
                GameObject item  = opItem.Get();

                Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner);

                if (opContainer.IsPresent())
                {
                    ItemsContainer container  = opContainer.Get();
                    Pickupable     pickupable = item.GetComponent <Pickupable>();

                    if (pickupable != null)
                    {
                        packetSender.AddSuppressedPacketType(typeof(ItemContainerRemove));
                        container.RemoveItem(pickupable, true);
                        packetSender.RemoveSuppressedPacketType(typeof(ItemContainerRemove));
                    }
                    else
                    {
                        Console.WriteLine(item.name + " did not have a corresponding pickupable script!");
                    }
                }
                else
                {
                    Console.WriteLine("Could not find container field on object " + owner.name);
                }
            }
            else
            {
                Console.WriteLine("Owner or item was not found: " + opOwner + " " + opItem + " " + packet.OwnerGuid + " " + packet.ItemGuid);
            }
        }
Exemplo n.º 3
0
        public override void Process(ItemContainerAdd packet)
        {
            Optional <GameObject> opOwner = GuidHelper.GetObjectFrom(packet.OwnerGuid);

            if (opOwner.IsPresent())
            {
                GameObject owner = opOwner.Get();

                Optional <ItemsContainer> opContainer = InventoryContainerHelper.GetBasedOnOwnersType(owner);

                if (opContainer.IsPresent())
                {
                    ItemsContainer container  = opContainer.Get();
                    GameObject     item       = SerializationHelper.GetGameObject(packet.ItemData);
                    Pickupable     pickupable = item.GetComponent <Pickupable>();

                    if (pickupable != null)
                    {
                        packetSender.AddSuppressedPacketType(typeof(ItemContainerAdd));
                        container.UnsafeAdd(new InventoryItem(pickupable));
                        packetSender.RemoveSuppressedPacketType(typeof(ItemContainerAdd));
                    }
                    else
                    {
                        Console.WriteLine(item.name + " did not have a corresponding pickupable script!");
                    }
                }
                else
                {
                    Console.WriteLine("Could not find container field on object " + owner.name);
                }
            }
            else
            {
                Console.WriteLine("Could not find owner with guid: " + packet.OwnerGuid);
            }
        }