Exemplo n.º 1
0
        private static string putOnPart(FreeData fd, int weaponType, FreeItemInfo info, string toInv = "", ServerRoom room = null)
        {
            WeaponResConfigItem weapon = GetWeapon(fd, weaponType);

            if (weapon != null)
            {
                foreach (EWeaponPartType part in SingletonManager.Get <WeaponPartsConfigManager>().GetAvaliablePartTypes(weapon.Id))
                {
                    int p        = FreeWeaponUtil.GetWeaponPart(part);
                    int detailId = WeaponUtil.GetRealAttachmentId(info.id, weapon.Id);
                    if (SingletonManager.Get <WeaponPartsConfigManager>().IsPartMatchWeapon(detailId, weapon.Id))
                    {
                        if ("p" + p == info.subType)
                        {
                            string        inv = "w" + weaponType + p;
                            ItemInventory ii  = fd.freeInventory.GetInventoryManager().GetInventory(inv);
                            if (ii != null && (ii.posList.Count == 0 ||
                                               toInv.StartsWith("w" + weaponType)))
                            {
                                if (ii.posList.Count > 0)
                                {
                                    DropPart(inv, fd, room);
                                }
                                return(inv);
                            }
                        }
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// API:parts
        /// </summary>
        /// <param name="slot"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool SetWeaponPart(EWeaponSlotType slot, int id)
        {
            var agent = GetWeaponAgent(slot);

            if (!agent.IsValid())
            {
                return(false);
            }
            WeaponPartsStruct lastParts = agent.BaseComponent.CreateParts();
            int  realAttachId           = WeaponUtil.GetRealAttachmentId(id, agent.ResConfig.Id);
            bool match = SingletonManager.Get <WeaponPartsConfigManager>().IsPartMatchWeapon(realAttachId, agent.ResConfig.Id);

            if (!match)
            {
                return(false);
            }
            var attachments = WeaponPartUtil.ModifyPartItem(
                agent.BaseComponent.CreateParts(),
                SingletonManager.Get <WeaponPartsConfigManager>().GetPartType(realAttachId),
                realAttachId);

            agent.BaseComponent.ApplyParts(attachments);
            if (slot == HeldSlotType)
            {
                RefreshHeldWeaponAttachment();
            }
            WeaponPartsRefreshStruct refreshData = new WeaponPartsRefreshStruct();

            refreshData.weaponInfo = agent.ComponentScan;
            refreshData.slot       = slot;
            refreshData.oldParts   = lastParts;
            refreshData.newParts   = agent.BaseComponent.CreateParts();
            RefreshModelWeaponParts(refreshData);
            return(true);
        }