/// <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 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(); } }
/// <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 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(); } }