Пример #1
0
        private IEnumerable <Pawn> PawnsCantShootWeapon()
        {
            List <Pawn> allMaps_FreeColonistsSpawned = PawnsFinder.AllMaps_FreeColonistsSpawned.ToList();

            for (int i = 0; i < allMaps_FreeColonistsSpawned.Count; i++)
            {
                Pawn pawn = allMaps_FreeColonistsSpawned[i];
                if (pawn.equipment.Primary != null)
                {
                    CompWeaponAvali compWeaponAvali = pawn.equipment.Primary.GetComp <CompWeaponAvali>();
                    if (compWeaponAvali == null)
                    {
                        yield break;
                    }
                    if (compWeaponAvali.ownerPawn == null)
                    {
                        yield break;
                    }

                    if (compWeaponAvali.currentBindMode == CompWeaponAvali.bindMode.OwnerPawnOnly.ToString() && pawn != compWeaponAvali.ownerPawn)
                    {
                        yield return(pawn);
                    }
                    else if (compWeaponAvali.currentBindMode == CompWeaponAvali.bindMode.AnyPawnInFaction.ToString() && pawn.Faction != compWeaponAvali.ownerPawn.Faction)
                    {
                        yield return(pawn);
                    }
                }
            }
            yield break;
        }
Пример #2
0
        public override bool Available()         // updates every tick if pawn drafted
        {
            //Log.Message(base.caster + " test.");

            if (base.CasterPawn == null)
            {
                return(base.Available());
            }

            compWeaponAvali = this.EquipmentSource.TryGetComp <CompWeaponAvali>();
            if (compWeaponAvali == null)
            {
                Log.Error(ownerPawn + ": CompWeaponAvali is required for Verb_ShootBinded");
                return(false);
            }

            /*
             * if (compWeaponAvali.ownerPawn == null && base.CasterPawn.IsColonist && base.CasterPawn.Drafted)
             * {
             *      return base.Available();
             * }
             */

            if (ownerPawn == null)
            {
                ownerPawn = compWeaponAvali.ownerPawn;
                if (ownerPawn == null)
                {
                    ownerPawn = base.CasterPawn;
                    compWeaponAvali.ownerPawn = base.CasterPawn;
                }
            }
            else if (compWeaponAvali.ownerPawn == null)
            {
                ownerPawn = base.CasterPawn;
                compWeaponAvali.ownerPawn = base.CasterPawn;
            }
            //Log.Message("Verb_ShootBinded ownerPawn: " + ownerPawn);

            if (ownerPawn != null)
            {
                currentBindMode = compWeaponAvali.currentBindMode;
                if (currentBindMode == CompWeaponAvali.bindMode.AnyPawnInFaction.ToString())
                {
                    if (ownerPawn.Faction != base.CasterPawn.Faction)
                    {
                        return(false);
                    }
                }
                else if (currentBindMode == CompWeaponAvali.bindMode.OwnerPawnOnly.ToString())
                {
                    if (ownerPawn != base.CasterPawn)
                    {
                        return(false);
                    }
                }
            }

            return(base.Available());
        }
Пример #3
0
        public static void GetInspectStringPostfix(ref Pawn __instance, ref string __result)
        {
            if (__instance.IsColonist == false)
            {
                return;
            }

            ThingWithComps equipedWeapon = __instance.equipment.Primary;

            if (equipedWeapon != null)
            {
                CompWeaponAvali compWeaponAvali = equipedWeapon.GetComp <CompWeaponAvali>();
                if (compWeaponAvali == null)
                {
                    return;
                }

                if (compWeaponAvali.ownerPawn != null)
                {
                    __result = __result + "\n" + "EquipedWeaponOwnerPawn".Translate() + compWeaponAvali.ownerPawn.Name;
                }
                else
                {
                    __result = __result + "\n" + "EquipedWeaponOwnerPawn".Translate() + "None".Translate();
                }
            }
        }
Пример #4
0
        public override void PostSplitOff(Thing piece)
        {
            CompWeaponAvali comp = ((ThingWithComps)piece).GetComp <CompWeaponAvali>();

            comp.currentBindMode = currentBindMode;
            comp.workLeft        = workLeft;
            comp.ownerPawn       = ownerPawn;
        }
Пример #5
0
        public static void GetVerbsCommandsPostfix(ref VerbTracker __instance, ref IEnumerable <Command> __result)
        {
            CompEquippable compEquippable = __instance.directOwner as CompEquippable;

            if (compEquippable == null)
            {
                return;
            }

            Thing thing = compEquippable.parent;

            CompWeaponAvali compWeaponAvali = null;

            //Log.Message("thing: " + thing);

            if (thing != null)
            {
                compWeaponAvali = thing.TryGetComp <CompWeaponAvali>();
            }
            if (compWeaponAvali == null)
            {
                return;
            }

            string currentBindMode = compWeaponAvali.currentBindMode;
            //Log.Message("currentBindMode: " + currentBindMode);
            bool   isDisabled       = false;
            string isDisabledReason = "CannotOrderNonControlled".Translate();

            Pawn holderPawn = compEquippable.PrimaryVerb.CasterPawn;

            //Log.Message("ownerPawn: " + ownerPawn);
            if (holderPawn == null || holderPawn.IsColonist == false)
            {
                return;
            }

            if (!holderPawn.Awake())
            {
                isDisabled       = true;
                isDisabledReason = string.Format("NotAwake".Translate(), holderPawn.LabelShort.CapitalizeFirst());
            }
            else if (compWeaponAvali.ownerPawn != null && holderPawn != compWeaponAvali.ownerPawn)
            {
                if (currentBindMode == CompWeaponAvali.bindMode.OwnerPawnOnly.ToString() ||
                    currentBindMode == CompWeaponAvali.bindMode.AnyPawnInFaction.ToString())
                {
                    isDisabled       = true;
                    isDisabledReason = "OwnerNotCasterPawn".Translate();
                }
            }
            else if (holderPawn.Drafted)
            {
                isDisabled       = true;
                isDisabledReason = string.Format("ShouldBeUndrafted".Translate(), holderPawn.LabelShort.CapitalizeFirst());
            }
            //Log.Message("isDisabled: " + isDisabled);

            List <Command> result = __result.ToList();

            /*result.Add(new Command_Action
             * {
             *      action = delegate
             *      {
             *              compWeaponAvali.ChangeBindMode();
             *      },
             *      disabled = isDisabled,
             *      disabledReason = isDisabledReason,
             *      //defaultLabel = ("BindMode_" + currentBindMode).Translate(),
             *      defaultDesc = ("BindMode_" + currentBindMode + "Desc").Translate(),
             *      icon = ContentFinder<Texture2D>.Get("UI/Commands/" + "BindMode_" + currentBindMode, true),
             *      hotKey = KeyBindingDefOf.Misc4
             * });*/
            result.Add(new Command_Action
            {
                action = delegate
                {
                    compWeaponAvali.EraseOwnerPawnInfo();
                },
                disabled       = isDisabled,
                disabledReason = isDisabledReason,
                //defaultLabel = "EraseOwnerPawnInfo".Translate(),
                defaultDesc = "EraseOwnerPawnInfoDesc".Translate(),
                icon        = ContentFinder <Texture2D> .Get("UI/Commands/EraseOwnerPawnInfo", true),
                hotKey      = KeyBindingDefOf.Misc5
            });

            List <Verb> verbs = __instance.AllVerbs;

            for (int i = 0; i < verbs.Count; i++)
            {
                Verb verb = verbs[i];
                if (verb.verbProps.hasStandardCommand)
                {
                    __result = result;
                }
            }
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            if (thing == null || building == null)
            {
                pawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
            }

            bool err   = false;
            Toil error = Toils_General.Do(delegate
            {
                Log.Error("Error in Toils_Haul.PlaceHauledThingInCell. Breaking job.");
                Log.Error("thingInd = " + thingInd);
                Log.Error("buildingInd = " + buildingInd);
                Log.Error("buildingCellInd = " + buildingCellInd);

                err = false;
            });

            CompProperties_WeaponAvali weaponAvali = thing.TryGetComp <CompWeaponAvali>().Props;

            if (weaponAvali != null)
            {
                float           num             = 0;
                CompWeaponAvali compWeaponAvali = thing.TryGetComp <CompWeaponAvali>();
                if (building != null && building.GetStatValue(StatDefOf.ResearchSpeedFactor, true) > 0)
                {
                    num  = 1.1f * pawn.GetStatValue(StatDefOf.ResearchSpeed, true);    // 1.1 * 0.58 = 0.638
                    num *= building.GetStatValue(StatDefOf.ResearchSpeedFactor, true); // 0.638 * 1 = 0.638
                    ticksPerWorkPoint = ticksPerWorkPoint / num;                       // 60 / 0.638 = 94
                    if (ticksPerWorkPoint > 1 && pawn.def == ThingDefOf.Avali)
                    {
                        ticksPerWorkPoint = ticksPerWorkPoint / 2;
                    }
                }
                else if (weaponAvali.hackWorkSkill != null)
                {
                    num = (pawn.skills.GetSkill(weaponAvali.hackWorkSkill).Level - weaponAvali.hackMinSkillLevel) * 2;

                    if (ticksPerWorkPoint - num > 0)
                    {
                        ticksPerWorkPoint = ticksPerWorkPoint - num;
                    }
                    else
                    {
                        ticksPerWorkPoint = 1;
                    }
                }

                //Log.Message("num = " + num);
                //Log.Message("ticksPerWorkPoint = " + ticksPerWorkPoint);
                //Log.Message("workLeft = " + compWeaponAvali.workLeft);

                yield return(Toils_Goto.GotoThing(thingInd, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(thingInd).FailOnSomeonePhysicallyInteracting(thingInd));

                yield return(Toils_Haul.StartCarryThing(thingInd, false, false, false));

                yield return(Toils_Misc.SetForbidden(thingInd, false));

                yield return(Toils_Goto.GotoThing(buildingInd, PathEndMode.InteractionCell).FailOnDestroyedOrNull(buildingInd));

                yield return(Toils_Haul.PlaceHauledThingInCell(buildingCellInd, Toils_Jump.Jump(error), false));

                //IntVec3 thingPosition = thing.PositionHeld;
                //IntVec3 buildingPosition = building.PositionHeld;

                float workLeftInTicks = compWeaponAvali.workLeft * (ticksPerWorkPoint * 1.1f);
                Toil  translate       = Toils_General.Wait((int)workLeftInTicks);
                translate.tickAction = delegate
                {
                    this.FailOnDespawnedOrNull(thingInd);
                    this.FailOnForbidden(thingInd);

                    this.FailOnDespawnedOrNull(buildingInd);
                    this.FailOnForbidden(buildingInd);

                    //else if (thing.PositionHeld != thingPosition || building.PositionHeld != buildingPosition) pawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    //else if (thing.IsForbidden(pawn)) pawn.jobs.EndCurrentJob(JobCondition.InterruptForced);

                    pawn.skills.Learn(weaponAvali.hackWorkSkill, 0.11f, false);
                    pawn.GainComfortFromCellIfPossible();

                    if (pawn.IsHashIntervalTick((int)ticksPerWorkPoint))
                    {
                        if (!building.IsPowered())
                        {
                            pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                        }

                        //Log.Message("workLeft = " + compWeaponAvali.workLeft);
                        compWeaponAvali.workLeft--;
                    }

                    if (compWeaponAvali.workLeft <= 0)
                    {
                        compWeaponAvali.workLeft = 0;
                        compWeaponAvali.EraseOwnerPawnInfo();
                        pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                    }
                };

                //Log.Message("Translate");
                yield return(translate);
            }

            if (err)
            {
                yield return(error);
            }
            yield break;
        }