Beispiel #1
0
 void InvokeEntity(string[] args)
 {
     if (args.Length < 2)
     {
         error("Error: voke <target>");
     }
     else
     {
         ConsoleEntity match = SingleActiveEntity(args[1]);
         match?.Invoke(args);
     }
 }
Beispiel #2
0
        ConsoleEntity SingleActiveEntity(string ident)
        {
            if (ident[0] == '@')
            {
                int index = 0;
                if (ident.Length > 1)
                {
                    int.TryParse(ident.Substring(1), out index);
                }
                if (index < _aliases.Length)
                {
                    return(_aliases[index]);
                }
                error("Invalid shortcut '{0}'.", ident);
                return(null);
            }

            Dictionary <string, ConsoleEntity> ents = ActiveEntities();

            if (!ents.TryGetValue(ident, out ConsoleEntity ent) || ent == null)
            {
                error("Unrecognized entity '{0}'.", ident);
                return(null);
            }

            string[] matchingEnts = ConsoleUtilities.Lookup(ident, ents);
            if (matchingEnts.Length > 1)
            {
                warn("Ambiguous entity '{0}'. Potential invokable matches:", ident);
                foreach (string me in matchingEnts)
                {
                    log("  " + me);
                }
                return(null);
            }

            ConsoleEntity match = ents[matchingEnts[0]];

            if (match?.Entity != null)
            {
                return(match);
            }

            warn("Entity '{0}' is null", matchingEnts[0]);
            return(null);
        }
Beispiel #3
0
        void CollectIncidents()
        {
            log("Loading incidents...");
            List <string> incidents = new List <string>();

            IncidentConfig[] configs   = Resources.FindObjectsOfTypeAll <IncidentConfig>();
            PartyConfig[]    parties   = Resources.LoadAll <PartyConfig>("Parties");
            LocationConfig[] locations = Resources.FindObjectsOfTypeAll <LocationConfig>();
            PlayerConfig[]   players   = Resources.FindObjectsOfTypeAll <PlayerConfig>();

            incidents.AddRange(configs.Select(c => c.name));
            foreach (PartyConfig party in parties)
            {
                if (party.IntroIncident != null)
                {
                    incidents.Add(party.IntroIncident.name);
                }
                if (party.ExitIncident != null)
                {
                    incidents.Add(party.ExitIncident.name);
                }
                incidents.AddRange(party.RequiredIncidents.Select(p => p?.name).Where(c => c != null));
                incidents.AddRange(party.SupplementalIncidents.Select(p => p.name));
            }
            foreach (LocationConfig location in locations)
            {
                if (location.IntroIncidentConfig != null)
                {
                    incidents.Add(location.IntroIncidentConfig.name);
                }
                incidents.AddRange(location.StoryIncidentConfigs.Select(i => i.name));
            }
            foreach (PlayerConfig player in players)
            {
                incidents.AddRange(player.Incidents.Select(i => i.name));
            }

            foreach (string incident in incidents)
            {
                var id = "incident." + incident;
                _entities[id] = new ConsoleEntity(incident.ToString(), (args) => { InvokeIncident(incident, args); });
            }
        }
Beispiel #4
0
        void CollectEntities()
        {
            // Incidents already taken care of
            FactionModel factions = AmbitionApp.GetModel <FactionModel>();

            _entities["factions"]  = new ConsoleEntity(factions);
            _entities["game"]      = new ConsoleEntity(AmbitionApp.GetModel <GameModel>());
            _entities["calendar"]  = new ConsoleEntity(AmbitionApp.GetModel <CalendarModel>());
            _entities["inventory"] = new ConsoleEntity(AmbitionApp.GetModel <InventoryModel>());

            foreach (FactionVO faction in factions.Factions.Values)
            {
                _entities["faction." + faction.Type.ToString().ToLower()] =
                    new ConsoleEntity(faction, (args) => InvokeFaction(faction, args));
            }

            _entities["uflow"]      = new ConsoleEntity(AmbitionApp.GetService <UFlowSvc>());
            _entities["servants"]   = new ConsoleEntity(AmbitionApp.GetModel <ServantModel>());
            _entities["characters"] = new ConsoleEntity(AmbitionApp.GetModel <CharacterModel>());
        }
Beispiel #5
0
        Dictionary <string, ConsoleEntity> ActiveEntities()
        {
            var transientEntities = _entities.ToDictionary(entry => entry.Key,
                                                           entry => entry.Value);

            // Add entities that are likely to change here, like currently active UFlow machines

            // Live UFlow machines
            var ufs = AmbitionApp.GetService <UFlowSvc>();

            foreach (var machine in ufs.GetAllFlows())
            {
                if (machine != null)
                {
                    transientEntities["machine." + machine.FlowID] = new ConsoleEntity(machine);
                }
            }

            // Servants, on staff or otherwise
            foreach (var servant in AmbitionApp.GetModel <ServantModel>().GetAllServants())
            {
                transientEntities[servant.ID] = new ConsoleEntity(servant);
            }

            // Characters

            foreach (var ckv in AmbitionApp.GetModel <CharacterModel>().Characters)
            {
                transientEntities["character." + ckv.Value.ID] = new ConsoleEntity(ckv.Value);
            }

            // party, if live
            var pm = AmbitionApp.GetModel <PartyModel>();

            if (pm != null)
            {
                transientEntities["party"] = new ConsoleEntity(pm);
            }

            return(transientEntities);
        }