public override void Execute() { RetCode rc; T record; gOut.WriteLine(); gEngine.PrintTitle(Title, true); if (!Globals.Config.GenerateUids && NewRecordUid == 0) { gOut.Write("{0}{1}", Environment.NewLine, gEngine.BuildPrompt(55, '\0', 0, string.Format("Enter the uid of the {0} record to add", RecordTypeName), null)); Buf.Clear(); rc = Globals.In.ReadField(Buf, Constants.BufSize01, null, '_', '\0', false, null, null, gEngine.IsCharDigit, null); Debug.Assert(gEngine.IsSuccess(rc)); NewRecordUid = Convert.ToInt64(Buf.Trim().ToString()); gOut.Print("{0}", Globals.LineSep); if (NewRecordUid > 0) { record = RecordTable.FindRecord(NewRecordUid); if (record != null) { gOut.Print("{0} record already exists.", RecordTypeName.FirstCharToUpper()); goto Cleanup; } RecordTable.FreeUids.Remove(NewRecordUid); } } record = Globals.CreateInstance <T>(x => { x.Uid = NewRecordUid; }); var helper = Globals.CreateInstance <U>(x => { x.Record = record; }); helper.InputRecord(false, Globals.Config.FieldDesc); Globals.Thread.Sleep(150); gOut.Write("{0}Would you like to save this {1} record (Y/N): ", Environment.NewLine, RecordTypeName); Buf.Clear(); rc = Globals.In.ReadField(Buf, Constants.BufSize02, null, ' ', '\0', false, null, gEngine.ModifyCharToUpper, gEngine.IsCharYOrN, gEngine.IsCharYOrN); Debug.Assert(gEngine.IsSuccess(rc)); Globals.Thread.Sleep(150); if (Buf.Length > 0 && Buf[0] == 'N') { record.Dispose(); goto Cleanup; } var character = record as ICharacter; if (character != null) { character.StripPoundCharsFromWeaponNames(); character.AddPoundCharsToWeaponNames(); } var artifact = record as IArtifact; if (artifact != null) { var i = gEngine.FindIndex(artifact.Categories, ac => ac != null && ac.Type == ArtifactType.None); if (i > 0) { rc = artifact.SetArtifactCategoryCount(i); Debug.Assert(gEngine.IsSuccess(rc)); } rc = artifact.SyncArtifactCategories(); Debug.Assert(gEngine.IsSuccess(rc)); gEngine.TruncatePluralTypeEffectDesc(artifact.PluralType, Constants.ArtNameLen); } var effect = record as IEffect; if (effect != null) { gEngine.TruncatePluralTypeEffectDesc(effect); } var monster = record as IMonster; if (monster != null) { gEngine.TruncatePluralTypeEffectDesc(monster.PluralType, Constants.MonNameLen); } rc = RecordTable.AddRecord(record); Debug.Assert(gEngine.IsSuccess(rc)); UpdateGlobals(); Cleanup: NewRecordUid = 0; }
public override void Execute() { RetCode rc; gOut.WriteLine(); gEngine.PrintTitle(Title, true); if (EditRecord == null) { gOut.Write("{0}{1}", Environment.NewLine, gEngine.BuildPrompt(55, '\0', 0, string.Format("Enter the uid of the {0} record to edit", RecordTypeName), "1")); Buf.Clear(); rc = Globals.In.ReadField(Buf, Constants.BufSize01, null, '_', '\0', true, "1", null, gEngine.IsCharDigit, null); Debug.Assert(gEngine.IsSuccess(rc)); var recordUid = Convert.ToInt64(Buf.Trim().ToString()); gOut.Print("{0}", Globals.LineSep); EditRecord = RecordTable.FindRecord(recordUid); if (EditRecord == null) { gOut.Print("{0} record not found.", RecordTypeName.FirstCharToUpper()); goto Cleanup; } } var editRecord01 = Globals.CloneInstance(EditRecord); Debug.Assert(editRecord01 != null); var helper = Globals.CreateInstance <U>(x => { x.Record = editRecord01; }); helper.InputRecord(true, Globals.Config.FieldDesc); Globals.Thread.Sleep(150); if (!Globals.CompareInstances(EditRecord, editRecord01)) { gOut.Write("{0}Would you like to save this updated {1} record (Y/N): ", Environment.NewLine, RecordTypeName); Buf.Clear(); rc = Globals.In.ReadField(Buf, Constants.BufSize02, null, ' ', '\0', false, null, gEngine.ModifyCharToUpper, gEngine.IsCharYOrN, gEngine.IsCharYOrN); Debug.Assert(gEngine.IsSuccess(rc)); Globals.Thread.Sleep(150); if (Buf.Length > 0 && Buf[0] == 'N') { goto Cleanup; } var character = editRecord01 as ICharacter; if (character != null) { character.StripPoundCharsFromWeaponNames(); character.AddPoundCharsToWeaponNames(); } var artifact = editRecord01 as IArtifact; if (artifact != null) { rc = artifact.SyncArtifactCategories(); Debug.Assert(gEngine.IsSuccess(rc)); gEngine.TruncatePluralTypeEffectDesc(artifact.PluralType, Constants.ArtNameLen); } var effect = editRecord01 as IEffect; if (effect != null) { gEngine.TruncatePluralTypeEffectDesc(effect); } var monster = editRecord01 as IMonster; if (monster != null) { gEngine.TruncatePluralTypeEffectDesc(monster.PluralType, Constants.MonNameLen); } var record = RecordTable.RemoveRecord(EditRecord.Uid); Debug.Assert(record != null); rc = RecordTable.AddRecord(editRecord01); Debug.Assert(gEngine.IsSuccess(rc)); UpdateGlobals(); } else { gOut.Print("{0} record not modified.", RecordTypeName.FirstCharToUpper()); } Cleanup: EditRecord = null; }
public override void Execute() { RetCode rc; gOut.WriteLine(); gEngine.PrintTitle(Title, true); gOut.Write("{0}{1}", Environment.NewLine, gEngine.BuildPrompt(55, '\0', 0, string.Format("Enter the uid of the {0} record to copy", RecordTypeName), "1")); Buf.Clear(); rc = Globals.In.ReadField(Buf, Constants.BufSize01, null, '_', '\0', true, "1", null, gEngine.IsCharDigit, null); Debug.Assert(gEngine.IsSuccess(rc)); var recordUid = Convert.ToInt64(Buf.Trim().ToString()); gOut.Print("{0}", Globals.LineSep); var record = RecordTable.FindRecord(recordUid); if (record == null) { gOut.Print("{0} record not found.", RecordTypeName.FirstCharToUpper()); goto Cleanup; } var record01 = Globals.CloneInstance(record); Debug.Assert(record01 != null); if (!Globals.Config.GenerateUids) { gOut.Write("{0}{1}", Environment.NewLine, gEngine.BuildPrompt(55, '\0', 0, string.Format("Enter the uid of the {0} record copy", RecordTypeName), null)); Buf.Clear(); rc = Globals.In.ReadField(Buf, Constants.BufSize01, null, '_', '\0', false, null, null, gEngine.IsCharDigit, null); Debug.Assert(gEngine.IsSuccess(rc)); recordUid = Convert.ToInt64(Buf.Trim().ToString()); gOut.Print("{0}", Globals.LineSep); if (recordUid > 0) { record = RecordTable.FindRecord(recordUid); if (record != null) { gOut.Print("{0} record already exists.", RecordTypeName.FirstCharToUpper()); goto Cleanup; } RecordTable.FreeUids.Remove(recordUid); record01.Uid = recordUid; record01.IsUidRecycled = false; } else { record01.Uid = RecordTable.GetRecordUid(); record01.IsUidRecycled = true; } } else { record01.Uid = RecordTable.GetRecordUid(); record01.IsUidRecycled = true; } var helper = Globals.CreateInstance <U>(x => { x.Record = record01; }); helper.ListRecord(true, true, false, true, false, false); PrintPostListLineSep(); gOut.Write("{0}Would you like to save this {1} record (Y/N): ", Environment.NewLine, RecordTypeName); Buf.Clear(); rc = Globals.In.ReadField(Buf, Constants.BufSize02, null, ' ', '\0', false, null, gEngine.ModifyCharToUpper, gEngine.IsCharYOrN, gEngine.IsCharYOrN); Debug.Assert(gEngine.IsSuccess(rc)); Globals.Thread.Sleep(150); if (Buf.Length > 0 && Buf[0] == 'N') { record01.Dispose(); goto Cleanup; } rc = RecordTable.AddRecord(record01); Debug.Assert(gEngine.IsSuccess(rc)); UpdateGlobals(); Cleanup: ; }
public override void Execute() { RetCode rc; gOut.WriteLine(); gEngine.PrintTitle(Title, true); gOut.Write("{0}{1}", Environment.NewLine, gEngine.BuildPrompt(55, '\0', 0, string.Format("Enter the uid of the {0} record to delete", RecordTypeName), null)); Buf.Clear(); rc = Globals.In.ReadField(Buf, Constants.BufSize01, null, '_', '\0', false, null, null, gEngine.IsCharDigit, null); Debug.Assert(gEngine.IsSuccess(rc)); var recordUid = Convert.ToInt64(Buf.Trim().ToString()); gOut.Print("{0}", Globals.LineSep); var record = RecordTable.FindRecord(recordUid); if (record == null) { gOut.Print("{0} record not found.", RecordTypeName.FirstCharToUpper()); goto Cleanup; } var character = record as ICharacter; if (character != null && character.Status != Status.Alive && character.Status != Status.Dead) { gOut.Print("{0} record Status not marked as Alive or Dead.", RecordTypeName.FirstCharToUpper()); goto Cleanup; } var helper = Globals.CreateInstance <U>(x => { x.Record = record; }); helper.ListRecord(true, true, false, true, false, false); PrintPostListLineSep(); Globals.Thread.Sleep(150); gOut.Write("{0}Would you like to delete this {1} record (Y/N): ", Environment.NewLine, RecordTypeName); Buf.Clear(); rc = Globals.In.ReadField(Buf, Constants.BufSize02, null, ' ', '\0', false, null, gEngine.ModifyCharToUpper, gEngine.IsCharYOrN, gEngine.IsCharYOrN); Debug.Assert(gEngine.IsSuccess(rc)); Globals.Thread.Sleep(150); if (Buf.Length > 0 && Buf[0] == 'N') { goto Cleanup; } record = RecordTable.RemoveRecord(recordUid); Debug.Assert(record != null); record.Dispose(); UpdateGlobals(); Cleanup: ; }