867 lines
40 KiB
C#
867 lines
40 KiB
C#
|
||
using Cal;
|
||
using Cal.DataTable;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
|
||
namespace ET
|
||
{
|
||
|
||
public class ItemComponentAwakeSystem : AwakeSystem<ItemComponent>
|
||
{
|
||
public override void Awake(ItemComponent self)
|
||
{
|
||
ItemComponent.Instance = self;
|
||
}
|
||
}
|
||
|
||
public static class ItemComponentSystem
|
||
{
|
||
public static bool CanAddItem(this ItemComponent self, Unit unit, int itemId, int count)
|
||
{
|
||
IConfig itemBase = BagHelper.GetItemBase(itemId);
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
switch (itemBase)
|
||
{
|
||
case EquipBase equipBase:
|
||
return bag.CanAddNewItem();
|
||
case GoodsBase goodsBase:
|
||
case MaterialBase materialBase:
|
||
return bag.CanAddItem(itemId, count);
|
||
}
|
||
return false;
|
||
}
|
||
public static int GetAddItemNeedSlot(this ItemComponent self, Unit unit, int itemId, int count)
|
||
{
|
||
IConfig itemBase = BagHelper.GetItemBase(itemId);
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
switch (itemBase)
|
||
{
|
||
case EquipBase:
|
||
return count;
|
||
case GoodsBase goodsBase:
|
||
return bag.AddItemNeedSlot(itemId, count, goodsBase.MaxAmount);
|
||
case MaterialBase materialBase:
|
||
return bag.AddItemNeedSlot(itemId, count, materialBase.MaxAmount);
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
public static bool CanAddItem(this ItemComponent self, Unit unit, List<(int, long)> list)
|
||
{
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
int needSlot = 0;
|
||
foreach ((int id, long count) in list)
|
||
{
|
||
if (!IsSpecialItem(id))
|
||
needSlot += GetAddItemNeedSlot(self, unit, id, (int)count);
|
||
}
|
||
return needSlot <= (bag.MaxItemCount - bag.ItemCount);
|
||
}
|
||
public static bool IsSpecialItem(int id)
|
||
{
|
||
return id == BagHelper.ExpId ||
|
||
id == BagHelper.YuanBaoId ||
|
||
id == BagHelper.VoucherId ||
|
||
id == BagHelper.GemId ||
|
||
id == BagHelper.CoinId;
|
||
}
|
||
public static string AddItem(this ItemComponent self, Unit unit, int itemId,out Item item, int count = 1,bool isLock = true, Item oldItem = null, float randomMax = 0.2f, string getSource = "未知")
|
||
{
|
||
item = null;
|
||
if (!CanAddItem(self, unit, itemId, count))
|
||
{
|
||
return ConstDefine.BagFullError;
|
||
}
|
||
if (itemId == 0)
|
||
{
|
||
Log.Error($"itemId == 0");
|
||
return "系统错误";
|
||
}
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
item = BagHelper.GenerateItem(unit, itemId, count, isLock, oldItem, randomMax, getSource);
|
||
|
||
bag.AddItem(item);
|
||
return null;
|
||
}
|
||
public static string AddItem(this ItemComponent self, Unit unit, int itemId, int count = 1, bool isLock = true, Item oldItem = null, float randomMax = 0.2f, string getSource = "未知")
|
||
{
|
||
if (!CanAddItem(self, unit, itemId, count))
|
||
{
|
||
return ConstDefine.BagFullError;
|
||
}
|
||
if (itemId == 0)
|
||
{
|
||
Log.Error($"itemId == 0");
|
||
return "系统错误";
|
||
}
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
Item item = BagHelper.GenerateItem(unit, itemId, count, isLock, oldItem, randomMax, getSource);
|
||
|
||
bag.AddItem(item);
|
||
return null;
|
||
}
|
||
public static string DeleteItem(this ItemComponent self, Unit unit, int index, int count)
|
||
{
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
Item item = bag.DeleteItem(index, count);
|
||
if (item == null) return "删除数量超过此物品数量";
|
||
return string.Empty;
|
||
}
|
||
public static async ETTask<(string, int)> UseGoods(this ItemComponent self, Unit unit, int index = -1, int itemId = -1)
|
||
{await ETTask.CompletedTask;
|
||
ModifierContainerComponent modifierContainerComponent = unit.GetComponent<ModifierContainerComponent>();
|
||
if (modifierContainerComponent.HasState(ModifierStateType.禁用物品状态))
|
||
{
|
||
return ("禁用物品状态", 0);
|
||
}
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
//!背包中使用
|
||
if (index != -1)
|
||
{
|
||
if (unit.teamState == TeamState.Fight)
|
||
{
|
||
return ("战斗中...", 0);
|
||
}
|
||
if (!bag.ItemDic.TryGetValueByKey1(index, out Item item))
|
||
{
|
||
return ("Bag系统错误,未找到相应背包位置的物品", 0);
|
||
}
|
||
if (item.ItemType != ItemType.GoodsItem)
|
||
{
|
||
return ("只能使用道具!", 0);
|
||
}
|
||
if (item.Count <= 0)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】 Id= {item.ItemId}的道具数量为0!");
|
||
return ("系统错误", 0);
|
||
}
|
||
string ret = BagHelper.CanUseGoods(unit, item);
|
||
if (ret != null)
|
||
{
|
||
return (ret, 0);
|
||
}
|
||
//!消耗物品
|
||
string delRet = self.DeleteItem(unit, index, 1);
|
||
if (!delRet.Equals(string.Empty))
|
||
return (delRet, 0);
|
||
//!使用逻辑
|
||
ret= BagHelper.UseGoodsEffect(unit, item);
|
||
if (ret != string.Empty)
|
||
{
|
||
self.AddItem(unit, item.ItemId, 1, item.IsLock);
|
||
return (ret, 0);
|
||
}
|
||
UnitHelper.Save<PlayerData>(unit).Coroutine();
|
||
return (null, item.ItemId);
|
||
}
|
||
//!快捷栏使用
|
||
{
|
||
string canUse = bag.CheckCanUse();
|
||
if (canUse != null)
|
||
{
|
||
return (canUse, 0);
|
||
}
|
||
if (!bag.ItemDic.TryGetValueByKey2(itemId, out List<Item> list))
|
||
{
|
||
return ("Bag系统错误,未找到相应背包位置的物品", 0);
|
||
}
|
||
Item item = list[0];
|
||
if (item.ItemType != ItemType.GoodsItem)
|
||
{
|
||
return ("只能使用道具!", 0);
|
||
}
|
||
if (item.Count <= 0)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】 Id= {itemId}的道具数量为0!");
|
||
return ("系统错误", 0);
|
||
}
|
||
string ret = BagHelper.CanUseGoods(unit, item);
|
||
if (ret != null)
|
||
{
|
||
return (ret, 0);
|
||
}
|
||
string delRet = self.DeleteItem(unit, item.index, 1);
|
||
if (!delRet.Equals(string.Empty))
|
||
return (delRet, 0);
|
||
//!使用逻辑
|
||
ret= BagHelper.UseGoodsEffect(unit, item);
|
||
if (ret != string.Empty)
|
||
{
|
||
self.AddItem(unit, item.ItemId, 1, item.IsLock);
|
||
return (ret, 0);
|
||
}
|
||
UnitHelper.Save<PlayerData>(unit).Coroutine();
|
||
}
|
||
return (null, 0);
|
||
}
|
||
|
||
private static readonly float[] MeltingAddPrice = { 1.0f, 1.5f, 2.2f, 3.0f };
|
||
/// <summary>
|
||
/// 镶嵌
|
||
/// </summary>
|
||
/// <param name="self"></param>
|
||
/// <param name="unit"></param>
|
||
/// <param name="equipIndex"></param>
|
||
/// <param name="gemIndex"></param>
|
||
/// <param name="attributeIndex"></param>
|
||
/// <returns></returns>
|
||
public static async ETTask<string> MeltEquip(this ItemComponent self, Unit unit, int equipIndex, int gemIndex, int attributeIndex)
|
||
{
|
||
await ETTask.CompletedTask;
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
if (!bag.ItemDic.TryGetValueByKey1(equipIndex, out Item equip))
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】背包中没有装备Index ={equipIndex}");
|
||
return "系统错误";
|
||
}
|
||
if (!bag.ItemDic.TryGetValueByKey1(gemIndex, out Item gem))
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】 背包中没有宝石Index ={gemIndex}");
|
||
return "系统错误";
|
||
}
|
||
if (equip.IsEmpty) return "您的背包中没有此装备,请重新放置";
|
||
if (gem.IsEmpty) return "您的背包中没有此宝石,请重新放置";
|
||
if (equip.ItemType != ItemType.EquipItem)
|
||
{
|
||
return "只能对装备进行炼化";
|
||
}
|
||
if (gem.ItemType != ItemType.MaterialsItem)
|
||
{
|
||
|
||
return "只能添加宝石";
|
||
}
|
||
MaterialBase materialBase = DataTableHelper.Get<MaterialBase>(gem.ItemId);
|
||
if (materialBase.MaterialType != (int)MaterialsType.宝石)
|
||
{
|
||
return "只能添加宝石";
|
||
}
|
||
EquipBase equipBase = DataTableHelper.Get<EquipBase>(equip.ItemId);
|
||
if (attributeIndex >= equipBase.MaxHole || attributeIndex < 0)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】炼化属性Index = {attributeIndex}超出范围");
|
||
return "系统错误";
|
||
}
|
||
bool canInlay = false;
|
||
GemInlayConfig gemInlayConfig = GemInlayConfigCategory.Instance.Get(equipBase.Type);
|
||
if (gemInlayConfig == null)
|
||
{
|
||
Log.Error($"【{UserComponent.Instance.Get(unit.Id)?.NickName}({unit.Id})】 gemInlay is null");
|
||
return "系统错误";
|
||
}
|
||
for (int i = 0; i < gemInlayConfig.CanInlayArr.Length; i++)
|
||
{
|
||
int canInlayGem = gemInlayConfig.CanInlayArr[i];
|
||
if (canInlayGem == materialBase.GemKey)
|
||
{
|
||
canInlay = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!canInlay) return "此属性的宝石不能镶嵌在当前装备上,请重新放置宝石!";
|
||
//!检验并扣钱
|
||
GemPriceConfig priceConfig = GemPriceConfigCategory.Instance.Get(materialBase.GemLevel);
|
||
int price = priceConfig.InlayPrice * 10000;
|
||
long coin = (long)(price * MeltingAddPrice[attributeIndex]);
|
||
string ret = CharacterHelper.ReduceMoney(unit, CharacterHelper.MoneyType.Coin, coin);
|
||
if (ret != null)
|
||
return ret;
|
||
//!改变属性
|
||
self.DeleteItem(unit, gemIndex, 1);
|
||
equip.IsLock = true;
|
||
EquipItem equipItem = equip.data.As<EquipItem>();
|
||
equipItem.gemList[attributeIndex] = gem.ItemId;
|
||
return string.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打造
|
||
/// </summary>
|
||
/// <param name="self"></param>
|
||
/// <param name="unit"></param>
|
||
/// <param name="dateTableId"></param>
|
||
/// <returns></returns>
|
||
public static async ETTask<string> ForgeEquip(this ItemComponent self, Unit unit, int dateTableId)
|
||
{
|
||
EquipForge equipForge = DataTableHelper.Get<EquipForge>(dateTableId);
|
||
if (equipForge == null)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】想要合成TableId = {dateTableId}的不存在装备");
|
||
return "系统错误";
|
||
}
|
||
bool checkRet = self.CanAddItem(unit, equipForge.MadeEquipId, 1);
|
||
if (!checkRet)
|
||
{
|
||
return "背包已满,至少留出一个空位!";
|
||
}
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
int equipIndex = 0;
|
||
if (equipForge.NeedEquipmentId != 0)
|
||
{
|
||
if (!bag.ItemDic.TryGetValueByKey2(equipForge.NeedEquipmentId, out List<Item> equipList) || equipList.Count == 0)
|
||
{
|
||
Log.Error($"[合成]【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】 背包中没有EquipId={equipForge.NeedEquipmentId}的装备,客户端已限制");
|
||
return "系统错误";
|
||
}
|
||
//!扣除装备
|
||
equipIndex = equipList[0].index;
|
||
}
|
||
List<(int, int)> removeList = new List<(int, int)>();
|
||
for (int i = equipForge.NeedMaterialArr.Length - 1; i >= 0; i--)
|
||
{
|
||
EquipForge.NeedMaterial needMaterial = equipForge.NeedMaterialArr[i];
|
||
if (!BagHelper.HasItem(bag, needMaterial.NeedMaterial_Id, needMaterial.NeedMaterial_Count))
|
||
{
|
||
Log.Error($"[合成]【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】 背包中背包中没有MaterialId={needMaterial.NeedMaterial_Id}的材料数量<{needMaterial.NeedMaterial_Count},客户端已限制");
|
||
return "系统错误";
|
||
}
|
||
//!扣除材料
|
||
removeList.Add((needMaterial.NeedMaterial_Id, needMaterial.NeedMaterial_Count));
|
||
}
|
||
//!扣钱
|
||
string reduceMoneyRet = CharacterHelper.ReduceMoney(unit, CharacterHelper.MoneyType.Coin, equipForge.NeedCoin);
|
||
if (reduceMoneyRet != null)
|
||
{
|
||
Log.Error($"[合成]【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】 铜钱不足{unit.GetComponent<NumericComponent>().GetAsLong(NumericType.Coin)}<{equipForge.NeedCoin},客户端已限制");
|
||
return "系统错误";
|
||
}
|
||
//!删装备
|
||
self.DeleteItem(unit, equipIndex, 1);
|
||
//!删材料
|
||
foreach ((int itemId, int itemCount) in removeList)
|
||
{
|
||
bag.DeleteMultiItem(itemId, itemCount);
|
||
}
|
||
//!给新货
|
||
User user = await UserComponent.Instance.Query(unit.Id);
|
||
self.AddItem(unit, equipForge.MadeEquipId, 1, false, randomMax: 0.25f, getSource: user?.NickName + "[合成]");
|
||
UnitHelper.SaveComponenet(bag).Coroutine();
|
||
|
||
return string.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 进化
|
||
/// </summary>
|
||
/// <param name="self"></param>
|
||
/// <param name="unit"></param>
|
||
/// <param name="itemIndex"></param>
|
||
/// <param name="requestIsLock"></param>
|
||
/// <returns></returns>
|
||
public static async ETTask<string> UpgradeItem(this ItemComponent self, Unit unit, int itemIndex, bool requestIsLock)
|
||
{
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
if (!bag.ItemDic.TryGetValueByKey1(itemIndex, out Item item))
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】背包中没有物品Index ={itemIndex}");
|
||
return "系统错误";
|
||
}
|
||
if (item.IsEmpty)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】背包中物品Index ={itemIndex}是空物品");
|
||
return "系统错误";
|
||
}
|
||
ItemUpgrade itemUpgrade = DataTableHelper.Get<ItemUpgrade>(item.ItemId);
|
||
if (itemUpgrade == null)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】背包中物品Index ={itemIndex}的物品Id ={item.ItemId}不能进化");
|
||
return "系统错误";
|
||
}
|
||
bool checkRet = self.CanAddItem(unit, itemUpgrade.UpgradeItemId, 1);
|
||
if (!checkRet)
|
||
{
|
||
return "背包已满,至少留出一个空位!";
|
||
}
|
||
bool needUnlocked =!requestIsLock && !item.IsLock;
|
||
using ListComponent<(int, int)> listComponent = ListComponent<(int, int)>.Create();
|
||
List<(int, int)> removeList = listComponent.List;
|
||
for (int i = itemUpgrade.UpgradeNeedMaterialArr.Length - 1; i >= 0; i--)
|
||
{
|
||
ItemUpgrade.UpgradeNeedMaterial needMaterial = itemUpgrade.UpgradeNeedMaterialArr[i];
|
||
int count = needMaterial.UpgradeNeedMaterial_Count;
|
||
if (item.ItemId == needMaterial.UpgradeNeedMaterial_Id)
|
||
count++;
|
||
if (!BagHelper.HasItem(bag, needMaterial.UpgradeNeedMaterial_Id, count, needUnlocked))
|
||
{
|
||
Log.Error($"[进化]【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】 背包中背包中没有MaterialId={needMaterial.UpgradeNeedMaterial_Id}的材料数量<{needMaterial.UpgradeNeedMaterial_Count}");
|
||
return "系统错误,材料不足";
|
||
}
|
||
removeList.Add((needMaterial.UpgradeNeedMaterial_Id, needMaterial.UpgradeNeedMaterial_Count));
|
||
}
|
||
if (MathHelper.IsHit(itemUpgrade.SucceefulRate))
|
||
{
|
||
//!扣取物品和材料
|
||
self.DeleteItem(unit, itemIndex, 1);
|
||
foreach ((int itemId, int itemCount) in removeList)
|
||
{
|
||
bag.DeleteMultiItem(itemId, itemCount,needUnlocked);
|
||
}
|
||
//!增加新物品
|
||
User user = await UserComponent.Instance.Query(unit.Id);
|
||
self.AddItem(unit, itemUpgrade.UpgradeItemId,out Item newItem, 1, item.IsLock, getSource: user?.NickName + "[进化]");
|
||
if(item.ItemType == ItemType.EquipItem)
|
||
InhintOldEquip(unit,item, newItem);
|
||
if (itemUpgrade.IsSysChat)
|
||
{
|
||
Chat.Instance.SendSystemCaht($"恭喜【{user?.NickName}】牛气冲天,成功进化一个[color=#ff0000]{BagHelper.GetName(itemUpgrade.UpgradeItemId)}[/color]!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (ItemUpgrade.FailCast failCast in itemUpgrade.FailCastArr)
|
||
{
|
||
bag.DeleteMultiItem(failCast._Id, failCast.Count,needUnlocked);
|
||
}
|
||
}
|
||
UnitHelper.SaveComponenet(bag).Coroutine();
|
||
return string.Empty;
|
||
|
||
static void InhintOldEquip(Unit unit, Item item, Item newItem)
|
||
{
|
||
try
|
||
{
|
||
EquipItem old = item.data.As<EquipItem>();
|
||
EquipItem newEquip = newItem.data.As<EquipItem>();
|
||
newEquip.equipLevel = old.equipLevel;
|
||
newEquip.gemList = old.gemList.Clone() as int[];
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】itemId:{newItem.ItemId} serverId{newItem.ServerId}\n{e}");
|
||
return;
|
||
}
|
||
}
|
||
|
||
}
|
||
public static async ETTask<string> SellItem(this ItemComponent self, Unit unit, int slotIndex, int count)
|
||
{
|
||
await ETTask.CompletedTask;
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
if (!bag.ItemDic.TryGetValueByKey1(slotIndex, out Item item))
|
||
{
|
||
Log.Error($"[玩家]{ UserComponent.Instance.Get(unit.Id)?.NickName} 想要出售得物品为空");
|
||
return "系统错误";
|
||
}
|
||
if (item.Count < count)
|
||
{
|
||
return "数量不足";
|
||
}
|
||
IConfig itemBase = BagHelper.GetItemBase(item.ItemId);
|
||
long price = itemBase switch
|
||
{
|
||
EquipBase equipBase => equipBase.Price,
|
||
GoodsBase goodsBase => goodsBase.Price,
|
||
MaterialBase materialBase => materialBase.Price,
|
||
_ => throw new Exception($"type is invalid : {itemBase.GetType()} "),
|
||
};
|
||
CharacterHelper.AddMoney(unit, CharacterHelper.MoneyType.Coin, price * count);
|
||
StatisticsHelper.AddInfo(unit.Id, StatisticComponent.StatisticType.Coin, StatisticsTypes.CoinSources_SellItem, price * count);
|
||
string ret = self.DeleteItem(unit, slotIndex, count);
|
||
if (!ret.Equals(string.Empty))
|
||
{
|
||
return ret;
|
||
}
|
||
return string.Empty;
|
||
}
|
||
public static async ETTask<string> MakeMunalEquip(this ItemComponent self, Unit unit, MunalStoneType stoneType, C2M_MakeMunalEquip.StoneType isRare)
|
||
{
|
||
try
|
||
{
|
||
EquipType equipType2 = stoneType switch
|
||
{
|
||
MunalStoneType.Red => EquipType.项链,
|
||
MunalStoneType.White => EquipType.护腕,
|
||
MunalStoneType.Green => EquipType.帽子,
|
||
MunalStoneType.Black => EquipType.戒指,
|
||
_ => throw new Exception($"type is wrong :{stoneType}"),
|
||
};
|
||
ManulEquip manulEquip = ManulEquipCategory.Instance.Get((long)equipType2);
|
||
switch (isRare)
|
||
{
|
||
case C2M_MakeMunalEquip.StoneType.Nomal:
|
||
{
|
||
ManulEquip.Material[] materialArr = manulEquip.MaterialArr;
|
||
foreach (ManulEquip.Material needMaterial7 in materialArr)
|
||
{
|
||
if (!BagHelper.HasItem(unit, needMaterial7.MaterialId, needMaterial7.Count))
|
||
{
|
||
return "材料[" + BagHelper.GetName(needMaterial7.MaterialId) + "]不足,无法制作";
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case C2M_MakeMunalEquip.StoneType.Rare:
|
||
{
|
||
ManulEquip.RareMaterial[] rareMaterialArr = manulEquip.RareMaterialArr;
|
||
foreach (ManulEquip.RareMaterial needMaterial8 in rareMaterialArr)
|
||
{
|
||
if (!BagHelper.HasItem(unit, needMaterial8.MaterialId, needMaterial8.Count))
|
||
{
|
||
return "材料[" + BagHelper.GetName(needMaterial8.MaterialId) + "]不足,无法制作";
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case C2M_MakeMunalEquip.StoneType.Epic:
|
||
{
|
||
ManulEquip.EpicMaterial[] epicMaterialArr = manulEquip.EpicMaterialArr;
|
||
foreach (ManulEquip.EpicMaterial needMaterial6 in epicMaterialArr)
|
||
{
|
||
if (!BagHelper.HasItem(unit, needMaterial6.MaterialId, needMaterial6.Count))
|
||
{
|
||
return "材料[" + BagHelper.GetName(needMaterial6.MaterialId) + "]不足,无法制作";
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case C2M_MakeMunalEquip.StoneType.UpgradeRare:
|
||
{
|
||
ManulEquip.UpgradeRareMaterial[] upgradeRareMaterialArr = manulEquip.UpgradeRareMaterialArr;
|
||
foreach (ManulEquip.UpgradeRareMaterial needMaterial in upgradeRareMaterialArr)
|
||
{
|
||
if (!BagHelper.HasItem(unit, needMaterial.MaterialId, needMaterial.Count))
|
||
{
|
||
return "材料[" + BagHelper.GetName(needMaterial.MaterialId) + "]不足,无法制作";
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
if (!bag.CanAddNewItem)
|
||
{
|
||
return "背包已满,请及时清理";
|
||
}
|
||
PlayerData data = unit.GetComponent<PlayerData>();
|
||
switch (isRare)
|
||
{
|
||
case C2M_MakeMunalEquip.StoneType.Nomal:
|
||
{
|
||
if (data.manulEquipMakeCount <= 0)
|
||
{
|
||
return "今日制作次数达到上限";
|
||
}
|
||
data.manulEquipMakeCount--;
|
||
ManulEquip.Material[] materialArr2 = manulEquip.MaterialArr;
|
||
foreach (ManulEquip.Material needMaterial2 in materialArr2)
|
||
{
|
||
BagHelper.DeleteItem(bag, needMaterial2.MaterialId, needMaterial2.Count);
|
||
}
|
||
break;
|
||
}
|
||
case C2M_MakeMunalEquip.StoneType.Rare:
|
||
{
|
||
if (data.manulEquipMakeCount <= 0)
|
||
{
|
||
return "今日制作次数达到上限";
|
||
}
|
||
data.manulEquipMakeCount--;
|
||
ManulEquip.RareMaterial[] rareMaterialArr2 = manulEquip.RareMaterialArr;
|
||
foreach (ManulEquip.RareMaterial needMaterial3 in rareMaterialArr2)
|
||
{
|
||
BagHelper.DeleteItem(bag, needMaterial3.MaterialId, needMaterial3.Count);
|
||
}
|
||
break;
|
||
}
|
||
case C2M_MakeMunalEquip.StoneType.Epic:
|
||
{
|
||
ManulEquip.EpicMaterial[] epicMaterialArr2 = manulEquip.EpicMaterialArr;
|
||
foreach (ManulEquip.EpicMaterial needMaterial4 in epicMaterialArr2)
|
||
{
|
||
BagHelper.DeleteItem(bag, needMaterial4.MaterialId, needMaterial4.Count);
|
||
}
|
||
break;
|
||
}
|
||
case C2M_MakeMunalEquip.StoneType.UpgradeRare:
|
||
{
|
||
if (data.manulEquipMakeCount <= 0)
|
||
{
|
||
return "今日制作次数达到上限";
|
||
}
|
||
data.manulEquipMakeCount--;
|
||
ManulEquip.UpgradeRareMaterial[] upgradeRareMaterialArr2 = manulEquip.UpgradeRareMaterialArr;
|
||
foreach (ManulEquip.UpgradeRareMaterial needMaterial5 in upgradeRareMaterialArr2)
|
||
{
|
||
BagHelper.DeleteItem(bag, needMaterial5.MaterialId, needMaterial5.Count);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
UnitHelper.SaveComponenet(data).Coroutine();
|
||
NumericComponent num = unit.GetComponent<NumericComponent>();
|
||
EquipItem equipItem = new EquipItem();
|
||
User user = await UserComponent.Instance.Query(unit.Id);
|
||
if (user == null)
|
||
{
|
||
Log.Error($"user== null where id ={unit.Id}");
|
||
return "系统错误,无人物信息";
|
||
}
|
||
AttributeType atkType = CharacterHelper.GetAtkType(user.JobId);
|
||
equipItem.CreateManul(unit,equipType2, atkType, isRare, num.GetAsInt(NumericType.Level));
|
||
Item item = new Item(equipItem)
|
||
{
|
||
ServerId = Game.IdGenerater.GenerateId(),
|
||
ItemType = ItemType.EquipItem,
|
||
Count = 1,
|
||
IsLock = (isRare == C2M_MakeMunalEquip.StoneType.Nomal || isRare == C2M_MakeMunalEquip.StoneType.UpgradeRare),
|
||
ItemId = manulEquip.EquipId,
|
||
getSource = user.NickName + "[手工]"
|
||
};
|
||
bag.AddItem(item);
|
||
UnitHelper.SaveComponenet(bag).Coroutine();
|
||
if (equipItem.star >= 8)
|
||
{
|
||
Chat.Instance.SendSystemCaht($"千锤百炼,[color=#ffff00]{user.NickName.Trim()}[/color]成功制作出[color=#aa0000]{equipItem.star}[color=#aa0000]星[{BagHelper.GetName(equipItem.itemId)}]!");
|
||
}
|
||
else if (equipItem.quality >= Quality.Legendary)
|
||
{
|
||
Chat.Instance.SendSystemCaht("千锤百炼,[color=#ffff00]" + user.NickName.Trim() + "[/color]成功制作出[color=#aa0000]" + ((equipItem.quality == Quality.Legendary) ? "传奇" : "天工") + "[color=#aa0000]品质的[" + BagHelper.GetName(equipItem.itemId) + "]!");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Exception e = ex;
|
||
Log.Error(e);
|
||
}
|
||
return null;
|
||
}
|
||
public static async ETTask<(string, bool)> StrangeEquip(this ItemComponent self, Unit unit, int itemIndex)
|
||
{
|
||
try
|
||
{
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
if (!bag.ItemDic.TryGetValueByKey1(itemIndex, out Item item))
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】背包中没有物品Index ={itemIndex}");
|
||
return ("系统错误", false);
|
||
}
|
||
if (item.IsEmpty)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】背包中物品Index ={itemIndex}是空物品");
|
||
return ("系统错误,强化的是空格子", false);
|
||
}
|
||
if (item.ItemType != ItemType.EquipItem)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】背包中物品Index ={itemIndex}不是装备:{item.ItemType}");
|
||
return ("系统错误,不是装备", false);
|
||
}
|
||
EquipItem equipItem = item.data.As<EquipItem>();
|
||
if (equipItem.equipLevel >= ConstDefine.EquipMaxLevel)
|
||
{
|
||
return ("已经达到最大等级,无法强化!", false);
|
||
}
|
||
|
||
int targetLevel = equipItem.equipLevel + 1;
|
||
Strengthentable strengthentable = StrengthentableCategory.Instance.Get(targetLevel);
|
||
|
||
|
||
//材料
|
||
foreach (Strengthentable.NeedMaterial needMaterial in strengthentable.NeedMaterialArr)
|
||
{
|
||
if (!BagHelper.HasItem(bag, needMaterial._Id, needMaterial.Count))
|
||
{
|
||
return ("材料不足", false);
|
||
}
|
||
}
|
||
string ret = CharacterHelper.ReduceMoney(unit, CharacterHelper.MoneyType.Coin, strengthentable.NeedCoin * 10000);
|
||
if (ret != null)
|
||
{
|
||
return (ret, false);
|
||
}
|
||
foreach (Strengthentable.NeedMaterial needMaterial in strengthentable.NeedMaterialArr)
|
||
{
|
||
BagHelper.DeleteItem(bag, needMaterial._Id, needMaterial.Count);
|
||
}
|
||
bool isSuccess = false;
|
||
|
||
if (MathHelper.IsHit(strengthentable.Probability))
|
||
{
|
||
await Succeed(unit, equipItem, targetLevel);
|
||
isSuccess = true;
|
||
}
|
||
else
|
||
{
|
||
//记录保底
|
||
PlayerData data = unit.GetComponent<PlayerData>();
|
||
int index = data.strengthCountList.FindIndex(t => t.Key == targetLevel);
|
||
KeyValuePair<int, int> kv;
|
||
if (index == -1)
|
||
{
|
||
kv = KeyValuePair.Create(targetLevel, RandomHelper.RandomNumber(strengthentable.MaxMinCount, strengthentable.MaxMaxCount));
|
||
data.strengthCountList.Add(kv);
|
||
index = data.strengthCountList.IndexOf(kv);
|
||
}
|
||
else
|
||
kv = data.strengthCountList[index];
|
||
int count = kv.Value;
|
||
if (count <= 0)
|
||
{
|
||
//保底
|
||
data.strengthCountList[index] = KeyValuePair.Create(targetLevel, RandomHelper.RandomNumber(strengthentable.MaxMinCount, strengthentable.MaxMaxCount));
|
||
await Succeed(unit, equipItem, targetLevel);
|
||
isSuccess = true;
|
||
}
|
||
else
|
||
{
|
||
//掉级
|
||
equipItem.equipLevel = strengthentable.FailLevel;
|
||
--count;
|
||
data.strengthCountList[index] = KeyValuePair.Create(targetLevel, count);
|
||
}
|
||
UnitHelper.SaveComponenet(data).Coroutine();
|
||
}
|
||
UnitHelper.SaveComponenet(bag).Coroutine();
|
||
return (null, isSuccess);
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Log.Error(e);
|
||
}
|
||
return (null, false);
|
||
|
||
static async ETTask Succeed(Unit unit, EquipItem equipItem, int targetLevel)
|
||
{
|
||
equipItem.isLock = true;
|
||
equipItem.equipLevel = targetLevel;
|
||
if (targetLevel >= 15)
|
||
{
|
||
User user = await UserComponent.Instance.Query(unit.Id);
|
||
if (user == null)
|
||
{
|
||
Log.Error($"user== null where id ={unit.Id}");
|
||
return;
|
||
}
|
||
Chat.Instance.SendSystemCaht($"天降洪福,[color=#ff6600]{user.NickName.Trim()}[/color]将装备[{BagHelper.GetName(equipItem.itemId)}]强化至[color=#ff0000]+{targetLevel}[/color],实力大增,称霸大业,近在咫尺!");
|
||
return;
|
||
}
|
||
if (targetLevel > 12)
|
||
{
|
||
User user = await UserComponent.Instance.Query(unit.Id);
|
||
if (user == null)
|
||
{
|
||
Log.Error($"user== null where id ={unit.Id}");
|
||
return;
|
||
}
|
||
Chat.Instance.SendSystemCaht($"恭喜[color=#ffff00]{user.NickName.Trim()}[/color]鸿运当头,成功将装备[{BagHelper.GetName(equipItem.itemId)}]强化至[color=#aa0000]+{targetLevel}[/color]!");
|
||
}
|
||
}
|
||
}
|
||
|
||
private static Item GetItem(Bag bag, int itemIndex)
|
||
{
|
||
if (!bag.ItemDic.TryGetValueByKey1(itemIndex, out Item item))
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(bag.Id)?.NickName} ({ bag.Id})】背包中没有物品Index ={itemIndex}");
|
||
return null;
|
||
}
|
||
if (item.IsEmpty)
|
||
{
|
||
Log.Error($"【{ UserComponent.Instance.Get(bag.Id)?.NickName} ({ bag.Id})】背包中物品Index ={itemIndex}是空物品");
|
||
return null;
|
||
}
|
||
return item;
|
||
}
|
||
public static async ETTask<string> RefreshEquipMainAttribute(this ItemComponent self, Unit unit, int index)
|
||
{
|
||
await ETTask.CompletedTask;
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
Item item = GetItem(bag, index);
|
||
if (item == null) return "系统错误";
|
||
if (item.ItemType != ItemType.EquipItem)
|
||
{
|
||
return "装备才能洗练";
|
||
}
|
||
EquipItem equipItem = item.data.As<EquipItem>();
|
||
if (equipItem.mainAttribute == null)
|
||
{
|
||
return "此装备无法洗练属性";
|
||
}
|
||
string ret = CharacterHelper.ReduceMoney(unit, CharacterHelper.MoneyType.Coin, ConstDefine.RefreshEquipMainAttributePrice);
|
||
if (ret != null)
|
||
return ret;
|
||
item.IsLock = true;
|
||
using ListComponent<int> listComponent = ListComponent<int>.Create();
|
||
listComponent.List.AddRange(equipItem.mainAttribute.Keys);
|
||
foreach (int key in listComponent.List)
|
||
{
|
||
equipItem.mainAttribute[key] = ItemHelper.GetRandom(ConstDefine.EquipMaxRandom);
|
||
}
|
||
UnitHelper.SaveComponenet(bag).Coroutine();
|
||
return null;
|
||
}
|
||
public static async ETTask<string> RefreshEquipAffix(this ItemComponent self, Unit unit, int index)
|
||
{
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
Item item = GetItem(bag, index);
|
||
if (item == null) return "系统错误";
|
||
if (item.ItemType != ItemType.EquipItem)
|
||
{
|
||
return "装备才能洗练";
|
||
}
|
||
EquipItem equipItem = item.data.As<EquipItem>();
|
||
if (equipItem.addtionalAttributes == null)
|
||
{
|
||
return "装备错误";
|
||
}
|
||
string ret = CharacterHelper.ReduceMoney(unit, CharacterHelper.MoneyType.Coin, ConstDefine.RefreshEquipAffixePrice);
|
||
if (ret != null)
|
||
return ret;
|
||
item.IsLock = true;
|
||
EquipBase equipBase = EquipBaseCategory.Instance.Get(equipItem.itemId);
|
||
int level = equipBase.UseLevel;
|
||
if (equipBase.UseLevel == 1)
|
||
{
|
||
User user = await UserComponent.Instance.Query(unit.Id);
|
||
level = user.Level;
|
||
}
|
||
ItemHelper.GenerateAdditionalAttribute(equipItem, level);
|
||
UnitHelper.SaveComponenet(bag).Coroutine();
|
||
return null;
|
||
}
|
||
/// <summary>
|
||
/// 拆卸宝石
|
||
/// </summary>
|
||
/// <param name="unit"></param>
|
||
/// <param name="index"></param>
|
||
/// <returns></returns>
|
||
public static async ETTask<string> DismountGem(this ItemComponent self, Unit unit, int index, int gemIndex)
|
||
{
|
||
Bag bag = unit.GetComponent<Bag>();
|
||
Item item = GetItem(bag, index);
|
||
if (item == null) return "系统错误";
|
||
if (item.ItemType != ItemType.EquipItem)
|
||
{
|
||
return "不是装备";
|
||
}
|
||
EquipItem equipItem = item.data.As<EquipItem>();
|
||
if (equipItem.gemList == null)
|
||
{
|
||
return "装备错误";
|
||
}
|
||
if (gemIndex < 0 || gemIndex > equipItem.gemList.Length)
|
||
{
|
||
Log.Error($"【{UserComponent.Instance.Get(unit.Id)?.NickName}({unit.Id})】想要拆卸{gemIndex}位置的宝石");
|
||
return "系统错误";
|
||
}
|
||
int itemId = equipItem.gemList[gemIndex];
|
||
if (itemId == 0)
|
||
{
|
||
return "拆卸的位置没有宝石";
|
||
}
|
||
MaterialBase materialBase = MaterialBaseCategory.Instance.Get(itemId);
|
||
if ((MaterialsType)materialBase.MaterialType != MaterialsType.宝石)
|
||
{
|
||
return "系统错误";
|
||
}
|
||
GemPriceConfig priceConfig = GemPriceConfigCategory.Instance.Get(materialBase.GemLevel);
|
||
string ret = CharacterHelper.ReduceMoney(unit, CharacterHelper.MoneyType.Coin, (long)(priceConfig.DiscountPrice * 10000 * MeltingAddPrice[gemIndex]));
|
||
if (ret != null)
|
||
return ret;
|
||
equipItem.gemList[gemIndex] = 0;
|
||
await MailHelper.AddItem(unit.Id, itemId, 1, true, "拆卸", "宝石拆卸", "宝石拆卸", "系统");
|
||
UnitHelper.SaveComponenet(bag).Coroutine();
|
||
return null;
|
||
}
|
||
}
|
||
}
|