コード例 #1
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);
        }