/// <summary> /// 双倍材料,月饼道具使用 /// </summary> /// <param name="userItem"></param> /// <param name="itemInfo"></param> /// <returns></returns> private bool DoCaiLiaoYueBingItem(UserItemInfo userItem, ItemBaseInfo itemInfo) { UserProps props = new GameDataCacheSet<UserProps>().FindKey(ContextUser.UserID, userItem.ItemID); if (props != null) { if (userItem.ItemID == 5200 && props.DoRefresh() > 0) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St1608_CombatPowerNotEnough; return false; } props.SurplusNum += itemInfo.EffectNum; props.ChangeTime = DateTime.Now; //props.Update(); } else { UserProps uProps = new UserProps(ContextUser.UserID, itemInfo.ItemID) { SurplusNum = itemInfo.EffectNum, ChangeTime = DateTime.Now }; new GameDataCacheSet<UserProps>().Add(uProps, GameEnvironment.CacheUserPeriod); } return true; }
private static bool UseProps(string userID, ItemBaseInfo itemInfo) { var cacheSet = new GameDataCacheSet<UserProps>(); List<UserProps> propsArray = cacheSet.FindAll(userID, u => u.PropType == itemInfo.PropType); if (itemInfo.PropType == 9 && propsArray.Count > 0) { int refreshNum = propsArray[0].DoRefresh(); if (refreshNum > 0) { return false; } } bool isUsed = false; foreach (UserProps propse in propsArray) { if (propse.ItemID == 7003 || propse.ItemID == 5200) { continue; } if (!isUsed && propse.ItemID == itemInfo.ItemID) { isUsed = true; propse.SurplusNum += itemInfo.EffectNum; propse.ChangeTime = DateTime.Now; //propse.Update(); } else { cacheSet.Delete(propse); } } //List<UserProps> propsArray1 = new GameDataCacheSet<UserProps>().FindAll(UserProps.Index_UserID, u => u.PropType == itemInfo.PropType && u.ItemID == itemInfo.ItemID, userID); if (!isUsed) { UserProps uProps = new UserProps(userID, itemInfo.ItemID) { SurplusNum = itemInfo.EffectNum, ChangeTime = DateTime.Now }; new GameDataCacheSet<UserProps>().Add(uProps, GameEnvironment.CacheUserPeriod); } return true; }
public override bool TakeAction() { int subLifeNum = 0; var package = UserItemPackage.Get(Uid); UserItemInfo userItem = package.ItemPackage.Find(m => !m.IsRemove && m.UserItemID.Equals(userItemID)); if (userItem == null) { ErrorCode = LanguageManager.GetLang().ErrorCode; return false; } //wuzf modify 2012-05-19 ItemBaseInfo itemInfo = new ConfigCacheSet<ItemBaseInfo>().FindKey(userItem.ItemID); var propsArray = new GameDataCacheSet<UserProps>().FindAll(ContextUser.UserID, u => u.PropType == 1); if (propsArray.Count > 0 && propsArray[0].SurplusNum > 0) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St1605_BandageUse; return false; } //判断背包是否有血包,没有提示去商城 var userItems = package.ItemPackage.FindAll(m => !m.IsRemove && new UserItemHelper(m).PropType == 1); if (userItems.Count == 0) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St1605_UseTwoGold; return false; } //给佣兵补血 var userGeneralArray = new GameDataCacheSet<UserGeneral>().FindAll(ContextUser.UserID, u => u.GeneralStatus == GeneralStatus.DuiWuZhong); int effectNum = itemInfo.EffectNum; foreach (var userGeneral in userGeneralArray) { int maxLifeNum = UserHelper.GetMaxLife(ContextUser.UserID, userGeneral.GeneralID); if (userGeneral.LifeNum < maxLifeNum) { subLifeNum = MathUtils.Subtraction(maxLifeNum, userGeneral.LifeNum, 0); userGeneral.LifeNum = MathUtils.Addition(userGeneral.LifeNum, effectNum, maxLifeNum); //userGeneral.Update(); effectNum = MathUtils.Subtraction(effectNum, subLifeNum, 0); } } var cacheSet = new GameDataCacheSet<UserProps>(); UserProps props = new GameDataCacheSet<UserProps>().FindKey(ContextUser.UserID, userItem.ItemID); if (props != null) { props.SurplusNum = effectNum; //props.Update(); } else { props = new UserProps(ContextUser.UserID, itemInfo.ItemID) { SurplusNum = effectNum }; cacheSet.Add(props, GameEnvironment.CacheUserPeriod); } ContextUser.IsUseupItem = false; UserItemHelper.UseUserItem(ContextUser.UserID, itemInfo.ItemID, 1); foreach (UserProps userPropse in propsArray) { if (userPropse.SurplusNum == 0) { cacheSet.Delete(userPropse); } } return true; }
/// <summary> /// 佣兵自动使用绷带补血 /// </summary> public static void UserGeneralPromptBlood(GameUser user) { int subLifeNum = 0; if (IsPromptBlood(user.UserID)) { var userItemArray = UserItemHelper.GetItems(user.UserID).FindAll(u => u.ItemType == ItemType.BengDai && u.ItemStatus != ItemStatus.Sell); if (userItemArray.Count > 0) { int itemID = userItemArray[0].ItemID; ItemBaseInfo itemInfo = new ConfigCacheSet<ItemBaseInfo>().FindKey(itemID); var propsCacheSet = new GameDataCacheSet<UserProps>(); List<UserProps> propsArray = propsCacheSet.FindAll(user.UserID, u => u.PropType == 1); if (propsArray.Count > 0 && propsArray[0].SurplusNum == 0) { foreach (UserProps userPropse in propsArray) { if (userPropse.SurplusNum == 0) { propsCacheSet.Delete(userPropse); } } } //给佣兵补血 List<UserGeneral> userGeneralArray = new GameDataCacheSet<UserGeneral>().FindAll(user.UserID, u => u.GeneralStatus == GeneralStatus.DuiWuZhong); int effectNum = itemInfo.EffectNum; foreach (var userGeneral in userGeneralArray) { int maxLifeNum = GetMaxLife(user.UserID, userGeneral.GeneralID); if (userGeneral.LifeNum < maxLifeNum) { subLifeNum = MathUtils.Subtraction(maxLifeNum, userGeneral.LifeNum, 0); userGeneral.LifeNum = MathUtils.Addition(userGeneral.LifeNum, effectNum, maxLifeNum); //userGeneral.Update(); effectNum = MathUtils.Subtraction(effectNum, subLifeNum, 0); } } UserProps props = new UserProps(user.UserID, itemInfo.ItemID) { SurplusNum = effectNum }; propsCacheSet.Add(props, GameEnvironment.CacheUserPeriod); user.IsUseupItem = false; UserItemHelper.UseUserItem(user.UserID, itemInfo.ItemID, 1); } } }
/// <summary> /// 中元节变身活动功能 /// </summary> /// <param name="userid"></param> /// <param name="chatContent"></param> public static void WingZhongYuanFestival(GameUser user, string chatContent) { int festivalID = 0;// 1019; FestivalInfo festival = new ShareCacheStruct<FestivalInfo>().FindKey(festivalID); if (festival != null && festival.FestivalExtend != null) { if (chatContent.IndexOf(festival.FestivalExtend.KeyWord) != -1) { FestivalRestrain restrain = new PersonalCacheStruct<FestivalRestrain>().FindKey(user.UserID); if (restrain == null) { List<PrizeInfo> prizeInfosArray = festival.Reward.ToList(); double[] probability = new double[prizeInfosArray.Count]; for (int i = 0; i < prizeInfosArray.Count; i++) { probability[i] = (double)prizeInfosArray[i].Probability; } int index2 = RandomUtils.GetHitIndex(probability); PrizeInfo prizeInfo = prizeInfosArray[index2]; if (prizeInfo != null) { var cacheSet = new PersonalCacheStruct<UserProps>(); UserProps props = cacheSet.FindKey(user.UserID, prizeInfo.ItemID); if (props != null && !IsFestivalOpen(festivalID)) { cacheSet.Delete(props); } else if (props == null && IsFestivalOpen(festivalID)) { props = new UserProps(user.UserID, prizeInfo.ItemID) { ChangeTime = festival.StartDate, SurplusNum = 0 }; cacheSet.Add(props); restrain = new FestivalRestrain() { UserID = user.UserID, FestivalID = festivalID, RefreashDate = DateTime.Now, RestrainNum = 1 }; new PersonalCacheStruct<FestivalRestrain>().Add(restrain); } } } } } }