public override bool TakeAction() { ItemBaseInfo itemInfo = new ConfigCacheSet <ItemBaseInfo>().FindKey(_itemId); //UserItemHelper.AddUserItem(ContextUser.UserID, 1702, 1); //UserItemHelper.AddUserItem(ContextUser.UserID, 1701, 1); //UserItemHelper.AddUserItem(ContextUser.UserID, 1213, 1); if (itemInfo == null) { return(false); } //判断背包是否已满 string fullTitle = string.Empty; bool isFull = false; if (itemInfo.ItemType == ItemType.ZhuangBei) { isFull = UserPackHelper.PackIsFull(ContextUser, BackpackType.ZhuangBei, _num, out fullTitle); } else { isFull = UserPackHelper.PackIsFull(ContextUser, BackpackType.BeiBao, _num, out fullTitle); } if (isFull) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = fullTitle; //ErrorInfo = LanguageManager.GetLang().St7004_BeiBaoTimeOut; return(false); } //读取物品信息 MallItemsInfo mallItemInfo = new ConfigCacheSet <MallItemsInfo>().FindKey(_itemId, CityId, _commandType); if (mallItemInfo == null) { return(false); } //物品价格 int mallPrice = mallItemInfo.Price; if (mallItemInfo.MallType == ShopType.Props || mallItemInfo.MallType == ShopType.PresendBox) { mallPrice = (FestivalHelper.StoreDiscount() * mallPrice).ToInt(); } else if (mallItemInfo.SpecialPrice > 0) { mallPrice = mallItemInfo.SpecialPrice; } //根据物品类型进行扣钱 if (_commandType == ShopType.Props || _commandType == ShopType.PresendBox) { int useGold = mallPrice * _num; //if (mallItemInfo.MallType == ShopType.PresendBox) //{ if (ContextUser.GoldNum < useGold) { ErrorCode = 3; ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough; return(false); } ContextUser.UseGold = MathUtils.Addition(ContextUser.UseGold, useGold); //增加道具日志统计 var mallItemLog = new MallItemLog { Amount = useGold, CreateDate = DateTime.Now, ItemID = _itemId, ItemName = itemInfo.ItemName, ItemNum = _num, MobileType = ContextUser.MobileType, Pid = ContextUser.Pid, PropType = itemInfo.PropType, RetailID = ContextUser.RetailID, Uid = ContextUser.UserID.ToInt() }; var sender = DataSyncManager.GetDataSender(); sender.Send(mallItemLog); UserItemHelper.AddUserItem(ContextUser.UserID, _itemId, _num); UserLogHelper.AppenUseGoldLog(ContextUser.UserID, 8, 1, 1, useGold, ContextUser.GoldNum, MathUtils.Addition(ContextUser.GoldNum, useGold, int.MaxValue)); //} //预留判断消耗的是金币还是晶石 //else //{ // if (ContextUser.GameCoin <useGold) // { // ErrorCode = LanguageManager.GetLang().ErrorCode; // ErrorInfo = LanguageManager.GetLang().St_GameCoinNotEnough; // return false; // } // ContextUser.GameCoin = MathUtils.Subtraction(ContextUser.GameCoin, useGold); // UserItemHelper.AddUserItem(ContextUser.UserID, _itemId, _num); //} } return(true); }
public override bool TakeAction() { UserGeneral userGeneral = new PersonalCacheStruct <UserGeneral>().FindKey(ContextUser.UserID, generalID); if (userGeneral == null) { ErrorCode = LanguageManager.GetLang().ErrorCode; return(false); } if (ops == 0) { //用户装备更换 var package = UserItemPackage.Get(Uid); if (package == null) { ErrorCode = LanguageManager.GetLang().ErrorCode; return(false); } UserItemInfo userItem = package.ItemPackage.Find(m => !m.IsRemove && m.UserItemID.Equals(userItemID)); if (userItem == null) { ErrorCode = LanguageManager.GetLang().ErrorCode; return(false); } ItemBaseInfo itemInfo = new ShareCacheStruct <ItemBaseInfo>().FindKey(userItem.ItemID); if (itemInfo != null) { if (string.IsNullOrEmpty(itemInfo.CareerRange) || itemInfo.CareerRange.IndexOf(userGeneral.CareerID.ToString()) == -1) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St1203_CareerError; return(false); } //佣兵装备部位为空才能更换 var generalItem = package.ItemPackage.Find(s => !s.IsRemove && s.Equparts == itemInfo.EquParts && s.GeneralID == userGeneral.GeneralID && s.ItemStatus == ItemStatus.YongBing); if (generalItem != null) { generalItem.GeneralID = 0; generalItem.ItemStatus = ItemStatus.BeiBao; package.SaveItem(generalItem); userItem.GeneralID = generalID; userItem.ItemStatus = ItemStatus.YongBing; package.SaveItem(userItem); } else { userItem.GeneralID = generalID; userItem.ItemStatus = ItemStatus.YongBing; package.SaveItem(userItem); } //int equCount = UserItemHelper.GetItems(Uid).FindAll( // m => new UserItemHelper(m).EquPartsID == (int)itemInfo.EquParts && m.GeneralID == userGeneral.GeneralID && m.ItemStatus == ItemStatus.YongBing).Count; //if (equCount == 0) //{ // userItem.GeneralID = generalID; // userItem.ItemStatus = ItemStatus.YongBing; // package.SaveItem(userItem); //} } } else if (ops == 1) { //卸下 //if (UserItemHelper.CheckItemOut(ContextUser, ItemStatus.BeiBao)) //{ // ErrorCode = LanguageManager.GetLang().ErrorCode; // ErrorInfo = LanguageManager.GetLang().St1606_GridNumNotEnough; // return false; //} string str = string.Empty; if (UserPackHelper.PackIsFull(ContextUser, BackpackType.ZhuangBei, 1, out str)) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St1606_GridNumNotEnough; ErrorInfo = str; return(false); } var package = UserItemPackage.Get(Uid); UserItemInfo userItem = package.ItemPackage.Find(m => !m.IsRemove && m.UserItemID.Equals(userItemID)); if (userItem != null && userItem.GeneralID > 0 && userItem.ItemStatus == ItemStatus.YongBing) { userItem.GeneralID = 0; userItem.ItemStatus = ItemStatus.BeiBao; package.SaveItem(userItem); } } userGeneral.RefreshMaxLife(); return(true); }
public override bool TakeAction() { DialHelper.CheckDialNum(ContextUser.UserID); UserDial userDial = new PersonalCacheStruct <UserDial>().FindKey(ContextUser.UserID); if (userDial == null || string.IsNullOrEmpty(userDial.UserItemID)) { ErrorCode = LanguageManager.GetLang().ErrorCode; return(false); } if (ops == 1) { string errContent = string.Empty; if (UserPackHelper.PackIsFull(ContextUser, BackpackType.BeiBao, 0, out errContent)) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = errContent; return(false); } int itemid = UserItemHelper.GetUserItemInfoID(ContextUser.UserID, userDial.UserItemID); var itemInfo = new ShareCacheStruct <ItemBaseInfo>().FindKey(itemid); if (itemInfo == null) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St1107_UserItemNotEnough; return(false); } // 根据宝箱取得该宝箱对应的钥匙ID int itemNum = UserItemHelper.CheckItemNum(ContextUser.UserID, itemInfo.EffectNum); if (itemNum <= 0) { ItemBaseInfo itemKey = new ShareCacheStruct <ItemBaseInfo>().FindKey(itemInfo.EffectNum); if (itemKey == null) { ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = LanguageManager.GetLang().St1107_UserItemNotEnough; return(false); } ErrorCode = LanguageManager.GetLang().ErrorCode; ErrorInfo = string.Format(LanguageManager.GetLang().St12004_ChestKeyNotEnough, itemKey.ItemName); return(false); } UserItemHelper.UseUserItem(ContextUser.UserID, itemid, 1); UserItemHelper.UseUserItem(ContextUser.UserID, itemInfo.EffectNum, 1); postion = DialHelper.ChestDialPrizePostion(ContextUser); postion = MathUtils.Addition(postion, (short)1); // 是否还可以继续使用 //var package = UserItemPackage.Get(ContextUser.UserID); bool hasBox = UserItemHelper.IsEnoughBeiBaoItem(ContextUser.UserID, itemid, 1); bool hasKey = UserItemHelper.IsEnoughBeiBaoItem(ContextUser.UserID, itemInfo.EffectNum, 1); // 如果钥匙和宝箱的数各 >= 1 if (hasBox && hasKey) { hasNextBox = 1; } } //int useGold = 0; //if (ops == 1) //{ // //if (!DialHelper.IsDialFree(ContextUser.UserID)) // //{ // // ErrorCode = LanguageManager.GetLang().ErrorCode; // // ErrorInfo = LanguageManager.GetLang().St12004_FreeNotEnough; // // return false; // //} //} //else if (ops == 2) //{ // useGold = GameConfigSet.SweepstakesRequiredGold; // ErrorCode = ops; // ErrorInfo = string.Format(LanguageManager.GetLang().St12004_SpendSparDraw, useGold, 1); // return false; //} //else if (ops == 3) //{ // if (DialHelper.IsDialFree(ContextUser.UserID)) // { // ErrorCode = LanguageManager.GetLang().ErrorCode; // ErrorInfo = LanguageManager.GetLang().St12004_FreeNumEnough; // return false; // } // useGold = GameConfigSet.SweepstakesRequiredGold; // if (ContextUser.GoldNum < useGold) // { // ErrorCode = LanguageManager.GetLang().ErrorCode; // ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough; // return false; // } // ContextUser.UseGold = MathUtils.Addition(ContextUser.UseGold, useGold); //} //else if (ops == 4) //{ // useGold = GameConfigSet.FiveRequiredGold; // ErrorCode = ops; // ErrorInfo = string.Format(LanguageManager.GetLang().St12004_SpendSparDraw, useGold, 5); // return false; //} //else if (ops == 5) //{ // if (DialHelper.IsDialFree(ContextUser.UserID)) // { // ErrorCode = LanguageManager.GetLang().ErrorCode; // ErrorInfo = LanguageManager.GetLang().St12004_FreeNumEnough; // return false; // } // useGold = GameConfigSet.FiveRequiredGold; // if (ContextUser.GoldNum < useGold) // { // ErrorCode = LanguageManager.GetLang().ErrorCode; // ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough; // return false; // } // ContextUser.UseGold = MathUtils.Addition(ContextUser.UseGold, useGold); //} //ErrorCode = ops; //postion = DialHelper.DialPrizePostion(ContextUser.UserID, ops); //postion = MathUtils.Addition(postion, (short)1); return(true); }