private void TallyItems(MyObjectBuilderType tallyTypeId, string tallySubTypeId, Decimal amountDecimal, string contentPath, SortedDictionary<string, OreContent> accumulateOres, SortedDictionary<string, ComponentItemModel> accumulateItems, SortedDictionary<string, ComponentItemModel> accumulateComponents)
{
var cd = MyDefinitionManager.Static.GetDefinition(tallyTypeId, tallySubTypeId) as MyPhysicalItemDefinition;
if (cd == null)
{
// A component, gun, ore that doesn't exist (Depricated by KeenSH, or Mod that isn't loaded).
return;
}
var componentTexture = SpaceEngineersCore.GetDataPathOrDefault(cd.Icons.First(), Path.Combine(contentPath, cd.Icons.First()));
if (tallyTypeId == SpaceEngineersTypes.Ore)
{
var mass = Math.Round((double)amountDecimal * cd.Mass, 7);
var volume = Math.Round((double)amountDecimal * cd.Volume * SpaceEngineersConsts.VolumeMultiplyer, 7);
#region unused ore value
var unusedKey = tallySubTypeId;
if (accumulateOres.ContainsKey(unusedKey))
{
accumulateOres[unusedKey].Amount += amountDecimal;
accumulateOres[unusedKey].Mass += mass;
accumulateOres[unusedKey].Volume += volume;
}
else
{
accumulateOres.Add(unusedKey, new OreContent { Name = cd.DisplayNameText, Amount = amountDecimal, Mass = mass, Volume = volume, TextureFile = componentTexture });
}
#endregion
#region tally items
if (accumulateItems != null)
{
var itemsKey = cd.DisplayNameText;
if (accumulateItems.ContainsKey(itemsKey))
{
accumulateItems[itemsKey].Count += amountDecimal;
accumulateItems[itemsKey].Mass += mass;
accumulateItems[itemsKey].Volume += volume;
}
else
{
accumulateItems.Add(itemsKey, new ComponentItemModel { Name = cd.DisplayNameText, Count = amountDecimal, Mass = mass, Volume = volume, TypeId = tallyTypeId, SubtypeId = tallySubTypeId, TextureFile = componentTexture, Time = TimeSpan.Zero });
}
}
#endregion
}
else if (tallyTypeId == SpaceEngineersTypes.Ingot)
{
var mass = Math.Round((double)amountDecimal * cd.Mass, 7);
var volume = Math.Round((double)amountDecimal * cd.Volume * SpaceEngineersConsts.VolumeMultiplyer, 7);
var bp = SpaceEngineersApi.GetBlueprint(tallyTypeId, tallySubTypeId);
var timeToMake = TimeSpan.Zero;
// no blueprint, means the item is not built by players, but generated by the environment.
if (bp != null && bp.Results != null && bp.Results.Length != 0)
{
timeToMake = TimeSpan.FromSeconds(bp.BaseProductionTimeInSeconds * (double)amountDecimal / (double)bp.Results[0].Amount);
}
#region unused ore value
var oreRequirements = new Dictionary<string, BlueprintRequirement>();
TimeSpan ingotTime;
SpaceEngineersApi.AccumulateCubeBlueprintRequirements(tallySubTypeId, tallyTypeId, amountDecimal, oreRequirements, out ingotTime);
foreach (var item in oreRequirements)
{
TallyItems(item.Value.Id.TypeId, item.Value.SubtypeId, item.Value.Amount, contentPath, accumulateOres, null, null);
}
#endregion
#region tally items
if (accumulateItems != null)
{
var itemsKey = cd.DisplayNameText;
if (accumulateItems.ContainsKey(itemsKey))
{
accumulateItems[itemsKey].Count += amountDecimal;
accumulateItems[itemsKey].Mass += mass;
accumulateItems[itemsKey].Volume += volume;
accumulateItems[itemsKey].Time += timeToMake;
}
else
{
accumulateItems.Add(itemsKey, new ComponentItemModel { Name = cd.DisplayNameText, Count = amountDecimal, Mass = mass, Volume = volume, TypeId = tallyTypeId, SubtypeId = tallySubTypeId, TextureFile = componentTexture, Time = timeToMake });
}
}
#endregion
}
else if (tallyTypeId == SpaceEngineersTypes.AmmoMagazine ||
tallyTypeId == SpaceEngineersTypes.PhysicalGunObject ||
tallyTypeId == SpaceEngineersTypes.OxygenContainerObject)
{
var mass = Math.Round((double)amountDecimal * cd.Mass, 7);
var volume = Math.Round((double)amountDecimal * cd.Volume * SpaceEngineersConsts.VolumeMultiplyer, 7);
var bp = SpaceEngineersApi.GetBlueprint(tallyTypeId, tallySubTypeId);
var timeToMake = TimeSpan.FromSeconds(bp == null ? 0 : bp.BaseProductionTimeInSeconds * (double)amountDecimal);
#region unused ore value
var oreRequirements = new Dictionary<string, BlueprintRequirement>();
TimeSpan ingotTime;
SpaceEngineersApi.AccumulateCubeBlueprintRequirements(tallySubTypeId, tallyTypeId, amountDecimal, oreRequirements, out ingotTime);
foreach (var item in oreRequirements)
{
TallyItems(item.Value.Id.TypeId, item.Value.SubtypeId, item.Value.Amount, contentPath, accumulateOres, null, accumulateComponents);
}
#endregion
#region tally items
if (accumulateItems != null)
{
var itemsKey = cd.DisplayNameText;
if (accumulateItems.ContainsKey(itemsKey))
{
accumulateItems[itemsKey].Count += amountDecimal;
accumulateItems[itemsKey].Mass += mass;
accumulateItems[itemsKey].Volume += volume;
accumulateItems[itemsKey].Time += timeToMake;
}
else
{
accumulateItems.Add(itemsKey, new ComponentItemModel() { Name = cd.DisplayNameText, Count = amountDecimal, Mass = mass, Volume = volume, TypeId = tallyTypeId, SubtypeId = tallySubTypeId, TextureFile = componentTexture, Time = timeToMake });
}
}
#endregion
}
else if (tallyTypeId == SpaceEngineersTypes.Component)
{
var mass = Math.Round((double)amountDecimal * cd.Mass, 7);
var volume = Math.Round((double)amountDecimal * cd.Volume * SpaceEngineersConsts.VolumeMultiplyer, 7);
var bp = SpaceEngineersApi.GetBlueprint(tallyTypeId, tallySubTypeId);
var timeToMake = new TimeSpan();
// mod provides no blueprint for component.
if (bp != null)
timeToMake = TimeSpan.FromSeconds(bp.BaseProductionTimeInSeconds * (double)amountDecimal);
#region unused ore value
var oreRequirements = new Dictionary<string, BlueprintRequirement>();
TimeSpan ingotTime;
SpaceEngineersApi.AccumulateCubeBlueprintRequirements(tallySubTypeId, tallyTypeId, amountDecimal, oreRequirements, out ingotTime);
foreach (var item in oreRequirements)
{
TallyItems(item.Value.Id.TypeId, item.Value.SubtypeId, item.Value.Amount, contentPath, accumulateOres, null, null);
}
#endregion
#region tally items
if (accumulateComponents != null)
{
var itemsKey = cd.DisplayNameText;
if (accumulateComponents.ContainsKey(itemsKey))
{
accumulateComponents[itemsKey].Count += amountDecimal;
accumulateComponents[itemsKey].Mass += mass;
accumulateComponents[itemsKey].Volume += volume;
accumulateComponents[itemsKey].Time += timeToMake;
}
else
{
accumulateComponents.Add(itemsKey, new ComponentItemModel() { Name = cd.DisplayNameText, Count = amountDecimal, Mass = mass, Volume = volume, TypeId = tallyTypeId, SubtypeId = tallySubTypeId, TextureFile = componentTexture, Time = timeToMake });
}
}
#endregion
}
//else if (typeId == SpaceEngineersConsts.CubeBlock)
else // if (tallyItem is MyObjectBuilder_EntityBase)
{
// TODO: missed a new object type?
}
}