Example #1
0
        private void shortenRoomUnitPath(roomUnit pUnit)
        {
            if (pUnit.Path.Count > 1)
            {
                blisterMoleNode pNode = pUnit.Path[1];

                if (!(Math.Abs(pUnit.X - pNode.X) > 1 || Math.Abs(pUnit.Y - pNode.Y) > 1))
                {
                    if (tileFree(pNode.X, pNode.Y))
                    {
                        int X1 = 0;
                        int X2 = 0;
                        if (pNode.X > pUnit.X)
                        {
                            X1 = -1;
                            X2 = 1;
                        }
                        else
                        {
                            X1 = 1;
                            X2 = -1;
                        }

                        if (tileFree((byte)(pNode.X + X1), pNode.Y) && tileFree((byte)(pUnit.X + X2), pUnit.Y)) // Valid shortcut
                        {
                            pUnit.Path.RemoveAt(0);
                        }
                    }
                }
            }
        }
Example #2
0
        private void moveRoomUnitToTile(roomUnit pUnit, ref blisterMoleNode nextTile)
        {
            // Set next step
            pUnit.nextX = nextTile.X;
            pUnit.nextY = nextTile.Y;
            pUnit.nextZ = this.gridHeight[nextTile.X, nextTile.Y];
            pUnit.Path.Remove(nextTile);

            // Set unit map
            this.gridUnit[pUnit.X, pUnit.Y]         = false;
            this.gridUnit[pUnit.nextX, pUnit.nextY] = true;

            // Calculate new rotation
            pUnit.rotationHead = rotationCalculator.calculateHumanMoveDirection(pUnit.X, pUnit.Y, pUnit.nextX, pUnit.nextY);
            pUnit.rotationBody = pUnit.rotationHead;

            pUnit.requiresUpdate = true;
        }
Example #3
0
        public void enterTeleporter(uint sessionID, int itemID)
        {
            floorItem pItem = this.getFloorItem(itemID);
            if (pItem != null && pItem.Definition.Behaviour.isTeleporter) // Valid item
            {
                roomUser pUser = this.getRoomUser(sessionID);
                if (pItem.Rotation == 2 && !(pUser.X == pItem.X + 1 && pUser.Y == pItem.Y))
                    return; // Invalid position of room user
                if (pItem.Rotation == 4 && !(pUser.X == pItem.X && pUser.Y == pItem.Y + 1))
                    return; // Invalid position of room user

                pUser.Path.Clear();
                blisterMoleNode pNode = new blisterMoleNode();
                pNode.X = pItem.X;
                pNode.Y = pItem.Y;
                pUser.Path.Add(pNode);

                requestStartRoomUnitWalk(pUser.Session.ID, pNode.X, pNode.Y, true);
            }
        }
Example #4
0
        public void enterTeleporter(uint sessionID, int itemID)
        {
            floorItem pItem = this.getFloorItem(itemID);

            if (pItem != null && pItem.Definition.Behaviour.isTeleporter) // Valid item
            {
                roomUser pUser = this.getRoomUser(sessionID);
                if (pItem.Rotation == 2 && !(pUser.X == pItem.X + 1 && pUser.Y == pItem.Y))
                {
                    return; // Invalid position of room user
                }
                if (pItem.Rotation == 4 && !(pUser.X == pItem.X && pUser.Y == pItem.Y + 1))
                {
                    return; // Invalid position of room user
                }
                pUser.Path.Clear();
                blisterMoleNode pNode = new blisterMoleNode();
                pNode.X = pItem.X;
                pNode.Y = pItem.Y;
                pUser.Path.Add(pNode);

                requestStartRoomUnitWalk(pUser.Session.ID, pNode.X, pNode.Y, true);
            }
        }
Example #5
0
        private void moveRoomUnitToTile(roomUnit pUnit, ref blisterMoleNode nextTile)
        {
            // Set next step
            pUnit.nextX = nextTile.X;
            pUnit.nextY = nextTile.Y;
            pUnit.nextZ = this.gridHeight[nextTile.X, nextTile.Y];
            pUnit.Path.Remove(nextTile);

            // Set unit map
            this.gridUnit[pUnit.X, pUnit.Y] = false;
            this.gridUnit[pUnit.nextX, pUnit.nextY] = true;

            // Calculate new rotation
            pUnit.rotationHead = rotationCalculator.calculateHumanMoveDirection(pUnit.X, pUnit.Y, pUnit.nextX, pUnit.nextY);
            pUnit.rotationBody = pUnit.rotationHead;

            pUnit.requiresUpdate = true;
        }
Example #6
0
        private void moveRoomUnit(roomUnit pUnit)
        {
            if (pUnit.Path.Count > 0)
            {
                shortenRoomUnitPath(pUnit); // Cut corners etc
                blisterMoleNode nextTile = pUnit.Path[0];

                bool nextTileNoRoomUnit = !this.gridUnit[nextTile.X, nextTile.Y];
                bool nextTileExists     = this.tileExists(nextTile.X, nextTile.Y);

                if (pUnit.allowOverideNextTile || (nextTileNoRoomUnit && nextTileExists && this.gridState[nextTile.X, nextTile.Y] == roomTileState.Free))
                {
                    moveRoomUnitToTile(pUnit, ref nextTile);
                    pUnit.allowOverideNextTile = false;
                    return;
                }
                else
                {
                    bool workInteractiveTile = false;

                    if (this.gridState[pUnit.goalX, pUnit.goalY] == roomTileState.Interactive)
                    {
                        if (!this.gridUnit[pUnit.goalX, pUnit.goalY])
                        {
                            this.gridState[pUnit.goalX, pUnit.goalY] = roomTileState.Free;
                            workInteractiveTile = true;
                        }
                    }

                    List <blisterMoleNode> Path = this.findShortestPath(pUnit.X, pUnit.Y, pUnit.goalX, pUnit.goalY);
                    if (workInteractiveTile)
                    {
                        this.gridState[pUnit.goalX, pUnit.goalY] = roomTileState.Interactive;
                    }

                    if (Path.Count > 0)
                    {
                        nextTile = Path[0];
                        if (!this.gridUnit[nextTile.X, nextTile.Y] && tileExists(nextTile.X, nextTile.Y))
                        {
                            pUnit.Path = Path;
                            moveRoomUnitToTile(pUnit, ref nextTile);
                            return;
                        }
                    }
                }
            }
            else
            {
                bool workInteractiveTile = false;

                if (this.gridState[pUnit.goalX, pUnit.goalY] == roomTileState.Interactive)
                {
                    if (!this.gridUnit[pUnit.goalX, pUnit.goalY])
                    {
                        this.gridState[pUnit.goalX, pUnit.goalY] = roomTileState.Free;
                        workInteractiveTile = true;
                    }
                }

                List <blisterMoleNode> Path = this.findShortestPath(pUnit.X, pUnit.Y, pUnit.goalX, pUnit.goalY);
                if (workInteractiveTile)
                {
                    this.gridState[pUnit.goalX, pUnit.goalY] = roomTileState.Interactive;
                }

                if (Path.Count > 0)
                {
                    pUnit.Path = Path;
                    unsetRoomUnitTileState(pUnit);
                    moveRoomUnit(pUnit);
                    return;
                }
                setRoomUnitTileState(pUnit);
            }

            // Stop moving
            pUnit.Moves          = false;
            pUnit.nextX          = 0;
            pUnit.nextY          = 0;
            pUnit.nextZ          = 0;
            pUnit.requiresUpdate = false;
        }