public PhysicsBody(XElement element, Vector2 position, float scale = 1.0f) { float radius = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "radius", 0.0f)) * scale; float height = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "height", 0.0f)) * scale; float width = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "width", 0.0f)) * scale; density = ToolBox.GetAttributeFloat(element, "density", 10.0f); CreateBody(width, height, radius, density); dir = 1.0f; body.CollisionCategories = Physics.CollisionItem; body.CollidesWith = Physics.CollisionWall | Physics.CollisionLevel; body.Friction = ToolBox.GetAttributeFloat(element, "friction", 0.3f); body.Restitution = ToolBox.GetAttributeFloat(element, "restitution", 0.05f); body.BodyType = BodyType.Dynamic; body.UserData = this; SetTransform(position, 0.0f); LastSentPosition = position; list.Add(this); }
public static void Load(XElement element, Submarine submarine) { Rectangle rect = Rectangle.Empty; if (element.Attribute("rect") != null) { string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0"); string[] rectValues = rectString.Split(','); rect = new Rectangle( int.Parse(rectValues[0]), int.Parse(rectValues[1]), int.Parse(rectValues[2]), int.Parse(rectValues[3])); } else { rect = new Rectangle( int.Parse(element.Attribute("x").Value), int.Parse(element.Attribute("y").Value), int.Parse(element.Attribute("width").Value), int.Parse(element.Attribute("height").Value)); } Hull h = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), rect, submarine); h.volume = ToolBox.GetAttributeFloat(element, "pressure", 0.0f); h.ID = (ushort)int.Parse(element.Attribute("ID").Value); }
public CharacterSound(XElement element) { Sound = Sound.Load(element.Attribute("file").Value); Range = ToolBox.GetAttributeFloat(element, "range", 1000.0f); Enum.TryParse <SoundType>(ToolBox.GetAttributeString(element, "state", "Idle"), true, out Type); }
public BackgroundCreaturePrefab(XElement element) { Speed = ToolBox.GetAttributeFloat(element, "speed", 1.0f); WanderAmount = ToolBox.GetAttributeFloat(element, "wanderamount", 0.0f); WanderZAmount = ToolBox.GetAttributeFloat(element, "wanderzamount", 0.0f); SwarmMin = ToolBox.GetAttributeInt(element, "swarmmin", 1); SwarmMax = ToolBox.GetAttributeInt(element, "swarmmax", 1); SwarmRadius = ToolBox.GetAttributeFloat(element, "swarmradius", 200.0f); DisableRotation = ToolBox.GetAttributeBool(element, "disablerotation", false); foreach (XElement subElement in element.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "sprite") { continue; } Sprite = new Sprite(subElement); break; } }
public Attack(XElement element) { try { DamageType = (DamageType)Enum.Parse(typeof(DamageType), ToolBox.GetAttributeString(element, "damagetype", "None"), true); } catch { DamageType = DamageType.None; } damage = ToolBox.GetAttributeFloat(element, "damage", 0.0f); structureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f); bleedingDamage = ToolBox.GetAttributeFloat(element, "bleedingdamage", 0.0f); Stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f); SeverLimbsProbability = ToolBox.GetAttributeFloat(element, "severlimbsprobability", 0.0f); Force = ToolBox.GetAttributeFloat(element, "force", 0.0f); TargetForce = ToolBox.GetAttributeFloat(element, "targetforce", 0.0f); Torque = ToolBox.GetAttributeFloat(element, "torque", 0.0f); Range = ToolBox.GetAttributeFloat(element, "range", 0.0f); Duration = ToolBox.GetAttributeFloat(element, "duration", 0.0f); priority = ToolBox.GetAttributeFloat(element, "priority", 1.0f); InitProjSpecific(element); string limbIndicesStr = ToolBox.GetAttributeString(element, "applyforceonlimbs", ""); if (!string.IsNullOrWhiteSpace(limbIndicesStr)) { ApplyForceOnLimbs = new List <int>(); foreach (string limbIndexStr in limbIndicesStr.Split(',')) { int limbIndex; if (int.TryParse(limbIndexStr, out limbIndex)) { ApplyForceOnLimbs.Add(limbIndex); } } } foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "statuseffect": if (statusEffects == null) { statusEffects = new List <StatusEffect>(); } statusEffects.Add(StatusEffect.Load(subElement)); break; } } }
public Sprite(XElement element, string path = "", string file = "") { if (file == "") { file = ToolBox.GetAttributeString(element, "texture", ""); } if (file == "") { DebugConsole.ThrowError("Sprite " + element + " doesn't have a texture specified!"); return; } if (!string.IsNullOrEmpty(path)) { if (!path.EndsWith("/")) { path += "/"; } } this.file = path + file; texture = LoadTexture(this.file); if (texture == null) { return; } Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", Vector4.Zero); if (sourceVector.Z == 0.0f) { sourceVector.Z = texture.Width; } if (sourceVector.W == 0.0f) { sourceVector.W = texture.Height; } sourceRect = new Rectangle( (int)sourceVector.X, (int)sourceVector.Y, (int)sourceVector.Z, (int)sourceVector.W); origin = ToolBox.GetAttributeVector2(element, "origin", new Vector2(0.5f, 0.5f)); origin.X = origin.X * sourceRect.Width; origin.Y = origin.Y * sourceRect.Height; size = ToolBox.GetAttributeVector2(element, "size", Vector2.One); size.X *= sourceRect.Width; size.Y *= sourceRect.Height; Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f); list.Add(this); }
public HumanoidAnimController(Character character, XElement element) : base(character, element) { walkAnimSpeed = ToolBox.GetAttributeFloat(element, "walkanimspeed", 4.0f); walkAnimSpeed = MathHelper.ToRadians(walkAnimSpeed); movementLerp = ToolBox.GetAttributeFloat(element, "movementlerp", 0.4f); thighTorque = ToolBox.GetAttributeFloat(element, "thightorque", -5.0f); }
public Attack(XElement element) { try { DamageType = (DamageType)Enum.Parse(typeof(DamageType), ToolBox.GetAttributeString(element, "damagetype", "None"), true); } catch { DamageType = DamageType.None; } damage = ToolBox.GetAttributeFloat(element, "damage", 0.0f); structureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f); bleedingDamage = ToolBox.GetAttributeFloat(element, "bleedingdamage", 0.0f); Force = ToolBox.GetAttributeFloat(element, "force", 0.0f); TargetForce = ToolBox.GetAttributeFloat(element, "targetforce", 0.0f); Torque = ToolBox.GetAttributeFloat(element, "torque", 0.0f); Stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f); string soundPath = ToolBox.GetAttributeString(element, "sound", ""); if (!string.IsNullOrWhiteSpace(soundPath)) { sound = Sound.Load(soundPath); } Range = ToolBox.GetAttributeFloat(element, "range", 0.0f); Duration = ToolBox.GetAttributeFloat(element, "duration", 0.0f); priority = ToolBox.GetAttributeFloat(element, "priority", 1.0f); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "particleemitter": particleEmitterPrefab = new ParticleEmitterPrefab(subElement); break; case "statuseffect": if (statusEffects == null) { statusEffects = new List <StatusEffect>(); } statusEffects.Add(StatusEffect.Load(subElement)); break; } } }
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 AnimController(Character character, XElement element) : base(character, element) { this.character = character; stepSize = ToolBox.GetAttributeVector2(element, "stepsize", Vector2.One); stepSize = ConvertUnits.ToSimUnits(stepSize); walkSpeed = ToolBox.GetAttributeFloat(element, "walkspeed", 1.0f); swimSpeed = ToolBox.GetAttributeFloat(element, "swimspeed", 1.0f); legTorque = ToolBox.GetAttributeFloat(element, "legtorque", 0.0f); }
public Explosion(XElement element) { attack = new Attack(element); force = ToolBox.GetAttributeFloat(element, "force", 0.0f); sparks = ToolBox.GetAttributeBool(element, "sparks", true); shockwave = ToolBox.GetAttributeBool(element, "shockwave", true); flames = ToolBox.GetAttributeBool(element, "flames", true); smoke = ToolBox.GetAttributeBool(element, "smoke", true); CameraShake = ToolBox.GetAttributeFloat(element, "camerashake", attack.Range * 0.1f); }
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 EnemyAIController(Character c, string file) : base(c) { targetMemories = new Dictionary <AITarget, AITargetMemory>(); XDocument doc = ToolBox.TryLoadXml(file); if (doc == null || doc.Root == null) { return; } XElement aiElement = doc.Root.Element("ai"); if (aiElement == null) { return; } attackRooms = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackrooms", "attackpriorityrooms") / 100.0f; attackHumans = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackhumans", "attackpriorityhumans") / 100.0f; attackWeaker = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackweaker", "attackpriorityweaker") / 100.0f; attackStronger = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackstronger", "attackprioritystronger") / 100.0f; eatDeadPriority = ToolBox.GetAttributeFloat(aiElement, "eatpriority", 0.0f) / 100.0f; combatStrength = ToolBox.GetAttributeFloat(aiElement, "combatstrength", 1.0f); attackCoolDown = ToolBox.GetAttributeFloat(aiElement, "attackcooldown", 5.0f); sight = ToolBox.GetAttributeFloat(aiElement, "sight", 0.0f); hearing = ToolBox.GetAttributeFloat(aiElement, "hearing", 0.0f); attackWhenProvoked = ToolBox.GetAttributeBool(aiElement, "attackwhenprovoked", false); fleeHealthThreshold = ToolBox.GetAttributeFloat(aiElement, "fleehealththreshold", 0.0f); attachToWalls = ToolBox.GetAttributeBool(aiElement, "attachtowalls", false); outsideSteering = new SteeringManager(this); insideSteering = new IndoorsSteeringManager(this, false); steeringManager = outsideSteering; state = AIState.None; }
partial void InitProjSpecific(XDocument doc) { soundInterval = ToolBox.GetAttributeFloat(doc.Root, "soundinterval", 10.0f); keys = new Key[Enum.GetNames(typeof(InputType)).Length]; for (int i = 0; i < Enum.GetNames(typeof(InputType)).Length; i++) { keys[i] = new Key(GameMain.Config.KeyBind((InputType)i)); } var soundElements = doc.Root.Elements("sound").ToList(); sounds = new List <CharacterSound>(); foreach (XElement soundElement in soundElements) { sounds.Add(new CharacterSound(soundElement)); } hudProgressBars = new Dictionary <object, HUDProgressBar>(); }
public FishAnimController(Character character, XElement element) : base(character, element) { waveAmplitude = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "waveamplitude", 0.0f)); waveLength = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "wavelength", 0.0f)); flip = ToolBox.GetAttributeBool(element, "flip", true); mirror = ToolBox.GetAttributeBool(element, "mirror", false); float footRot = ToolBox.GetAttributeFloat(element, "footrotation", float.NaN); if (float.IsNaN(footRot)) { footRotation = null; } else { footRotation = MathHelper.ToRadians(footRot); } rotateTowardsMovement = ToolBox.GetAttributeBool(element, "rotatetowardsmovement", true); }
public EnemyAIController(Character c, string file) : base(c) { targetMemories = new Dictionary <AITarget, AITargetMemory>(); XDocument doc = ToolBox.TryLoadXml(file); if (doc == null || doc.Root == null) { return; } XElement aiElement = doc.Root.Element("ai"); if (aiElement == null) { return; } attackRooms = ToolBox.GetAttributeFloat(aiElement, "attackrooms", 0.0f) / 100.0f; attackHumans = ToolBox.GetAttributeFloat(aiElement, "attackhumans", 0.0f) / 100.0f; attackWeaker = ToolBox.GetAttributeFloat(aiElement, "attackweaker", 0.0f) / 100.0f; attackStronger = ToolBox.GetAttributeFloat(aiElement, "attackstronger", 0.0f) / 100.0f; attackCoolDown = ToolBox.GetAttributeFloat(aiElement, "attackcooldown", 5.0f); sight = ToolBox.GetAttributeFloat(aiElement, "sight", 0.0f); hearing = ToolBox.GetAttributeFloat(aiElement, "hearing", 0.0f); attackWhenProvoked = ToolBox.GetAttributeBool(aiElement, "attackwhenprovoked", false); outsideSteering = new SteeringManager(this); insideSteering = new IndoorsSteeringManager(this, false); steeringManager = outsideSteering; state = AiState.None; }
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); }
protected StatusEffect(XElement element) { requiredItems = new List <RelatedItem>(); #if CLIENT particleEmitters = new List <ParticleEmitterPrefab>(); #endif IEnumerable <XAttribute> attributes = element.Attributes(); List <XAttribute> propertyAttributes = new List <XAttribute>(); foreach (XAttribute attribute in attributes) { switch (attribute.Name.ToString()) { case "type": try { type = (ActionType)Enum.Parse(typeof(ActionType), attribute.Value, true); } catch { string[] split = attribute.Value.Split('='); type = (ActionType)Enum.Parse(typeof(ActionType), split[0], true); string[] containingNames = split[1].Split(','); onContainingNames = new HashSet <string>(); for (int i = 0; i < containingNames.Length; i++) { onContainingNames.Add(containingNames[i].Trim()); } } break; case "target": string[] Flags = attribute.Value.Split(','); foreach (string s in Flags) { targetTypes |= (TargetType)Enum.Parse(typeof(TargetType), s, true); } break; case "disabledeltatime": disableDeltaTime = ToolBox.GetAttributeBool(attribute, false); break; case "setvalue": setValue = ToolBox.GetAttributeBool(attribute, false); break; case "targetnames": string[] names = attribute.Value.Split(','); targetNames = new HashSet <string>(); for (int i = 0; i < names.Length; i++) { targetNames.Add(names[i].Trim()); } break; case "duration": duration = ToolBox.GetAttributeFloat(attribute, 0.0f); break; #if CLIENT case "sound": sound = Sound.Load(attribute.Value.ToString()); break; #endif default: propertyAttributes.Add(attribute); break; } } int count = propertyAttributes.Count; propertyNames = new string[count]; propertyEffects = new object[count]; int n = 0; foreach (XAttribute attribute in propertyAttributes) { propertyNames[n] = attribute.Name.ToString().ToLowerInvariant(); propertyEffects[n] = ToolBox.GetAttributeObject(attribute); n++; } foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "explosion": explosion = new Explosion(subElement); break; case "fire": FireSize = ToolBox.GetAttributeFloat(subElement, "size", 10.0f); break; case "use": case "useitem": useItem = true; break; case "requireditem": case "requireditems": RelatedItem newRequiredItem = RelatedItem.Load(subElement); if (newRequiredItem == null) { continue; } requiredItems.Add(newRequiredItem); break; #if CLIENT case "particleemitter": particleEmitters.Add(new ParticleEmitterPrefab(subElement)); break; #endif } } }
public CharacterInfo(string file, string name = "", Gender gender = Gender.None, JobPrefab jobPrefab = null) { this.File = file; headSpriteRange = new Vector2[2]; pickedItems = new List <ushort>(); SpriteTags = new List <string>(); //ID = -1; XDocument doc = ToolBox.TryLoadXml(file); if (doc == null) { return; } if (ToolBox.GetAttributeBool(doc.Root, "genders", false)) { if (gender == Gender.None) { float femaleRatio = ToolBox.GetAttributeFloat(doc.Root, "femaleratio", 0.5f); this.gender = (Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < femaleRatio) ? Gender.Female : Gender.Male; } else { this.gender = gender; } } headSpriteRange[0] = ToolBox.GetAttributeVector2(doc.Root, "headid", Vector2.Zero); headSpriteRange[1] = headSpriteRange[0]; if (headSpriteRange[0] == Vector2.Zero) { headSpriteRange[0] = ToolBox.GetAttributeVector2(doc.Root, "maleheadid", Vector2.Zero); headSpriteRange[1] = ToolBox.GetAttributeVector2(doc.Root, "femaleheadid", Vector2.Zero); } int genderIndex = (this.gender == Gender.Female) ? 1 : 0; if (headSpriteRange[genderIndex] != Vector2.Zero) { HeadSpriteId = Rand.Range((int)headSpriteRange[genderIndex].X, (int)headSpriteRange[genderIndex].Y + 1); } this.Job = (jobPrefab == null) ? Job.Random() : new Job(jobPrefab); if (!string.IsNullOrEmpty(name)) { this.Name = name; return; } name = ""; if (doc.Root.Element("name") != null) { string firstNamePath = ToolBox.GetAttributeString(doc.Root.Element("name"), "firstname", ""); if (firstNamePath != "") { firstNamePath = firstNamePath.Replace("[GENDER]", (this.gender == Gender.Female) ? "f" : ""); this.Name = ToolBox.GetRandomLine(firstNamePath); } string lastNamePath = ToolBox.GetAttributeString(doc.Root.Element("name"), "lastname", ""); if (lastNamePath != "") { lastNamePath = lastNamePath.Replace("[GENDER]", (this.gender == Gender.Female) ? "f" : ""); if (this.Name != "") { this.Name += " "; } this.Name += ToolBox.GetRandomLine(lastNamePath); } } Salary = CalculateSalary(); }
public static StructurePrefab Load(XElement element) { StructurePrefab sp = new StructurePrefab(); sp.name = element.Name.ToString(); sp.tags = new List <string>(); sp.tags.AddRange(ToolBox.GetAttributeString(element, "tags", "").Split(',')); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString()) { case "sprite": sp.sprite = new Sprite(subElement); if (ToolBox.GetAttributeBool(subElement, "fliphorizontal", false)) { sp.sprite.effects = SpriteEffects.FlipHorizontally; } if (ToolBox.GetAttributeBool(subElement, "flipvertical", false)) { sp.sprite.effects = SpriteEffects.FlipVertically; } sp.canSpriteFlipX = ToolBox.GetAttributeBool(subElement, "canflipx", true); break; case "backgroundsprite": sp.BackgroundSprite = new Sprite(subElement); if (ToolBox.GetAttributeBool(subElement, "fliphorizontal", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipHorizontally; } if (ToolBox.GetAttributeBool(subElement, "flipvertical", false)) { sp.BackgroundSprite.effects = SpriteEffects.FlipVertically; } break; } } MapEntityCategory category; if (!Enum.TryParse(ToolBox.GetAttributeString(element, "category", "Structure"), true, out category)) { category = MapEntityCategory.Structure; } sp.Category = category; sp.Description = ToolBox.GetAttributeString(element, "description", ""); sp.size = Vector2.Zero; sp.size.X = ToolBox.GetAttributeFloat(element, "width", 0.0f); sp.size.Y = ToolBox.GetAttributeFloat(element, "height", 0.0f); string spriteColorStr = ToolBox.GetAttributeString(element, "spritecolor", "1.0,1.0,1.0,1.0"); sp.SpriteColor = new Color(ToolBox.ParseToVector4(spriteColorStr)); sp.maxHealth = ToolBox.GetAttributeFloat(element, "health", 100.0f); sp.resizeHorizontal = ToolBox.GetAttributeBool(element, "resizehorizontal", false); sp.resizeVertical = ToolBox.GetAttributeBool(element, "resizevertical", false); sp.isPlatform = ToolBox.GetAttributeBool(element, "platform", false); sp.stairDirection = (Direction)Enum.Parse(typeof(Direction), ToolBox.GetAttributeString(element, "stairdirection", "None"), true); sp.castShadow = ToolBox.GetAttributeBool(element, "castshadow", false); sp.hasBody = ToolBox.GetAttributeBool(element, "body", false); return(sp); }
public DelayedEffect(XElement element) : base(element) { delay = ToolBox.GetAttributeFloat(element, "delay", 1.0f); }
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 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; }