All pastes #382361 Raw Edit

Untitled

public text v1 · immutable
·published 2007-03-05 15:56 UTC
rendered paste body
;
;(02:35:04) |                           Lax| uh no, you just have to design interzone travel properly
;(02:36:44) |                           Lax| abstract zone connections by connecting them directly. to move from zone a to zone b, select the path in the zone connection map, and execute the path.
;(02:37:08) |                           Lax| you will know which zones to load by following the connections when iterating the path
;(02:37:47) |                           Lax| to move through 3 zones, you could load zones 1 and 2 to get to 2, then 2 and 3 to get to 3
;

#define MAPPER_NONE 0
#define MAPPER_MAP 1

objectdef oMapper inherits oBase
{
	variable lnavregionref CurrentZone
	variable lnavregionref CurrentSubZone
	variable lnavregionref CurrentPoint
	variable lnavregionref PreviousZone
	variable point3f CurrentLocation
	variable int CurrentPointDistance = 1
	variable int LastPOIScan = ${LavishScript.RunningTime}
	
        member SubZoneText()
        {
                return ${WoWScript[GetMinimapZoneText()]}
        }

        member ZoneText()
        {
                return ${WoWScript[GetRealZoneText()]}
        }

        member Continent()
        {
                WoWScript SetMapToCurrentZone()
		if ${WoWScript[GetMapContinents(),${WoWScript[GetCurrentMapContinent()]}](exists)}
		{
			return ${WoWScript[GetMapContinents(),${WoWScript[GetCurrentMapContinent()]}]}
		}
        }

        method InitializeRegions()
        {
                variable string Continent
                variable int IdxContinent
                variable string Zone
                variable int IdxZone

                if ${LNavRegion[Azeroth](exists)}
                {
                        LNavRegion[Azeroth]:Remove
                }
                LavishNav.Tree:AddChild[universe,Azeroth,-unique]

                IdxContinent:Set[1]
                do
                {
                        Continent:Set[${WoWScript[GetMapContinents(),${IdxContinent}]}]
                        LNavRegion[Azeroth]:AddChild[universe,${Continent},-unique,-coordinatesystem]
                        IdxZone:Set[1]
                        do
                        {
                                Zone:Set[${WoWScript[GetMapZones(${IdxContinent}),${IdxZone}]}]
                                LNavRegion[${Continent}]:AddChild[universe,${Zone},-unique]
                                IdxZone:Inc
                        }
                        while ${WoWScript[GetMapZones(${IdxContinent}),${IdxZone}](exists)}
                        IdxContinent:Inc
                }
                while ${WoWScript[GetMapContinents(),${IdxContinent}](exists)}
        }

        method Save()
        {
		variable lnavregionref CurrentContinent
		variable lnavregionref CurrentZone

		if ${LNavRegion[Azeroth].Children(exists)}
		{
			CurrentContinent:SetRegion[${LNavRegion[Azeroth].Children}]
			do
			{
				if ${CurrentContinent.Children(exists)}
				{
					CurrentZone:SetRegion[${CurrentContinent.Children}]
					do
					{
						if ${CurrentZone.ChildCount} > 0
						{
							CurrentZone:ExportChildren[-lso,"map/${CurrentContinent.Name}.${CurrentZone.Name}.lso"]
						}
						CurrentZone:SetRegion[${CurrentZone.Next}]
					}
					while ${CurrentZone.Region(exists)}
				}
				CurrentContinent:SetRegion[${CurrentContinent.Next}]
			}
			while ${CurrentContinent.Region(exists)}
		}
        }

	member CollisionTest(float FromX, float FromY, float FromZ, float ToX, float ToY, float ToZ)
	{
		return ${Me.IsPathObstructed[${ToX},${ToY},${ToZ},999,${FromX}, ${FromY}, ${FromZ}]}
	}

	member PointDistance()
	{
		variable int Count = 1
		variable float X1 = ${Me.X}
		variable float Y1 = ${Me.Y}
		variable float Z1 = ${Math.Calc[${Me.Z} + 0.3]}

		variable float X2 = ${Me.X}
		variable float Y2 = ${Me.Y}
		variable float Z2 = ${Math.Calc[${Me.Z} + 0.3]}

		if ${Math.Distance[${Me.Location},${This.CurrentLocation}]} < 0.9
		{
			return ${This.CurrentPointDistance}
		}

		This.CurrentLocation.X:Set[${Me.X}]
		This.CurrentLocation.X:Set[${Me.Y}]
		This.CurrentLocation.X:Set[${Me.Z}]
		
		do
		{
			X1:Dec
			Y1:Dec
			X2:Inc
			Y2:Inc
			X1:Dec
			Y1:Dec
			X2:Inc
			Y2:Inc

			if ${This.CollisionTest[${X1},${Y1},${Z1},${X2},${Y1},${Z2}]}
			{
				This.CurrentPointDistance:Set[${Count}]
				return ${Count}
			}

			if ${This.CollisionTest[${X1},${Y2},${Z1},${X2},${Y2},${Z2}]}
			{
				This.CurrentPointDistance:Set[${Count}]
				return ${Count}
			}

			if ${This.CollisionTest[${X1},${Y1},${Z1},${X1},${Y2},${Z2}]}
			{
				This.CurrentPointDistance:Set[${Count}]
				return ${Count}
			}

			if ${This.CollisionTest[${X2},${Y1},${Z1},${X2},${Y2},${Z2}]}
			{
				This.CurrentPointDistance:Set[${Count}]
				return ${Count}
			}
			
			Count:Inc
		}
		while ${Count} <= 10
			
		This.CurrentPointDistance:Set[10]
		return 10
	}
	
        method Load(string Continent, string ZoneName)
        {
                variable filepath Dir = "map/"
		variable lnavregionref ZoneRef
		ZoneRef:SetRegion[${ZoneName}]

                if ${Dir.FileExists["${Continent}.${ZoneRef.Name}.lso"]}
                {
			ZoneRef:Import[-lso,"map/${Continent}.${ZoneRef.Name}.lso"]
			This:Echo["Importing file: ${Continent}.${ZoneRef.Name}.lso"]
                }
		elseif  ${Dir.FileExists["${Continent}.${ZoneRef.Name}.xml"]}
		{
			ZoneRef:Import["map/${Continent}.${ZoneRef.Name}.xml"]
			This:Echo["Importing old file: ${Continent}.${ZoneRef.Name}.xml"]
		}		
        }
	
	
	method MinimapZoneChanged()
	{
		if !${LNavRegion["${This.SubZoneText}.${This.CurrentZone.Name}"](exists)}
		{
			This.CurrentZone:AddChild[universe,"${This.SubZoneText}"]
		}
		This.CurrentSubZone:SetRegion["${This.SubZoneText}.${This.CurrentZone.Name}"]
		This:Echo["Subzone changed to: ${This.SubZoneText}.${This.CurrentZone.Name}"]
	}
	
	method ZoneChanged()
	{
		if !${LNavRegion[${This.ZoneText}](exists)}
		{
			LNavRegion[${This.Continent}]:AddChild[universe,${This.ZoneText},-unique]
		}

		;Connect zones to each other for automatic loading by iteration
		if ${This.CurrentZone.ID(exists)}
		{
			This.PreviousZone:SetRegion[${This.CurrentZone.FQN}]
			LNavRegion[${This.ZoneText}]:Connect[${This.PreviousZone.FQN}]
			This.PreviousZone:Connect[${LNavRegion[${This.ZoneText}].FQN}]
			This:Debug["Connecting zone: ${LNavRegion[${This.ZoneText}].FQN} to: ${This.PreviousZone.FQN}"]
		}
		
		This.CurrentZone:SetRegion[${LNavRegion[${This.ZoneText}].FQN}]
		This:Load[${This.Continent},${This.CurrentZone.Name}]
		This:Save
		This:Echo["Zone changed to: ${LNavRegion[${This.ZoneText}].FQN}"]
		This:MinimapZoneChanged
	}
	
	method Map()
	{
		variable string RegionName = ""
		variable int Connections = 0
		variable index:lnavregionref Regions
		variable lnavregionref NewRegion
		variable lnavregionref DestRegion
		variable int Idx = 1
		
		RegionName:Set["P${This.CurrentSubZone.ChildCount}"]
		This.CurrentSubZone:AddChild[point,${RegionName},${Me.X},${Me.Y},${Me.Z}]
		NewRegion:SetRegion["${RegionName}.${This.CurrentSubZone.Name}.${This.CurrentZone.Name}"]
		
		if ${This.CurrentPoint.FQN(exists)}
		{
			if ${Math.Distance[${NewRegion.CenterPoint},${This.CurrentPoint.CenterPoint}]} < 20
			{
				Connections:Inc
				NewRegion:Connect[${This.CurrentPoint.FQN}]
				This.CurrentPoint:Connect[${NewRegion.FQN}]
			}
		}
		This.CurrentPoint:SetRegion[${NewRegion.FQN}]
		
		if ${This.CurrentZone.DescendantsWithin[Regions,20,${Me.X},${Me.Y},${Me.Z}]}
		{
			do
			{
				DestRegion:SetRegion[${Regions.Get[${Idx}].FQN}]
				if !${Me.IsPathObstructed[${DestRegion.CenterPoint.X},${DestRegion.CenterPoint.Y},${Math.Calc[${DestRegion.CenterPoint.Z} + 0.3]},999,${Me.X},${Me.Y},${Math.Calc[${Me.Z} + 0.3]}]} && ${NewRegion.ID} != ${DestRegion.ID}
				{
					NewRegion:Connect[${DestRegion.FQN}]
					DestRegion:Connect[${NewRegion.FQN}]
					Connections:Inc
				}
			}
			while ${Idx:Inc} <= ${Regions.Used}
		}
		
		This:Echo["Added ${NewRegion.FQN} (${Connections} connections)"]
	}
	
	member NeedPoint()
	{
		variable int PointCount
		variable index:lnavregionref Regions
		
		if !${Me(exists)} || ${Me.Flying}
		{
			return FALSE
		}

		PointCount:Set[${This.CurrentZone.DescendantsWithin[Regions,${Math.Calc[${This.PointDistance} + 1]},${Me.X},${Me.Y},${Me.Z}]}]
		if ${PointCount} > 0
		{
			return FALSE
		}
		
		return TRUE
	}

	/*
	 * GUI
	 */
	
	method UpdateGUI()
	{
		variable settingsetref SpotSet
		variable iterator ProfileIterator

		LavishSettings["Profiles"]:GetSetIterator[ProfileIterator]
		UIElement["lstDelete@Roam profiles@Pages@MapperGUI"]:ClearItems
		UIElement["cmbProfiles@Roam spots@Pages@MapperGUI"]:ClearItems
		if ${ProfileIterator:First(exists)}
		{
			do
			{
				UIElement["lstDelete@Roam profiles@Pages@MapperGUI"]:AddItem["${ProfileIterator.Key}"]
				UIElement["cmbProfiles@Roam spots@Pages@MapperGUI"]:AddItem["${ProfileIterator.Key}"]
			}
			while ${ProfileIterator:Next(exists)}
		}
	}
	
	method InitGUI()
	{
                variable string Continent
                variable int IdxContinent
                variable string Zone
                variable int IdxZone
		
		UIElement["edtName@Roam profiles@Pages@MapperGUI"]:SetText["${This.CurrentSubZone.Name} Hunt"]
		UIElement["edtLevelLow@Roam profiles@Pages@MapperGUI"]:SetText["${Me.Level}"]
		UIElement["edtLevelHigh@Roam profiles@Pages@MapperGUI"]:SetText["${Math.Calc[${Me.Level} + 5].Int}"]
		UIElement["edtMaxRoam@Roam profiles@Pages@MapperGUI"]:SetText["200"]
		
                IdxContinent:Set[1]
                do
                {
                        Continent:Set[${WoWScript[GetMapContinents(),${IdxContinent}]}]
                        IdxZone:Set[1]
                        do
                        {
                                Zone:Set[${WoWScript[GetMapZones(${IdxContinent}),${IdxZone}]}]
				UIElement["lstPreLoad@Roam profiles@Pages@MapperGUI"]:AddItem["${Zone}"]
                                IdxZone:Inc
                        }
                        while ${WoWScript[GetMapZones(${IdxContinent}),${IdxZone}](exists)}
                        IdxContinent:Inc
                }
                while ${WoWScript[GetMapContinents(),${IdxContinent}](exists)}
		This:UpdateGUI
	}
	
	method MapperGUIVisible(bool Show)
	{
		if ${Show}
		{
			UIElement[MapperGUI]:Show
		}
		else
		{
			UIElement[MapperGUI]:Hide
		}
	}

	method MapperGUINpc(string Action)
	{
		variable int CurrentIdx = 1
		variable int Total

		switch ${Action}
		{
			case add
				This.CurrentSubZone:AddChild[point,${Target.Name},${Target.X},${Target.Y},${Target.Z}]

				Total:Set[${UIElement[lstFlags@Npc@Pages@MapperGUI].SelectedItems}]
				if ${Total}
				{
					do
					{
						LNavRegionGroup["${UIElement[lstFlags@Npc@Pages@MapperGUI].SelectedItem[${CurrentIdx}]}"]:Add["${Target.Name}.${This.CurrentSubZone.FQN}"]
					}
					while ${CurrentIdx:Inc} <= ${Total}
				}
				break
			case target
				UIElement["edtName@Npc@Pages@MapperGUI"]:SetText["${Target.Name}"]
				break
		}
	}
	
	method MapperGUISpots(string Action)
	{
		variable int CurrentIdx = 1
		variable int Total
		variable iterator SpotIterator
		variable settingsetref SpotSet

		switch ${Action}
		{
			case add
				SpotSet:Set[${LavishSettings["Profiles"].FindSet["${UIElement[cmbProfiles@Roam spots@Pages@MapperGUI].SelectedItem}"].FindSet["Spots"]}]
				SpotSet:AddSet["${UIElement[edtName@Roam spots@Pages@MapperGUI].Text}"]
				SpotSet.FindSet["${UIElement[edtName@Roam spots@Pages@MapperGUI].Text}"]:AddSetting["x",${Me.X}]
				SpotSet.FindSet["${UIElement[edtName@Roam spots@Pages@MapperGUI].Text}"]:AddSetting["y",${Me.Y}]
				SpotSet.FindSet["${UIElement[edtName@Roam spots@Pages@MapperGUI].Text}"]:AddSetting["z",${Me.Z}]
				This:MapperGUISpots["update"]
				break
			case delete
				Total:Set[${UIElement[lstDelete@Roam spots@Pages@MapperGUI].SelectedItems}]
				if ${Total}
				{
					do
					{
						SpotSet:Set[${LavishSettings["Profiles"].FindSet["${UIElement[cmbProfiles@Roam spots@Pages@MapperGUI].SelectedItem}"].FindSet["Spots"].FindSet["${UIElement[lstDelete@Roam spots@Pages@MapperGUI].SelectedItem[${CurrentIdx}]}"]}]
						SpotSet:Remove
					}
					while ${CurrentIdx:Inc} <= ${Total}
				}
				This:MapperGUISpots["update"]
				break
			case update
				SpotSet:Set[${LavishSettings["Profiles"].FindSet["${UIElement[cmbProfiles@Roam spots@Pages@MapperGUI].SelectedItem}"].FindSet["Spots"]}]
				SpotSet:GetSetIterator[SpotIterator]
				UIElement["lstDelete@Roam spots@Pages@MapperGUI"]:ClearItems
				if ${SpotIterator:First(exists)}
				{
					do
					{
						UIElement["lstDelete@Roam spots@Pages@MapperGUI"]:AddItem["${SpotIterator.Key}"]
					}
					while ${SpotIterator:Next(exists)}
				}
				UIElement["edtName@Roam spots@Pages@MapperGUI"]:SetText["Spot ${UIElement["lstDelete@Roam spots@Pages@MapperGUI"].Items}"]
				break
		}
	}
	
	method MapperGUIProfiles(string Action)
	{
		variable settingsetref ProfileSet
		variable int CurrentIdx = 1
		variable int Total
		
		switch ${Action}
		{
			case add
				LavishSettings["Profiles"]:AddSet["${UIElement[edtName@Roam profiles@Pages@MapperGUI].Text}"]
				ProfileSet:Set[${LavishSettings["Profiles"].FindSet["${UIElement[edtName@Roam profiles@Pages@MapperGUI].Text}"]}]
				ProfileSet:AddSetting["Level low","${UIElement[edtLevelLow@Roam profiles@Pages@MapperGUI].Text}"]
				ProfileSet:AddSetting["Level high","${UIElement[edtLevelHigh@Roam profiles@Pages@MapperGUI].Text}"]
				ProfileSet:AddSetting["Max roam","${UIElement[edtMaxRoam@Roam profiles@Pages@MapperGUI].Text}"]
				ProfileSet:AddSet["Spots"]

				Total:Set[${UIElement[lstPreLoad@Roam profiles@Pages@MapperGUI].SelectedItems}]
				if ${Total}
				{
					ProfileSet:AddSet["PreLoad"]
					do
					{
						ProfileSet.FindSet["PreLoad"]:AddSetting["${UIElement[lstPreLoad@Roam Profiles@Pages@MapperGUI].SelectedItem[${CurrentIdx}]}",1]						
					}
					while ${CurrentIdx:Inc} <= ${Total}
				}

				break
			case delete
				Total:Set[${UIElement[lstDelete@Roam profiles@Pages@MapperGUI].SelectedItems}]
				if ${Total}
				{
					do
					{
						ProfileSet:Set[${LavishSettings["Profiles"].FindSet["${UIElement[lstDelete@Roam Profiles@Pages@MapperGUI].SelectedItem[${CurrentIdx}]}"]}]
						ProfileSet:Remove
					}
					while ${CurrentIdx:Inc} <= ${Total}
				}
				break
		}
		
		This:UpdateGUI
	}
	
	
	/*
	 *
	 */

	member State()
	{
		if ${This.NeedPoint}
		{
			return MAPPER_MAP
		}
		
		return MAPPER_NONE
	}
	 
	method Pulse(int Priority)
	{
		This.CurrentState:Set[${This.State}]
		switch ${This.CurrentState}
		{
			case MAPPER_MAP
				This:Map
				break
			case MAPPER_NONE
				break
		}
	}
	 
	/*
	 *
	 */

	method Plugin()
	{
		This:InitializeRegions
		This:ZoneChanged

		LavishScript:RegisterEvent[MAPPER_GUI_VISIBLE]
		LavishScript:RegisterEvent[MAPPER_GUI_PROFILES]
		LavishScript:RegisterEvent[MAPPER_GUI_SPOTS]
		LavishScript:RegisterEvent[MAPPER_GUI_NPC]
		Event[MAPPER_GUI_VISIBLE]:AttachAtom[${This.ObjectName}:MapperGUIVisible]
		Event[MAPPER_GUI_PROFILES]:AttachAtom[${This.ObjectName}:MapperGUIProfiles]
		Event[MAPPER_GUI_SPOTS]:AttachAtom[${This.ObjectName}:MapperGUISpots]
		Event[MAPPER_GUI_NPC]:AttachAtom[${This.ObjectName}:MapperGUINpc]

		LavishSettings:AddSet["Profiles"]
		LavishSettings["Profiles"]:Clear
		LavishSettings["Profiles"]:Import["etc/profiles.xml"]
		ui -load "gui/mapper.xml"
		This:InitGUI
		
		Event[ZONE_CHANGED_NEW_AREA]:AttachAtom[${This.ObjectName}:ZoneChanged]
		Event[ZONE_CHANGED]:AttachAtom[${This.ObjectName}:MinimapZoneChanged]
		Event[CORE_EVENT_PULSE]:AttachAtom[${This.ObjectName}:Pulse]
	}
	 
	method Shutdown()
	{
		Event[MAPPER_GUI_VISIBLE]:Unregister
		Event[MAPPER_GUI_PROFILES]:Unregister
		Event[MAPPER_GUI_SPOTS]:Unregister
		Event[MAPPER_GUI_NPC]:Unregister

		ui -unload "gui/mapper.xml"
		LavishSettings["Profiles"]:Export["etc/profiles.xml"]
		
		Event[CORE_EVENT_PULSE]:DetachAtom[${This.ObjectName}:Pulse]
		Event[ZONE_CHANGED_NEW_AREA]:DetachAtom[${This.ObjectName}:ZoneChanged]
		Event[ZONE_CHANGED]:DetachAtom[${This.ObjectName}:MinimapZoneChanged]
		This:Save
	}

}