Пример #1
0
        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:

            ;
        }
Пример #2
0
        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;
        }
Пример #3
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;
        }