Beispiel #1
0
        public LocationVO SaveLocation(LocationConfig config)
        {
            if (config == null)
            {
                return(null);
            }

            List <string> incidents = new List <string>();
            IncidentModel story     = AmbitionApp.Story;
            IncidentVO    incident  = config.IntroIncidentConfig?.GetIncident();

            if (incident != null)
            {
                story.Incidents[incident.ID] = incident;
                story.AddDependency(incident, config.name, IncidentType.Location);
            }

            if (config.StoryIncidentConfigs != null)
            {
                foreach (IncidentConfig iconfig in config.StoryIncidentConfigs)
                {
                    incident = iconfig?.GetIncident();
                    if (incident != null)
                    {
                        incidents.Add(incident.ID);
                        story.Incidents[incident.ID] = incident;
                        story.AddDependency(incident, config.name, IncidentType.Location);
                    }
                }
            }

            return(Locations[config.name] = new LocationVO()
            {
                ID = config.name,
                IntroIncident = config.IntroIncidentConfig?.name,
                StoryIncidents = incidents.ToArray(),
                SceneID = config.SceneID,
                IsOneShot = config.OneShot,
                IsDiscoverable = config.IsDiscoverable,
                IsRendezvous = config.IsRendezvous,
                Requirements = config.Requirements ?? new RequirementVO[0]
            });
        }
Beispiel #2
0
        public bool LoadParty(string partyID, out PartyVO party)
        {
            PartyConfig config = Resources.Load <PartyConfig>(Filepath.PARTIES + partyID);

            if (config == null)
            {
                party = null;
                Resources.UnloadUnusedAssets();
                return(false);
            }

            IncidentModel story     = AmbitionApp.Story;
            List <string> incidents = new List <string>();
            IncidentVO    incident  = config.IntroIncident?.GetIncident();
            PartyModel    model     = AmbitionApp.GetModel <PartyModel>();

            party               = new PartyVO(config.name);
            party.Size          = config.Size == PartySize.None ? PartySize.Trivial : config.Size;
            party.IntroIncident = incident?.ID;
            story.AddDependency(incident, config.name, IncidentType.Party);

            incident           = config.ExitIncident?.GetIncident();
            party.ExitIncident = incident?.ID;
            story.AddDependency(incident, config.name, IncidentType.Party);

            if (config.RequiredIncidents != null)
            {
                string[] names    = Enum.GetNames(typeof(PartySize));
                int      index    = Array.IndexOf(names, party.Size.ToString());
                int      numTurns = index < model.NumTurnsByPartySize.Length
                    ? model.NumTurnsByPartySize[index]
                    : model.NumTurnsByPartySize[model.NumTurnsByPartySize.Length - 1];
                if (config.RequiredIncidents.Length > numTurns)
                {
                    numTurns = config.RequiredIncidents.Length;
                    for (int i = model.NumTurnsByPartySize.Length - 1; i > 0; --i)
                    {
                        if (numTurns >= model.NumTurnsByPartySize[i] && i < names.Length)
                        {
                            party.Size = (PartySize)i;
                            break;
                        }
                    }
                }
                foreach (IncidentConfig iconfig in config.RequiredIncidents)
                {
                    incident = iconfig?.GetIncident();
                    incidents.Add(incident?.ID);
                    story.AddDependency(incident, config.name, IncidentType.Party);
                }
            }
            party.RequiredIncidents = incidents.ToArray();

            if (config.SupplementalIncidents != null)
            {
                incidents.Clear();
                foreach (IncidentConfig iconfig in config.SupplementalIncidents)
                {
                    incident = iconfig?.GetIncident();
                    if (incident != null)
                    {
                        incidents.Add(incident?.ID);
                        story.AddDependency(incident, config.name, IncidentType.Party);
                    }
                }
            }
            party.SupplementalIncidents = incidents.ToArray();

            if (config.Date > 0)
            {
                party.Day = new DateTime(config.Date).Subtract(AmbitionApp.Calendar.StartDate).Days;
            }
            party.Faction = config.Faction == FactionType.None ? party.Faction : config.Faction;
            party.RSVP    = config.RSVP == RSVP.Required || party.RSVP == RSVP.Required
                ? RSVP.Required
                : party.RSVP == RSVP.New
                ? config.RSVP
                : config.RSVP == RSVP.New
                ? party.RSVP
                : config.RSVP;
            if (!string.IsNullOrWhiteSpace(config.Host))
            {
                party.Host = config.Host;
            }

            party.Requirements = config.Requirements;
            party.Map          = config.Map?.name;
            config             = null;
            Resources.UnloadUnusedAssets();
            return(true);
        }