Example #1
0
        public override void OnReceivedClientPacket(IServerPlayer player, int packetid, byte[] data)
        {
            if (packetid < 1000)
            {
                Inventory.InvNetworkUtil.HandleClientPacket(player, packetid, data);
                return;
            }
            if (packetid == 1000)
            {
                EnumTransactionResult result = Inventory.TryBuySell(player);
                if (result == EnumTransactionResult.Success)
                {
                    (Api as ICoreServerAPI).WorldManager.GetChunk(ServerPos.AsBlockPos)?.MarkModified();

                    AnimManager.StopAnimation("idle");
                    AnimManager.StartAnimation(new AnimationMetaData()
                    {
                        Animation = "nod", Code = "nod", Weight = 10, EaseOutSpeed = 10000, EaseInSpeed = 10000
                    });

                    TreeAttribute tree = new TreeAttribute();
                    Inventory.ToTreeAttributes(tree);
                    (Api as ICoreServerAPI).Network.BroadcastEntityPacket(EntityId, 1234, tree.ToBytes());
                }
            }
        }
Example #2
0
 public override void OnReceivedClientPacket(IServerPlayer player, int packetid, byte[] data)
 {
     if (packetid < 1000)
     {
         Inventory.InvNetworkUtil.HandleClientPacket(player, packetid, data);
         return;
     }
     if (packetid == 1000)
     {
         Inventory.TryBuySell(player);
     }
 }
        private bool OnBuySellClicked()
        {
            EnumTransactionResult result = traderInventory.TryBuySell(capi.World.Player);

            if (result == EnumTransactionResult.Success)
            {
                capi.Gui.PlaySound(new AssetLocation("sounds/effect/cashregister"), false, 0.25f);
                (owningEntity as EntityTrader).talkUtil.Talk(EnumTalkType.Purchase);
            }

            if (result == EnumTransactionResult.PlayerNotEnoughAssets)
            {
                (owningEntity as EntityTrader).talkUtil.Talk(EnumTalkType.Complain);
                if (notifyPlayerMoneyTextSeconds <= 0)
                {
                    prevPlrAbsFixedX = SingleComposer.GetDynamicText("playerMoneyText").Bounds.absFixedX;
                    prevPlrAbsFixedY = SingleComposer.GetDynamicText("playerMoneyText").Bounds.absFixedY;
                }
                notifyPlayerMoneyTextSeconds = 1.5f;
            }

            if (result == EnumTransactionResult.TraderNotEnoughAssets)
            {
                (owningEntity as EntityTrader).talkUtil.Talk(EnumTalkType.Complain);
                if (notifyTraderMoneyTextSeconds <= 0)
                {
                    prevTdrAbsFixedX = SingleComposer.GetDynamicText("traderMoneyText").Bounds.absFixedX;
                    prevTdrAbsFixedY = SingleComposer.GetDynamicText("traderMoneyText").Bounds.absFixedY;
                }
                notifyTraderMoneyTextSeconds = 1.5f;
            }

            if (result == EnumTransactionResult.TraderNotEnoughSupplyOrDemand)
            {
                (owningEntity as EntityTrader).talkUtil.Talk(EnumTalkType.Complain);
            }

            capi.Network.SendEntityPacket(owningEntity.EntityId, 1000, null);

            TraderInventory_SlotModified(0);
            CalcAndUpdateAssetsDisplay();

            return(true);
        }