Ejemplo n.º 1
0
        private void SetAsDefender(Pawn p)
        {
            LordToilData_DefendBomb data = Data;

            p.mindState.duty        = new PawnDuty(DutyDefOf.Defend, data.defendCenter, -1f);
            p.mindState.duty.radius = data.baseRadius;
        }
Ejemplo n.º 2
0
        public override void LordToilTick()
        {
            base.LordToilTick();
            if (lord.ticksInToil == 450)
            {
                lord.CurLordToil.UpdateAllDuties();
            }
            if (lord.ticksInToil > 450 && lord.ticksInToil % 500 == 0)
            {
                UpdateAllDuties();
            }
            if (Find.TickManager.TicksGame % 500 == 0)
            {
                LordToilData_DefendBomb data = Data;

                /*
                 * if (data.empBomb != null&& data.empBomb.ParentHolder !=null&&((Thing)data.empBomb.ParentHolder).Destroyed)
                 * {
                 *  Log.Message("data.empBomb.ParentHolder Destroyed");
                 * }*/
                if (data.EmpBomb != null && data.EmpBomb.Destroyed || (data.minifiedEmpBomb != null && data.minifiedEmpBomb.Destroyed && !data.EmpBomb.Spawned))
                {
                    lord.ReceiveMemo("NoBomb");
                    return;
                }
                if (!data.empIsSpawned && data.minifiedEmpBombDestoryed)
                {
                    lord.ReceiveMemo("NoBomb");
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        public override void Init()
        {
            base.Init();
            Current.Game.GetComponent <GameComponent_EMPCheck>().lord = lord;
            LordToilData_DefendBomb data = Data;

            data.baseRadius = Mathf.InverseLerp(14f, 25f, lord.ownedPawns.Count / 50f);
            data.baseRadius = Mathf.Clamp(data.baseRadius, 14f, 25f);

            Thing   bomb            = ThingMaker.MakeThing(RatkinBuildingDefOf.RK_EmpBomb);
            Faction ratkiniaFaction = Find.FactionManager.FirstFactionOfDef(RatkinFactionDefOf.Rakinia);

            data.EmpBomb = bomb;
            bomb.SetFaction(ratkiniaFaction);
            if (bomb.TryGetComp <Comp_Emp>() != null)
            {
                bomb.TryGetComp <Comp_Emp>().eventPoint = Data.eventPoint;
            }
            MinifiedThing minified = bomb.MakeMinified();

            data.minifiedEmpBomb = minified;
            IntVec3 intVec3 = CellFinder.RandomClosewalkCellNear(Data.defendCenter, Map, 1);

            GenSpawn.Spawn(minified, intVec3, Map);
            IntVec3   bluePrintPosition = CellFinder.RandomClosewalkCellNear(intVec3, Map, 5);
            Blueprint b = GenConstruct.PlaceBlueprintForInstall(minified, bluePrintPosition, Map, Rot4.North, Find.FactionManager.FirstFactionOfDef(RatkinFactionDefOf.Rakinia));

            data.blueprint = b;
            data.desiredBuilderFraction = BuilderCountFraction.RandomInRange;
        }
Ejemplo n.º 4
0
        public override void Cleanup()
        {
            LordToilData_DefendBomb data = Data;

            if (data.blueprint != null && !data.blueprint.Destroyed)
            {
                data.blueprint.Destroy(DestroyMode.Cancel);
            }
        }
Ejemplo n.º 5
0
        public override void UpdateAllDuties()
        {
            LordToilData_DefendBomb data = Data;

            if (lord.ticksInToil < 450)
            {
                for (int i = 0; i < lord.ownedPawns.Count; i++)
                {
                    SetAsDefender(lord.ownedPawns[i]);
                }
            }
            else
            {
                int bombPlanerCount = 0;
                rememberedDuties.Clear();
                for (int j = 0; j < lord.ownedPawns.Count; j++)
                {
                    Pawn bombPlaner = lord.ownedPawns[j];
                    if (bombPlaner.mindState.duty.def == DutyDefOf.Build)
                    {
                        rememberedDuties.Add(bombPlaner, DutyDefOf.Build);
                        SetAsBuilder(bombPlaner);
                        bombPlanerCount++;
                        break;
                    }
                }
                if (bombPlanerCount < 1)
                {
                    Pawn bombPlaner;
                    if ((from pawnB in lord.ownedPawns
                         where !rememberedDuties.ContainsKey(pawnB) && CanBeBuilder(pawnB)
                         select pawnB).TryRandomElement(out bombPlaner))
                    {
                        rememberedDuties.Add(bombPlaner, DutyDefOf.Build);
                        SetAsBuilder(bombPlaner);
                        bombPlanerCount++;
                    }
                }
                for (int l = 0; l < lord.ownedPawns.Count; l++)
                {
                    Pawn defender = lord.ownedPawns[l];
                    if (!rememberedDuties.ContainsKey(defender))
                    {
                        SetAsDefender(defender);
                        rememberedDuties.Add(defender, DutyDefOf.Defend);
                    }
                }
                if (bombPlanerCount == 0)
                {
                    //Log.Message("NoBuilders");
                    lord.ReceiveMemo("NoBuilders");
                    return;
                }
            }
        }
Ejemplo n.º 6
0
        private void SetAsBuilder(Pawn p)
        {
            LordToilData_DefendBomb data = Data;

            p.mindState.duty        = new PawnDuty(DutyDefOf.Build, data.defendCenter, -1f);
            p.mindState.duty.radius = data.baseRadius;
            p.skills.GetSkill(SkillDefOf.Construction).EnsureMinLevelWithMargin(4);
            p.workSettings.EnableAndInitialize();
            List <WorkTypeDef> allDefsListForReading = DefDatabase <WorkTypeDef> .AllDefsListForReading;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                WorkTypeDef workTypeDef = allDefsListForReading[i];
                if (workTypeDef == WorkTypeDefOf.Construction)
                {
                    p.workSettings.SetPriority(workTypeDef, 1);
                }
                else
                {
                    p.workSettings.Disable(workTypeDef);
                }
            }
        }
Ejemplo n.º 7
0
 public LordToil_DefendBomb(IntVec3 defendCenter, float eventPoint)
 {
     data = new LordToilData_DefendBomb();
     Data.defendCenter = defendCenter;
     Data.eventPoint   = eventPoint;
 }