Exemple #1
0
        public static void AddCurrentClipToBag(int key, FreeData fd, IEventArgs args)
        {
            int remainClip = GetCurrentWeaponClip(key, fd, args);
            int clipType   = GetClipType(args.GameContext, key, fd);

            AddClip(remainClip, clipType, fd, args);
            fd.Player.WeaponController().SetReservedBullet((EBulletCaliber)clipType, CarryClipUtil.GetClipCount(clipType, fd, args));
        }
Exemple #2
0
        public static bool CanExchangeAttachment(ServerRoom room, FreeData fd, FreeItemInfo fromPart, FreeItemInfo toPart, WeaponBaseAgent fromAgent, WeaponBaseAgent toAgent)
        {
            double capacity = Math.Round(GetCapacity(fd) - GetWeight(fd), 3);

            int toBullet   = SingletonManager.Get <WeaponPartsConfigManager>().GetConfigById(WeaponPartUtil.GetWeaponFstMatchedPartId(toPart.id, fromAgent.ConfigId)).Bullet;
            int fromBullet = SingletonManager.Get <WeaponPartsConfigManager>().GetConfigById(WeaponPartUtil.GetWeaponFstMatchedPartId(fromPart.id, toAgent.ConfigId)).Bullet;

            if (toBullet == fromBullet)
            {
                return(true);
            }

            int overBulletFrom = fromAgent.BaseComponent.Bullet - fromAgent.WeaponConfigAssy.PropertyCfg.Bullet - toBullet;
            int overBulletTo   = toAgent.BaseComponent.Bullet - toAgent.WeaponConfigAssy.PropertyCfg.Bullet - fromBullet;

            float bulletWeight = 0f;

            if (overBulletFrom > 0)
            {
                bulletWeight += SingletonManager.Get <GameItemConfigManager>().GetConfigById((int)fromAgent.Caliber).Weight *overBulletFrom;
            }

            if (overBulletTo > 0)
            {
                bulletWeight += SingletonManager.Get <GameItemConfigManager>().GetConfigById((int)toAgent.Caliber).Weight *overBulletTo;
            }

            if (capacity < bulletWeight)
            {
                SimpleProto msg = FreePool.Allocate();
                msg.Key = FreeMessageConstant.ChickenTip;
                msg.Ss.Add("word79");
                FreeMessageSender.SendMessage(fd.Player, msg);
                return(false);
            }

            if (overBulletFrom > 0)
            {
                fromAgent.BaseComponent.Bullet = fromAgent.WeaponConfigAssy.PropertyCfg.Bullet + toBullet;
                CarryClipUtil.AddClip(overBulletFrom, (int)fromAgent.Caliber, fd, room.ContextsWrapper.FreeArgs);
                fd.Player.WeaponController().SetReservedBullet(fromAgent.Caliber, CarryClipUtil.GetClipCount((int)fromAgent.Caliber, fd, room.ContextsWrapper.FreeArgs));
            }

            if (overBulletTo > 0)
            {
                toAgent.BaseComponent.Bullet = toAgent.WeaponConfigAssy.PropertyCfg.Bullet + fromBullet;
                CarryClipUtil.AddClip(overBulletTo, (int)toAgent.Caliber, fd, room.ContextsWrapper.FreeArgs);
                fd.Player.WeaponController().SetReservedBullet(toAgent.Caliber, CarryClipUtil.GetClipCount((int)toAgent.Caliber, fd, room.ContextsWrapper.FreeArgs));
            }

            return(true);
        }
        private int CreateItemFromInventory(IEventArgs fr, FreeData fd, ItemInventory ii, Vector3 p, string realName, int entityId)
        {
            int itemAdded = 0;

            if (ii != null && ii.name != ChickenConstant.BagGround)
            {
                foreach (ItemPosition ip in ii.GetItems())
                {
                    FreeMoveEntity en = fr.GameContext.freeMove.CreateEntity();
                    en.AddEntityKey(new EntityKey(fr.GameContext.session.commonSession.EntityIdGenerator.GetNextEntityId(), (short)EEntityType.FreeMove));
                    en.AddPosition();
                    en.position.Value = new Vector3(p.x, p.y, p.z);

                    en.AddFreeData(FreeUtil.ReplaceVar(name, fr), null);
                    en.AddPositionFilter(Core.Components.PositionFilterType.Filter2D, 1000);
                    en.freeData.Cat = FreeEntityConstant.DeadBox;

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

                    if (itemInfo.cat == (int)ECategory.Weapon)
                    {
                        int key = CarryClipUtil.GetWeaponKey(ii.name, fd);
                        if (key >= 1 && key <= 3)
                        {
                            CarryClipUtil.AddCurrentClipToBag(key, fd, fr);
                        }
                    }

                    en.AddFlagImmutability(fr.GameContext.session.currentTimeObject.CurrentTime);

                    SimpleItemInfo info = new SimpleItemInfo(realName, itemInfo.cat, itemInfo.id, ip.GetCount(), en.entityKey.Value.EntityId);
                    en.freeData.Value    = SingletonManager.Get <DeadBoxParser>().ToString(info);
                    en.freeData.IntValue = entityId;

                    en.isFlagSyncNonSelf = true;

                    itemAdded++;
                }
            }

            return(itemAdded);
        }
Exemple #4
0
        public static bool CanDemountAttachment(ServerRoom room, FreeData fd, FreeItemInfo part, string ipStr, bool toGround)
        {
            double          capacity     = Math.Round(GetCapacity(fd) - GetWeight(fd), 3);
            float           bulletWeight = 0f;
            WeaponBaseAgent agent        = fd.Player.WeaponController().GetWeaponAgent((EWeaponSlotType)short.Parse(ipStr.Substring(1, 1)));
            int             overBullet   = 0;

            if (SingletonManager.Get <WeaponPartsConfigManager>().GetConfigById(WeaponPartUtil.GetWeaponFstMatchedPartId(part.id, agent.ConfigId)).Bullet > 0)
            {
                overBullet = agent.BaseComponent.Bullet - agent.WeaponConfigAssy.PropertyCfg.Bullet;
                if (overBullet > 0)
                {
                    bulletWeight = SingletonManager.Get <GameItemConfigManager>().GetConfigById((int)agent.Caliber).Weight *overBullet;
                }
            }

            var partWeight = 0f;

            if (!toGround)
            {
                partWeight = part.weight;
            }

            if (capacity < bulletWeight + partWeight)
            {
                SimpleProto msg = FreePool.Allocate();
                msg.Key = FreeMessageConstant.ChickenTip;
                msg.Ss.Add("word79");
                FreeMessageSender.SendMessage(fd.Player, msg);
                return(false);
            }

            if (overBullet > 0)
            {
                agent.BaseComponent.Bullet = agent.WeaponConfigAssy.PropertyCfg.Bullet;
                CarryClipUtil.AddClip(overBullet, (int)agent.Caliber, fd, room.ContextsWrapper.FreeArgs);
                fd.Player.WeaponController().SetReservedBullet(agent.Caliber, CarryClipUtil.GetClipCount((int)agent.Caliber, fd, room.ContextsWrapper.FreeArgs));
            }

            return(true);
        }