private static int CalculateChanceToDrag(CharacterInstance ch, CharacterInstance victim) { var chance = GetChanceByCharacterClass(ch); chance += (ch.GetCurrentStrength() - 15) * 3; chance += ch.Level - victim.Level; chance += GetBonusByCharacterRace(ch); return(chance); }
public static int CanCarryMaxWeight(this CharacterInstance ch) { if (!ch.IsNpc() && ch.Level >= LevelConstants.ImmortalLevel) { return(1000000); } if (ch.IsNpc() && ch.Act.IsSet((int)ActFlags.Immortal)) { return(1000000); } return((int)LookupManager.Instance.GetStatMod("Strength", ch.GetCurrentStrength(), StrengthModTypes.Carry)); }
private static void BashSomething(CharacterInstance actor, ExitData exit, SkillData skill, string arg) { if (CheckFunctions.CheckIfSet(actor, exit.Flags, ExitFlags.Closed, "Calm down. It is already open.")) { return; } Macros.WAIT_STATE(actor, skill.Rounds); var keyword = exit.Flags.IsSet(ExitFlags.Secret) ? "wall" : exit.Keywords; var chance = !actor.IsNpc() ? Macros.LEARNED(actor, (int)skill.ID) / 2 : 90; if (exit.Flags.IsSet(ExitFlags.Locked)) { chance /= 3; } if (exit.Flags.IsSet(ExitFlags.BashProof) || actor.CurrentMovement < 15 || SmaugRandom.D100() >= chance + 4 * (actor.GetCurrentStrength() - 19)) { Bash(actor, skill, arg); return; } BashExit(exit); comm.act(ATTypes.AT_SKILL, "Crash! You bashed open the $d!", actor, null, keyword, ToTypes.Character); comm.act(ATTypes.AT_SKILL, "$n bashes open the $d!", actor, null, keyword, ToTypes.Room); skill.LearnFromSuccess(actor); var reverseExit = exit.GetReverse(); BashExit(reverseExit); var destination = exit.GetDestination(RepositoryManager.Instance); foreach (var ch in destination.Persons) { comm.act(ATTypes.AT_SKILL, "The $d crashes open!", ch, null, reverseExit.Keywords, ToTypes.Character); } actor.CauseDamageTo(actor, actor.CurrentHealth / 20, (int)skill.ID); }
private static void ItemEquipMissileWeapon(ObjectInstance obj, CharacterInstance ch, ObjectInstance mw, ObjectInstance dw, ObjectInstance hd, ObjectInstance sd) { if (!ch.CanDualWield()) { return; } if (CheckFunctions.CheckIfTrue(ch, obj.ItemType == ItemTypes.MissileWeapon, "You're already wielding a missile weapon.")) { return; } var strWieldMod = (int)LookupManager.Instance.GetStatMod("Strength", ch.GetCurrentStrength(), StrengthModTypes.Wield); if (CheckFunctions.CheckIfTrue(ch, obj.GetWeight() + mw.GetWeight() > strWieldMod, "It is too heavy for you to wield.")) { return; } if (CheckFunctions.CheckIfNotNullObject(ch, dw, "You're already wielding two weapons.")) { return; } if (CheckFunctions.CheckIfTrue(ch, hd != null || sd != null, "You're already wielding a weapon AND holding something.")) { return; } if (!MudProgHandler.ExecuteObjectProg(MudProgTypes.Use, ch, obj, null, null)) { comm.act(ATTypes.AT_ACTION, "$n wields $p.", ch, obj, null, ToTypes.Room); comm.act(ATTypes.AT_ACTION, "You wield $p.", ch, obj, null, ToTypes.Character); } ch.Equip(obj, WearLocations.Wield); MudProgHandler.ExecuteObjectProg(MudProgTypes.Wear, ch, obj); }
public static void do_shove(CharacterInstance ch, string argument) { if (CheckFunctions.CheckIfTrue(ch, ch.IsNpc() || !((PlayerInstance)ch).PlayerData.Flags.IsSet(PCFlags.Deadly), "Only deadly characters can shove.")) { return; } if (CheckFunctions.CheckIfTrue(ch, ch.HasTimer(TimerTypes.PKilled), "You can't shove a player right now.")) { return; } var firstArg = argument.FirstWord(); if (CheckFunctions.CheckIfEmptyString(ch, firstArg, "Shove whom?")) { return; } var victim = ch.GetCharacterInRoom(firstArg); if (CheckFunctions.CheckIfNullObject(ch, victim, "They aren't here.")) { return; } if (CheckFunctions.CheckIfEquivalent(ch, ch, victim, "You shove yourself around, to no avail.")) { return; } if (CheckFunctions.CheckIfTrue(ch, victim.IsNpc() || !((PlayerInstance)victim).PlayerData.Flags.IsSet(PCFlags.Deadly), "You can only shove deadly characters.")) { return; } if (CheckFunctions.CheckIfTrue(ch, ch.Level.GetAbsoluteDifference(victim.Level) > 5, "There is too great an experience difference for you to even bother.")) { return; } if (CheckFunctions.CheckIfNullObject(ch, victim.HasTimer(TimerTypes.PKilled), "You can't shove that player right now.")) { return; } if (victim.CurrentPosition != PositionTypes.Standing) { comm.act(ATTypes.AT_PLAIN, "$N isn't standing up.", ch, null, victim, ToTypes.Character); return; } var secondArg = argument.SecondWord(); if (CheckFunctions.CheckIfEmptyString(ch, secondArg, "Shove them in which direction?")) { return; } if (CheckFunctions.CheckIfTrue(ch, victim.CurrentRoom.Flags.IsSet(RoomFlags.Safe) && !ch.HasTimer(TimerTypes.ShoveDrag), "That character cannot be shoved right now.")) { return; } victim.CurrentPosition = PositionTypes.Shove; var exitDir = EnumerationExtensions.GetEnumByName <DirectionTypes>(secondArg); var exit = ch.CurrentRoom.GetExit(exitDir); if (CheckFunctions.CheckIfNullObject(ch, exit, "There's no exit in that direction.")) { victim.CurrentPosition = PositionTypes.Standing; return; } if (CheckFunctions.CheckIfTrue(ch, exit.Flags.IsSet(ExitFlags.Closed) && (!victim.IsAffected(AffectedByTypes.PassDoor) || exit.Flags.IsSet(ExitFlags.NoPassDoor)), "There's no exit in that direction.")) { victim.CurrentPosition = PositionTypes.Standing; return; } var toRoom = exit.GetDestination(); if (CheckFunctions.CheckIfSet(ch, toRoom.Flags, RoomFlags.Death, "You cannot shove someone into a death trap.")) { victim.CurrentPosition = PositionTypes.Standing; 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 = GetChanceByCharacterClass(ch); chance += (ch.GetCurrentStrength() - 15) * 3; chance += ch.Level - victim.Level; chance += GetBonusByCharacterRace(ch); if (CheckFunctions.CheckIfTrue(ch, chance < SmaugRandom.D100(), "You failed.")) { victim.CurrentPosition = PositionTypes.Standing; return; } comm.act(ATTypes.AT_ACTION, "You shove $M.", ch, null, victim, ToTypes.Character); comm.act(ATTypes.AT_ACTION, "$n shoves you.", ch, null, victim, ToTypes.Victim); Move.move_char(victim, exit, 0); if (!victim.CharDied()) { victim.CurrentPosition = PositionTypes.Standing; } Macros.WAIT_STATE(ch, 12); if (ch.CurrentRoom.Flags.IsSet(RoomFlags.Safe) && !ch.HasTimer(TimerTypes.ShoveDrag)) { ch.AddTimer(TimerTypes.ShoveDrag, 10); } }
public static void ModifyAffect(this CharacterInstance ch, AffectData affect, bool add) { var mod = affect.Modifier; if (add) { mod = ModifyAndAddAffect(ch, affect, mod); } else { ch.AffectedBy.RemoveBit((int)affect.Type); if ((int)affect.Location % Program.REVERSE_APPLY == (int)ApplyTypes.RecurringSpell) { mod = Math.Abs(mod); var skill = RepositoryManager.Instance.SKILLS.Values.ToList()[mod]; if (!Macros.IS_VALID_SN(mod) || skill == null || skill.Type != SkillTypes.Spell) { throw new InvalidDataException($"RecurringSpell with bad SN {mod}"); } ch.AffectedBy.RemoveBit((int)AffectedByTypes.RecurringSpell); return; } switch ((int)affect.Location % Program.REVERSE_APPLY) { case (int)ApplyTypes.Affect: return; case (int)ApplyTypes.ExtendedAffect: ch.AffectedBy.RemoveBit(mod); return; case (int)ApplyTypes.Resistance: ch.Resistance.RemoveBit(mod); return; case (int)ApplyTypes.Immunity: ch.Immunity.RemoveBit(mod); return; case (int)ApplyTypes.Susceptibility: ch.Susceptibility.RemoveBit(mod); return; case (int)ApplyTypes.Remove: return; } mod = 0 - mod; } var applyType = Common.EnumerationExtensions.GetEnum <ApplyTypes>((int)affect.Location % Program.REVERSE_APPLY); switch (applyType) { case ApplyTypes.Strength: ch.ModStrength += mod; break; case ApplyTypes.Dexterity: ch.ModDexterity += mod; break; case ApplyTypes.Intelligence: ch.ModIntelligence += mod; break; case ApplyTypes.Wisdom: ch.ModWisdom += mod; break; case ApplyTypes.Constitution: ch.ModConstitution += mod; break; case ApplyTypes.Charisma: ch.ModCharisma += mod; break; case ApplyTypes.Luck: ch.ModLuck += mod; break; case ApplyTypes.Gender: //ch.Gender = (ch.Gender + mod) % 3; // TODO Fix this //if (ch.Gender < 0) // ch.Gender += 2; //ch.Gender = Check.Range(0, ch.Gender, 2); break; case ApplyTypes.Height: ch.Height += mod; break; case ApplyTypes.Weight: ch.Weight += mod; break; case ApplyTypes.Mana: ch.MaximumMana += mod; break; case ApplyTypes.Hit: ch.MaximumHealth += mod; break; case ApplyTypes.Movement: ch.MaximumMovement += mod; break; case ApplyTypes.ArmorClass: ch.ArmorClass += mod; break; case ApplyTypes.HitRoll: ch.HitRoll.SizeOf += mod; break; case ApplyTypes.DamageRoll: ch.DamageRoll.SizeOf += mod; break; case ApplyTypes.SaveVsPoison: ch.SavingThrows.SaveVsPoisonDeath += mod; break; case ApplyTypes.SaveVsRod: ch.SavingThrows.SaveVsWandRod += mod; break; case ApplyTypes.SaveVsParalysis: ch.SavingThrows.SaveVsParalysisPetrify += mod; break; case ApplyTypes.SaveVsBreath: ch.SavingThrows.SaveVsBreath += mod; break; case ApplyTypes.SaveVsSpell: ch.SavingThrows.SaveVsSpellStaff += mod; break; case ApplyTypes.Affect: ch.AffectedBy.Bits[0].SetBit(mod); break; case ApplyTypes.ExtendedAffect: ch.AffectedBy.SetBit(mod); break; case ApplyTypes.Resistance: ch.Resistance.SetBit(mod); break; case ApplyTypes.Immunity: ch.Immunity.SetBit(mod); break; case ApplyTypes.Susceptibility: ch.Susceptibility.SetBit(mod); break; case ApplyTypes.Remove: ch.AffectedBy.Bits[0].RemoveBit(mod); break; case ApplyTypes.Full: case ApplyTypes.Thirst: case ApplyTypes.Drunk: case ApplyTypes.Blood: HandlePlayerCondition(ch, applyType, mod); break; case ApplyTypes.MentalState: ch.MentalState = (ch.MentalState + mod).GetNumberThatIsBetween(-100, 100); break; case ApplyTypes.Emotion: ch.EmotionalState = ch.EmotionalState.GetNumberThatIsBetween(-100, 100); break; case ApplyTypes.StripSN: if (Macros.IS_VALID_SN(mod)) { ch.StripAffects(mod); } else { LogManager.Instance.Bug("apply_modify: ApplyTypes.StripSN invalid SN %d", mod); } break; case ApplyTypes.WearSpell: case ApplyTypes.RemoveSpell: if (ch.CurrentRoom.Flags.IsSet(RoomFlags.NoMagic) || ch.Immunity.IsSet(ResistanceTypes.Magic) || (applyType == ApplyTypes.WearSpell && !add) || (applyType == ApplyTypes.RemoveSpell && add) || handler.SavingCharacter == ch || handler.LoadingCharacter == ch) { return; } mod = Math.Abs(mod); var skill = RepositoryManager.Instance.SKILLS.Values.ToList()[mod]; if (Macros.IS_VALID_SN(mod) && skill != null && skill.Type == SkillTypes.Spell) { if (skill.Target == TargetTypes.Ignore || skill.Target == TargetTypes.InventoryObject) { LogManager.Instance.Bug("ApplyTypes.WearSpell trying to apply bad target spell. SN is %d.", mod); return; } var retcode = skill.SpellFunction.Value.Invoke(mod, ch.Level, ch, ch); if (retcode == ReturnTypes.CharacterDied || ch.CharDied()) { return; } } break; default: var skillData = RepositoryManager.Instance.GetEntity <SkillData>(applyType.GetName()); if (skillData != null) { ch.ModifySkill((int)skillData.Type, mod, add); } else { LogManager.Instance.Bug("affect_modify: unknown location %d", affect.Location); } break; } var wield = ch.GetEquippedItem(WearLocations.Wield); var strWieldMod = (int)LookupManager.Instance.GetStatMod("Strength", ch.GetCurrentStrength(), StrengthModTypes.Wield); if (!ch.IsNpc() && handler.SavingCharacter != ch && wield != null && wield.GetWeight() > strWieldMod) { if (Depth == 0) { Depth++; comm.act(ATTypes.AT_ACTION, "You are too weak to wield $p any longer.", ch, wield, null, ToTypes.Character); comm.act(ATTypes.AT_ACTION, "$n stops wielding $p.", ch, wield, null, ToTypes.Room); ch.Unequip(wield); Depth--; } } }
private static void ItemWearWield(ObjectInstance obj, CharacterInstance ch, bool replace, ItemWearFlags wearFlag) { var strWieldMod = (int)LookupManager.Instance.GetStatMod("Strength", ch.GetCurrentStrength(), StrengthModTypes.Wield); if (!ch.CouldDualWield()) { if (!ch.RemoveFrom(WearLocations.WieldMissile, replace) || !ch.RemoveFrom(WearLocations.Wield, replace)) { return; } } else { var tobj = ch.GetEquippedItem(WearLocations.Wield); var mw = ch.GetEquippedItem(WearLocations.WieldMissile); var dw = ch.GetEquippedItem(WearLocations.DualWield); var hd = ch.GetEquippedItem(WearLocations.Hold); var sd = ch.GetEquippedItem(WearLocations.Shield); if (CheckFunctions.CheckIfTrue(ch, hd != null && sd != null, "You are already holding something and wearing a shield.")) { return; } if (tobj != null) { if (!ch.CanDualWield()) { return; } if (CheckFunctions.CheckIfTrue(ch, obj.GetWeight() + tobj.GetWeight() > strWieldMod, "It is too heavy for you to wield.")) { return; } if (CheckFunctions.CheckIfTrue(ch, hd != null || sd != null, "You're already wielding a weapon AND holding something.")) { return; } if (!MudProgHandler.ExecuteObjectProg(MudProgTypes.Use, ch, obj, null, null)) { comm.act(ATTypes.AT_ACTION, "$n dual-wields $p.", ch, obj, null, ToTypes.Room); comm.act(ATTypes.AT_ACTION, "You dual-wield $p.", ch, obj, null, ToTypes.Character); } ch.Equip(obj, wearFlag == ItemWearFlags.MissileWield ? WearLocations.WieldMissile : WearLocations.DualWield); MudProgHandler.ExecuteObjectProg(MudProgTypes.Wear, ch, obj); return; } if (mw != null) { ItemEquipMissileWeapon(obj, ch, mw, dw, hd, sd); return; } } if (CheckFunctions.CheckIfTrue(ch, obj.GetWeight() > strWieldMod, "It is too heavy for you to wield.")) { return; } if (!MudProgHandler.ExecuteObjectProg(MudProgTypes.Use, ch, obj, null, null)) { comm.act(ATTypes.AT_ACTION, "$n wields $p.", ch, obj, null, ToTypes.Room); comm.act(ATTypes.AT_ACTION, "You wield $p.", ch, obj, null, ToTypes.Character); } ch.Equip(obj, wearFlag == ItemWearFlags.MissileWield ? WearLocations.WieldMissile : WearLocations.Wield); MudProgHandler.ExecuteObjectProg(MudProgTypes.Wear, ch, obj); }