protected internal virtual void OnInitialSpawn(EntitySpawnEventArgs e) { if (InitialSpawn != null) { InitialSpawn(this, e); } }
/// <summary> /// Post-spawn handling. /// </summary> /// <param name="e">The event.</param> public void SpawnHandle(EntitySpawnEventArgs e) { Character = PhysEnt.OriginalObject as CharacterController; if (double.IsNaN(StandardGroundForce)) { StandardGroundForce = Character.TractionForce; } }
public void OnSpawn(EntitySpawnEventArgs e) { if (e.EventCanceled) { return; } _plugin.Server.Broadcast(e.Entity.GetType() + " Spawned"); }
/// <summary> /// Post-spawn handling. /// </summary> /// <param name="e">The event.</param> public void SpawnHandle(EntitySpawnEventArgs e) { if (ForcePosition) { POPJ = new PointOnPlaneJoint(null, PhysEnt.SpawnedBody, Vector3.Zero, Vector3.UnitZ, Vector3.Zero); PhysEnt.PhysicsWorld.Internal.Add(POPJ); } RAJ = new RevoluteAngularJoint(null, PhysEnt.SpawnedBody, Vector3.UnitZ); PhysEnt.PhysicsWorld.Internal.Add(RAJ); }
private void OnSpawn(EntitySpawnEventArgs e) { foreach (EventListener el in Plugins) { if (el.Event == Event.EntitySpawn) { IEntityListener l = el.Listener as IEntityListener; l.OnSpawn(e); } } }
/// <summary> /// Spawns an entity /// </summary> /// <param name="sender">Object command is sent from</param> /// <param name="e">EventArgs that contain position, name, entityID and max number</param> private void Spawn(Entity sender, BoxArgs e) { EntitySpawnEventArgs args = e as EntitySpawnEventArgs; //get current count of entities of this type int currentNum = entities.Count(entity => entity.EntityName.Contains(args.Name) && entity.EntityID == args.EntityID); Entity potential = new Enemy(this, args.Position, args.Name + currentNum, args.EntityID, args.Direction, args.Bounds); if (args.Type == EntityType.Enemy && CheckForCollisions(potential)) { entities.Add(potential); } //else //entities.Add(new NPC(this, args.Position, args.Name + currentNum, args.EntityID)); }
private static void DoSpawn(WorldManager world, HashSet <int> chunksToSpawnIn, Mob[] mobEntities, List <WeightedValue <MobType> > mobGroup, int maximumMobs, bool inWater = false) { // Based on original server spawn logic and minecraft wiki (http://www.minecraftwiki.net/wiki/Spawn) // Check that we haven't already reached the maximum number of this type of mob if (mobGroup.Count > 0 && (mobEntities.Where(e => mobGroup.Where(mob => mob.Value == e.Type).Any()).Count() <= maximumMobs * chunksToSpawnIn.Count / 256)) { foreach (var packedChunk in chunksToSpawnIn) { MobType mobType = mobGroup.SelectRandom(world.Server.Rand); UniversalCoords packSpawnPosition = GetRandomPointInChunk(world, UniversalCoords.FromPackedChunkToX(packedChunk), UniversalCoords.FromPackedChunkToZ(packedChunk)); byte?blockId = world.GetBlockId(packSpawnPosition); if (blockId == null) { continue; } BlockBase blockClass = BlockHelper.Instance.CreateBlockInstance((byte)blockId); if (!blockClass.IsOpaque && ((!inWater && blockClass.Type == BlockData.Blocks.Air) || (inWater && blockClass.IsLiquid))) // Lava is Opaque, so IsLiquid is safe to use here for water & still water { int spawnedCount = 0; int x = packSpawnPosition.WorldX; int y = packSpawnPosition.WorldY; int z = packSpawnPosition.WorldZ; for (int i = 0; i < 21; i++) { // Every 4th attempt reset the coordinates to the centre of the pack spawn if (i % 4 == 0) { x = packSpawnPosition.WorldX; y = packSpawnPosition.WorldY; z = packSpawnPosition.WorldZ; } const int distance = 6; x += world.Server.Rand.Next(distance) - world.Server.Rand.Next(distance); y += world.Server.Rand.Next(1) - world.Server.Rand.Next(1); z += world.Server.Rand.Next(distance) - world.Server.Rand.Next(distance); if (CanMobTypeSpawnAtLocation(mobType, world, x, y, z)) { AbsWorldCoords spawnPosition = new AbsWorldCoords(x + 0.5, y, z + 0.5); // Check that no player is within a radius of 24 blocks of the spawnPosition if (world.GetClosestPlayer(spawnPosition, 24.0) == null) { // Check that the squared distance is more than 576 from spawn (24 blocks) if (spawnPosition.ToVector().DistanceSquared(new AbsWorldCoords(world.Spawn).ToVector()) > 576.0) { Mob newMob = MobFactory.Instance.CreateMob(world, world.Server, mobType) as Mob; if (newMob == null) { break; } newMob.Position = spawnPosition; newMob.Yaw = world.Server.Rand.NextDouble() * 360.0; // Finally apply any mob specific rules about spawning here if (newMob.CanSpawnHere()) { //Event EntitySpawnEventArgs e = new EntitySpawnEventArgs(newMob, newMob.Position); world.Server.PluginManager.CallEvent(Event.EntitySpawn, e); if (e.EventCanceled) { continue; } newMob.Position = e.Location; //End Event ++spawnedCount; MobSpecificInitialisation(newMob, world, spawnPosition); world.Server.AddEntity(newMob); if (spawnedCount >= newMob.MaxSpawnedPerGroup) { // This chunk is full - move to the next break; } } } } } } } } } }
/// <summary> /// Creates list of all strucutures in area by reading from specified area id /// </summary> /// <param name="areaID">ID of area to load</param> /// <returns>List of drawable elements in array</returns> private void loadArea(string areaID) { XDocument doc = XDocument.Load(AppDomain.CurrentDomain.BaseDirectory + @"Content\areas\" + areaID + ".xml"); //create new lists for area drawElements = new List <IDrawable>(); entities = new List <Entity>(); sheets = new List <Spritesheet>(); //create new eventboxes, replacing old ones if necessary if (boxes != null) { boxes.ForEach(box => box.UnloadBox()); } boxes = new List <EventBox>(); //loads main menu menu = new Menu(doc.Descendants("Area").Elements("Menu").First().Value); foreach (XElement element in doc.Descendants("Area").Descendants("Sheets").Descendants("SheetID")) { sheets.Add(new Spritesheet(element.Value)); } if (doc.Descendants("Area").Elements("BGM").Count() > 0 && doc.Descendants("Area").Elements("BGM").First().Element("MusicID").Value != "None") //load bgm if is contained in xml { background = Content.Load <Song>("sound/music/" + doc.Descendants("Area").Elements("BGM").First().Element("MusicID").Value); if (MediaPlayer.State != MediaState.Playing || MediaPlayer.Queue.ActiveSong.Name != background.Name) { MediaPlayer.Play(background); MediaPlayer.Volume = .3f; MediaPlayer.IsRepeating = bool.Parse(doc.Descendants("Area").Elements("BGM").First().Element("Loop").Value); } } foreach (XElement element in doc.Descendants("Area").Descendants("Tile")) //load tiles { drawElements.Add(Tile.LoadFromXML(element, sheets)); } foreach (XElement element in doc.Descendants("Area").Descendants("Structure")) //load structures { drawElements.Add(Structure.LoadFromXML(element, sheets)); } foreach (XElement element in doc.Descendants("Area").Elements("Entity")) { EntityType type = (EntityType)Enum.Parse(typeof(EntityType), element.Element("Type").Value); SpriteDirection direction = (SpriteDirection)Enum.Parse(typeof(SpriteDirection), element.Element("Direction").Value); string entityID = element.Element("EntityID").Value; string name = element.Element("Name").Value; RectangleF bounds = RectangleF.FromArray(element.Element("Bounds").Value.Split(',')); string[] pos = element.Element("Position").Value.Split(','); Vector2 position = new Vector2(float.Parse(pos[0]), float.Parse(pos[1])); EntitySpawnEventArgs args = new EntitySpawnEventArgs(entityID, name, type, 1, direction, position, bounds); Spawn(User, args); } foreach (XElement element in doc.Descendants("Area").Descendants("Player").Elements("EventBox")) //load player event boxes { RectangleF rect = RectangleF.FromArray(element.Element("Box").Value.Split(',')); EventBox.Condition condition = null; if (element.Elements("Condition").Count() > 0) { string methodString = element.Element("Condition").Value; condition = (EventBox.Condition)Delegate.CreateDelegate(typeof(EventBox.Condition), this, methodString); } if (element.Element("Method").Value == "OnNewAreaEnter") { Vector2 position = VectorEx.FromArray(element.Element("Position").Value.Split(',')); NewAreaEventArgs args = new NewAreaEventArgs(element.Element("AreaID").Value, position); boxes.Add(new EventBox(User, rect, OnNewAreaEnter, args, condition)); } else if (element.Element("Method").Value == "Spawn") { int maxNum = int.Parse(element.Element("MaxNum").Value); Vector2 position = VectorEx.FromArray(element.Element("Position").Value.Split(',')); EntityType type = (EntityType)Enum.Parse(typeof(EntityType), element.Element("Type").Value); SpriteDirection direction = (SpriteDirection)Enum.Parse(typeof(SpriteDirection), element.Element("Direction").Value); EntitySpawnEventArgs args = new EntitySpawnEventArgs(element.Element("EntityID").Value, element.Element("Name").Value, type, maxNum, direction, position, RectangleF.FromArray(element.Element("Bounds").Value.Split(','))); boxes.Add(new EventBox(User, rect, Spawn, args, null)); } } }
public void Use(IClient client, string commandName, string[] tokens) { MobType type = MobType.Sheep; int amount = 1; bool validMob = false; if (tokens.Length > 1) { Int32.TryParse(tokens[1], out amount); } if (tokens.Length > 0) { int mobId; Int32.TryParse(tokens[0], out mobId); string mobName = Enum.GetName(typeof(MobType), mobId); if (mobId == 0) { if (mobId.ToString() != tokens[0]) { Enum.TryParse(tokens[0], true, out type); validMob = true; } } else if (!string.IsNullOrEmpty(mobName)) { type = (MobType)Enum.Parse(typeof(MobType), mobName); validMob = true; } } else { validMob = true; } if (amount < 1 || !validMob) { Help(client); return; } IServer server = client.GetServer(); AbsWorldCoords position = client.GetOwner().Position; IMobFactory mobFactory = server.GetMobFactory(); for (int i = 0; i < amount; i++) { var mob = mobFactory.CreateMob(client.GetOwner().GetWorld(), server, type, null); mob.Position = position; //Event EntitySpawnEventArgs e = new EntitySpawnEventArgs(mob, mob.Position); server.GetPluginManager().CallEvent(Event.EntitySpawn, e); if (e.EventCanceled) { continue; } mob.Position = e.Location; //End Event server.AddEntity(mob); } }
/// <summary> /// Fired on the secondary spawn event. /// </summary> /// <param name="e">Event data.</param> public void OnSpawnSecond(EntitySpawnEventArgs e) { PhysChar = Entity.GetProperty <EntityPhysicsProperty>().OriginalObject as CharacterController; }