/// <summary> /// Stops the duel if player attack or is attacked by anything other that duel target /// </summary> /// <param name="e"></param> /// <param name="sender"></param> /// <param name="arguments"></param> protected virtual void DuelOnAttack(DOLEvent e, object sender, EventArgs arguments) { AttackData ad = null; GameLiving target = null; var afea = arguments as AttackFinishedEventArgs; var abeea = arguments as AttackedByEnemyEventArgs; if (afea != null) { ad = afea.AttackData; target = ad.Target; } else if (abeea != null) { ad = abeea.AttackData; target = ad.Attacker; } if (ad == null) { return; } // check pets owner for my and enemy attacks GameNPC npc = target as GameNPC; if (npc != null) { IControlledBrain brain = npc.Brain as IControlledBrain; if (brain != null) { target = brain.GetPlayerOwner(); } } // Duel should end if players join group and trys to attack if (ad.Attacker.Group != null && ad.Attacker.Group.IsInTheGroup(ad.Target)) { Stop(); } if (ad.IsHit && target != Target) { Stop(); } }
public override void TakeDamage(GameObject source, eDamageType damageType, int damageAmount, int criticalAmount) { //Check if this encounter mob is tethered and if so, ignore any damage done both outside of or too far from it's tether range. if (this.TetherRange > 100) { // if controlled NPC - do checks for owner instead if (source is GameNPC) { IControlledBrain controlled = ((GameNPC)source).Brain as IControlledBrain; if (controlled != null) { source = controlled.GetPlayerOwner(); } } if (IsOutOfTetherRange) { if (source is GamePlayer) { GamePlayer player = source as GamePlayer; player.Out.SendMessage("The " + this.Name + " is too far from its encounter area, your damage fails to have an effect on it!", eChatType.CT_Important, eChatLoc.CL_ChatWindow); return; } return; } else { if (IsWithinRadius(source, this.TetherRange)) { base.TakeDamage(source, damageType, damageAmount, criticalAmount); return; } if (source is GamePlayer) { GamePlayer player = source as GamePlayer; player.Out.SendMessage("You are too far from the " + this.Name + ", your damage fails to effect it!", eChatType.CT_Important, eChatLoc.CL_ChatWindow); } return; } } else { base.TakeDamage(source, damageType, damageAmount, criticalAmount); } }
/// <summary> /// execute direct effect /// </summary> /// <param name="target">target that gets the damage</param> /// <param name="effectiveness">factor from 0..1 (0%-100%)</param> public override void OnDirectEffect(GameLiving target, double effectiveness) { if (target == null) { return; } bool spellOK = !(Spell.Target.ToLower() == "cone" || Spell.Target == "Enemy" && Spell.Radius > 0 && Spell.Range == 0); if (spellOK == false || MustCheckLOS(Caster)) { GamePlayer checkPlayer = null; if (target is GamePlayer) { checkPlayer = target as GamePlayer; } else { if (Caster is GamePlayer) { checkPlayer = Caster as GamePlayer; } else if ((Caster as GameNPC)?.Brain is IControlledBrain) { IControlledBrain brain = ((GameNPC)Caster).Brain as IControlledBrain; checkPlayer = brain.GetPlayerOwner(); } } if (checkPlayer != null) { checkPlayer.TempProperties.setProperty(LOSEFFECTIVENESS + target.ObjectID, effectiveness); checkPlayer.Out.SendCheckLOS(Caster, target, new CheckLOSResponse(DealDamageCheckLOS)); } else { DealDamage(target, effectiveness); } } else { DealDamage(target, effectiveness); } }
/// <summary> /// execute direct effect /// </summary> /// <param name="target">target that gets the damage</param> /// <param name="effectiveness">factor from 0..1 (0%-100%)</param> public override void OnDirectEffect(GameLiving target, double effectiveness) { if (target == null) { return; } bool spellOK = !(Spell.Target == "Frontal" || Spell.Target == "Enemy" && Spell.Radius > 0 && Spell.Range == 0); if (!spellOK || CheckLOS(Caster)) { GamePlayer player = null; if (target is GamePlayer gamePlayer) { player = gamePlayer; } else { if (Caster is GamePlayer player1) { player = player1; } else if ((Caster as GameNPC)?.Brain is IControlledBrain) { IControlledBrain brain = ((GameNPC)Caster).Brain as IControlledBrain; player = brain.GetPlayerOwner(); } } if (player != null) { player.TempProperties.setProperty(LOSEFFECTIVENESS, effectiveness); player.Out.SendCheckLOS(Caster, target, new CheckLOSResponse(DealDamageCheckLOS)); } else { DealDamage(target, effectiveness); } } else { DealDamage(target, effectiveness); } }
/// <summary> /// Handler fired on every melee attack by effect target /// </summary> /// <param name="e"></param> /// <param name="sender"></param> /// <param name="arguments"></param> protected override void EventHandler(DOLEvent e, object sender, EventArgs arguments) { AttackFinishedEventArgs atkArgs = arguments as AttackFinishedEventArgs; if (atkArgs == null) { return; } if (atkArgs.AttackData.AttackResult != GameLiving.eAttackResult.HitUnstyled && atkArgs.AttackData.AttackResult != GameLiving.eAttackResult.HitStyle) { return; } GameLiving target = atkArgs.AttackData.Target; if (target == null) { return; } if (target.ObjectState != GameObject.eObjectState.Active) { return; } if (target.IsAlive == false) { return; } if (target is GameKeepComponent || target is GameKeepDoor) { return; } GameLiving attacker = sender as GameLiving; if (attacker == null) { return; } if (attacker.ObjectState != GameObject.eObjectState.Active) { return; } if (attacker.IsAlive == false) { return; } int spread = m_minDamageSpread; spread += Util.Random(50); double dpsCap = DPSCap(attacker.Level); double dps = IgnoreDamageCap ? Spell.Damage : Math.Min(Spell.Damage, dpsCap); double damage = dps * atkArgs.AttackData.WeaponSpeed * spread * 0.001; // attack speed is 10 times higher (2.5spd=25) double damageResisted = damage * target.GetResist(Spell.DamageType) * -0.01; // log.DebugFormat("dps: {0}, damage: {1}, damageResisted: {2}, minDamageSpread: {3}, spread: {4}", dps, damage, damageResisted, m_minDamageSpread, spread); if (Spell.Damage < 0) { damage = atkArgs.AttackData.Damage * Spell.Damage / -100.0; damageResisted = damage * target.GetResist(Spell.DamageType) * -0.01; } AttackData ad = new AttackData(); ad.Attacker = attacker; ad.Target = target; ad.Damage = (int)(damage + damageResisted); ad.Modifier = (int)damageResisted; ad.DamageType = Spell.DamageType; ad.AttackType = AttackData.eAttackType.Spell; ad.SpellHandler = this; ad.AttackResult = GameLiving.eAttackResult.HitUnstyled; if (ad.Attacker is GameNPC) { IControlledBrain brain = ((GameNPC)ad.Attacker).Brain as IControlledBrain; if (brain != null) { GamePlayer owner = brain.GetPlayerOwner(); if (owner != null) { MessageToLiving(owner, String.Format(LanguageMgr.GetTranslation(owner.Client, "DamageAddAndShield.EventHandlerDA.YourHitFor"), ad.Attacker.Name, target.GetName(0, false), ad.Damage), eChatType.CT_Spell); } } } else { GameClient attackerClient = null; if (attacker is GamePlayer) { attackerClient = ((GamePlayer)attacker).Client; } if (attackerClient != null) { MessageToLiving(attacker, String.Format(LanguageMgr.GetTranslation(attackerClient, "DamageAddAndShield.EventHandlerDA.YouHitExtra"), target.GetName(0, false), ad.Damage), eChatType.CT_Spell); } } GameClient targetClient = null; if (target is GamePlayer) { targetClient = ((GamePlayer)target).Client; } if (targetClient != null) { MessageToLiving(target, String.Format(LanguageMgr.GetTranslation(targetClient, "DamageAddAndShield.EventHandlerDA.DamageToYou"), attacker.GetName(0, false), ad.Damage), eChatType.CT_Spell); } target.OnAttackedByEnemy(ad); attacker.DealDamage(ad); foreach (GamePlayer player in ad.Attacker.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) { if (player == null) { continue; } player.Out.SendCombatAnimation(null, target, 0, 0, 0, 0, 0x0A, target.HealthPercent); } }
/// <summary> /// Handler fired whenever effect target is attacked /// </summary> /// <param name="e"></param> /// <param name="sender"></param> /// <param name="arguments"></param> protected override void EventHandler(DOLEvent e, object sender, EventArgs arguments) { AttackedByEnemyEventArgs args = arguments as AttackedByEnemyEventArgs; if (args == null) { return; } if (args.AttackData.AttackResult != GameLiving.eAttackResult.HitUnstyled && args.AttackData.AttackResult != GameLiving.eAttackResult.HitStyle) { return; } if (!args.AttackData.IsMeleeAttack) { return; } GameLiving attacker = sender as GameLiving; //sender is target of attack, becomes attacker for damage shield if (attacker == null) { return; } if (attacker.ObjectState != GameObject.eObjectState.Active) { return; } if (attacker.IsAlive == false) { return; } GameLiving target = args.AttackData.Attacker; //attacker becomes target for damage shield if (target == null) { return; } if (target.ObjectState != GameObject.eObjectState.Active) { return; } if (target.IsAlive == false) { return; } int spread = m_minDamageSpread; spread += Util.Random(50); double damage = Spell.Damage * target.AttackSpeed(target.AttackWeapon) * spread * 0.00001; double damageResisted = damage * target.GetResist(Spell.DamageType) * -0.01; if (Spell.Damage < 0) { damage = args.AttackData.Damage * Spell.Damage / -100.0; damageResisted = damage * target.GetResist(Spell.DamageType) * -0.01; } AttackData ad = new AttackData(); ad.Attacker = attacker; ad.Target = target; ad.Damage = (int)(damage + damageResisted); ad.Modifier = (int)damageResisted; ad.DamageType = Spell.DamageType; ad.SpellHandler = this; ad.AttackType = AttackData.eAttackType.Spell; ad.AttackResult = GameLiving.eAttackResult.HitUnstyled; GamePlayer owner = null; GameClient attackerClient = null; if (attacker is GamePlayer) { attackerClient = ((GamePlayer)attacker).Client; } if (ad.Attacker is GameNPC) { IControlledBrain brain = ((GameNPC)ad.Attacker).Brain as IControlledBrain; if (brain != null) { owner = brain.GetPlayerOwner(); if (owner != null && owner.ControlledBrain != null && ad.Attacker == owner.ControlledBrain.Body) { MessageToLiving(owner, String.Format(LanguageMgr.GetTranslation(owner.Client, "DamageAddAndShield.EventHandlerDS.YourHitFor"), ad.Attacker.Name, target.GetName(0, false), ad.Damage), eChatType.CT_Spell); } } } else if (attackerClient != null) { MessageToLiving(attacker, String.Format(LanguageMgr.GetTranslation(attackerClient, "DamageAddAndShield.EventHandlerDS.YouHitFor"), target.GetName(0, false), ad.Damage), eChatType.CT_Spell); } GameClient targetClient = null; if (target is GamePlayer) { targetClient = ((GamePlayer)target).Client; } if (targetClient != null) { MessageToLiving(target, String.Format(LanguageMgr.GetTranslation(targetClient, "DamageAddAndShield.EventHandlerDS.DamageToYou"), attacker.GetName(0, false), ad.Damage), eChatType.CT_Spell); } target.OnAttackedByEnemy(ad); attacker.DealDamage(ad); foreach (GamePlayer player in attacker.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) { if (player == null) { continue; } player.Out.SendCombatAnimation(null, target, 0, 0, 0, 0, 0x14, target.HealthPercent); } // Log.Debug(String.Format("spell damage: {0}; damage: {1}; resisted damage: {2}; damage type {3}; minSpread {4}.", Spell.Damage, ad.Damage, ad.Modifier, ad.DamageType, m_minDamageSpread)); // Log.Debug(String.Format("dmg {0}; spread: {4}; resDmg: {1}; atkSpeed: {2}; resist: {3}.", damage, damageResisted, target.AttackSpeed(null), ad.Target.GetResist(Spell.DamageType), spread)); }
public override bool IsAllowedToAttack(GameLiving attacker, GameLiving defender, bool quiet) { if (!base.IsAllowedToAttack(attacker, defender, quiet)) { return(false); } // if controlled NPC - do checks for owner instead if (attacker is GameNPC) { IControlledBrain controlled = ((GameNPC)attacker).Brain as IControlledBrain; if (controlled != null) { attacker = controlled.GetPlayerOwner(); quiet = true; // silence all attacks by controlled npc } } if (defender is GameNPC) { IControlledBrain controlled = ((GameNPC)defender).Brain as IControlledBrain; if (controlled != null) { defender = controlled.GetPlayerOwner(); } } //"You can't attack yourself!" if (attacker == defender) { if (quiet == false) { MessageToLiving(attacker, "You can't attack yourself!"); } return(false); } // Pet release might cause one of these to be null if (attacker == null || defender == null) { return(false); } if (attacker.Realm != eRealm.None && defender.Realm != eRealm.None) { if (attacker is GamePlayer && ((GamePlayer)attacker).DuelTarget == defender) { return(true); } if (quiet == false) { MessageToLiving(attacker, "You can not attack other players on this server!"); } return(false); } //allow attacks on same realm only under the following circumstances if (attacker.Realm == defender.Realm) { //allow confused mobs to attack same realm if (attacker is GameNPC && (attacker as GameNPC).IsConfused) { return(true); } // else, don't allow mobs to attack mobs if (attacker.Realm == eRealm.None) { return(FactionMgr.CanLivingAttack(attacker, defender)); } if (quiet == false) { MessageToLiving(attacker, "You can't attack a member of your realm!"); } return(false); } return(true); }
public override bool IsSameRealm(GameLiving source, GameLiving target, bool quiet) { if (source == null || target == null) { return(false); } // if controlled NPC - do checks for owner instead if (source is GameNPC) { IControlledBrain controlled = ((GameNPC)source).Brain as IControlledBrain; if (controlled != null) { source = controlled.GetPlayerOwner(); quiet = true; // silence all attacks by controlled npc } } if (target is GameNPC) { IControlledBrain controlled = ((GameNPC)target).Brain as IControlledBrain; if (controlled != null) { target = controlled.GetPlayerOwner(); } } if (source == target) { return(true); } // clients with priv level > 1 are considered friendly by anyone if (target is GamePlayer && ((GamePlayer)target).Client.Account.PrivLevel > 1) { return(true); } // mobs can heal mobs, players heal players/NPC if (source.Realm == 0 && target.Realm == 0) { return(true); } if (source.Realm != 0 && target.Realm != 0) { return(true); } //Peace flag NPCs are same realm if (target is GameNPC) { if ((((GameNPC)target).Flags & GameNPC.eFlags.PEACE) != 0) { return(true); } } if (source is GameNPC) { if ((((GameNPC)source).Flags & GameNPC.eFlags.PEACE) != 0) { return(true); } } if (quiet == false) { MessageToLiving(source, target.GetName(0, true) + " is not a member of your realm!"); } return(false); }
/// <summary> /// Grants credit for the encounter to the killer/player and /// optionally his group or battlegroup mates. /// </summary> public static void GrantEncounterCredit(GameObject killer, bool group, bool battlegroup, string artifactid) { List <GamePlayer> creditPlayerList = new List <GamePlayer>(); // if controlled NPC - do checks for owner instead if (killer is GameNPC) { IControlledBrain controlled = ((GameNPC)killer).Brain as IControlledBrain; if (controlled != null) { killer = controlled.GetPlayerOwner(); } } GamePlayer player = killer as GamePlayer; //add the killer player to the list. if (!creditPlayerList.Contains(player)) { creditPlayerList.Add(player); } //if killing player has a group, let's add those players to the list to receive credit. if (player.Group != null && group) { //player is grouped, let's add the group to the list to recieve credit. foreach (GamePlayer groupplayer in (player.Group.GetPlayersInTheGroup())) { if (!creditPlayerList.Contains(groupplayer)) { //only add players are near enough that they would have earned XP from the kill. if (groupplayer.IsWithinRadius(killer, WorldMgr.MAX_EXPFORKILL_DISTANCE)) { creditPlayerList.Add(groupplayer); } } } } //if killing player has a battlegroup, let's add those players to the list to receive credit. if (player.isInBG && battlegroup) { BattleGroup bg = (BattleGroup)player.TempProperties.getProperty <object>(BattleGroup.BATTLEGROUP_PROPERTY, null); HybridDictionary bgplayers = bg.Members; foreach (GamePlayer eachplayer in bgplayers.Keys) { if (!creditPlayerList.Contains(eachplayer)) { //only add players who are near enough that they would have earned XP from the kill. if (eachplayer.IsWithinRadius(killer, WorldMgr.MAX_EXPFORKILL_DISTANCE)) { creditPlayerList.Add(eachplayer); } } } } //List should now contain the killer, plus optionally the players in his group, and optionally his battlegroup if (creditPlayerList.Count > 0) { foreach (GamePlayer creditplayer in creditPlayerList) { creditplayer.Out.SendMessage("The " + artifactid + " encounter has been completed, you should have received credit, if you were eligible.", eChatType.CT_Important, eChatLoc.CL_ChatWindow); ArtifactMgr.GrantArtifactCredit(creditplayer, artifactid); } } return; }
public override LootList GenerateLoot(GameNPC mob, GameObject killer) { LootList loot = base.GenerateLoot(mob, killer); List <LootOTD> lootOTDs = null; try { if (m_mobOTDList.ContainsKey(mob.Name.ToLower())) { lootOTDs = m_mobOTDList[mob.Name.ToLower()]; } if (lootOTDs != null) { foreach (GameObject gainer in mob.XPGainers.Keys) { GamePlayer player = null; if (gainer is GamePlayer) { player = gainer as GamePlayer; } else if (gainer is GameNPC) { IControlledBrain brain = ((GameNPC)gainer).Brain as IControlledBrain; if (brain != null) { player = brain.GetPlayerOwner(); } } if (player != null) { foreach (LootOTD drop in lootOTDs) { if (drop.MinLevel <= player.Level) { CharacterXOneTimeDrop hasDrop = GameServer.Database.SelectObject <CharacterXOneTimeDrop>("CharacterID = '" + GameServer.Database.Escape(player.QuestPlayerID) + "' AND ItemTemplateID = '" + GameServer.Database.Escape(drop.ItemTemplateID) + "'"); if (hasDrop == null) { ItemTemplate item = GameServer.Database.FindObjectByKey <ItemTemplate>(drop.ItemTemplateID); if (item != null) { if (player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, GameInventoryItem.Create <ItemTemplate>(item))) { CharacterXOneTimeDrop charXDrop = new CharacterXOneTimeDrop(); charXDrop.CharacterID = player.QuestPlayerID; charXDrop.ItemTemplateID = drop.ItemTemplateID; GameServer.Database.AddObject(charXDrop); player.Out.SendMessage(string.Format("You receive {0} from {1}!", item.GetName(1, false), mob.GetName(1, false)), eChatType.CT_Loot, eChatLoc.CL_SystemWindow); InventoryLogging.LogInventoryAction(mob, player, eInventoryActionType.Loot, item); } else { // do not drop, player will have to try again player.Out.SendMessage("Your inventory is full and a one time drop cannot be added!", eChatType.CT_Important, eChatLoc.CL_SystemWindow); log.DebugFormat("OTD Failed, Inventory full: {0} from mob {1} for player {2}.", drop.ItemTemplateID, drop.MobName, player.Name); break; } } else { log.ErrorFormat("Error trying to drop ItemTemplate {0} from {1}. Item not found.", drop.ItemTemplateID, drop.MobName); } } } } } } } } catch (Exception ex) { log.Error("LootGeneratorOneTimeDrop exception for mob " + mob.Name + ":", ex); } return(loot); }
public override void Start(GameLiving living) { m_living = living; //Send messages if (m_living is GamePlayer) { ((GamePlayer)m_living).Out.SendMessage("You begin to charge wildly!", eChatType.CT_Spell, eChatLoc.CL_SystemWindow); } else if (m_living is GameNPC) { IControlledBrain icb = ((GameNPC)m_living).Brain as IControlledBrain; if (icb != null && icb.Body != null) { GamePlayer playerowner = icb.GetPlayerOwner(); if (playerowner != null) { playerowner.Out.SendMessage("The " + icb.Body.Name + " charges its prey!", eChatType.CT_Say, eChatLoc.CL_SystemWindow); } } } else { return; } m_startTick = living.CurrentRegion.Time; foreach (GamePlayer t_player in living.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) { t_player.Out.SendSpellEffectAnimation(living, living, 7035, 0, false, 1); } //sets player into combat mode living.LastAttackTickPvP = m_startTick; ArrayList speedSpells = new ArrayList(); lock (living.EffectList) { foreach (IGameEffect effect in living.EffectList) { if (effect is GameSpellEffect == false) { continue; } if ((effect as GameSpellEffect).Spell.SpellType == "SpeedEnhancement") { speedSpells.Add(effect); } } } foreach (GameSpellEffect spell in speedSpells) { spell.Cancel(false); } m_living.BuffBonusMultCategory1.Set((int)eProperty.MaxSpeed, this, PropertyCalc.MaxSpeedCalculator.SPEED3); m_living.TempProperties.setProperty("Charging", true); if (m_living is GamePlayer) { ((GamePlayer)m_living).Out.SendUpdateMaxSpeed(); } StartTimers(); m_living.EffectList.Add(this); }