summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XSuperRiskMap.cs
blob: ac8d8408b9c503c2f8c3f1589a2293fdf0485f7f (plain)
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
using System;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XSuperRiskMap
	{
		public XSuperRiskMapStaticInfo StaticInfo;

		public XSuperRiskMapDynamicInfo DynamicInfo;

		public Coordinate PlayerCoord;

		public Direction PlayerMoveDirection;

		public XSuperRiskMapRenderer renderer = new XSuperRiskMapRenderer();

		public void Clear()
		{
			this.StaticInfo = null;
			this.DynamicInfo = null;
			this.PlayerCoord = Coordinate.Invalid;
			this.PlayerMoveDirection = Direction.Up;
		}

		public Direction StartMoveNext(ref Coordinate targetCoord)
		{
			this.PlayerMoveDirection = this.GetNextTryDirection(this.PlayerMoveDirection, 3);
			for (int i = 0; i < 4; i++)
			{
				Coordinate coordinate = this.GoWithDirection(this.PlayerCoord, this.PlayerMoveDirection);
				bool flag = this.StaticInfo.FindMapNode(coordinate) != null;
				if (flag)
				{
					targetCoord = coordinate;
					break;
				}
				this.PlayerMoveDirection = this.GetNextTryDirection(this.PlayerMoveDirection, 1);
			}
			return this.PlayerMoveDirection;
		}

		protected Direction GetNextTryDirection(Direction dir, int offset)
		{
			return (Direction)((XFastEnumIntEqualityComparer<Direction>.ToInt(dir) + offset) % 4);
		}

		public void MoveNext()
		{
			this.PlayerCoord = this.GoWithDirection(this.PlayerCoord, this.PlayerMoveDirection);
			bool flag = this.StaticInfo.FindMapNode(this.PlayerCoord) == null;
			if (flag)
			{
				XSingleton<XDebug>.singleton.AddErrorLog("SuperRisk: why do I go to a null place??", null, null, null, null, null);
			}
		}

		protected Coordinate GoWithDirection(Coordinate c, Direction dir)
		{
			Coordinate result;
			switch (dir)
			{
			case Direction.Right:
				result = new Coordinate(c.x + 1, c.y);
				break;
			case Direction.Down:
				result = new Coordinate(c.x, c.y + 1);
				break;
			case Direction.Left:
				result = new Coordinate(c.x - 1, c.y);
				break;
			case Direction.Up:
				result = new Coordinate(c.x, c.y - 1);
				break;
			default:
				result = new Coordinate(-1, -1);
				break;
			}
			return result;
		}

		public bool GetNodeGroup(Coordinate c, out char group)
		{
			XSuperRiskMapNode xsuperRiskMapNode = this.StaticInfo.FindMapNode(c);
			bool flag = xsuperRiskMapNode != null;
			bool result;
			if (flag)
			{
				group = xsuperRiskMapNode.group;
				result = true;
			}
			else
			{
				group = ' ';
				result = false;
			}
			return result;
		}
	}
}