public static int LoadPlayerByRealName(string name, out TraderDatRecord record) { int PlayerNumber = 0; if (File.Exists(Global.TraderDatFileName)) { using (FileStream FS = new FileStream(Global.TraderDatFileName, FileMode.Open)) { long FSLength = FS.Length; while (FS.Position < FSLength) { PlayerNumber += 1; TraderDatRecord TDR = DataStructures.ReadStruct <TraderDatRecord>(FS); if (TDR.RealName.Trim().ToUpper() == name.Trim().ToUpper()) { record = TDR; return(PlayerNumber); } } } } // If we get here, user doesn't have an account yet record = new TraderDatRecord(true); return(-1); }
private static void SavePlayer() { if (RTGlobal.PlayerNum != -1) { using (FileStream FS = new FileStream(Global.TraderDatFileName, FileMode.OpenOrCreate, FileAccess.Write)) { FS.Position = RTGlobal.PlayerNum * Marshal.SizeOf(typeof(TraderDatRecord)); DataStructures.WriteStruct <TraderDatRecord>(FS, Global.Player); } } }
public static void LoadDataFiles() { // Load ITEMS.DAT if (File.Exists(Global.ItemsDatFileName)) { using (FileStream FS = new FileStream(Global.ItemsDatFileName, FileMode.Open)) { long FSLength = FS.Length; while (FS.Position < FSLength) { ItemsDat.Add(DataStructures.ReadStruct <ItemsDatRecord>(FS)); } } } else { throw new Exception($"{Global.ItemsDatFileName} not found"); } // Load MAP.DAT if (File.Exists(Global.MapDatFileName)) { using (FileStream FS = new FileStream(Global.MapDatFileName, FileMode.Open)) { long FSLength = FS.Length; while (FS.Position < FSLength) { MapDat.Add(DataStructures.ReadStruct <MapDatRecord>(FS)); } } } else { throw new Exception($"{Global.MapDatFileName} not found"); } // Load STIME.DAT if (File.Exists(Global.STimeDatFileName)) { if (Convert.ToInt32(FileUtils.FileReadAllText(Global.STimeDatFileName)) != STime) { FileUtils.FileWriteAllText(Global.STimeDatFileName, STime.ToString()); IsNewDay = true; } } else { IsNewDay = true; FileUtils.FileWriteAllText(Global.STimeDatFileName, STime.ToString()); } // Load TIME.DAT if (File.Exists(Global.TimeDatFileName)) { RTGlobal.Time = Convert.ToInt32(FileUtils.FileReadAllText(Global.TimeDatFileName)); if (IsNewDay) { RTGlobal.Time += 1; FileUtils.FileWriteAllText(Global.TimeDatFileName, RTGlobal.Time.ToString()); } } else { FileUtils.FileWriteAllText(Global.TimeDatFileName, "1"); RTGlobal.Time = 1; } // Load WORLD.DAT if (File.Exists(Global.WorldDatFileName)) { using (FileStream FS = new FileStream(Global.WorldDatFileName, FileMode.Open)) { WorldDat = DataStructures.ReadStruct <WorldDatRecord>(FS); } } else { throw new Exception($"{Global.WorldDatFileName} not found"); } }
public static void Start() { // Ensure the platform/architecture we're running on has the right data type sizes DataStructures.Validate(); // Load the game data files into memory Global.LoadDataFiles(); // Initialize the RTReader engine RTGlobal.OnDRAWMAP += RTGlobal_OnDRAWMAP; RTGlobal.OnMOVEBACK += RTGlobal_OnMOVEBACK; RTGlobal.OnUPDATE += RTGlobal_OnUPDATE; // TODOX Pascal did this -- needed? //Global.Player.RealName = Door.DropInfo.RealName; //Global.Player.LastDayOn = (short)RTGlobal.Time; //Global.Player.LastDayPlayed = RTGlobal.Time; //Global.Player.LastSaved = RTGlobal.Time; // Load the rules and run maint, if it's a new day RTReader.Execute("RULES.REF", "RULES"); if (Global.IsNewDay) { RTReader.Execute("MAINT.REF", "MAINT"); } // Check if user has a Global.Player already RTGlobal.PlayerNum = Global.LoadPlayerByRealName(Door.DropInfo.RealName, out Global.Player); if (RTGlobal.PlayerNum == -1) { if (Global.TotalPlayerAccounts() < 200) { // Nope, so try to get them to create one RTReader.Execute("GAMETXT.REF", "NEWPLAYER"); RTGlobal.PlayerNum = Global.LoadPlayerByRealName(Door.DropInfo.RealName, out Global.Player); } else { RTReader.Execute("GAMETXT.REF", "FULL"); } } // Now check again to see if the user has a Global.Player (either because they already had one, or because they just created one) if (RTGlobal.PlayerNum != -1) { try { // Global.Player exists, so start the game RTReader.Execute("GAMETXT.REF", "STARTGAME"); // We're now in map mode until we hit a hotspot Global.LoadMap(Global.Player.Map); DrawMap(); /*TODO W Write mail to another player * H Interact with another player.The player pressing this key must be on the * same map square as the player they are trying to interact with. * B Show the log of messages. * F Show the last three messages. * Q Quit the game. Confirmation will be requested.*/ // Allow Global.Player to move around char?Ch = null; while (Ch != 'Q') { Ch = Door.ReadKey(); if (Ch != null) { Ch = char.ToUpper((char)Ch); switch (Ch) { case Door.ExtendedKeys.UpArrow: case '8': MovePlayer(0, -1); break; case Door.ExtendedKeys.LeftArrow: case '4': MovePlayer(-1, 0); break; case Door.ExtendedKeys.RightArrow: case '6': MovePlayer(1, 0); break; case Door.ExtendedKeys.DownArrow: case '2': MovePlayer(0, 1); break; case 'L': RTReader.Execute("HELP", "LISTPLAYERS"); break; case 'M': RTReader.Execute("HELP", "MAP"); break; case 'P': RTReader.Execute("HELP", "WHOISON"); break; case 'Q': // Confirm exit Door.GotoXY(1, 23); Door.Write("`r0`2 Are you sure you want to quit back to the BBS? [`%Y`2] : "); bool KeepLooping = true; while (KeepLooping) { // Repeat until we have a valid selection Ch = Door.ReadKey(); if (Ch != null) { Ch = char.ToUpper((char)Ch); switch (Ch) { case 'N': Ch = null; Door.GotoXY(1, 23); Door.Write(StringUtils.PadRight("", ' ', 79)); Door.GotoXY(Global.Player.X, Global.Player.Y); KeepLooping = false; break; case '\r': case 'Y': Ch = 'Q'; KeepLooping = false; break; } } } break; case 'T': RTReader.Execute("HELP", "TALK"); break; case 'V': RTReader.Execute("GAMETXT", "STATS"); //TODOX ViewInventory(); RTReader.Execute("GAMETXT", "CLOSESTATS"); break; case 'Y': RTReader.Execute("HELP", "YELL"); break; case 'Z': RTReader.Execute("HELP", "Z"); break; case '?': RTReader.Execute("HELP", "HELP"); break; } } } // TODO Clear status bar and disable events so its not redrawn RTReader.Execute("GAMETXT", "ENDGAME"); Thread.Sleep(2500); } finally { // Ensure the player gets saved even if we run into an exception above SavePlayer(); } } }