/// <summary> /// Gets all the things in the vicinity (as specified in the parameters) /// and adds them to the ThingSet specified in the parameters. /// Note: general vicinity is specified as an 18x14 box w/ the Position /// in the center at x == 6 && y == 7. /// </summary> /// <param name="position">The position for which to get the things /// in Vicinity.</param> /// <param name="tSet">The ThingSet to add all the things gotten in /// the vacanity.</param> /// <param name="leftXOffset">The left offset from the general Vicinity.</param> /// <param name="rightXOffset">The right offset from the general Vicinity.</param> /// <param name="leftYOffset">The left offset from the general Vicinity.</param> /// <param name="rightYOffset">The right offset from the gernal Vicinity</param> /// <param name="noZChange">True if only get things on the same z level or false /// in order to get things on all z levels defined in the general Vicinity.</param> public void GetThingsInVicinity(Position position, ThingSet tSet, int leftXOffset, int rightXOffset, int leftYOffset, int rightYOffset, bool noZChange) { short startZ = 0; short endZ = 0; short zStep = 1; if (noZChange) { startZ = endZ = position.z; } else { GetZIter(ref startZ, ref endZ, ref zStep, position.z); } //Original x: -9, +8, y: -7, +6 for (int x = position.x - 9 - leftXOffset; x <= position.x + 9 + rightXOffset; x++) { for (int y = position.y - 7 - leftYOffset; y <= position.y + 6 + rightYOffset; y++) { for (short z = startZ; z != endZ + zStep; z += zStep) { short offset = (short)(position.z - z); Tile mapTile = GetTile((ushort)(x + offset), (ushort)(y + offset), (byte)(z)); if (mapTile == null) { continue; } mapTile.GetThings(tSet); } } } }
/// <summary> /// Gets the ground speed at the specified position. Note: This /// method is not thread safe. /// Note: The position must be valid in terms of the map. /// </summary> /// <param name="position"></param> /// <returns></returns> public virtual int GetGroundSpeed(Position position) { Tile tile = gameMap.GetTile(position); Item item = (Item)tile.GetThings()[0]; //TODO: Fix downcast return(item.Speed); }
/// <summary> /// Adds a single map tile. /// </summary> /// <param name="tile">Maptile to add.</param> /// <param name="player">Player for whom the map tile is being added.</param> private void AddMapTile(Tile tile, Player player) { if (tile != null) { foreach (Thing t in tile.GetThings()) { t.AddItself(this, player); } } }
/// <summary> /// Adds a single map tile. /// </summary> /// <param name="tile">Maptile to add.</param> /// <param name="player">Player for whom the map tile is being added.</param> private void AddMapTile(Tile tile, Player player) { if (tile != null) { foreach (Thing t in tile.GetThings()) { t.AddItself(this, player); } } netmsg.AddByte(0xFF); //End of maptile byte }
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); } } }