/// <summary> /// Given an old position and a direction, this method returns /// a new position based on that direction. /// </summary> /// <param name="oldPos">The old position.</param> /// <param name="direction">The direction to move.</param> /// <returns>The new position.</returns> public static Position GetNewPosition(Position oldPos, Direction direction) { Position pos = oldPos.Clone(); switch (direction) { case Direction.NORTH: pos.y--; break; case Direction.EAST: pos.x++; break; case Direction.SOUTH: pos.y++; break; case Direction.WEST: pos.x--; break; default: Log.WriteLine("Unknown direction: " + direction); break; } return pos; }
public virtual void HandleChat(Creature creature, string msg) { lock (lockThis) { if (Command.IsCommand(msg, creature)) { Command.ExecuteCommand(this, gameMap, msg, creature); return; } chatSystem.HandleChat(creature, msg); if (msg == "test") //TODO: REMOVE PLX { HandleCreatureTarget(creature, creature); } else if (msg == "magic") { ((Player)creature).AppendAddManaSpent(10000); } else if (msg == "combat") { for (int i = 0; i < 1000; i++) { ((Player)creature).NotifyOfAttack(); creature.AddDamage(0, creature, false); } } else if (msg == "distance") { ((Player)creature).buggabugga(); } else if (msg == "shooteffect") { Position orig = creature.CurrentPosition; Position dest = orig.Clone(); dest.x += 4; dest.y += 2; creature.AddShootEffect((byte)DistanceType.EFFECT_ENERGY, orig, dest); SendProtocolMessages(); } else if (msg == "a") { ((Player)creature).add(); } else if (msg == "b") { ((Player)creature).remove(); } else if (msg == "!dragon") { } else if (msg == "monster") { List <Monster> monsterList = new List <Monster>(); // m.SetMaster(creature); //SendAddCreature(m, gameMap.GetFreePosition(creature.CurrentPosition, m)); //SendProtocolMessages(); return; //return; } else if (msg == "dead") { ThingSet ttSet = gameMap.GetThingsInVicinity(creature.CurrentPosition); AppendAddDamage(creature, creature, creature.CurrentHP, ImmunityType.IMMUNE_PHYSICAL, true); } else if (msg == "!up") { Position newPos = creature.CurrentPosition.Clone(); newPos.z--; //Z goes down as player goes up :D HandleMove(creature, newPos, creature.CurrentDirection); return; } else if (msg == "!down") { Position newPos = creature.CurrentPosition.Clone(); newPos.z++; HandleMove(creature, newPos, creature.CurrentDirection); return; } else if (msg == "!lighthack") { creature.SpellLightLevel = 10; creature.UpdateCreatureLight(creature); } else if (msg == "burn") { creature.Burning = new int[] { 10, 10, 10 }; creature.BurningCheck = new BurningCheck(); creature.BurningCheck.TimeInCS = 200; creature.BurningCheck.World = this; creature.BurningCheck.CurrentCreature = creature; AddEventInCS(creature.BurningCheck.TimeInCS, creature.BurningCheck.PerformCheck); } else if (msg == "position") { creature.AddAnonymousChat(ChatAnonymous.WHITE, "Your position: " + creature.CurrentPosition); } else if (msg == "knight") { ((Player)creature).CurrentVocation = Vocation.KNIGHT; } else if (msg == "sorcerer") { ((Player)creature).CurrentVocation = Vocation.SORCERER; } else if (msg == "druid") { ((Player)creature).CurrentVocation = Vocation.DRUID; } else if (msg == "paladin") { ((Player)creature).CurrentVocation = Vocation.PALADIN; } else if (msg == "hudini") { creature.CharType++; SendUpdateOutfit(creature); return; } else if (msg == "resetoutfit") { creature.CharType = 1; SendUpdateOutfit(creature); } else if (msg == "resetoutfit") { creature.CharType = 0; SendUpdateOutfit(creature); } else if (msg == "level") { ((Player)creature).AddExperienceGain(1000000); } else if (msg.ToLower().StartsWith("item")) { msg = Regex.Split(msg, "\\s+")[1]; Item item = Item.CreateItem("sword"); item.ItemID = ushort.Parse(msg); AppendAddItem(item, creature.CurrentPosition.Clone()); } else if (msg == "sd") { Item item = Item.CreateItem(2127); item.Charges = 2; AppendAddItem(item, creature.CurrentPosition.Clone()); } else if (msg == "vial") { Item item = Item.CreateItem("vial"); item.FluidType = Fluids.FLUID_MILK; AppendAddItem(item, creature.CurrentPosition.Clone()); } else if (msg == "speed") { creature.AddAnonymousChat(ChatAnonymous.WHITE, "Your speed is: " + creature.GetSpeed() + "."); } if (Spell.IsSpell(msg, SpellType.PLAYER_SAY)) { Spell spell = Spell.CreateSpell(msg, (Player)creature); spellSystem.CastSpell(msg, creature, spell, this); } SendProtocolMessages(); } }
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); } } }
/// <summary> /// Gets a position for which a creature could be added. /// Returns null if all the spaces around this position are taken. /// </summary> /// <param name="curPos">The position to add the creature.</param> /// <param name="creatureFor">The creature to add.</param> /// <returns>A free space or null if all spaces are taken.</returns> public Position GetFreePosition(Position curPos, Creature creatureFor) { Position tempPos = curPos.Clone(); if (!TileContainsType(curPos, Constants.TYPE_BLOCKS_AUTO_WALK)) { return tempPos; } for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { tempPos.x = (ushort)(curPos.x + i); tempPos.y = (ushort)(curPos.y + j); if (!TileContainsType(tempPos, Constants.TYPE_BLOCKS_AUTO_WALK)) { return tempPos; } } } return null; }