Exemplo n.º 1
0
        public static void CheckForAutoAttack(JobDriver jobDriver)
        {
            List <Hediff> hediffs = jobDriver.pawn.health.hediffSet.hediffs;

            foreach (Hediff hediff in hediffs)
            {
                HediffComp_VerbGiverExtended verbGiverExtended = hediff.TryGetComp <HediffComp_VerbGiverExtended>();
                if (verbGiverExtended != null) // for each comp that gives verbs do this:
                {
                    List <Verb> allVerbs = new List <Verb>(verbGiverExtended.AllVerbs.SkipWhile((Verb verb) => verb is Verb_CastPsycast));
                    int         radVerb  = Random.Range(0, allVerbs.Count);
                    if (allVerbs[radVerb] != null && verbGiverExtended.canAutoAttack && verbGiverExtended.canAttack) // take a random verb that can attack
                    {
                        TargetScanFlags targetScanFlags = TargetScanFlags.NeedLOSToPawns | TargetScanFlags.NeedLOSToNonPawns | TargetScanFlags.NeedThreat;
                        if (allVerbs[radVerb].IsIncendiary())
                        {
                            targetScanFlags |= TargetScanFlags.NeedNonBurning;
                        }
                        // find best thing to attack
                        Thing thing = (Thing)PCF_AttackTargetFinder.BestShootTargetFromCurrentPosition(jobDriver.pawn, allVerbs[radVerb], targetScanFlags, null, 0f, 9999f);
                        if (thing != null && !allVerbs[radVerb].IsMeleeAttack) // attack (weird shit inbetween)
                        {
                            verbGiverExtended.rangedVerbWarmupTime = allVerbs[radVerb].verbProps.warmupTime;
                            allVerbs[radVerb].verbProps.warmupTime = 0f;
                            allVerbs[radVerb].TryStartCastOn(thing, false, true);
                            allVerbs[radVerb].verbProps.warmupTime = verbGiverExtended.rangedVerbWarmupTime;
                        }
                    }
                    verbGiverExtended.canAttack = false;
                }
            }
        }
Exemplo n.º 2
0
        public static void CheckForAutoAttack(JobDriver jobDriver)
        {
            List <Hediff> hediffs = jobDriver.pawn.health.hediffSet.hediffs;
            int           hediff  = hediffs.Count;

            for (int i = 0; i < hediff; i++)
            {
                HediffComp_VerbGiverExtended verbGiverExtended = hediffs[i].TryGetComp <HediffComp_VerbGiverExtended>();
                if (verbGiverExtended != null)
                {
                    List <Verb> allVerbs = verbGiverExtended.AllVerbs;
                    int         radVerb  = Random.Range(0, allVerbs.Count);
                    if (allVerbs[radVerb] != null && verbGiverExtended.canAutoAttack && verbGiverExtended.canAttack)
                    {
                        TargetScanFlags targetScanFlags = TargetScanFlags.NeedLOSToPawns | TargetScanFlags.NeedLOSToNonPawns | TargetScanFlags.NeedThreat;
                        if (allVerbs[radVerb].IsIncendiary())
                        {
                            targetScanFlags |= TargetScanFlags.NeedNonBurning;
                        }
                        Thing thing = (Thing)PCF_AttackTargetFinder.BestShootTargetFromCurrentPosition(jobDriver.pawn, allVerbs[radVerb], targetScanFlags, null, 0f, 9999f);
                        if (thing != null && !allVerbs[radVerb].IsMeleeAttack)
                        {
                            verbGiverExtended.rangedVerbWarmupTime = allVerbs[radVerb].verbProps.warmupTime;
                            allVerbs[radVerb].verbProps.warmupTime = 0f;
                            allVerbs[radVerb].TryStartCastOn(thing, false, true);
                            allVerbs[radVerb].verbProps.warmupTime = verbGiverExtended.rangedVerbWarmupTime;
                        }
                    }
                    verbGiverExtended.canAttack = false;
                }
            }
        }
Exemplo n.º 3
0
            private static void HediffVerbGiverExtended(ref IEnumerable <Gizmo> __result, Pawn pawn)
            {
                List <Gizmo> gizmos = new List <Gizmo>(__result);

                if (pawn.Drafted)
                {
                    List <Hediff> hediffs = pawn.health.hediffSet.hediffs;
                    for (int i = 0; i < hediffs.Count; i++)
                    {
                        HediffComp_VerbGiverExtended verbGiverExtended = hediffs[i].TryGetComp <HediffComp_VerbGiverExtended>();
                        if (verbGiverExtended != null)
                        {
                            foreach (Verb verb in verbGiverExtended.AllVerbs.Where(verbs => verbs.IsMeleeAttack))
                            {
                                foreach (PCF_VerbProperties verbProperties in verbGiverExtended.Props.verbsProperties)
                                {
                                    if (verb.verbProps.label == verbProperties.label)
                                    {
                                        Command_HediffVerbMelee command_HediffVerbMelee = new Command_HediffVerbMelee
                                        {
                                            verb         = verb,
                                            defaultLabel = verbProperties.label,
                                            defaultDesc  = verbProperties.description.CapitalizeFirst(),
                                            icon         = PCF_VanillaExtender.GetIcon(verbGiverExtended.Pawn.GetUniqueLoadID() + "_" + verb.loadID, verbProperties.uiIconPath),
                                            iconAngle    = verbProperties.uiIconAngle,
                                            iconOffset   = verbProperties.uiIconOffset
                                        };
                                        if (pawn.Faction != Faction.OfPlayer)
                                        {
                                            command_HediffVerbMelee.Disable("CannotOrderNonControlledLower".Translate());
                                        }
                                        else if (pawn.IsColonist)
                                        {
                                            if (pawn.story.WorkTagIsDisabled(WorkTags.Violent))
                                            {
                                                command_HediffVerbMelee.Disable("IsIncapableOfViolenceLower".Translate(pawn.LabelShort, pawn));
                                            }
                                        }
                                        gizmos.Add(command_HediffVerbMelee);
                                    }
                                }
                            }
                        }
                    }
                }
                __result = gizmos;
            }