/// <summary> /// Gets whether the tile at the specified position contains /// any thing that is of the specified type. /// </summary> /// <param name="pos">The position to check.</param> /// <param name="type">The type to check.</param> /// <returns>True if tile contains such a type, false otherwise.</returns> public bool TileContainsType(Position pos, uint type) { Tile tile = GetTile(pos); if (tile == null) { return(false); } return(tile.ContainsType(type)); }
/// <summary> /// Todo: Finish code. /// </summary> /// <returns></returns> public bool CanSpawn() { if (!Monster.ExistsMonster(MonsterName)) { return(false); } Position pos = new Position(CenterX, CenterY, CenterZ); Map map = world.GetGameMap(); Tile tile = map.GetTile(pos); if (tile == null || tile.ContainsType(Constants.TYPE_BLOCKS_AUTO_WALK)) { return(false); } return(true); }
/// <summary> /// Use this method cast the specified spell. Note: This method only /// appends and does not send protocol data. /// </summary> /// <param name="caster">The creature casting the spell</param> /// <param name="spell">The spell to cast</param> /// <param name="tSet">The set of affected things</param> public void CastSpell(string msg, Creature caster, Spell spell, GameWorld world) { /*string error = caster.CanCastSpell(spell); * if (error != null) { * caster.AddAnonymousChat(ChatAnonymous.WHITE, error); * return; * }*///TODO: Uncomment if (spell.IsSpellValid != null && !spell.IsSpellValid(world, msg)) { world.AddMagicEffect(MagicEffect.PUFF, caster.CurrentPosition); return; } if (spell.RequiresTarget) { Tile tile = map.GetTile(spell.SpellCenter); if (tile == null || !tile.ContainsType(Constants.TYPE_CREATURE)) { world.AddMagicEffect(MagicEffect.PUFF, caster.CurrentPosition); caster.AddAnonymousChat(ChatAnonymous.WHITE, "No target selected."); return; } } //Constants. //Not the most efficient method but it is simple and works. int length = spell.SpellArea.GetLength(0); int width = spell.SpellArea.GetLength(1); Position startPos = new Position(); startPos.x = (ushort)(spell.SpellCenter.x - (width / 2)); startPos.y = (ushort)(spell.SpellCenter.y - (length / 2)); startPos.z = spell.SpellCenter.z; Position local = new Position(); List <Thing> things = new List <Thing>(); for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) { local.x = (ushort)(startPos.x + j); local.y = (ushort)(startPos.y + i); local.z = startPos.z; if (map.GetTile(local) == null /*|| !map.GetTile(local).CanMoveTo(caster) * TODO: Finish*/) { continue; } if (spell.SpellArea[i, j] && !map.GetTile(local).ContainsType(Constants.TYPE_BLOCKS_MAGIC)) { ThingSet tSet = map.GetThingsInVicinity(local); foreach (Thing thing in tSet.GetThings()) { thing.AddEffect(spell.SpellEffect, local); if (spell.HasDistanceType()) { thing.AddShootEffect((byte)spell.DistanceEffect, caster.CurrentPosition, spell.SpellCenter); } } List <Thing> localThings = map.GetTile(local).GetThings(); if (spell.Action != null) { spell.Action.Invoke(world, local, localThings); } foreach (Thing thing in map.GetTile(local).GetThings()) { things.Add(thing); } } } } foreach (Thing thing in things) { thing.AppendHandleDamage(spell.GetDamage(), caster, spell.Immunity, world, true); } //caster.NotifyOfSuccessfulCast(spell); TODO: Uncomment }
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); } } }