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>(); } }
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>(); } }