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 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); }
private LevelGenerationParams(XElement element) { Name = element == null ? "default" : element.Name.ToString(); ObjectProperties = ObjectProperty.InitProperties(this, element); Vector3 colorVector = ToolBox.GetAttributeVector3(element, "BackgroundColor", new Vector3(50, 46, 20)); BackgroundColor = new Color((int)colorVector.X, (int)colorVector.Y, (int)colorVector.Z); VoronoiSiteInterval = ToolBox.GetAttributeVector2(element, "VoronoiSiteInterval", new Vector2(3000, 3000)); VoronoiSiteVariance = ToolBox.GetAttributeVector2(element, "VoronoiSiteVariance", new Vector2(voronoiSiteInterval.X, voronoiSiteInterval.Y) * 0.4f); MainPathNodeIntervalRange = ToolBox.GetAttributeVector2(element, "MainPathNodeIntervalRange", new Vector2(5000.0f, 10000.0f)); SmallTunnelLengthRange = ToolBox.GetAttributeVector2(element, "SmallTunnelLengthRange", new Vector2(5000.0f, 10000.0f)); }
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; } } }
public static void Load(XElement element, Submarine submarine) { Vector2 pos = ToolBox.GetAttributeVector2(element, "pos", Vector2.Zero); LinkedSubmarine linkedSub = null; if (Screen.Selected == GameMain.EditMapScreen) { //string filePath = ToolBox.GetAttributeString(element, "filepath", ""); linkedSub = CreateDummy(submarine, element, pos); linkedSub.saveElement = element; } else { linkedSub = new LinkedSubmarine(submarine); linkedSub.saveElement = element; string levelSeed = ToolBox.GetAttributeString(element, "location", ""); if (!string.IsNullOrWhiteSpace(levelSeed) && GameMain.GameSession.Level != null && GameMain.GameSession.Level.Seed != levelSeed) { linkedSub.loadSub = false; return; } linkedSub.loadSub = true; linkedSub.rect.Location = pos.ToPoint(); } linkedSub.filePath = ToolBox.GetAttributeString(element, "filepath", ""); string linkedToString = ToolBox.GetAttributeString(element, "linkedto", ""); if (linkedToString != "") { string[] linkedToIds = linkedToString.Split(','); for (int i = 0; i < linkedToIds.Length; i++) { linkedSub.linkedToID.Add((ushort)int.Parse(linkedToIds[i])); } } }
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 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 IEnumerable <object> Init() { OverrideMusicType = null; XDocument doc = ToolBox.TryLoadXml("Content/Sounds/sounds.xml"); if (doc == null) { yield return(CoroutineStatus.Failure); } SoundCount = 16 + doc.Root.Elements().Count(); startDrone = Sound.Load("Content/Sounds/startDrone.ogg", false); startDrone.Play(); yield return(CoroutineStatus.Running); waterAmbiences[0] = Sound.Load("Content/Sounds/Water/WaterAmbience1.ogg", false); yield return(CoroutineStatus.Running); waterAmbiences[1] = Sound.Load("Content/Sounds/Water/WaterAmbience2.ogg", false); yield return(CoroutineStatus.Running); flowSounds[0] = Sound.Load("Content/Sounds/Water/FlowSmall.ogg", false); yield return(CoroutineStatus.Running); flowSounds[1] = Sound.Load("Content/Sounds/Water/FlowMedium.ogg", false); yield return(CoroutineStatus.Running); flowSounds[2] = Sound.Load("Content/Sounds/Water/FlowLarge.ogg", false); yield return(CoroutineStatus.Running); for (int i = 0; i < 10; i++) { SplashSounds[i] = Sound.Load("Content/Sounds/Water/Splash" + (i) + ".ogg", false); yield return(CoroutineStatus.Running); } var xMusic = doc.Root.Elements("music").ToList(); if (xMusic.Any()) { musicClips = new BackgroundMusic[xMusic.Count]; int i = 0; foreach (XElement element in xMusic) { string file = ToolBox.GetAttributeString(element, "file", ""); string type = ToolBox.GetAttributeString(element, "type", "").ToLowerInvariant(); Vector2 priority = ToolBox.GetAttributeVector2(element, "priorityrange", new Vector2(0.0f, 100.0f)); musicClips[i] = new BackgroundMusic(file, type, priority); yield return(CoroutineStatus.Running); i++; } } List <KeyValuePair <string, Sound> > miscSoundList = new List <KeyValuePair <string, Sound> >(); damageSounds = new List <DamageSound>(); foreach (XElement subElement in doc.Root.Elements()) { yield return(CoroutineStatus.Running); switch (subElement.Name.ToString().ToLowerInvariant()) { case "music": continue; case "damagesound": Sound damageSound = Sound.Load(ToolBox.GetAttributeString(subElement, "file", ""), false); if (damageSound == null) { continue; } DamageSoundType damageSoundType = DamageSoundType.None; Enum.TryParse <DamageSoundType>(ToolBox.GetAttributeString(subElement, "damagesoundtype", "None"), false, out damageSoundType); damageSounds.Add(new DamageSound( damageSound, ToolBox.GetAttributeVector2(subElement, "damagerange", new Vector2(0.0f, 100.0f)), damageSoundType, ToolBox.GetAttributeString(subElement, "requiredtag", ""))); break; default: Sound sound = Sound.Load(ToolBox.GetAttributeString(subElement, "file", ""), false); if (sound != null) { miscSoundList.Add(new KeyValuePair <string, Sound>(subElement.Name.ToString().ToLowerInvariant(), sound)); } break; } } miscSounds = miscSoundList.ToLookup(kvp => kvp.Key, kvp => kvp.Value); Initialized = true; yield return(CoroutineStatus.Success); }
public override void OnMapLoaded() { if (!loadSub) { return; } sub = Submarine.Load(saveElement, false); Vector2 worldPos = ToolBox.GetAttributeVector2(saveElement, "worldpos", Vector2.Zero); if (worldPos != Vector2.Zero) { sub.SetPosition(worldPos); } else { sub.SetPosition(WorldPosition); } DockingPort linkedPort = null; DockingPort myPort = null; MapEntity linkedItem = linkedTo.FirstOrDefault(lt => (lt is Item) && ((Item)lt).GetComponent <DockingPort>() != null); if (linkedItem == null) { linkedPort = DockingPort.list.Find(dp => dp.DockingTarget != null && dp.DockingTarget.Item.Submarine == sub); } else { linkedPort = ((Item)linkedItem).GetComponent <DockingPort>(); } if (linkedPort == null) { return; } float closestDistance = 0.0f; foreach (DockingPort port in DockingPort.list) { if (port.Item.Submarine != sub || port.IsHorizontal != linkedPort.IsHorizontal) { continue; } float dist = Vector2.Distance(port.Item.WorldPosition, linkedPort.Item.WorldPosition); if (myPort == null || dist < closestDistance) { myPort = port; closestDistance = dist; } } if (myPort != null) { Vector2 portDiff = myPort.Item.WorldPosition - sub.WorldPosition; Vector2 offset = (myPort.IsHorizontal ? Vector2.UnitX * Math.Sign(linkedPort.Item.WorldPosition.X - myPort.Item.WorldPosition.X) : Vector2.UnitY * Math.Sign(linkedPort.Item.WorldPosition.Y - myPort.Item.WorldPosition.Y)); offset *= myPort.DockedDistance; sub.SetPosition( (linkedPort.Item.WorldPosition - portDiff) - offset); myPort.Dock(linkedPort); myPort.Lock(true); } sub.SetPosition(sub.WorldPosition - Submarine.WorldPosition); sub.Submarine = Submarine; }
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); }