예제 #1
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn != null && pawn.Map != null && pawn.health != null && pawn.health.hediffSet != null && pawn.health.hediffSet.HasHediff(TorannMagicDefOf.TM_ChiHD) && !pawn.Drafted)
            {
                if (pawn.InBed() || HealthAIUtility.ShouldSeekMedicalRest(pawn) || !(pawn.GetPosture() == PawnPosture.Standing))
                {
                    return(null);
                }
                Need_Joy curJoy = pawn.needs.joy;
                if (curJoy == null)
                {
                    return(null);
                }
                if (curJoy.CurLevel >= .8f)
                {
                    return(null);
                }
                CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>();
                if (comp != null)
                {
                    MightPower mightPower = comp.MightData.MightPowersM.FirstOrDefault <MightPower>((MightPower x) => x.abilityDef == TorannMagicDefOf.TM_Meditate);

                    if (mightPower == null)
                    {
                        return(null);
                    }

                    if (!mightPower.AutoCast)
                    {
                        return(null);
                    }

                    Hediff      hediff  = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_ChiHD);
                    PawnAbility ability = pawn.GetComp <CompAbilityUserMight>().AbilityData.Powers.FirstOrDefault((PawnAbility x) => x.Def == TorannMagicDefOf.TM_Meditate);

                    if (ability.CooldownTicksLeft > 0 || hediff.Severity >= 70)
                    {
                        return(null);
                    }

                    Building_Bed building_Bed = pawn.ownership.OwnedBed;
                    if (building_Bed != null)
                    {
                        if (building_Bed.GetRoom() != null && !building_Bed.GetRoom().PsychologicallyOutdoors)
                        {
                            List <IntVec3> roomCells = building_Bed.GetRoom().Cells.ToList();
                            for (int i = 0; i < roomCells.Count; i++)
                            {
                                if (roomCells[i].IsValid && roomCells[i].Walkable(pawn.Map) && roomCells[i].GetFirstBuilding(pawn.Map) == null)
                                {
                                    return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, roomCells[i]));
                                }
                            }
                        }
                    }
                    return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, pawn.Position));
                }
            }
            return(null);
        }
예제 #2
0
        protected override bool TryCastShot()
        {
            Pawn caster = base.CasterPawn;
            Pawn pawn   = this.currentTarget.Thing as Pawn;

            bool flag = caster != null && !caster.Dead;

            if (flag)
            {
                TMAbilityDef ability = (TMAbilityDef)this.Ability.Def;
                if (ability != null && ability.abilityHediff != null)
                {
                    HediffDef hdDef = ability.abilityHediff;
                    if (caster.health.hediffSet.HasHediff(hdDef))
                    {
                        Hediff hd = caster.health.hediffSet.GetFirstHediffOfDef(hdDef);
                        caster.health.RemoveHediff(hd);
                    }
                    else
                    {
                        HealthUtility.AdjustSeverity(caster, hdDef, hdDef.initialSeverity);
                        if (caster.Map != null)
                        {
                            MoteMaker.ThrowLightningGlow(caster.DrawPos, caster.Map, 1f);
                            MoteMaker.ThrowDustPuff(caster.Position, caster.Map, 1f);
                        }
                    }

                    CompAbilityUserMagic magicComp = caster.TryGetComp <CompAbilityUserMagic>();
                    if (magicComp != null && magicComp.MagicData != null)
                    {
                        MagicPower mp = magicComp.MagicData.ReturnMatchingMagicPower(ability);
                        if (mp != null)
                        {
                            mp.autocast = caster.health.hediffSet.HasHediff(hdDef);
                        }
                    }
                    CompAbilityUserMight mightComp = caster.TryGetComp <CompAbilityUserMight>();
                    if (mightComp != null && mightComp.MightData != null)
                    {
                        MightPower mp = mightComp.MightData.ReturnMatchingMightPower(ability);
                        if (mp != null)
                        {
                            mp.autocast = caster.health.hediffSet.HasHediff(hdDef);
                        }
                    }
                }
                else
                {
                    Log.Warning("Unrecognized ability or no hediff assigned for this ability.");
                }
            }
            return(true);
        }
        public override void DoEffect(Pawn user)
        {
            CompAbilityUserMagic compMagic = user.GetComp <CompAbilityUserMagic>();
            CompAbilityUserMight compMight = user.GetComp <CompAbilityUserMight>();
            int essenceXP = 0;

            if (compMagic != null && compMagic.IsMagicUser && compMagic.MagicUserXP != 0 && compMagic.MagicData != null)
            {
                essenceXP += Rand.Range(300, 500);
                for (int i = 0; i < compMagic.MagicData.MagicPowersStandalone.Count; i++)
                {
                    MagicPower mp = compMagic.MagicData.MagicPowersStandalone[i];
                    if (mp.learned)
                    {
                        essenceXP += Rand.Range(80, 120);
                    }
                }
                essenceXP += Mathf.RoundToInt(compMagic.MagicUserXP / Rand.Range(1.7f, 2.3f));
                Thing             mes      = ThingMaker.MakeThing(TorannMagicDefOf.TM_MagicArtifact_MagicEssence, null);
                CompEnchantedItem itemComp = mes.TryGetComp <CompEnchantedItem>();
                if (itemComp != null && itemComp.HasEnchantment)
                {
                    itemComp.magicEssence = essenceXP;
                }
                GenPlace.TryPlaceThing(mes, this.parent.Position, this.parent.Map, ThingPlaceMode.Near);
                essenceXP = 0;
            }
            if (compMight != null && compMight.IsMightUser && compMight.MightUserXP != 0 && compMight.MightData != null)
            {
                essenceXP += Rand.Range(300, 500);
                for (int i = 0; i < compMight.MightData.MightPowersStandalone.Count; i++)
                {
                    MightPower mp = compMight.MightData.MightPowersStandalone[i];
                    if (mp.learned)
                    {
                        essenceXP += Rand.Range(80, 120);
                    }
                }
                essenceXP += Mathf.RoundToInt(compMight.MightUserXP / Rand.Range(1.7f, 2.3f));
                Thing             mes      = ThingMaker.MakeThing(TorannMagicDefOf.TM_MagicArtifact_MightEssence, null);
                CompEnchantedItem itemComp = mes.TryGetComp <CompEnchantedItem>();
                if (itemComp != null && itemComp.HasEnchantment)
                {
                    itemComp.mightEssence = essenceXP;
                }
                GenPlace.TryPlaceThing(mes, this.parent.Position, this.parent.Map, ThingPlaceMode.Near);
                essenceXP = 0;
            }

            ModOptions.TM_DebugTools.RemoveClass(user);
            TM_Action.TransmutateEffects(user.Position, user);
            TM_Action.TransmutateEffects(parent.Position, user);
        }
예제 #4
0
        private void ToggleAbilityAutocast()
        {
            MightPower mightPower = null;

            if (this.Ability.Def == TorannMagicDefOf.TM_ProvisionerAura)
            {
                mightPower = this.CasterPawn.GetComp <CompAbilityUserMight>().MightData.MightPowersC.FirstOrDefault <MightPower>((MightPower x) => x.abilityDef == TorannMagicDefOf.TM_ProvisionerAura);
            }
            else if (this.Ability.Def == TorannMagicDefOf.TM_TaskMasterAura)
            {
                mightPower = this.CasterPawn.GetComp <CompAbilityUserMight>().MightData.MightPowersC.FirstOrDefault <MightPower>((MightPower x) => x.abilityDef == TorannMagicDefOf.TM_TaskMasterAura);
            }
            else if (this.Ability.Def == TorannMagicDefOf.TM_CommanderAura)
            {
                mightPower = this.CasterPawn.GetComp <CompAbilityUserMight>().MightData.MightPowersC.FirstOrDefault <MightPower>((MightPower x) => x.abilityDef == TorannMagicDefOf.TM_CommanderAura);
            }

            if (mightPower != null)
            {
                mightPower.autocast = !mightPower.autocast;
            }
        }
예제 #5
0
파일: Verb_Mimic.cs 프로젝트: bluba/TMagic
        protected override bool TryCastShot()
        {
            bool result = false;

            if (this.currentTarget != null && base.CasterPawn != null && this.currentTarget.Thing is Pawn)
            {
                Pawn targetPawn = this.currentTarget.Thing as Pawn;
                if (targetPawn.RaceProps.Humanlike)
                {
                    CompAbilityUserMagic magicPawn = targetPawn.GetComp <CompAbilityUserMagic>();
                    CompAbilityUserMight mightPawn = targetPawn.GetComp <CompAbilityUserMight>();
                    bool copyMagic = false;
                    bool copyMight = false;
                    if (magicPawn != null && magicPawn.IsMagicUser)
                    {
                        copyMagic = true;
                    }
                    if (mightPawn != null && mightPawn.IsMightUser)
                    {
                        copyMight = true;
                    }

                    if (copyMight && copyMagic && Rand.Chance(.5f))
                    {
                        copyMagic = false;
                    }
                    TMAbilityDef         tempAbility = null;
                    CompAbilityUserMight mightComp   = this.CasterPawn.GetComp <CompAbilityUserMight>();
                    CompAbilityUserMagic magicComp   = this.CasterPawn.GetComp <CompAbilityUserMagic>();

                    if (copyMagic)
                    {
                        tempAbility = TM_Calc.GetCopiedMagicAbility(targetPawn, base.CasterPawn);

                        if (tempAbility != null)
                        {
                            if (mightComp.mimicAbility != null)
                            {
                                if (mightComp.mimicAbility.manaCost > 0)
                                {
                                    MagicPower mp = magicComp.MagicData.AllMagicPowers.FirstOrDefault((MagicPower x) => x.abilityDef == mightComp.mimicAbility);
                                    if (mp != null)
                                    {
                                        mp.autocast = false;
                                    }
                                }
                                else if (mightComp.mimicAbility.staminaCost > 0)
                                {
                                    MightPower mp = mightComp.MightData.AllMightPowers.FirstOrDefault((MightPower x) => x.abilityDef == mightComp.mimicAbility);
                                    if (mp != null)
                                    {
                                        mp.autocast = false;
                                    }
                                }
                                mightComp.RemovePawnAbility(mightComp.mimicAbility);
                            }
                            mightComp.mimicAbility = tempAbility;
                            mightComp.AddPawnAbility(tempAbility);
                        }
                        else
                        {
                            //invalid target
                            Messages.Message("TM_MimicFailed".Translate(
                                                 this.CasterPawn.LabelShort
                                                 ), MessageTypeDefOf.RejectInput);
                        }
                    }
                    else if (copyMight)
                    {
                        tempAbility = TM_Calc.GetCopiedMightAbility(targetPawn, base.CasterPawn);

                        if (tempAbility != null)
                        {
                            if (mightComp.mimicAbility != null)
                            {
                                if (mightComp.mimicAbility.manaCost > 0)
                                {
                                    MagicPower mp = magicComp.MagicData.AllMagicPowers.FirstOrDefault((MagicPower x) => x.abilityDef == mightComp.mimicAbility);
                                    if (mp != null)
                                    {
                                        mp.autocast = false;
                                    }
                                }
                                else if (mightComp.mimicAbility.staminaCost > 0)
                                {
                                    MightPower mp = mightComp.MightData.AllMightPowers.FirstOrDefault((MightPower x) => x.abilityDef == mightComp.mimicAbility);
                                    if (mp != null)
                                    {
                                        mp.autocast = false;
                                    }
                                }
                                mightComp.RemovePawnAbility(mightComp.mimicAbility);
                            }
                            if (magicComp.mimicAbility != null)
                            {
                                magicComp.RemovePawnAbility(magicComp.mimicAbility);
                            }
                            mightComp.mimicAbility = tempAbility;
                            mightComp.AddPawnAbility(tempAbility);
                        }
                        else
                        {
                            //invalid target
                            Messages.Message("TM_MimicFailed".Translate(
                                                 this.CasterPawn.LabelShort
                                                 ), MessageTypeDefOf.RejectInput);
                        }
                    }
                }
            }
            else
            {
                Log.Warning("failed to TryCastShot");
            }
            this.burstShotsLeft = 0;
            return(result);
        }