public void CheckStruckOre(IntVec3 justMinedPos, ThingDef justMinedDef, Thing miner)
 {
     if (miner.Faction != Faction.OfPlayer)
     {
         return;
     }
     for (int i = 0; i < 4; i++)
     {
         IntVec3 intVec = justMinedPos + GenAdj.CardinalDirections[i];
         if (intVec.InBounds(miner.Map))
         {
             Building edifice = intVec.GetEdifice(miner.Map);
             if (edifice != null && edifice.def != justMinedDef && MineStrikeManager.MineableIsValuable(edifice.def) && !this.AlreadyVisibleNearby(intVec, miner.Map, edifice.def) && !this.RecentlyStruck(intVec, edifice.def))
             {
                 StrikeRecord item = default(StrikeRecord);
                 item.cell      = intVec;
                 item.def       = edifice.def;
                 item.ticksGame = Find.TickManager.TicksGame;
                 this.strikeRecords.Add(item);
                 Messages.Message("StruckMineable".Translate(new object[]
                 {
                     edifice.def.label
                 }), edifice, MessageTypeDefOf.PositiveEvent, true);
                 TaleRecorder.RecordTale(TaleDefOf.StruckMineable, new object[]
                 {
                     miner,
                     edifice
                 });
             }
         }
     }
 }
Exemplo n.º 2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnCellMissingDesignation(TargetIndex.A, DesignationDefOf.Mine);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil mine = new Toil();

            mine.tickAction = delegate
            {
                Pawn  actor      = mine.actor;
                Thing mineTarget = this.$this.MineTarget;
                if (this.$this.ticksToPickHit < -100)
                {
                    this.$this.ResetTicksToPickHit();
                }
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Mining, 0.11f, false);
                }
                this.$this.ticksToPickHit--;
                if (this.$this.ticksToPickHit <= 0)
                {
                    IntVec3 position = mineTarget.Position;
                    if (this.$this.effecter == null)
                    {
                        this.$this.effecter = EffecterDefOf.Mine.Spawn();
                    }
                    this.$this.effecter.Trigger(actor, mineTarget);
                    int      num      = 80;
                    Mineable mineable = mineTarget as Mineable;
                    if (mineable == null || mineTarget.HitPoints > num)
                    {
                        DamageDef  mining = DamageDefOf.Mining;
                        int        amount = num;
                        Pawn       actor2 = mine.actor;
                        DamageInfo dinfo  = new DamageInfo(mining, amount, -1f, actor2, null, null, DamageInfo.SourceCategory.ThingOrUnknown);
                        mineTarget.TakeDamage(dinfo);
                    }
                    else
                    {
                        mineable.Notify_TookMiningDamage(mineTarget.HitPoints, mine.actor);
                        mineable.HitPoints = 0;
                        mineable.DestroyMined(actor);
                    }
                    if (mineTarget.Destroyed)
                    {
                        actor.Map.mineStrikeManager.CheckStruckOre(position, mineTarget.def, actor);
                        actor.records.Increment(RecordDefOf.CellsMined);
                        if (this.$this.pawn.Faction != Faction.OfPlayer)
                        {
                            List <Thing> thingList = position.GetThingList(this.$this.Map);
                            for (int i = 0; i < thingList.Count; i++)
                            {
                                thingList[i].SetForbidden(true, false);
                            }
                        }
                        if (this.$this.pawn.Faction == Faction.OfPlayer && MineStrikeManager.MineableIsVeryValuable(mineTarget.def))
                        {
                            TaleRecorder.RecordTale(TaleDefOf.MinedValuable, new object[]
                            {
                                this.$this.pawn,
                                mineTarget.def.building.mineableThing
                            });
                        }
                        if (this.$this.pawn.Faction == Faction.OfPlayer && MineStrikeManager.MineableIsValuable(mineTarget.def) && !this.$this.pawn.Map.IsPlayerHome)
                        {
                            TaleRecorder.RecordTale(TaleDefOf.CaravanRemoteMining, new object[]
                            {
                                this.$this.pawn,
                                mineTarget.def.building.mineableThing
                            });
                        }
                        this.$this.ReadyForNextToil();
                        return;
                    }
                    this.$this.ResetTicksToPickHit();
                }
            };
            mine.defaultCompleteMode = ToilCompleteMode.Never;
            mine.WithProgressBar(TargetIndex.A, () => 1f - (float)this.$this.MineTarget.HitPoints / (float)this.$this.MineTarget.MaxHitPoints, false, -0.5f);
            mine.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            yield return(mine);
        }
Exemplo n.º 3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnCellMissingDesignation(TargetIndex.A, DesignationDefOf.Mine);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil mine = new Toil();

            mine.tickAction = delegate
            {
                Pawn  actor      = mine.actor;
                Thing mineTarget = MineTarget;
                if (ticksToPickHit < -100)
                {
                    ResetTicksToPickHit();
                }
                if (actor.skills != null && (mineTarget.Faction != actor.Faction || actor.Faction == null))
                {
                    actor.skills.Learn(SkillDefOf.Mining, 0.07f);
                }
                ticksToPickHit--;
                if (ticksToPickHit <= 0)
                {
                    IntVec3 position = mineTarget.Position;
                    if (effecter == null)
                    {
                        effecter = EffecterDefOf.Mine.Spawn();
                    }
                    effecter.Trigger(actor, mineTarget);
                    int      num      = (mineTarget.def.building.isNaturalRock ? 80 : 40);
                    Mineable mineable = mineTarget as Mineable;
                    if (mineable == null || mineTarget.HitPoints > num)
                    {
                        DamageInfo dinfo = new DamageInfo(DamageDefOf.Mining, num, 0f, -1f, mine.actor);
                        mineTarget.TakeDamage(dinfo);
                    }
                    else
                    {
                        mineable.Notify_TookMiningDamage(mineTarget.HitPoints, mine.actor);
                        mineable.HitPoints = 0;
                        mineable.DestroyMined(actor);
                    }
                    if (mineTarget.Destroyed)
                    {
                        actor.Map.mineStrikeManager.CheckStruckOre(position, mineTarget.def, actor);
                        actor.records.Increment(RecordDefOf.CellsMined);
                        if (pawn.Faction != Faction.OfPlayer)
                        {
                            List <Thing> thingList = position.GetThingList(base.Map);
                            for (int i = 0; i < thingList.Count; i++)
                            {
                                thingList[i].SetForbidden(value: true, warnOnFail: false);
                            }
                        }
                        if (pawn.Faction == Faction.OfPlayer && MineStrikeManager.MineableIsVeryValuable(mineTarget.def))
                        {
                            TaleRecorder.RecordTale(TaleDefOf.MinedValuable, pawn, mineTarget.def.building.mineableThing);
                        }
                        if (pawn.Faction == Faction.OfPlayer && MineStrikeManager.MineableIsValuable(mineTarget.def) && !pawn.Map.IsPlayerHome)
                        {
                            TaleRecorder.RecordTale(TaleDefOf.CaravanRemoteMining, pawn, mineTarget.def.building.mineableThing);
                        }
                        ReadyForNextToil();
                    }
                    else
                    {
                        ResetTicksToPickHit();
                    }
                }
            };
            mine.defaultCompleteMode = ToilCompleteMode.Never;
            mine.WithProgressBar(TargetIndex.A, () => 1f - (float)MineTarget.HitPoints / (float)MineTarget.MaxHitPoints);
            mine.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            mine.activeSkill = () => SkillDefOf.Mining;
            yield return(mine);
        }