public void CheckIf_NoArgs() { var actor = new CharacterInstance(1, "TestNpc") { PermanentStrength = 25 }; Assert.That(CheckFunctions.CheckIf(actor, () => 5 * 10 == 50, string.Empty), Is.True); }
public static void do_atobj(CharacterInstance ch, string argument) { ch.SetColor(ATTypes.AT_IMMORT); var firstArg = argument.FirstWord(); if (CheckFunctions.CheckIfEmptyString(ch, firstArg, "At where what?")) { return; } ObjectInstance obj = RepositoryManager.Instance.GetEntity <ObjectInstance>(argument); if (CheckFunctions.CheckIf(ch, () => obj?.InRoom == null, "No such object in existence.")) { return; } RoomTemplate location = obj.InRoom; if (location.IsPrivate()) { if (CheckFunctions.CheckIf(ch, () => ch.Trust < LevelConstants.GetLevel(ImmortalTypes.Greater), "That room is private right now.")) { return; } ch.SendTo("Overriding private flag!"); } CharacterInstance victim = location.IsDoNotDisturb(ch); if (victim != null) { ch.PagerPrintf("That room is \"do not disturb\" right now."); victim.PagerPrintf("Your do-not-disturb flag just foiled %s's atobj command.", ch.Name); return; } ch.SetColor(ATTypes.AT_PLAIN); RoomTemplate original = ch.CurrentRoom; ch.CurrentRoom.RemoveFrom(ch); location.AddTo(ch); interp.interpret(ch, argument); if (ch.CharDied()) { return; } ch.CurrentRoom.RemoveFrom(ch); original.AddTo(ch); }
public void CheckIf_WithArgs() { var actor = new CharacterInstance(1, "TestNpc") { PermanentStrength = 25 }; Assert.That( CheckFunctions.CheckIf(actor, args => ((CharacterInstance)args[0]).PermanentStrength == 25, string.Empty, new List <object> { actor }), Is.True); }
public static void do_say(CharacterInstance ch, string argument) { #if !SCRAMBLE var speaking = -1; /*foreach (int key in GameConstants.LanguageTable.Keys * .Where(key => (key & ch.Speaking) > 0)) * { * speaking = key; * break; * }*/ #endif if (CheckFunctions.CheckIfEmptyString(ch, argument, "Say what?")) { return; } if (CheckFunctions.CheckIf(ch, args => ((CharacterInstance)args[0]).CurrentRoom.Flags.IsSet((int)RoomFlags.Silence), "You can't do that here.", new List <object> { ch })) { return; } var actflags = ch.Act; if (ch.IsNpc()) { ch.Act.RemoveBit((int)ActFlags.Secretive); } foreach (var vch in ch.CurrentRoom.Persons.Where(vch => vch != ch)) { var sbuf = argument; if (vch.IsIgnoring(ch)) { if (!ch.IsImmortal() || vch.Trust > ch.Trust) { continue; } vch.SetColor(ATTypes.AT_IGNORE); vch.Printf("You attempt to ignore %s, but are unable to do so.\r\n", ch.Name); } #if !SCRAMBLE /*if (speaking != -1 && (!ch.IsNpc() || ch.Speaking != 0)) * { * int speakswell = vch.KnowsLanguage(ch.Speaking, ch).GetLowestOfTwoNumbers(ch.KnowsLanguage(ch.Speaking, vch)); * if (speakswell < 75) * sbuf = act_comm.TranslateLanguage(speakswell, argument, GameConstants.LanguageTable[speaking]); * }*/ #else if (KnowsLanguage(vch, ch.Speaking, ch) == 0 && (!ch.IsNpc() || ch.Speaking != 0)) { sbuf = ScrambleText(argument, ch.Speaking); } #endif sbuf = sbuf.Drunkify(ch); // TODO Toggle global mobtrigger flag comm.act(ATTypes.AT_SAY, "$n says '$t'", ch, sbuf, vch, ToTypes.Victim); } ch.Act = actflags; // TODO Toggle global mobtrigger flag comm.act(ATTypes.AT_SAY, "You say '%T'", ch, null, argument.Drunkify(ch), ToTypes.Character); if (ch.CurrentRoom.Flags.IsSet((int)RoomFlags.LogSpeech)) { db.append_to_file(SystemConstants.GetSystemFile(SystemFileTypes.Log), $"{(ch.IsNpc() ? ch.ShortDescription : ch.Name)}: {argument}"); } MudProgHandler.ExecuteMobileProg(MudProgTypes.Speech, argument, ch); if (ch.CharDied()) { return; } MudProgHandler.ExecuteObjectProg(MudProgTypes.Speech, argument, ch); if (ch.CharDied()) { return; } MudProgHandler.ExecuteRoomProg(MudProgTypes.Speech, argument, ch); }
public static void do_at(CharacterInstance ch, string argument) { ch.SetColor(ATTypes.AT_IMMORT); var firstArg = argument.FirstWord(); if (CheckFunctions.CheckIfEmptyString(ch, firstArg, "At where what?")) { return; } RoomTemplate location = null; CharacterInstance worldCharacter = null; if (argument.IsNumber()) { location = RepositoryManager.Instance.GetEntity <RoomTemplate>(argument); } else if (argument.EqualsIgnoreCase("pk")) { // todo get last pkroom } else { worldCharacter = RepositoryManager.Instance.GetEntity <CharacterInstance>(argument); if (CheckFunctions.CheckIf(ch, () => worldCharacter?.CurrentRoom == null, "No such mobile or player in the world.")) { return; } } if (location == null && worldCharacter != null) { location = worldCharacter.CurrentRoom; } if (CheckFunctions.CheckIfNullObject(ch, location, "No such location exists.")) { return; } if (worldCharacter != null && !worldCharacter.IsNpc()) { if (((PlayerInstance)worldCharacter).PlayerData.Flags.IsSet(PCFlags.DoNotDisturb)) { ch.PagerPrintf("Sorry. %s does not wish to be disturbed.", worldCharacter.Name); worldCharacter.PagerPrintf("Your Do-Not-Disturb flag just foiled %s's AT command.", ch.Name); return; } } if (location.IsPrivate()) { if (CheckFunctions.CheckIf(ch, () => ch.Trust < LevelConstants.GetLevel(ImmortalTypes.Greater), "That room is private right now.")) { return; } ch.SendTo("Overriding private flag!"); } CharacterInstance victim = location.IsDoNotDisturb(ch); if (victim != null) { ch.PagerPrintf("That room is \"do not disturb\" right now."); victim.PagerPrintf("Your do-not-disturb flag just foiled %s's atmob command.", ch.Name); return; } ch.SetColor(ATTypes.AT_PLAIN); RoomTemplate original = ch.CurrentRoom; ch.CurrentRoom.RemoveFrom(ch); location.AddTo(ch); interp.interpret(ch, argument); if (!ch.CharDied()) { ch.CurrentRoom.RemoveFrom(ch); original.AddTo(ch); } }
public static bool CheckAbility(CharacterInstance ch, string command, string argument, IRepositoryManager databaseManager = null) { var sn = ch.GetIDOfSkillCharacterKnows(command); if (sn == -1) { return(false); } var skill = (databaseManager ?? RepositoryManager.Instance).GetEntity <SkillData>(sn); if (skill.SkillFunction == null || skill.SpellFunction == null || ch.CanUseSkill(0, sn)) { return(false); } if (!interp.check_pos(ch, skill.MinimumPosition)) { return(true); } if (CheckFunctions.CheckIf(ch, HelperFunctions.IsCharmedOrPossessed, "For some reason, you seem unable to perform that...", new List <object> { ch })) { comm.act(ATTypes.AT_GREY, "$n wanders around aimlessly.", ch, null, null, ToTypes.Room); return(true); } //// Check if mana is required int mana = 0, blood = 0; if (skill.MinimumMana > 0) { mana = ch.IsNpc() ? 0 : skill.MinimumMana .GetHighestOfTwoNumbers(100 / (2 + ch.Level - skill.RaceLevel.ToList()[(int)ch.CurrentRace])); if (CheckFunctions.CheckIf(ch, HelperFunctions.HasSufficientBloodPower, "You don't have enough blood power.", new List <object> { ch, blood })) { return(true); } if (CheckFunctions.CheckIf(ch, HelperFunctions.HasSufficientMana, "You don't have enough mana.", new List <object> { ch, mana })) { return(true); } } DateTime start, end; //// Is this a real d-fun or just a spell? if (skill.SkillFunction == null) { CharacterInstance victim = null; ObjectInstance obj = null; var targetName = string.Empty; object vo; switch (skill.Target) { default: LogManager.Instance.Bug("Bad target to Skill {0}", sn); ch.SendTo("Something went wrong..."); return(true); case TargetTypes.Ignore: vo = null; victim = ch.GetMyTarget(); targetName = argument.IsNullOrEmpty() && victim != null ? victim.Name : argument; break; case TargetTypes.OffensiveCharacter: victim = ch.GetMyTarget(); if (argument.IsNullOrEmpty() && victim == null) { ch.Printf("Confusion overcomes you as your '%s' has no target.\r\n", skill.Name); return(true); } victim = ch.GetCharacterInRoom(argument); if (CheckFunctions.CheckIfTrue(ch, !argument.IsNullOrEmpty() && victim == null, "They aren't here.")) { return(true); } if (fight.is_safe(ch, victim, true)) { return(true); } if (CheckFunctions.CheckIfTrue(ch, ch == victim && skill.Flags.IsSet(SkillFlags.NoSelf), "You can't target yourself!")) { return(true); } if (!ch.IsNpc()) { if (!victim.IsNpc()) { if (CheckFunctions.CheckIfNotNullObject(ch, ch.GetTimer(TimerTypes.PKilled), "You have been killed in the last five minutes.")) { return(true); } if (CheckFunctions.CheckIfNotNullObject(ch, victim.GetTimer(TimerTypes.PKilled), "This player has been killed in the last five minutes.")) { return(true); } if (CheckFunctions.CheckIfEquivalent(ch, ch, victim, "You really shouldn't do this to another player...")) { return(true); } } if (CheckFunctions.CheckIfTrue(ch, ch.IsAffected(AffectedByTypes.Charm) && ch.Master == victim, "You can't do that on your own follower.")) { return(true); } } if (CheckFunctions.CheckIfTrue(ch, fight.check_illegal_pk(ch, victim), "You can't do that to another player!")) { return(true); } vo = victim; break; case TargetTypes.DefensiveCharacter: victim = ch.GetCharacterInRoom(argument); if (CheckFunctions.CheckIfTrue(ch, !argument.IsNullOrEmpty() && victim == null, "They aren't here.")) { return(true); } if (CheckFunctions.CheckIfTrue(ch, ch == victim && skill.Flags.IsSet(SkillFlags.NoSelf), "You can't target yourself!")) { return(true); } vo = victim; break; case TargetTypes.Self: victim = ch; vo = ch; break; case TargetTypes.InventoryObject: obj = ch.GetCarriedObject(argument); if (CheckFunctions.CheckIfNullObject(ch, obj, "You can't find that.")) { return(true); } vo = obj; break; } Macros.WAIT_STATE(ch, skill.Rounds); //// Check for failure if (SmaugRandom.D100() + skill.difficulty * 5 > (ch.IsNpc() ? 75 : Macros.LEARNED(ch, (int)skill.ID))) { ch.FailedCast(skill, victim, obj); skill.LearnFromFailure((PlayerInstance)ch); if (mana > 0) { if (ch.IsVampire()) { ((PlayerInstance)ch).GainCondition(ConditionTypes.Bloodthirsty, -blood / 2); } else { ch.CurrentMana -= mana / 2; } } return(true); } if (mana > 0) { if (ch.IsVampire()) { ((PlayerInstance)ch).GainCondition(ConditionTypes.Bloodthirsty, -blood); } else { ch.CurrentMana -= mana; } } start = DateTime.Now; var retcode = skill.SpellFunction.Value.Invoke((int)skill.ID, ch.Level, ch, vo); end = DateTime.Now; skill.UseHistory.Use(ch, end.Subtract(start)); if (retcode == ReturnTypes.CharacterDied || retcode == ReturnTypes.Error || ch.CharDied()) { return(true); } if (retcode == ReturnTypes.SpellFailed) { skill.LearnFromFailure((PlayerInstance)ch); retcode = ReturnTypes.None; } else { skill.AbilityLearnFromSuccess((PlayerInstance)ch); } if (skill.Target == TargetTypes.OffensiveCharacter && victim != ch && !victim.CharDied()) { if (ch.CurrentRoom.Persons.Any(vch => victim == vch && victim.CurrentFighting == null && victim.Master != ch)) { retcode = fight.multi_hit(victim, ch, Program.TYPE_UNDEFINED); } } return(true); } if (mana > 0) { if (ch.IsVampire()) { ((PlayerInstance)ch).GainCondition(ConditionTypes.Bloodthirsty, -blood); } else { ch.CurrentMana -= mana; } } ch.LastCommand = skill.SkillFunction; start = DateTime.Now; skill.SkillFunction.Value.Invoke(ch, argument); end = DateTime.Now; skill.UseHistory.Use(ch, end.Subtract(start)); // TODO: Tail chain? return(true); }
public static void do_advance(CharacterInstance ch, string argument) { ch.SetColor(ATTypes.AT_IMMORT); string firstArg = argument.FirstWord(); string secondArg = argument.SecondWord(); if (CheckFunctions.CheckIf(ch, () => string.IsNullOrEmpty(firstArg) || string.IsNullOrEmpty(secondArg) || !secondArg.IsNumeric(), "Syntax: advance <character> <Level>")) { return; } var victim = ch.GetCharacterInRoom(firstArg); if (CheckFunctions.CheckIfNullObject(ch, victim, "That character is not in the room.")) { return; } if (CheckFunctions.CheckIfNpc(ch, victim, "You cannot advance a non-player-character.")) { return; } if (CheckFunctions.CheckIf(ch, () => ch.Trust <= victim.Trust || ch == victim, "You can't do that.")) { return; } var level = Convert.ToInt32(secondArg); if (CheckFunctions.CheckIf(ch, () => level < 1 || level > GameConstants.GetConstant <int>("MaximumLevel"), $"Level range is 1 to {GameConstants.GetConstant<int>("MaximumLevel")}.")) { return; } if (CheckFunctions.CheckIf(ch, () => level > ch.Trust, "Level limited to your trust level.")) { return; } if (level <= victim.Level) { LowerVictimLevel(ch, victim, level); } else { RaiseVictimLevel(ch, victim, level); } for (int i = victim.Level; i < level; i++) { if (level < LevelConstants.ImmortalLevel) { victim.SendTo("You raise a level!"); } victim.Level += 1; if (victim is PlayerInstance) { ((PlayerInstance)victim).AdvanceLevel(); } } victim.Experience = victim.GetExperienceLevel(victim.Level); victim.Trust = 0; }
public static void do_quit(CharacterInstance ch, string argument) { if (CheckFunctions.CheckIfNpc(ch, ch)) { return; } if (CheckFunctions.CheckIf(ch, HelperFunctions.IsInFightingPosition, "No way! You are fighting.", new List <object> { ch }, ATTypes.AT_RED)) { return; } if (CheckFunctions.CheckIf(ch, args => ((CharacterInstance)args[0]).CurrentPosition == PositionTypes.Stunned, "You're not DEAD yet.", new List <object> { ch }, ATTypes.AT_BLOOD)) { return; } var timer = ch.Timers.FirstOrDefault(x => x.Type == TimerTypes.RecentFight); if (timer != null && !ch.IsImmortal()) { ch.SetColor(ATTypes.AT_RED); ch.SendTo("Your adrenaline is pumping too hard to quit now!"); return; } // TODO: auction if (CheckFunctions.CheckIf(ch, args => { var actor = (CharacterInstance)args[0]; return(actor.IsPKill() && actor.wimpy > actor.MaximumHealth / 2.25f); }, "Your wimpy has been adjusted to the maximum level for deadlies.", new List <object> { ch })) { Wimpy.do_wimpy(ch, "max"); } if (ch.CurrentPosition == PositionTypes.Mounted) { Dismount.do_dismount(ch, string.Empty); } ch.SetColor(ATTypes.AT_WHITE); ch.SendTo("Your surroundings begin to fade as a mystical swirling vortex of colors\r\nenvelops your body... When you come to, things are not as they were.\r\n\r\n"); comm.act(ATTypes.AT_SAY, "A strange voice says, 'We await your return, $n...'", ch, null, null, ToTypes.Character); comm.act(ATTypes.AT_BYE, "$n has left the game.", ch, null, null, ToTypes.CanSee); ch.SetColor(ATTypes.AT_GREY); // TODO quitting_char = ch; save.save_char_obj(ch); if (GameManager.Instance.SystemData.SavePets && ((PlayerInstance)ch).PlayerData.Pet != null) { comm.act(ATTypes.AT_BYE, "$N follows $S master into the Void.", ch, null, ((PlayerInstance)ch).PlayerData.Pet, ToTypes.Room); ((PlayerInstance)ch).PlayerData.Pet.Extract(true); } //if (ch.PlayerData.Clan != null) // ch.PlayerData.Clan.Save(); // TODO saving_char = null; for (var x = 0; x < GameConstants.MaximumWearLocations; x++) { for (var y = 0; y < GameConstants.MaximumWearLayers; y++) { // TODO Save equipment } } LogManager.Instance.Info( $"{ch.Name} has quit (Room {ch.CurrentRoom?.ID ?? -1}).", LogTypes.Info, ch.Trust); ch.Extract(true); }
public static void do_drag(CharacterInstance ch, string argument) { if (CheckFunctions.CheckIfNpc(ch, ch, "Only characters can drag.")) { return; } if (CheckFunctions.CheckIfTrue(ch, ch.HasTimer(TimerTypes.PKilled), "You can't drag a player right now.")) { return; } var pch = (PlayerInstance)ch; var firstArg = argument.FirstWord(); if (CheckFunctions.CheckIfEmptyString(pch, firstArg, "Drag whom?")) { return; } var victim = pch.GetCharacterInRoom(firstArg); if (CheckFunctions.CheckIfNullObject(pch, victim, "They aren't here.")) { return; } if (CheckFunctions.CheckIfEquivalent(pch, pch, victim, "You take yourself by the scruff of your neck, but go nowhere.")) { return; } if (CheckFunctions.CheckIfNpc(ch, victim, "You can only drag characters.")) { return; } if (CheckFunctions.CheckIfTrue(ch, !victim.Act.IsSet((int)PlayerFlags.ShoveDrag) || (!victim.IsNpc() && !victim.IsDeadly()), "That character doesn't seem to appreciate your attentions.")) { return; } if (CheckFunctions.CheckIfTrue(ch, victim.HasTimer(TimerTypes.PKilled), "You can't drag that player right now.")) { return; } if (CheckFunctions.CheckIf(ch, HelperFunctions.IsFighting, "You try, but can't get close enough.", new List <object> { ch })) { return; } if (CheckFunctions.CheckIfTrue(ch, !ch.IsNpc() && !victim.IsDeadly() && ch.IsDeadly(), "You can't drag a deadly character.")) { return; } if (CheckFunctions.CheckIfTrue(ch, !ch.IsNpc() && !ch.IsDeadly() && (int)ch.CurrentPosition > 3, "They don't seem to need your assistance.")) { return; } var secondArg = argument.SecondWord(); if (CheckFunctions.CheckIfEmptyString(ch, secondArg, "Drag them in which direction?")) { return; } if (CheckFunctions.CheckIfTrue(ch, Math.Abs(ch.Level - victim.Level) > 5, "There is too great an experience difference for you to even bother.")) { return; } if (CheckFunctions.CheckIfTrue(ch, victim.CurrentRoom.Flags.IsSet(RoomFlags.Safe) && victim.GetTimer(TimerTypes.ShoveDrag) == null, "That character cannot be dragged right now.")) { return; } var exitDir = EnumerationExtensions.GetEnumByName <DirectionTypes>(secondArg); var exit = ch.CurrentRoom.GetExit(exitDir); if (CheckFunctions.CheckIfNullObject(ch, exit, "There's no exit in that direction.")) { return; } if (CheckFunctions.CheckIfTrue(ch, !IsPassable(exit, victim), "There's no exit in that direction.")) { return; } var toRoom = exit.GetDestination(); if (CheckFunctions.CheckIfSet(ch, toRoom.Flags, RoomFlags.Death, "You cannot drag someone into a death trap.")) { return; } if (CheckFunctions.CheckIfTrue(ch, ch.CurrentRoom.Area != toRoom.Area && !toRoom.Area.IsInHardRange(victim), "That character cannot enter that area.")) { victim.CurrentPosition = PositionTypes.Standing; return; } var chance = CalculateChanceToDrag(ch, victim); if (CheckFunctions.CheckIfTrue(ch, chance < SmaugRandom.D100(), "You failed.")) { victim.CurrentPosition = PositionTypes.Standing; return; } if ((int)victim.CurrentPosition < (int)PositionTypes.Standing) { DragIntoNextRoom(ch, victim, exit); return; } ch.SendTo("You cannot do that to someone who is standing."); }
public static void do_balzhur(CharacterInstance ch, string argument) { ch.SetColor(ATTypes.AT_BLOOD); var firstArg = argument.FirstWord(); if (CheckFunctions.CheckIfEmptyString(ch, firstArg, "Who is deserving of such a fate?")) { return; } var victim = ch.GetCharacterInWorld(firstArg); if (CheckFunctions.CheckIfNullObject(ch, victim, "They aren't currently playing.")) { return; } if (CheckFunctions.CheckIfNpc(ch, victim, "This will do little good on mobiles.")) { return; } if (CheckFunctions.CheckIf(ch, () => ch.Trust <= victim.Level || ch == victim, "I wouldn't even think of that if I were you...")) { return; } victim.Level = 2; victim.Trust = 0; // TODO check_switch(victim, true) ch.SetColor(ATTypes.AT_WHITE); ch.SendTo("You summon the demon Balzhur to wreak your wrath!"); ch.SendTo("Balzhur sneers at you evilly, then vanishes in a puff of smoke"); victim.SetColor(ATTypes.AT_IMMORT); victim.SendTo("You hear an ungodly sound in the distance that makes your blood run cold!"); victim.SendTo($"Balzhur screams, 'You are MINE {victim.Name}!!!"); // echo_to_all(AT_IMMORT, ECHOTAR_ALL) victim.Experience = 2000; victim.MaximumHealth = 10; victim.MaximumMana = 100; victim.MaximumMovement = 100; ((PlayerInstance)victim).PlayerData.ClearLearnedSkills(); victim.Practice = 0; victim.CurrentHealth = victim.MaximumHealth; victim.CurrentMana = victim.MaximumMana; victim.CurrentMovement = victim.MaximumMovement; //snprintf(buf, MAX_STRING_LENGTH, "%s%s", GOD_DIR, capitalize(victim->name)); ch.SetColor(ATTypes.AT_RED); // TODO act_wiz.c lines 3527 to 3556 (writing it out to data file) ((PlayerInstance)victim).AdvanceLevel(); Help.do_help(victim, "M_BALZHUR_"); victim.SetColor(ATTypes.AT_WHITE); victim.SendTo("You awake after a long period of time..."); if (victim.Carrying.Any()) { //extract_obj(victim.Carrying.First()); } }