예제 #1
0
        public Err_WeaponLogicErrCode AddWeaponToSlot(EWeaponSlotType slot, WeaponInfo weapon, out WeaponInfo lastWeapon)
        {
            lastWeapon = WeaponInfo.Empty;
            if (slot == EWeaponSlotType.None)
            {
                Logger.Error("slot should not be none");
                return(Err_WeaponLogicErrCode.Err_SlotNone);
            }
            if (!_playerEntity.modeLogic.ModeLogic.IsSlotValid(slot))
            {
                Logger.ErrorFormat("slot {0} is not valid in this mode ", slot);
                return(Err_WeaponLogicErrCode.Err_SlotInvailed);
            }

            var weaponCfg = _newWeaponConfigManager.GetConfigById(weapon.Id);

            if (null == weaponCfg)
            {
                return(Err_WeaponLogicErrCode.Err_IdNotExisted);
            }
            var weaponComp = GetWeaponComponentBySlot(slot);

            if (null == weaponComp)
            {
                Logger.ErrorFormat("set weapon failed : weaponcompent in slot {0} is null", slot);
                return(Err_WeaponLogicErrCode.Err_SlotNone);
            }
            lastWeapon = GetWeaponInfo(slot);
            var attachments = weapon.GetParts();

            weapon.CopyToWeaponComponentWithDefaultParts(weaponComp);
            weaponComp.FireMode = 0;
            var avatarId = weapon.AvatarId;

            if (avatarId < 1)
            {
                avatarId = weaponCfg.AvatorId;
            }
            ProcessMountWeaponInPackage(slot.ToWeaponInPackage(), weapon.Id, avatarId);
            RefreshWeaponPartsModel(weapon.Id, slot, new WeaponPartsStruct(), attachments);
            if (slot == GetCurrentWeaponSlot())
            {
                RefreshCurrentWeaponLogic();
            }
            return(Err_WeaponLogicErrCode.Sucess);
        }