Dictionary <string, bool> mGoodsSettingInfoConditionsCache = null; // 条件缓存 bool CheckMeetGoodsSettingInfoCondition(uint goodsId, HookGoodsSettingInfo hookGoodsSettingInfo, Dictionary <uint, HookGoodsSettingInfo> hookGoodsSettingInfos, string cacheKeyPrefix) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(cacheKeyPrefix); sb.Append("_"); sb.Append(goodsId); sb.Append("_"); sb.Append(hookGoodsSettingInfo.Id); string cacheKey = sb.ToString(); if (mGoodsSettingInfoConditionsCache == null) { mGoodsSettingInfoConditionsCache = new Dictionary <string, bool>(); mGoodsSettingInfoConditionsCache.Clear(); } if (mGoodsSettingInfoConditionsCache.ContainsKey(cacheKey) == true) { return(mGoodsSettingInfoConditionsCache[cacheKey]); } bool ret = false; switch (hookGoodsSettingInfo.Type) { case HookGoodsSettingInfo.EType.OtherAll: { Dictionary <uint, HookGoodsSettingInfo> otherAllHookGoodsSettingInfos = new Dictionary <uint, HookGoodsSettingInfo>(); otherAllHookGoodsSettingInfos.Clear(); foreach (HookGoodsSettingInfo otherHookGoodsSettingInfo in hookGoodsSettingInfos.Values) { if (otherHookGoodsSettingInfo.Type != HookGoodsSettingInfo.EType.OtherAll) { otherAllHookGoodsSettingInfos.Add(otherHookGoodsSettingInfo.Id, otherHookGoodsSettingInfo); } } ret = true; foreach (HookGoodsSettingInfo otherHookGoodsSettingInfo in otherAllHookGoodsSettingInfos.Values) { if (CheckMeetGoodsSettingInfoCondition(goodsId, otherHookGoodsSettingInfo, otherAllHookGoodsSettingInfos, "other_all_hook_goods_setting") == true) { ret = false; break; } } break; } case HookGoodsSettingInfo.EType.GoodsIds: { if (hookGoodsSettingInfo.Params.Contains(goodsId) == true) { ret = true; break; } break; } case HookGoodsSettingInfo.EType.GoodsType: { uint goodsType = GoodsHelper.GetGoodsType(goodsId); uint goodsSubType = GoodsHelper.GetGoodsSubType(goodsId); if (hookGoodsSettingInfo.Params.Count >= 2) { if (goodsType == hookGoodsSettingInfo.Params[0] && goodsSubType == hookGoodsSettingInfo.Params[1]) { ret = true; break; } } break; } case HookGoodsSettingInfo.EType.EquipCertainColor: { uint goodsType = GoodsHelper.GetGoodsType(goodsId); if (goodsType == GameConst.GIVE_TYPE_EQUIP) { uint color = GoodsHelper.GetGoodsColorTypeByTypeId(goodsId); if (color == hookGoodsSettingInfo.Params[0]) { ret = true; break; } } break; } case HookGoodsSettingInfo.EType.EquipUponCertainColor: { uint goodsType = GoodsHelper.GetGoodsType(goodsId); if (goodsType == GameConst.GIVE_TYPE_EQUIP) { uint color = GoodsHelper.GetGoodsColorTypeByTypeId(goodsId); if (color >= hookGoodsSettingInfo.Params[0]) { ret = true; break; } } break; } case HookGoodsSettingInfo.EType.EquipPoses: { uint pos = xc.Equip.EquipHelper.GetEquipPosByGid(goodsId); foreach (uint param in hookGoodsSettingInfo.Params) { if (pos == param) { ret = true; break; } } break; } default: break; } mGoodsSettingInfoConditionsCache.Add(cacheKey, ret); return(ret); }
void OnPlayerSettingsChanged(CEventBaseArgs data) { bool isSettingHookChanged = false; foreach (PkgPlayerPersonality settingInfo in GlobalSettings.Instance.PlayerSettings) { switch (settingInfo.type) { case GameConst.SETTING_KEY_HOOK_USE_HP_DRUG_HP_RATIO: { mUseHPDrugHPRatio = (float)(settingInfo.value) / 100f; isSettingHookChanged = true; break; } case GameConst.SETTING_KEY_HOOK_USE_MP_DRUG_MP_RATIO: { mUseMPDrugMPRatio = (float)(settingInfo.value) / 100f; isSettingHookChanged = true; break; } case GameConst.SETTING_KEY_HOOK_RANGE_TYPE: { mRangeType = (EHookRangeType)settingInfo.value; isSettingHookChanged = true; break; } case GameConst.SETTING_KEY_HOOK_AUTO_BUY_DRUG: { mAutoBuyDrug = settingInfo.value == 0 ? false : true; isSettingHookChanged = true; break; } case GameConst.SETTING_KEY_HOOK_AUTO_SWALLOW: { mAutoSwallow = settingInfo.value == 0 ? false : true; isSettingHookChanged = true; break; } case GameConst.SETTING_KEY_HOOK_AUTO_REVIVE: { mAutoRevive = settingInfo.value == 0 ? false : true; isSettingHookChanged = true; break; } case GameConst.SETTING_KEY_HOOK_AUTO_SELL_GOODS: { mAutoSellGoods = settingInfo.value == 0 ? false : true; isSettingHookChanged = true; break; } case GameConst.SETTING_KEY_HOOK_AUTO_PICK_DROP_PREFIX: { mAutoPickDrop = settingInfo.value == 0 ? false : true; isSettingHookChanged = true; break; } default: break; } HookGoodsSettingInfo hookGoodsSettingInfo = null; int hookGoodsSettingInfoId = (int)(settingInfo.type) - (int)(GameConst.SETTING_KEY_HOOK_AUTO_PICK_DROP_PREFIX); if (hookGoodsSettingInfoId > 0) { if (mAutoPickDropInfos.TryGetValue((uint)(hookGoodsSettingInfoId), out hookGoodsSettingInfo) == true && hookGoodsSettingInfo != null) { SetAutoPickDrop((uint)(hookGoodsSettingInfoId), settingInfo.value == 0 ? false : true); isSettingHookChanged = true; } } } if (isSettingHookChanged == true) { ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_SETTING_HOOK_CHANGED, null); } }
Dictionary <uint, HookGoodsSettingInfo> ReadHookSettingGoodsInfos(string tableName, HookGoodsSettingInfo.ECondition condition) { Dictionary <uint, HookGoodsSettingInfo> hookSettingGoodsInfos = new Dictionary <uint, HookGoodsSettingInfo>(); hookSettingGoodsInfos.Clear(); List <Dictionary <string, string> > datas = DBManager.Instance.QuerySqliteTable <string>(GlobalConfig.DBFile, tableName); foreach (Dictionary <string, string> row in datas) { HookGoodsSettingInfo hookSettingGoodsInfo = new HookGoodsSettingInfo(); foreach (KeyValuePair <string, string> kv in row) { if (kv.Key == "id") { hookSettingGoodsInfo.Id = DBTextResource.ParseUI_s(kv.Value, 0); } else if (kv.Key == "condition") { hookSettingGoodsInfo.Condition = (HookGoodsSettingInfo.ECondition)DBTextResource.ParseUI_s(kv.Value, 0); } else if (kv.Key == "type") { hookSettingGoodsInfo.Type = (HookGoodsSettingInfo.EType)DBTextResource.ParseUI_s(kv.Value, 0); } else if (kv.Key == "param") { switch (hookSettingGoodsInfo.Type) { case HookGoodsSettingInfo.EType.OtherAll: { break; } case HookGoodsSettingInfo.EType.GoodsIds: { hookSettingGoodsInfo.Params = DBTextResource.ParseArrayUint(kv.Value, ","); break; } case HookGoodsSettingInfo.EType.GoodsType: { hookSettingGoodsInfo.Params = DBTextResource.ParseArrayUint(kv.Value, ","); break; } case HookGoodsSettingInfo.EType.EquipCertainColor: { hookSettingGoodsInfo.Params = new List <uint>(); hookSettingGoodsInfo.Params.Clear(); hookSettingGoodsInfo.Params.Add(DBTextResource.ParseUI_s(kv.Value, 0)); break; } case HookGoodsSettingInfo.EType.EquipUponCertainColor: { hookSettingGoodsInfo.Params = new List <uint>(); hookSettingGoodsInfo.Params.Clear(); hookSettingGoodsInfo.Params.Add(DBTextResource.ParseUI_s(kv.Value, 0)); break; } case HookGoodsSettingInfo.EType.EquipPoses: { hookSettingGoodsInfo.Params = DBTextResource.ParseArrayUint(kv.Value, ","); break; } default: break; } } else if (kv.Key == "name") { hookSettingGoodsInfo.Name = kv.Value; } } hookSettingGoodsInfo.IsOn = true; if (condition == hookSettingGoodsInfo.Condition) { hookSettingGoodsInfos.Add(hookSettingGoodsInfo.Id, hookSettingGoodsInfo); } } return(hookSettingGoodsInfos); }