Ejemplo n.º 1
0
        public void Execute(Ability ab, GamePlayer player)
        {
            if (player == null)
            {
                if (log.IsWarnEnabled)
                    log.Warn("Could not retrieve player in GuardAbilityHandler.");
                return;
            }

            GameObject targetObject = player.TargetObject;
            if (targetObject == null)
            {
                foreach (GuardEffect guard in player.EffectList.GetAllOfType<GuardEffect>())
                {
                    if (guard.GuardSource == player)
                        guard.Cancel(false);
                }
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Skill.Ability.Guard.CancelTargetNull"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            // You cannot guard attacks on yourself
            GamePlayer guardTarget = player.TargetObject as GamePlayer;
            if (guardTarget == player)
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Skill.Ability.Guard.CannotUse.GuardTargetIsGuardSource"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            // Only attacks on other players may be guarded.
            // guard may only be used on other players in group
            Group group = player.Group;
            if (guardTarget == null || group == null || !group.IsInTheGroup(guardTarget))
            {
                player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Skill.Ability.Guard.CannotUse.NotInGroup"), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            // check if someone is guarding the target
            foreach (GuardEffect guard in guardTarget.EffectList.GetAllOfType<GuardEffect>())
            {
                if (guard.GuardTarget != guardTarget) continue;
                if (guard.GuardSource == player)
                {
                    guard.Cancel(false);
                    return;
                }
                if(!(guard.GuardSource is GameNPC))
                {
                    player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "Skill.Ability.Guard.CannotUse.GuardTargetAlreadyGuarded", guard.GuardSource.GetName(0, true), guard.GuardTarget.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
            }

            // cancel all guard effects by this player before adding a new one
            foreach (GuardEffect guard in player.EffectList.GetAllOfType<GuardEffect>())
            {
                if (guard.GuardSource == player)
                    guard.Cancel(false);
            }

            new GuardEffect().Start(player, guardTarget);
        }
Ejemplo n.º 2
0
		private static void LoadAbilities()
		{
			// load Abilities
			log.Info("Loading Abilities...");

			var abilities = GameServer.Database.SelectAllObjects<DBAbility>();
			if (abilities != null)
			{
				foreach (DBAbility dba in abilities)
				{
					if (m_abilitiesByName.ContainsKey(dba.KeyName) == false)
					{
						m_abilitiesByName.Add(dba.KeyName, dba);
					}

					if (string.IsNullOrEmpty(dba.Implementation) == false && m_implementationTypeCache.ContainsKey(dba.Implementation) == false)
					{
						Type type = ScriptMgr.GetType(dba.Implementation);
						if (type != null)
						{
							Type typeCheck = new Ability(dba).GetType();
							if (type != typeCheck && type.IsSubclassOf(typeCheck))
							{
								m_implementationTypeCache.Add(dba.Implementation, type);
							}
							else
							{
								log.Warn("Ability implementation " + dba.Implementation + " is not derived from Ability. Cannot be used.");
							}
						}
						else
						{
							log.Warn("Ability implementation " + dba.Implementation + " for ability " + dba.Name + " not found");
						}
					}
				}
			}
			if (log.IsInfoEnabled)
			{
				log.Info("Total abilities loaded: " + ((abilities != null) ? abilities.Count : 0));
			}
		}
Ejemplo n.º 3
0
		private static Ability GetNewAbilityInstance(DBAbility dba)
		{
			// try instanciating ability
			Ability ab = null;
			
			if (Util.IsEmpty(dba.Implementation, true) == false)
			{
				// Try instanciating Ability
				foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
				{
					try
					{
						ab = (Ability)asm.CreateInstance(
							typeName: dba.Implementation, // string including namespace of the type
							ignoreCase: true,
							bindingAttr: BindingFlags.Default,
							binder: null,
							args: new object[] { dba, 0 },
							culture: null,
							activationAttributes: null);
						
						// instanciation worked
						if (ab != null) 
						{								
							break;
						}
					}
					catch
					{
					}
				}
				
				if (ab == null)
				{
					// Something Went Wrong when instanciating
					ab = new Ability(dba, 0);
					
					if (log.IsWarnEnabled)
						log.WarnFormat("Could not Instanciate Ability {0} from {1} reverting to default Ability...", dba.KeyName, dba.Implementation);
				}
			}
			else
			{
				ab = new Ability(dba, 0);
			}
			
			return ab;
		}
Ejemplo n.º 4
0
        public void Execute(Ability ab, GamePlayer player)
        {
            if (!player.IsAlive)
            {
                player.Out.SendMessage("You're dead and can't Bodyguard!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }
            if (player == null)
            {
                if (log.IsWarnEnabled)
                    log.Warn("Could not retrieve player in BodyguardAbilityHandler.");
                return;
            }

            GameObject targetObject = player.TargetObject;
            if (targetObject == null)
            {
				foreach (BodyguardEffect bg in player.EffectList.GetAllOfType<BodyguardEffect>())
                {
                    if (bg.GuardSource == player)
                        bg.Cancel(false);
                }
                player.Out.SendMessage("You are no longer Bodyguarding anyone.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            // You cannot guard attacks on yourself            
            GamePlayer guardTarget = player.TargetObject as GamePlayer;
            if (guardTarget == player)
            {
                player.Out.SendMessage("You can't Bodyguard yourself!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            // Only attacks on other players may be guarded. 
            // guard may only be used on other players in group
            Group group = player.Group;
            if (guardTarget == null || group == null || !group.IsInTheGroup(guardTarget))
            {
                player.Out.SendMessage("You can only guard players in your group!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            // check if someone is guarding the target
			foreach (BodyguardEffect bg in guardTarget.EffectList.GetAllOfType<BodyguardEffect>())
            {
                if (bg.GuardTarget != guardTarget) continue;
                if (bg.GuardSource == player)
                {
                    bg.Cancel(false);
                    return;
                }
                player.Out.SendMessage(string.Format("{0} is already guarding {1}!", bg.GuardSource.GetName(0, true), bg.GuardTarget.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

			foreach (BodyguardEffect bg in player.EffectList.GetAllOfType<BodyguardEffect>())
            {
                    if (bg != null && player == bg.GuardTarget)
                    {
                        player.Out.SendMessage("You cannot bodyguard someone if you are Bodyguarded!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                        return;
                    }
            }

            // cancel all guard effects by this player before adding a new one
			foreach (BodyguardEffect bg in player.EffectList.GetAllOfType<BodyguardEffect>())
            {
                if (bg.GuardSource == player)
                    bg.Cancel(false);
            }

            new BodyguardEffect().Start(player, guardTarget);
        }