Exemplo n.º 1
0
        private void TankIcon_OnClick(EventContext context)
        {
            this.m_infoTip.visible = true;

            this.m_infoTip.GetChild("bg").onClick.Set(() => { this.m_infoTip.visible = false; });

            GComponent tip = this.m_infoTip.GetChild("InfoTip").asCom;

            tip.x = context.inputEvent.x;

            tip.y = context.inputEvent.y;

            TankCfg tankInfo = ((context.sender as GLoader).parent.data) as TankCfg;

            tip.GetChild("n2").asLoader.url = tankInfo.Icon;

            tip.GetChild("n4").asTextField.text = tankInfo.Name();

            tip.GetChild("n6").asTextField.text = tankInfo.Type();

            tip.GetChild("n8").asTextField.text = Message.Get(1088);

            GList attrList = tip.GetChild("n7").asList;

            attrList.numItems = 3;

            attrList.GetChildAt(0).asCom.GetChild("n0").asTextField.text = $"{Message.Get(1089)}   +{tankInfo.Attack}";

            attrList.GetChildAt(1).asCom.GetChild("n0").asTextField.text = $"{Message.Get(1090)}   +{tankInfo.Defence}";

            attrList.GetChildAt(2).asCom.GetChild("n0").asTextField.text = $"{Message.Get(1091)}  +{tankInfo.SunderArmor}";

            attrList.ResizeToFit(3);
        }
Exemplo n.º 2
0
        private void TankItemRender()
        {
            IConfig[] configs = Game.Scene.GetComponent <ConfigComponent>().GetAll(typeof(TankCfg));

            this.m_itemList.RemoveChildrenToPool();

            for (int i = 0; i < configs.Length; i++)
            {
                TankCfg tankInfo = configs[i] as TankCfg;

                if (tankInfo.CanBuy == 0)
                {
                    continue;
                }


                GComponent com = this.m_itemList.AddItemFromPool().asCom;

                com.GetChild("n11").text = tankInfo.Name();

                com.GetChild("n7").text = tankInfo.Price.ToString();

                com.GetChild("n15").asLoader.url = tankInfo.Icon;

                Log.Warning($"{tankInfo.Icon}");

                com.GetChild("n15").asLoader.onClick.Set(this.TankIcon_OnClick);

                com.GetChild("n12").text = Message.Get(1075);

                com.GetChild("n12").asButton.onClick.Set(() =>
                {
                    Send_C2G_OptGood(GoodType.Tank, (int)tankInfo.Id);
                });

                com.data = tankInfo;
            }
        }
Exemplo n.º 3
0
        protected override void Run(Session session, C2G_OptGood message)
        {
            Player player = session.GetComponent <SessionPlayerComponent>().Player;

            WarehouseComponent warehouse = player.UserDB.GetComponent <WarehouseComponent>();

            UserBaseComponent userBase = player.UserDB.GetComponent <UserBaseComponent>();

            switch (message.GoodType)
            {
            case GoodType.Tank:
                TankCfg tankInfo = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(TankCfg), message.TableId) as TankCfg;

                if (message.GoodOpt == GoodOpt.Use && warehouse.UseTankId != message.TableId &&
                    warehouse.isExitTank(message.TableId))
                {
                    warehouse.UseTankId = message.TableId;
                    Send_G2C_Warehouse(player);
                    player.Send_PopMessage(1083);
                }

                if (message.GoodOpt == GoodOpt.Buy)
                {
                    if (warehouse.isExitTank(message.TableId))
                    {
                        player.Send_PopMessage(1084);
                    }
                    else if (userBase.Gold < tankInfo.Price)
                    {
                        player.Send_PopMessage(1086);
                    }
                    else
                    {
                        userBase.Gold -= tankInfo.Price;
                        player.Send_PopMessage(1087);
                        warehouse.Tanks.Add(message.TableId);
                    }
                }
                break;

            case GoodType.Bullet:
                BulletCfg bulletInfo = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(BulletCfg), message.TableId) as BulletCfg;
                if (message.GoodOpt == GoodOpt.Use && warehouse.UseBulletId != message.TableId &&
                    warehouse.isExitBullet(message.TableId))
                {
                    warehouse.UseBulletId = message.TableId;
                    Send_G2C_Warehouse(player);
                    player.Send_PopMessage(1085);
                }

                if (message.GoodOpt == GoodOpt.Buy)
                {
                    if (warehouse.isExitBullet(message.TableId))
                    {
                        player.Send_PopMessage(1084);
                    }
                    else if (userBase.Gold < bulletInfo.Price)
                    {
                        player.Send_PopMessage(1086);
                    }
                    else
                    {
                        userBase.Gold -= bulletInfo.Price;
                        player.Send_PopMessage(1087);
                        warehouse.Bullets.Add(message.TableId);
                    }
                }

                break;

            case GoodType.Prop:
                Prop propInfo = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(Prop), message.TableId) as Prop;

                if (message.GoodOpt == GoodOpt.Use && warehouse.GetUnUseProp(message.TableId) != null)
                {
                    PropItem unUseItem = warehouse.GetUnUseProp(message.TableId);

                    PropItem inUseItem = warehouse.GetInUseProp(message.TableId);


                    if (inUseItem != null)
                    {
                        inUseItem.TotalTimes += unUseItem.TotalTimes;

                        unUseItem.Num -= 1;

                        if (unUseItem.Num <= 0)
                        {
                            warehouse.UnUseProps.Remove(unUseItem);
                        }
                    }
                    else
                    {
                        inUseItem = new PropItem(unUseItem);

                        inUseItem.PropState = PropState.InUser;

                        inUseItem.Num = 1;

                        warehouse.InUseProps.Add(inUseItem);

                        unUseItem.Num -= 1;

                        if (unUseItem.Num <= 0)
                        {
                            warehouse.UnUseProps.Remove(unUseItem);
                        }
                    }

                    Send_G2C_Warehouse(player);
                    player.Send_PopMessage(1085);
                }

                if (message.GoodOpt == GoodOpt.Buy)
                {
                    if (userBase.Gold < propInfo.Price)
                    {
                        player.Send_PopMessage(1086);
                        break;
                    }

                    PropItem propItem = warehouse.GetUnUseProp(message.TableId);

                    if (propItem != null)
                    {
                        propItem.Num += 1;
                    }
                    else
                    {
                        propItem = new PropItem();

                        propItem.PropState = PropState.WaitUse;

                        propItem.TableId = message.TableId;

                        propItem.BuyTime = TimeHelper.NowSecond();

                        propItem.Num = 1;

                        propItem.TotalTimes = (Game.Scene.GetComponent <ConfigComponent>().Get(typeof(Prop), message.TableId) as Prop).TotleTimes;

                        warehouse.UnUseProps.Add(propItem);
                    }

                    userBase.Gold -= propInfo.Price;

                    player.Send_PopMessage(1087);


                    Send_G2C_Warehouse(player);
                }

                break;

            default:
                Log.Error($"不存在的GoodType:{message.GoodType}");
                break;
            }
        }