Exemple #1
0
        public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message)
        {
            FreeData fd       = (FreeData)player.freeData.FreeData;
            var      freeArgs = room.ContextsWrapper.FreeArgs as FreeRuleEventArgs;

            freeArgs.TempUse(PARA_PLAYER_CURRENT, fd);
            eventKey.SetValue(message.Ss[0]);
            freeArgs.GetDefault().GetParameters().TempUse(eventKey);

            Debug.Log("drag from:" + message.Ss[0] + " to:" + message.Ss[1]);
            string from = message.Ss[0];
            string to   = message.Ss[1];

            ItemPosition fromIp = FreeItemManager.GetItemPosition(freeArgs, from, fd.freeInventory.GetInventoryManager());
            ItemPosition toIp   = FreeItemManager.GetItemPosition(freeArgs, to, fd.freeInventory.GetInventoryManager());

            // 显示拆分UI
            if (message.Bs[0] && from.StartsWith(ChickenConstant.BagDefault))
            {
                PickupItemUtil.ShowSplitUI(room, fd, from);
            }
            else if (!HandleBag(from, to, room, fd))
            {
            }
            else if (player.gamePlay.GameState == GameState.AirPlane || player.gamePlay.GameState == GameState.Gliding || player.gamePlay.GameState == GameState.JumpPlane)
            {
            }

            /*else if (from.StartsWith(ChickenConstant.BagBelt) || to.StartsWith(ChickenConstant.BagBelt))
             * {
             *  // 腰包不能做任何操作
             *  SimpleProto msg = FreePool.Allocate();
             *  msg.Key = FreeMessageConstant.ChickenTip;
             *  msg.Ss.Add("word63");
             *  FreeMessageSender.SendMessage(fd.Player, msg);
             * }*/
            else if (from.StartsWith(ChickenConstant.BagGround) && !to.StartsWith(ChickenConstant.BagGround))
            {
                // 地面模糊操作
                HandleAuto(from, to, room, fd);
            }
            else if (from.StartsWith(ChickenConstant.BagGround) || to.StartsWith(ChickenConstant.BagGround))
            {
                /*if (from.StartsWith(Ground) && !to.StartsWith(Ground))
                 * {
                 *  handleFromGround(from, to, room, fd);
                 * }*/
                if (!from.StartsWith(ChickenConstant.BagGround) && to.StartsWith(ChickenConstant.BagGround))
                {
                    FreeItemInfo fromInfo = FreeItemConfig.GetItemInfo(fromIp.key.GetKey());
                    if (fromInfo.cat == (int)ECategory.WeaponPart && from.StartsWith("w"))
                    {
                        if (BagCapacityUtil.CanDemountAttachment(room, fd, fromInfo, from, true))
                        {
                            handleToGround(from, to, room, fd);
                        }
                    }
                    else
                    {
                        handleToGround(from, to, room, fd);
                    }
                }
            }
            else if (from.StartsWith(ChickenConstant.BagDefault) && to.StartsWith("w"))
            {
                // 背包物品拖动到武器槽
                if (fromIp != null)
                {
                    FreeItemInfo info = FreeItemConfig.GetItemInfo(fromIp.key.GetKey());
                    if (info.cat == (int)ECategory.WeaponPart)
                    {
                        MovePartToWeapon(room, fd, fromIp, to, info);
                    }
                    else
                    {
                        FreeItemManager.DragItem(from, fd, room.ContextsWrapper.FreeArgs, to);
                    }
                }
            }
            else if (PickupItemUtil.IsDefault(from) && string.IsNullOrEmpty(to))
            {
                // 背包物品拖动到人身上
                if (fromIp != null)
                {
                    FreeItemInfo info = FreeItemConfig.GetItemInfo(fromIp.key.GetKey());
                    if (info.cat == (int)ECategory.WeaponPart)
                    {
                        MovePartToWeapon(room, fd, fromIp, to, info);
                    }
                    else
                    {
                        FreeItemManager.UseItem(from, fd, room.ContextsWrapper.FreeArgs);
                    }
                }
            }
            else if ((from.StartsWith("w1,") && to.StartsWith("w2,")) || (from.StartsWith("w2,") && to.StartsWith("w1,")))
            {
                ExchangeWeapon(room.ContextsWrapper.FreeArgs, fd, from, to);
            }
            else if (from.StartsWith("w") && to.StartsWith("w") && from.IndexOf(",") == 3 && to.IndexOf(",") == 2)
            {
                if (fromIp != null && toIp != null)
                {
                    WeaponBaseAgent toAgent  = fd.Player.WeaponController().GetWeaponAgent((EWeaponSlotType)short.Parse(to.Substring(1, 1)));
                    FreeItemInfo    fromInfo = FreeItemConfig.GetItemInfo(fromIp.key.GetKey());
                    if (!toAgent.WeaponConfigAssy.IsPartMatchWeapon(WeaponPartUtil.GetWeaponFstMatchedPartId(fromInfo.id, toAgent.ConfigId)))
                    {
                        SimpleProto msg = FreePool.Allocate();
                        msg.Key = FreeMessageConstant.ChickenTip;
                        msg.Ss.Add("word77," + toAgent.WeaponConfigAssy.S_Name + "," + fromInfo.name);
                        FreeMessageSender.SendMessage(fd.Player, msg);
                    }
                    else
                    {
                        string          toPosition = to.Substring(0, 2) + from.Substring(2, 1) + ",0,0";
                        ItemPosition    toPart     = FreeItemManager.GetItemPosition(room.ContextsWrapper.FreeArgs, toPosition, fd.freeInventory.GetInventoryManager());
                        WeaponBaseAgent fromAgent  = fd.Player.WeaponController().GetWeaponAgent((EWeaponSlotType)short.Parse(from.Substring(1, 1)));
                        if (toPart != null)
                        {
                            FreeItemInfo toInfo = FreeItemConfig.GetItemInfo(toPart.key.GetKey());
                            if (!fromAgent.WeaponConfigAssy.IsPartMatchWeapon(WeaponPartUtil.GetWeaponFstMatchedPartId(toInfo.id, fromAgent.ConfigId)))
                            {
                                SimpleProto msg = FreePool.Allocate();
                                msg.Key = FreeMessageConstant.ChickenTip;
                                msg.Ss.Add("word77," + fromAgent.WeaponConfigAssy.S_Name + "," + toInfo.name);
                                FreeMessageSender.SendMessage(fd.Player, msg);
                            }
                            else
                            {
                                if (BagCapacityUtil.CanExchangeAttachment(room, fd, fromInfo, toInfo, fromAgent, toAgent))
                                {
                                    FreeItemManager.DragItem(from, fd, room.ContextsWrapper.FreeArgs, toPosition);
                                }
                            }
                        }
                        else
                        {
                            if (BagCapacityUtil.CanDemountAttachment(room, fd, fromInfo, from, false))
                            {
                                FreeItemManager.DragItem(from, fd, room.ContextsWrapper.FreeArgs, toPosition);
                            }
                        }
                    }
                }
            }
            else if (from.StartsWith("w") && from.IndexOf(",") == 3 && PickupItemUtil.IsDefault(to))
            {
                FreeItemInfo fromInfo = FreeItemConfig.GetItemInfo(fromIp.key.GetKey());
                if (BagCapacityUtil.CanDemountAttachment(room, fd, fromInfo, from, false))
                {
                    ItemInventory fromInv = fromIp.GetInventory();
                    ItemInventory toInv   = toIp == null?fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagDefault) : toIp.GetInventory();

                    int[] pos = toIp == null ? new int[] { 0, 0 } : toInv.GetNextEmptyPosition(toIp.GetKey());
                    ItemInventoryUtil.MoveItem(pos[0], pos[1], fromInv, toInv, fromInv.GetInventoryUI(), toInv.GetInventoryUI(), fromIp, null, room.ContextsWrapper.FreeArgs);
                }
            }
            else
            {
                FreeItemManager.DragItem(from, fd, room.ContextsWrapper.FreeArgs, to);
            }

            room.ContextsWrapper.FreeArgs.Resume(PARA_PLAYER_CURRENT);
            room.ContextsWrapper.FreeArgs.GetDefault().GetParameters().Resume(PARA_EVENT_KEY);
        }
        public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message)
        {
            FreeData fd = (FreeData)player.freeData.FreeData;

            room.ContextsWrapper.FreeArgs.TempUse(PARA_PLAYER_CURRENT, fd);
            eventKey.SetValue(message.Ss[0]);
            room.ContextsWrapper.FreeArgs.GetDefault().GetParameters().TempUse(eventKey);

            room.GameRule.HandleFreeEvent(room.RoomContexts, player, message);

            string key = message.Ss[0];

            Debug.LogFormat("click item {0}. ", key);
            if (message.Bs[0])
            {
                // 显示拆分UI
                if (message.Bs[1])
                {
                    PickupItemUtil.ShowSplitUI(room, fd, key);
                    return;
                }
                if (key.StartsWith(ChickenConstant.BagGround))
                {
                    SimpleItemInfo info = PickupItemUtil.GetGroundItemInfo(room, fd, key);
                    if (info.cat > 0)
                    {
                        if (CanChangeBag(room, fd, key))
                        {
                            if (PickupItemUtil.AddItemToPlayer(room, player, info.entityId, info.cat, info.id, info.count))
                            {
                                SimpleProto sp = FreePool.Allocate();
                                sp.Key = FreeMessageConstant.PlaySound;
                                sp.Ks.Add(2);
                                sp.Ins.Add(5018);
                                sp.Bs.Add(false);
                                FreeMessageSender.SendMessage(player, sp);
                            }
                        }
                    }
                }
                else if (key.StartsWith(ChickenConstant.BagDefault))
                {
                    ItemPosition ip   = FreeItemManager.GetItemPosition(room.ContextsWrapper.FreeArgs, key, fd.GetFreeInventory().GetInventoryManager());
                    FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey());
                    if (info.cat == (int)ECategory.WeaponPart)
                    {
                        string inv = PickupItemUtil.AutoPutPart(fd, FreeItemConfig.GetItemInfo(info.cat, info.id));
                        if (inv != null && inv != ChickenConstant.BagDefault)
                        {
                            ItemInventoryUtil.MovePosition(ip,
                                                           fd.GetFreeInventory().GetInventoryManager().GetInventory(inv), 0, 0, room.ContextsWrapper.FreeArgs);
                        }
                    }
                    else
                    {
                        FreeItemManager.UseItem(key, fd, room.ContextsWrapper.FreeArgs);
                    }
                }
                // 点击装配好的配件,自动进背包
                else if (key.StartsWith("w") && key.IndexOf(",") == 3)
                {
                    ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory(key.Substring(0, 3));
                    ItemInventory defaultInventory = fd.GetFreeInventory().GetInventoryManager().GetDefaultInventory();

                    if (ii != null && ii.posList.Count > 0)
                    {
                        ItemPosition ip = ii.posList[0];
                        if (BagCapacityUtil.CanDemountAttachment(room, fd, FreeItemConfig.GetItemInfo(ip.key.GetKey()), key, false))
                        {
                            int[] xy = defaultInventory.GetNextEmptyPosition(ip.GetKey());
                            ItemInventoryUtil.MovePosition(ip,
                                                           defaultInventory, xy[0], xy[1], room.ContextsWrapper.FreeArgs);
                        }
                    }
                }
                else
                {
                    FreeItemManager.UseItem(key, fd, room.ContextsWrapper.FreeArgs);
                }
            }

            room.ContextsWrapper.FreeArgs.Resume(PARA_PLAYER_CURRENT);
            room.ContextsWrapper.FreeArgs.GetDefault().GetParameters().Resume(PARA_EVENT_KEY);
        }