Пример #1
0
        public EFuncResult SetWeaponPart(EWeaponSlotType slot, int id)
        {
            if (slot == EWeaponSlotType.None)
            {
                return(EFuncResult.Exception);
            }

            var weaponComp = GetWeaponComponentBySlot(slot);

            if (weaponComp.Id < 1)
            {
                Logger.ErrorFormat("set attachment failed : no weapon in slot {0}", slot);
                return(EFuncResult.Exception);
            }
            var lastParts = weaponComp.GetParts();
            var weaponCfg = _newWeaponConfigManager.GetConfigById(weaponComp.Id);

            if (null == weaponCfg)
            {
                return(EFuncResult.Exception);
            }

            var realAttachId = BagUtility.GetRealAttachmentId(id, weaponCfg.Id);
            var match        = SingletonManager.Get <WeaponPartsConfigManager>().IsPartMatchWeapon(realAttachId, weaponCfg.Id);

            if (!match)
            {
                return(EFuncResult.Failed);
            }

            if (WeaponValid(weaponComp))
            {
                var attachments = WeaponPartsUtil.ModifyParts(
                    weaponComp.GetParts(),
                    SingletonManager.Get <WeaponPartsConfigManager>().GetPartType(realAttachId),
                    realAttachId);
                weaponComp.ApplyParts(attachments);
            }
            else
            {
                Logger.ErrorFormat("No weapon in slot {0}", slot);
            }

            if (slot == CurWeaponSlot)
            {
                RefreshCurrentWeaponAttachmentLogic();
            }

            RefreshWeaponPartsModel(weaponComp.Id,
                                    slot,
                                    lastParts,
                                    weaponComp.GetParts());
            return(EFuncResult.Success);
        }
Пример #2
0
        /// <summary>
        /// API:parts
        /// </summary>
        /// <param name="slot"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool SetSlotWeaponPart(EWeaponSlotType slot, int id)
        {
            WeaponEntity entity = GetWeaponAgent(slot).Entity;

            if (entity == null)
            {
                throw new ExWeaponNotFoundException("{0} slot weapon not found", slot);
                return(false);
            }
            NewWeaponConfigItem wpConfig  = SingletonManager.Get <WeaponConfigManager>().GetConfigById(entity.weaponBasicData.ConfigId);
            WeaponPartsStruct   lastParts = entity.weaponBasicData.GetParts();
            int  realAttachId             = BagUtility.GetRealAttachmentId(id, wpConfig.Id);
            bool match = SingletonManager.Get <WeaponPartsConfigManager>().IsPartMatchWeapon(realAttachId, wpConfig.Id);

            if (!match)
            {
                return(false);
            }
            var attachments = WeaponPartsUtil.ModifyParts(
                entity.weaponBasicData.GetParts(),
                SingletonManager.Get <WeaponPartsConfigManager>().GetPartType(realAttachId),
                realAttachId);

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

            refreshData.weaponInfo = entity.ToWeaponScan();
            refreshData.slot       = slot;
            refreshData.oldParts   = lastParts;
            refreshData.newParts   = entity.weaponBasicData.GetParts();
            RefreshModelWeaponParts(refreshData);
            return(true);
        }