All pastes #251371 Raw Edit

Untitled

public text v1 · immutable
#251371 ·published 2006-11-18 01:59 UTC
rendered paste body
#define RADAR_NONE 0
#define RADAR_SWEEP 1

#define RADAR_MAX_RANGE 60

objectdef oBlip
{
	variable int Priority
	variable objectref Data
	
	method Initialize(string DataGUID, int Priority = 100)
	{
		This.Data:Set[${DataGUID}]
		This.Priority:Set[${Priority}]
	}
}

objectdef oBlacklist
{
	variable string BlacklistGUID
	variable int Expiration
	
	method Initialize(string BlacklistGUID, int Expiration)
	{
		This.BlacklistGUID:Set[${BlacklistGUID}]
		This.Expiration:Set[${This.Expiration}]
	}
}

objectdef oRadar inherits oBase
{
	variable int LastSweep

	variable index:oBlip HostilePlayers
	variable index:oBlip FriendlyPlayers
	variable index:oBlip Aggro
	variable index:oBlacklist Blacklist
	
	variable int TargetCount = 0
	variable int HostilePlayerCount = 0
	variable int FriendlyPlayerCount = 0
	
	method BlacklistGUID(string ObjectGUID, int Expiration=0)
	{
		This.Blacklist:Collapse
	}
	
	member Blacklisted(string ObjectGUID)
	{
	}
	
	method ResetHostilePlayers()
	{
		This.HostilePlayerCount:Set[0]
		HostilePlayers:Collapse
		if ${HostilePlayers.Get[1](exists)}
		{
			do
			{
				HostilePlayers:Remove[1]
			}
			while ${HostilePlayers.Get[1](exists)}
		}
	}

	method ResetFriendlyPlayers()
	{
		This.FriendlyPlayerCount:Set[0]
		FriendlyPlayers:Collapse
		if ${FriendlyPlayers.Get[1](exists)}
		{
			do
			{
				FriendlyPlayers:Remove[1]
			}
			while ${FriendlyPlayers.Get[1](exists)}
		}
	}
	
	method SweepHostilePlayers()
	{
		variable guidlist Targets
		variable int Index = 1
		Targets:Search[-players,-hostile,-lineofsight,-alive,-nearest,-notflying,-range 0-RADAR_MAX_RANGE] 
		
		if ${Targets.Count} > 0
		{
			do
			{
				This.HostilePlayerCount:Inc
				This.TargetCount:Inc
				HostilePlayers:Insert[${Targets.GUID[${Index}]},50]
			}
			while ${Index:Inc}<=${Targets.Count}
		}
		
		Event[RADAR_EVENT_HOSTILEPLAYERSUPDATED]:Execute
	}

	method SweepFriendlyPlayers()
	{
		variable guidlist Targets
		variable int Index = 1
		Targets:Search[-players,-friendly,-lineofsight,-alive,-nearest,-notflying,-range 0-RADAR_MAX_RANGE] 
		
		if ${Targets.Count} > 0
		{
			do
			{
				if ${Targets.GUID[${Index}].NotEqual[${Me.GUID}]}
				{
					This.FriendlyPlayerCount:Inc
					This.TargetCount:Inc
					FriendlyPlayers:Insert[${Targets.GUID[${Index}]},50]
				}
			}
			while ${Index:Inc}<=${Targets.Count}
		}
		
		Event[RADAR_EVENT_FRIENDLYPLAYERSUPDATED]:Execute
	}
	
	method Sweep()
	{
		This.LastSweep:Set[${LavishScript.RunningTime}]
		This.TargetCount:Set[0]
		
		This:ResetHostilePlayers
		This:SweepHostilePlayers
		
		This:ResetFriendlyPlayers
		This:SweepFriendlyPlayers
		
		Event[RADAR_EVENT_SWEEP]:Execute
	}
	
	member NeedSweep()
	{
		if ${Math.Calc[${LavishScript.RunningTime} - ${This.LastSweep}]} > 50
		{
			return TRUE
		}
		return FALSE
	}
	
	member HaveTarget()
	{
		if ${This.HostilePlayerCount} > 0
		{
			return TRUE
		}
		
		return FALSE
	}
	
	method SelectTarget()
	{
		if ${HostilePlayers.Get[1](exists)}
		{
			This:Debug["Target ${This.HostilePlayers.Get[1].GUID}"]
			Target ${This.HostilePlayers.Get[1].Data.GUID}
		}	
	}
	
	/*
	 *
	 */
	
	member State()
	{
		if ${This.NeedSweep}
		{
			return RADAR_SWEEP
		}
		return RADAR_NONE
	}

	method Pulse(int Priority)
	{
		This.CurrentState:Set[${This.State}]

		switch ${This.CurrentState}
		{
			case RADAR_SWEEP
				This:Sweep
				break
			case RADAR_NONE
				break
		}
	}

	method Plugin()
	{
		Event[CORE_EVENT_PULSE]:AttachAtom[${This.ObjectName}:Pulse]
		LavishScript:RegisterEvent[RADAR_EVENT_SWEEP]
		LavishScript:RegisterEvent[RADAR_EVENT_HOSTILEPLAYERSUPDATED]
		LavishScript:RegisterEvent[RADAR_EVENT_FRIENDLYPLAYERSUPDATED]
	}
	
	method Initialize()
	{
		This.LastSweep:Set[${LavishScript.RunningTime}]
	}
	
	method Shutdown()
	{
		Event[CORE_EVENT_PULSE]:DetachAtom[${This.ObjectName}:Pulse]
		Event[RADAR_EVENT_SWEEP]:Unregister
		Event[RADAR_EVENT_HOSTILEPLAYERSUPDATED]:Unregister
		Event[RADAR_EVENT_FRIENDLYPLAYERSUPDATED]:Unregister
	}
	
}