zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/System/Bag/ItemComponentSystem.cs

1009 lines
41 KiB
C#
Raw Normal View History

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