public MonsterEvent(XElement element) : base(element) { characterFile = ToolBox.GetAttributeString(element, "characterfile", ""); minAmount = ToolBox.GetAttributeInt(element, "minamount", 1); maxAmount = Math.Max(ToolBox.GetAttributeInt(element, "maxamount", 1), minAmount); var spawnPosTypeStr = ToolBox.GetAttributeString(element, "spawntype", ""); if (string.IsNullOrWhiteSpace(spawnPosTypeStr) || !Enum.TryParse <Level.PositionType>(spawnPosTypeStr, true, out spawnPosType)) { spawnPosType = Level.PositionType.MainPath; } spawnDeep = ToolBox.GetAttributeBool(element, "spawndeep", false); if (GameMain.NetworkMember != null) { List <string> monsterNames = GameMain.NetworkMember.monsterEnabled.Keys.ToList(); string tryKey = monsterNames.Find(s => characterFile.ToLower().Contains(s.ToLower())); if (!string.IsNullOrWhiteSpace(tryKey)) { if (!GameMain.NetworkMember.monsterEnabled[tryKey]) { disallowed = true; //spawn was disallowed by host } } } }
public FixRequirement(XElement element) { name = ToolBox.GetAttributeString(element, "name", ""); requiredSkills = new List <Skill>(); requiredItems = new List <string>(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "skill": string skillName = ToolBox.GetAttributeString(subElement, "name", ""); int level = ToolBox.GetAttributeInt(subElement, "level", 1); requiredSkills.Add(new Skill(skillName, level)); break; case "item": string itemName = ToolBox.GetAttributeString(subElement, "name", ""); requiredItems.Add(itemName); break; } } }
public static Map Load(XElement element) { string mapSeed = ToolBox.GetAttributeString(element, "seed", "a"); int size = ToolBox.GetAttributeInt(element, "size", 500); Map map = new Map(mapSeed, size); map.SetLocation(ToolBox.GetAttributeInt(element, "currentlocation", 0)); string discoveredStr = ToolBox.GetAttributeString(element, "discovered", ""); string[] discoveredStrs = discoveredStr.Split(','); for (int i = 0; i < discoveredStrs.Length; i++) { int index = -1; if (int.TryParse(discoveredStrs[i], out index)) { map.locations[index].Discovered = true; } } string passedStr = ToolBox.GetAttributeString(element, "passed", ""); string[] passedStrs = passedStr.Split(','); for (int i = 0; i < passedStrs.Length; i++) { int index = -1; if (int.TryParse(passedStrs[i], out index)) { map.connections[index].Passed = true; } } return(map); }
public ScriptedEvent(XElement element) { name = ToolBox.GetAttributeString(element, "name", ""); description = ToolBox.GetAttributeString(element, "description", ""); difficulty = ToolBox.GetAttributeInt(element, "difficulty", 1); commonness = ToolBox.GetAttributeInt(element, "commonness", 1); MusicType = ToolBox.GetAttributeString(element, "musictype", "default"); }
private void LoadItemAsChild(XElement element, Item parent) { string itemName = ToolBox.GetAttributeString(element, "name", ""); ItemPrefab itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab; if (itemPrefab == null) { DebugConsole.ThrowError("Couldn't spawn item for cargo mission: item prefab \"" + element.Name.ToString() + "\" not found"); return; } WayPoint cargoSpawnPos = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub, true); if (cargoSpawnPos == null) { DebugConsole.ThrowError("Couldn't spawn items for cargo mission, cargo spawnpoint not found"); return; } var cargoRoom = cargoSpawnPos.CurrentHull; if (cargoRoom == null) { DebugConsole.ThrowError("A waypoint marked as Cargo must be placed inside a room!"); return; } Vector2 position = new Vector2( cargoSpawnPos.Position.X + Rand.Range(-20.0f, 20.0f, Rand.RandSync.Server), cargoRoom.Rect.Y - cargoRoom.Rect.Height + itemPrefab.Size.Y / 2); var item = new Item(itemPrefab, position, cargoRoom.Submarine); item.FindHull(); items.Add(item); if (parent != null) { parent.Combine(item); } foreach (XElement subElement in element.Elements()) { int amount = ToolBox.GetAttributeInt(subElement, "amount", 1); for (int i = 0; i < amount; i++) { LoadItemAsChild(subElement, item); } } }
public static void Load(XElement element, Submarine submarine) { string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0"); string[] rectValues = rectString.Split(','); Rectangle rect = new Rectangle( int.Parse(rectValues[0]), int.Parse(rectValues[1]), int.Parse(rectValues[2]), int.Parse(rectValues[3])); string name = element.Attribute("name").Value; Structure s = null; foreach (MapEntityPrefab ep in MapEntityPrefab.list) { if (ep.Name == name) { s = new Structure(rect, (StructurePrefab)ep, submarine); s.Submarine = submarine; s.ID = (ushort)int.Parse(element.Attribute("ID").Value); break; } } if (s == null) { DebugConsole.ThrowError("Structure prefab " + name + " not found."); return; } foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString()) { case "section": int index = ToolBox.GetAttributeInt(subElement, "i", -1); if (index == -1) { continue; } s.sections[index].damage = ToolBox.GetAttributeFloat(subElement, "damage", 0.0f); s.sections[index].GapID = ToolBox.GetAttributeInt(subElement, "gap", -1); break; } } }
public CrewManager(XElement element) : this() { money = ToolBox.GetAttributeInt(element, "money", 0); foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "character") { continue; } characterInfos.Add(new CharacterInfo(subElement)); } }
public BackgroundSpritePrefab(XElement element) { string alignmentStr = ToolBox.GetAttributeString(element, "alignment", ""); if (string.IsNullOrEmpty(alignmentStr) || !Enum.TryParse(alignmentStr, out Alignment)) { Alignment = Alignment.Top | Alignment.Bottom | Alignment.Left | Alignment.Right; } Commonness = ToolBox.GetAttributeInt(element, "commonness", 1); SpawnOnWalls = ToolBox.GetAttributeBool(element, "spawnonwalls", true); Scale.X = ToolBox.GetAttributeFloat(element, "minsize", 1.0f); Scale.Y = ToolBox.GetAttributeFloat(element, "maxsize", 1.0f); DepthRange = ToolBox.GetAttributeVector2(element, "depthrange", new Vector2(0.0f, 1.0f)); AlignWithSurface = ToolBox.GetAttributeBool(element, "alignwithsurface", false); RandomRotation = ToolBox.GetAttributeVector2(element, "randomrotation", Vector2.Zero); RandomRotation.X = MathHelper.ToRadians(RandomRotation.X); RandomRotation.Y = MathHelper.ToRadians(RandomRotation.Y); SwingAmount = MathHelper.ToRadians(ToolBox.GetAttributeFloat(element, "swingamount", 0.0f)); OverrideCommonness = new Dictionary <string, int>(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "sprite": Sprite = new Sprite(subElement); break; case "overridecommonness": string levelType = ToolBox.GetAttributeString(subElement, "leveltype", ""); if (!OverrideCommonness.ContainsKey(levelType)) { OverrideCommonness.Add(levelType, ToolBox.GetAttributeInt(subElement, "commonness", 1)); } break; } } }
private LocationType(XElement element) { name = element.Name.ToString(); commonness = ToolBox.GetAttributeInt(element, "commonness", 1); totalWeight += commonness; nameFormats = new List <string>(); foreach (XAttribute nameFormat in element.Element("nameformats").Attributes()) { nameFormats.Add(nameFormat.Value); } hireableJobs = new List <Tuple <JobPrefab, float> >(); foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "hireable") { continue; } string jobName = ToolBox.GetAttributeString(subElement, "name", ""); JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == jobName.ToLowerInvariant()); if (jobPrefab == null) { DebugConsole.ThrowError("Invalid job name (" + jobName + ") in location type " + name); } float jobCommonness = ToolBox.GetAttributeFloat(subElement, "commonness", 1.0f); totalHireableWeight += jobCommonness; Tuple <JobPrefab, float> hireableJob = new Tuple <JobPrefab, float>(jobPrefab, jobCommonness); hireableJobs.Add(hireableJob); } string spritePath = ToolBox.GetAttributeString(element, "symbol", "Content/Map/beaconSymbol.png"); symbolSprite = new Sprite(spritePath, new Vector2(0.5f, 0.5f)); string backgroundPath = ToolBox.GetAttributeString(element, "background", ""); backGround = new Sprite(backgroundPath, Vector2.Zero); }
public CharacterInfo(XElement element) { Name = ToolBox.GetAttributeString(element, "name", "unnamed"); string genderStr = ToolBox.GetAttributeString(element, "gender", "male").ToLowerInvariant(); gender = (genderStr == "m") ? Gender.Male : Gender.Female; File = ToolBox.GetAttributeString(element, "file", ""); Salary = ToolBox.GetAttributeInt(element, "salary", 1000); headSpriteId = ToolBox.GetAttributeInt(element, "headspriteid", 1); StartItemsGiven = ToolBox.GetAttributeBool(element, "startitemsgiven", false); int hullId = ToolBox.GetAttributeInt(element, "hull", -1); if (hullId > 0 && hullId <= ushort.MaxValue) { this.HullID = (ushort)hullId; } pickedItems = new List <ushort>(); string pickedItemString = ToolBox.GetAttributeString(element, "items", ""); if (!string.IsNullOrEmpty(pickedItemString)) { string[] itemIds = pickedItemString.Split(','); foreach (string s in itemIds) { pickedItems.Add((ushort)int.Parse(s)); } } foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "job") { continue; } Job = new Job(subElement); break; } }
public JobPrefab(XElement element) { Name = ToolBox.GetAttributeString(element, "name", "name not found"); Description = ToolBox.GetAttributeString(element, "description", ""); MinNumber = ToolBox.GetAttributeInt(element, "minnumber", 0); MaxNumber = ToolBox.GetAttributeInt(element, "maxnumber", 10); Commonness = ToolBox.GetAttributeInt(element, "commonness", 10); AllowAlways = ToolBox.GetAttributeBool(element, "allowalways", false); ItemNames = new List <string>(); Skills = new List <SkillPrefab>(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "items": Items = subElement; foreach (XElement itemElement in subElement.Elements()) { string itemName = ToolBox.GetAttributeString(itemElement, "name", ""); if (!string.IsNullOrWhiteSpace(itemName)) { ItemNames.Add(itemName); } } break; case "skills": foreach (XElement skillElement in subElement.Elements()) { Skills.Add(new SkillPrefab(skillElement)); } break; } } Skills.Sort((x, y) => y.LevelRange.X.CompareTo(x.LevelRange.X)); }
public void StartServer() { XDocument doc = ToolBox.TryLoadXml(GameServer.SettingsFile); if (doc == null) { DebugConsole.ThrowError("File \"" + GameServer.SettingsFile + "\" not found. Starting the server with default settings."); Server = new GameServer("Server", 14242, false, "", false, 10); return; } Server = new GameServer( ToolBox.GetAttributeString(doc.Root, "name", "Server"), ToolBox.GetAttributeInt(doc.Root, "port", 14242), ToolBox.GetAttributeBool(doc.Root, "public", false), ToolBox.GetAttributeString(doc.Root, "password", ""), ToolBox.GetAttributeBool(doc.Root, "enableupnp", false), ToolBox.GetAttributeInt(doc.Root, "maxplayers", 10)); }
public Mission(XElement element, Location[] locations) { name = ToolBox.GetAttributeString(element, "name", ""); description = ToolBox.GetAttributeString(element, "description", ""); reward = ToolBox.GetAttributeInt(element, "reward", 1); successMessage = ToolBox.GetAttributeString(element, "successmessage", "Mission completed successfully"); failureMessage = ToolBox.GetAttributeString(element, "failuremessage", "Mission failed"); radarLabel = ToolBox.GetAttributeString(element, "radarlabel", ""); messages = new List <string>(); headers = new List <string>(); foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "message") { continue; } headers.Add(ToolBox.GetAttributeString(subElement, "header", "")); messages.Add(ToolBox.GetAttributeString(subElement, "text", "")); } for (int n = 0; n < 2; n++) { description = description.Replace("[location" + (n + 1) + "]", locations[n].Name); successMessage = successMessage.Replace("[location" + (n + 1) + "]", locations[n].Name); failureMessage = failureMessage.Replace("[location" + (n + 1) + "]", locations[n].Name); for (int m = 0; m < messages.Count; m++) { messages[m] = messages[m].Replace("[location" + (n + 1) + "]", locations[n].Name); } } }
public static void Load(XElement element, Submarine submarine) { Rectangle rect = new Rectangle( int.Parse(element.Attribute("x").Value), int.Parse(element.Attribute("y").Value), (int)Submarine.GridSize.X, (int)Submarine.GridSize.Y); WayPoint w = new WayPoint(rect, submarine); w.ID = (ushort)int.Parse(element.Attribute("ID").Value); Enum.TryParse <SpawnType>(ToolBox.GetAttributeString(element, "spawn", "Path"), out w.spawnType); string idCardTagString = ToolBox.GetAttributeString(element, "idcardtags", ""); if (!string.IsNullOrWhiteSpace(idCardTagString)) { w.IdCardTags = idCardTagString.Split(','); } string jobName = ToolBox.GetAttributeString(element, "job", "").ToLowerInvariant(); if (!string.IsNullOrWhiteSpace(jobName)) { w.assignedJob = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == jobName); } w.ladderId = (ushort)ToolBox.GetAttributeInt(element, "ladders", 0); w.gapId = (ushort)ToolBox.GetAttributeInt(element, "gap", 0); w.linkedToID = new List <ushort>(); int i = 0; while (element.Attribute("linkedto" + i) != null) { w.linkedToID.Add((ushort)int.Parse(element.Attribute("linkedto" + i).Value)); i += 1; } }
public SpriteSheet(XElement element, string path = "", string file = "") : base(element, path, file) { int columnCount = Math.Max(ToolBox.GetAttributeInt(element, "columns", 1), 1); int rowCount = Math.Max(ToolBox.GetAttributeInt(element, "rows", 1), 1); sourceRects = new Rectangle[rowCount * columnCount]; int cellWidth = SourceRect.Width / columnCount; int cellHeight = SourceRect.Height / rowCount; for (int x = 0; x < columnCount; x++) { for (int y = 0; y < rowCount; y++) { sourceRects[x + y * columnCount] = new Rectangle(x * cellWidth, y * cellHeight, cellWidth, cellHeight); } } origin = ToolBox.GetAttributeVector2(element, "origin", new Vector2(0.5f, 0.5f)); origin.X = origin.X * cellWidth; origin.Y = origin.Y * cellHeight; }
public Job(XElement element) { string name = ToolBox.GetAttributeString(element, "name", "").ToLowerInvariant(); prefab = JobPrefab.List.Find(jp => jp.Name.ToLowerInvariant() == name); skills = new Dictionary <string, Skill>(); foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "skill") { continue; } string skillName = ToolBox.GetAttributeString(subElement, "name", ""); if (string.IsNullOrEmpty(name)) { continue; } skills.Add( skillName, new Skill(skillName, ToolBox.GetAttributeInt(subElement, "level", 0))); } }
public static Mission LoadRandom(Location[] locations, MTRandom rand, string missionType = "", bool isSinglePlayer = false) { missionType = missionType.ToLowerInvariant(); var files = GameMain.SelectedPackage.GetFilesOfType(ContentType.Missions); string configFile = files[rand.Next(files.Count)]; XDocument doc = ToolBox.TryLoadXml(configFile); if (doc == null) { return(null); } int eventCount = doc.Root.Elements().Count(); //int[] commonness = new int[eventCount]; float[] eventProbability = new float[eventCount]; float probabilitySum = 0.0f; List <XElement> matchingElements = new List <XElement>(); if (missionType == "random") { matchingElements = doc.Root.Elements().ToList(); } else if (missionType == "none") { return(null); } else if (string.IsNullOrWhiteSpace(missionType)) { matchingElements = doc.Root.Elements().ToList(); } else { matchingElements = doc.Root.Elements().ToList().FindAll(m => m.Name.ToString().ToLowerInvariant().Replace("mission", "") == missionType); } if (isSinglePlayer) { matchingElements.RemoveAll(m => ToolBox.GetAttributeBool(m, "multiplayeronly", false)); } else { matchingElements.RemoveAll(m => ToolBox.GetAttributeBool(m, "singleplayeronly", false)); } int i = 0; foreach (XElement element in matchingElements) { eventProbability[i] = ToolBox.GetAttributeInt(element, "commonness", 1); probabilitySum += eventProbability[i]; i++; } float randomNumber = (float)rand.NextDouble() * probabilitySum; i = 0; foreach (XElement element in matchingElements) { if (randomNumber <= eventProbability[i]) { Type t; string type = element.Name.ToString(); try { t = Type.GetType("Barotrauma." + type, true, true); if (t == null) { DebugConsole.ThrowError("Error in " + configFile + "! Could not find a mission class of the type \"" + type + "\"."); continue; } } catch { DebugConsole.ThrowError("Error in " + configFile + "! Could not find a mission class of the type \"" + type + "\"."); continue; } ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement), typeof(Location[]) }); object instance = constructor.Invoke(new object[] { element, locations }); Mission mission = (Mission)instance; return(mission); } randomNumber -= eventProbability[i]; i++; } return(null); }
public ItemPrefab(XElement element, string filePath) { configFile = filePath; ConfigElement = element; name = ToolBox.GetAttributeString(element, "name", ""); if (name == "") { DebugConsole.ThrowError("Unnamed item in " + filePath + "!"); } DebugConsole.Log(" " + name); Description = ToolBox.GetAttributeString(element, "description", ""); pickThroughWalls = ToolBox.GetAttributeBool(element, "pickthroughwalls", false); pickDistance = ToolBox.GetAttributeFloat(element, "pickdistance", 0.0f); isLinkable = ToolBox.GetAttributeBool(element, "linkable", false); resizeHorizontal = ToolBox.GetAttributeBool(element, "resizehorizontal", false); resizeVertical = ToolBox.GetAttributeBool(element, "resizevertical", false); focusOnSelected = ToolBox.GetAttributeBool(element, "focusonselected", false); offsetOnSelected = ToolBox.GetAttributeFloat(element, "offsetonselected", 0.0f); CanUseOnSelf = ToolBox.GetAttributeBool(element, "canuseonself", false); FireProof = ToolBox.GetAttributeBool(element, "fireproof", false); ImpactTolerance = ToolBox.GetAttributeFloat(element, "impacttolerance", 0.0f); string aliases = ToolBox.GetAttributeString(element, "aliases", ""); if (!string.IsNullOrWhiteSpace(aliases)) { Aliases = aliases.Split(','); } MapEntityCategory category; if (!Enum.TryParse(ToolBox.GetAttributeString(element, "category", "Misc"), true, out category)) { category = MapEntityCategory.Misc; } Category = category; string spriteColorStr = ToolBox.GetAttributeString(element, "spritecolor", "1.0,1.0,1.0,1.0"); SpriteColor = new Color(ToolBox.ParseToVector4(spriteColorStr)); price = ToolBox.GetAttributeInt(element, "price", 0); Triggers = new List <Rectangle>(); DeconstructItems = new List <DeconstructItem>(); DeconstructTime = 1.0f; tags = new List <string>(); tags.AddRange(ToolBox.GetAttributeString(element, "tags", "").Split(',')); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "sprite": string spriteFolder = ""; if (!ToolBox.GetAttributeString(subElement, "texture", "").Contains("/")) { spriteFolder = Path.GetDirectoryName(filePath); } canSpriteFlipX = ToolBox.GetAttributeBool(subElement, "canflipx", true); sprite = new Sprite(subElement, spriteFolder); size = sprite.size; break; case "deconstruct": DeconstructTime = ToolBox.GetAttributeFloat(subElement, "time", 10.0f); foreach (XElement deconstructItem in subElement.Elements()) { string deconstructItemName = ToolBox.GetAttributeString(deconstructItem, "name", "not found"); bool requireFullCondition = ToolBox.GetAttributeBool(deconstructItem, "requirefullcondition", false); DeconstructItems.Add(new DeconstructItem(deconstructItemName, requireFullCondition)); } break; case "trigger": Rectangle trigger = new Rectangle(0, 0, 10, 10); trigger.X = ToolBox.GetAttributeInt(subElement, "x", 0); trigger.Y = ToolBox.GetAttributeInt(subElement, "y", 0); trigger.Width = ToolBox.GetAttributeInt(subElement, "width", 0); trigger.Height = ToolBox.GetAttributeInt(subElement, "height", 0); Triggers.Add(trigger); break; } } list.Add(this); }
public Limb(Character character, XElement element, float scale = 1.0f) { this.character = character; wearingItems = new List <WearableSprite>(); dir = Direction.Right; doesFlip = ToolBox.GetAttributeBool(element, "flip", false); this.scale = scale; body = new PhysicsBody(element, scale); if (ToolBox.GetAttributeBool(element, "ignorecollisions", false)) { body.CollisionCategories = Category.None; body.CollidesWith = Category.None; ignoreCollisions = true; } else { //limbs don't collide with each other body.CollisionCategories = Physics.CollisionCharacter; body.CollidesWith = Physics.CollisionAll & ~Physics.CollisionCharacter & ~Physics.CollisionItem; } body.UserData = this; refJointIndex = -1; Vector2 pullJointPos = Vector2.Zero; if (element.Attribute("type") != null) { try { type = (LimbType)Enum.Parse(typeof(LimbType), element.Attribute("type").Value, true); } catch { type = LimbType.None; DebugConsole.ThrowError("Error in " + element + "! \"" + element.Attribute("type").Value + "\" is not a valid limb type"); } pullJointPos = ToolBox.GetAttributeVector2(element, "pullpos", Vector2.Zero) * scale; pullJointPos = ConvertUnits.ToSimUnits(pullJointPos); stepOffset = ToolBox.GetAttributeVector2(element, "stepoffset", Vector2.Zero) * scale; stepOffset = ConvertUnits.ToSimUnits(stepOffset); refJointIndex = ToolBox.GetAttributeInt(element, "refjoint", -1); } else { type = LimbType.None; } pullJoint = new FixedMouseJoint(body.FarseerBody, pullJointPos); pullJoint.Enabled = false; pullJoint.MaxForce = ((type == LimbType.LeftHand || type == LimbType.RightHand) ? 400.0f : 150.0f) * body.Mass; GameMain.World.AddJoint(pullJoint); steerForce = ToolBox.GetAttributeFloat(element, "steerforce", 0.0f); //maxHealth = Math.Max(ToolBox.GetAttributeFloat(element, "health", 100.0f),1.0f); armorSector = ToolBox.GetAttributeVector2(element, "armorsector", Vector2.Zero); armorSector.X = MathHelper.ToRadians(armorSector.X); armorSector.Y = MathHelper.ToRadians(armorSector.Y); armorValue = Math.Max(ToolBox.GetAttributeFloat(element, "armor", 0.0f), 0.0f); if (element.Attribute("mouthpos") != null) { MouthPos = ConvertUnits.ToSimUnits(ToolBox.GetAttributeVector2(element, "mouthpos", Vector2.Zero)); } body.BodyType = BodyType.Dynamic; body.FarseerBody.AngularDamping = LimbAngularDamping; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "sprite": string spritePath = subElement.Attribute("texture").Value; string spritePathWithTags = spritePath; if (character.Info != null) { spritePath = spritePath.Replace("[GENDER]", (character.Info.Gender == Gender.Female) ? "f" : ""); spritePath = spritePath.Replace("[HEADID]", character.Info.HeadSpriteId.ToString()); if (character.Info.HeadSprite != null && character.Info.SpriteTags.Any()) { string tags = ""; character.Info.SpriteTags.ForEach(tag => tags += "[" + tag + "]"); spritePathWithTags = Path.Combine( Path.GetDirectoryName(spritePath), Path.GetFileNameWithoutExtension(spritePath) + tags + Path.GetExtension(spritePath)); } } if (File.Exists(spritePathWithTags)) { sprite = new Sprite(subElement, "", spritePathWithTags); } else { sprite = new Sprite(subElement, "", spritePath); } break; case "damagedsprite": string damagedSpritePath = subElement.Attribute("texture").Value; if (character.Info != null) { damagedSpritePath = damagedSpritePath.Replace("[GENDER]", (character.Info.Gender == Gender.Female) ? "f" : ""); damagedSpritePath = damagedSpritePath.Replace("[HEADID]", character.Info.HeadSpriteId.ToString()); } damagedSprite = new Sprite(subElement, "", damagedSpritePath); break; case "attack": attack = new Attack(subElement); break; } } InitProjSpecific(element); }
public static ScriptedEvent LoadRandom(Random rand) { var configFiles = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.RandomEvents); if (!configFiles.Any()) { DebugConsole.ThrowError("No config files for random events found in the selected content package"); return(null); } string configFile = configFiles[0]; XDocument doc = ToolBox.TryLoadXml(configFile); if (doc == null) { return(null); } int eventCount = doc.Root.Elements().Count(); //int[] commonness = new int[eventCount]; float[] eventProbability = new float[eventCount]; float probabilitySum = 0.0f; int i = 0; foreach (XElement element in doc.Root.Elements()) { eventProbability[i] = ToolBox.GetAttributeInt(element, "commonness", 1); //if the event has been previously selected, it's less likely to be selected now //int previousEventIndex = previousEvents.FindIndex(x => x == i); //if (previousEventIndex >= 0) //{ // //how many shifts ago was the event last selected // int eventDist = eventCount - previousEventIndex; // float weighting = (1.0f / eventDist) * PreviouslyUsedWeight; // eventProbability[i] *= weighting; //} probabilitySum += eventProbability[i]; i++; } float randomNumber = (float)rand.NextDouble() * probabilitySum; i = 0; foreach (XElement element in doc.Root.Elements()) { if (randomNumber <= eventProbability[i]) { Type t; string type = element.Name.ToString(); try { t = Type.GetType("Barotrauma." + type, true, true); if (t == null) { DebugConsole.ThrowError("Error in " + configFile + "! Could not find an event class of the type \"" + type + "\"."); continue; } } catch { DebugConsole.ThrowError("Error in " + configFile + "! Could not find an event class of the type \"" + type + "\"."); continue; } ConstructorInfo constructor = t.GetConstructor(new[] { typeof(XElement) }); object instance = null; try { instance = constructor.Invoke(new object[] { element }); } catch (Exception ex) { DebugConsole.ThrowError(ex.InnerException != null ? ex.InnerException.ToString() : ex.ToString()); } //previousEvents.Add(i); return((ScriptedEvent)instance); } randomNumber -= eventProbability[i]; i++; } return(null); }
public void Load(string filePath) { XDocument doc = ToolBox.TryLoadXml(filePath); if (doc == null) { DebugConsole.ThrowError("No config file found"); GraphicsWidth = 1024; GraphicsHeight = 678; MasterServerUrl = ""; SelectedContentPackage = ContentPackage.list.Any() ? ContentPackage.list[0] : new ContentPackage(""); JobNamePreferences = new List <string>(); foreach (JobPrefab job in JobPrefab.List) { JobNamePreferences.Add(job.Name); } return; } XElement graphicsMode = doc.Root.Element("graphicsmode"); GraphicsWidth = ToolBox.GetAttributeInt(graphicsMode, "width", 0); GraphicsHeight = ToolBox.GetAttributeInt(graphicsMode, "height", 0); VSyncEnabled = ToolBox.GetAttributeBool(graphicsMode, "vsync", true); if (GraphicsWidth == 0 || GraphicsHeight == 0) { GraphicsWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; GraphicsHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; } //FullScreenEnabled = ToolBox.GetAttributeBool(graphicsMode, "fullscreen", true); var windowModeStr = ToolBox.GetAttributeString(graphicsMode, "displaymode", "Fullscreen"); if (!Enum.TryParse <WindowMode>(windowModeStr, out windowMode)) { windowMode = WindowMode.Fullscreen; } MasterServerUrl = ToolBox.GetAttributeString(doc.Root, "masterserverurl", ""); AutoCheckUpdates = ToolBox.GetAttributeBool(doc.Root, "autocheckupdates", true); WasGameUpdated = ToolBox.GetAttributeBool(doc.Root, "wasgameupdated", false); SoundVolume = ToolBox.GetAttributeFloat(doc.Root, "soundvolume", 1.0f); MusicVolume = ToolBox.GetAttributeFloat(doc.Root, "musicvolume", 0.3f); VerboseLogging = ToolBox.GetAttributeBool(doc.Root, "verboselogging", false); EnableSplashScreen = ToolBox.GetAttributeBool(doc.Root, "enablesplashscreen", true); keyMapping = new KeyOrMouse[Enum.GetNames(typeof(InputType)).Length]; keyMapping[(int)InputType.Up] = new KeyOrMouse(Keys.W); keyMapping[(int)InputType.Down] = new KeyOrMouse(Keys.S); keyMapping[(int)InputType.Left] = new KeyOrMouse(Keys.A); keyMapping[(int)InputType.Right] = new KeyOrMouse(Keys.D); keyMapping[(int)InputType.Run] = new KeyOrMouse(Keys.LeftShift); keyMapping[(int)InputType.Chat] = new KeyOrMouse(Keys.Tab); keyMapping[(int)InputType.CrewOrders] = new KeyOrMouse(Keys.C); keyMapping[(int)InputType.Select] = new KeyOrMouse(Keys.E); keyMapping[(int)InputType.Use] = new KeyOrMouse(0); keyMapping[(int)InputType.Aim] = new KeyOrMouse(1); foreach (XElement subElement in doc.Root.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "contentpackage": string path = ToolBox.GetAttributeString(subElement, "path", ""); SelectedContentPackage = ContentPackage.list.Find(cp => cp.Path == path); if (SelectedContentPackage == null) { SelectedContentPackage = new ContentPackage(path); } break; case "keymapping": foreach (XAttribute attribute in subElement.Attributes()) { InputType inputType; if (Enum.TryParse(attribute.Name.ToString(), true, out inputType)) { int mouseButton; if (int.TryParse(attribute.Value.ToString(), out mouseButton)) { keyMapping[(int)inputType] = new KeyOrMouse(mouseButton); } else { Keys key; if (Enum.TryParse(attribute.Value.ToString(), true, out key)) { keyMapping[(int)inputType] = new KeyOrMouse(key); } } } } break; case "gameplay": JobNamePreferences = new List <string>(); foreach (XElement ele in subElement.Element("jobpreferences").Elements("job")) { JobNamePreferences.Add(ToolBox.GetAttributeString(ele, "name", "")); } break; } } foreach (InputType inputType in Enum.GetValues(typeof(InputType))) { if (keyMapping[(int)inputType] == null) { DebugConsole.ThrowError("Key binding for the input type \"" + inputType + " not set!"); keyMapping[(int)inputType] = new KeyOrMouse(Keys.D1); } } UnsavedSettings = false; }