Ejemplo n.º 1
0
        private static void EndGameCondition()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (GameCondition activeCondition in Find.CurrentMap.gameConditionManager.ActiveConditions)
            {
                GameCondition localMc = activeCondition;
                list.Add(new DebugMenuOption(localMc.LabelCap, DebugMenuOptionMode.Action, delegate
                {
                    localMc.End();
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
Ejemplo n.º 2
0
        public override void End()
        {
            for (int i = 0; i < spawnedThings.Count; i++)
            {
                Pawn p = spawnedThings[i];
                if (!p.DestroyedOrNull())
                {
                    if (p.Map != null)
                    {
                        p.Map.weatherManager.eventHandler.AddEvent(new TM_WeatherEvent_MeshFlash(p.Map, p.Position, TM_MatPool.redLightning));
                    }
                    p.Destroy(DestroyMode.Vanish);
                }
            }
            List <GameCondition> gcs      = new List <GameCondition>();
            GameCondition        gcClouds = null;
            GameCondition        gcVW     = null;

            gcs = this.SingleMap.GameConditionManager.ActiveConditions;
            for (int i = 0; i < gcs.Count; i++)
            {
                if (gcs[i].def == TorannMagicDefOf.DarkClouds)
                {
                    gcClouds = gcs[i];
                }
                else if (gcs[i].def == GameConditionDefOf.VolcanicWinter)
                {
                    gcVW = gcs[i];
                }
            }
            if (gcClouds != null)
            {
                gcClouds.End();
            }
            if (gcVW != null)
            {
                gcVW.End();
            }
            MagicMapComponent mmc = this.SingleMap.GetComponent <MagicMapComponent>();

            if (mmc != null)
            {
                mmc.allowAllIncidents = false;
            }
            base.End();
        }
Ejemplo n.º 3
0
        protected override bool TryCastShot()
        {
            bool flag   = false;
            Pawn caster = base.CasterPawn;

            CompAbilityUserMagic comp = caster.GetComp <CompAbilityUserMagic>();

            pwrVal    = comp.MagicData.MagicPowerSkill_AlterFate.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_AlterFate_pwr").level;
            arcaneDmg = comp.arcaneDmg;

            if (comp.predictionIncidentDef != null)
            {
                if (Rand.Chance((.25f + (.05f * pwrVal)) * this.arcaneDmg)) //success end
                {
                    //Log.Message("remove event");
                    List <QueuedIncident> iQue = Traverse.Create(root: Find.Storyteller.incidentQueue).Field(name: "queuedIncidents").GetValue <List <QueuedIncident> >();
                    if (iQue != null && iQue.Count > 0)
                    {
                        for (int i = 0; i < iQue.Count; i++)
                        {
                            //Log.Message("checking ique " + iQue[i].FiringIncident.def.defName + " against " + comp.predictionIncidentDef.defName);
                            if (iQue[i].FiringIncident.def == comp.predictionIncidentDef)
                            {
                                //Log.Message("Removing incident " + iQue[i].FiringIncident.def.defName);
                                iQue.Remove(iQue[i]);
                                if (Rand.Chance(.6f + (.1f * pwrVal)))
                                {
                                    this.confident = true;
                                }
                                else if (Rand.Chance(.1f))
                                {
                                    this.uneasy = true;
                                }
                                else
                                {
                                    this.unsure = true;
                                }
                                break;
                            }
                        }
                    }
                }
                else if (Rand.Chance(.2f - (.02f * pwrVal))) //shifting incident
                {
                    //Log.Message("shift event");
                    List <QueuedIncident> iQue = Traverse.Create(root: Find.Storyteller.incidentQueue).Field(name: "queuedIncidents").GetValue <List <QueuedIncident> >();
                    if (iQue != null && iQue.Count > 0)
                    {
                        for (int i = 0; i < iQue.Count; i++)
                        {
                            //Log.Message("checking ique " + iQue[i].FiringIncident.def.defName + " against " + comp.predictionIncidentDef.defName);
                            if (iQue[i].FiringIncident.def == comp.predictionIncidentDef)
                            {
                                //Log.Message("replacing incident " + iQue[i].FiringIncident.def.defName);
                                iQue.Remove(iQue[i]);
                            }
                        }
                    }

                    IEnumerable <IncidentDef> enumerable = from def in DefDatabase <IncidentDef> .AllDefs
                                                           where (def != comp.predictionIncidentDef && def.TargetAllowed(this.CasterPawn.Map))
                                                           orderby Rand.ValueSeeded(Find.TickManager.TicksGame)
                                                           select def;

                    foreach (IncidentDef item in enumerable)
                    {
                        //Log.Message("checking incident " + item.defName);
                        IncidentDef   localDef = item;
                        IncidentParms parms    = StorytellerUtility.DefaultParmsNow(localDef.category, this.CasterPawn.Map);
                        if (localDef.Worker.CanFireNow(parms))
                        {
                            QueuedIncident iq = new QueuedIncident(new FiringIncident(localDef, null, parms), comp.predictionTick);
                            Find.Storyteller.incidentQueue.Add(iq);
                            //Log.Message("queueing incident " + localDef.defName + " in " + comp.predictionTick + " ticks");
                            //localDef.Worker.TryExecute(parms);
                            if (Rand.Chance(.6f + (.1f * pwrVal)))
                            {
                                this.uneasy = true;
                            }
                            else if (Rand.Chance(.1f))
                            {
                                this.confident = true;
                            }
                            else
                            {
                                this.unsure = true;
                            }
                            break;
                        }
                    }
                }
                else if (Rand.Chance(.11f - (.011f * pwrVal))) //add another event
                {
                    //Log.Message("add event");
                    IEnumerable <IncidentDef> enumerable = from def in DefDatabase <IncidentDef> .AllDefs
                                                           where (def != comp.predictionIncidentDef && def.TargetAllowed(this.CasterPawn.Map))
                                                           orderby Rand.ValueSeeded(Find.TickManager.TicksGame)
                                                           select def;

                    foreach (IncidentDef item in enumerable)
                    {
                        //Log.Message("checking incident " + item.defName);
                        IncidentDef   localDef = item;
                        IncidentParms parms    = StorytellerUtility.DefaultParmsNow(localDef.category, this.CasterPawn.Map);
                        if (localDef.Worker.CanFireNow(parms))
                        {
                            QueuedIncident iq = new QueuedIncident(new FiringIncident(localDef, null, parms), comp.predictionTick + Rand.Range(-500, 10000));

                            Find.Storyteller.incidentQueue.Add(iq);
                            //Log.Message("queueing incident " + localDef.defName + " in " + comp.predictionTick + " ticks");
                            //localDef.Worker.TryExecute(parms);
                            if (Rand.Chance(.4f + (.1f * pwrVal)))
                            {
                                this.uneasy = true;
                            }
                            else if (Rand.Chance(.2f))
                            {
                                this.terrified = true;
                            }
                            else
                            {
                                this.unsure = true;
                            }
                            break;
                        }
                    }
                }
                else if (Rand.Chance(.05f - (.005f * pwrVal))) //butterfly effect
                {
                    int eventCount     = Rand.RangeInclusive(1, 5);
                    int butterflyCount = 0;
                    //Log.Message("butteryfly event");
                    IEnumerable <IncidentDef> enumerable = from def in DefDatabase <IncidentDef> .AllDefs
                                                           where (def.TargetAllowed(this.CasterPawn.Map))
                                                           orderby Rand.ValueSeeded(Find.TickManager.TicksGame)
                                                           select def;

                    foreach (IncidentDef item in enumerable)
                    {
                        //Log.Message("checking incident " + item.defName);
                        IncidentDef   localDef = item;
                        IncidentParms parms    = StorytellerUtility.DefaultParmsNow(localDef.category, this.CasterPawn.Map);
                        if (localDef.Worker.CanFireNow(parms))
                        {
                            int            eventTick = Find.TickManager.TicksGame + Rand.Range(0, 3600);
                            QueuedIncident iq        = new QueuedIncident(new FiringIncident(localDef, null, parms), eventTick);
                            Find.Storyteller.incidentQueue.Add(iq);
                            //Log.Message("queueing incident " + localDef.defName + " in " + eventTick + " ticks");
                            //localDef.Worker.TryExecute(parms);
                            butterflyCount++;
                            if (butterflyCount > eventCount)
                            {
                                if (Rand.Chance(.6f + (.1f * pwrVal)))
                                {
                                    this.terrified = true;
                                }
                                else if (Rand.Chance(.3f))
                                {
                                    this.uneasy = true;
                                }
                                else
                                {
                                    this.unsure = true;
                                }
                                break;
                            }
                        }
                    }
                }
                else // failed
                {
                    //Log.Message("failed event");
                    if (Rand.Chance(.6f + (.1f * pwrVal)))
                    {
                        this.unsure = true;
                    }
                    else if (Rand.Chance(.1f))
                    {
                        this.uneasy = true;
                    }
                    else
                    {
                        this.confident = true;
                    }
                    //Messages.Message("TM_AlterGameConditionFailed".Translate(this.CasterPawn.LabelShort, localGC.Label), MessageTypeDefOf.NeutralEvent);
                }
                DisplayConfidence(comp.predictionIncidentDef.label);
            }
            else if (pwrVal >= 3)
            {
                if (this.CasterPawn.Map.GameConditionManager.ActiveConditions.Count > 0)
                {
                    GameCondition localGC = null;
                    foreach (GameCondition activeCondition in this.CasterPawn.Map.GameConditionManager.ActiveConditions)
                    {
                        localGC = activeCondition;
                        if (activeCondition.TicksPassed < (2500 + (250 * pwrVal)))
                        {
                            if (Rand.Chance(.25f + (.05f * pwrVal))) //success
                            {
                                Messages.Message("TM_EndingGameCondition".Translate(this.CasterPawn.LabelShort, localGC.Label), MessageTypeDefOf.PositiveEvent);
                                localGC.End();
                            }
                            else if (Rand.Chance(.2f - (.02f * pwrVal))) //shifting game condition
                            {
                                IEnumerable <GameConditionDef> enumerable = from def in DefDatabase <GameConditionDef> .AllDefs
                                                                            where (def != localGC.def)
                                                                            select def;

                                GameConditionDef newGCdef = enumerable.RandomElement();
                                GameConditionMaker.MakeCondition(newGCdef);
                                Messages.Message("TM_GameConditionChanged".Translate(this.CasterPawn.LabelShort, localGC.Label, newGCdef.label), MessageTypeDefOf.NeutralEvent);
                                localGC.End();
                            }
                            else if (Rand.Chance(.02f)) //permanent
                            {
                                Messages.Message("TM_GameConditionMadePermanent".Translate(localGC.Label), MessageTypeDefOf.NeutralEvent);
                                localGC.Permanent = true;
                            }
                            else if (Rand.Chance(.15f - (.015f * pwrVal))) //add another event
                            {
                                IEnumerable <GameConditionDef> enumerable = from def in DefDatabase <GameConditionDef> .AllDefs
                                                                            where (def != localGC.def)
                                                                            select def;
                                GameConditionDef newGCdef = enumerable.RandomElement();
                                GameConditionMaker.MakeCondition(newGCdef);
                                Messages.Message("TM_GameConditionAdded".Translate(this.CasterPawn.LabelShort, newGCdef.label, localGC.Label), MessageTypeDefOf.NeutralEvent);
                            }
                            else
                            {
                                Messages.Message("TM_AlterGameConditionFailed".Translate(this.CasterPawn.LabelShort, localGC.Label), MessageTypeDefOf.NeutralEvent);
                            }
                            break;
                        }
                    }
                }
            }
            TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_AlterFate, CasterPawn.DrawPos, this.CasterPawn.Map, 1f, .2f, 0, 1f, Rand.Range(-500, 500), 0, 0, Rand.Range(0, 360));
            TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_AlterFate, CasterPawn.DrawPos, this.CasterPawn.Map, 2.5f, .2f, .1f, .8f, Rand.Range(-500, 500), 0, 0, Rand.Range(0, 360));
            TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_AlterFate, CasterPawn.DrawPos, this.CasterPawn.Map, 6f, 0f, .2f, .6f, Rand.Range(-500, 500), 0, 0, Rand.Range(0, 360));
            this.PostCastShot(flag, out flag);
            return(flag);
        }
        public static void TryGenerateMapCondition(GameConditionDef gameCondition, Map map, int duration = -1, bool permanent = false, bool remove = false, bool add = false, bool reduce = false, bool increase = false, bool random = false)
        {
            GameCondition        gc     = null;
            List <GameCondition> gcList = new List <GameCondition>();

            map.GameConditionManager.GetAllGameConditionsAffectingMap(map, gcList);
            if (random && !add && gcList != null && gcList.Count > 0)
            {
                gc = map.GameConditionManager.GetActiveCondition(gcList.RandomElement().def);
            }
            else if (gameCondition != null && map.GameConditionManager.ConditionIsActive(gameCondition))
            {
                gc = map.GameConditionManager.GetActiveCondition(gameCondition);
            }
            else if (gameCondition != null)
            {
                gc = GameConditionMaker.MakeCondition(gameCondition, duration);
            }
            else if (gameCondition == null && random && add)
            {
                IEnumerable <GameConditionDef> enumerable = from def in DefDatabase <GameConditionDef> .AllDefs
                                                            where true
                                                            select def;
                gc = GameConditionMaker.MakeCondition(enumerable.RandomElement());
            }

            if (gc != null)
            {
                if (permanent)
                {
                    gc.Permanent = true;
                }
                else if (remove)
                {
                    gc.End();
                }
                else if (duration != -1)
                {
                    if (reduce)
                    {
                        gc.Duration -= duration;
                        if (gc.Duration < 0)
                        {
                            gc.End();
                        }
                    }
                    else if (increase)
                    {
                        gc.Duration += duration;
                    }
                    else
                    {
                        gc.Duration = duration;
                    }
                }
                map.gameConditionManager.RegisterCondition(gc);
            }
            else
            {
                Messages.Message("No game condition found.", MessageTypeDefOf.RejectInput);
            }
        }