public GameState LoadGame() { GameState gs = new GameState(); string json = File.ReadAllText(@"savegame/game.json"); Ship ship = JsonConvert.DeserializeObject <Ship>(json); gs.ship = ship; gs.BuildingTypes = ShowBuildingTypes.GetBuildings(); gs.JobTypes = ShowJobTypes.GetJobs(); gs.PersonalityTypes = ShowPersonalityTypes.GetPersonalitys(); gs.SocialQueue = new List <SocialQueue>(); return(gs); }
public Character CreateCharacter(Ship ship, int job_id, int mother_id = 0, int father_id = 0, string last_name = null) { Character NewChar = new Character(); int gender = r.Next(1, 100); if (gender < 50) { NewChar.gender = 0; } else { NewChar.gender = 1; } if (last_name == null) { last_name = ShowCharacterNames.GetName(0, NewChar.gender); } NewChar.idkey = ship.Characters.Count; string first_name = ShowCharacterNames.GetName(1, NewChar.gender); NewChar.name = first_name + " " + last_name; NewChar.age = r.Next(864, 1728); NewChar.spouse_id = 0; NewChar.mother_id = mother_id; NewChar.father_id = father_id; NewChar.job_id = job_id; NewChar.job_skill = r.Next(1, 7); NewChar.dorm_id = 0; NewChar.sleep_shift = 0; NewChar.stress = (float)5; NewChar.happiness = (float)5; NewChar.anxiety = (float)5; int val = r.Next(3, 7); NewChar.strength = (float)val; val = r.Next(3, 7); NewChar.reflexes = (float)val; val = r.Next(3, 8); NewChar.constitution = (float)val; NewChar.stamina = (float)5; NewChar.sanity = (float)5; NewChar.mood = (float)5; NewChar.Personality = new List <CharacterPersonality>(); foreach (var p in ShowPersonalityTypes.GetPersonalitys()) { var newper = new CharacterPersonality(); val = r.Next(0, 10); if (val > 8) { val = r.Next(0, 10); } if (val < 2) { val = r.Next(0, 10); } newper.idkey = (p.idkey - 1); newper.value = (float)val; newper.value_mods = (float)0; if (val > 8 || val < 2) { newper.discovered = true; } else { newper.discovered = false; } NewChar.Personality.Add(newper); } NewChar.Needs = new List <CharacterNeeds>(); for (int i = 0; i < 9; i++) { var newneed = new CharacterNeeds(); newneed.idkey = i; newneed.value = (float)r.Next(5, 10); newneed.value_mods = (float)0; NewChar.Needs.Add(newneed); } NewChar.Wants = new List <CharacterWants>(); NewChar.Modifiers = new List <CharacterModifiers>(); NewChar.Memories = new List <CharacterMemories>(); NewChar.Relationships = new List <CharacterRelationship>(); NewChar.current_building = 22; NewChar.pos_x = 0; NewChar.pos_y = 0; NewChar.current_task = "dorm"; NewChar.dest_x = 0; NewChar.dest_y = 0; NewChar.hired = false; NewChar.dead = false; ship.Characters.Add(NewChar); GameService gs = new GameService(); gs.SaveGame(ship); return(NewChar); }
// Member variables here, example: // private int a = 2; // private string b = "textvar"; public override void _Ready() { // Called every time the node is added to the scene. // Initialization here GameService gsi = new GameService(); GameState gs = gsi.LoadGame(); Ship ship = gs.ship; var shipnamelabel = (Label)GetNode("VBoxContainer/HBoxContainer/VBoxContainer/sname"); shipnamelabel.Text = gs.ship.name; var jobnamelabel = (Label)GetNode("VBoxContainer/Screenbox/LeftSide/JobName"); var jobnamedesc = (Label)GetNode("VBoxContainer/Screenbox/LeftSide/building"); JobType job = gsi.GetNextJob(gs.ship); if (job.idkey == 0 || job.name == null) { gsi.cleanAndSave(gs.ship); GetTree().ChangeScene("res://MainGame.tscn"); } if (ShowJobTypes.GetJobs() != null && ShowJobTypes.GetJobs() != null) { List <JobType> JobList = gs.JobTypes; //Jobtype= BuildingType building = job.GetBuilding(job.building_id); string JobName = job.name + " (" + building.name + ")"; jobnamelabel.Text = JobName; jobnamedesc.Text = building.description; GenerateCharacter cg = new GenerateCharacter(); List <Character> Canidates = new List <Character>(); string npath = ""; int idx = 0; for (int i = 0; i <= 2; i++) { idx = i + 1; npath = "VBoxContainer/Screenbox/VBoxContainer/VBoxContainer/canidate" + idx + "/VBoxContainer2/"; Canidates.Add(cg.CreateCharacter(gs.ship, job.idkey)); var charnamelabel1 = (Label)GetNode(npath + "name1"); string cname = Canidates[i].name; float age = Canidates[i].age / 48; int ageyrs = (int)(Math.Floor(age)); cname = cname + ", Age " + ageyrs; if (Canidates[i].gender == 0) { cname = cname + " Male"; } else { cname = cname + " Female"; } charnamelabel1.Text = cname; var traitlabel1 = (Label)GetNode(npath + "traits1"); string strtrait = "Known Traits: "; string pname = ""; bool lined = false; foreach (var p in Canidates[i].Personality) { if (p.discovered == true) { //int pid= (p.idkey + 1); if (p.value < 3) { pname = ShowPersonalityTypes.GetPersonality(p.idkey).opposite; } else { pname = ShowPersonalityTypes.GetPersonality(p.idkey).adjective; } if (strtrait.Length > 50 && lined == false) { strtrait = strtrait + "\n"; lined = true; } strtrait = strtrait + " " + pname + ","; } } traitlabel1.Text = strtrait; var skilllabel1 = (Label)GetNode(npath + "skill1"); skilllabel1.Text = "Skill Level: " + Canidates[i].job_skill; } } var charnumlabel = (Label)GetNode("VBoxContainer/HBoxContainer/HBoxContainer/VBoxContainer2/chars"); charnumlabel.Text = "Crew Hired: " + (ship.Characters.Count - 3); var inventorylabel1 = (Label)GetNode("VBoxContainer/HBoxContainer/HBoxContainer/VBoxContainer/inventory1"); var inventorylabel2 = (Label)GetNode("VBoxContainer/HBoxContainer/HBoxContainer/VBoxContainer5/inventory2"); var inventorylabel3 = (Label)GetNode("VBoxContainer/HBoxContainer/HBoxContainer/VBoxContainer4/inventory3"); var inventorylabel4 = (Label)GetNode("VBoxContainer/HBoxContainer/HBoxContainer/VBoxContainer3/inventory4"); inventorylabel1.Text = "Raw Food: \n Clean H20: \n Fuel: \n Power: \n Spare Parts: \n Medical: \n Oxygen:"; int total_gas = (ship.oxygen + ship.nitrogen + ship.hydrogen + (int)Math.Round(ship.carbondioxide)); double oxy_perc = Math.Round(100 * (double)((double)ship.oxygen / (double)total_gas)); double co_perc = Math.Round(100 * (double)((double)ship.carbondioxide / (double)total_gas)); inventorylabel2.Text = ship.food + "\n" + ship.water + "\n" + ship.fuel + "\n" + ship.power + "\n" + ship.spare_parts + "\n" + ship.medical + "\n" + oxy_perc + "%"; inventorylabel3.Text = "Cooked Meals: \n Dirty H20: \n Hydrogen: \n Raw Resources: \n Waste Parts: \n Organics: \n C02 : "; inventorylabel4.Text = ship.meals + "\n" + ship.dirty_water + "\n" + ship.hydrogen + "\n " + ship.raw_resources + "\n" + ship.waste_parts + "\n" + ship.organics + "\n" + co_perc + "%"; }