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); }); } }
public override void Execute() { RetCode rc; Debug.Assert(DobjArtifact != null); DobjArtAc = DobjArtifact.GetArtifactCategory(ArtTypes, false); if (DobjArtAc == null) { PrintNotWeapon(DobjArtifact); NextState = Globals.CreateInstance <IStartState>(); goto Cleanup; } if (DobjArtAc.Type == ArtifactType.Wearable) { NextState = Globals.CreateInstance <IWearCommand>(); CopyCommandData(NextState as ICommand); goto Cleanup; } if (!DobjArtifact.IsReadyableByCharacter()) { PrintNotReadyableWeapon(DobjArtifact); NextState = Globals.CreateInstance <IStartState>(); goto Cleanup; } if (!DobjArtifact.IsCarriedByCharacter()) { if (!GetCommandCalled) { RedirectToGetCommand <IReadyCommand>(DobjArtifact); } else if (DobjArtifact.DisguisedMonster == null) { NextState = Globals.CreateInstance <IStartState>(); } goto Cleanup; } // can't use two-handed weapon while wearing shield if (gGameState.Sh > 0 && DobjArtAc.Field5 > 1) { ShieldArtifact = gADB[gGameState.Sh]; Debug.Assert(ShieldArtifact != null); PrintCantReadyWeaponWithShield(DobjArtifact, ShieldArtifact); NextState = Globals.CreateInstance <IStartState>(); goto Cleanup; } 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)); gOut.Print("{0} readied.", DobjArtifact.GetNoneName(true, false)); ProcessEvents(EventType.AfterReadyArtifact); if (GotoCleanup) { goto Cleanup; } Cleanup: if (NextState == null) { NextState = Globals.CreateInstance <IMonsterStartState>(); } }
public override void Execute() { RetCode rc; Debug.Assert(DobjArtifact != null); DobjArtAc = DobjArtifact.LightSource; if (DobjArtAc == null) { if (ActorMonster.IsInRoomLit() || DobjArtifact.IsCarriedByCharacter()) { PrintCantVerbObj(DobjArtifact); } NextState = Globals.CreateInstance <IStartState>(); goto Cleanup; } if (!DobjArtifact.IsUnmovable()) { if (!DobjArtifact.IsCarriedByCharacter()) { if (!GetCommandCalled) { RedirectToGetCommand <ILightCommand>(DobjArtifact); } else if (DobjArtifact.DisguisedMonster == null) { NextState = Globals.CreateInstance <IStartState>(); } goto Cleanup; } } if (DobjArtAc.Field1 == 0) { PrintWontLight(DobjArtifact); NextState = Globals.CreateInstance <IMonsterStartState>(); goto Cleanup; } if (gGameState.Ls == DobjArtifact.Uid) { gOut.Write("{0}Extinguish {1} (Y/N): ", Environment.NewLine, DobjArtifact.GetTheName()); 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] == 'Y') { rc = DobjArtifact.RemoveStateDesc(DobjArtifact.GetProvidingLightDesc()); Debug.Assert(gEngine.IsSuccess(rc)); gGameState.Ls = 0; PrintLightExtinguished(DobjArtifact); } NextState = Globals.CreateInstance <IMonsterStartState>(); goto Cleanup; } if (gGameState.Ls > 0) { LsArtifact = gADB[gGameState.Ls]; Debug.Assert(LsArtifact != null && LsArtifact.LightSource != null); gEngine.LightOut(LsArtifact); } rc = DobjArtifact.AddStateDesc(DobjArtifact.GetProvidingLightDesc()); Debug.Assert(gEngine.IsSuccess(rc)); gGameState.Ls = DobjArtifact.Uid; PrintLightObj(DobjArtifact); Cleanup: if (NextState == null) { NextState = Globals.CreateInstance <IMonsterStartState>(); } }
public override void Execute() { RetCode rc; Debug.Assert(GoldAmount > 0 || DobjArtifact != null); Debug.Assert(IobjMonster != null); if (GoldAmount > 0) { gOut.Print("Give {0} gold piece{1} to {2}.", gEngine.GetStringFromNumber(GoldAmount, false, Globals.Buf), GoldAmount > 1 ? "s" : "", IobjMonster.GetTheName(buf: Globals.Buf01)); gOut.Write("{0}Are you sure (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; } if (gCharacter.HeldGold < GoldAmount) { PrintNotEnoughGold(); NextState = Globals.CreateInstance <IStartState>(); goto Cleanup; } ProcessEvents(EventType.BeforeTakePlayerGold); if (GotoCleanup) { goto Cleanup; } gOut.Print("{0} take{1} the money.", IobjMonster.GetTheName(true), IobjMonster.EvalPlural("s", "")); gCharacter.HeldGold -= GoldAmount; if (Globals.IsRulesetVersion(5, 25)) { IobjMonster.CalculateGiftFriendliness(GoldAmount, false); IobjMonster.ResolveReaction(gCharacter); } else { if (IobjMonster.Reaction == Friendliness.Neutral && GoldAmount > 4999) { IobjMonster.Friendliness = (Friendliness)200; IobjMonster.Reaction = Friendliness.Friend; gEngine.MonsterEmotes(IobjMonster); gOut.WriteLine(); } } goto Cleanup; } if (DobjArtifact.IsWornByCharacter()) { PrintWearingRemoveFirst(DobjArtifact); NextState = Globals.CreateInstance <IStartState>(); goto Cleanup; } if (!DobjArtifact.IsCarriedByCharacter()) { if (!GetCommandCalled) { RedirectToGetCommand <IGiveCommand>(DobjArtifact); } else if (DobjArtifact.DisguisedMonster == null) { NextState = Globals.CreateInstance <IStartState>(); } goto Cleanup; } if (IobjMonster.ShouldRefuseToAcceptGift(DobjArtifact)) { gEngine.MonsterEmotes(IobjMonster); gOut.WriteLine(); goto Cleanup; } 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)); } if (gEngine.EnforceMonsterWeightLimits) { IobjMonsterInventoryWeight = 0; rc = IobjMonster.GetFullInventoryWeight(ref _iobjMonsterInventoryWeight, recurse: true); Debug.Assert(gEngine.IsSuccess(rc)); if (DobjArtifactWeight > IobjMonster.GetWeightCarryableGronds() || DobjArtifactWeight + IobjMonsterInventoryWeight > IobjMonster.GetWeightCarryableGronds() * IobjMonster.CurrGroupCount) { PrintTooHeavy(DobjArtifact); goto Cleanup; } } ProcessEvents(EventType.AfterEnforceMonsterWeightLimitsCheck); if (GotoCleanup) { goto Cleanup; } if (DobjArtifact.DeadBody != null && IobjMonster.ShouldRefuseToAcceptDeadBody(DobjArtifact)) { PrintPolitelyRefuses(IobjMonster); goto Cleanup; } if (gGameState.Ls == DobjArtifact.Uid) { Debug.Assert(DobjArtifact.LightSource != null); gEngine.LightOut(DobjArtifact); } if (ActorMonster.Weapon == DobjArtifact.Uid) { Debug.Assert(DobjArtifact.GeneralWeapon != null); rc = DobjArtifact.RemoveStateDesc(DobjArtifact.GetReadyWeaponDesc()); Debug.Assert(gEngine.IsSuccess(rc)); ActorMonster.Weapon = -1; } ProcessEvents(EventType.AfterGiveReadiedWeaponCheck); if (GotoCleanup) { goto Cleanup; } PrintGiveObjToActor(DobjArtifact, IobjMonster); DobjArtAc = DobjArtifact.GetArtifactCategory(new ArtifactType[] { ArtifactType.Drinkable, ArtifactType.Edible }); if (Globals.IsRulesetVersion(5, 25) || DobjArtAc == null || DobjArtAc.Field2 <= 0) { DobjArtifact.SetCarriedByMonster(IobjMonster); if (Globals.IsRulesetVersion(5, 25)) { IobjMonster.CalculateGiftFriendliness(DobjArtifact.Value, true); IobjMonster.ResolveReaction(gCharacter); } else { if (IobjMonster.Reaction == Friendliness.Neutral) { IobjMonster.Friendliness = (Friendliness)200; IobjMonster.Reaction = Friendliness.Friend; gEngine.MonsterEmotes(IobjMonster); gOut.WriteLine(); } } goto Cleanup; } IobjMonsterName = IobjMonster.EvalPlural(IobjMonster.GetTheName(true), IobjMonster.GetArticleName(true, true, false, true, Globals.Buf01)); Globals.Buf01.Clear(); if (!DobjArtAc.IsOpen()) { Globals.Buf01.SetFormat(" opens {0}", DobjArtifact.GetTheName()); DobjArtAc.SetOpen(true); } if (DobjArtAc.Field2 != Constants.InfiniteDrinkableEdible) { DobjArtAc.Field2--; } if (DobjArtAc.Field2 > 0) { Globals.Buf.SetPrint("{0}{1}{2} takes a {3} and hands {4} back.", IobjMonsterName, Globals.Buf01, Globals.Buf01.Length > 0 ? "," : "", DobjArtAc.Type == ArtifactType.Edible ? "bite" : "drink", DobjArtifact.EvalPlural("it", "them")); } else { DobjArtifact.Value = 0; if (DobjArtAc.Type == ArtifactType.Edible) { DobjArtifact.SetInLimbo(); Globals.Buf.SetPrint("{0}{1}{2} eats {3} all.", IobjMonsterName, Globals.Buf01, Globals.Buf01.Length > 0 ? " and" : "", DobjArtifact.EvalPlural("it", "them")); } else { rc = DobjArtifact.AddStateDesc(DobjArtifact.GetEmptyDesc()); Debug.Assert(gEngine.IsSuccess(rc)); Globals.Buf.SetPrint("{0}{1}{2} drinks {3} all and hands {4} back.", IobjMonsterName, Globals.Buf01, Globals.Buf01.Length > 0 ? "," : "", DobjArtifact.EvalPlural("it", "them"), DobjArtifact.EvalPlural("it", "them")); } } gOut.Write("{0}", Globals.Buf); if (DobjArtAc.Field1 == 0) { goto Cleanup; } IobjMonster.DmgTaken -= DobjArtAc.Field1; if (IobjMonster.DmgTaken < 0) { IobjMonster.DmgTaken = 0; } Globals.Buf.SetFormat("{0}{1} is ", Environment.NewLine, IobjMonster.GetTheName(true, true, false, true, Globals.Buf01)); IobjMonster.AddHealthStatus(Globals.Buf); gOut.Write("{0}", Globals.Buf); if (IobjMonster.IsDead()) { gEngine.MonsterDies(ActorMonster, IobjMonster); } Cleanup: if (NextState == null) { NextState = Globals.CreateInstance <IMonsterStartState>(); } }
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>(); } }
public override void Execute() { RetCode rc; Debug.Assert(DobjArtifact != null || DobjMonster != null); if (!BlastSpell && ActorMonster.Weapon <= 0) { PrintMustFirstReadyWeapon(); NextState = Globals.CreateInstance <IStartState>(); goto Cleanup; } if (DobjMonster != null) { ProcessEvents(EventType.BeforeAttackMonster); if (GotoCleanup) { goto Cleanup; } if (!DobjMonster.IsAttackable(ActorMonster)) { PrintWhyAttack(DobjMonster); NextState = Globals.CreateInstance <IStartState>(); goto Cleanup; } if (!CheckAttack && DobjMonster.Reaction != 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(DobjMonster); } CombatSystem = Globals.CreateInstance <ICombatSystem>(x => { x.SetNextStateFunc = s => NextState = s; x.OfMonster = ActorMonster; x.DfMonster = DobjMonster; x.MemberNumber = MemberNumber; x.AttackNumber = AttackNumber; x.BlastSpell = BlastSpell; x.OmitSkillGains = !BlastSpell && !ShouldAllowSkillGains(); }); CombatSystem.ExecuteAttack(); goto Cleanup; } ProcessEvents(EventType.BeforeAttackArtifact); if (GotoCleanup) { goto Cleanup; } DobjArtAc = null; if (!DobjArtifact.IsAttackable01(ref _dobjArtAc)) { PrintWhyAttack(DobjArtifact); NextState = Globals.CreateInstance <IStartState>(); goto Cleanup; } Debug.Assert(DobjArtAc != null); if (DobjArtAc.Type == ArtifactType.DeadBody) { if (BlastSpell) { gOut.Print("{0}", gEngine.GetBlastDesc()); } DobjArtifact.SetInLimbo(); PrintHackToBits(); goto Cleanup; } if (DobjArtAc.Type == ArtifactType.DisguisedMonster) { gEngine.RevealDisguisedMonster(ActorRoom, DobjArtifact); DisguisedMonster = gMDB[DobjArtAc.Field1]; Debug.Assert(DisguisedMonster != null); RedirectCommand = null; if (BlastSpell) { RedirectCommand = Globals.CreateInstance <IBlastCommand>(x => { x.CastSpell = false; }); } else { RedirectCommand = Globals.CreateInstance <IAttackCommand>(); } CopyCommandData(RedirectCommand); RedirectCommand.Dobj = DisguisedMonster; NextState = RedirectCommand; goto Cleanup; } /* * Damage it... */ KeyArtifactUid = DobjArtAc.GetKeyUid(); if (KeyArtifactUid == -2) { PrintAlreadyBrokeIt(DobjArtifact); goto Cleanup; } BreakageStrength = DobjArtAc.GetBreakageStrength(); if (BreakageStrength < 1000) { gOut.Print("Nothing happens."); goto Cleanup; } BreakageDice = 0; BreakageSides = 0; if (BlastSpell) { if (Globals.IsRulesetVersion(5, 15, 25)) { BreakageDice = 1; BreakageSides = 6; } else { BreakageDice = 2; BreakageSides = 5; } Globals.Buf.SetPrint("{0}", gEngine.GetBlastDesc()); } else { ActorWeapon = gADB[ActorMonster.Weapon]; Debug.Assert(ActorWeapon != null); ActorWeaponAc = ActorWeapon.GeneralWeapon; Debug.Assert(ActorWeaponAc != null); BreakageDice = ActorWeaponAc.Field3; BreakageSides = ActorWeaponAc.Field4; BuildWhamHitObj(); } gOut.Write("{0}", Globals.Buf); BreakageDamage = gEngine.RollDice(BreakageDice, BreakageSides, 0); BreakageStrength -= BreakageDamage; if (BreakageStrength > 1000) { DobjArtAc.SetBreakageStrength(BreakageStrength); goto Cleanup; } /* * Broken! */ DobjArtAc.SetOpen(true); DobjArtAc.SetKeyUid(-2); DobjArtAc.Field4 = 0; DobjArtifact.Value = 0; rc = DobjArtifact.AddStateDesc(DobjArtifact.GetBrokenDesc()); Debug.Assert(gEngine.IsSuccess(rc)); BuildSmashesToPieces(); if (DobjArtAc.Type == ArtifactType.InContainer) { SpilledArtifactList = DobjArtifact.GetContainedList(containerType: ContainerType.In); if (DobjArtifact.OnContainer != null && DobjArtifact.IsInContainerOpenedFromTop()) { SpilledArtifactList.AddRange(DobjArtifact.GetContainedList(containerType: ContainerType.On)); } foreach (var artifact in SpilledArtifactList) { artifact.SetInRoom(ActorRoom); } if (SpilledArtifactList.Count > 0) { BuildContentsSpillToFloor(); } DobjArtAc.Field3 = 0; } Globals.Buf.AppendFormat("!{0}", Environment.NewLine); gOut.Write("{0}", Globals.Buf); Cleanup: if (NextState == null) { NextState = Globals.CreateInstance <IMonsterStartState>(); } }