2021-04-08 20:09:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Cal;
|
|
|
|
|
using Cal.DataTable;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public static class ItemHelper
|
|
|
|
|
{
|
|
|
|
|
private static float randomMax;
|
|
|
|
|
const float randomMin = -0.20f;
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
public static void GenerateRandomMainAttribute(EquipItem self, Cal.DataTable.EquipBase equipBase, float randomMax)
|
|
|
|
|
{
|
|
|
|
|
ItemHelper.randomMax = randomMax;
|
|
|
|
|
if (equipBase.Hp != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.最大生命, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Mp != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.最大精力, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Str != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.力量, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Quk != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.敏捷, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Spi != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.精神, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Wim != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.智慧, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Phy != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.体质, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Sta != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.耐力, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.PhyAtk != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.物理攻击, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.SpiAtk != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.精神攻击, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.PhyDef != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.物理防御, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.SpiDef != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.精神防御, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Pcrir != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.物理暴击系数, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Mcrir != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.精神暴击系数, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Pcri != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.物理暴击效果, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Mcri != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.精神暴击效果, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Rpcrir != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.抗物理暴击系数, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Rmcrir != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.抗精神暴击系数, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Rpcri != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.抗物理暴击效果, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Rmcri != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.抗精神暴击效果, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Dvo != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.辅助值, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Nphyi != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.物理免伤, GetRandom());
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipBase.Nmeni != 0)
|
|
|
|
|
{
|
|
|
|
|
self.SetMainAttribute(AttributeType.精神免伤, GetRandom());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static List<int> qualityWeightList = new() { 0, 1025, 856, 1 };
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
public static void GenerateAdditionalAttribute(EquipItem self, int useLevel)
|
|
|
|
|
{
|
|
|
|
|
self.addtionalAttributes.Clear();
|
|
|
|
|
int randCount = 0;
|
|
|
|
|
if (MathHelper.IsHit(0.6f))
|
|
|
|
|
randCount = 1;
|
2021-05-01 22:06:12 +08:00
|
|
|
|
else if (MathHelper.IsHit(0.2f))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
randCount = 2;
|
|
|
|
|
for (int i = 0; i < randCount; i++)
|
|
|
|
|
{
|
|
|
|
|
//稀有度
|
|
|
|
|
int quality = MathHelper.GetProbabilityIndexByWeight(qualityWeightList);
|
2021-05-01 22:06:12 +08:00
|
|
|
|
List<int> vidList = EquipAffixConfigCategory.Instance.vidDic[quality];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (vidList == null || vidList.Count == 0) continue;
|
|
|
|
|
int vidCount = vidList.Count;
|
|
|
|
|
int vid = vidList[RandomHelper.RandomNumber(0, vidCount)];
|
2021-05-01 22:06:12 +08:00
|
|
|
|
List<int> levelList = EquipAffixConfigCategory.Instance.levelDic[vid];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (levelList == null || levelList.Count == 0) continue;
|
2021-05-01 22:06:12 +08:00
|
|
|
|
int level = levelList[^1];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
for (int j = 0; j < levelList.Count; j++)
|
|
|
|
|
{
|
|
|
|
|
if (useLevel < levelList[j])
|
|
|
|
|
{
|
|
|
|
|
if (j == 0) break;
|
|
|
|
|
level = levelList[j - 1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
|
|
|
|
EquipAffixConfig equipAffix = EquipAffixConfigCategory.Instance.Get(vid * 100000 + quality * 10000 + level);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (equipAffix == null)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"affix == null where vid = {vid} level = {level}");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
|
|
|
|
self.addtionalAttributes.Add((int) equipAffix.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static readonly List<int> starSoulQualityWeightList = new()
|
|
|
|
|
{
|
|
|
|
|
32,
|
|
|
|
|
4,
|
|
|
|
|
1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static readonly List<int> starSoulViceCountWeight = new()
|
|
|
|
|
{
|
|
|
|
|
0,
|
|
|
|
|
60,
|
|
|
|
|
30,
|
|
|
|
|
9,
|
|
|
|
|
1
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-02 01:19:35 +08:00
|
|
|
|
public static StarSoulItem GenerateStarSoulItem(Quality starQuality = Quality.Common)
|
2021-05-01 22:06:12 +08:00
|
|
|
|
{
|
|
|
|
|
StarSoulItem item = new();
|
|
|
|
|
item.typeId = 1001;
|
|
|
|
|
item.level = 0;
|
|
|
|
|
item.exp = 0;
|
|
|
|
|
int qualityInt = RandomHelper.RandomByWeight(starSoulQualityWeightList);
|
|
|
|
|
if (qualityInt == -1)
|
|
|
|
|
return null;
|
2021-05-02 01:19:35 +08:00
|
|
|
|
qualityInt = (int) (starQuality + (byte) qualityInt);
|
2021-05-01 22:06:12 +08:00
|
|
|
|
Quality quality = (Quality) qualityInt;
|
|
|
|
|
item.quality = quality;
|
|
|
|
|
item.Id = Game.IdGenerater.GenerateId();
|
|
|
|
|
item.posType = (EquipType) RandomHelper.RandomNumber(0, 12);
|
|
|
|
|
long mainId = GenerateMain(item.posType, qualityInt);
|
|
|
|
|
if (mainId == -1) return null;
|
|
|
|
|
item.mainId = (int) mainId;
|
|
|
|
|
GenerateVice(item);
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
|
|
|
|
|
static long GenerateMain(EquipType type, int qualityInt)
|
|
|
|
|
{
|
|
|
|
|
StarSoulEquipAttributeTypeConfig starSoulEquipAttributeTypeConfig =
|
|
|
|
|
StarSoulEquipAttributeTypeConfigCategory.Instance.Get((long) type);
|
|
|
|
|
if (starSoulEquipAttributeTypeConfig == null) return -1;
|
|
|
|
|
var mainAttibuteList = StarSoulAttributeConfigCategory.Instance.mainAttributeDic[qualityInt];
|
|
|
|
|
long Id = -1;
|
|
|
|
|
using var list1=ListComponent<long>.Create();
|
|
|
|
|
using var weightList=ListComponent<int>.Create();
|
|
|
|
|
var orginWeightList = StarSoulAttributeConfigCategory.Instance.mainWeigt;
|
|
|
|
|
for (var i = 0; i < mainAttibuteList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var l = mainAttibuteList[i];
|
|
|
|
|
StarSoulAttributeConfig soulAttributeConfig = StarSoulAttributeConfigCategory.Instance.Get(l);
|
|
|
|
|
if (starSoulEquipAttributeTypeConfig.AttributeTypeArr.As<IList<int>>().Contains(soulAttributeConfig.Key))
|
|
|
|
|
{
|
|
|
|
|
list1.List.Add(l);
|
|
|
|
|
weightList.List.Add(orginWeightList[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int mainIndex = RandomHelper.RandomByWeight(weightList.List);
|
|
|
|
|
if (mainIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("配置表错误");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mainIndex >= list1.List.Count)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"{mainIndex}>{list1.List.Count}");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Id = list1.List[mainIndex];
|
|
|
|
|
|
|
|
|
|
return Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void GenerateVice(StarSoulItem starSoulItem)
|
|
|
|
|
{
|
|
|
|
|
int count = RandomHelper.RandomByWeight(starSoulViceCountWeight);
|
|
|
|
|
var list = StarSoulAttributeConfigCategory.Instance.viceKeyList;
|
2021-05-02 01:19:35 +08:00
|
|
|
|
using var listComponent=ListComponent<long>.Create();
|
2021-05-01 22:06:12 +08:00
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
{
|
2021-05-02 01:19:35 +08:00
|
|
|
|
long id = 0;
|
|
|
|
|
do
|
2021-05-01 22:06:12 +08:00
|
|
|
|
{
|
2021-05-02 01:19:35 +08:00
|
|
|
|
int index = RandomHelper.RandomByWeight(StarSoulAttributeConfigCategory.Instance.viceWeigt);
|
|
|
|
|
if (index >= list.Count)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"{index}>{list.Count}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id = list[index].Value;
|
2021-05-01 22:06:12 +08:00
|
|
|
|
}
|
2021-05-02 01:19:35 +08:00
|
|
|
|
while (listComponent.List.Contains(id));
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-05-02 01:19:35 +08:00
|
|
|
|
listComponent.List.Add(id);
|
2021-05-01 22:06:12 +08:00
|
|
|
|
starSoulItem.viceIds[i] = (int) id;
|
|
|
|
|
}
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 01:19:35 +08:00
|
|
|
|
private const float reduceCoe = 0.8f;
|
|
|
|
|
public static float GetRealViceValue(float oldValue, Quality quality) => quality switch
|
|
|
|
|
{
|
|
|
|
|
>=Quality.Legendary=>oldValue,
|
|
|
|
|
>=Quality.Rare=>oldValue*reduceCoe,
|
|
|
|
|
<=Quality.UnCommon => oldValue * (reduceCoe*reduceCoe),
|
|
|
|
|
};
|
2021-04-08 20:09:59 +08:00
|
|
|
|
public static float GetRandom()
|
|
|
|
|
{
|
|
|
|
|
return GetRandom(randomMax);
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
public static float GetRandom(float randomMax)
|
|
|
|
|
{
|
|
|
|
|
float maxRandomMultier = randomMax;
|
|
|
|
|
if (MathHelper.IsHit(0.4f))
|
|
|
|
|
{
|
|
|
|
|
maxRandomMultier -= 0.07f;
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (MathHelper.IsHit(0.1f))
|
|
|
|
|
{
|
|
|
|
|
maxRandomMultier -= 0.13f;
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return RandomHelper.RandomFloat(randomMin, maxRandomMultier);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-01 22:06:12 +08:00
|
|
|
|
}
|