Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private EBulletCaliber GetCaliber(Entity entity, EWeaponSlotType slot)
        {
            var playerEntity = entity as PlayerEntity;
            var weapon       = playerEntity.GetBagLogicImp().GetWeaponInfo(slot);
            var weaponId     = weapon.Id;

            if (weaponId > 0)
            {
                var cfg = _weaponConfigManager.GetConfigById(weaponId);
                return((EBulletCaliber)cfg.Caliber);
            }
            Logger.ErrorFormat("no weapon in slot {0} !!", slot);
            return(EBulletCaliber.Length);
        }