So my ambition has quickly escalated since I started modding. I am now starting my first attempt at C# to create a buildingClass for a production building that functions similarly to how to fermenting barrel does, except instead of wort and beer, you turn cartridges into graphene.
I have two problems, the first is that my visual studios project is running on .NET framework 2.0 and I have been completely unable to get anything past 2.0 to work. Will this work fine? If not how do I install other frameworks?
My second problem is that I have only one error. 'ThingDefOf' does not contain a definition for 'Graphene'.
I haven't the faintest clue how to resolve this. The code for the fermenting barrel also doesn't have a definiton for beer yet that seems to work fine. What do?
Here's my code if you're willing to look through. I appreciate any and all help.
I have two problems, the first is that my visual studios project is running on .NET framework 2.0 and I have been completely unable to get anything past 2.0 to work. Will this work fine? If not how do I install other frameworks?
My second problem is that I have only one error. 'ThingDefOf' does not contain a definition for 'Graphene'.
I haven't the faintest clue how to resolve this. The code for the fermenting barrel also doesn't have a definiton for beer yet that seems to work fine. What do?
Here's my code if you're willing to look through. I appreciate any and all help.
Code Select
using RimWorld;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Verse;
namespace Building_AdvancedPrinter
{
[StaticConstructorOnStartup]
public class Building_AdvancedPrinter : Building
{
private int GrapheneCartridgeCount;
private float progressInt;
private Material barFilledCachedMat;
public const int MaxGrapheneCartridgeCapacity = 10;
private const int BaseReactionDuration = 120000;
public const float MinIdealTemperature = -125f;
private static readonly Vector2 BarSize = new Vector2(0.55f, 0.1f);
private static readonly Color BarZeroProgressColor = new Color(0.4f, 0.27f, 0.22f);
private static readonly Color BarFermentedColor = new Color(0.6f, 0.93f, 0.96f);
private static readonly Material BarUnfilledMat = SolidColorMaterials.SimpleSolidColorMaterial(new Color(0.3f, 0.3f, 0.3f));
public float Progress
{
get
{
return progressInt;
}
set
{
if (value != progressInt)
{
progressInt = value;
barFilledCachedMat = null;
}
}
}
private Material BarFilledMat
{
get
{
if (barFilledCachedMat == null)
{
barFilledCachedMat = SolidColorMaterials.SimpleSolidColorMaterial(Color.Lerp(BarZeroProgressColor, BarFermentedColor, Progress));
}
return barFilledCachedMat;
}
}
public int SpaceLeftForGrapheneCartridge
{
get
{
if (Fermented)
{
return 0;
}
return 10 - GrapheneCartridgeCount;
}
}
private bool Empty => GrapheneCartridgeCount <= 0;
public bool Fermented => !Empty && Progress >= 1f;
private float CurrentTempProgressSpeedFactor
{
get
{
CompProperties_TemperatureRuinable compProperties = def.GetCompProperties<CompProperties_TemperatureRuinable>();
float ambientTemperature = base.AmbientTemperature;
if (ambientTemperature < compProperties.minSafeTemperature)
{
return 0.1f;
}
if (ambientTemperature < 7f)
{
return GenMath.LerpDouble(compProperties.minSafeTemperature, 7f, 0.1f, 1f, ambientTemperature);
}
return 1f;
}
}
private float ProgressPerTickAtCurrentTemp => 2.77777781E-06f * CurrentTempProgressSpeedFactor;
private int EstimatedTicksLeft => Mathf.Max(Mathf.RoundToInt((1f - Progress) / ProgressPerTickAtCurrentTemp), 0);
public override void ExposeData()
{
base.ExposeData();
Scribe_Values.Look(ref GrapheneCartridgeCount, "GraphiteCount", 0);
Scribe_Values.Look(ref progressInt, "progress", 0f);
}
public override void TickRare()
{
base.TickRare();
if (!Empty)
{
Progress = Mathf.Min(Progress + 125f * ProgressPerTickAtCurrentTemp, 1f);
}
}
public void AddGraphite(int count)
{
GetComp<CompTemperatureRuinable>().Reset();
if (Fermented)
{
Log.Warning("Tried to add a graphene cartridge to a depositor filled with graphene sheets. Colonists should remove the graphene sheets first.");
return;
}
int num = Mathf.Min(count, 10 - GrapheneCartridgeCount);
if (num > 0)
{
Progress = GenMath.WeightedAverage(0f, num, Progress, GrapheneCartridgeCount);
GrapheneCartridgeCount += num;
}
}
protected override void ReceiveCompSignal(string signal)
{
if (signal == "RuinedByTemperature")
{
Reset();
}
}
private void Reset()
{
GrapheneCartridgeCount = 0;
Progress = 0f;
}
public void AddGrapheneCartridge(Thing GrapheneCartridge)
{
int num = Mathf.Min(GrapheneCartridge.stackCount, 10 - GrapheneCartridgeCount);
if (num > 0)
{
AddGraphite(num);
GrapheneCartridge.SplitOff(num).Destroy();
}
}
public override string GetInspectString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(base.GetInspectString());
if (stringBuilder.Length != 0)
{
stringBuilder.AppendLine();
}
CompTemperatureRuinable comp = GetComp<CompTemperatureRuinable>();
if (!Empty && !comp.Ruined)
{
if (Fermented)
{
stringBuilder.AppendLine("ContainsGraphene".Translate(GrapheneCartridgeCount, 10));
}
else
{
stringBuilder.AppendLine("ContainsGrapheneCartridge".Translate(GrapheneCartridgeCount, 10));
}
}
if (!Empty)
{
if (Fermented)
{
stringBuilder.AppendLine("Complete".Translate());
}
else
{
stringBuilder.AppendLine("ReactionProgress".Translate(Progress.ToStringPercent(), EstimatedTicksLeft.ToStringTicksToPeriod()));
if (CurrentTempProgressSpeedFactor != 1f)
{
stringBuilder.AppendLine("GrapheneVatOutOfIdealTemperature".Translate(CurrentTempProgressSpeedFactor.ToStringPercent()));
}
}
}
stringBuilder.AppendLine("Temperature".Translate() + ": " + base.AmbientTemperature.ToStringTemperature("F0"));
stringBuilder.AppendLine("IdealReactingTemperature".Translate() + ": " + 7f.ToStringTemperature("F0") + " ~ " + comp.Props.maxSafeTemperature.ToStringTemperature("F0"));
return stringBuilder.ToString().TrimEndNewlines();
}
public Thing TakeOutGraphene()
{
if (!Fermented)
{
Log.Warning("Tried to get graphene but it's not yet complete.");
return null;
}
Thing thing = ThingMaker.MakeThing(ThingDefOf.Graphene);
thing.stackCount = GrapheneCartridgeCount;
Reset();
return thing;
}
public override void Draw()
{
base.Draw();
if (!Empty)
{
Vector3 drawPos = DrawPos;
drawPos.y += 3f / 64f;
drawPos.z += 0.25f;
GenDraw.FillableBarRequest r = default(GenDraw.FillableBarRequest);
r.center = drawPos;
r.size = BarSize;
r.fillPercent = (float)GrapheneCartridgeCount / 25f;
r.filledMat = BarFilledMat;
r.unfilledMat = BarUnfilledMat;
r.margin = 0.1f;
r.rotation = Rot4.North;
GenDraw.DrawFillableBar(r);
}
}
public override IEnumerable<Gizmo> GetGizmos()
{
foreach (Gizmo gizmo in base.GetGizmos())
{
yield return gizmo;
}
if (Prefs.DevMode && !Empty)
{
yield return new Command_Action
{
defaultLabel = "Debug: Set progress to 1",
action = delegate
{
Progress = 1f;
}
};
}
}
}
}