Beispiel #1
0
        public void OnMove(HexXY from, HexXY to, bool isDrawing)
        {
            EnsurePrevMoveFinished();

            if (!WorldBlock.CanTryToMoveToBlockType(Level.S.GetPFBlockedMap(to)))
            {
                avatar.finishState = Avatar.FinishedState.CantMoveThere;
                return;
            }

            if (!isDrawing)
            {
                if (!avatar.spell.caster.SpendMana(1))
                {
                    avatar.finishState = Avatar.FinishedState.NoManaLeft;
                    return;
                }
            }
            else
            {
                if (!avatar.spell.caster.SpendMana(5))
                {
                    avatar.finishState = Avatar.FinishedState.NoManaLeft;
                    return;
                }
            }

            this.isDrawing = isDrawing;

            Interfacing.PerformInterfaceMove(graphicsHandle, to, movTime);
            movTimeLeft = movTime * 0.75f; //TODO: this is point in time when avatar element entity changes pos
            movPos      = to;
        }
Beispiel #2
0
 public void OnMove(HexXY from, HexXY to, bool isDrawing)
 {
     if (!WorldBlock.CanTryToMoveToBlockType(Level.S.GetPFBlockedMap(to)))
     {
         avatar.finishState = Avatar.FinishedState.CantMoveThere;
     }
     else
     {
         Interfacing.PerformInterfaceMove(graphicsHandle, to, movTime);
         movTimeLeft = movTime * 0.75f; //TODO: this is point in time when avatar changes pos
     }
 }
Beispiel #3
0
        public bool OnUpdate(float dt)
        {
            if (onTileCenter && shouldRecalcPath)
            {
                var pathLen = Pathfinder.FindPath(entity.pos, dest.Value, pathStorage, distToStop, blockedCost);
                //Logger.Log(pathLen.ToString());
                pathStart        = 0;
                shouldRecalcPath = false;
                isWalkBlocked    = false;

                if (!pathLen.HasValue || pathLen.Value == 0)
                {
                    pathEnd = 0;
                    if (isWalking)
                    {
                        Interfacing.PerformInterfaceStop(entity.graphicsHandle, entity.pos);
                        isWalking = false;
                    }
                    return(true);
                }


                pathEnd = pathLen.Value;
            }

            if (pathStart == pathEnd)
            {
                return(true);
            }
            var nextTile = pathStorage[pathStart];

            if (distToNextTile > 0.5)
            {
                entity.pos = prevTile;
            }
            else
            {
                entity.pos = nextTile;
            }

            if (onTileCenter)
            {
                if (Level.S.GetPFBlockedMap(nextTile) == WorldBlock.PFBlockType.DynamicBlocked)
                {
                    if (!isWalkBlocked)
                    {
                        isWalkBlocked   = true;
                        walkBlockedTime = 0;
                        isWalking       = false;
                        Interfacing.PerformInterfaceStop(entity.graphicsHandle, entity.pos);
                    }
                    walkBlockedTime += dt;
                    return(true);
                }
                isWalkBlocked = false;
                Level.S.SetPFBlockedMap(nextTile, WorldBlock.PFBlockType.DynamicBlocked);
                Level.S.SetPFBlockedMap(prevTile, WorldBlock.PFBlockType.Unblocked);
                pfBlockedTile = nextTile;

                Interfacing.PerformInterfaceMove(entity.graphicsHandle, nextTile, distToNextTile * invSpeed);
                isWalking = true;
            }

            float timeLeft = distToNextTile * invSpeed;

            if (timeLeft > dt)
            {
                distToNextTile -= dt * speed;
                onTileCenter    = false;
            }
            else
            {
                prevTile       = nextTile;
                distToNextTile = 1;
                onTileCenter   = true;
                ++pathStart;

                if (pathEnd - pathStart > 0)
                {
                    OnUpdate(dt - timeLeft);
                }
                else
                {
                    Interfacing.PerformInterfaceStop(entity.graphicsHandle, prevTile);
                    isWalking = false;
                }
            }

            return(true);
        }