/// <summary> /// Constructor for Place_Serialised taking seperate values. /// For creating Place_Serialised from CSV file. /// </summary> /// <param name="id">String holding place ID</param> /// <param name="nam">String holding place name</param> /// <param name="own">String holding Place owner (ID)</param> /// <param name="tiHo">String holding place title holder (charID)</param> /// <param name="rnk">String holding Place rank (ID)</param> public Place_Serialised(String id, String nam, byte r, String tiHo = null, string own = null) { // VALIDATION // ID // trim and ensure is uppercase id = id.Trim().ToUpper(); if (!Utility_Methods.ValidatePlaceID(id)) { throw new InvalidDataException("Place_Serialised id must be 5 characters long, start with a letter, and end in at least 2 numbers"); } // NAM // trim and ensure 1st is uppercase nam = Utility_Methods.FirstCharToUpper(nam.Trim()); if (!Utility_Methods.ValidateName(nam)) { throw new InvalidDataException("Place_Serialised name must be 1-40 characters long and contain only valid characters (a-z and ') or spaces"); } // TIHO if (!String.IsNullOrWhiteSpace(tiHo)) { // trim and ensure 1st is uppercase tiHo = Utility_Methods.FirstCharToUpper(tiHo.Trim()); if (!Utility_Methods.ValidateCharacterID(tiHo)) { throw new InvalidDataException("Place_Serialised titleHolder must have the format 'Char_' followed by some numbers"); } } // OWNER if (!String.IsNullOrWhiteSpace(owner)) { // trim and ensure 1st is uppercase owner = Utility_Methods.FirstCharToUpper(owner.Trim()); if (!Utility_Methods.ValidateCharacterID(owner)) { throw new InvalidDataException("Place_Serialised owner must have the format 'Char_' followed by some numbers"); } } this.id = id; this.name = nam; this.owner = own; this.titleHolder = tiHo; this.rank = r; }
/// <summary> /// Constructor for Province_Serialised taking seperate values. /// For creating Province_Serialised from CSV file. /// </summary> /// <param name="otax">Double holding province tax rate</param> /// <param name="king">string holding Province's Kingdom (id)</param> public Province_Serialised(String id, String nam, byte r, Double otax, String tiHo = null, string own = null, string king = null) : base(id, nam, r, own: own, tiHo: tiHo) { // VALIDATION // OTAX if (!Utility_Methods.ValidatePercentage(otax)) { throw new InvalidDataException("Province_Serialised taxrate must be a double between 0 and 100"); } // KING // trim and ensure is uppercase king = king.Trim().ToUpper(); if (!Utility_Methods.ValidatePlaceID(king)) { throw new InvalidDataException("Province_Serialised kingdom ID must be 5 characters long, start with a letter, and end in at least 2 numbers"); } this.taxRate = otax; this.kingdom = king; }
/// <summary> /// Create a new JournalEntry- used for more complex messages that would be more appropriate to be reconstructed on the client side /// </summary> /// <param name="m"></param> /// <param name="id"></param> /// <param name="yr"></param> /// <param name="seas"></param> /// <param name="pers"></param> /// <param name="typ"></param> /// <param name="loc"></param> /// <param name="desc"></param> public JournalEntry(ProtoMessage m, uint id, uint yr, byte seas, String[] pers, String typ, String loc = null, string desc = null) { this.entryDetails = m; // VALIDATION // SEAS // check between 0-3 if (!Utility_Methods.ValidateSeason(seas)) { throw new InvalidDataException("JournalEntry season must be a byte between 0-3"); } // PERS if (pers.Length > 0) { for (int i = 0; i < pers.Length; i++) { // split using'|' string[] persSplit = pers[i].Split('|'); if (persSplit.Length > 1) { // character ID: trim and ensure 1st is uppercase if (!persSplit[0].Contains("all")) { persSplit[0] = Utility_Methods.FirstCharToUpper(persSplit[0].Trim()); } // trim role persSplit[1] = persSplit[1].Trim(); // put back together pers[i] = persSplit[0] + "|" + persSplit[1]; } if (!Utility_Methods.ValidateJentryPersonae(pers[i])) { throw new InvalidDataException("Each JournalEntry personae must consist of 2 sections of letters, divided by '|', the 1st of which must be a valid character ID"); } } } // TYPE if (String.IsNullOrWhiteSpace(typ)) { throw new InvalidDataException("JournalEntry type must be a string > 0 characters in length"); } // LOC if (!String.IsNullOrWhiteSpace(loc)) { // trim and ensure is uppercase loc = loc.Trim().ToUpper(); if (!Utility_Methods.ValidatePlaceID(loc)) { throw new InvalidDataException("JournalEntry location id must be 5 characters long, start with a letter, and end in at least 2 numbers"); } } this.jEntryID = id; this.year = yr; this.season = seas; this.personae = pers; this.type = typ; if (!String.IsNullOrWhiteSpace(loc)) { this.location = loc; } this.viewed = false; }