Exemple #1
0
        public override void DoAction(IEventArgs args)
        {
            Vector3 p           = UnityPositionUtil.ToVector3(pos.Select(args));
            string  realName    = FreeUtil.ReplaceVar(name, args);
            var     groupEntity = args.GameContext.freeMove.CreateEntity();

            groupEntity.AddEntityKey(new EntityKey(args.GameContext.session.commonSession.EntityIdGenerator.GetNextEntityId(), (short)EEntityType.FreeMove));
            groupEntity.AddPosition();
            groupEntity.position.Value = new Vector3(p.x, p.y, p.z);
            groupEntity.AddFreeData("", null);
            groupEntity.AddPositionFilter(Core.Components.PositionFilterType.Filter2D, 1000);
            groupEntity.freeData.Value = "";
            if (type == 1)
            {
                groupEntity.freeData.Cat = FreeEntityConstant.DeadBoxGroup;
            }
            else if (type == 2)
            {
                groupEntity.freeData.Cat = FreeEntityConstant.DropBoxGroup;
            }
            groupEntity.isFlagSyncNonSelf = true;

            if (string.IsNullOrEmpty(id))
            {
                ItemDrop[] list = FreeItemDrop.GetDropItems(FreeUtil.ReplaceVar(cat, args), FreeUtil.ReplaceInt(count, args), args.GameContext.session.commonSession.RoomInfo.MapId);
                foreach (ItemDrop drop in list)
                {
                    CreateItemFromItemDrop(args, p, drop, realName);
                    List <ItemDrop> extra = FreeItemDrop.GetExtraItems(drop);
                    foreach (ItemDrop e in extra)
                    {
                        CreateItemFromItemDrop(args, p, e, realName);
                    }
                }
            }
            else
            {
                PlayerEntity player = args.GameContext.player.GetEntityWithEntityKey(new EntityKey(FreeUtil.ReplaceInt(id, args), (short)EEntityType.Player));
                if (player != null)
                {
                    groupEntity.freeData.IntValue = player.entityKey.Value.EntityId;
                    groupEntity.freeData.Value    = realName;
                    realName = player.playerInfo.PlayerName;
                    FreeData fd = ((FreeData)player.freeData.FreeData);
                    foreach (string inv in fd.GetFreeInventory().GetInventoryManager().GetInventoryNames())
                    {
                        ItemInventory ii = fd.GetFreeInventory().GetInventoryManager().GetInventory(inv);
                        if (ii.name != ChickenConstant.BagDefault)
                        {
                            CreateItemFromInventory(args, fd, ii, p, realName);
                        }
                    }
                    CreateItemFromInventory(args, fd, fd.GetFreeInventory().GetInventoryManager().GetDefaultInventory(), p, realName);
                }
            }
        }
Exemple #2
0
        // 获取玩家物品总重量
        public static float GetWeight(FreeData fd)
        {
            float         w  = 0;
            ItemInventory ii = fd.GetFreeInventory().GetInventoryManager().GetDefaultInventory();

            if (ii != null)
            {
                foreach (ItemPosition ip in ii.GetItems())
                {
                    FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.GetKey().GetKey());

                    w += ip.GetCount() * info.weight;
                }
            }
            return(w);
        }
        public override void DoAction(IEventArgs args)
        {
            FreeRuleEventArgs fr     = (FreeRuleEventArgs)args;
            IGameUnit         player = GetPlayer(args);

            if (StringUtil.IsNullOrEmpty(item))
            {
                item = "item";
            }
            if (player != null)
            {
                FreeData fd = (FreeData)player;
                FreeItem fi = (FreeItem)fr.GetUnit(FreeUtil.ReplaceVar(item, args));
                FreeItemManager.UseItem(fd.GetFreeInventory().GetItemPosition(fi), fd, fr);
            }
        }
Exemple #4
0
 private void HandleAutoPartPut(IEventArgs args)
 {
     if (code == "AutoPart")
     {
         FreeData fd = (FreeData)args.GetUnit("current");
         if (fd != null)
         {
             ItemPosition[] items = fd.freeInventory.GetInventoryManager().GetDefaultInventory().GetItems();
             foreach (ItemPosition ip in items)
             {
                 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.StartsWith("w" + FreeUtil.ReplaceVar("{key}", args)))
                     {
                         ItemInventoryUtil.MovePosition(ip,
                                                        fd.GetFreeInventory().GetInventoryManager().GetInventory(inv), 0, 0, (ISkillArgs)args);
                     }
                 }
             }
         }
     }
 }
Exemple #5
0
 public static void ShowSplitUI(ServerRoom room, FreeData fd, string key)
 {
     // 分拆道具
     if (key.StartsWith("default"))
     {
         ItemPosition ip   = FreeItemManager.GetItemPosition(room.FreeArgs, key, fd.GetFreeInventory().GetInventoryManager());
         FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey());
         if (ip.count > 1)
         {
             SimpleProto data = FreePool.Allocate();
             data.Key = FreeMessageConstant.ShowSplitUI;
             data.Ins.Add(info.cat);
             data.Ins.Add(info.id);
             data.Ins.Add(ip.count);
             data.Ss.Add(key);
             data.Ss.Add(ip.GetKey().GetName());
             FreeMessageSender.SendMessage(fd.Player, data);
         }
     }
 }
Exemple #6
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);
        }
        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);
        }
Exemple #8
0
        public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message)
        {
            FreeData fd = (FreeData)player.freeData.FreeData;

            room.FreeArgs.TempUse(PARA_PLAYER_CURRENT, fd);

            string key   = message.Ss[0];
            int    count = message.Ins[0];

            if (key.StartsWith(ChickenConstant.BagDefault))
            {
                ItemPosition ip   = FreeItemManager.GetItemPosition(room.FreeArgs, key, fd.GetFreeInventory().GetInventoryManager());
                FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey());

                if (ip.GetCount() > count)
                {
                    ip.SetCount(ip.GetCount() - count);
                    ip.GetInventory().GetInventoryUI().ReDraw((ISkillArgs)room.FreeArgs, ip.GetInventory(), true);
                }
                else
                {
                    ip.GetInventory().RemoveItem((ISkillArgs)room.FreeArgs, ip);
                }

                room.RoomContexts.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleEquipmentEntity(
                    (Assets.XmlConfig.ECategory)info.cat,
                    info.id,
                    count,
                    fd.Player.position.Value);
            }

            room.FreeArgs.Resume(PARA_PLAYER_CURRENT);
        }
 public static void ShowSplitUI(ServerRoom room, FreeData fd, string key)
 {
     // 分拆道具
     if (key.StartsWith(ChickenConstant.BagDefault))
     {
         ItemPosition ip        = FreeItemManager.GetItemPosition(room.ContextsWrapper.FreeArgs, key, fd.GetFreeInventory().GetInventoryManager());
         FreeItemInfo info      = FreeItemConfig.GetItemInfo(ip.key.GetKey());
         var          stackable = true;
         if (info.cat == (int)ECategory.Weapon)
         {
             WeaponResConfigItem item = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(info.id);
             if (item.Type != (int)EWeaponType_Config.ThrowWeapon)
             {
                 stackable = false;
             }
         }
         else
         {
             if (info.stack <= 1)
             {
                 stackable = false;
             }
         }
         SimpleProto data = FreePool.Allocate();
         if (!stackable || ip.count <= 1)
         {
             data.Key = FreeMessageConstant.ChickenTip;
             data.Ss.Add("word78");
             FreeMessageSender.SendMessage(fd.Player, data);
             return;
         }
         data.Key = FreeMessageConstant.ShowSplitUI;
         data.Ins.Add(info.cat);
         data.Ins.Add(info.id);
         data.Ins.Add(ip.count);
         data.Ss.Add(key);
         data.Ss.Add(ip.GetKey().GetName());
         FreeMessageSender.SendMessage(fd.Player, data);
         PlayerStateUtil.AddPlayerState(EPlayerGameState.InterruptItem, fd.Player.gamePlay);
     }
 }
Exemple #10
0
        public void Handle(ServerRoom room, PlayerEntity player, SimpleProto message)
        {
            FreeData fd = (FreeData)player.freeData.FreeData;

            room.ContextsWrapper.FreeArgs.TempUse(PARA_PLAYER_CURRENT, fd);

            string key   = message.Ss[0];
            int    count = message.Ins[0];

            if (key.StartsWith(ChickenConstant.BagDefault))
            {
                ItemPosition ip   = FreeItemManager.GetItemPosition(room.ContextsWrapper.FreeArgs, key, fd.GetFreeInventory().GetInventoryManager());
                FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey());

                if (ip.GetCount() > count)
                {
                    if (info.cat == (int)ECategory.Weapon && SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(info.id).Type == (int)EWeaponType_Config.ThrowWeapon)
                    {
                        CarryClipUtil.DeleteGrenade(count, info.id, fd, room.ContextsWrapper.FreeArgs);
                        for (int i = 0; i < count; i++)
                        {
                            player.WeaponController().RemoveGreande(info.id);
                        }
                    }
                    else
                    {
                        ip.SetCount(ip.GetCount() - count);
                        ip.GetInventory().GetInventoryUI().ReDraw((ISkillArgs)room.ContextsWrapper.FreeArgs, ip.GetInventory(), true);
                    }
                }
                else
                {
                    ip.GetInventory().RemoveItem((ISkillArgs)room.ContextsWrapper.FreeArgs, ip);
                }

                room.RoomContexts.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleObjectEntity(
                    (ECategory)info.cat, info.id, count, fd.Player.position.Value);

                if (info.cat == (int)ECategory.GameItem && SingletonManager.Get <GameItemConfigManager>().GetConfigById(info.id).Type == (int)GameItemType.Bullet)
                {
                    player.WeaponController().SetReservedBullet((EBulletCaliber)info.id, CarryClipUtil.GetClipCount(info.id, fd, room.ContextsWrapper.FreeArgs));
                }

                SimpleProto sp = FreePool.Allocate();
                sp.Key = FreeMessageConstant.PlaySound;
                sp.Ks.Add(2);
                sp.Ins.Add(5017);
                sp.Bs.Add(false);
                FreeMessageSender.SendMessage(fd.Player, sp);
            }

            room.ContextsWrapper.FreeArgs.Resume(PARA_PLAYER_CURRENT);
        }