Beispiel #1
0
        public override void PostSpawnSetup(bool respawningAfterLoad)
        {
            base.PostSpawnSetup(respawningAfterLoad);
            CompPowerBattery comp = this.parent.GetComp <CompPowerBattery>();

            comp.SetStoredEnergyPct(1f);
        }
        private void CompTickWhatever()
        {
            if (linkedBatteryShare == null)
            {
                Building_PocketDimensionEntranceBase parentEntrance = this.parent as Building_PocketDimensionEntranceBase;

                if (parentEntrance != null)
                {
                    Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(parentEntrance);

                    if (otherSide != null)
                    {
                        linkedBatteryShare = otherSide.GetComp <CompPocketDimensionBatteryShare>();
                    }
                }
            }

            if (thisBattery != null && linkedBatteryShare != null && linkedBatteryShare.parent.Map != null)
            {
                float newEnergyOtherSide = linkedBatteryShare.GetEnergyStored(thisBattery.StoredEnergy);
                float maxEnergyOtherSide = linkedBatteryShare.GetEnergyMax();

                // Calculate actual energy percent first
                if (maxEnergyOtherSide > 0.0f)
                {
                    energyPercent = newEnergyOtherSide / maxEnergyOtherSide;
                }
                else
                {
                    energyPercent = 0.0f;
                }

                float maxEnergyTotal = maxEnergyOtherSide + Props.storedEnergyMax;


                if (newEnergyOtherSide > maxEnergyTotal)
                {
                    newEnergyOtherSide = maxEnergyTotal;
                }

                storedEnergyMax = maxEnergyTotal;

                // The props is a single instance shared across all instances of the comp. Just need to make sure it can always hold enough.
                if (thisBattery.Props.storedEnergyMax < maxEnergyTotal)
                {
                    thisBattery.Props.storedEnergyMax = maxEnergyTotal;
                }

                float showEnergyPercent = 1.0f;
                if (thisBattery.Props.storedEnergyMax > 0.0f)
                {
                    showEnergyPercent = newEnergyOtherSide / thisBattery.Props.storedEnergyMax;
                }

                thisBattery.SetStoredEnergyPct(showEnergyPercent);

                //Logger.MessageFormat(this, "Updated battery, energy: {0} ({2}), max: {1} ({3}), {4} - {5}", newEnergy, maxEnergy, thisBattery.StoredEnergy, thisBattery.Props.storedEnergyMax, thisBattery.parent.Label, linkedBatteryShare.parent.Label);
            }
        }
        public static Toil FinalizeIngestAnything(Pawn ingester, TargetIndex ingestibleInd, CompEatWeirdFood comp)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn  actor  = toil.actor;
                Job   curJob = actor.jobs.curJob;
                Thing thing  = curJob.GetTarget(ingestibleInd).Thing;

                float num = ingester.needs.food.NutritionWanted;
                if (curJob.overeat)
                {
                    num = Mathf.Max(num, 0.75f);
                }
                float num2 = comp.Props.nutrition;// thing.Ingested(ingester, num);
                if (comp.Props.fullyDestroyThing)
                {
                    if (comp.Props.drainBattery)
                    {
                        Building_Battery battery = thing as Building_Battery;
                        if (battery != null)
                        {
                            CompPowerBattery compPower = battery.TryGetComp <CompPowerBattery>();
                            compPower.SetStoredEnergyPct(compPower.StoredEnergyPct - comp.Props.percentageDrain);
                        }
                        else
                        {
                            thing.Destroy(DestroyMode.Vanish);
                        }
                    }
                    else
                    {
                        thing.Destroy(DestroyMode.Vanish);
                    }
                }
                else
                {
                    if (thing.def.useHitPoints)
                    {
                        thing.HitPoints -= (int)(thing.MaxHitPoints * comp.Props.percentageOfDestruction);
                        if (thing.HitPoints <= 0)
                        {
                            thing.Destroy(DestroyMode.Vanish);
                        }
                    }
                    else
                    {
                        int thingsToDestroy = (int)(comp.Props.percentageOfDestruction * thing.def.stackLimit);
                        //Log.Message(thingsToDestroy.ToString());

                        thing.stackCount = thing.stackCount - thingsToDestroy;
                        //Log.Message(thing.stackCount.ToString());
                        if (thing.stackCount < 10)
                        {
                            thing.Destroy(DestroyMode.Vanish);
                        }
                    }
                    if ((actor.def.defName == "AA_AngelMoth") && (actor.Faction == Faction.OfPlayer) && (thing.TryGetComp <CompQuality>() != null) && (thing.TryGetComp <CompQuality>().Quality == QualityCategory.Legendary))
                    {
                        actor.health.AddHediff(HediffDef.Named("AA_AteFinestClothes"));
                    }
                }

                if (comp.Props.hediffWhenEaten != "")
                {
                    actor.health.AddHediff(HediffDef.Named(comp.Props.hediffWhenEaten));
                }

                if (comp.Props.advanceLifeStage && actor.Map != null)
                {
                    comp.currentFeedings++;
                    if (comp.currentFeedings >= comp.Props.advanceAfterXFeedings)
                    {
                        if (comp.Props.fissionAfterXFeedings)
                        {
                            if (!comp.Props.fissionOnlyIfTamed || actor.Faction.IsPlayer)
                            {
                                for (int i = 0; i < comp.Props.numberOfOffspring; i++)
                                {
                                    PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDef.Named(comp.Props.defToFissionTo), actor.Faction, PawnGenerationContext.NonPlayer, -1, true, true, false, false, true, false, 1f, false, true, true, false, false);
                                    Pawn newPawn = PawnGenerator.GeneratePawn(request);
                                    newPawn.playerSettings.AreaRestriction = actor.playerSettings.AreaRestriction;
                                    newPawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, actor);
                                    GenSpawn.Spawn(newPawn, actor.Position, actor.Map, WipeMode.Vanish);
                                }

                                actor.Destroy();
                            }
                        }
                        else
                        {
                            PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDef.Named(comp.Props.defToAdvanceTo), actor.Faction, PawnGenerationContext.NonPlayer, -1, true, true, false, false, true, false, 1f, false, true, true, false, false);
                            Pawn newPawn = PawnGenerator.GeneratePawn(request);
                            if (!actor.Name.ToString().UncapitalizeFirst().Contains(actor.def.label))
                            {
                                newPawn.Name = actor.Name;
                            }
                            newPawn.training        = actor.training;
                            newPawn.health          = actor.health;
                            newPawn.foodRestriction = actor.foodRestriction;
                            newPawn.playerSettings.AreaRestriction = actor.playerSettings.AreaRestriction;
                            GenSpawn.Spawn(newPawn, actor.Position, actor.Map, WipeMode.Vanish);
                            actor.Destroy();
                        }
                    }
                }

                if (!ingester.Dead)
                {
                    ingester.needs.food.CurLevel += num2;
                }
                ingester.records.AddTo(RecordDefOf.NutritionEaten, num2);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            return(toil);
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            ThingDef def = this.def;

            Pawn caster = this.launcher as Pawn;

            if (!this.initialized)
            {
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                CompAbilityUserMagic   comp        = caster.GetComp <CompAbilityUserMagic>();

                pwrVal = comp.MagicData.MagicPowerSkill_Sabotage.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Sabotage_pwr").level;
                verVal = comp.MagicData.MagicPowerSkill_Sabotage.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Sabotage_ver").level;
                if (caster.story.traits.HasTrait(TorannMagicDefOf.Faceless))
                {
                    MightPowerSkill mpwr = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr");
                    MightPowerSkill mver = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver");
                    pwrVal = mpwr.level;
                    verVal = mver.level;
                }
                this.arcaneDmg = comp.arcaneDmg;
                if (settingsRef.AIHardMode && !caster.IsColonist)
                {
                    pwrVal = 3;
                    verVal = 3;
                }
                SoundInfo info = SoundInfo.InMap(new TargetInfo(base.Position, this.Map, false), MaintenanceType.None);
                info.pitchFactor  = .5f;
                info.volumeFactor = .8f;
                SoundDefOf.PsychicPulseGlobal.PlayOneShot(info);
                Effecter SabotageEffect = TorannMagicDefOf.TM_SabotageExplosion.Spawn();
                SabotageEffect.Trigger(new TargetInfo(base.Position, this.Map, false), new TargetInfo(base.Position, this.Map, false));
                SabotageEffect.Cleanup();
                targetCells       = GenRadial.RadialCellsAround(base.Position, this.def.projectile.explosionRadius, true).ToList();
                this.targetThings = new List <SabotageThing>();
                this.targetThings.Clear();
                this.initialized = true;

                Pawn     targetPawn     = null;
                Building targetBuilding = null;

                for (int i = 0; i < this.targetCells.Count; i++)
                {
                    var targetCell = this.targetCells[i];
                    if (Rand.Chance((.5f + (.1f * verVal)) * this.arcaneDmg))
                    {
                        float rnd = Rand.Range(0, 1f);
                        targetPawn = targetCell.GetFirstPawn(this.Map);
                        if (targetPawn != null)
                        {
                            if (TM_Calc.IsRobotPawn(targetPawn))
                            {
                                TM_Action.DoAction_SabotagePawn(targetPawn, caster, rnd, pwrVal, this.arcaneDmg, this.launcher);
                                this.age = this.duration;
                            }
                            else
                            {
                                targetPawn = null;
                                //Log.Message("pawn not a robot, mechanoid, or android");
                            }
                        }

                        targetBuilding = targetCell.GetFirstBuilding(this.Map);
                        if (targetPawn == null && targetBuilding != null)
                        {
                            CompPower       compP = targetBuilding.GetComp <CompPower>();
                            CompPowerTrader cpt   = targetBuilding.GetComp <CompPowerTrader>();
                            if (compP != null && compP.Props.basePowerConsumption != 0 && cpt != null && cpt.powerOutputInt != 0)
                            {
                                if (true)
                                {
                                    //stun/electrical explosion
                                    GenExplosion.DoExplosion(targetBuilding.Position, base.Map, 2 + pwrVal + Mathf.RoundToInt(cpt.powerOutputInt / 400), DamageDefOf.Stun, null);
                                    GenExplosion.DoExplosion(targetBuilding.Position, base.Map, 1 + pwrVal + Mathf.RoundToInt(cpt.powerOutputInt / 600), TMDamageDefOf.DamageDefOf.TM_ElectricalBurn, null);
                                }
                                else
                                {
                                }
                            }

                            Building_Battery targetBattery = targetBuilding as Building_Battery;
                            if (targetBattery != null && targetBattery.def.thingClass.ToString() == "RimWorld.Building_Battery")
                            {
                                CompPowerBattery compB = targetBattery.GetComp <CompPowerBattery>();
                                if (rnd <= .5f)
                                {
                                    Traverse.Create(root: targetBattery).Field(name: "ticksToExplode").SetValue(Rand.Range(40, 130) - (5 * pwrVal));
                                    compB.SetStoredEnergyPct(.81f);
                                }
                                else
                                {
                                    GenExplosion.DoExplosion(targetBattery.Position, base.Map, 2 + pwrVal + Mathf.RoundToInt(compB.StoredEnergy / 200), DamageDefOf.EMP, null);
                                    compB.DrawPower(compB.StoredEnergy);
                                }
                            }

                            Building_TurretGun targetTurret = targetBuilding as Building_TurretGun;
                            if (targetTurret != null && targetTurret.gun != null)
                            {
                                if (rnd <= .5f)
                                {
                                    targetTurret.SetFaction(Faction.OfAncientsHostile, null);
                                }
                                else
                                {
                                    GenExplosion.DoExplosion(targetTurret.Position, base.Map, 2 + pwrVal, TMDamageDefOf.DamageDefOf.TM_ElectricalBurn, null); //20 default damage
                                }
                            }
                        }
                        else
                        {
                            //Log.Message("no thing to sabotage");
                        }
                        targetPawn     = null;
                        targetBuilding = null;
                    }
                }
            }
            else if (this.targetThings.Count > 0)
            {
                this.age = this.duration;
            }
            else
            {
                this.age = this.duration;
            }
        }
Beispiel #5
0
        private void CompTickWhatever()
        {
            if (thisBattery == null)
            {
                Logger.MessageFormat(this, "No battery found.");
            }

            if (otherSharer == null)
            {
                Building_PocketDimensionEntranceBase parentEntrance = this.parent as Building_PocketDimensionEntranceBase;

                if (parentEntrance != null)
                {
                    Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(parentEntrance);

                    if (otherSide != null)
                    {
                        SetOtherThing(otherSide);
                    }
                }
            }

            if (thisBattery != null && otherSharer != null && otherSharer.parent.Map != null)
            {
                float newEnergy = otherSharer.GetEnergyStored(thisBattery.StoredEnergy);
                float maxEnergy = otherSharer.GetEnergyMax();

                float energyPercent = 1.0f;

                if (newEnergy != maxEnergy && maxEnergy > 0.0f)
                {
                    energyPercent = newEnergy / maxEnergy;
                }

                thisBattery.Props.storedEnergyMax = maxEnergy;
                thisBattery.SetStoredEnergyPct(energyPercent);
            }
            else if (thisBattery != null)
            {
                thisBattery.Props.storedEnergyMax = 0.0f;
                thisBattery.SetStoredEnergyPct(1.0f);
            }

            //if (otherSharer != null && otherSharer.parent.Map != null)
            //{
            //    this.PowerTransferAmount = otherSharer.GetExcessEnergy();
            //}
            //else
            //{
            //    this.PowerTransferAmount = 0.0f;
            //}


            ////this.UpdateDesiredPowerOutput();
            //// Using refuelable to add components breaks the normal UpdatedDesiredPowerOutput logic, reproduced and circumvented here
            //if ((breakdownableComp != null && breakdownableComp.BrokenDown) || /*(refuelableComp != null && !refuelableComp.HasFuel) ||*/ (flickableComp != null && !flickableComp.SwitchIsOn) || !base.PowerOn)
            //{
            //    base.PowerOutput = 0.0f;
            //}
            //else
            //{
            //    base.PowerOutput = DesiredPowerOutput;
            //}

            base.PowerOutput = 0.0f;
        }