Exemplo n.º 1
0
        string ExplanationPartForPawn(StatRequest req)
        {
            //Just in case
            var pawn = req.Thing as Pawn;

            if (pawn == null)
            {
                return(null);
            }

            var result = new StringBuilder();

            result.AppendLine(ResourceBank.Strings.DescBonus);

            //Pawn has a primary weapon
            if (CompInfused.TryGetInfusedComp(pawn.equipment.Primary, out CompInfused comp))
            {
                result.Append(WriteExplanation(pawn.equipment.Primary, comp));
            }

            //Pawn has apparels
            foreach (var apparel in pawn.apparel.WornApparel)
            {
                if (CompInfused.TryGetInfusedComp(pawn.equipment.Primary, out comp))
                {
                    result.Append(WriteExplanation(apparel, comp));
                }
            }

            return(result.ToString());
        }
Exemplo n.º 2
0
 void TransformValueForThing(StatRequest req, ref float val)
 {
     if (CompInfused.TryGetInfusedComp(req.Thing, out CompInfused inf))
     {
         TransformValue(inf, parentStat, ref val);
     }
 }
Exemplo n.º 3
0
        string WriteExplanation(Thing thing, CompInfused comp)
        {
            var result = new StringBuilder();

            foreach (var infusion in comp.Infusions)
            {
                var mod = infusion.stats.TryGetValue(parentStat);
                if (mod == null)
                {
                    continue;
                }

                if (System.Math.Abs(mod.offset) > 0.001f)
                {
                    result.Append("    " + infusion.label.CapitalizeFirst() + ": ");
                    result.Append(mod.offset > 0 ? "+" : "-");
                    result.AppendLine(parentStat.ValueToString(UnityEngine.Mathf.Abs(mod.offset)));
                }

                if (System.Math.Abs(mod.multiplier - 1f) > 0.001f)
                {
                    result.Append("    " + infusion.label.CapitalizeFirst() + ": x");
                    result.AppendLine(mod.multiplier.ToStringPercent());
                }
            }

            return(result.ToString());
        }
Exemplo n.º 4
0
        void TransformValueForPawn(StatRequest req, ref float val)
        {
            var pawn = req.Thing as Pawn;

            //Just in case
            if (pawn == null)
            {
                return;
            }

            //Pawn has a primary weapon
            if (pawn.equipment.Primary != null)
            {
                if (CompInfused.TryGetInfusedComp(pawn.equipment.Primary, out CompInfused inf))
                {
                    TransformValue(inf, parentStat, ref val);
                }
            }

            //Pawn has apparels
            foreach (var apparel in pawn.apparel.WornApparel)
            {
                if (CompInfused.TryGetInfusedComp(apparel, out CompInfused inf))
                {
                    TransformValue(inf, parentStat, ref val);
                }
            }
        }
        public override void DoEffectOn(Pawn user, Thing target)
        {
            float hp = (float)target.HitPoints / target.MaxHitPoints;

            CompInfused infused = target.TryGetComp <CompInfused>();

            var toTranfer = parent.GetComp <CompInfused>().Infusions.ToList();

            if (toTranfer.NullOrEmpty())
            {
                List <Def> list      = infused.RemoveRandom(Rand.Range(1, Settings.max));
                Thing      amplifier = ThingMaker.MakeThing(ResourceBank.Things.InfusedAmplifier);
                infused = amplifier.TryGetComp <CompInfused>();
                infused.SetInfusions(list);
                amplifier.HitPoints = amplifier.MaxHitPoints;
                GenSpawn.Spawn(amplifier, parent.Position, parent.Map);
            }
            else
            {
                foreach (Def infusion in toTranfer)
                {
                    infused.Attach(infusion);
                }
            }

            target.HitPoints = Mathf.FloorToInt(target.MaxHitPoints * hp);

            infused.ThrowMote();
        }
        static void DrawInfusions(CompInfused comp, Rect view)
        {
            var infusions = comp.Infusions;

            GUI.color = Color.white;
            Text.Font = GameFont.Small;

            float scrollerWidth = view.width - 20.0f;
            float totalHeight   = 0;

            StringBuilder sb = new StringBuilder();

            foreach (var i in comp.Infusions)
            {
                sb.AppendLine(i.DescriptionLabel);
                sb.AppendLine(i.DescriptionStats);
                sb.Append(i.DescriptionExtras);
            }
            totalHeight = Text.CalcHeight(sb.ToString(), scrollerWidth) + 16f * comp.InfusionCount;

            var scroller = new Rect(0.0f, 0.0f, scrollerWidth, totalHeight);

            Widgets.BeginScrollView(view, ref scrollPos, scroller);

            float yOffset = 0f;

            foreach (var i in comp.Infusions)
            {
                yOffset += DrawInfusion(i, scroller, yOffset);
            }

            Widgets.EndScrollView();
        }
        static float DrawQuality(CompInfused comp, Rect view)
        {
            comp.parent.TryGetQuality(out QualityCategory qc);

            GUI.color = Color.white;
            Text.Font = GameFont.Small;

            var subLabelBuilder = new StringBuilder();

            subLabelBuilder.Append(qc.GetLabel().CapitalizeFirst())
            .Append(" ")
            .Append(ResourceBank.Strings.Quality)
            .Append(" ");

            if (comp.parent.Stuff != null)
            {
                subLabelBuilder.Append(comp.parent.Stuff.LabelAsStuff).Append(" ");
            }

            subLabelBuilder.Append(comp.parent.def.label);

            string subLabel = subLabelBuilder.ToString();

            Widgets.Label(view, subLabel);

            return(Text.CalcHeight(subLabel, view.width));
        }
Exemplo n.º 8
0
        string ExplanationPartForThing(StatRequest req)
        {
            if (CompInfused.TryGetInfusedComp(req.Thing, out CompInfused comp))
            {
                return(WriteExplanation(req.Thing, comp));
            }

            return(null);
        }
        static float DrawLabel(CompInfused comp, Rect view)
        {
            string label = comp.InfusedLabel;

            GUI.color = comp.InfusedLabelColor;
            Text.Font = GameFont.Medium;

            Widgets.Label(view, label);

            return(Text.CalcHeight(label, view.width));
        }
Exemplo n.º 10
0
        void TransformValue(CompInfused comp, StatDef stat, ref float val)
        {
            foreach (var infusion in comp.Infusions)
            {
                var statMod = infusion.stats.TryGetValue(stat);
                if (statMod == null)
                {
                    continue;
                }

                val += statMod.offset;
                val *= statMod.multiplier;
            }
        }
Exemplo n.º 11
0
        string ExplanationPartForPawn(StatRequest req)
        {
            //Just in case
            var pawn = req.Thing as Pawn;

            if (pawn == null)
            {
                return(null);
            }

            var result = new StringBuilder();

            //Pawn has a primary weapon
            if ((pawn.equipment != null) && (pawn.equipment.Primary != null))
            {
                if (CompInfused.TryGetInfusedComp(pawn.equipment.Primary, out CompInfused comp))
                {
                    result.Append(WriteExplanation(pawn.equipment.Primary, comp));
                }
            }

            //Pawn has apparels
            if (pawn.apparel != null)
            {
                foreach (var apparel in pawn.apparel.WornApparel)
                {
                    if (CompInfused.TryGetInfusedComp(apparel, out CompInfused comp))
                    {
                        result.Append(WriteExplanation(apparel, comp));
                    }
                }
            }

            if (result.Length > 0)
            {
                return(ResourceBank.Strings.DescBonus + "\n" + result);
            }

            return(null);
        }
Exemplo n.º 12
0
        static void Postfix(Thing thing)
        {
            if (!CompInfused.TryGetInfusedComp(thing, out CompInfused comp))
            {
                return;
            }

            Text.Font   = GameFont.Tiny;
            Text.Anchor = TextAnchor.UpperCenter;
            GUI.color   = comp.InfusedLabelColor;

            string text      = comp.InfusedLabelShort;
            float  x         = Text.CalcSize(text).x;
            var    screenPos = GenMapUI.LabelDrawPosFor(thing, -0.66f);
            var    rect      = new Rect(screenPos.x - x / 2f, screenPos.y - 3f, x, 999f);

            Widgets.Label(rect, text);

            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
            Text.Font   = GameFont.Small;
        }
Exemplo n.º 13
0
 public static bool TryGetInfusedComp(Thing thing, out CompInfused comp)
 {
     comp = thing.TryGetComp <CompInfused>();
     return(comp != null && comp.IsActive);
 }
Exemplo n.º 14
0
 public override bool Matches(Thing t) => CanEverMatch(t.def) && WantsInfused == CompInfused.TryGetInfusedComp(t, out CompInfused comp);