示例#1
0
        public void AppendHandleMove(Creature creature, Position newPos, Direction direction, bool validateMove)
        {
            lock (lockThis) {
                Position oldPos = creature.CurrentPosition;
                Tile oldTile = gameMap.GetTile(oldPos);
                Tile newTile = gameMap.GetTile(newPos);
                if (validateMove) {
                    if (newTile == null || newTile.ContainsType(Constants.TYPE_BLOCKING)) {
                        return;
                    }
                }

                foreach (Thing thing in oldTile.GetThings()) {
                    bool proceed = thing.HandleWalkAction(creature, this, WalkType.WALK_OFF);
                    if (!proceed) {
                        return;
                    }
                }
                foreach (Thing thing in newTile.GetThings()) {
                    bool proceed = thing.HandleWalkAction(creature, this, WalkType.WALK_ON);
                    if (!proceed) {
                        return;
                    }
                }

                if (creature.IsNextTo(newPos)) {
                    //TODO: Finish coding speed
                    int speed = GetGroundSpeed(creature.CurrentPosition);
                    int duration = (100 * 90 /*speed*/) / (creature.GetSpeed());
                    creature.LastWalk.SetTimeInCS((uint)duration);

                    if (!creature.LastWalk.Elapsed()) {
                        return;
                    }

                    Position oldPosClone = oldPos.Clone();
                    if (oldPos.y > newPos.y) {
                        direction = Direction.NORTH;
                        oldPosClone.y--;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    } else if (oldPos.y < newPos.y) {
                        direction = Direction.SOUTH;
                        oldPosClone.y++;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    }
                    if (oldPos.x < newPos.x) {
                        direction = Direction.EAST;
                        oldPosClone.x++;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    } else if (oldPos.x > newPos.x) {
                        direction = Direction.WEST;
                        oldPosClone.x--;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    }
                }
                ThingSet tSet = gameMap.GetThingsInVicinity(creature.CurrentPosition);
                byte oldStackPos = gameMap.GetStackPosition(creature, oldPos);
                gameMap.MoveThing(creature, oldPos, newPos);
                creature.CurrentDirection = direction;
                byte newStackPos = gameMap.GetStackPosition(creature, newPos);
                gameMap.GetThingsInVicinity(newPos, tSet);
                creature.HandleMove();

                foreach (Thing thing in tSet.GetThings()) {
                    thing.AddCreatureMove(direction, creature, oldPos, newPos,
                        oldStackPos, newStackPos);
                }

                if (!creature.IsNextTo(oldPos)) {
                    creature.AddTeleport(gameMap);
                }
            }
        }