Esempio n. 1
0
        public override void OnSucessfullCast(Saveable_Caster pawn, IEnumerable <Thing> targets, IExposable effectState)
        {
            List <Pawn> newPawns = new List <Pawn>();

            foreach (PawnKindDef pawnKind in this.pawnKinds)
            {
                Pawn    newPawn = PawnGenerator.GeneratePawn(pawnKind, pawn.pawn.Faction);
                IntVec3 loc     = CellFinder.RandomClosewalkCellNear(pawn.pawn.Position, this.range);
                GenSpawn.Spawn(newPawn, loc);
                newPawns.Add(newPawn);

                if (this.spawnedMote != null)
                {
                    this.spawnedMote.AbilityStarted(pawn, newPawn);
                }
            }

            Brain brain = pawn.pawn.GetSquadBrain();

            if (brain == null)
            {
                StateGraph squadBrainStateGraph = GraphMaker.AssaultColonyGraph(pawn.pawn.Faction, false, false);
                newPawns.Insert(0, pawn.pawn);
                BrainMaker.MakeNewBrain(pawn.pawn.Faction, squadBrainStateGraph, newPawns);
            }
            else
            {
                foreach (Pawn newPawn in newPawns)
                {
                    brain.AddPawn(newPawn);
                }
            }
        }
Esempio n. 2
0
        public override void OnSucessfullCast(Saveable_Caster caster, IEnumerable <Thing> targets, IExposable effectState)
        {
            MapComponent_Ability component = MapComponent_Ability.GetOrCreate();

            foreach (Pawn target in targets)
            {
                AbilityEffect_UtilityChangeKind evolveItem = this.items.First(i => i.from.Contains(target.def));


                Brain brain = target.GetSquadBrain();
                foreach (PawnKindDef kind in evolveItem.to)
                {
                    Pawn newPawn = AbilityEffect_Revive.Copy(caster.pawn, kind, target.Faction);
                    GenSpawn.Spawn(newPawn, target.Position);

                    if (brain != null)
                    {
                        brain.AddPawn(newPawn);
                    }
                }

                Building building = StoreUtility.StoringBuilding(target);
                if (building != null)
                {
                    ((Building_Storage)building).Notify_LostThing(target);
                }
                target.Destroy(DestroyMode.Vanish);
            }
        }
Esempio n. 3
0
        public override void OnSucessfullCast(Saveable_Caster caster, IEnumerable <Thing> targets, IExposable effectState)
        {
            float exceedPower = this.totalPower;

            foreach (Pawn target in targets.OfType <Pawn>())
            {
                float pawnAvailPower = this.targetPower;

                if (pawnAvailPower + exceedPower >= this.treatLocalInjuryPowerUse)
                {
                    foreach (Hediff_Injury toTreat in target.health.hediffSet.GetInjuriesTreatable().OrderByDescending(i => i.Severity))
                    {
                        pawnAvailPower -= this.treatLocalInjuryPowerUse;

                        HediffComp_Tendable hediffComp_Treatable = toTreat.TryGetComp <HediffComp_Tendable>();
                        if (hediffComp_Treatable == null)
                        {
                            Log.Error("Tried to treat " + toTreat + " which does not have a HediffComp_Tendable");
                        }
                        else
                        {
                            hediffComp_Treatable.CompTreated(0.3f, 1);
                        }

                        Brain brain = caster.pawn.GetSquadBrain();
                        if ((brain != null) &&
                            (!target.Downed) &&
                            (target.GetSquadBrain() == null))
                        {
                            brain.AddPawn(target);
                        }

                        if (pawnAvailPower < 0)
                        {
                            exceedPower   += pawnAvailPower;
                            pawnAvailPower = 0;
                        }

                        if (pawnAvailPower + exceedPower < this.treatLocalInjuryPowerUse)
                        {
                            break;
                        }
                    }
                }

                if (pawnAvailPower + exceedPower >= this.healLocalInjuryPowerUse)
                {
                    foreach (Hediff_Injury toHeal in target.health.hediffSet.hediffs.OfType <Hediff_Injury>()
                             .Where(i => i.IsTendedAndHealing() && (i.Severity != 0.0f))
                             .OrderByDescending(i => i.Severity))
                    {
                        float maximum = ((pawnAvailPower + exceedPower) / this.healLocalInjuryPowerUse);
                        maximum = Math.Min(maximum, toHeal.Severity);

                        toHeal.DirectHeal(maximum);

                        pawnAvailPower -= maximum * this.healLocalInjuryPowerUse;
                        if (pawnAvailPower < 0)
                        {
                            exceedPower   += pawnAvailPower;
                            pawnAvailPower = 0;
                        }

                        if (pawnAvailPower + exceedPower < this.healLocalInjuryPowerUse)
                        {
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public override void OnSucessfullCast(Saveable_Caster caster, IEnumerable <Thing> targets, IExposable effectState)
        {
            MapComponent_Ability component = MapComponent_Ability.GetOrCreate();

            Brain brain = caster.pawn.GetSquadBrain();

            foreach (Corpse corpse in targets)
            {
                List <PawnKindDef> newKinds = new List <PawnKindDef>();
                if (this.changes != null)
                {
                    AbilityEffect_UtilityChangeKind kind = this.changes.FirstOrDefault(i => i.from.Contains(corpse.innerPawn.def));
                    if (kind != null)
                    {
                        newKinds.AddRange(kind.to);
                    }
                    else
                    {
                        newKinds.Add(corpse.innerPawn.kindDef);
                    }
                }
                else
                {
                    newKinds.Add(corpse.innerPawn.kindDef);
                }

                foreach (PawnKindDef kindDef in newKinds)
                {
                    Pawn newPawn = AbilityEffect_Revive.Copy(caster.pawn, kindDef, this.changeFaction ? caster.pawn.Faction : corpse.innerPawn.Faction);

                    if (corpse.innerPawn == caster.pawn)
                    {
                        component.ReplacePawnAbility(caster, newPawn);
                    }

                    IntVec3 position = corpse.Position;

                    GenSpawn.Spawn(newPawn, position);

                    if ((newPawn.Faction == caster.pawn.Faction) &&
                        (brain != null))
                    {
                        brain.AddPawn(newPawn);
                    }
                }

                Building building = StoreUtility.StoringBuilding(corpse);
                if (building != null)
                {
                    ((Building_Storage)building).Notify_LostThing(corpse);
                }
                corpse.Destroy(DestroyMode.Vanish);

                //if (this.healUntil > 0)
                //{
                //    HediffSet hediffSet = newPawn.healthTracker.hediffSet;
                //    while ((newPawn.healthTracker.summaryHealth.SummaryHealthPercent >= this.healUntil) &&
                //        (AbilityEffect_Revive.HittablePartsViolence(hediffSet).Any<BodyPartRecord>()))
                //    {
                //        BodyPartRecord bodyPartRecord = AbilityEffect_Revive.HittablePartsViolence(hediffSet).RandomElementByWeight((BodyPartRecord x) => x.absoluteFleshCoverage);
                //        int amount = Rand.RangeInclusive(8, 25);
                //        DamageDef def;
                //        if (bodyPartRecord.depth == BodyPartDepth.Outside)
                //            def = HealthUtility.RandomViolenceDamageType();
                //        else
                //            def = DamageDefOf.Blunt;
                //        DamageInfo dinfo = new DamageInfo(def, amount, null, new BodyPartDamageInfo?(new BodyPartDamageInfo(bodyPartRecord, false, (List<HediffDef>)null)), null);
                //        newPawn.TakeDamage(dinfo);
                //    }
                //}
            }
        }