public void Thrall(CharacterTemplateID id, int amount) { var charTemplate = CharacterTemplateManager.Instance[id]; if (charTemplate == null) { UserChat("Invalid character template `{0}`.", id); return; } if (amount < 1) { UserChat("Must thrall 1 or more characters."); return; } var thrallArea = new Rectangle(); var useThrallArea = false; // When standing on top of something, also spawn the NPCs on the thing the User is standing on, // and spread them out a bit on it without exceeding the size of it var userStandingOn = User.StandingOn; if (userStandingOn != null) { useThrallArea = true; var minX = userStandingOn.Position.X; var maxX = userStandingOn.Max.X; var y = userStandingOn.Position.Y; minX = Math.Max(minX, User.Position.X - 96); maxX = Math.Min(maxX, User.Position.X + 96); thrallArea = new Rectangle(minX, y, maxX - minX + 1, 1); } for (var i = 0; i < amount; i++) { // Create a ThralledNPC and add it to the world var npc = new ThralledNPC(World, charTemplate, User.Map, User.Position); // When using the thrallArea, move the NPC to the correct area if (useThrallArea) { var npcSize = npc.Size; var minX = thrallArea.Left; var maxX = thrallArea.Right - (int)npcSize.X; int x; if (maxX <= minX) { x = minX; } else { x = RandomHelper.NextInt(minX, maxX); } var y = thrallArea.Y - (int)npc.Size.Y; npc.Position = new Vector2(x, y); } } }
public void Thrall(CharacterTemplateID id, int amount) { var charTemplate = CharacterTemplateManager.Instance[id]; if (charTemplate == null) { UserChat("Invalid character template `{0}`.", id); return; } if (amount < 1) { UserChat("Must thrall 1 or more characters."); return; } var thrallArea = new Rectangle(); var useThrallArea = false; // When standing on top of something, also spawn the NPCs on the thing the User is standing on, // and spread them out a bit on it without exceeding the size of it var userStandingOn = User.StandingOn; if (userStandingOn != null) { useThrallArea = true; var minX = userStandingOn.Position.X; var maxX = userStandingOn.Max.X; var y = userStandingOn.Position.Y; minX = Math.Max(minX, User.Position.X - 96); maxX = Math.Min(maxX, User.Position.X + 96); thrallArea = new Rectangle((int)minX, (int)y, (int)(maxX - minX + 1), 1); } for (var i = 0; i < amount; i++) { // Create a ThralledNPC and add it to the world var npc = new ThralledNPC(World, charTemplate, User.Map, User.Position); // When using the thrallArea, move the NPC to the correct area if (useThrallArea) { var npcSize = npc.Size; var minX = thrallArea.Left; var maxX = thrallArea.Right - (int)npcSize.X; int x; if (maxX <= minX) x = minX; else x = RandomHelper.NextInt(minX, maxX); var y = thrallArea.Y - (int)npc.Size.Y; npc.Position = new Vector2(x, y); } } }