Beispiel #1
0
        public override void Execute()
        {
            Debug.Assert(DobjArtifact != null);

            DobjArtAc = DobjArtifact.DoorGate;

            if (DobjArtAc == null)
            {
                PrintDontFollowYou();

                NextState = Globals.CreateInstance <IStartState>();

                goto Cleanup;
            }

            NextState = Globals.CreateInstance <IBeforePlayerMoveState>(x =>
            {
                x.DoorGateArtifact = DobjArtifact;
            });

Cleanup:

            if (NextState == null)
            {
                NextState = Globals.CreateInstance <IMonsterStartState>();
            }
        }
Beispiel #2
0
        public virtual bool IsAttackable01(ref IArtifactCategory ac)
        {
            var artTypes = new ArtifactType[] { ArtifactType.DeadBody, ArtifactType.DisguisedMonster, ArtifactType.InContainer, ArtifactType.DoorGate };

            ac = GetArtifactCategory(artTypes, false);

            return(!Globals.IsRulesetVersion(5) && ac != null);
        }
Beispiel #3
0
        public virtual void PrintLightAlmostOutCheck(IArtifact artifact, IArtifactCategory ac)
        {
            Debug.Assert(artifact != null && ac != null);

            if (ac.Field1 <= 20)
            {
                gOut.Print("{0}{1}", artifact.GetTheName(true, buf: Globals.Buf01), ac.Field1 <= 10 ? " is almost out!" : " grows dim!");
            }
        }
Beispiel #4
0
        public virtual RetCode SetArtifactCategoryCount(long count)
        {
            RetCode rc;

            if (count < 1 || count > Constants.NumArtifactCategories)
            {
                rc = RetCode.InvalidArg;

                // PrintError

                goto Cleanup;
            }

            rc = RetCode.Success;

            var categories01 = new IArtifactCategory[count];

            var i = 0L;

            if (categories01.Length < Categories.Length)
            {
                while (i < categories01.Length)
                {
                    categories01[i] = GetCategories(i);

                    i++;
                }
            }
            else
            {
                while (i < Categories.Length)
                {
                    categories01[i] = GetCategories(i);

                    i++;
                }

                while (i < categories01.Length)
                {
                    categories01[i] = Globals.CreateInstance <IArtifactCategory>(x =>
                    {
                        x.Parent = this;
                    });

                    i++;
                }
            }

            Categories = categories01;

Cleanup:

            _lastArtifactCategory = null;

            return(rc);
        }
Beispiel #5
0
        public override void PrintLightAlmostOutCheck(IArtifact artifact, IArtifactCategory ac)
        {
            Debug.Assert(artifact != null && ac != null);

            if (artifact.Uid == 1)
            {
                if (ac.Field1 <= 10 && gEngine.RollDice(1, 100, 0) > 50)
                {
                    gOut.Print("{0} flickers momentarily.", artifact.GetTheName(true, buf: Globals.Buf01));
                }
            }
            else
            {
                base.PrintLightAlmostOutCheck(artifact, ac);
            }
        }
Beispiel #6
0
        public virtual IArtifactCategory GetArtifactCategory(ArtifactType[] artifactTypes, bool categoryArrayPrecedence = true)
        {
            IArtifactCategory result = null;

            if (artifactTypes == null)
            {
                // PrintError

                goto Cleanup;
            }

            if (GetCategories(0) != null && GetCategories(0).Type != ArtifactType.None)
            {
                if (categoryArrayPrecedence)
                {
                    result = Categories.FirstOrDefault(ac => ac != null && artifactTypes.Contains(ac.Type));
                }
                else
                {
                    foreach (var at in artifactTypes)
                    {
                        result = Categories.FirstOrDefault(ac => ac != null && ac.Type == at);

                        if (result != null)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                result = null;
            }

Cleanup:

            _lastArtifactCategory = result;

            return(result);
        }
Beispiel #7
0
        public virtual IArtifactCategory GetArtifactCategory(ArtifactType artifactType)
        {
            IArtifactCategory result = null;

            if (_lastArtifactCategory != null && _lastArtifactCategory.Type == artifactType)
            {
                result = _lastArtifactCategory;
            }
            else if (GetCategories(0) != null && GetCategories(0).Type != ArtifactType.None)
            {
                result = Categories.FirstOrDefault(ac => ac != null && ac.Type == artifactType);
            }
            else
            {
                result = null;
            }

            _lastArtifactCategory = result;

            return(result);
        }
Beispiel #8
0
        public override void ProcessArtifact(IArtifact artifact, IArtifactCategory ac, ref bool nlFlag)
        {
            Debug.Assert(artifact != null);

            Debug.Assert(ac != null);

            // Get slime

            if (artifact.Uid == 24 || artifact.Uid == 25)
            {
                ProcessAction(() => PrintCantGetSlime(), ref nlFlag);
            }

            // Get rope

            else if (artifact.Uid == 28)
            {
                gEngine.PrintEffectDesc(25);

                if (!gGameState.PulledRope)
                {
                    var monsters = gEngine.GetMonsterList(m => m.Uid >= 14 && m.Uid <= 16);

                    foreach (var monster in monsters)
                    {
                        monster.SetInRoomUid(48);
                    }

                    gGameState.PulledRope = true;
                }

                ProcessAction(() => PrintCantDetachRope(), ref nlFlag);
            }
            else
            {
                base.ProcessArtifact(artifact, ac, ref nlFlag);
            }
        }
Beispiel #9
0
        public override void ProcessArtifact(IArtifact artifact, IArtifactCategory ac, ref bool nlFlag)
        {
            // Get the handle

            if (artifact.Uid == 23)
            {
                var SwampMonster = gMDB[6];                 // create Swamp monster variable
                var SilverSword  = gADB[25];                // create SilverSword variable

                if (gLMKKP1.SwampMonsterKilled == 0 && SwampMonster.IsInLimbo())
                {
                    var effect = gEDB[20];
                    SwampMonster.SetInRoomUid(8);
                    ProcessAction(() => gOut.Print("{0}", effect.Desc), ref nlFlag);
                }
                else if (SwampMonster.IsInRoomUid(8))
                {
                    var effect = gEDB[21];
                    ProcessAction(() => gOut.Print("{0}", effect.Desc), ref nlFlag);
                }
                else if (gLMKKP1.SwampMonsterKilled == 1)
                {
                    var effect = gEDB[22];
                    ProcessAction(() => gOut.Print("{0}", effect.Desc), ref nlFlag);
                    SilverSword.SetCarriedByCharacter();                                        // TODO: put silver sword in Room if its too heavy to be carried
                    artifact.SetInLimbo();
                }
                else
                {
                    base.ProcessArtifact(artifact, ac, ref nlFlag);
                }
            }
            else
            {
                base.ProcessArtifact(artifact, ac, ref nlFlag);
            }
        }
Beispiel #10
0
        public virtual void ProcessArtifact(IArtifact artifact, IArtifactCategory ac, ref bool nlFlag)
        {
            RetCode rc;

            Debug.Assert(artifact != null);

            Debug.Assert(ac != null);

            if (ac.Type == ArtifactType.DisguisedMonster)
            {
                ProcessAction(() => gEngine.RevealDisguisedMonster(ActorRoom, artifact), ref nlFlag);
            }
            else if (artifact.Weight > 900)
            {
                ProcessAction(() => PrintDontBeAbsurd(), ref nlFlag);
            }
            else if (artifact.IsUnmovable01())
            {
                ProcessAction(() => PrintCantVerbThat(artifact), ref nlFlag);
            }
            else
            {
                DobjArtifactCount = 0;

                DobjArtifactWeight = artifact.Weight;

                if (artifact.GeneralContainer != null)
                {
                    rc = artifact.GetContainerInfo(ref _dobjArtifactCount, ref _dobjArtifactWeight, ContainerType.In, true);

                    Debug.Assert(gEngine.IsSuccess(rc));

                    rc = artifact.GetContainerInfo(ref _dobjArtifactCount, ref _dobjArtifactWeight, ContainerType.On, true);

                    Debug.Assert(gEngine.IsSuccess(rc));
                }

                ActorMonsterInventoryWeight = 0;

                rc = ActorMonster.GetFullInventoryWeight(ref _actorMonsterInventoryWeight, recurse: true);

                Debug.Assert(gEngine.IsSuccess(rc));

                if (ac.Type == ArtifactType.DeadBody && ac.Field1 != 1)
                {
                    ProcessAction(() => PrintBestLeftAlone(artifact), ref nlFlag);
                }
                else if (!OmitWeightCheck && (DobjArtifactWeight + ActorMonsterInventoryWeight > ActorMonster.GetWeightCarryableGronds()))
                {
                    ProcessAction(() => PrintTooHeavy(artifact), ref nlFlag);
                }
                else if (ac.Type == ArtifactType.BoundMonster)
                {
                    ProcessAction(() => PrintMustBeFreed(artifact), ref nlFlag);
                }
                else
                {
                    WeaponAffinityMonster = gEngine.GetMonsterList(m => m.IsInRoom(ActorRoom) && m.Weapon == -artifact.Uid - 1 && m != ActorMonster).FirstOrDefault();

                    if (WeaponAffinityMonster != null)
                    {
                        ProcessAction(() => PrintObjBelongsToActor(artifact, WeaponAffinityMonster), ref nlFlag);
                    }
                    else
                    {
                        IsCarriedByContainer = artifact.IsCarriedByContainer();

                        artifact.SetCarriedByCharacter();

                        if (NextState is IRequestCommand)
                        {
                            PrintReceived(artifact);
                        }
                        else if (NextState is IRemoveCommand || IsCarriedByContainer)
                        {
                            PrintRetrieved(artifact);
                        }
                        else
                        {
                            PrintTaken(artifact);
                        }

                        nlFlag = true;
                    }
                }
            }
        }
Beispiel #11
0
 public virtual void SetCategories(long index, IArtifactCategory value)
 {
     Categories[index] = value;
 }
Beispiel #12
0
        public virtual IArtifactCategory GetCategories(long index)
        {
            _lastArtifactCategory = Categories[index];

            return(_lastArtifactCategory);
        }
Beispiel #13
0
        public override void PlayerExecute()
        {
            RetCode rc;

            Debug.Assert(gDobjArtifact != null || gDobjMonster != null);

            if (!BlastSpell && gActorMonster.Weapon <= 0)
            {
                PrintMustFirstReadyWeapon();

                NextState = Globals.CreateInstance <IStartState>();

                goto Cleanup;
            }

            if (gDobjArtifact != null)
            {
                IArtifactCategory ac = null;

                if (gDobjArtifact.IsAttackable01(ref ac))
                {
                    Debug.Assert(ac != null);

                    if (ac.Type == ArtifactType.DeadBody)
                    {
                        if (BlastSpell)
                        {
                            gOut.Print("{0}", gEngine.GetBlastDesc());
                        }

                        gDobjArtifact.SetInLimbo();

                        PrintHackToBits();

                        goto Cleanup;
                    }

                    if (ac.Type == ArtifactType.DisguisedMonster)
                    {
                        gEngine.RevealDisguisedMonster(gActorRoom, gDobjArtifact);

                        var monster = gMDB[ac.Field1];

                        Debug.Assert(monster != null);

                        ICommand command = null;

                        if (BlastSpell)
                        {
                            command = Globals.CreateInstance <IBlastCommand>(x =>
                            {
                                x.CastSpell = false;
                            });
                        }
                        else
                        {
                            command = Globals.CreateInstance <IAttackCommand>();
                        }

                        CopyCommandData(command);

                        command.Dobj = monster;

                        NextState = command;

                        goto Cleanup;
                    }

                    /*
                     *      Damage it...
                     */

                    var keyUid = ac.GetKeyUid();

                    if (keyUid == -2)
                    {
                        PrintAlreadyBrokeIt(gDobjArtifact);

                        goto Cleanup;
                    }

                    var breakageStrength = ac.GetBreakageStrength();

                    if (breakageStrength < 1000)
                    {
                        gOut.Print("Nothing happens.");

                        goto Cleanup;
                    }

                    var d = 0L;

                    var s = 0L;

                    if (BlastSpell)
                    {
                        d = 2;

                        s = 5;

                        Globals.Buf.SetPrint("{0}", gEngine.GetBlastDesc());
                    }
                    else
                    {
                        var weapon = gADB[gActorMonster.Weapon];

                        Debug.Assert(weapon != null);

                        var weaponAc = weapon.GeneralWeapon;

                        Debug.Assert(weaponAc != null);

                        d = weaponAc.Field3;

                        s = weaponAc.Field4;

                        BuildWhamHitObj();
                    }

                    gOut.Write("{0}", Globals.Buf);

                    var rl = gEngine.RollDice(d, s, 0);

                    breakageStrength -= rl;

                    if (breakageStrength > 1000)
                    {
                        ac.SetBreakageStrength(breakageStrength);

                        rc = gDobjArtifact.SyncArtifactCategories(ac);

                        Debug.Assert(gEngine.IsSuccess(rc));

                        goto Cleanup;
                    }

                    /*
                     *      Broken!
                     */

                    ac.SetOpen(true);

                    ac.SetKeyUid(-2);

                    ac.Field4 = 0;

                    rc = gDobjArtifact.SyncArtifactCategories(ac);

                    Debug.Assert(gEngine.IsSuccess(rc));

                    gDobjArtifact.Value = 0;

                    rc = gDobjArtifact.AddStateDesc(gDobjArtifact.GetBrokenDesc());

                    Debug.Assert(gEngine.IsSuccess(rc));

                    BuildSmashesToPieces();

                    if (ac.Type == ArtifactType.InContainer)
                    {
                        var artifactList = gDobjArtifact.GetContainedList(containerType: ContainerType.In);

                        if (gDobjArtifact.OnContainer != null && gDobjArtifact.IsInContainerOpenedFromTop())
                        {
                            artifactList.AddRange(gDobjArtifact.GetContainedList(containerType: ContainerType.On));
                        }

                        foreach (var artifact in artifactList)
                        {
                            artifact.SetInRoom(gActorRoom);
                        }

                        if (artifactList.Count > 0)
                        {
                            BuildContentsSpillToFloor();
                        }

                        ac.Field3 = 0;
                    }

                    Globals.Buf.AppendFormat("!{0}", Environment.NewLine);

                    gOut.Write("{0}", Globals.Buf);
                }
                else
                {
                    PrintWhyAttack(gDobjArtifact);

                    NextState = Globals.CreateInstance <IStartState>();

                    goto Cleanup;
                }
            }
            else
            {
                if (!CheckAttack && gDobjMonster.Friendliness != Friendliness.Enemy)
                {
                    gOut.Write("{0}Attack non-enemy (Y/N): ", Environment.NewLine);

                    Globals.Buf.Clear();

                    rc = Globals.In.ReadField(Globals.Buf, Constants.BufSize02, null, ' ', '\0', false, null, gEngine.ModifyCharToUpper, gEngine.IsCharYOrN, null);

                    Debug.Assert(gEngine.IsSuccess(rc));

                    if (Globals.Buf.Length == 0 || Globals.Buf[0] == 'N')
                    {
                        NextState = Globals.CreateInstance <IStartState>();

                        goto Cleanup;
                    }

                    CheckAttack = true;

                    gEngine.MonsterGetsAggravated(gDobjMonster);
                }

                var combatSystem = Globals.CreateInstance <ICombatSystem>(x =>
                {
                    x.SetNextStateFunc = s => NextState = s;

                    x.OfMonster = gActorMonster;

                    x.DfMonster = gDobjMonster;

                    x.MemberNumber = MemberNumber;

                    x.AttackNumber = AttackNumber;

                    x.BlastSpell = BlastSpell;

                    x.OmitSkillGains = !BlastSpell && !ShouldAllowSkillGains();
                });

                combatSystem.ExecuteAttack();
            }

Cleanup:

            if (NextState == null)
            {
                NextState = Globals.CreateInstance <IMonsterStartState>();
            }
        }
Beispiel #14
0
        public override void Execute()
        {
            Debug.Assert(DobjArtifact != null);

            DrinkableAc = DobjArtifact.Drinkable;

            EdibleAc = DobjArtifact.Edible;

            DobjArtAc = DrinkableAc != null ? DrinkableAc : EdibleAc;

            if (DobjArtAc == null)
            {
                PrintCantVerbObj(DobjArtifact);

                NextState = Globals.CreateInstance <IStartState>();

                goto Cleanup;
            }

            if (DobjArtAc.Type == ArtifactType.Edible)
            {
                NextState = Globals.CreateInstance <IEatCommand>();

                CopyCommandData(NextState as ICommand);

                goto Cleanup;
            }

            if (!DobjArtAc.IsOpen())
            {
                PrintMustFirstOpen(DobjArtifact);

                NextState = Globals.CreateInstance <IStartState>();

                goto Cleanup;
            }

            if (DobjArtAc.Field2 < 1)
            {
                PrintNoneLeft(DobjArtifact);

                goto Cleanup;
            }

            if (DobjArtAc.Field2 != Constants.InfiniteDrinkableEdible)
            {
                DobjArtAc.Field2--;
            }

            ProcessEvents(EventType.BeforeNowEmptyArtifactCheck);

            if (GotoCleanup)
            {
                goto Cleanup;
            }

            if (DobjArtAc.Field2 < 1)
            {
                DobjArtifact.Value = 0;

                DobjArtifact.AddStateDesc(DobjArtifact.GetEmptyDesc());

                PrintVerbItAll(DobjArtifact);
            }
            else if (DobjArtAc.Field1 == 0)
            {
                PrintOkay(DobjArtifact);
            }

            if (DobjArtAc.Field1 != 0)
            {
                ActorMonster.DmgTaken -= DobjArtAc.Field1;

                if (ActorMonster.DmgTaken < 0)
                {
                    ActorMonster.DmgTaken = 0;
                }

                if (DobjArtAc.Field1 > 0)
                {
                    PrintFeelBetter(DobjArtifact);
                }
                else
                {
                    PrintFeelWorse(DobjArtifact);
                }

                Globals.Buf.SetFormat("{0}You are ", Environment.NewLine);

                ActorMonster.AddHealthStatus(Globals.Buf);

                gOut.Write("{0}", Globals.Buf);

                if (ActorMonster.IsDead())
                {
                    gGameState.Die = 1;

                    NextState = Globals.CreateInstance <IPlayerDeadState>(x =>
                    {
                        x.PrintLineSep = true;
                    });

                    goto Cleanup;
                }
            }

            ProcessEvents(EventType.AfterDrinkArtifact);

            if (GotoCleanup)
            {
                goto Cleanup;
            }

Cleanup:

            if (NextState == null)
            {
                NextState = Globals.CreateInstance <IMonsterStartState>();
            }
        }
Beispiel #15
0
        public virtual void DecrementLightTurnCounter(IArtifact artifact, IArtifactCategory ac)
        {
            Debug.Assert(artifact != null && ac != null);

            ac.Field1--;
        }
Beispiel #16
0
        public override void Execute()
        {
            Debug.Assert(DobjArtifact != null);

            ProcessEvents(EventType.BeforeUseArtifact);

            if (GotoCleanup)
            {
                goto Cleanup;
            }

            DobjArtAc = DobjArtifact.GetArtifactCategory(ArtTypes, false);

            if (DobjArtAc == null)
            {
                PrintTryDifferentCommand(DobjArtifact);

                goto Cleanup;
            }

            if (DobjArtAc.IsWeapon01())
            {
                NextState = Globals.CreateInstance <IReadyCommand>();

                CopyCommandData(NextState as ICommand);

                goto Cleanup;
            }

            if (DobjArtAc.Type == ArtifactType.DisguisedMonster)
            {
                if (!DobjArtifact.IsUnmovable() && !DobjArtifact.IsCarriedByCharacter())
                {
                    if (DobjArtifact.IsCarriedByContainer())
                    {
                        PrintRemovingFirst(DobjArtifact);
                    }
                    else
                    {
                        PrintTakingFirst(DobjArtifact);
                    }
                }

                gEngine.RevealDisguisedMonster(ActorRoom, DobjArtifact);

                NextState = Globals.CreateInstance <IMonsterStartState>();

                goto Cleanup;
            }

            if (DobjArtAc.Type == ArtifactType.Drinkable)
            {
                NextState = Globals.CreateInstance <IDrinkCommand>();

                CopyCommandData(NextState as ICommand);

                goto Cleanup;
            }

            if (DobjArtAc.Type == ArtifactType.Edible)
            {
                NextState = Globals.CreateInstance <IEatCommand>();

                CopyCommandData(NextState as ICommand);

                goto Cleanup;
            }

            Debug.Assert(DobjArtAc.Type == ArtifactType.Wearable);

            NextState = Globals.CreateInstance <IWearCommand>();

            CopyCommandData(NextState as ICommand);

Cleanup:

            if (NextState == null)
            {
                NextState = Globals.CreateInstance <IMonsterStartState>();
            }
        }
Beispiel #17
0
        public override void Execute()
        {
            Debug.Assert(DobjArtifact != null);

            InContainerAc = DobjArtifact.InContainer;

            DoorGateAc = DobjArtifact.DoorGate;

            DrinkableAc = DobjArtifact.Drinkable;

            EdibleAc = DobjArtifact.Edible;

            ReadableAc = DobjArtifact.Readable;

            DobjArtAc = InContainerAc != null ? InContainerAc :
                        DoorGateAc != null ? DoorGateAc :
                        DrinkableAc != null ? DrinkableAc :
                        EdibleAc != null ? EdibleAc :
                        ReadableAc;

            if (DobjArtAc == null)
            {
                PrintCantVerbIt(DobjArtifact);

                NextState = Globals.CreateInstance <IStartState>();

                goto Cleanup;
            }

            if (DobjArtAc.Type == ArtifactType.Drinkable || DobjArtAc.Type == ArtifactType.Edible || DobjArtAc.Type == ArtifactType.Readable || DobjArtAc.GetKeyUid() == -1)
            {
                PrintDontNeedTo();

                NextState = Globals.CreateInstance <IStartState>();

                goto Cleanup;
            }

            if (DobjArtAc.Type == ArtifactType.DoorGate)
            {
                if (DobjArtifact.Seen)
                {
                    DobjArtAc.Field4 = 0;
                }

                if (DobjArtAc.Field4 == 1)
                {
                    PrintDontFollowYou();

                    NextState = Globals.CreateInstance <IStartState>();

                    goto Cleanup;
                }
            }

            if (DobjArtAc.GetKeyUid() == -2)
            {
                PrintBrokeIt(DobjArtifact);

                goto Cleanup;
            }

            if (!DobjArtAc.IsOpen())
            {
                PrintNotOpen(DobjArtifact);

                NextState = Globals.CreateInstance <IStartState>();

                goto Cleanup;
            }

            PrintClosed(DobjArtifact);

            DobjArtAc.SetOpen(false);

            ProcessEvents(EventType.AfterCloseArtifact);

            if (GotoCleanup)
            {
                goto Cleanup;
            }

Cleanup:

            if (NextState == null)
            {
                NextState = Globals.CreateInstance <IMonsterStartState>();
            }
        }