예제 #1
0
        public void Execute(CommodityVO reward)
        {
            if (reward.ID != null)
            {
                PartyConfig config = UnityEngine.Resources.Load <PartyConfig>("Parties/" + reward.ID);
                if (config != null && config.Party != null)
                {
                    CalendarModel calendar = AmbitionApp.GetModel <CalendarModel>();
                    PartyVO       party    = config.Party;
                    AmbitionApp.Execute <InitPartyCmd, PartyVO>(party);
                    party.RSVP           = (RSVP)reward.Value;
                    party.InvitationDate = calendar.Today;

                    if (default(DateTime) == party.Date)
                    {
                        party.Date = calendar.Today;
                    }

                    calendar.Schedule(party);

                    if (party.RSVP == RSVP.Accepted && party.Date == calendar.Today)
                    {
                        AmbitionApp.GetModel <PartyModel>().Party = party;
                    }
                }
                else
                {
                    UnityEngine.Debug.Log("Warning: PartyReward.cs: No party with ID \"" + reward.ID + "\" exists!");
                }
                config = null;
                UnityEngine.Resources.UnloadUnusedAssets();
            }
            else
            {
                UnityEngine.Debug.Log("Warning: PartyReward.cs: No party ID specified!");
            }
        }
예제 #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);
        }