public static void do_aid(CharacterInstance ch, string argument) { if (CheckFunctions.CheckIfTrue(ch, ch.IsNpc() && ch.IsAffected(AffectedByTypes.Charm), Resources.CANNOT_CONCENTRATE)) { return; } var arg = argument.FirstWord(); if (CheckFunctions.CheckIfEmptyString(ch, arg, Resources.AID_WHO)) { return; } var victim = ch.GetCharacterInRoom(arg); if (CheckFunctions.CheckIfNullObject(ch, victim, "They aren't here.")) { return; } if (CheckFunctions.CheckIfNpc(ch, victim, "Not on mobs.")) { return; } if (CheckFunctions.CheckIfNotNullObject(ch, ch.CurrentMount, "You can't do that while mounted.")) { return; } if (CheckFunctions.CheckIfEquivalent(ch, ch, victim, "Aid yourself?")) { return; } if ((int)victim.CurrentPosition >= (int)PositionTypes.Stunned) { comm.act(ATTypes.AT_PLAIN, "$N doesn't need your help.", ch, null, victim, ToTypes.Character); return; } if (victim.CurrentHealth <= -6) { comm.act(ATTypes.AT_PLAIN, "$N's condition is beyond your aiding ability.", ch, null, victim, ToTypes.Character); return; } var percent = SmaugRandom.D100() - ch.GetCurrentLuck() - 13; var skill = RepositoryManager.Instance.GetEntity <SkillData>("aid"); if (skill == null) { throw new ObjectNotFoundException("Skill 'aid' was not found."); } Macros.WAIT_STATE(ch, skill.Rounds); if (!ch.CanUseSkill(percent, skill)) { ch.SendTo("You fail."); skill.LearnFromFailure((PlayerInstance)ch); return; } comm.act(ATTypes.AT_SKILL, "You aid $N!", ch, null, victim, ToTypes.Character); comm.act(ATTypes.AT_SKILL, "$n aids $N!", ch, null, victim, ToTypes.Room); skill.LearnFromSuccess((PlayerInstance)ch); ((PlayerInstance)ch).AdjustFavor(DeityFieldTypes.Aid, 1); if (victim.CurrentHealth < 1) { victim.CurrentHealth = 1; } victim.UpdatePositionByCurrentHealth(); comm.act(ATTypes.AT_SKILL, "$n aids you!", ch, null, victim, ToTypes.Victim); }
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 ReturnTypes ranged_got_target(CharacterInstance ch, CharacterInstance victim, ObjectInstance weapon, ObjectInstance projectile, int dist, int dt, string stxt, ATTypes color) { if (ch.CurrentRoom.Flags.IsSet(RoomFlags.Safe)) { if (projectile != null) { ch.PrintfColor("Your %s is blasted from existence by a godly presence.", projectile); comm.act(color, "A godly presence smites $p!", ch, projectile, null, ToTypes.Room); projectile.Extract(); } else { ch.Printf("Your %s is blasted from existence by a godly presence.", stxt); comm.act(color, "A godly presence smites $t!", ch, stxt.AddArticle(ArticleAppendOptions.TheToFront), null, ToTypes.Room); } return(ReturnTypes.None); } var skill = RepositoryManager.Instance.GetEntity <SkillData>("MissileWeapons"); if (victim.IsNpc() && victim.Act.IsSet((int)ActFlags.Sentinel) && ch.CurrentRoom != victim.CurrentRoom) { if (projectile == null) { return(ch.CauseDamageTo(victim, 0, dt)); } skill.LearnFromFailure(ch); if (SmaugRandom.D100() < 50) { projectile.Extract(); } else { if (projectile.InObject != null) { projectile.RemoveFrom(projectile.InObject); } if (projectile.CarriedBy != null) { projectile.RemoveFrom(); } victim.CurrentRoom.AddTo(projectile); } return(ch.CauseDamageTo(victim, 0, dt)); } if (SmaugRandom.D100() > 50 || (projectile != null && weapon != null && ch.CanUseSkill(SmaugRandom.D100(), skill))) { return(projectile != null?fight.projectile_hit(ch, victim, weapon, projectile, dist) : Attack.spell_attack(dt, ch.Level, ch, victim)); } skill.LearnFromFailure(ch); var returnCode = ch.CauseDamageTo(victim, 0, dt); if (projectile == null) { return(returnCode); } if (SmaugRandom.D100() < 50) { projectile.Extract(); } else { if (projectile.InObject != null) { projectile.RemoveFrom(projectile.InObject); } if (projectile.CarriedBy != null) { projectile.RemoveFrom(); } victim.CurrentRoom.AddTo(projectile); } return(returnCode); }