public virtual GameLiving GetLivingOwner() { if (Body is GamePet pet) { GamePet currPet = pet; for (int i = 0; currPet.Owner is GamePet nextPet; i++) { if (i > 50) { String Err = "GetLivingOwner() caused a cyclical loop for GamePet " + pet.Name; if (Owner != null) { Err += ", Owner " + Owner.Name; } log.Error(Err); return(null); } currPet = nextPet; } return(currPet.Owner); } return(null); }
public void CalculateDamageBase_SpellDamageIs100SourceIsAnimistPetWith100IntAndOwnerWith100Int_ReturnAround119() { var spell = NewFakeSpell(); spell.Damage = 100; var owner = NewFakePlayer(); owner.fakeCharacterClass = new CharacterClassAnimist(); owner.modifiedIntelligence = 100; owner.Level = 50; var brain = new FakeControlledBrain(); brain.fakeOwner = owner; GamePet source = new GamePet(brain); source.Level = 50; //temporal coupling through AutoSetStat() source.Intelligence = 100; var target = NewFakePlayer(); var spellLine = NewSpellLine(); var spellHandler = new SpellHandler(source, spell, spellLine); double actual = spellHandler.CalculateDamageBase(target); double expected = 100 * (100 + 200) / 275.0 * (100 + 200) / 275.0; Assert.AreEqual(expected, actual, 0.001); }
/// <summary> /// Apply effect on target or do spell action if non duration spell /// </summary> /// <param name="target">target that gets the effect</param> /// <param name="effectiveness">factor from 0..1 (0%-100%)</param> public override void ApplyEffectOnTarget(GameLiving target, double effectiveness) { INpcTemplate template = NpcTemplateMgr.GetTemplate(Spell.LifeDrainReturn); if (template == null) { if (log.IsWarnEnabled) { log.WarnFormat("NPC template {0} not found! Spell: {1}", Spell.LifeDrainReturn, Spell.ToString()); } MessageToCaster("NPC template " + Spell.LifeDrainReturn + " not found!", eChatType.CT_System); return; } GameSpellEffect effect = CreateSpellEffect(target, effectiveness); IControlledBrain brain = GetPetBrain(Caster); m_pet = GetGamePet(template); //brain.WalkState = eWalkState.Stay; m_pet.SetOwnBrain(brain as AI.ABrain); int x, y, z; ushort heading; Region region; GetPetLocation(out x, out y, out z, out heading, out region); m_pet.X = x; m_pet.Y = y; m_pet.Z = z; m_pet.Heading = heading; m_pet.CurrentRegion = region; m_pet.CurrentSpeed = 0; m_pet.Realm = Caster.Realm; m_pet.Level = GetPetLevel(); if (m_isSilent) { m_pet.IsSilent = true; } m_pet.AddToWorld(); //Check for buffs if (brain is ControlledNpcBrain) { (brain as ControlledNpcBrain).CheckSpells(StandardMobBrain.eCheckSpellType.Defensive); } AddHandlers(); SetBrainToOwner(brain); effect.Start(m_pet); Caster.OnPetSummoned(m_pet); }
public static GamePet Pet(GameLiving owner) { var brain = Substitute.For <ABrain, IControlledBrain>(); var npcTemplate = Substitute.For <INpcTemplate>(); (brain as IControlledBrain).Owner.Returns(owner); GamePet pet = new GamePet(brain); return(pet); }
public void CalculateDamageBase_SpellDamageIs100SourceIsAnimistPetWith100IntAndOwnerWith100Int_ReturnAround119() { var spell = Create.DamageSpell(100); var owner = Create.FakePlayer(new CharacterClassAnimist()); owner.modifiedIntelligence = 100; owner.Level = 50; GamePet source = Create.Pet(owner); source.Level = 50; //temporal coupling through AutoSetStat() source.Intelligence = 100; var target = Create.FakePlayer(); var spellLine = new SpellLine("", "", "", false); var spellHandler = new SpellHandler(source, spell, spellLine); double actual = spellHandler.CalculateDamageBase(target); double expected = 100 * (100 + 200) / 275.0 * (100 + 200) / 275.0; Assert.AreEqual(expected, actual, 0.001); }
/// <summary> /// Apply effect on target or do spell action if non duration spell /// </summary> /// <param name="target">target that gets the effect</param> /// <param name="effectiveness">factor from 0..1 (0%-100%)</param> public override void ApplyEffectOnTarget(GameLiving target, double effectiveness) { INpcTemplate template = NpcTemplateMgr.GetTemplate(Spell.LifeDrainReturn); if (template == null) { if (log.IsWarnEnabled) log.WarnFormat("NPC template {0} not found! Spell: {1}", Spell.LifeDrainReturn, Spell.ToString()); MessageToCaster("NPC template " + Spell.LifeDrainReturn + " not found!", eChatType.CT_System); return; } GameSpellEffect effect = CreateSpellEffect(target, effectiveness); IControlledBrain brain = GetPetBrain(Caster); m_pet = GetGamePet(template); //brain.WalkState = eWalkState.Stay; m_pet.SetOwnBrain(brain as AI.ABrain); int x, y, z; ushort heading; Region region; GetPetLocation(out x, out y, out z, out heading, out region); m_pet.X = x; m_pet.Y = y; m_pet.Z = z; m_pet.Heading = heading; m_pet.CurrentRegion = region; m_pet.CurrentSpeed = 0; m_pet.Realm = Caster.Realm; m_pet.Level = GetPetLevel(); if (m_isSilent) m_pet.IsSilent = true; m_pet.AddToWorld(); //Check for buffs if (brain is ControlledNpcBrain) (brain as ControlledNpcBrain).CheckSpells(StandardMobBrain.eCheckSpellType.Defensive); AddHandlers(); SetBrainToOwner(brain); effect.Start(m_pet); Caster.OnPetSummoned(m_pet); }
public void OnCommand(GameClient client, string[] args) { if (IsSpammingCommand(client.Player, "assist")) { return; } if (args.Length > 1) { // This makes absolutely no sense, but it's one of the weird features of the live servers if (args[1].ToLower() == client.Player.Name.ToLower()) // ToLower() is correct, don't change it! { // We cannot assist our target when it has no target. if (!HasTarget(client, client.Player)) { return; } YouAssist(client, client.Player.Name, client.Player.TargetObject); return; } GamePlayer assistPlayer = null; // Should be faster then WorldMgr.GetClientByPlayerName foreach (GamePlayer plr in client.Player.GetPlayersInRadius(2048)) { // ToLower() is correct, don't change it! if (plr.Name.ToLower() != args[1].ToLower()) { continue; } assistPlayer = plr; break; } if (assistPlayer != null) { // Each server type handles the assist command on it's own way. switch (GameServer.Instance.Configuration.ServerType) { case eGameServerType.GST_Normal: { // We cannot assist players of an enemy realm. if (!SameRealm(client, assistPlayer, false)) { return; } // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } case eGameServerType.GST_PvE: { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } case eGameServerType.GST_PvP: { // Note: // I absolutely don't have experience with pvp servers - change it when something is wrong. // Lets check if the client and it's targeted player are in the same alliance. if (client.Player.Guild != null) { if (client.Player.Guild.alliance != null && client.Player.Guild.alliance.Contains(assistPlayer.Guild)) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } // They are no alliance members, maybe guild members? if (client.Player.Guild.GetOnlineMemberByID(assistPlayer.InternalID) != null) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } } // They are no alliance or guild members - maybe group members? if (client.Player.Group != null && client.Player.Group.IsInTheGroup(assistPlayer)) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } // Ok, they are not in the same alliance, guild or group - maybe in the same battle group? BattleGroup clientBattleGroup = client.Player.TempProperties.getProperty <BattleGroup>(BattleGroup.BATTLEGROUP_PROPERTY, null); if (clientBattleGroup != null) { if (clientBattleGroup.Members.Contains(assistPlayer)) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } } // Ok, they are not in the same alliance, guild, group or battle group - maybe in the same chat group? ChatGroup clientChatGroup = client.Player.TempProperties.getProperty <ChatGroup>(ChatGroup.CHATGROUP_PROPERTY, null); if (clientChatGroup != null) { if (clientChatGroup.Members.Contains(assistPlayer)) { // We cannot assist our target when it has no target. if (!HasTarget(client, assistPlayer)) { return; } YouAssist(client, assistPlayer.Name, assistPlayer.TargetObject); return; } } // They are not in the same alliance, guild, group, battle group or chat group. And now? Well, they are enemies! NoValidTarget(client, assistPlayer); return; } } } client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Assist.MemberNotFound"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } if (client.Player.TargetObject != null) { // This makes absolutely no sense, but it's one of the weird features of the live servers if (client.Player.TargetObject == client.Player) { YouAssist(client, client.Player.Name, client.Player.TargetObject); return; } // Only assist npc's or players! if (client.Player.TargetObject is GameNPC || client.Player.TargetObject is GamePlayer) { // We cannot assist game objects! if (client.Player.TargetObject is GameMovingObject) { NoValidTarget(client, client.Player.TargetObject as GameLiving); return; } // Each server type handles the assist command on it's own way. switch (GameServer.Instance.Configuration.ServerType) { case eGameServerType.GST_Normal: { GameLiving targetLiving = (GameLiving)client.Player.TargetObject; // We cannot assist npc's or players of an enemy realm. if (!SameRealm(client, targetLiving, false)) { return; } // We cannot assist our target when it has no target. if (!HasTarget(client, targetLiving)) { return; } YouAssist(client, client.Player.TargetObject.GetName(0, true), targetLiving.TargetObject); return; } case eGameServerType.GST_PvE: { if (client.Player.TargetObject is GamePlayer) { // We cannot assist our target when it has no target. if (!HasTarget(client, client.Player.TargetObject as GameLiving)) { return; } YouAssist(client, client.Player.TargetObject.Name, (client.Player.TargetObject as GameLiving).TargetObject); return; } if (client.Player.TargetObject is GameNPC) { if (!SameRealm(client, client.Player.TargetObject as GameNPC, true)) { return; } else { // We cannot assist our target when it has no target. if (!HasTarget(client, client.Player.TargetObject as GameNPC)) { return; } YouAssist(client, client.Player.TargetObject.GetName(0, true), (client.Player.TargetObject as GameLiving).TargetObject); return; } } } break; case eGameServerType.GST_PvP: { // Note: // I absolutely don't have experience with pvp servers - change it when something is wrong. if (client.Player.TargetObject is GamePlayer) { GamePlayer targetPlayer = client.Player.TargetObject as GamePlayer; // Lets check if the client and it's targeted player are in the same alliance. if (client.Player.Guild != null && client.Player.Guild.alliance != null && client.Player.Guild.alliance.Contains(targetPlayer.Guild)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } // They are no alliance members, maybe guild members? if (client.Player.Guild != null && client.Player.Guild.GetOnlineMemberByID(targetPlayer.InternalID) != null) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } // They are no alliance or guild members - maybe group members? if (client.Player.Group != null && client.Player.Group.IsInTheGroup(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } // Ok, they are not in the same alliance, guild or group - maybe in the same battle group? BattleGroup clientBattleGroup = (BattleGroup)client.Player.TempProperties.getProperty <object>(BattleGroup.BATTLEGROUP_PROPERTY, null); if (clientBattleGroup != null) { if (clientBattleGroup.Members.Contains(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } } // Ok, they are not in the same alliance, guild, group or battle group - maybe in the same chat group? ChatGroup clientChatGroup = client.Player.TempProperties.getProperty <ChatGroup>(ChatGroup.CHATGROUP_PROPERTY, null); if (clientChatGroup != null) { if (clientChatGroup.Members.Contains(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPlayer)) { return; } YouAssist(client, targetPlayer.Name, targetPlayer.TargetObject); return; } } // They are not in the same alliance, guild, group, battle group or chat group. And now? Well, they are enemies! NoValidTarget(client, targetPlayer); return; } if (client.Player.TargetObject is GameNPC) { if (client.Player.TargetObject is GamePet) { GamePet targetPet = client.Player.TargetObject as GamePet; if (targetPet.Owner is GamePlayer) { GamePlayer targetPlayer = targetPet.Owner as GamePlayer; // Lets check if the client and it's targeted pets owner are in the same alliance. if (client.Player.Guild != null && client.Player.Guild.alliance != null && client.Player.Guild.alliance.Contains(targetPlayer.Guild)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } // They are no alliance members, maybe guild members? if (client.Player.Guild != null && client.Player.Guild.GetOnlineMemberByID(targetPlayer.InternalID) != null) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } // They are no alliance or guild members - maybe group members? if (client.Player.Group != null && client.Player.Group.IsInTheGroup(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } // Ok, they are not in the same alliance, guild or group - maybe in the same battle group? BattleGroup clientBattleGroup = client.Player.TempProperties.getProperty <BattleGroup>(BattleGroup.BATTLEGROUP_PROPERTY, null); if (clientBattleGroup != null) { if (clientBattleGroup.Members.Contains(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } } // Ok, they are not in the same alliance, guild, group or battle group - maybe in the same chat group? ChatGroup clientChatGroup = client.Player.TempProperties.getProperty <ChatGroup>(ChatGroup.CHATGROUP_PROPERTY, null); if (clientChatGroup != null) { if (clientChatGroup.Members.Contains(targetPlayer)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } } // They are not in the same alliance, guild, group, battle group or chat group. And now? Well, they are enemies! NoValidTarget(client, targetPet); return; } if (targetPet.Owner is GameNPC) { if (!SameRealm(client, targetPet.Owner as GameNPC, true)) { return; } else { // We cannot assist our target when it has no target if (!HasTarget(client, targetPet)) { return; } YouAssist(client, targetPet.GetName(0, false), targetPet.TargetObject); return; } } } if (client.Player.TargetObject is GameKeepGuard) { // Note: // We do not check if the targeted guard is attacking us, because this can be a bug! GameKeepGuard targetGuard = client.Player.TargetObject as GameKeepGuard; Guild targetedGuardGuild = GuildMgr.GetGuildByName(targetGuard.GuildName); // We can assist guards of an unclaimed keep! if (targetedGuardGuild == null) { // We cannot assist our target when it has no target if (!HasTarget(client, targetGuard)) { return; } YouAssist(client, targetGuard.GetName(0, false), targetGuard.TargetObject); return; } // Is the guard of our guild? if (client.Player.Guild == targetedGuardGuild) { // We cannot assist our target when it has no target if (!HasTarget(client, targetGuard)) { return; } YouAssist(client, targetGuard.GetName(0, false), targetGuard.TargetObject); return; } // Is the guard of one of our alliance guilds? if (client.Player.Guild.alliance.Contains(targetedGuardGuild)) { // We cannot assist our target when it has no target if (!HasTarget(client, targetGuard)) { return; } YouAssist(client, targetGuard.GetName(0, false), targetGuard.TargetObject); return; } // The guard is not of one of our alliance guilds and our guild. And now? Well, he is an enemy and we cannot assist enemies! NoValidTarget(client, targetGuard); return; } // We cannot assist npc's of an enemy realm. if (!SameRealm(client, client.Player.TargetObject as GameNPC, true)) { return; } // We cannot assist our target when it has no target if (!HasTarget(client, client.Player.TargetObject as GameNPC)) { return; } YouAssist(client, (client.Player.TargetObject as GameNPC).GetName(0, false), (client.Player.TargetObject as GameNPC).TargetObject); return; } } break; } } } client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Assist.SelectMember"), eChatType.CT_System, eChatLoc.CL_SystemWindow); return; }
/// <summary> /// Apply effect on target or do spell action if non duration spell /// </summary> /// <param name="target">target that gets the effect</param> /// <param name="effectiveness">factor from 0..1 (0%-100%)</param> public override void ApplyEffectOnTarget(GameLiving target, double effectiveness) { INpcTemplate template = NpcTemplateMgr.GetTemplate(Spell.LifeDrainReturn); if (template == null) { if (log.IsWarnEnabled) { log.WarnFormat("NPC template {0} not found! Spell: {1}", Spell.LifeDrainReturn, Spell.ToString()); } MessageToCaster("NPC template " + Spell.LifeDrainReturn + " not found!", eChatType.CT_System); return; } GameSpellEffect effect = CreateSpellEffect(target, effectiveness); IControlledBrain brain = null; if (template.ClassType != null && template.ClassType.Length > 0) { Assembly asm = Assembly.GetExecutingAssembly(); brain = (IControlledBrain)asm.CreateInstance(template.ClassType, true); if (brain == null && log.IsWarnEnabled) { log.Warn($"ApplyEffectOnTarget(): ClassType {template.ClassType} on NPCTemplateID {template.TemplateId} not found, using default ControlledBrain"); } } if (brain == null) { brain = GetPetBrain(Caster); } m_pet = GetGamePet(template); //brain.WalkState = eWalkState.Stay; m_pet.SetOwnBrain(brain as AI.ABrain); m_pet.SummonSpellDamage = Spell.Damage; m_pet.SummonSpellValue = Spell.Value; int x, y, z; ushort heading; Region region; GetPetLocation(out x, out y, out z, out heading, out region); m_pet.X = x; m_pet.Y = y; m_pet.Z = z; m_pet.Heading = heading; m_pet.CurrentRegion = region; m_pet.CurrentSpeed = 0; m_pet.Realm = Caster.Realm; if (m_isSilent) { m_pet.IsSilent = true; } m_pet.AddToWorld(); //Check for buffs if (brain is ControlledNpcBrain) { (brain as ControlledNpcBrain).CheckSpells(StandardMobBrain.eCheckSpellType.Defensive); } AddHandlers(); SetBrainToOwner(brain); m_pet.SetPetLevel(); m_pet.Health = m_pet.MaxHealth; if (DOL.GS.ServerProperties.Properties.PET_SCALE_SPELL_MAX_LEVEL > 0) { m_pet.Spells = template.Spells; // Have to scale spells again now that the pet level has been assigned } effect.Start(m_pet); Caster.OnPetSummoned(m_pet); }