//TODO:Check for exception public static ShipBaseData GetShip(string name) { var doc = new XmlDocument(); doc.LoadXml(Data.Ships); var node = doc.SelectSingleNode($"//ship[name=\'{name}\']"); var ship = new ShipBaseData { Name = name, HP = float.Parse(node["hp"].InnerText), Defence = float.Parse(node["defence"].InnerText), MoveSpeed = float.Parse(node["speed"].InnerText), slots = new ShipSlotData[node["slots"].ChildNodes.Count] }; var slotNodes = doc.SelectNodes($"//ship[name=\'{name}\']//slots//slot"); for (var i = 0; i < slotNodes.Count; i++) { var slotNode = slotNodes[i]; ship.slots[i].SlotId = i; ship.slots[i].HasGun = false; ship.slots[i].MaxTier = int.Parse(slotNode["maxTier"].InnerText); ship.slots[i].positionOffset = new Vector2D(float.Parse(slotNode["position"]["x"].InnerText), float.Parse(slotNode["position"]["y"].InnerText)); } return(ship); }
public ShipData(Ship owner) { this.owner = owner; shipBase = new ShipBaseData(); ShipBuffs = new Buffs(); ShipStats = new ShipStats(); }
public void SetShip(ShipBaseData data) { if (shipBase.slots != null) { foreach (var shipBaseSlot in shipBase.slots) { if (shipBaseSlot.HasGun) { owner.Inventory.Add(shipBaseSlot.Gun); } } } shipBase = data; UpdateFields(); ShipStats.SetHP(ShipStats.MaxHP); }