public void PowersSetup() { CompForceUser forcePowers = this.GetComp <CompForceUser>(); if (forcePowers == null) { ThingComp thingComp = (ThingComp)Activator.CreateInstance(typeof(CompForceUser)); thingComp.parent = this; var comps = AccessTools.Field(typeof(ThingWithComps), "comps").GetValue(this); if (comps != null) { ((List <ThingComp>)comps).Add(thingComp); } thingComp.Initialize(null); } forcePowers = this.GetComp <CompForceUser>(); if (forcePowers != null) { forcePowers.AlignmentValue = 0.99f; for (int o = 0; o < 10; o++) { forcePowers.ForceUserLevel += 1; forcePowers.ForceData.Skills.InRandomOrder <ForceSkill>().First((ForceSkill x) => x.level < 4).level++; forcePowers.ForceData.AbilityPoints -= 1; } for (int i = 0; i < 8; i++) { forcePowers.ForceUserLevel += 1; forcePowers.LevelUpPower(forcePowers.ForceData.PowersLight.InRandomOrder <ForcePower>().First((ForcePower x) => x.level < 2)); forcePowers.ForceData.AbilityPoints -= 1; } } }
public static void PowersGUIHandler(Rect inRect, CompForceUser compForce, List <ForcePower> forcePowers, Texture2D pointTexture) { var buttonYOffset = inRect.y; foreach (var power in forcePowers) { var buttonRect = new Rect(inRect.x, buttonYOffset, ForceButtonSize, ForceButtonSize); TooltipHandler.TipRegion(buttonRect, () => power.AbilityDef.label + "\n\n" + power.AbilityDef.description + "\n\n" + "PJ_CheckStarsForMoreInfo".Translate(), 398462); if (compForce.ForceData.AbilityPoints == 0 || power.level >= 3) { Widgets.DrawTextureFitted(buttonRect, power.Icon, 1.0f); } else if (Widgets.ButtonImage(buttonRect, power.Icon) && compForce.AbilityUser.Faction == Faction.OfPlayer) { var powerDef = power.NextLevelAbilityDef as ForceAbilityDef; if (powerDef != null && powerDef.requiredAlignmentType != ForceAlignmentType.None && powerDef.requiredAlignmentType != compForce.ForceAlignmentType) { Messages.Message( "PJ_NextLevelAlignmentMismatch".Translate(powerDef.requiredAlignmentType.ToString(), compForce.ForceAlignmentType.ToString()), MessageTypeDefOf.RejectInput); return; } if (powerDef != null && compForce.LightsidePoints < powerDef.lightsideTreePointsRequired) { Messages.Message("PJ_LightsidePointsRequired".Translate(powerDef.lightsideTreePointsRequired), MessageTypeDefOf.RejectInput); return; } if (powerDef != null && compForce.DarksidePoints < powerDef.darksideTreePointsRequired) { Messages.Message("PJ_DarksidePointsRequired".Translate(powerDef.darksideTreePointsRequired), MessageTypeDefOf.RejectInput); return; } if (powerDef != null && compForce.ForceData.AbilityPoints < powerDef.abilityPoints) { Messages.Message( "PJ_NotEnoughAbilityPoints".Translate(compForce.ForceData.AbilityPoints, powerDef.abilityPoints), MessageTypeDefOf.RejectInput); return; } if (compForce.AbilityUser.story != null && compForce.AbilityUser.WorkTagIsDisabled(WorkTags.Violent) && power.AbilityDef.MainVerb.isViolent) { Messages.Message("IsIncapableOfViolenceLower".Translate(compForce.parent.LabelShort), MessageTypeDefOf.RejectInput); return; } compForce.LevelUpPower(power); if (powerDef != null) { compForce.ForceData.AbilityPoints -= powerDef.abilityPoints; } } for (var i = 0; i < 3; i++) { var drawXOffset = ForceButtonSize + 1f; if (i != 0) { drawXOffset += ForceButtonPointSize * i; } var drawYOffset = buttonYOffset + (ForceButtonSize / 3f); var powerRegion = new Rect(inRect.x + drawXOffset, drawYOffset, ForceButtonPointSize, ForceButtonPointSize); Widgets.DrawTextureFitted(powerRegion, power.level > i ? pointTexture : TexButton.PJTex_ForcePointDim, 1.0f); if (power.GetAbilityDef(i) is ForceAbilityDef powerDef) { TooltipHandler.TipRegion(powerRegion, () => powerDef.GetDescription() + "\n" + compForce.PostAbilityVerbCompDesc(powerDef.MainVerb) + "\n" + powerDef.GetPointDesc(), 398462); } } buttonYOffset += ForceButtonSize + 1; } }