Esempio n. 1
0
        public static Toil TakeEnchantGem(TargetIndex ind, Func <int> countGetter)
        {
            Toil takeThing = new Toil();

            takeThing.initAction = delegate
            {
                Pawn  actor = takeThing.actor;
                Thing thing = actor.CurJob.GetTarget(ind).Thing;
                Toils_Enchant.ErrorCheck(actor, thing);
                int num = Mathf.Min(countGetter(), thing.stackCount);
                if (num <= 0)
                {
                    actor.jobs.curDriver.ReadyForNextToil();
                }
                else
                {
                    CompEnchant comp = actor.GetComp <CompEnchant>();
                    if (comp != null)
                    {
                        if (comp.enchantingContainer.Count > 0)
                        {
                            comp.enchantingContainer.TryDropAll(actor.Position, actor.Map, ThingPlaceMode.Near);
                        }
                        comp.enchantingContainer.TryAdd(thing.SplitOff(1), true);
                        thing.def.soundPickup.PlayOneShot(new TargetInfo(actor.Position, actor.Map, false));
                    }
                    else
                    {
                        Log.Message("comp was null");
                    }
                }
            };
            return(takeThing);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch));  //probably remove, drop should be immediate at location

            Toil drop = new Toil();

            drop.initAction = delegate
            {
                Pawn        actor = drop.actor;
                CompEnchant comp  = actor.TryGetComp <CompEnchant>();
                comp.enchantingContainer.TryDropAll(actor.Position, actor.Map, ThingPlaceMode.Near);
            };
            drop.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(drop);
        }
Esempio n. 3
0
        //public override void PostDeSpawn(Map map)
        //{
        //    base.PostDeSpawn(map);
        //    enchantingContainer?.TryDropAll(parent.Position, map, ThingPlaceMode.Near, null, null);
        //}

        public override void Initialize(CompProperties props)
        {
            base.Initialize(props);
            Pawn        pawn = this.parent as Pawn;
            CompEnchant comp = pawn.TryGetComp <CompEnchant>();

            //try
            //{
            //    bool flag = comp.enchantingContainer.Count > 0;
            //}
            //catch(NullReferenceException ex)
            //{
            //    this.enchantingContainer = new ThingOwner<Thing>();
            //}
            if (initialize && comp.enchantingContainer == null)
            {
                this.enchantingContainer = new ThingOwner <Thing>();
                this.initialize          = false;
            }
        }
Esempio n. 4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);


            Toil gotoThing = new Toil();

            gotoThing.initAction = delegate
            {
                this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.Touch);
            };
            gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(gotoThing);

            Toil enchanting = new Toil();//actions performed to enchant an item

            enchanting.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            enchanting.FailOnDestroyedOrNull(TargetIndex.A);
            enchanting.initAction = delegate
            {
                actor    = enchanting.actor;
                thing    = TargetThingA;
                thingLoc = thing.Position;
                if (!(thing.def.IsMeleeWeapon || thing.def.IsRangedWeapon || thing.def.IsApparel))
                {
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                    Log.Message("Failed to initialize enchanting - invalid item type.");
                }
                else if (thing.def.defName.Contains("TM_Artifact"))
                {
                    Messages.Message("TM_CannotEnchantArtifact".Translate(
                                         actor.LabelShort,
                                         thing.LabelShort
                                         ), MessageTypeDefOf.RejectInput);
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                }
            };
            enchanting.tickAction = delegate
            {
                if (thing.Position != thingLoc || thing.Destroyed)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                    Log.Message("Failed to complete enchanting - item being enchanted not at enchanting location or destroyed");
                }
                if (Find.TickManager.TicksGame % 5 == 0)
                {
                    TM_MoteMaker.ThrowEnchantingMote(TargetLocA.ToVector3Shifted(), actor.Map, .6f);
                }
            };
            enchanting.WithProgressBar(TargetIndex.A, delegate
            {
                if (thing == null)
                {
                    return(1f);
                }
                return(1f - (float)enchanting.actor.jobs.curDriver.ticksLeftThisToil / 240);
            }, false, 0f);
            enchanting.defaultCompleteMode = ToilCompleteMode.Delay;
            enchanting.defaultDuration     = 240;
            enchanting.AddFinishAction(delegate
            {
                CompEnchantedItem enchantment = thing.TryGetComp <CompEnchantedItem>();
                CompEnchant enchantingItem    = actor.TryGetComp <CompEnchant>();
                CompAbilityUserMagic pawnComp = actor.TryGetComp <CompAbilityUserMagic>();
                if (enchantment != null && enchantingItem != null && enchanting.actor.jobs.curDriver.ticksLeftThisToil < 1)
                {
                    if (EnchantItem(enchantingItem.enchantingContainer[0], enchantment))
                    {
                        enchantingItem.enchantingContainer[0].SplitOff(1).Destroy(DestroyMode.Vanish);
                        pawnComp.Mana.CurLevel -= .5f;
                        int num = Rand.Range(130, 180);
                        pawnComp.MagicUserXP += num;
                        MoteMaker.ThrowText(actor.DrawPos, actor.Map, "XP +" + num, -1f);
                        MoteMaker.ThrowText(TargetLocA.ToVector3Shifted(), actor.Map, "TM_Enchanted".Translate(), -1);
                        SoundStarter.PlayOneShotOnCamera(TorannMagicDefOf.ItemEnchanted, null);
                    }
                    else
                    {
                        Messages.Message("TM_NothingEnchanted".Translate(actor.LabelShort, thing.LabelShort, enchantingItem.enchantingContainer[0].LabelShort), MessageTypeDefOf.RejectInput);
                    }

                    //DestroyEnchantingStone(enchantingItem.innerContainer[0]);
                }
                else
                {
                    Log.Message("Detected null enchanting comp.");
                }
            });
            yield return(enchanting);
        }