File size: 4,446 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// This will be used to parse and load contaminated area related data
class EffectAreaLoader
{
	private static string m_Path = "$mission:cfgeffectarea.json";
	
	static void CreateZones()
	{
		JsonDataContaminatedAreas effectAreaData;
		
		// We confirm the contaminated area configuration file exists in mission folder
		if ( !FileExist( m_Path ) )
		{
			// We fallback to check in data and notify user file was not found in mission
			PrintToRPT("[WARNING] :: [EffectAreaLoader CreateZones] :: No contaminated area file found in MISSION folder, your path is " + m_Path + " Attempting DATA folder"); // If the path is invalid, we warn the user
			
			m_Path = "";
			GetGame().GetWorldName( m_Path );
			m_Path = string.Format("dz/worlds/%1/ce/cfgeffectarea.json", m_Path );
			
			if ( !FileExist( m_Path ) )
			{
				PrintToRPT("[WARNING] :: [EffectAreaLoader CreateZones] :: No contaminated area file found in DATA folder, your path is " + m_Path); // If the path is invalid, we warn the user
				return; // Nothing could be read, just end here
			}
		}
		
		// We load the data from file, in case of failure we notify user
		effectAreaData = EffectAreaLoader.GetData();
		if ( effectAreaData )
		{
			// Now that we have extracted the data we go through every declared area
			//Debug.Log("Contaminated area JSON contains : " + effectAreaData.Areas.Count());
			
			for ( int i = 0; i < effectAreaData.Areas.Count(); i++ )
			{
				EffectAreaParams params = new EffectAreaParams();
				
				// We feed in all relevant data
				params.m_ParamName = effectAreaData.Areas.Get( i ).AreaName;
				string areaType = effectAreaData.Areas.Get( i ).Type;
				params.m_ParamTriggerType = effectAreaData.Areas.Get( i ).TriggerType;
				JsonDataAreaData data = effectAreaData.Areas.Get( i ).Data;
				
				// World level area data ( Trigger info, world particles, etc... )
				vector pos = Vector( data.Pos[0], data.Pos[1], data.Pos[2] );
				params.m_ParamRadius = data.Radius;
				params.m_ParamPosHeight = data.PosHeight;
				params.m_ParamNegHeight = data.NegHeight;
				params.m_ParamInnerRings = data.InnerRingCount;
				params.m_ParamInnerSpace = data.InnerPartDist;
				params.m_ParamOuterToggle = data.OuterRingToggle;
				params.m_ParamOuterSpace = data.OuterPartDist;
				params.m_ParamOuterOffset = data.OuterOffset;
				params.m_ParamVertLayers = data.VerticalLayers;
				params.m_ParamVerticalOffset = data.VerticalOffset;
				string particleName = data.ParticleName;
				
				// Local level area data ( Player particles and PPE )
				JsonDataPlayerData playerData = effectAreaData.Areas.Get( i ).PlayerData;
				string aroundPartName = playerData.AroundPartName;
				string tinyPartName = playerData.TinyPartName;
				string ppeRequesterType = playerData.PPERequesterType;
				
				// Conversion of particle name to ID for synchronization and loading
				if (particleName != "")
					params.m_ParamPartId = ParticleList.GetParticleID( particleName );
				
				if (aroundPartName != "")
					params.m_ParamAroundPartId = ParticleList.GetParticleID( aroundPartName );
				
				if (tinyPartName != "")
					params.m_ParamTinyPartId = ParticleList.GetParticleID( tinyPartName );
				
				params.m_ParamPpeRequesterType = ppeRequesterType;

				EffectArea newZone; // Zones MUST inherit from EffectArea
				
				// We snap item position to ground before creating if specified Y is 0
				if ( pos[1] == 0 )
				{
					pos[1] = GetGame().SurfaceRoadY( pos[0], pos[2] );
					Class.CastTo( newZone, GetGame().CreateObjectEx( areaType, pos, ECE_PLACE_ON_SURFACE ) );
				}
				else
					Class.CastTo( newZone, GetGame().CreateObjectEx( areaType, pos, ECE_NONE ) );
				
				// We created a new zone, we feed in the data to finalize setup
				if ( newZone )
					newZone.SetupZoneData( params );
				else
					Error("[WARNING] :: [EffectAreaLoader CreateZones] :: Cast failed, are you sure your class ( 'Type:' ) inherits from EffectArea and that there are no Typos?");
			}
		}
		else
			Error("[WARNING] :: [EffectAreaLoader CreateZones] :: Data could not be read, please check data and syntax"); // Most JSON related errors should be handled, but we have an extra check in case data could not be read
	}
	
	static JsonDataContaminatedAreas GetData()
	{
		string errorMessage;
		JsonDataContaminatedAreas data;
		if (!JsonFileLoader<JsonDataContaminatedAreas>.LoadFile(m_Path, data, errorMessage))
			ErrorEx(errorMessage);
		
		return data;
	}
}