public override void SyncData(IDataStore dataStore) { try { JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; if (dataStore.IsSaving) { // TODO: fix this, it's throwing exception when the list is empty. List <MissiveSyncData> sync = (from m in _missives select new MissiveSyncData(m)).ToList(); _missiveSyncData = JsonConvert.SerializeObject(sync, settings); dataStore.SyncData("_missiveSyncData", ref _missiveSyncData); } else if (dataStore.IsLoading) { dataStore.SyncData("_missiveSyncData", ref _missiveSyncData); List <MissiveSyncData> sync = JsonConvert.DeserializeObject(_missiveSyncData, settings) as List <MissiveSyncData>; _missives = (from m in sync where m.TypeName == "MissiveFriendly" select new MissiveFriendly(m)).ToList <IMissive>(); _missives.AddRange((from m in sync where m.TypeName == "MissiveThreat" select new MissiveThreat(m))); _missives.AddRange((from m in sync where m.TypeName == "MissiveCommand" select new MissiveCommand(m))); } } catch (Exception ex) { CPSModule.DebugMessage(ex, log); } }
public void game_menu_cps_town_courier_missive_threat_on_consequence(MenuCallbackArgs args) { // create and send the missive CPSModule.DebugMessage("Threatening Missive selected.", log); InformationManager.ShowTextInquiry(new TextInquiryData("Let them know how you really feel:", "", true, false, "Send", "Cancel", (string s) => { SendMissive <MissiveThreat>(s); }, null)); GameMenu.SwitchToMenu("cps_town_courier"); }
public void game_menu_cps_town_courier_missive_friendly_on_consequence(MenuCallbackArgs args) { // create and send the missive CPSModule.DebugMessage("Friendly Missive selected.", log); InformationManager.ShowTextInquiry(new TextInquiryData("Enter a brief message:", "", true, false, "Send", "Cancel", (string s) => { SendMissive <MissiveFriendly>(s); }, null)); GameMenu.SwitchToMenu("cps_town_courier"); }
private void OnSelectRecipient(List <InquiryElement> recipients) { try { var element = recipients.First <InquiryElement>(); Hero recipient = Hero.FindFirst((Hero h) => { return(h.StringId == element.Identifier.ToString()); }); MBTextManager.SetTextVariable("CPS_MISSIVE_RECIPIENT", recipient.Name); _recipientSelected = recipient; GameMenu.SwitchToMenu("cps_town_courier_missive"); } catch (Exception ex) { CPSModule.DebugMessage(ex, log); } }
public override void OnDelivery() { CPSModule.DebugMessage("OnDelivery called.", log); float relationWithSender = (float)Recipient.GetRelation(Sender); float roll = MBRandom.RandomFloat; CPSModule.DebugMessage($"relationWithSender: {relationWithSender}, roll: {roll}", log); if (roll <= (100.0f - relationWithSender) / 100.0f) { if (Hero.MainHero == Sender) { CPSModule.InfoMessage($"{Recipient} appreciated your letter."); } ChangeRelationAction.ApplyRelationChangeBetweenHeroes(Sender, Recipient, 1); } else if (Hero.MainHero == Sender) { CPSModule.InfoMessage($"{Recipient} received your letter."); } }
private void OnDailyTick() { try { CPSModule.DebugMessage($"{_missives.Count} missives out for delivery..", log); for (int i = _missives.Count - 1; i >= 0; --i) { if (_missives[i].CampaignTimeArrival <= CampaignTime.Now) { // missive delivered _missives[i].OnDelivery(); CPSModule.DebugMessage($"Missive delivered from {_missives[i].Sender.Name} to {_missives[i].Recipient.Name}: {_missives[i].Text}", log); _missives.RemoveAt(i); } } } catch (Exception ex) { CPSModule.DebugMessage(ex, log); } }
private void SendMissive <T>(string s) where T : IMissive, new() { try { CPSModule.DebugMessage($"You entered: {s}", log); var missive = new T { Sender = Hero.MainHero, Recipient = _recipientSelected, CampaignTimeSent = CampaignTime.Now, CampaignTimeArrival = PostalServiceModel.GetMissiveDeliveryTime(Hero.MainHero, _recipientSelected), Text = s }; _missives.Add(missive); missive.OnSend(); } catch (Exception ex) { CPSModule.DebugMessage(ex, log); } }
public override void OnReturn() { CPSModule.DebugMessage("OnReturn called.", log); }