Beispiel #1
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;
        }
Beispiel #2
0
 private void unsetRoomUnitTileState(roomUnit pUnit)
 {
     if (this.gridState[pUnit.X, pUnit.Y] == roomTileState.Interactive)
     {
         List<floorItem> Items = this.getFloorItems(pUnit.X, pUnit.Y);
         foreach (floorItem lItem in Items)
         {
             if (lItem.Definition.Behaviour.canSitOnTop) // User was seated, remove sit animation and reset height
             {
                 pUnit.removeStatus("sit");
                 pUnit.Z = this.gridHeight[pUnit.X, pUnit.Y];
             }
         }
     }
 }
Beispiel #3
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);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private void setRoomUnitTileState(roomUnit pUnit)
        {
            pUnit.removeStatus("sit");
            pUnit.removeStatus("lay");

            List<floorItem> tileItems = this.getFloorItems(pUnit.X, pUnit.Y);
            foreach (Items.floorItem lItem in tileItems)
            {
                if (lItem.Definition.Behaviour.canSitOnTop)
                {
                    pUnit.Z = lItem.Z;
                    pUnit.rotationHead = lItem.Rotation;
                    pUnit.rotationBody = lItem.Rotation;

                    pUnit.removeStatus("dance");
                    pUnit.addStatus("sit", "sit", stringFunctions.formatFloatForClient(lItem.Definition.topHeight), 0, null, 0, 0);
                }
                else if (lItem.Definition.Behaviour.canLayOnTop)
                {
                    //pUnit.X = lItem.X;
                    //pUnit.Y = lItem.Y;
                    pUnit.Z = lItem.Z;
                    pUnit.rotationBody = lItem.Rotation;
                    pUnit.rotationHead = lItem.Rotation;

                    pUnit.removeStatus("dance");
                    pUnit.removeStatus("handitem");
                    pUnit.addStatus("lay", "lay", stringFunctions.formatFloatForClient(lItem.Definition.topHeight) + " null", 0, null, 0, 0);
                }
            }
        }
Beispiel #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;
        }
Beispiel #6
0
        public void animateTalkingUnit(roomUnit pUnit, ref string Text, bool applyEmotes)
        {
            string[] Words = Text.Split(' ');
            string Gesture = null;

            if (applyEmotes)
            {
                foreach (string Word in Words)
                {
                    if (Gesture != null)
                        break;

                    switch (Word.ToLower())
                    {
                        case ":)":
                        case ":-)":
                        case ":d":
                        case ":-d":
                        case ":p":
                        case ":-p":
                        case ";)":
                        case ";-)":
                            Gesture = "sml";
                            break;

                        case ":o":
                            Gesture = "srp";
                            break;

                        case ":s":
                        case ":-s":
                        case ":(":
                        case ":-(":
                        case ":'(":
                        case ":'-(":
                            Gesture = "sad";
                            break;

                        case ":@":
                        case ">:(":
                        case ">:-(":
                            Gesture = "agr";
                            break;
                    }
                }
            }

            int wordAmount = Words.Length;
            if (Gesture != null)
            {
                pUnit.addStatus("gest", "gest", Gesture, 5, null, 0, 0);
                if (wordAmount == 1) // Only word is the gesture emote
                    return;
            }

            int speakSecs = 1;
            if (wordAmount > 1)
                speakSecs = wordAmount / 2;
            else if (wordAmount > 5)
                speakSecs = 5;

            pUnit.addStatus("talk", "talk", null, speakSecs, null, 0, 0);
        }