public static int CoreGetDamage(CompPower FencePowerComp)
        {
            var powerGain  = FencePowerComp.PowerNet.CurrentEnergyGainRate();
            var powerStore = FencePowerComp.PowerNet.CurrentStoredEnergy();
            var multiplier = 1;

            if (powerStore > 1000)
            {
                multiplier = Mathf.RoundToInt(powerStore / 1000);
            }

            var powerTotal = powerGain * 60 * multiplier;
            var calcPower  = Mathf.RoundToInt(powerTotal);

            // batteries
            var batteryDamage = 0;

            foreach (var compPowerBattery in FencePowerComp.PowerNet.batteryComps)
            {
                var storedPower = compPowerBattery.StoredEnergy;
                if (storedPower > 10000)
                {
                    storedPower = 10000f;
                }

                batteryDamage += Mathf.RoundToInt(storedPower / 100);
            }

            calcPower += batteryDamage;
            return(calcPower);
        }
 static void Postfix(CompPower __instance)
 {
     if (__instance.parent != null && __instance.parent.def.HasComp(typeof(Comp_EnhancedBeacon)))
     {
         __instance.parent.GetComp <Comp_EnhancedBeacon>().UpdateTradeRegion();
     }
 }
 public static void RemoveReconnectGizmo(CompPower __instance, ref IEnumerable <Gizmo> __result)
 {
     if (__instance.parent.def.defName == "HeatedFloorThing")
     {
         List <Gizmo> gizmos = __result.Where(x => !(x is Command_Action)).ToList();
         __result = gizmos;
     }
 }
 static bool Prefix(CompPower pc)
 {
     if (pc.parent.GetComp <CompMountable>() is CompMountable comp && comp.Active)
     {
         return(false);
     }
     return(true);
 }
        public static void CoreAssignPawnDamage(Pawn p, int damage, Thing source, CompPower FencePowerComp,
                                                float drainPower)
        {
            // batteries
            CoreDrainPower(FencePowerComp, drainPower);

            int randomInRange;

            switch (damage)
            {
            case < 50:
                randomInRange = 1;
                break;

            case < 100:
                randomInRange = 2;
                break;

            case < 200:
                randomInRange = 3;
                break;

            default:
                randomInRange = 5;
                break;
            }

            var height = Rand.Value >= 0.666 ? BodyPartHeight.Middle : BodyPartHeight.Top;

            for (var i = 0; i < randomInRange; i++)
            {
                if (damage <= 0)
                {
                    break;
                }

                var num2 = Mathf.Max(1, Mathf.RoundToInt(Rand.Value * damage));
                damage -= num2;
                var dinfo = new DamageInfo(DamageDefOf.Burn, num2, -1, -1f, source);
                if (randomInRange > 2)
                {
                    dinfo = new DamageInfo(DamageDefOf.Flame, num2, -1, -1f, source);
                }

                dinfo.SetBodyRegion(height, BodyPartDepth.Outside);
                p.TakeDamage(dinfo);

                var sparks = new Effecter(DefDatabase <EffecterDef> .GetNamed("ConstructMetal"));
                // If we have a spark effecter

                for (var y = 0; y < randomInRange; y++)
                {
                    sparks.EffectTick(p, source);
                }

                sparks.Cleanup();
            }
        }
        public static void Postfix(Thing parent, ref Material __result)
        {
            CompPower comp = parent.TryGetComp <CompPower>();

            if (comp != null)
            {
                __result = new PowerMaterial(__result, comp);
            }
        }
Esempio n. 7
0
        public static bool Prefix(ref CompPower __result, ref IntVec3 connectorPos, ref Map map, ref List <PowerNet> disallowedNets)
        {
            CellRect cellRect = CellRect.SingleCell(connectorPos).ExpandedBy(6).ClipInsideMap(map);
            float    num      = 999999f;

            cellRect.ClipInsideMap(map);
            __result = null;
            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    IntVec3  c           = new IntVec3(j, 0, i);
                    Building transmitter = c.GetTransmitter(map);
                    if (transmitter != null && !transmitter.Destroyed)
                    {
                        CompPower powerComp = transmitter.PowerComp;
                        if (powerComp != null && powerComp.TransmitsPowerNow && (transmitter.def.building == null || transmitter.def.building.allowWireConnection))
                        {
                            if (disallowedNets == null || !disallowedNets.Contains(powerComp.transNet))
                            {
                                float num2 = (float)(transmitter.Position - connectorPos).LengthHorizontalSquared;
                                if (num2 < num)
                                {
                                    num      = num2;
                                    __result = powerComp;
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (Thing thing in c.GetThingList(map))
                        {
                            if (thing.GetType() == typeof(Building_Steam))
                            {
                                Building  building  = (Building)thing;
                                CompPower powerComp = building.PowerComp;
                                if (powerComp != null &&
                                    (disallowedNets == null || !disallowedNets.Contains(powerComp.transNet)))
                                {
                                    float num2 = (building.Position - connectorPos).LengthHorizontalSquared;
                                    if (num2 < num)
                                    {
                                        num      = num2;
                                        __result = powerComp;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 8
0
        public bool SuitablePosition(IntVec3 pos, Map map, bool fallback = false)
        {
            if (!pos.InBounds(map))
            {
                return(false);
            }
            if (!pos.Roofed(map))
            {
                return(false);
            }
            if (!pos.Standable(map))
            {
                return(false);
            }

            if (!fallback)
            {
                int v = 0;
                int h = 0;
                if (new IntVec3(pos.x + 1, pos.y, pos.z + 0).Impassable(map))
                {
                    v++;
                }
                if (new IntVec3(pos.x - 1, pos.y, pos.z + 0).Impassable(map))
                {
                    v++;
                }
                if (new IntVec3(pos.x + 0, pos.y, pos.z + 1).Impassable(map))
                {
                    h++;
                }
                if (new IntVec3(pos.x + 0, pos.y, pos.z - 1).Impassable(map))
                {
                    h++;
                }

                if (v < 1 || h < 1)
                {
                    return(false);
                }
            }

            CompPower comp = PowerConnectionMaker.BestTransmitterForConnector(pos, map);

            if (comp?.PowerNet == null)
            {
                return(false);
            }

            return(comp.PowerNet.HasActivePowerSource);
        }
        public static void CoreDrainPower(CompPower FencePowerComp, float drainPowerMax)
        {
            foreach (var compPowerBattery in FencePowerComp.PowerNet.batteryComps)
            {
                var storedPower = compPowerBattery.StoredEnergy;
                var drainPower  = compPowerBattery.Props.storedEnergyMax / 10;
                if (drainPower > drainPowerMax / 10)
                {
                    drainPower = drainPowerMax / 10;
                }

                compPowerBattery.DrawPower(storedPower > drainPower ? drainPower : storedPower);
            }
        }
Esempio n. 10
0
        public static void Postfix(ref BuildableDef def)
        {
            ThingDef thingDef = def as ThingDef;

            if (thingDef != null && thingDef.GetCompProperties <CompProperties_SteamAlternator>() != null)
            {
                IntVec3   intVec    = UI.MouseCell();
                CompPower compPower = PowerConnectionMaker.BestTransmitterForConnector(intVec, Find.VisibleMap, null);
                if (compPower != null)
                {
                    PowerNetGraphics.RenderAnticipatedWirePieceConnecting(intVec, compPower.parent);
                }
            }
        }
        public HydroponicsFlooder(IntVec3 position, Rot4 orientation, CompPower compPower,
                                  CompPowerTrader compPowerTrader, Map map)
        {
            Position    = position;
            Orientation = orientation;
            CP          = compPower;
            CPT         = compPowerTrader;
            Map         = map;

            ColorCellIndexCache = new List <GlowGridCache>();

            Color = new Color32(191, 63, 191, 1);

            Log.Safe($"HydroponicsFlooder belongs on {Map.uniqueID} and we are on {Find.CurrentMap.uniqueID}  ");
        }
Esempio n. 12
0
        public void Drain()
        {
            Building building = null;

            if (previousBuilding != null && previousBuilding.Position.DistanceTo(pawn.Position) < def.range)
            {
                building = previousBuilding;
            }
            if (building == null)
            {
                building = pawn.Map.listerBuildings.allBuildingsColonistElecFire.FirstOrDefault(x => x.Position.DistanceTo(pawn.Position) < def.range);
            }
            previousBuilding = building;

            if (building == null)
            {
                return;
            }

            CompPower power = building.GetComp <CompPower>();

            if (power == null || power.PowerNet == null)
            {
                return;
            }

            float amount  = Mathf.Min(power.PowerNet.AvailablePower(), def.drain);
            float canTake = def.efficiency < 0.0001 ? def.capacity : (def.capacity - charge) / def.efficiency;

            if (amount > canTake)
            {
                amount = canTake;
            }
            if (amount < def.drain / 2)
            {
                return;
            }

            power.PowerNet.Drain(amount);
            charge += amount * def.efficiency;

            RadiologyEffectSpawnerDef.Spawn(def.effectDraining, pawn.Map, pawn.TrueCenter(), (building.Position - pawn.Position).AngleFlat);
            RadiologyEffectSpawnerDef.Spawn(def.effectDrained, pawn.Map, building.RandomPointNearTrueCenter(), (pawn.Position - building.Position).AngleFlat);
        }
        public override void SelectedUpdate()
        {
            base.SelectedUpdate();
            IntVec3  intVec   = UI.MouseCell();
            ThingDef thingDef = this.entDef as ThingDef;

            if (thingDef != null && (thingDef.EverTransmitsPower || thingDef.ConnectToPower))
            {
                OverlayDrawHandler.DrawPowerGridOverlayThisFrame();
                if (thingDef.ConnectToPower)
                {
                    CompPower compPower = PowerConnectionMaker.BestTransmitterForConnector(intVec, Find.VisibleMap, null);
                    if (compPower != null)
                    {
                        PowerNetGraphics.RenderAnticipatedWirePieceConnecting(intVec, compPower.parent);
                    }
                }
            }
        }
Esempio n. 14
0
        public void InkrementPower(CompPower cp)
        {
            string compType = cp.parent.def.defName.ToString();

            this.PowerComps.Add(cp);

            float amount = 0f;

            switch (compType)
            {
            case "Battery":
                amount = 1.5f;
                break;

            case "PowerConduit":
                amount = 0.25f;
                break;

            case "PowerSwitch":
                amount = 0.1f;
                break;

            case "WoodFiredGenerator":
                amount = 1.0f;
                break;

            case "ChemfuelPoweredGenerator":
                amount = 5.0f;
                break;

            case "SolarGenerator":
                amount = 1.5f;
                break;

            case "GeothermalGenerator":
                amount = 7.5f;
                break;
            }

            this.powerBuildingCount += amount;
        }
Esempio n. 15
0
        protected override void TakePrintFrom(Thing t)
        {
            if (!ActiveCircuitsSettings.displayBadOnMain)
            {
                return;
            }
            if (t.Faction != null && t.Faction != Faction.OfPlayer)
            {
                return;
            }

            Building building = t as Building;

            if (building != null)
            {
                CompPower comp = t.TryGetComp <CompPower>();
                if (comp != null && ShouldPrint(comp))
                {
                    building.PrintForPowerGrid(this);
                }
            }
        }
Esempio n. 16
0
        public static void DrawPowerGrid(SectionLayer layer, CompPower comp)
        {
            if (comp.TransmitsPowerNow)
            {
                //Graphic_LinkedTransmitterOverlay graphic = (Graphic_LinkedTransmitterOverlay)PowerOverlayMats.LinkedOverlayGraphic;
                //Color color = GetNetColor(comp);
                //SectionLayer l = layer;

                //Graphic_LinkedTransmitterOverlay colored = GetColoredVersion(graphic, graphic.Shader, color, color);
                //colored.Print(l, comp.parent);
                Graphic_LinkedTransmitterOverlay graphic = NewPowerOverlayMats.LinkedOverlayGraphic;
                graphic.Print(layer, comp.parent);
            }
            if (comp.parent.def.ConnectToPower)
            {
                PowerNetGraphics.PrintOverlayConnectorBaseFor(layer, comp.parent);
            }
            if (comp.connectParent != null)
            {
                PowerNetGraphics.PrintWirePieceConnecting(layer, comp.parent, comp.connectParent.parent, true);
            }
        }
Esempio n. 17
0
        public AngledGlowFlooder(IntVec3 position, Rot4 orientation, CompPower compPower,
                                 CompPowerTrader compPowerTrader, Map map)
        {
            Position    = position;
            Orientation = orientation;
            CP          = compPower;
            CPT         = compPowerTrader;
            Map         = map;

            ColorCellIndexCache = new List <GlowGridCache>();
            //FloodBlockers = new List<FloodBlocker>();

            //Color = new Color32(191, 63, 191, 1);
            Color = new Color32(254, 255, 179, 0);

            innerArray = Map.edificeGrid.InnerArray;

            targetDistance = 16;
            angleModulus   =
                2; //0 is 90 and the higher you go the more narrow the angle. //angle 45 is every two tiles? - actually its 90 because left side is 0->45 and then right is 45<-0

            Log.Safe($"AngledGlowFlooder created belongs on {Map.uniqueID} and we are on {Find.CurrentMap.uniqueID}  ");
        }
Esempio n. 18
0
        private void DrawConnection(CompPower powerComp)
        {
            var transmitter = powerComp as CompPowerTransmitter;

            if (transmitter != null)
            {
                DrawTransmitter(transmitter);
            }

            var trader = powerComp as CompPowerTrader;

            if (trader != null)
            {
                DrawTrader(trader);
            }

            var battery = powerComp as CompPowerBattery;

            if (battery != null)
            {
                DrawBattery(battery);
            }
        }
Esempio n. 19
0
 public static bool Prefix(SectionLayer layer, CompPower __instance)
 {
     ActiveCircuitsBase.DrawPowerGrid(layer, __instance);
     return(false);
 }
Esempio n. 20
0
        private void DrawConnection( CompPower powerComp )
        {
            var transmitter = powerComp as CompPowerTransmitter;
            if ( transmitter != null )
            {
                DrawTransmitter( transmitter );
            }

            var trader = powerComp as CompPowerTrader;
            if ( trader != null )
            {
                DrawTrader( trader );
            }

            var battery = powerComp as CompPowerBattery;
            if ( battery != null )
            {
                DrawBattery( battery );
            }
        }
Esempio n. 21
0
        protected override bool TryCastShot()
        {
            Pawn caster = base.CasterPawn;

            comp   = caster.GetComp <CompAbilityUserMagic>();
            pwrVal = comp.MagicData.MagicPowerSkill_Overdrive.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Overdrive_pwr").level;
            verVal = comp.MagicData.MagicPowerSkill_Overdrive.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Overdrive_ver").level;
            ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
            if (caster.story.traits.HasTrait(TorannMagicDefOf.Faceless))
            {
                pwrVal = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr").level;
                verVal = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver").level;
            }
            if (settingsRef.AIHardMode && !caster.IsColonist)
            {
                pwrVal = 3;
                verVal = 3;
            }
            Thing targetThing = null;

            if (this.currentTarget.Thing != null)
            {
                targetThing = this.currentTarget.Thing;
            }
            else
            {
                targetThing = this.currentTarget.Cell.GetFirstBuilding(this.CasterPawn.Map);
            }
            if (targetThing != null)
            {
                Pawn pawn = targetThing as Pawn;
                if (pawn != null)
                {
                    if (TM_Calc.IsRobotPawn(pawn))
                    {
                        ApplyOverdriveHD(pawn);
                    }
                    else
                    {
                        Log.Message("pawn not a robot, mechanoid, or android");
                    }
                }

                Building bldg = targetThing as Building;
                if (bldg != null)
                {
                    CompPower       compP = bldg.GetComp <CompPower>();
                    CompPowerTrader cpt   = bldg.GetComp <CompPowerTrader>();
                    if (compP != null && compP.Props.basePowerConsumption != 0 && cpt != null && cpt.powerOutputInt != 0)
                    {
                        comp.overdriveBuilding    = bldg;
                        comp.overdrivePowerOutput = Mathf.RoundToInt(cpt.powerOutputInt * (2 + .6f * pwrVal * comp.arcaneDmg));
                        comp.overdriveDuration    = Mathf.RoundToInt((20 + 2 * pwrVal) * comp.arcaneDmg);
                        //compP.Props.basePowerConsumption *= 2;
                    }

                    Building_TurretGun bldgTurret = targetThing as Building_TurretGun;
                    if (bldgTurret != null && bldgTurret.gun != null)
                    {
                        comp.overdriveBuilding = bldgTurret;
                        comp.overdriveDuration = Mathf.RoundToInt((10 + pwrVal) * comp.arcaneDmg);
                    }
                    List <Pawn> odPawns = ModOptions.Constants.GetOverdrivePawnList();
                    if (odPawns != null)
                    {
                        odPawns.AddDistinct(caster);
                        ModOptions.Constants.SetOverdrivePawnList(odPawns);
                    }
                }
            }
            else
            {
                Log.Message("no thing targetted");
            }
            return(true);
        }
Esempio n. 22
0
        public bool ShouldPrint(CompPower comp)
        {
            Color color = ActiveCircuitsBase.GetNetColor(comp);

            return(color == ActiveCircuitsSettings.noPower || color == ActiveCircuitsSettings.nothingConnected || color == ActiveCircuitsSettings.justConduits);
        }
		public static void PostSpawnSetup_Prefix(CompPower __instance) {
			Spawner.spawnerPokemon.InkrementPower (__instance);
		}
Esempio n. 24
0
 public PowerMaterial(Material source, CompPower c) : base(source)
 {
     comp = c;
 }
        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;
            }
        }
Esempio n. 26
0
        public static Color GetNetColor(CompPower comp)
        {
            Color result;

            return(netColors.TryGetValue(comp.PowerNet, out result) ? result : Color.white);
        }