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