Beispiel #1
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);
        }
Beispiel #2
0
        private static float ReduceDamage(IEventArgs args, FreeData fd, PlayerDamageInfo damage, ItemPosition ip, int percent, ItemType itemType)
        {
            if (ip != null)
            {
                float realDamage = damage.damage;
                float reduce     = damage.damage * percent / 100;
                float realReduce = reduce;

                damage.damage -= realReduce;
                fd.Player.statisticsData.Statistics.DefenseDamage += reduce;

                // 普通帽子不减少
                if (reduce > 0)
                {
                    ip.SetCount(ip.GetCount() - (int)realDamage);
                    UpdateGamePlayData(fd, ip, itemType);

                    args.TempUse("current", fd);

                    if (ip.GetCount() <= 0)
                    {
                        ip.GetInventory().RemoveItem((FreeRuleEventArgs)args, ip);
                        FuntionUtil.Call(args, "showBottomTip", "msg", "{desc:10075," + ip.key.GetName() + "}");
                    }
                    else
                    {
                        ip.GetInventory().GetInventoryUI().UpdateItem((FreeRuleEventArgs)args, ip.GetInventory(), ip);
                    }

                    args.Resume("current");
                }
            }

            return(damage.damage);
        }
Beispiel #3
0
        public static void UpdateGamePlayData(FreeData fd, ItemPosition ip, ItemType itemType)
        {
            GamePlayComponent gamePlay = fd.Player.gamePlay;

            if (ip == null)
            {
                if (itemType == ItemType.Armor)
                {
                    gamePlay.MaxArmor = 0;
                    gamePlay.CurArmor = 0;
                }
                if (itemType == ItemType.Helmet)
                {
                    gamePlay.MaxHelmet = 0;
                    gamePlay.CurHelmet = 0;
                }
            }
            else
            {
                FreeItemInfo itemInfo = FreeItemConfig.GetItemInfo(ip.key.GetKey());
                switch (itemType)
                {
                case ItemType.Armor:
                    gamePlay.CurArmor = Math.Max(0, ip.GetCount());
                    if (itemInfo.id == 1)
                    {
                        gamePlay.MaxArmor = 200;
                    }
                    else if (itemInfo.id == 2)
                    {
                        gamePlay.MaxArmor = 220;
                    }
                    else if (itemInfo.id == 3)
                    {
                        gamePlay.MaxArmor = 250;
                    }
                    break;

                case ItemType.Helmet:
                    gamePlay.CurHelmet = Math.Max(0, ip.GetCount());
                    if (itemInfo.id == 8)
                    {
                        gamePlay.MaxHelmet = 80;
                    }
                    else if (itemInfo.id == 9)
                    {
                        gamePlay.MaxHelmet = 150;
                    }
                    else if (itemInfo.id == 10)
                    {
                        gamePlay.MaxHelmet = 230;
                    }
                    break;
                }
            }
        }
Beispiel #4
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);
        }
Beispiel #5
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);
                    }
                }
            }
        }
 public static void UseItem(ItemPosition ip, FreeData fd, FreeRuleEventArgs fr)
 {
     if (ip != null)
     {
         fr.TempUse(PARA_ITEM, ip.GetKey());
         if (ip.GetKey().Effect(fr))
         {
             if (!ip.GetKey().IsGoods())
             {
                 if (ip.GetKey().IsUseClose())
                 {
                     CloseInventory(ip.GetInventory(), fr);
                 }
                 ip.GetInventory().UseItem(fr, ip);
                 if (ip.GetCount() <= 0 && ip.GetKey().IsConsume())
                 {
                     RemoveUI(ip, fr);
                 }
             }
         }
         fr.Resume(PARA_ITEM);
         if (!ip.GetKey().IsGoods())
         {
             fd.freeInventory.SetCurrentItem(ip, fr);
         }
         ip.GetKey().GetParameters().AddPara(new IntPara(PARA_ITEM_USE_TIME, fr.GameContext.session.currentTimeObject.CurrentTime));
     }
 }
Beispiel #7
0
        private static void ChangeItemStack(int delta, ItemInventory fromIn, ItemInventory toIn, IInventoryUI fromUI, IInventoryUI toUI, ItemPosition ip, ItemPosition old, ISkillArgs args)
        {
            if (ip.GetCount() <= delta)
            {
                RemoveItem(fromIn, ip, args);
                HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args, true);

                old.SetCount(old.GetCount() + (int)MyMath.Min(delta, ip.GetCount()));
                toUI.UpdateItem(args, toIn, old);
            }
            else
            {
                old.SetCount(old.GetKey().GetItemStack());
                ip.SetCount(ip.GetCount() - delta);
                toUI.UpdateItem(args, toIn, old);
                fromUI.UpdateItem(args, fromIn, ip);
            }
        }
Beispiel #8
0
        public static bool MoveOut(ItemInventory fromIn, ItemInventory toIn, ItemPosition ip, int countX, int countY, ISkillArgs args, FreeRuleEventArgs fr, IInventoryUI fromUI, IInventoryUI toUI)
        {
            if (fromIn == toIn)
            {
                // 竖格超出
                if (countY >= toIn.GetRow() || countY < 0)
                {
                    if (toUI.MoveOutAction != null)
                    {
                        ip.GetKey().SetCount(ip.GetCount());
                        fr.TempUse(PARA_ITEM, ip.GetKey());
                        fr.Resume(PARA_ITEM);
                        RemoveItem(fromIn, ip, args);

                        toUI.MoveOutAction.Act(args);
                        return(true);
                    }
                }
            }
            if (fromIn == toIn)
            {
                // 横格超出
                if (countX >= toIn.GetColumn() || countX < 0)
                {
                    if (toUI.MoveOutAction != null)
                    {
                        ip.GetKey().SetCount(ip.GetCount());
                        fr.TempUse(PARA_ITEM, ip.GetKey());
                        fr.Resume(PARA_ITEM);
                        RemoveItem(fromIn, ip, args);

                        toUI.MoveOutAction.Act(args);
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #9
0
        private void SetCount(ItemPosition ip)
        {
            FreeNumberComponet countUI = GetCount();

            if (countUI != null)
            {
                if (ip.GetKey().GetItemStack() == 1)
                {
                    countUI.SetNumber(string.Empty);
                }
                else
                {
                    countUI.SetNumber(ip.GetCount().ToString());
                }
            }
        }
Beispiel #10
0
        private static void DropItem(string inv, FreeData fd, ServerRoom room)
        {
            Debug.LogFormat("inv {0}", inv);
            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 (info.cat > 0)
                {
                    room.RoomContexts.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleEquipmentEntity(
                        (ECategory)info.cat,
                        info.id,
                        ip.GetCount(), fd.Player.position.Value);
                }
            }
        }
Beispiel #11
0
        public void ReDraw(ISkillArgs args, ItemInventory inventory, bool includeBack)
        {
            SimpleProto itemInfo = FreePool.Allocate();

            itemInfo.Key = FreeMessageConstant.ItemInfo;
            itemInfo.Ss.Add(inventory.name);

            if (inventory.posList.Count > 0)
            {
                ItemPosition ip = inventory.posList[0];
                itemInfo.Bs.Add(false);
                FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey());
                itemInfo.Ins.Add(info.cat);
                itemInfo.Ins.Add(info.id);
                itemInfo.Ins.Add(ip.GetCount());
            }
            else
            {
                itemInfo.Bs.Add(true);
            }

            FreeMessageSender.SendMessage(args, "current", itemInfo);
        }
Beispiel #12
0
        public static void Move(ItemInventory fromIn, ItemInventory toIn, ItemPosition ip, int countX, int countY, ISkillArgs args, FreeRuleEventArgs fr, IInventoryUI fromUI, IInventoryUI toUI)
        {
            if (fromIn != toIn)
            {
                fr.TempUse(PARA_ITEM, ip);
                bool canDrop = toIn.IsCanDrop(ip, args);
                // 如果toIn 不可以拖入物品
                if (!canDrop)
                {
                    fromUI.UpdateItem(args, fromIn, ip);
                    if (toIn.GetDropAction() != null)
                    {
                        toIn.GetDropAction().Act(args);
                    }
                    //HandleMoveAction(fromIn, toIn, fromUI, toUI, ip, args);
                    fr.Resume(PARA_ITEM);
                    return;
                }
                fr.Resume(PARA_ITEM);
            }
            // 已有
            ItemPosition[] olds = toIn.GetItem(countX, countY, ip.GetKey().GetGridWidth(), ip.GetKey().GetGridHeight());
            ItemPosition   old  = null;

            if (olds.Length == 1)
            {
                old = olds[0];
                if (old != ip)
                {
                    fr.TempUse(PARA_ITEM, ip);
                    if (old.GetKey().GetKey().Equals(ip.GetKey().GetKey()))
                    {
                        int delta = old.GetKey().GetItemStack() - old.GetCount();
                        if (delta > 0)
                        {
                            // 堆叠物品
                            ChangeItemStack(delta, fromIn, toIn, fromUI, toUI, ip, old, args);
                        }
                        else
                        {
                            // 交换物品位置
                            ExchangeItem(fromIn, toIn, fromUI, toUI, ip, old, args);
                        }
                    }
                    else
                    {
                        if (!ip.DragTo(args, old))
                        {
                            ExchangeItem(fromIn, toIn, fromUI, toUI, ip, old, args);
                        }
                        else
                        {
                            if (ip.GetInventory() != null)
                            {
                                fromUI.UpdateItem(args, fromIn, ip);
                            }
                        }
                    }
                    fr.Resume(PARA_ITEM);
                    return;
                }
            }
            fr.TempUse(PARA_ITEM, ip);
            MoveItem(countX, countY, fromIn, toIn, fromUI, toUI, ip, old, args);
            fr.Resume(PARA_ITEM);
        }
Beispiel #13
0
        public virtual void Draw(SimpleInventoryUI ui, IEventArgs args, ItemInventory inventory, ItemPosition ip)
        {
            this.inventory = inventory;
            if (fui == null)
            {
                fui = new FreeUICreateAction();
                Sharpen.Collections.AddAll(fui.GetComponents(), components);
            }
            ip.GetParameters().AddPara(new StringPara("inventory", inventory.GetName()));
            StringPara img      = new StringPara("img", string.Empty);
            StringPara itemName = new StringPara("name", string.Empty);
            IntPara    count    = new IntPara("count", 0);

            args.GetDefault().GetParameters().TempUse(img);
            args.GetDefault().GetParameters().TempUse(count);
            args.GetDefault().GetParameters().TempUse(itemName);

            img.SetValue(ip.GetKey().GetImg());
            count.SetValue(ip.GetCount());
            itemName.SetValue(ip.GetKey().GetName());
            FreeImageComponet back = GetBackground();

            if (ui.nomouse)
            {
                back.SetNoMouse("true");
            }
            if (ui.itemFixed)
            {
                back.SetFixed("true");
            }
            int startX = GetX(args, ui, ip, back);
            int startY = GetY(args, ui, ip, back);

            if (!StringUtil.IsNullOrEmpty(notused) && !StringUtil.IsNullOrEmpty(used))
            {
                if (ip.IsUsed())
                {
                    back.SetUrl(used);
                }
                else
                {
                    back.SetUrl(notused);
                }
            }
            back.SetX(startX.ToString());
            back.SetY(startY.ToString());
            back.SetRelative(ui.relative);
            back.SetEvent(inventory.GetName() + "," + ip.GetX() + "," + ip.GetY());
            FreeImageComponet itemImg         = back;
            FreeImageComponet secondComponent = GetItemImage();

            if (secondComponent != null)
            {
                back.SetEvent(string.Empty);
                itemImg = secondComponent;
            }
            if (ui.nomouse)
            {
                itemImg.SetNoMouse("true");
            }
            if (ui.itemFixed)
            {
                itemImg.SetFixed("true");
            }
            itemImg.SetUrl(ip.GetKey().GetImg());
            itemImg.SetOriginalSize(ip.GetKey().GetItemWidth() + "," + ip.GetKey().GetItemHeight());
            if (itemImg == back)
            {
                AdjustSize(args, ui, ip, inventory, back, itemImg, startX, startY);
            }
            else
            {
                AdjustSize(args, ui, ip, inventory, back, itemImg, 0, 0);
            }
            SetCount(ip);
            fui.SetKey(ip.GetUIKey());
            fui.SetShow(inventory.IsOpen());
            fui.SetScope(1);
            fui.SetPlayer("current");
            fui.Act(args);
            UpdateHotKey(ui, args, ip);
            args.GetDefault().GetParameters().Resume("img");
            args.GetDefault().GetParameters().Resume("name");
            args.GetDefault().GetParameters().Resume("count");
        }
        public void ReDraw(ISkillArgs args, ItemInventory inventory, bool includeBack)
        {
            if (update == null)
            {
                update = new FreeUIUpdateAction();
            }

            update.SetKey(FreeUtil.ReplaceVar(uiKey, args));
            update.ClearValue();

            FreeData fd = (FreeData)args.GetUnit("current");

            FreePrefabValue v = new FreePrefabValue();

            v.SetSeq("1");
            update.AddValue(v);
            v.AddOneValue(new OnePrefabValue(image, ""));
            if (!string.IsNullOrEmpty(name))
            {
                v.AddOneValue(new OnePrefabValue(name, ""));
            }
            if (!string.IsNullOrEmpty(count))
            {
                v.AddOneValue(new OnePrefabValue(count, ""));
            }
            update.SetScope(1);
            update.SetPlayer("current");
            update.Act(args);

            if (inventory.posList.Count > 0)
            {
                ItemPosition ip = inventory.posList[0];
                v.Clear();
                v.AddOneValue(new OnePrefabValue(image, ip.key.GetImg()));
                if (!string.IsNullOrEmpty(name))
                {
                    v.AddOneValue(new OnePrefabValue(name, ip.key.GetName()));
                }
                if (!string.IsNullOrEmpty(count))
                {
                    if (ip.count != 1)
                    {
                        v.AddOneValue(new OnePrefabValue(count, ip.GetCount().ToString()));
                    }
                }
                else
                {
                    v.AddOneValue(new OnePrefabValue(count, ""));
                }
                update.Act(args);

                redrawPart(inventory, args, ip, fd);

                SimpleProto itemInfo = FreePool.Allocate();
                itemInfo.Key = FreeMessageConstant.ItemInfo;
                itemInfo.Ss.Add(inventory.name);
                FreeItemInfo info = FreeItemConfig.GetItemInfo(ip.key.GetKey());
                itemInfo.Ins.Add(info.cat);
                itemInfo.Ins.Add(info.id);
                itemInfo.Ins.Add(ip.GetCount());
                FreeMessageSender.SendMessage(args, "current", itemInfo);
            }
            else
            {
                clearPart(inventory, args, fd);
            }
        }