From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XSuperRiskMap.cs | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XSuperRiskMap.cs (limited to 'Client/Assets/Scripts/XMainClient/XSuperRiskMap.cs') diff --git a/Client/Assets/Scripts/XMainClient/XSuperRiskMap.cs b/Client/Assets/Scripts/XMainClient/XSuperRiskMap.cs new file mode 100644 index 00000000..ac8d8408 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XSuperRiskMap.cs @@ -0,0 +1,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.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.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; + } + } +} -- cgit v1.1-26-g67d0