Example #1
0
 protected void processCommunicable(ICommunicable comm, Pawn myPawn, List <FloatMenuOption> result)
 {
     if (comm != null)
     {
         string text   = "CallOnRadio".Translate(comm.GetCallLabel());
         Action action = delegate {
             ICommunicable localCommTarget = comm;
             if (!Building_OrbitalTradeBeacon.AllPowered(this.Map).Any <Building_OrbitalTradeBeacon>())
             {
                 Messages.Message("MessageNeedBeaconToTradeWithShip".Translate(), this, MessageTypeDefOf.RejectInput);
                 return;
             }
             if (comm is ILoadReferenceable)
             {
                 //if we communicate with an object that can be saved we create a job.
                 Job job = new Job(JobDefOf.UseCommsConsole, this);
                 job.commTarget = localCommTarget;
                 myPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
             }
             else
             {
                 //if we cannot save the com target we avoid creating a job and start the communication immediately.
                 localCommTarget.TryOpenComms(myPawn);
             }
             PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.OpeningComms, KnowledgeAmount.Total);
         };
         result.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text, action, MenuOptionPriority.InitiateSocial, null, null, 0f, null, null), myPawn, this));
     }
 }
Example #2
0
        public static void LaunchThingsOfType(ThingDef resDef, int debt, TradeShip trader)
        {
            while (debt > 0)
            {
                Thing thing = null;
                foreach (Building_OrbitalTradeBeacon current in Building_OrbitalTradeBeacon.AllPowered())
                {
                    foreach (IntVec3 current2 in current.TradeableCells)
                    {
                        foreach (Thing current3 in Find.ThingGrid.ThingsAt(current2))
                        {
                            if (current3.def == resDef)
                            {
                                thing = current3;
                                goto IL_C4;
                            }
                        }
                    }
                }
IL_C4:
                if (thing == null)
                {
                    Log.Error("Could not find any " + resDef + " to transfer to trader.");
                    break;
                }
                int   num    = Math.Min(debt, thing.stackCount);
                Thing thing2 = thing.SplitOff(num);
                if (trader != null)
                {
                    trader.AddToStock(thing2);
                }
                debt -= num;
            }
        }
Example #3
0
 static bool Prefix(Building_OrbitalTradeBeacon __instance, ref IEnumerable <IntVec3> __result)
 {
     if (!withinOverrideCall && __instance is Building_CustomTradeBeacon inst)
     {
         try
         {
             withinOverrideCall = true;
             __result           = inst.TradeableCells();
         }
         finally
         {
             withinOverrideCall = false;
         }
         return(false);
     }
     return(true);
 }
Example #4
0
        public override IEnumerable <FloatMenuOption> CompFloatMenuOptions(Pawn myPawn)
        {
            foreach (var g in base.CompFloatMenuOptions(myPawn))
            {
                yield return(g);
            }

            if (!myPawn.CanReach(parent, PathEndMode.InteractionCell, Danger.Some))
            {
                yield return(new FloatMenuOption("CannotUseNoPath".Translate(), null));

                yield break;
            }
            if (parent.Spawned && parent.Map.gameConditionManager.ConditionIsActive(GameConditionDefOf.SolarFlare))
            {
                yield return(new FloatMenuOption("CannotUseSolarFlare".Translate(), null));

                yield break;
            }
            if (Props.usesPower && (!parent.TryGetComp <CompPowerTrader>()?.PowerOn ?? false))
            {
                yield return(new FloatMenuOption("CannotUseNoPower".Translate(), null));

                yield break;
            }
            if (!myPawn.health.capacities.CapableOf(PawnCapacityDefOf.Talking))
            {
                yield return(new FloatMenuOption("CannotUseReason".Translate("IncapableOfCapacity".Translate(PawnCapacityDefOf.Talking.label)), null));

                yield break;
            }
            if (myPawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled)
            {
                yield return(new FloatMenuOption("CannotPrioritizeWorkTypeDisabled".Translate(new object[]
                {
                    SkillDefOf.Social.LabelCap
                }), null));

                yield break;
            }
            if (!this.CanUseCommsNow)
            {
                Log.Error(myPawn + " could not use " + parent.Label + " for unknown reason.");
                yield return(new FloatMenuOption("Cannot use now", null));

                yield break;
            }

            var list       = new List <FloatMenuOption>();
            var enumerable = myPawn.Map.passingShipManager.passingShips.Cast <ICommunicable>().Concat(Find.FactionManager.AllFactionsInViewOrder.Cast <ICommunicable>());

            using (var enumerator = enumerable.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    var localCommTarget = enumerator.Current;
                    if (localCommTarget == null)
                    {
                        continue;
                    }
                    var text = "CallOnRadio".Translate(localCommTarget.GetCallLabel());
                    if (localCommTarget is Faction faction)
                    {
                        if (faction.IsPlayer)
                        {
                            continue;
                        }
                        if (!LeaderIsAvailableToTalk(faction))
                        {
                            string str;
                            if (faction.leader != null)
                            {
                                str = "LeaderUnavailable".Translate(faction.leader.LabelShort);
                            }
                            else
                            {
                                str = "LeaderUnavailableNoLeader".Translate();
                            }
                            list.Add(new FloatMenuOption(text + " (" + str + ")", null));
                            continue;
                        }
                    }

                    void Action()
                    {
                        if (localCommTarget is TradeShip && !Building_OrbitalTradeBeacon.AllPowered(parent.Map).Any())
                        {
                            Messages.Message("MessageNeedBeaconToTradeWithShip".Translate(), parent, MessageTypeDefOf.RejectInput);
                            return;
                        }
                        UseAct(myPawn, localCommTarget);
                    }

                    list.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text, Action, MenuOptionPriority.InitiateSocial), myPawn, parent, "ReservedBy"));
                }
            }
            foreach (var option in list)
            {
                yield return(option);
            }
            yield break;
        }
        public static IEnumerable <FloatMenuOption> GetFloatMenuOptions(this Building_CommsConsole building, Pawn myPawn)
        {
            /*if (!myPawn.CanReserve(building, 1))
             * {
             *  FloatMenuOption item = new FloatMenuOption("CannotUseReserved".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null);
             *  return new List<FloatMenuOption>
             *  {
             *      item
             *  };
             * }*/
            if (!myPawn.CanReach(building, PathEndMode.InteractionCell, Danger.Some, false, TraverseMode.ByPawn))
            {
                FloatMenuOption item2 = new FloatMenuOption("CannotUseNoPath".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null);
                return(new List <FloatMenuOption>
                {
                    item2
                });
            }
            if (building.Map.mapConditionManager.ConditionIsActive(MapConditionDefOf.SolarFlare))
            {
                FloatMenuOption item3 = new FloatMenuOption("CannotUseSolarFlare".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null);
                return(new List <FloatMenuOption>
                {
                    item3
                });
            }
            if (!building.GetFieldViaReflection <CompPowerTrader>("powerComp").PowerOn)
            {
                FloatMenuOption item4 = new FloatMenuOption("CannotUseNoPower".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null);
                return(new List <FloatMenuOption>
                {
                    item4
                });
            }
            if (!myPawn.health.capacities.CapableOf(PawnCapacityDefOf.Talking))
            {
                FloatMenuOption item5 = new FloatMenuOption("CannotUseReason".Translate(new object[]
                {
                    "IncapableOfCapacity".Translate(new object[]
                    {
                        PawnCapacityDefOf.Talking.label
                    })
                }), null, MenuOptionPriority.Default, null, null, 0f, null);
                return(new List <FloatMenuOption>
                {
                    item5
                });
            }
            if (!building.CanUseCommsNow)
            {
                Log.Error(myPawn + " could not use comm console for unknown reason.");
                FloatMenuOption item6 = new FloatMenuOption("Cannot use now", null, MenuOptionPriority.Default, null, null, 0f, null);
                return(new List <FloatMenuOption>
                {
                    item6
                });
            }
            IEnumerable <ICommunicable> enumerable = myPawn.Map.passingShipManager.passingShips.Cast <ICommunicable>().Concat(Find.FactionManager.AllFactionsInViewOrder.Cast <ICommunicable>());
            List <FloatMenuOption>      list       = new List <FloatMenuOption>();

            foreach (ICommunicable commTarget in enumerable)
            {
                ICommunicable localCommTarget = commTarget;
                string        text            = "CallOnRadio".Translate(new object[]
                {
                    localCommTarget.GetCallLabel()
                });
                Faction faction = localCommTarget as Faction;
                if (faction != null)
                {
                    if (faction.IsPlayer)
                    {
                        continue;
                    }
                    if (!Building_CommsConsole.LeaderIsAvailableToTalk(faction))
                    {
                        list.Add(new FloatMenuOption(text + " (" + "LeaderUnavailable".Translate(new object[]
                        {
                            faction.leader.LabelShort
                        }) + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null));
                        continue;
                    }
                }
                Action action = delegate
                {
                    if (commTarget is TradeShip && !Building_OrbitalTradeBeacon.AllPowered(building.Map).Any <Building_OrbitalTradeBeacon>())
                    {
                        Messages.Message("MessageNeedBeaconToTradeWithShip".Translate(), building, MessageSound.RejectInput);
                        return;
                    }
                    Job job = new Job(JobDefOf.UseCommsConsole, building);
                    job.commTarget = localCommTarget;
                    myPawn.jobs.TryTakeOrderedJob(job);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.OpeningComms, KnowledgeAmount.Total);
                };
                ITWN.PostMenuOption(list,
                                    myPawn,
                                    building,
                                    text,
                                    action,
                                    priority: MenuOptionPriority.InitiateSocial);
            }
            return(list);
        }
Example #6
0
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
        {
            if (!ReachabilityUtility.CanReach(myPawn, this, (PathEndMode)4, (Danger)2, false, 0))
            {
                FloatMenuOption item = new FloatMenuOption(Translator.Translate("CannotUseNoPath"), null, (MenuOptionPriority)4, null, null, 0f, null, null);
                return(new List <FloatMenuOption>
                {
                    item
                });
            }

            if (Spawned && Map.gameConditionManager.ConditionIsActive(GameConditionDefOf.SolarFlare))
            {
                return(new List <FloatMenuOption>
                {
                    new FloatMenuOption(Translator.Translate("CannotUseSolarFlare"), null, (MenuOptionPriority)4, null, null, 0f, null, null)
                });
            }

            if (!myPawn.health.capacities.CapableOf(PawnCapacityDefOf.Talking))
            {
                return(new List <FloatMenuOption>
                {
                    new FloatMenuOption(Translator.Translate("CannotUseReason", new object[]
                    {
                        Translator.Translate("IncapableOfCapacity", new object[]
                        {
                            PawnCapacityDefOf.Talking.label
                        })
                    }), null, (Verse.MenuOptionPriority) 4, null, null, 0f, null, null)
                });
            }

            if (!this.CanUseSignalFireNow)
            {
                Log.Error(myPawn + " could not use comm console for unknown reason.");
                return(new List <FloatMenuOption>
                {
                    new FloatMenuOption("Cannot use now", null, (MenuOptionPriority)4, null, null, 0f, null, null)
                });
            }

            List <FloatMenuOption> list = new List <FloatMenuOption>();

            foreach (ICommunicable commTarget in Find.FactionManager.AllFactionsInViewOrder)
            {
                ICommunicable localCommTarget = commTarget;
                string        text            = Translator.Translate("CallOnRadio", new object[]
                {
                    localCommTarget.GetCallLabel()
                });

                if (localCommTarget is Faction faction)
                {
                    if (faction.IsPlayer)
                    {
                        continue;
                    }
                    if (!LeaderIsAvailableToTalk(faction))
                    {
                        string str;
                        if (faction.leader != null)
                        {
                            str = Translator.Translate("LeaderUnavailable", new object[]
                            {
                                faction.leader.LabelShort
                            });
                        }
                        else
                        {
                            str = Translator.Translate("LeaderUnavailableNoLeader");
                        }
                        list.Add(new FloatMenuOption(text + " (" + str + ")", null, (MenuOptionPriority)4, null, null, 0f, null, null));
                        continue;
                    }
                }
                void action()
                {
                    if (commTarget is TradeShip && !Building_OrbitalTradeBeacon.AllPowered(Map).Any())
                    {
                        Messages.Message(Translator.Translate("MessageNeedBeaconToTradeWithShip"), this, MessageTypeDefOf.RejectInput, false);
                    }
                    else
                    {
                        Job job = new Job(DefDatabase <JobDef> .GetNamed("UseSignalFire", true), this)
                        {
                            commTarget = localCommTarget
                        };
                        myPawn.jobs.TryTakeOrderedJob(job, 0);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.OpeningComms, (KnowledgeAmount)6);
                    }
                }

                list.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text, action, (MenuOptionPriority)7, null, null, 0f, null, null), myPawn, this, "ReservedBy"));
            }
            return(list);
        }