/// <summary> /// Adds all characters from family A and B to each others "At War" lists /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void declareWar(string a, string b) { Character aC = Globals_Game.getCharFromID(a); Character bC = Globals_Game.getCharFromID(b); for (int i = 0; i < Globals_Game.npcMasterList.Count; i++) { if (Globals_Game.npcMasterList.Values.ElementAt(i).familyID.Equals(bC.familyID)) { Globals_Game.npcMasterList.Values.ElementAt(i).atWar.Add(aC.familyID); } if (Globals_Game.npcMasterList.Values.ElementAt(i).familyID.Equals(aC.familyID)) { Globals_Game.npcMasterList.Values.ElementAt(i).atWar.Add(bC.familyID); } } for (int i = 0; i < Globals_Game.pcMasterList.Count; i++) { if (Globals_Game.pcMasterList.Values.ElementAt(i).familyID.Equals(bC.familyID)) { Globals_Game.pcMasterList.Values.ElementAt(i).atWar.Add(aC.familyID); } if (Globals_Game.pcMasterList.Values.ElementAt(i).familyID.Equals(aC.familyID)) { Globals_Game.pcMasterList.Values.ElementAt(i).atWar.Add(bC.familyID); } } }
/// <summary> /// forges alliance between character a and character b families. depending on how the alliance was forged an identifier would be used to determine so /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="x"></param> /// <returns></returns> public static void forgeAlliance(String a, String b) { Character aC = Globals_Game.getCharFromID(a); Character bC = Globals_Game.getCharFromID(b); if (!aC.isAlly(bC) && !bC.isAlly(aC)) { for (int i = 0; i < Globals_Game.npcMasterList.Count; i++) { if (Globals_Game.npcMasterList.Values.ElementAt(i).familyID.Equals(bC.familyID)) { Globals_Game.npcMasterList.Values.ElementAt(i).allies.Add(aC.familyID); } if (Globals_Game.npcMasterList.Values.ElementAt(i).familyID.Equals(aC.familyID)) { Globals_Game.npcMasterList.Values.ElementAt(i).allies.Add(bC.familyID); } } for (int i = 0; i < Globals_Game.pcMasterList.Count; i++) { if (Globals_Game.pcMasterList.Values.ElementAt(i).familyID.Equals(bC.familyID)) { Globals_Game.pcMasterList.Values.ElementAt(i).allies.Add(aC.familyID); } if (Globals_Game.pcMasterList.Values.ElementAt(i).familyID.Equals(aC.familyID)) { Globals_Game.pcMasterList.Values.ElementAt(i).allies.Add(bC.familyID); } } } }
/// <summary> /// Breaks alliance between Character a family and Character b family /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void removeAlly(String a, String b) { Character aC = Globals_Game.getCharFromID(a); Character bC = Globals_Game.getCharFromID(b); for (int i = 0; i < Globals_Game.npcMasterList.Count; i++) { if (Globals_Game.npcMasterList.Values.ElementAt(i).familyID.Equals(bC.familyID)) { Globals_Game.npcMasterList.Values.ElementAt(i).allies.Remove(aC.familyID); } if (Globals_Game.npcMasterList.Values.ElementAt(i).familyID.Equals(aC.familyID)) { Globals_Game.npcMasterList.Values.ElementAt(i).allies.Remove(bC.familyID); } } for (int i = 0; i < Globals_Game.pcMasterList.Count; i++) { if (Globals_Game.pcMasterList.Values.ElementAt(i).familyID.Equals(bC.familyID)) { Globals_Game.pcMasterList.Values.ElementAt(i).allies.Remove(aC.familyID); } if (Globals_Game.pcMasterList.Values.ElementAt(i).familyID.Equals(aC.familyID)) { Globals_Game.pcMasterList.Values.ElementAt(i).allies.Remove(bC.familyID); } } }
/// <summary> /// Removes character A and B families from each other "At War" lists /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void makePeace(string a, string b) { Character aC = Globals_Game.getCharFromID(a); Character bC = Globals_Game.getCharFromID(b); if (aC.wagingWar(bC) && bC.wagingWar(aC)) { for (int i = 0; i < Globals_Game.npcMasterList.Count; i++) { if (Globals_Game.npcMasterList.Values.ElementAt(i).familyID.Equals(bC.familyID)) { Globals_Game.npcMasterList.Values.ElementAt(i).atWar.Remove(aC.familyID); } if (Globals_Game.npcMasterList.Values.ElementAt(i).familyID.Equals(aC.familyID)) { Globals_Game.npcMasterList.Values.ElementAt(i).atWar.Remove(bC.familyID); } } for (int i = 0; i < Globals_Game.pcMasterList.Count; i++) { if (Globals_Game.pcMasterList.Values.ElementAt(i).familyID.Equals(bC.familyID)) { Globals_Game.pcMasterList.Values.ElementAt(i).atWar.Remove(aC.familyID); } if (Globals_Game.pcMasterList.Values.ElementAt(i).familyID.Equals(aC.familyID)) { Globals_Game.pcMasterList.Values.ElementAt(i).atWar.Remove(bC.familyID); } } } }
public Client deserialise() { Client c = new Client(user, pcID); c.myPastEvents = this.myPastEvents; c.myPlayerCharacter = Globals_Game.getCharFromID(pcID) as PlayerCharacter; c.activeChar = Globals_Game.getCharFromID(activeChar); return(c); }
/// <summary> /// Test stub for spy character /// </summary> /// <param name="testClient"></param> /// <param name="charID"></param> /// <param name="targetID"></param> /// <param name="DoSpy"></param> public void SpyCharacterTest(TestClient testClient, string charID, string targetID, bool DoSpy) { bool ownsCharacter = true; Character spy = Globals_Game.getCharFromID(charID); Client client = Globals_Server.Clients[testClient.playerID]; if (spy != null) { ownsCharacter = (spy.GetPlayerCharacter().Equals(client.myPlayerCharacter)); } testClient.SpyOnCharacter(charID, targetID); Task <ProtoMessage> responseTask = testClient.GetReply(); responseTask.Wait(); ProtoMessage response = responseTask.Result; // If don't identify either character, CharacterUnidentified error // If don't own spy, PermissionDenied error // If target is own character, SpyCharacterOwn error // If target is not in same fief as spy, TooFarFromFief error // If target is not valid, other error // Otherwise, expect a response if (string.IsNullOrWhiteSpace(charID) || string.IsNullOrWhiteSpace(targetID)) { Assert.AreEqual(DisplayMessages.ErrorGenericMessageInvalid, response.ResponseType); return; } Character target = Globals_Game.getCharFromID(targetID); if (spy == null || target == null) { Assert.AreEqual(DisplayMessages.ErrorGenericCharacterUnidentified, response.ResponseType); return; } if (!ownsCharacter) { Assert.AreEqual(DisplayMessages.ErrorGenericUnauthorised, response.ResponseType); return; } if (spy.location != target.location) { Assert.AreEqual(DisplayMessages.ErrorGenericNotInSameFief, response.ResponseType); return; } if (spy.days < 10) { Assert.AreEqual(DisplayMessages.ErrorGenericNotEnoughDays, response.ResponseType); return; } if (target.GetPlayerCharacter() == spy.GetPlayerCharacter()) { Assert.AreEqual(DisplayMessages.ErrorSpyOwn, response.ResponseType); return; } }
///// <summary> ///// The main entry point for the application. ///// </summary> //static void Main() //{ // try // { // using (Globals_Server.LogFile = new System.IO.StreamWriter("LogFile.txt")) // { // //Globals_Server.rCluster = RiakCluster.FromConfig("riakConfig","app.config"); // //Globals_Server.rClient = Globals_Server.rCluster.CreateClient(); // Globals_Server.LogFile.AutoFlush = true; // Globals_Server.logEvent("Server start"); // Game game = new Game(); // SetUpForDemo(); // /* // //DatabaseWrite.DatabaseWriteAll ("testBucket"); // /*if (Globals_Server.rClient.Ping ().IsSuccess) { // Console.WriteLine ("Database connection successful"); // string gameID = "testBucket"; // foreach (string trait in Globals_Game.traitKeys) { // Console.WriteLine (trait); // } // // Test can read from database // var newClient = Globals_Server.rCluster.CreateClient(); // RiakObject newObj = new RiakObject (gameID, "superawesome3", Globals_Game.traitKeys.ToArray ()); // newClient.Put (newObj); // Thread.Sleep (5000); // var testRead =newClient.Get (gameID, "superawesome3"); // if (!testRead.IsSuccess) { // Console.WriteLine ("FAIL :(" + testRead.ErrorMessage); // } else { // Console.WriteLine ("Got traitkeys:"); // } // //DatabaseRead.DatabaseReadAll (gameID); // } else { // Console.WriteLine ("Could not connect to database :( "); // } */ // //testCaptives(); // Server server = new Server(); // try // { // //TestSuite testSuite = new TestSuite(); // TestClient client = new TestClient(); // client.LogInAndConnect("helen", "potato"); // } // catch (Exception e) // { // Console.WriteLine(e.Message); // } // //client.LogIn("helen", "potato"); // String s = Console.ReadLine(); // if (s != null && s.Equals("exit")) // { // Globals_Server.logEvent("Server exits"); // server.isListening = false; // Globals_Server.server.Shutdown("Server exits"); // } // //testArmy(); // //testSpying(); // /* // while (true) // { // if (s != null && s.Equals("exit")) // { // Globals_Server.logEvent("Server exits"); // server.isListening = false; // Globals_Server.server.Shutdown("Server exits"); // break; // } // } // * */ // Globals_Server.LogFile.Close(); // } // } // catch (Exception e) // { // Globals_Server.LogFile.Close(); // Console.WriteLine("Encountered an error:" + e.StackTrace); // Console.ReadLine(); // } //} /// <summary> /// Code which was used in the 2015 demo- sets up a few armies, adds funds and sets a few traits to demonstrate trait effects /// </summary> public static void SetUpForDemo() { // Make Anselm Marshal very sneaky Character Anselm = Globals_Game.getCharFromID("Char_390"); Character Bishop = Globals_Game.getCharFromID("Char_391"); Tuple <Trait, int>[] newTraits = new Tuple <Trait, int> [2]; newTraits[0] = new Tuple <Trait, int>(Globals_Game.traitMasterList["trait_9"], 9); newTraits[1] = new Tuple <Trait, int>(Globals_Game.traitMasterList["trait_8"], 9); Anselm.traits = newTraits; // Make Bishop Henry Marshal not sneaky Tuple <Trait, int>[] newTraits2 = new Tuple <Trait, int> [1]; newTraits2[0] = new Tuple <Trait, int>(Globals_Game.traitMasterList["trait_5"], 2); Bishop.traits = newTraits2; // Add funds to home treasury (Globals_Game.getCharFromID("Char_158") as PlayerCharacter).GetHomeFief().AdjustTreasury(100000); // create enemy character in home fief NonPlayerCharacter enemyGeneral = new NonPlayerCharacter("Char_164459", "John", "Smith", new Tuple <uint, byte>(1142, 3), true, Globals_Game.nationalityMasterList["Sco"], true, 9, 9, new Queue <Fief>(), Globals_Game.languageMasterList["lang_C1"], 90, 9, 9, 9, new Tuple <Trait, int> [0], true, false, "Char_126", null, "Char_126", null, 0, false, false, new List <string>(), null, null, Globals_Game.fiefMasterList["EPM02"]); PlayerCharacter factionLeader = Globals_Game.pcMasterList["Char_126"]; factionLeader.myNPCs.Add(enemyGeneral); enemyGeneral.inKeep = false; // create enemy army for above enemy character uint[] enemyArmyTroops = new uint[] { 3, 7, 0, 20, 30, 65, 190 }; Army enemyArmy = new Army(Globals_Game.GetNextArmyID(), Globals_Game.npcMasterList["Char_164459"].charID, Globals_Game.pcMasterList["Char_196"].charID, Globals_Game.npcMasterList["Char_164459"].days, Globals_Game.npcMasterList["Char_164459"].location.id, trp: enemyArmyTroops); enemyArmy.AddArmy(); // create and add army uint[] myArmyTroops1 = new uint[] { 8, 10, 0, 30, 60, 100, 220 }; Army myArmy1 = new Army(Globals_Game.GetNextArmyID(), Globals_Game.pcMasterList["Char_196"].charID, Globals_Game.pcMasterList["Char_196"].charID, Globals_Game.pcMasterList["Char_196"].days, Globals_Game.pcMasterList["Char_196"].location.id, trp: myArmyTroops1); myArmy1.AddArmy(); // create and add army uint[] myArmyTroops2 = new uint[] { 5, 10, 0, 30, 40, 80, 220 }; Army myArmy2 = new Army(Globals_Game.GetNextArmyID(), Globals_Game.pcMasterList["Char_158"].charID, Globals_Game.pcMasterList["Char_158"].charID, Globals_Game.pcMasterList["Char_158"].days, Globals_Game.pcMasterList["Char_158"].location.id, trp: myArmyTroops2, aggr: 1, odds: 2); myArmy2.AddArmy(); // Add single lady appropriate for marriage //Nationality nat = Globals_Game.nationalityMasterList["Sco"]; NonPlayerCharacter proposalChar = new NonPlayerCharacter("Char_626", "Mairi", "Meah", new Tuple <uint, byte>(1162, 3), false, Globals_Game.nationalityMasterList["Sco"], true, 9, 9, new Queue <Fief>(), Globals_Game.languageMasterList["lang_C1"], 90, 9, 9, 9, new Tuple <Trait, int> [0], true, false, "Char_126", null, "Char_126", null, 0, false, false, new List <string>(), null, null, Globals_Game.fiefMasterList["ESW05"]); PlayerCharacter pc = Globals_Game.pcMasterList["Char_126"]; pc.myNPCs.Add(proposalChar); proposalChar.inKeep = false; }
/// <summary> /// Test stub for spy character /// </summary> /// <param name="testClient"></param> /// <param name="charID"></param> /// <param name="targetID"></param> /// <param name="DoSpy"></param> public void SpyFiefTest(TestClient testClient, string charID, string targetID, bool DoSpy) { Character spy = Globals_Game.getCharFromID(charID); Client client = Globals_Server.Clients[testClient.playerID]; bool ownSpy = true; if (spy != null) { ownSpy = (spy.GetPlayerCharacter().Equals(client.myPlayerCharacter)); } testClient.SpyOnFief(charID, targetID); Task <ProtoMessage> responseTask = testClient.GetReply(); responseTask.Wait(); ProtoMessage response = responseTask.Result; if (string.IsNullOrWhiteSpace(charID) || string.IsNullOrWhiteSpace(targetID)) { Assert.AreEqual(DisplayMessages.ErrorGenericMessageInvalid, response.ResponseType); return; } Fief target = null; Globals_Game.fiefMasterList.TryGetValue(targetID, out target); if (spy == null || target == null) { Assert.AreEqual(DisplayMessages.ErrorGenericCharacterUnidentified, response.ResponseType); return; } if (!ownSpy) { Assert.AreEqual(DisplayMessages.ErrorGenericUnauthorised, response.ResponseType); return; } if (spy.location != target) { Assert.AreEqual(DisplayMessages.ErrorGenericNotInSameFief, response.ResponseType); return; } if (spy.days < 10) { Assert.AreEqual(DisplayMessages.ErrorGenericNotEnoughDays, response.ResponseType); return; } }
/// <summary> /// Test stub for spy character /// </summary> /// <param name="testClient"></param> /// <param name="charID"></param> /// <param name="targetID"></param> /// <param name="DoSpy"></param> public void SpyArmyTest(TestClient testClient, string charID, string targetID) { testClient.SpyOnArmy(charID, targetID); Task <ProtoMessage> responseTask = testClient.GetReply(); responseTask.Wait(); ProtoMessage response = responseTask.Result; if (string.IsNullOrWhiteSpace(charID) || string.IsNullOrWhiteSpace(targetID)) { Assert.AreEqual(DisplayMessages.ErrorGenericMessageInvalid, response.ResponseType); return; } Character spy = Globals_Game.getCharFromID(charID); Army target = null; Globals_Game.armyMasterList.TryGetValue(targetID, out target); if (spy == null || target == null) { Assert.AreEqual(DisplayMessages.ErrorGenericCharacterUnidentified, response.ResponseType); return; } Client client = Globals_Server.Clients[testClient.playerID]; if (spy.GetPlayerCharacter() != client.myPlayerCharacter) { Assert.AreEqual(DisplayMessages.ErrorGenericUnauthorised, response.ResponseType); return; } if (spy.location != target.GetLocation()) { Assert.AreEqual(DisplayMessages.ErrorGenericNotInSameFief, response.ResponseType); return; } if (!(spy.days >= 10)) { Assert.AreEqual(DisplayMessages.ErrorGenericNotEnoughDays, response.ResponseType); return; } }
/// <summary> /// Respond to ransom demands /// </summary> /// <param name="paid">Whether or not ransom is to be paid</param> /// <returns>Bool indicating success</returns> public bool RansomResponse(bool paid, out ProtoMessage error) { error = null; // Check if type is ransom if (this.type.Equals("ransom")) { // Check if already replied if (replied) { // Already replied error = new ProtoMessage(); error.ResponseType = DisplayMessages.RansomRepliedAlready; return(false); } Character captive = null; PlayerCharacter captor; PlayerCharacter captiveHeadOfHousehold; // Confirm captive is still alive and being held foreach (string persona in personae) { string[] split = persona.Split(new char[] { '|' }); if (split[1].Equals("Captive")) { captive = Globals_Game.getCharFromID(split[0]); } } if (captive == null) { // Captive does not exist- error error = new ProtoMessage(); error.ResponseType = DisplayMessages.ErrorGenericCharacterUnidentified; Globals_Server.logError("Captive unidentified in JEntry: " + this.jEntryID); return(false); } else if (!captive.isAlive) { // Captive is dead error = new ProtoMessage(); error.ResponseType = DisplayMessages.RansomCaptiveDead; return(false); } captor = Globals_Game.getCharFromID(captive.captorID) as PlayerCharacter; if (captor == null) { // Captive does not have a captor error = new ProtoMessage(); error.ResponseType = DisplayMessages.NotCaptive; return(false); } captiveHeadOfHousehold = captive.GetPlayerCharacter(); if (captiveHeadOfHousehold == null) { // Captive is not an employee, family member or player character Globals_Server.logError("Captive has no PlayerCharacter: " + captive.charID); error = new ProtoMessage(); error.ResponseType = DisplayMessages.ErrorGenericCharacterUnidentified; return(false); } if (paid) { // Get ransom amount uint ransom = 0; if (!UInt32.TryParse(entryDetails.MessageFields[1], out ransom)) { // Error parsing to int Globals_Server.logError("Could not parse ransom to uint in JEntry: " + jEntryID); error = new ProtoMessage(); error.ResponseType = DisplayMessages.ErrorGenericMessageInvalid; return(false); } else { // Check captive's head of household has the funds to release if (captiveHeadOfHousehold.GetHomeFief().GetAvailableTreasury(false) >= ransom) { if (!captiveHeadOfHousehold.GetHomeFief().TreasuryTransfer(captor.GetHomeFief(), (Int32)ransom, out error)) { return(false); } else { // Release captive captor.ReleaseCaptive(captive); replied = true; Globals_Game.UpdatePlayer(captor.playerID, DisplayMessages.RansomPaid, new string[] { captive.firstName + " " + captive.familyName }); return(true); } } else { // Insufficient funds error = new ProtoMessage(); error.ResponseType = DisplayMessages.ErrorGenericInsufficientFunds; return(false); } } } // If not paying ransom, inform captor else { // Create journal entry and update captor string[] newPersonae = new string[] { captive.charID + "|Captive", captor.charID + "|Captor", captiveHeadOfHousehold.charID + "|HeadOfCaptiveFamily" }; ProtoMessage deniedMessage = new ProtoMessage(); deniedMessage.ResponseType = DisplayMessages.RansonDenied; deniedMessage.MessageFields = new string[] { captive.firstName + " " + captive.familyName, captor.firstName + " " + captor.familyName, captiveHeadOfHousehold.firstName + " " + captiveHeadOfHousehold.familyName }; Globals_Game.UpdatePlayer(captor.playerID, deniedMessage); JournalEntry ransomDenied = new JournalEntry(Globals_Game.GetNextJournalEntryID(), Globals_Game.clock.currentYear, Globals_Game.clock.currentSeason, newPersonae, "ransomDenied", deniedMessage); Globals_Game.AddPastEvent(ransomDenied); replied = true; return(true); } } else { // Not a ransom error = new ProtoMessage(); error.ResponseType = DisplayMessages.EntryNotRansom; return(false); } }