Exemplo n.º 1
0
        private ExpandWeaponLogicConfig GetAndCacheConfig(int id, WeaponPartsStruct weaponParts)
        {
            InitCache();
            Dictionary <WeaponPartsStruct, ExpandWeaponLogicConfig> partsDic;

            if (_configCache.TryGetValue(id, out partsDic))
            {
                ExpandWeaponLogicConfig config;
                if (partsDic.TryGetValue(weaponParts, out config))
                {
                    return(config);
                }
            }

            Prepare(weaponParts);
            var weaponConfig = _weaponDataConfigManager.GetConfigById(id);

            if (null == weaponConfig)
            {
                Logger.ErrorFormat("WeaponConfig is null for {0}", id);
                return(null);
            }
            var baseConfig   = weaponConfig.WeaponLogic;
            var targetConfig = baseConfig.Copy();

            ApplyAttachment(baseConfig, targetConfig);
            if (!_configCache.ContainsKey(id))
            {
                _configCache[id] = new Dictionary <WeaponPartsStruct, ExpandWeaponLogicConfig>(WeaponPartsStructComparer.Instance);
            }

            var defaultWeaponLogicCfg = targetConfig as DefaultWeaponLogicConfig;

            if (null != defaultWeaponLogicCfg)
            {
                var expandConfig = new ExpandWeaponLogicConfig(defaultWeaponLogicCfg);
                _configCache[id][weaponParts] = expandConfig;
                return(expandConfig);
            }
            else
            {
                var tacticWeaponLogicCfg = targetConfig as TacticWeaponLogicConfig;
                if (null != tacticWeaponLogicCfg)
                {
                    var expandConfig = new ExpandWeaponLogicConfig(tacticWeaponLogicCfg);
                    _configCache[id][weaponParts] = expandConfig;
                    return(expandConfig);
                }
            }
            Logger.ErrorFormat("illegal weapon config for {0}", id);
            return(null);
        }
Exemplo n.º 2
0
        public IWeaponLogic GetWeaponLogic(int?weaponId)
        {
            var realWeaponId = weaponId;

            if (!weaponId.HasValue)
            {
                realWeaponId = WeaponUtil.EmptyHandId;
            }
            if (!realWeaponId.HasValue)
            {
                return(null);
            }
            var weaponDataConfig = _weaponDataConfigManager.GetConfigById(realWeaponId.Value);
            var weaponConfig     = _weaponConfigManager.GetConfigById(realWeaponId.Value);

            if (null == weaponConfig || null == weaponConfig)
            {
                realWeaponId = WeaponUtil.EmptyHandId;
            }
            if (!realWeaponId.HasValue)
            {
                Logger.Error("weaponId is illegal and no hand in config");
                return(null);
            }
            var defaultConfig = weaponDataConfig.WeaponLogic as DefaultWeaponLogicConfig;

            if (null != defaultConfig)
            {
                _defaultWeaponLogic.SetFireLogic(_fireLogicCreator.GetFireLogic(weaponConfig, defaultConfig.FireLogic));
                return(_defaultWeaponLogic);
            }
            var doubleConfig = weaponDataConfig.WeaponLogic as DoubleWeaponLogicConfig;

            if (null != doubleConfig)
            {
                return(new DoubleWeaponLogic(_fireLogicCreator.GetFireLogic(weaponConfig, doubleConfig.LeftFireLogic),
                                             _fireLogicCreator.GetFireLogic(weaponConfig, doubleConfig.RightFireLogic)));
            }
            var tacticConfig = weaponDataConfig.WeaponLogic as TacticWeaponLogicConfig;

            if (null != tacticConfig)
            {
                return(new TacticWeaponLogic(realWeaponId.Value, _freeArgs));
            }
            Logger.ErrorFormat("illegal weaponLogic for id {0}", realWeaponId);
            return(null);
        }