Ejemplo n.º 1
0
        private void HandleDropWeapon(IEventArgs args)
        {
            if ("DropWeapon" == code)
            {
                int      key = FreeUtil.ReplaceInt("{key}", args);
                FreeData fd  = (FreeData)args.GetUnit("current");

                ItemInventory defInv = fd.freeInventory.GetInventoryManager().GetDefaultInventory();
                for (int i = 1; i <= 5; i++)
                {
                    ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory("w" + key + "" + i);
                    if (ii.posList.Count > 0)
                    {
                        ItemPosition ip = ii.posList[0];
                        if (BagCapacityUtil.CanAddToBag(args, fd, ip))
                        {
                            int[] next = defInv.GetNextEmptyPosition(ip.key);
                            ItemInventoryUtil.MovePosition(ip, defInv, next[0], next[1], (ISkillArgs)args);
                        }
                        else
                        {
                            ItemInventory ground = fd.freeInventory.GetInventoryManager().GetInventory("ground");
                            int[]         next   = ground.GetNextEmptyPosition(ip.key);
                            ItemInventoryUtil.MovePosition(ip, ground, next[0], next[1], (ISkillArgs)args);
                        }
                    }
                }

                CarryClipUtil.AddCurrentClipToBag(key, fd, args);
            }
        }
Ejemplo n.º 2
0
        private static void DropPart(string inv, FreeData fd, ServerRoom room)
        {
            int           c3 = fd.freeInventory.GetInventoryManager().GetInventory(inv).posList.Count;
            ItemInventory w3 = fd.freeInventory.GetInventoryManager().GetInventory(inv);

            if (c3 > 0)
            {
                ItemPosition ip = w3.posList[0];

                w3.RemoveItem(room.FreeArgs, ip);

                FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey());

                if (BagCapacityUtil.CanAddToBag(room.FreeArgs, fd, ip))
                {
                    fd.freeInventory.GetInventoryManager().GetDefaultInventory().AddItem(room.FreeArgs, ip.key, true);
                }
                else
                {
                    if (info.cat > 0)
                    {
                        room.RoomContexts.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleEquipmentEntity(
                            (ECategory)info.cat,
                            info.id,
                            ip.GetCount(), fd.Player.position.Value);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message)
 {
     if (BagCapacityUtil.CanAddToBag(room.FreeArgs, (FreeData)player.freeData.FreeData, message.Ins[1], message.Ins[2], message.Ins[3]))
     {
         PickupItemUtil.AddItemToPlayer(room, player, message.Ins[0], message.Ins[1], message.Ins[2], message.Ins[3]);
     }
 }
Ejemplo n.º 4
0
        private bool HandleBag(string from, string to, ServerRoom room, FreeData fd)
        {
            FreeItemInfo info = null;

            if (from.StartsWith(ChickenConstant.BagGround))
            {
                SimpleItemInfo sinfo = PickupItemUtil.GetGroundItemInfo(room, fd, from);
                info = FreeItemConfig.GetItemInfo(sinfo.cat, sinfo.id);
            }
            else
            {
                ItemPosition ip = FreeItemManager.GetItemPosition(room.ContextsWrapper.FreeArgs, from, fd.freeInventory.GetInventoryManager());
                if (ip == null)
                {
                    ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory(from.Trim());
                    if (ii != null && ii.posList.Count > 0)
                    {
                        ip = ii.posList[0];
                    }
                }
                if (ip != null)
                {
                    info = FreeItemConfig.GetItemInfo(ip.key.GetKey());
                }
            }

            if (info != null && info.cat == 9)
            {
                RoleAvatarConfigItem avatar = SingletonManager.Get <RoleAvatarConfigManager>().GetConfigById(info.id);
                if (avatar.Capacity > 0)
                {
                    if (from.StartsWith(ChickenConstant.BagGround) && !to.StartsWith(ChickenConstant.BagGround))
                    {
                        return(BagCapacityUtil.CanAddToBag(room.ContextsWrapper.FreeArgs, fd, info.cat, info.id, 1));
                    }

                    if (to.StartsWith(ChickenConstant.BagGround) && !from.StartsWith(ChickenConstant.BagGround))
                    {
                        return(BagCapacityUtil.CanTakeOff(room.ContextsWrapper.FreeArgs, fd, info.cat, info.id));
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        public static void AddItemToPlayer(ServerRoom room, PlayerEntity player, int entityId, int cat, int id, int count, string toInv = "")
        {
            SceneObjectEntity entity         = room.RoomContexts.sceneObject.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(entityId, (short)EEntityType.SceneObject));
            FreeMoveEntity    freeMoveEntity = null;

            if (entity == null || entity.isFlagDestroy)
            {
                freeMoveEntity = room.RoomContexts.freeMove.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(entityId, (short)EEntityType.FreeMove));
                if (freeMoveEntity == null)
                {
                    return;
                }
            }

            room.FreeArgs.TempUse("current", (FreeData)player.freeData.FreeData);

            if (!FreeItemConfig.Contains(cat, id))
            {
                return;
            }

            FreeItemInfo             item   = FreeItemConfig.GetItemInfo(cat, id);
            CreateItemToPlayerAction action = new CreateItemToPlayerAction();

            FreeData fd = (FreeData)player.freeData.FreeData;

            action.name = "default";

            switch (item.cat)
            {
            case (int)ECategory.Weapon:
                if (item.subType == "w1")
                {
                    action.name = "w1";

                    int c1 = fd.freeInventory.GetInventoryManager().GetInventory("w1").posList.Count;
                    int c2 = fd.freeInventory.GetInventoryManager().GetInventory("w2").posList.Count;


                    if (toInv.StartsWith("w1"))
                    {
                        action.name = "w1";
                        if (c1 > 0)
                        {
                            DropItem(action.name, fd, room);
                        }
                    }
                    else if (toInv.StartsWith("w2"))
                    {
                        action.name = "w2";
                        if (c2 > 0)
                        {
                            DropItem(action.name, fd, room);
                        }
                    }
                    else
                    {
                        if (c1 > 0 && c2 == 0)
                        {
                            action.name = "w2";
                        }

                        if (c1 > 0 && c2 > 0)
                        {
                            int currentKey = FreeWeaponUtil.GetWeaponKey(fd.Player.WeaponController().HeldSlotType);
                            if (currentKey == 0)
                            {
                                currentKey = 1;
                            }
                            if (currentKey == 1 || currentKey == 2)
                            {
                                action.name = "w" + currentKey;
                            }
                            else
                            {
                                action.name = "w1";
                            }

                            DropItem(action.name, fd, room);
                        }
                    }
                }
                else if (item.subType == "w2")
                {
                    action.name = "w3";
                    DropItem(action.name, fd, room);
                }
                else if (item.subType == "w3")
                {
                    action.name = "w4";
                    DropItem(action.name, fd, room);
                }
                else if (item.subType == "w4")
                {
                    action.name = "default";
                }

                break;

            case (int)ECategory.Avatar:
                action.name = item.subType;
                DropItem(item.subType, fd, room);
                break;

            case (int)ECategory.WeaponPart:
                action.name = AutoPutPart(fd, item, toInv, room);
                break;

            default:
                break;
            }

            //handleDropOne(new string[] { "w2" }, action, item, fd, room, entity);
            //handleAddToDefault(new string[] { "p1", "p2", "p3", "p4", "p5" }, action, item, fd, room, entity);

            action.key = FreeItemConfig.GetItemKey(item.cat, item.id);

            bool canAdd = true;

            if (action.name == "default")
            {
                canAdd = BagCapacityUtil.CanAddToBag(room.FreeArgs, fd, item.cat, item.id, count);
            }

            if (canAdd)
            {
                PlayerAnimationAction.DoAnimation(room.RoomContexts, PlayerAnimationAction.Interrupt, fd.Player, true);
                PlayerAnimationAction.DoAnimation(room.RoomContexts, 101, fd.Player, true);

                if (!string.IsNullOrEmpty(action.key))
                {
                    action.count = count.ToString();
                    action.SetPlayer("current");
                    room.FreeArgs.TempUse("current", fd);

                    action.Act(room.FreeArgs);

                    room.FreeArgs.Resume("current");
                }
                else
                {
                    Debug.LogError(item.cat + "-" + item.key + " not existed");
                }

                if (entity != null)
                {
                    entity.isFlagDestroy = true;
                }

                if (freeMoveEntity != null)
                {
                    freeMoveEntity.isFlagDestroy = true;
                }
                //Debug.LogErrorFormat("destroy entity {0}", entity != null);

                FreeSoundUtil.PlayOnce("pick", 225, room.FreeArgs, fd);
            }

            room.FreeArgs.Resume("current");
        }
Ejemplo n.º 6
0
        public static void DragItem(string key, FreeData fd, ISkillArgs args, string toKey)
        {
            ItemPosition ip = GetItemPosition(args, key, fd.freeInventory.GetInventoryManager());

            if (ip == null)
            {
                ItemInventory inv = fd.freeInventory.GetInventoryManager().GetInventory(key.Trim());
                if (inv != null && inv.GetInventoryUI() is UnityOneInventoryUi)
                {
                    if (inv.posList.Count > 0)
                    {
                        ip = inv.posList[0];
                    }
                }
            }
            ItemPosition toIp = null;

            if (!StringUtil.IsNullOrEmpty(toKey))
            {
                toIp = GetItemPosition(args, toKey, fd.freeInventory.GetInventoryManager());
            }
            if (ip != null)
            {
                InventoryManager invManager = fd.freeInventory.GetInventoryManager();
                ItemInventory    fromInv    = ip.GetInventory();

                ItemInventory toInv = null;
                if (toIp != null)
                {
                    toInv = toIp.GetInventory();
                }
                else
                {
                    string[] ss = toKey.Split(',');
                    toInv = fd.freeInventory.GetInventoryManager().GetInventory(ss[0].Trim());
                }

                int x = -1;
                int y = -1;
                if (toIp != null)
                {
                    x = toIp.x;
                    y = toIp.y;
                }
                else if (toInv != null)
                {
                    if (toInv.GetName() == ChickenConstant.BagDefault)
                    {
                        foreach (ItemPosition old in toInv.GetItems())
                        {
                            if (old.GetKey().GetKey() == ip.GetKey().GetKey() && old.GetCount() < ip.GetKey().GetItemStack())
                            {
                                x = old.GetX();
                                y = old.GetY();
                                break;
                            }
                        }
                    }

                    if (x < 0)
                    {
                        int[] pos = toInv.GetNextEmptyPosition(ip.GetKey());
                        x = pos[0];
                        y = pos[1];
                    }
                }

                if (toInv != null && fromInv != toInv)
                {
                    if (toInv.GetName() == ChickenConstant.BagDefault)
                    {
                        if (BagCapacityUtil.CanAddToBag(args, fd, ip))
                        {
                            ItemInventoryUtil.Move(fromInv, toInv, ip, x, y, args, (FreeRuleEventArgs)args, fromInv.GetInventoryUI(), toInv.GetInventoryUI());
                        }
                    }
                    else
                    {
                        ItemInventoryUtil.Move(fromInv, toInv, ip, x, y, args, (FreeRuleEventArgs)args, fromInv.GetInventoryUI(), toInv.GetInventoryUI());
                    }
                }
                else
                {
                    if (toInv == null)
                    {
                        //fromInv.GetInventoryUI().ReDraw(args, fromInv, true);
                    }
                    else
                    {
                        //fromInv.GetInventoryUI().ReDraw(args, fromInv, true);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message)
        {
            FreeData fd = (FreeData)player.freeData.FreeData;

            room.FreeArgs.TempUse(PARA_PLAYER_CURRENT, fd);
            eventKey.SetValue(message.Ss[0]);
            room.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("ground"))
                {
                    SimpleItemInfo info = PickupItemUtil.GetGroundItemInfo(room, fd, key);
                    if (info.cat > 0)
                    {
                        if (CanChangeBag(room, fd, key))
                        {
                            PickupItemUtil.AddItemToPlayer(room, player, info.entityId, info.cat, info.id, info.count);
                        }
                    }
                }
                else if (key.StartsWith("default"))
                {
                    ItemPosition ip   = FreeItemManager.GetItemPosition(room.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 != "default")
                        {
                            ItemInventoryUtil.MovePosition(ip,
                                                           fd.GetFreeInventory().GetInventoryManager().GetInventory(inv), 0, 0, room.FreeArgs);
                        }
                    }
                    else
                    {
                        FreeItemManager.UseItem(key, fd, room.FreeArgs);
                    }
                }
                // 点击装配好的配件,自动进背包
                else if (key.StartsWith("w") && key.Length == 3)
                {
                    ItemInventory ii = fd.freeInventory.GetInventoryManager().GetInventory(key);
                    ItemInventory defaultInventory = fd.GetFreeInventory().GetInventoryManager().GetDefaultInventory();

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

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