Пример #1
0
        public override void Execute()
        {
            RetCode rc;

            Debug.Assert(DobjArtifact != null);

            if (DobjArtifact.IsReadyableByMonster(ActorMonster) && DobjArtifact.IsCarriedByMonster(ActorMonster))
            {
                ActorWeapon = gADB[ActorMonster.Weapon];

                if (ActorWeapon != null)
                {
                    rc = ActorWeapon.RemoveStateDesc(ActorWeapon.GetReadyWeaponDesc());

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

                ActorMonster.Weapon = DobjArtifact.Uid;

                rc = DobjArtifact.AddStateDesc(DobjArtifact.GetReadyWeaponDesc());

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

                Debug.Assert(gCharMonster != null);

                if (gCharMonster.IsInRoom(ActorRoom))
                {
                    if (ActorRoom.IsLit())
                    {
                        MonsterName = ActorMonster.EvalPlural(ActorMonster.GetTheName(true), ActorMonster.GetArticleName(true, true, false, true, Globals.Buf01));

                        gOut.Print("{0} readies {1}.", MonsterName, DobjArtifact.GetArticleName());
                    }
                    else
                    {
                        MonsterName = string.Format("An unseen {0}", ActorMonster.CheckNBTLHostility() ? "offender" : "entity");

                        gOut.Print("{0} readies {1}.", MonsterName, "a weapon");
                    }

                    if (ActorMonster.CheckNBTLHostility())
                    {
                        Globals.Thread.Sleep(gGameState.PauseCombatMs);
                    }
                }
            }

            if (NextState == null)
            {
                NextState = Globals.CreateInstance <IErrorState>(x =>
                {
                    x.ErrorMessage = string.Format("{0}: NextState == null", Name);
                });
            }
        }
Пример #2
0
        public override void Execute()
        {
            RetCode rc;

            Debug.Assert(GetAll || DobjArtifact != null);

            if (GetAll)
            {
                // screen out all weapons in the room which have monsters present with affinities to those weapons

                TakenArtifactList = ActorRoom.GetTakeableList().Where(a => gEngine.GetMonsterList(m => m.IsInRoom(ActorRoom) && m.Weapon == -a.Uid - 1 && m != ActorMonster).FirstOrDefault() == null).ToList();
            }
            else
            {
                TakenArtifactList = new List <IArtifact>()
                {
                    DobjArtifact
                };
            }

            if (TakenArtifactList.Count <= 0)
            {
                gOut.Print("There's nothing for you to get.");

                NextState = Globals.CreateInstance <IStartState>();

                goto Cleanup;
            }

            ArtTypes = new ArtifactType[] { ArtifactType.DisguisedMonster, ArtifactType.DeadBody, ArtifactType.BoundMonster, ArtifactType.Weapon, ArtifactType.MagicWeapon };

            NewlineFlag = false;

            foreach (var artifact in TakenArtifactList)
            {
                DobjArtAc = artifact.GetArtifactCategory(ArtTypes, false);

                if (DobjArtAc == null)
                {
                    DobjArtAc = artifact.GetCategories(0);
                }

                Debug.Assert(DobjArtAc != null);

                OmitWeightCheck = artifact.IsCarriedByCharacter(true);

                ProcessArtifact(artifact, DobjArtAc, ref _newlineFlag);

                if (artifact.IsCarriedByCharacter())
                {
                    // when a weapon is picked up all monster affinities to that weapon are broken

                    FumbleMonsterList = gEngine.GetMonsterList(m => m.Weapon == -artifact.Uid - 1 && m != ActorMonster);

                    foreach (var monster in FumbleMonsterList)
                    {
                        monster.Weapon = -1;
                    }

                    WeaponArtifactAc = artifact.GeneralWeapon;

                    if (artifact.IsReadyableByCharacter() && (WeaponArtifact == null || gEngine.WeaponPowerCompare(artifact, WeaponArtifact) > 0) && (!GetAll || TakenArtifactList.Count == 1 || gGameState.Sh < 1 || WeaponArtifactAc.Field5 < 2))
                    {
                        WeaponArtifact = artifact;
                    }
                }
            }

            if (NewlineFlag)
            {
                gOut.WriteLine();

                NewlineFlag = false;
            }

            if (ActorRoom.IsLit())
            {
                if (!gEngine.AutoDisplayUnseenArtifactDescs && !GetAll && DobjArtifact.IsCarriedByCharacter() && !DobjArtifact.Seen)
                {
                    Globals.Buf.Clear();

                    rc = DobjArtifact.BuildPrintedFullDesc(Globals.Buf, false);

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

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

                    DobjArtifact.Seen = true;
                }
            }

            if (ActorMonster.Weapon <= 0 && WeaponArtifact != null && NextState == null)
            {
                RedirectCommand = Globals.CreateInstance <IReadyCommand>();

                CopyCommandData(RedirectCommand);

                RedirectCommand.Dobj = WeaponArtifact;

                NextState = RedirectCommand;
            }

Cleanup:

            if (NextState == null)
            {
                NextState = Globals.CreateInstance <IMonsterStartState>();
            }
        }
Пример #3
0
        public virtual void Execute()
        {
            Debug.Assert(ActorMonster != null);

            ActorRoom = ActorMonster.GetInRoom();

            Debug.Assert(ActorRoom != null);

            if (InputBuf.Length == 0)
            {
                InputBuf.SetFormat("{0}", LastInputStr);

                if (InputBuf.Length > 0 && ActorMonster.IsCharacterMonster())
                {
                    if (Environment.NewLine.Length == 1 && Globals.CursorPosition.Y > -1 && Globals.CursorPosition.Y + 1 >= gOut.GetBufferHeight())
                    {
                        Globals.CursorPosition.Y--;
                    }

                    gOut.SetCursorPosition(Globals.CursorPosition);

                    if (Globals.LineWrapUserInput)
                    {
                        gEngine.LineWrap(InputBuf.ToString(), Globals.Buf, Globals.CommandPrompt.Length);
                    }
                    else
                    {
                        Globals.Buf.SetFormat("{0}", InputBuf.ToString());
                    }

                    gOut.WordWrap = false;

                    gOut.WriteLine(Globals.Buf);

                    gOut.WordWrap = true;
                }
            }

            LastInputStr = InputBuf.ToString();

            InputBuf = ReplacePrepositions(InputBuf);

            Tokens = InputBuf.ToString().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            if (CurrToken < Tokens.Length)
            {
                if (Tokens.Length == 1)
                {
                    Globals.Buf.SetFormat("{0}", Tokens[CurrToken]);

                    Tokens[CurrToken] = Globals.Buf.TrimEndPunctuationMinusPound().ToString().Trim();
                }

                if (Tokens[CurrToken].Length == 0)
                {
                    Tokens[CurrToken] = "???";
                }
                else if (string.Equals(Tokens[CurrToken], "at", StringComparison.OrdinalIgnoreCase))
                {
                    Tokens[CurrToken] = "a";
                }

                var command = Globals.CommandList.FirstOrDefault(x => x.Verb != null && string.Equals(x.Verb, Tokens[CurrToken], StringComparison.OrdinalIgnoreCase) && x.IsEnabled(ActorMonster));

                if (command == null)
                {
                    command = Globals.CommandList.FirstOrDefault(x => x.Synonyms != null && x.Synonyms.FirstOrDefault(s => string.Equals(s, Tokens[CurrToken], StringComparison.OrdinalIgnoreCase)) != null && x.IsEnabled(ActorMonster));
                }

                if (command == null)
                {
                    command = Globals.CommandList.FirstOrDefault(x => x.Verb != null && (x.Verb.StartsWith(Tokens[CurrToken], StringComparison.OrdinalIgnoreCase) || x.Verb.EndsWith(Tokens[CurrToken], StringComparison.OrdinalIgnoreCase)) && x.IsEnabled(ActorMonster));
                }

                if (command == null)
                {
                    command = Globals.CommandList.FirstOrDefault(x => x.Synonyms != null && x.Synonyms.FirstOrDefault(s => s.StartsWith(Tokens[CurrToken], StringComparison.OrdinalIgnoreCase) || s.EndsWith(Tokens[CurrToken], StringComparison.OrdinalIgnoreCase)) != null && x.IsEnabled(ActorMonster));
                }

                if (command != null)
                {
                    CurrToken++;

                    NextState = Activator.CreateInstance(command.GetType()) as IState;

                    command = NextState as ICommand;

                    Debug.Assert(command != null);

                    command.CommandParser = this;

                    command.ActorMonster = ActorMonster;

                    command.ActorRoom = ActorRoom;

                    command.Dobj = DobjData.Obj;

                    command.Iobj = IobjData.Obj;

                    if (command.ShouldStripTrailingPunctuation() && Tokens.Length > 1)
                    {
                        Globals.Buf.SetFormat("{0}", Tokens[Tokens.Length - 1]);

                        Tokens[Tokens.Length - 1] = Globals.Buf.TrimEndPunctuationMinusPound().ToString().Trim();
                    }

                    if (ActorMonster.IsCharacterMonster())
                    {
                        CheckPlayerCommand(command, false);

                        if (NextState == command)
                        {
                            if (ActorRoom.IsLit() || command.IsDarkEnabled)
                            {
                                command.FinishParsing();

                                if (NextState == command)
                                {
                                    CheckPlayerCommand(command, true);
                                }
                            }
                            else
                            {
                                NextState = null;
                            }
                        }
                    }
                    else
                    {
                        command.FinishParsing();
                    }

                    if (NextState == null)
                    {
                        NextState = Globals.CreateInstance <IStartState>();
                    }
                }
            }
        }
Пример #4
0
        public override void Execute()
        {
            RetCode rc;

            Debug.Assert(DobjArtifact != null);

            ArtTypes = new ArtifactType[] { ArtifactType.DisguisedMonster, ArtifactType.DeadBody, ArtifactType.BoundMonster, ArtifactType.Weapon, ArtifactType.MagicWeapon };

            DobjArtAc = DobjArtifact.GetArtifactCategory(ArtTypes, false);

            if (DobjArtAc == null)
            {
                DobjArtAc = DobjArtifact.GetCategories(0);
            }

            if (DobjArtAc != null && DobjArtAc.Type != ArtifactType.DisguisedMonster && DobjArtifact.Weight <= 900 && !DobjArtifact.IsUnmovable01() && (DobjArtAc.Type != ArtifactType.DeadBody || DobjArtAc.Field1 == 1) && DobjArtAc.Type != ArtifactType.BoundMonster)
            {
                OmitWeightCheck = DobjArtifact.IsCarriedByMonster(ActorMonster, true);

                DobjArtifactCount = 0;

                DobjArtifactWeight = DobjArtifact.Weight;

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

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

                    rc = DobjArtifact.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 (!gEngine.EnforceMonsterWeightLimits || OmitWeightCheck || (DobjArtifactWeight <= ActorMonster.GetWeightCarryableGronds() && DobjArtifactWeight + ActorMonsterInventoryWeight <= ActorMonster.GetWeightCarryableGronds() * ActorMonster.CurrGroupCount))
                {
                    DobjArtifact.SetCarriedByMonster(ActorMonster);

                    Debug.Assert(gCharMonster != null);

                    if (gCharMonster.IsInRoom(ActorRoom))
                    {
                        if (ActorRoom.IsLit())
                        {
                            MonsterName = ActorMonster.EvalPlural(ActorMonster.GetTheName(true), ActorMonster.GetArticleName(true, true, false, true, Globals.Buf01));

                            gOut.Print("{0} picks up {1}.", MonsterName, DobjArtifact.GetTheName());
                        }
                        else
                        {
                            MonsterName = string.Format("An unseen {0}", ActorMonster.CheckNBTLHostility() ? "offender" : "entity");

                            gOut.Print("{0} picks up {1}.", MonsterName, "a weapon");
                        }
                    }

                    // when a weapon is picked up all monster affinities to that weapon are broken

                    FumbleMonsterList = gEngine.GetMonsterList(m => m.Weapon == -DobjArtifact.Uid - 1 && m != ActorMonster);

                    foreach (var monster in FumbleMonsterList)
                    {
                        monster.Weapon = -1;
                    }
                }
            }

            if (NextState == null)
            {
                NextState = Globals.CreateInstance <IErrorState>(x =>
                {
                    x.ErrorMessage = string.Format("{0}: NextState == null", Name);
                });
            }
        }
Пример #5
0
        public override void Execute()
        {
            RetCode rc;

            Debug.Assert(DobjArtifact != null || DobjMonster != null);

            if (!ActorRoom.IsLit())
            {
                Debug.Assert(DobjMonster != null && DobjMonster.IsCharacterMonster());
            }

            if (DobjArtifact != null)
            {
                DobjArtAc = DobjArtifact.InContainer;

                if (DobjArtAc == null)
                {
                    DobjArtAc = DobjArtifact.OnContainer;
                }

                if (DobjArtAc == null && AllowExtendedContainers)
                {
                    DobjArtAc = DobjArtifact.UnderContainer;
                }

                if (DobjArtAc == null && AllowExtendedContainers)
                {
                    DobjArtAc = DobjArtifact.BehindContainer;
                }

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

                    NextState = Globals.CreateInstance <IStartState>();

                    goto Cleanup;
                }

                DobjArtContainerType = gEngine.GetContainerType(DobjArtAc.Type);

                if (DobjArtifact.IsEmbeddedInRoom(ActorRoom))
                {
                    DobjArtifact.SetInRoom(ActorRoom);
                }

                if (DobjArtAc == DobjArtifact.InContainer && !DobjArtAc.IsOpen() && !DobjArtifact.ShouldExposeInContentsWhenClosed())
                {
                    PrintMustFirstOpen(DobjArtifact);

                    NextState = Globals.CreateInstance <IStartState>();

                    goto Cleanup;
                }

                DobjArtContainedArtifactList = DobjArtifact.GetContainedList(containerType: DobjArtContainerType);

                ShowCharOwned = !DobjArtifact.IsCarriedByCharacter() && !DobjArtifact.IsWornByCharacter();

                if (DobjArtContainedArtifactList.Count > 0)
                {
                    Globals.Buf.SetFormat("{0}{1} {2} you see ",
                                          Environment.NewLine,
                                          gEngine.EvalContainerType(DobjArtContainerType, "Inside", "On", "Under", "Behind"),
                                          DobjArtifact.GetTheName(false, ShowCharOwned, false, false, Globals.Buf01));

                    rc = gEngine.GetRecordNameList(DobjArtContainedArtifactList.Cast <IGameBase>().ToList(), ArticleType.A, ShowCharOwned, StateDescDisplayCode.None, false, false, Globals.Buf);

                    Debug.Assert(gEngine.IsSuccess(rc));
                }
                else
                {
                    Globals.Buf.SetFormat("{0}There's nothing {1} {2}",
                                          Environment.NewLine,
                                          gEngine.EvalContainerType(DobjArtContainerType, "inside", "on", "under", "behind"),
                                          DobjArtifact.GetTheName(false, ShowCharOwned, false, false, Globals.Buf01));
                }

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

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

                goto Cleanup;
            }

            IsCharMonster = DobjMonster.IsCharacterMonster();

            if (!IsCharMonster && DobjMonster.Reaction < Friendliness.Friend)
            {
                gEngine.MonsterEmotes(DobjMonster);

                gOut.WriteLine();

                goto Cleanup;
            }

            HasWornInventory = DobjMonster.HasWornInventory();

            if (HasWornInventory)
            {
                DobjMonsterWornArtifactList = DobjMonster.GetWornList();

                if (DobjMonsterWornArtifactList.Count > 0)
                {
                    Globals.Buf.SetFormat("{0}{1} {2} {3}",
                                          Environment.NewLine,
                                          IsCharMonster ? "You" : DobjMonster.EvalPlural(DobjMonster.GetTheName(true, true, false, true, Globals.Buf01), "They"),
                                          IsCharMonster ? "are" : DobjMonster.EvalPlural("is", "are"),
                                          IsCharMonster ? "wearing " : DobjMonster.EvalPlural("wearing ", "wearing among them "));

                    rc = gEngine.GetRecordNameList(DobjMonsterWornArtifactList.Cast <IGameBase>().ToList(), ArticleType.A, IsCharMonster ? false : true, IsCharMonster ? StateDescDisplayCode.AllStateDescs : StateDescDisplayCode.SideNotesOnly, IsCharMonster ? true : false, false, Globals.Buf);

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

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

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

            HasCarriedInventory = DobjMonster.HasCarriedInventory();

            if (HasCarriedInventory)
            {
                DobjMonsterCarriedArtifactList = DobjMonster.GetCarriedList();

                if (IsCharMonster)
                {
                    // use total debt for characters with no assets; otherwise use HeldGold (which may be debt or asset)

                    TotalGold = gCharacter.HeldGold < 0 && gCharacter.BankGold < 0 ? gCharacter.HeldGold + gCharacter.BankGold : gCharacter.HeldGold;

                    if (TotalGold != 0)
                    {
                        GoldArtifact = Globals.CreateInstance <IArtifact>(x =>
                        {
                            x.Name = string.Format("{0}{1} gold piece{2}",
                                                   TotalGold < 0 ? "a debt of " : "",
                                                   gEngine.GetStringFromNumber(Math.Abs(TotalGold), false, Globals.Buf),
                                                   Math.Abs(TotalGold) != 1 ? "s" : "");
                        });

                        DobjMonsterCarriedArtifactList.Add(GoldArtifact);
                    }
                }

                Globals.Buf.SetFormat("{0}{1} {2} {3}",
                                      Environment.NewLine,
                                      IsCharMonster ? "You" : DobjMonster.EvalPlural(DobjMonster.GetTheName(true, true, false, true, Globals.Buf01), "They"),
                                      IsCharMonster ? "are" : DobjMonster.EvalPlural("is", "are"),
                                      DobjMonsterCarriedArtifactList.Count == 0 ? "" :
                                      IsCharMonster ? "carrying " : DobjMonster.EvalPlural("carrying ", "carrying among them "));

                if (DobjMonsterCarriedArtifactList.Count > 0)
                {
                    rc = gEngine.GetRecordNameList(DobjMonsterCarriedArtifactList.Cast <IGameBase>().ToList(), ArticleType.A, IsCharMonster ? false : true, IsCharMonster ? StateDescDisplayCode.AllStateDescs : StateDescDisplayCode.SideNotesOnly, IsCharMonster ? true : false, false, Globals.Buf);

                    Debug.Assert(gEngine.IsSuccess(rc));
                }
                else
                {
                    Globals.Buf.Append("empty handed");
                }

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

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

            ShouldShowHealthStatusWhenInventoried = DobjMonster.ShouldShowHealthStatusWhenInventoried();

            if (ShouldShowHealthStatusWhenInventoried)
            {
                IsUninjuredGroup = DobjMonster.CurrGroupCount > 1 && DobjMonster.DmgTaken == 0;

                Globals.Buf.SetFormat("{0}{1} {2} ",
                                      Environment.NewLine,
                                      IsCharMonster ? "You" :
                                      IsUninjuredGroup ? "They" :
                                      DobjMonster.GetTheName(true, true, false, true, Globals.Buf01),
                                      IsCharMonster || IsUninjuredGroup ? "are" : "is");

                DobjMonster.AddHealthStatus(Globals.Buf);

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

            if (GoldArtifact != null)
            {
                GoldArtifact.Dispose();

                GoldArtifact = null;
            }

            if (!HasWornInventory && !HasCarriedInventory && !ShouldShowHealthStatusWhenInventoried)
            {
                PrintCantVerbObj(DobjMonster);

                NextState = Globals.CreateInstance <IStartState>();

                goto Cleanup;
            }

Cleanup:

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