//买东西 public ErrorCodes BuyItem(StoneManager _this, int id, int count) { var tbStore = Table.GetStore(id); if (tbStore == null) { return(ErrorCodes.Error_StoreID); } int NeedType = tbStore.NeedType; int NeedValue = tbStore.NeedValue; //检查职业 var character = _this.mCharacter; var bag = character.mBag; var roleType = character.GetRole(); if (BitFlag.GetLow(tbStore.SeeCharacterID, roleType) == false) { return(ErrorCodes.RoleIdError); } //检查条件 if (tbStore.DisplayCondition != -1) { var retCond = character.CheckCondition(tbStore.DisplayCondition); if (retCond != -2) { return(ErrorCodes.Error_ConditionNoEnough); } } //限购 var vipLevel = character.mBag.GetRes(eResourcesType.VipLevel); var tbVip = Table.GetVIP(vipLevel); var idx = -1; for (int i = 0, imax = tbVip.BuyItemId.Length; i < imax; i++) { if (tbVip.BuyItemId[i] == id) { idx = i; break; } } var vipAddCount = idx < 0 ? 0 : tbVip.BuyItemCount[idx]; if (tbStore.DayCount >= 0) { if (character.GetExData(tbStore.DayCount) + vipAddCount < count) { return(ErrorCodes.Error_StoreBuyCountMax); } } if (tbStore.WeekCount >= 0) { if (character.GetExData(tbStore.WeekCount) + vipAddCount < count) { return(ErrorCodes.Error_StoreBuyCountMax); } } if (tbStore.MonthCount >= 0) { if (character.GetExData(tbStore.MonthCount) + vipAddCount < count) { return(ErrorCodes.Error_StoreBuyCountMax); } } //资源是否足够 var nowCount = bag.GetItemCount(NeedType); var needCount = (long)NeedValue * count; //价格波动处理 if (tbStore.WaveValue >= 0) { //从store表指到skillupgrading中读取次数2价格,然后把价格和购买个数重置 int exIdx = -1; if (tbStore.DayCount >= 0) { exIdx = tbStore.DayCount; } else if (tbStore.WeekCount >= 0) { exIdx = tbStore.WeekCount; } else if (tbStore.MonthCount >= 0) { exIdx = tbStore.MonthCount; } if (exIdx >= 0) { var tbExdata = Table.GetExdata(exIdx); //已经购买的次数 int times = tbExdata.RefreshValue[0] - character.GetExData(exIdx); var tbCost = Table.GetSkillUpgrading(tbStore.WaveValue); if (tbCost == null) { return(ErrorCodes.Error_StoreNotHaveItem); } if (times < 0 || tbCost.Values.Count <= 0) { return(ErrorCodes.Error_StoreBuyCountMax); } if (times >= tbCost.Values.Count) { times = tbCost.Values.Count - 1; } needCount = tbCost.GetSkillUpgradingValue(times); count = 1; } } if (nowCount < needCount) { return(ErrorCodes.Error_ResNoEnough); } //物品是否足够 var nowItemCount = bag.GetItemCount(tbStore.NeedItem); var needItemCount = tbStore.NeedCount * count; if (nowItemCount < needItemCount) { return(ErrorCodes.Error_ResNoEnough); } //组判断 if (tbStore.GroupId != -1) { if (!_this.GroupDatas.ContainsKey(id)) { return(ErrorCodes.Error_StoreNotHaveItem); } } //添加道具 int level = _this.mCharacter.GetLevel(); int tempItemCount = 0; tempItemCount = tbStore.ItemCount * count; if (tbStore.ItemId == (int)eResourcesType.DiamondRes)//祈福根据玩家等级获得不同的经验加成 { if (level > 100) { tempItemCount = tbStore.ItemCount * count + ((level - 100) / 10) * tbStore.BlessGrow; } } var result = bag.CheckAddItem(tbStore.ItemId, tempItemCount); if (result != ErrorCodes.OK) { if (result != ErrorCodes.OK) { return(result); } } bag.AddItem(tbStore.ItemId, tempItemCount, eCreateItemType.StoreBuy); var e = new BuyItemEvent(character, tbStore.ItemId, tempItemCount); EventDispatcher.Instance.DispatchEvent(e); //扣除资源 bag.DeleteItem(NeedType, (int)needCount, eDeleteItemType.StoreBuy); if (NeedType == (int)eResourcesType.Contribution) { _this.mCharacter.AddExData(953, 1); } //记录商店购买日志 // server, account, charname, charid, goodsname, buycount, pricetype, totalprice, logtime try { string v = string.Format("gamegoodslog#{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}", _this.mCharacter.serverId, "account", _this.mCharacter.GetName(), _this.mCharacter.mGuid, ((int)tbStore.ItemId + 1) * 1000, "", tempItemCount, (int)NeedType, needCount, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); // 时间 kafaLogger.Info(v); } catch (Exception) { } //限购次数设置 if (tbStore.DayCount >= 0) { character.AddExData(tbStore.DayCount, -count); } if (tbStore.WeekCount >= 0) { character.AddExData(tbStore.WeekCount, -count); } if (tbStore.MonthCount >= 0) { character.AddExData(tbStore.MonthCount, -count); } if (tbStore.FuBenCount >= 0) { } //设置标记位 if (tbStore.BugSign != -1) { character.SetFlag(tbStore.BugSign, true, 1); } _this.mCharacter.BroadCastGetEquip(tbStore.ItemId, 100002168); return(ErrorCodes.OK); }
//买东西 public ErrorCodes BuyEquipItem(StoneManager _this, int id, int bagId, int bagIndex, ref int isAddEquip) { var tbStore = Table.GetStore(id); if (tbStore == null) { return(ErrorCodes.Error_StoreID); } //检查职业 var roleType = _this.mCharacter.GetRole(); if (BitFlag.GetLow(tbStore.SeeCharacterID, roleType) == false) { return(ErrorCodes.RoleIdError); } //检查条件 if (tbStore.DisplayCondition != -1) { var retCond = _this.mCharacter.CheckCondition(tbStore.DisplayCondition); if (retCond != -2) { return(ErrorCodes.Error_ConditionNoEnough); } } var count = 1; //限购 if (tbStore.DayCount >= 0) { if (_this.mCharacter.GetExData(tbStore.DayCount) < count) { return(ErrorCodes.Error_StoreBuyCountMax); } } if (tbStore.WeekCount >= 0) { if (_this.mCharacter.GetExData(tbStore.WeekCount) < count) { return(ErrorCodes.Error_StoreBuyCountMax); } } if (tbStore.MonthCount >= 0) { if (_this.mCharacter.GetExData(tbStore.MonthCount) < count) { return(ErrorCodes.Error_StoreBuyCountMax); } } //资源是否足够 var nowCount = _this.mCharacter.mBag.GetItemCount(tbStore.NeedType); var needCount = tbStore.NeedValue * count; if (nowCount < needCount) { return(ErrorCodes.Error_ResNoEnough); } //组判断 if (tbStore.GroupId != -1) { if (!_this.GroupDatas.ContainsKey(id)) { return(ErrorCodes.Error_StoreNotHaveItem); } } if (tbStore.NeedItem == -1) { return(ErrorCodes.Unknow); } var item = _this.mCharacter.GetItemByBagByIndex(bagId, bagIndex); if (item == null || item.GetId() == -1 || !(item is ItemEquip2)) { return(ErrorCodes.Error_ResNoEnough); } //物品是否足够 if (item.GetId() != tbStore.NeedItem) { return(ErrorCodes.Error_ResNoEnough); } var oldEquip = Table.GetEquip(item.GetId()); var nextEquip = Table.GetEquip(tbStore.ItemId); if (oldEquip.Part != nextEquip.Part || nextEquip.Occupation != oldEquip.Occupation) { //添加道具 var result = _this.mCharacter.mBag.CheckAddItem(tbStore.ItemId, tbStore.ItemCount * 1); if (result != ErrorCodes.OK) { if (result != ErrorCodes.OK) { return(result); } } _this.mCharacter.mBag.AddItem(tbStore.ItemId, tbStore.ItemCount * 1, eCreateItemType.StoreBuy); _this.mCharacter.GetBag(bagId).ReduceCountByIndex(bagIndex, 1, eDeleteItemType.StoreBuy); _this.mCharacter.EquipChange(0, bagId, bagIndex, item); isAddEquip = 1; } else { isAddEquip = 0; //设置道具 item.SetId(tbStore.ItemId); item.MarkDbDirty(); //通知属性变化 _this.mCharacter.EquipChange(2, bagId, bagIndex, item); } //扣除资源 _this.mCharacter.mBag.DeleteItem(tbStore.NeedType, needCount, eDeleteItemType.StoreBuy); try { //记录商店购买日志 // server, account, charname, charid, goodsname, buycount, pricetype, totalprice, logtime string v = string.Format("gamegoodslog#{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}", _this.mCharacter.serverId, "account", _this.mCharacter.GetName(), _this.mCharacter.mGuid, ((int)tbStore.ItemId + 1) * 1000, "", tbStore.ItemCount * count, (int)tbStore.NeedType, needCount, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); // 时间 kafaLogger.Info(v); } catch (Exception) { } var e = new BuyItemEvent(_this.mCharacter, tbStore.ItemId, count); EventDispatcher.Instance.DispatchEvent(e); //限购次数设置 if (tbStore.DayCount >= 0) { _this.mCharacter.AddExData(tbStore.DayCount, -count); } if (tbStore.WeekCount >= 0) { _this.mCharacter.AddExData(tbStore.WeekCount, -count); } if (tbStore.MonthCount >= 0) { _this.mCharacter.AddExData(tbStore.MonthCount, -count); } //设置标记位 if (tbStore.BugSign != -1) { _this.mCharacter.SetFlag(tbStore.BugSign, true, 1); } return(ErrorCodes.OK); }