示例#1
0
        private static Gizmo GetMeleeAttackGizmo(Pawn pawn)
        {
            Command_Target command_Target = new Command_Target();

            command_Target.defaultLabel    = "CommandMeleeAttack".Translate();
            command_Target.defaultDesc     = "CommandMeleeAttackDesc".Translate();
            command_Target.targetingParams = TargetingParameters.ForAttackAny();
            command_Target.hotKey          = KeyBindingDefOf.Misc2;
            command_Target.icon            = TexCommand.AttackMelee;
            if (FloatMenuUtility.GetMeleeAttackAction(pawn, LocalTargetInfo.Invalid, out string failStr) == null)
            {
                command_Target.Disable(failStr.CapitalizeFirst() + ".");
            }
            command_Target.action = delegate(Thing target)
            {
                IEnumerable <Pawn> enumerable = Find.Selector.SelectedObjects.Where(delegate(object x)
                {
                    Pawn pawn2 = x as Pawn;
                    return(pawn2 != null && pawn2.IsColonistPlayerControlled && pawn2.Drafted);
                }).Cast <Pawn>();
                foreach (Pawn item in enumerable)
                {
                    FloatMenuUtility.GetMeleeAttackAction(item, target, out string _)?.Invoke();
                }
            };
            return(command_Target);
        }
示例#2
0
        private static Gizmo GetMeleeAttackGizmo(Pawn pawn)
        {
            Command_Target command_Target = new Command_Target();

            command_Target.defaultLabel    = "CommandMeleeAttack".Translate();
            command_Target.defaultDesc     = "CommandMeleeAttackDesc".Translate();
            command_Target.targetingParams = TargetingParameters.ForAttackAny();
            command_Target.hotKey          = KeyBindingDefOf.Misc2;
            command_Target.icon            = TexCommand.AttackMelee;
            if (FloatMenuUtility.GetMeleeAttackAction(pawn, LocalTargetInfo.Invalid, out var failStr) == null)
            {
                command_Target.Disable(failStr.CapitalizeFirst() + ".");
            }
            command_Target.action = delegate(Thing target)
            {
                foreach (Pawn item in Find.Selector.SelectedObjects.Where(delegate(object x)
                {
                    Pawn pawn2 = x as Pawn;
                    return(pawn2 != null && pawn2.IsColonistPlayerControlled && pawn2.Drafted);
                }).Cast <Pawn>())
                {
                    string failStr2;
                    Action meleeAttackAction = FloatMenuUtility.GetMeleeAttackAction(item, target, out failStr2);
                    if (meleeAttackAction != null)
                    {
                        meleeAttackAction();
                    }
                    else if (!failStr2.NullOrEmpty())
                    {
                        Messages.Message(failStr2, target, MessageTypeDefOf.RejectInput, historical: false);
                    }
                }
            };
            return(command_Target);
        }
示例#3
0
 public static Action GetAttackAction(Pawn pawn, LocalTargetInfo target, out string failStr)
 {
     if (pawn.equipment.Primary != null && !pawn.equipment.PrimaryEq.PrimaryVerb.verbProps.IsMeleeAttack)
     {
         return(FloatMenuUtility.GetRangedAttackAction(pawn, target, out failStr));
     }
     return(FloatMenuUtility.GetMeleeAttackAction(pawn, target, out failStr));
 }
        private static void <GetMeleeAttackGizmo> m__1(Thing target)
        {
            IEnumerable <Pawn> enumerable = Find.Selector.SelectedObjects.Where(delegate(object x)
            {
                Pawn pawn2 = x as Pawn;
                return(pawn2 != null && pawn2.IsColonistPlayerControlled && pawn2.Drafted);
            }).Cast <Pawn>();

            foreach (Pawn pawn in enumerable)
            {
                string text;
                Action meleeAttackAction = FloatMenuUtility.GetMeleeAttackAction(pawn, target, out text);
                if (meleeAttackAction != null)
                {
                    meleeAttackAction();
                }
            }
        }
示例#5
0
        private static void AddDraftedOrders(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts)
        {
            IntVec3 clickCell = IntVec3.FromVector3(clickPos);

            foreach (LocalTargetInfo item in GenUI.TargetsAt(clickPos, TargetingParameters.ForAttackHostile(), true))
            {
                LocalTargetInfo attackTarg = item;
                if (pawn.equipment.Primary != null && !pawn.equipment.PrimaryEq.PrimaryVerb.verbProps.MeleeRange)
                {
                    string          str             = default(string);
                    Action          rangedAct       = FloatMenuUtility.GetRangedAttackAction(pawn, attackTarg, out str);
                    string          text            = "FireAt".Translate(attackTarg.Thing.Label);
                    FloatMenuOption floatMenuOption = new FloatMenuOption(MenuOptionPriority.High);
                    if (rangedAct == null)
                    {
                        text = text + " (" + str + ")";
                    }
                    else
                    {
                        floatMenuOption.autoTakeable = true;
                        floatMenuOption.action       = delegate
                        {
                            MoteMaker.MakeStaticMote(attackTarg.Thing.DrawPos, attackTarg.Thing.Map, ThingDefOf.Mote_FeedbackAttack, 1f);
                            rangedAct();
                        };
                    }
                    floatMenuOption.Label = text;
                    opts.Add(floatMenuOption);
                }
                string             str2               = default(string);
                Action             meleeAct           = FloatMenuUtility.GetMeleeAttackAction(pawn, attackTarg, out str2);
                Pawn               pawn2              = attackTarg.Thing as Pawn;
                string             text2              = (pawn2 == null || !pawn2.Downed) ? "MeleeAttack".Translate(attackTarg.Thing.Label) : "MeleeAttackToDeath".Translate(attackTarg.Thing.Label);
                MenuOptionPriority menuOptionPriority = (MenuOptionPriority)((!attackTarg.HasThing || !pawn.HostileTo(attackTarg.Thing)) ? 1 : 6);
                string             empty              = string.Empty;
                Action             action             = null;
                MenuOptionPriority priority           = menuOptionPriority;
                Thing              thing              = attackTarg.Thing;
                FloatMenuOption    floatMenuOption2   = new FloatMenuOption(empty, action, priority, null, thing, 0f, null, null);
                if (meleeAct == null)
                {
                    text2 = text2 + " (" + str2 + ")";
                }
                else
                {
                    floatMenuOption2.action = delegate
                    {
                        MoteMaker.MakeStaticMote(attackTarg.Thing.DrawPos, attackTarg.Thing.Map, ThingDefOf.Mote_FeedbackAttack, 1f);
                        meleeAct();
                    };
                }
                floatMenuOption2.Label = text2;
                opts.Add(floatMenuOption2);
            }
            if (pawn.RaceProps.Humanlike && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                foreach (LocalTargetInfo item2 in GenUI.TargetsAt(clickPos, TargetingParameters.ForArrest(pawn), true))
                {
                    LocalTargetInfo dest = item2;
                    if (!pawn.CanReach(dest, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn))
                    {
                        opts.Add(new FloatMenuOption("CannotArrest".Translate() + " (" + "NoPath".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                    else
                    {
                        Pawn   pTarg   = (Pawn)dest.Thing;
                        Action action2 = delegate
                        {
                            Building_Bed building_Bed = RestUtility.FindBedFor(pTarg, pawn, true, false, false);
                            if (building_Bed == null)
                            {
                                building_Bed = RestUtility.FindBedFor(pTarg, pawn, true, false, true);
                            }
                            if (building_Bed == null)
                            {
                                Messages.Message("CannotArrest".Translate() + ": " + "NoPrisonerBed".Translate(), pTarg, MessageTypeDefOf.RejectInput);
                            }
                            else
                            {
                                Job job = new Job(JobDefOf.Arrest, pTarg, building_Bed);
                                job.count = 1;
                                pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                                TutorUtility.DoModalDialogIfNotKnown(ConceptDefOf.ArrestingCreatesEnemies);
                            }
                        };
                        string             empty    = "TryToArrest".Translate(dest.Thing.LabelCap);
                        Action             action   = action2;
                        MenuOptionPriority priority = MenuOptionPriority.High;
                        Thing thing = dest.Thing;
                        opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(empty, action, priority, null, thing, 0f, null, null), pawn, pTarg, "ReservedBy"));
                    }
                }
            }
            FloatMenuOption floatMenuOption3 = FloatMenuMakerMap.GotoLocationOption(clickCell, pawn);

            if (floatMenuOption3 != null)
            {
                opts.Add(floatMenuOption3);
            }
        }