Example #1
0
        public static bool ShotCalculationTipStringPrefix(ref string __result, Thing target)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (Find.Selector.SingleSelectedThing != null)
            {
                Thing singleSelectedThing = Find.Selector.SingleSelectedThing;
                Verb  verb = null;
                if (singleSelectedThing is Pawn pawn && pawn != target && pawn.equipment != null && pawn.equipment.Primary != null)
                {
                    Comp_VerbSaveable compsav = pawn.equipment.Primary.GetComp <Comp_VerbSaveable>();
                    if (compsav != null && compsav.tempVerb != null && compsav.tempVerb is Verb_LaunchProjectile)
                    {
                        verb = compsav.tempVerb;
                    }
                    else
                    {
                        verb = pawn.equipment.PrimaryEq.PrimaryVerb;
                    }
                }
                if (singleSelectedThing is Building_TurretGun building_TurretGun && building_TurretGun != target)
                {
                    verb = building_TurretGun.AttackVerb;
                }
                if (verb != null)
                {
                    stringBuilder.Append("ShotBy".Translate(Find.Selector.SingleSelectedThing.LabelShort, Find.Selector.SingleSelectedThing) + ": ");
                    if (verb.CanHitTarget(target))
                    {
                        stringBuilder.Append(ShotReport.HitReportFor(verb.caster, verb, target).GetTextReadout());
                    }
                    else
                    {
                        stringBuilder.AppendLine("CannotHit".Translate());
                    }
                    if (target is Pawn pawn2 && pawn2.Faction == null && !pawn2.InAggroMentalState)
                    {
                        float manhunterOnDamageChance;
                        if (verb.IsMeleeAttack)
                        {
                            manhunterOnDamageChance = PawnUtility.GetManhunterOnDamageChance(pawn2, 0f, singleSelectedThing);
                        }
                        else
                        {
                            manhunterOnDamageChance = PawnUtility.GetManhunterOnDamageChance(pawn2, singleSelectedThing);
                        }
                        if (manhunterOnDamageChance > 0f)
                        {
                            stringBuilder.AppendLine();
                            stringBuilder.AppendLine(string.Format("{0}: {1}", "ManhunterPerHit".Translate(), manhunterOnDamageChance.ToStringPercent()));
                        }
                    }
                }
            }
            __result = stringBuilder.ToString();
            return(false);
        }
Example #2
0
        public static bool PrimaryVerbPrefix(CompEquippable __instance, ref Verb __result)
        {
            //Comp_VerbSaveable comp = ((CompEquippable)(__instance.directOwner)).parent.GetComp<Comp_VerbSaveable>();//VerbTracker
            Comp_VerbSaveable comp = __instance.parent.GetComp <Comp_VerbSaveable>();

            if (comp != null)
            {
                __result = comp.currentVerb;
                if (__result != null)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #3
0
 public static void BeginTargetingPrefix(ITargetingSource source)
 {
     if (!(source is Verb verb))
     {
         return;
     }
     if (verb.verbTracker != null && verb.verbTracker.directOwner != null && verb.DirectOwner is CompEquippable equippable)
     {
         Comp_VerbSaveable comp = equippable.parent.GetComp <Comp_VerbSaveable>();
         if (comp != null)
         {
             comp.tempVerb = verb;
         }
     }
 }
Example #4
0
 public static void StopTargetingPrefix(Verb ___targetingSource)
 {
     if (!(___targetingSource is Verb verb))
     {
         return;
     }
     if (verb.verbTracker != null && verb.verbTracker.directOwner != null)
     {
         if (verb.DirectOwner is CompEquippable compEquip && compEquip.parent != null)
         {
             Comp_VerbSaveable compVerbSave = compEquip.parent.GetComp <Comp_VerbSaveable>();
             if (compVerbSave != null)
             {
                 compVerbSave.tempVerb = null;
             }
         }
     }
 }
Example #5
0
 public static void OrderPawnForceTargetPostfix(Targeter __instance, ITargetingSource targetingSource)
 {
     if (!(targetingSource is Verb verb))
     {
         return;
     }
     if (verb.verbTracker != null && verb.verbTracker.directOwner != null && verb.DirectOwner is CompEquippable equippable)
     {
         Comp_VerbSaveable comp = equippable.parent.GetComp <Comp_VerbSaveable>();
         if (comp != null)
         {
             if (!Traverse.Create(__instance).Method("CurrentTargetUnderMouse", true).GetValue <LocalTargetInfo>().IsValid)
             {
                 return;
             }
             comp.currentVerb = verb;
         }
     }
 }
Example #6
0
        /*public static void GizmoOnGUIPostfix(ref GizmoResult __result, Vector2 topLeft, float maxWidth, Command_VerbTarget __instance)
         * {
         *  Text.Font = GameFont.Tiny;
         *  Rect rect = new Rect(topLeft.x, topLeft.y, __instance.GetWidth(maxWidth), 75f);
         *
         *  if (((Verb_Shoot_Cooldown)__instance.verb).RemainingProgressBeforeFire() != 0)
         *  {
         *      Widgets.FillableBar(rect,
         *          ((Verb_Shoot_Cooldown)__instance.verb).RemainingProgressBeforeFire(),
         *          ((VerbProperties_Custom)((Verb_Shoot_Cooldown)__instance.verb).verbProps).texture,
         *          ((VerbProperties_Custom)((Verb_Shoot_Cooldown)__instance.verb).verbProps).textureCooldown,
         *          false
         *          );
         *  }
         *
         *  bool flag = false;
         *  if (Mouse.IsOver(rect))
         *  {
         *      flag = true;
         *      if (!__instance.disabled)
         *      {
         *          GUI.color = GenUI.MouseoverColor;
         *      }
         *  }
         *  Texture2D badTex = __instance.icon;
         *  if (badTex == null)
         *  {
         *      badTex = BaseContent.BadTex;
         *  }
         *  Material material = (!__instance.disabled) ? null : TexUI.GrayscaleGUI;
         *  GenUI.DrawTextureWithMaterial(rect, Command.BGTex, material, default(Rect));
         *  MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Command);
         *  Rect outerRect = rect;
         *  outerRect.position += new Vector2(__instance.iconOffset.x * outerRect.size.x, __instance.iconOffset.y * outerRect.size.y);
         *  GUI.color = __instance.IconDrawColor;
         *  Widgets.DrawTextureFitted(outerRect, badTex, __instance.iconDrawScale * 0.85f, __instance.iconProportions, __instance.iconTexCoords, __instance.iconAngle, material);
         *  GUI.color = Color.white;
         *  bool flag2 = false;
         *  KeyCode keyCode = (__instance.hotKey != null) ? __instance.hotKey.MainKey : KeyCode.None;
         *  if (keyCode != KeyCode.None && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
         *  {
         *      Rect rect2 = new Rect(rect.x + 5f, rect.y + 5f, rect.width - 10f, 18f);
         *      Widgets.Label(rect2, keyCode.ToStringReadable());
         *      GizmoGridDrawer.drawnHotKeys.Add(keyCode);
         *      if (__instance.hotKey.KeyDownEvent)
         *      {
         *          flag2 = true;
         *          Event.current.Use();
         *      }
         *  }
         *  if (Widgets.ButtonInvisible(rect, false))
         *  {
         *      flag2 = true;
         *  }
         *  string labelCap = __instance.LabelCap;
         *  if (!labelCap.NullOrEmpty())
         *  {
         *      float num = Text.CalcHeight(labelCap, rect.width);
         *      Rect rect3 = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num);
         *      GUI.DrawTexture(rect3, TexUI.GrayTextBG);
         *      GUI.color = Color.white;
         *      Text.Anchor = TextAnchor.UpperCenter;
         *      Widgets.Label(rect3, labelCap);
         *      Text.Anchor = TextAnchor.UpperLeft;
         *      GUI.color = Color.white;
         *  }
         *  GUI.color = Color.white;
         *  if (true)
         *  {
         *      TipSignal tip = __instance.Desc;
         *      if (__instance.disabled && !__instance.disabledReason.NullOrEmpty())
         *      {
         *          string text = tip.text;
         *          tip.text = string.Concat(new string[]
         *          {
         *              text,
         *              "\n\n",
         *              "DisabledCommand".Translate(),
         *              ": ",
         *              __instance.disabledReason
         *          });
         *      }
         *      TooltipHandler.TipRegion(rect, tip);
         *  }
         *  if (!__instance.HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null || !Find.WindowStack.FloatMenu.windowRect.Overlaps(rect)))
         *  {
         *      UIHighlighter.HighlightOpportunity(rect, __instance.HighlightTag);
         *  }
         *  Text.Font = GameFont.Small;
         *  if (flag2)
         *  {
         *      if (__instance.disabled)
         *      {
         *          if (!__instance.disabledReason.NullOrEmpty())
         *          {
         *              Messages.Message(__instance.disabledReason, MessageTypeDefOf.RejectInput, false);
         *          }
         *          __result = new GizmoResult(GizmoState.Mouseover, null);
         *          return;
         *      }
         *      GizmoResult result;
         *      if (Event.current.button == 1)
         *      {
         *          result = new GizmoResult(GizmoState.OpenedFloatMenu, Event.current);
         *      }
         *      else
         *      {
         *          if (!TutorSystem.AllowAction(__instance.TutorTagSelect))
         *          {
         *              __result = new GizmoResult(GizmoState.Mouseover, null);
         *              return;
         *          }
         *          result = new GizmoResult(GizmoState.Interacted, Event.current);
         *          TutorSystem.Notify_Event(__instance.TutorTagSelect);
         *      }
         *      __result = result;
         *      return;
         *  }
         *  else
         *  {
         *      if (flag)
         *      {
         *          __result = new GizmoResult(GizmoState.Mouseover, null);
         *          return;
         *      }
         *      __result = new GizmoResult(GizmoState.Clear, null);
         *      return;
         *  }
         * }
         *
         * public static void GizmoOnGUIPostfix(ref GizmoResult __result, Command_VerbTarget __instance, Vector2 topLeft, float maxWidth)
         * {
         *  GizmoOnGUIPostfixPRE(ref __result, __instance, topLeft, maxWidth);
         *
         *  var rect = new Rect(topLeft.x, topLeft.y, __instance.GetWidth(maxWidth), 75f);
         *  if (((Verb_Shoot_Cooldown)__instance.verb).RemainingProgressBeforeFire() != 0)
         *  {
         *      Widgets.FillableBar(rect,
         *          ((Verb_Shoot_Cooldown)__instance.verb).RemainingProgressBeforeFire(),
         *          ((VerbProperties_Custom)((Verb_Shoot_Cooldown)__instance.verb).verbProps).texture,
         *          ((VerbProperties_Custom)((Verb_Shoot_Cooldown)__instance.verb).verbProps).textureCooldown,
         *          false
         *          );
         *  }
         * }*/

        public static bool CreateVerbTargetCommandPrefix(ref Command_VerbTarget __result, Thing ownerThing, Verb verb)
        {
            Command_VerbTarget    command_VerbTarget = new Command_VerbTarget();
            VerbProperties_Custom verbProps          = verb.verbProps as VerbProperties_Custom;
            Verb_Shoot_Cooldown   verb_with_cooldown = verb is Verb_Shoot_Cooldown ? verb as Verb_Shoot_Cooldown : null;

            if (verbProps != null)
            {
                command_VerbTarget.defaultDesc  = verbProps.desc;
                command_VerbTarget.defaultLabel = verbProps.label;
                Comp_VerbSaveable comp_VerbSaveable = ownerThing.TryGetComp <Comp_VerbSaveable>();
                if (!verbProps.disable)
                {
                    if (verb_with_cooldown != null)
                    {
                        if (!verb_with_cooldown.CanFire())
                        {
                            command_VerbTarget.Disable("Magnuassembly_AdditionalVerbPatch_CooldownDisableReason".Translate(
                                                           FormattingTickTime(verb_with_cooldown.RemainingTickBeforeFire() / 60.0D)
                                                           )
                                                       );
                        }
                        else
                        {
                            command_VerbTarget.disabled = false;
                        }
                    }
                }
                if (comp_VerbSaveable != null && comp_VerbSaveable.currentVerb == verb)
                {
                    command_VerbTarget.icon = verb_with_cooldown != null?
                                              FloodingTexture(
                        verbProps.textureSelected,
                        verb_with_cooldown.RemainingProgressBeforeFire()
                        ) : verbProps.textureSelected;

                    if (command_VerbTarget.disabled && verb_with_cooldown != null)
                    {
                        comp_VerbSaveable.SwitchVerb(verbProps.redirectVerbAfterShoot);
                    }
                }
                else
                {
                    command_VerbTarget.icon = verb_with_cooldown != null?
                                              FloodingTexture(
                        verbProps.texture,
                        verb_with_cooldown.RemainingProgressBeforeFire()
                        ) : verbProps.texture;
                }
            }
            else
            {
                command_VerbTarget.icon        = ownerThing.def.uiIcon;
                command_VerbTarget.defaultDesc = ownerThing.LabelCap + ": " + ownerThing.def.description.CapitalizeFirst();
            }
            command_VerbTarget.iconAngle  = ownerThing.def.uiIconAngle;
            command_VerbTarget.iconOffset = ownerThing.def.uiIconOffset;
            command_VerbTarget.tutorTag   = "VerbTarget";
            command_VerbTarget.verb       = verb;
            bool disableReasonOverwrite = false;

            if (verb.caster.Faction == Faction.OfPlayer)
            {
                if (verb.CasterIsPawn)
                {
                    if (verb.CasterPawn.WorkTagIsDisabled(WorkTags.Violent))
                    {
                        command_VerbTarget.Disable("IsIncapableOfViolence".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn));
                        disableReasonOverwrite = true;
                    }
                    else if (!verb.CasterPawn.drafter.Drafted)
                    {
                        command_VerbTarget.Disable("IsNotDrafted".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn));
                        disableReasonOverwrite = true;
                    }
                }
            }
            else
            {
                command_VerbTarget.Disable("CannotOrderNonControlled".Translate());
                disableReasonOverwrite = true;
            }
            if (disableReasonOverwrite)
            {
                if (verbProps != null && verbProps.disable)
                {
                    command_VerbTarget.disabledReason = verbProps.disableReason + "\n" + command_VerbTarget.disabledReason;
                }
                else if (verb_with_cooldown != null && !verb_with_cooldown.CanFire())
                {
                    command_VerbTarget.disabledReason =
                        "Magnuassembly_AdditionalVerbPatch_CooldownDisableReason".Translate(
                            FormattingTickTime(verb_with_cooldown.RemainingTickBeforeFire() / 60.0D)
                            ) + "\n" + command_VerbTarget.disabledReason;
                }
            }
            else if (verbProps != null && verbProps.disable)
            {
                command_VerbTarget.Disable(verbProps.disableReason);
            }
            __result = command_VerbTarget;
            return(false);
        }