public bool SetShipModInvItem(InvItemData invItem, string equipmentType) { if (equipmentType == "PassiveShipMod") { for (int i = 0; i < ShipMods.Length; i++) { if (ShipMods[i] == null) { ShipMods[i] = invItem; return(true); } } return(false); } else if (equipmentType == "ActiveShipMod") { if (ShipMods.Length > 0 && ShipMods[0] == null) { ShipMods[0] = invItem; return(true); } return(false); } return(false); }
public int TakeItemFromItemDataList(List <InvItemData> itemList, InvItemData target, int quantity) { List <InvItemData> listCopy = new List <InvItemData>(itemList); foreach (InvItemData item in listCopy) { if (item == target) { int newQuantity = item.Quantity - quantity; if (newQuantity <= 0) { int taken = item.Quantity; itemList.Remove(item); return(taken); } else { target.Quantity = newQuantity; return(quantity); } } } return(0); }
public void OnSwitchToShip(InvItemData shipItem) { string loadoutID = shipItem.Item.Description; Loadout loadout = FindLoadoutInHangar(loadoutID); if (loadout != null) { //check if there's enough hangar space InvItemData activeShipItemData = this.GetShipItemDataFromLoadout(GameManager.Inst.PlayerProgress.ActiveLoadout); int activeShipUnits = activeShipItemData.Item.GetIntAttribute("Hangar Units"); int newShipUnits = shipItem.Item.GetIntAttribute("Hangar Units"); int hangarSpaceAfterSwitch = Mathf.FloorToInt(AvailableHangarSpaceValue + newShipUnits - activeShipUnits); if (hangarSpaceAfterSwitch >= 0) { _currentStationData.HomeStationData.ShipsInHangar.Remove(loadout); _currentStationData.HomeStationData.ShipsInHangar.Add(GameManager.Inst.PlayerProgress.ActiveLoadout); GameManager.Inst.PlayerProgress.ActiveLoadout = loadout; ShipInfoSheet.CurrentLoadout = loadout; ShipDataSheet.CurrentLoadout = loadout; GameManager.Inst.UIManager.ShipInfoPanel.ResetLoadout(); ShipInfoSheet.Refresh(); ShipDataSheet.Refresh(); } else { GameManager.Inst.UIManager.ErrorMessagePanel.DisplayMessage("NOT ENOUGH SPACE IN HANGAR"); } } }
public void SetEquipmentInvItem(InvItemData invItem, string equipmentType) { switch (equipmentType) { case "Shield": Shield = invItem; break; case "WeaponCapacitor": WeaponCapacitor = invItem; break; case "Thruster": Thruster = invItem; break; case "Scanner": Scanner = invItem; break; case "Teleporter": Teleporter = invItem; break; } }
public override void Initialize(InvItemData itemData, string ammoID) { this.WeaponItem = itemData.Item; this.Class = itemData.Item.GetIntAttribute("Weapon Class"); this.FireRate = itemData.Item.GetFloatAttribute("Fire Rate"); this.Range = itemData.Item.GetFloatAttribute("Range"); ProjectileSpeed = itemData.Item.GetFloatAttribute("Velocity"); this.PowerConsumption = itemData.Item.GetFloatAttribute("Power Consumption"); this.FiringSound = itemData.Item.GetStringAttribute("Firing Sound"); this.RotationType = (WeaponRotationType)Enum.Parse(typeof(WeaponRotationType), itemData.Item.GetStringAttribute("Rotation Type")); ProjectilePrefab = itemData.Item.GetStringAttribute("Projectile ID"); this.AmmoType = itemData.Item.GetStringAttribute("Ammo Type"); this.AmmoID = ammoID; if (this.AmmoType != "") { _isAmmoRequired = true; } if (ParentShip.MyAI.MyFaction != null && ParentShip.MyAI.MyFaction.ID == "player") { _isNPC = false; } else { _isNPC = true; } }
public override void OnItemSelect(InventoryItemEntry itemEntry, InventoryView container) { _selectedItem = itemEntry.ItemData; _selectedItemContainer = container; _selectedItemIndex = itemEntry.InventoryIndex; EquipmentInventory.DeselectAll(); CargoEquipmentInventory.DeselectAll(); ShipModsInventory.DeselectAll(); ActionSheet.SetItemTitle(itemEntry.ItemData.Item.DisplayName); //build description with item description and attributes ActionSheet.SetItemDesc(itemEntry.ItemData.Item.Description); ActionSheet.SetItemSubnote("", ""); ActionSheet.ListItemAttributes(itemEntry.ItemData.Item); if (container == EquipmentInventory) { InstallButton.isEnabled = false; RemoveButton.isEnabled = true; } else if (container == CargoEquipmentInventory) { InstallButton.isEnabled = true; RemoveButton.isEnabled = false; } else if (container == ShipModsInventory) { InstallButton.isEnabled = false; RemoveButton.isEnabled = true; } }
public virtual void Initialize(InvItemData shieldItem) { if (shieldItem == null) { //no shield installed TotalCapacity = 0; } else { Type = (ShieldType)Enum.Parse(typeof(ShieldType), shieldItem.Item.GetStringAttribute("Shield Type")); Tech = (ShieldTech)Enum.Parse(typeof(ShieldTech), shieldItem.Item.GetStringAttribute("Shield Technology")); Class = (ShieldClass)Enum.Parse(typeof(ShieldClass), shieldItem.Item.GetStringAttribute("Shield Class")); TotalCapacity = shieldItem.Item.GetFloatAttribute("Capacity"); RechargeRate = shieldItem.Item.GetFloatAttribute("Recharge Rate"); RechargeDelay = shieldItem.Item.GetFloatAttribute("Recharge Delay"); this.PowerRequired = shieldItem.Item.GetFloatAttribute("Power Required"); } MyRenderer = this.GetComponent <MeshRenderer>(); Material mat = null; //if playership then load separate materials //if NPC then use preloaded materials in material manager //this way playership material can be faded without affecting NPC's material if (ParentShip == GameManager.Inst.PlayerControl.PlayerShip) { if (Tech == ShieldTech.Gravity) { mat = GameObject.Instantiate(Resources.Load("ShieldEffect1")) as Material; } else if (Tech == ShieldTech.Plasma) { mat = GameObject.Instantiate(Resources.Load("ShieldEffect2")) as Material; } else { mat = GameObject.Instantiate(Resources.Load("ShieldEffect3")) as Material; } mat.SetFloat("_Brightness", 0); } else { if (Tech == ShieldTech.Gravity) { mat = GameManager.Inst.MaterialManager.ShieldMaterial1; } else if (Tech == ShieldTech.Plasma) { mat = GameManager.Inst.MaterialManager.ShieldMaterial2; } else { mat = GameManager.Inst.MaterialManager.ShieldMaterial3; } } MyRenderer.materials = new Material[] { mat, mat, mat }; }
private void TradeCommodity(MacroAIParty party, DockableStationData stationData) { //check if there are any commodity goods in leader's cargo bay. if so, check if station is in demand for it //if so, sell it and trigger economy event. if demand level is less than 1, only a certain probability will sell it List <InvItemData> cargoCopy = new List <InvItemData>(party.LeaderLoadout.CargoBayItems); foreach (InvItemData invItem in cargoCopy) { if (invItem.Item.Type == ItemType.Commodity) { ResourceType resourceType = invItem.Item.GetResourceTypeAttribute(); foreach (DemandResource demand in stationData.DemandResources) { if (demand.Type == resourceType || demand.ItemID == invItem.Item.ID) { float sellProbability = 1; if (demand.CurrentDemand <= 1) { sellProbability = 0.4f; } if (UnityEngine.Random.value < sellProbability) { party.LeaderLoadout.CargoBayItems.Remove(invItem); GameManager.Inst.EconomyManager.OnConvoySellCommodity(stationData, resourceType, invItem.Quantity); } } } } } //check if leader cargobay has room. if so, check if station has any commodity for sale and supply level is above 1 //if so buy it and trigger economy event. if supply level is less than 1, only a certain probability will buy it float cargoBayUsage = party.LeaderLoadout.GetCargoBayUsage(); float cargoBaySize = GameManager.Inst.ItemManager.GetShipStats(party.LeaderLoadout.ShipID).CargoBaySize; foreach (SaleItem saleItem in stationData.TraderSaleItems) { ItemStats stats = GameManager.Inst.ItemManager.GetItemStats(saleItem.ItemID); if (stats.Type == ItemType.Commodity) { float buyProbability = 1; if (saleItem.SupplyLevel <= 1) { buyProbability = 0.4f; } if (UnityEngine.Random.value < buyProbability && cargoBayUsage < cargoBaySize) { InvItemData itemData = new InvItemData(); Item item = new Item(GameManager.Inst.ItemManager.GetItemStats(saleItem.ItemID)); itemData.Item = item; itemData.Quantity = UnityEngine.Random.Range(1, Mathf.FloorToInt(cargoBaySize - cargoBayUsage)); GameManager.Inst.ItemManager.AddItemtoInvItemDataList(party.LeaderLoadout.CargoBayItems, itemData, itemData.Quantity); GameManager.Inst.EconomyManager.OnConvoyBuyCommodity(stationData, itemData.Item.ID, itemData.Quantity); } } } }
public InvItemData GenerateInvitemData(string itemID, int quantity) { Item item = new Item(GameManager.Inst.ItemManager.GetItemStats(itemID)); InvItemData itemData = new InvItemData(); itemData.Item = item; itemData.Quantity = quantity; return(itemData); }
public void RemoveShipMod(InvItemData invItem) { for (int i = 0; i < ShipMods.Length; i++) { if (ShipMods[i] == invItem) { ShipMods[i] = null; } } }
public void ClearSelections() { EquipmentInventory.DeselectAll(); CargoEquipmentInventory.DeselectAll(); ShipModsInventory.DeselectAll(); _selectedItem = null; _selectedItemContainer = null; InstallButton.isEnabled = false; RemoveButton.isEnabled = false; ActionSheet.Clear(); }
public void ClearSelections() { CargoAmmoInventory.DeselectAll(); VaultInventory.DeselectAll(); _selectedItem = null; _selectedItemContainer = null; StoreButton.isEnabled = false; RetrieveButton.isEnabled = false; QuantitySlider.alpha = 0; NGUITools.SetActive(QuantitySlider.gameObject, false); ActionSheet.Clear(); }
public void ClearSelections() { WeaponInventory.DeselectAll(); CargoAmmoInventory.DeselectAll(); DefensivesInventory.DeselectAll(); _selectedWeaponItem = null; _selectedItemContainer = null; //_selectedAmmoItem = null; InstallButton.isEnabled = false; RemoveButton.isEnabled = false; ActionSheet.Clear(); }
public void RefreshLoadButtons(InvItemData relatedItem) { if (relatedItem != null && (relatedItem.Item.Type == ItemType.Weapon || relatedItem.Item.Type == ItemType.Defensives)) { Inventory.RelatedItem = relatedItem; } else { Inventory.RelatedItem = null; } Inventory.RefreshLoadButtons(); }
private InvItemData GetShipItemDataFromLoadout(Loadout loadout) { Debug.Log("Creating ship item " + loadout.ShipID); Item shipItem = new Item(GameManager.Inst.ItemManager.AllItemStats["ship_" + loadout.ShipID]); shipItem.DisplayName = GameManager.Inst.ItemManager.AllShipStats[loadout.ShipID].DisplayName; shipItem.Description = loadout.LoadoutID; InvItemData shipInvItem = new InvItemData(); shipInvItem.Item = shipItem; shipInvItem.Quantity = 1; return(shipInvItem); }
public virtual void Initialize(InvItemData shipModItem) { NumericAttributes = new Dictionary <string, float>(); foreach (ItemAttribute attribute in shipModItem.Item.Attributes) { if (attribute.Name != "Ship Mod Type" && attribute.Name != "Power Required" && attribute.Name != "Active Mod Class Name" && attribute.Name != "Dependency" && attribute.Name != "Equipment Type" && attribute.IsHidden) { NumericAttributes.Add(attribute.Name, shipModItem.Item.GetFloatAttribute(attribute.Name)); } } DependencyID = shipModItem.Item.GetStringAttribute("Dependency"); }
public override void OnItemSelect(InventoryItemEntry itemEntry, InventoryView container) { if (itemEntry != null) { _selectedItemContainer = container; _selectedItem = itemEntry.ItemData; ActionSheet.SetItemTitle(itemEntry.ItemData.Item.DisplayName); //build description with item description and attributes ActionSheet.SetItemDesc(itemEntry.ItemData.Item.Description); ActionSheet.ListItemAttributes(itemEntry.ItemData.Item); ActionSheet.SetItemSubnote("", ""); VaultInventory.DeselectAll(); CargoAmmoInventory.DeselectAll(); if (container == VaultInventory) { StoreButton.isEnabled = false; RetrieveButton.isEnabled = true; } else if (container == CargoAmmoInventory && _currentStationData.HomeStationData != null && _currentStationData.HomeStationData.VaultSize > 0) { StoreButton.isEnabled = true; RetrieveButton.isEnabled = false; } if (_selectedItem.Quantity > 1) { QuantitySlider.alpha = 1; NGUITools.SetActive(QuantitySlider.gameObject, true); QuantitySlider.value = 1; _selectedQuantity = _selectedItem.Quantity; QuantityLabel.text = _selectedItem.Quantity.ToString(); } else { QuantitySlider.alpha = 0; _selectedQuantity = 1; NGUITools.SetActive(QuantitySlider.gameObject, false); } } }
public void Refresh() { //make a list of all items trader is selling string stationID = GameManager.Inst.PlayerProgress.SpawnStationID; ClearSelections(); if (GameManager.Inst.WorldManager.DockableStationDatas.ContainsKey(stationID)) { _currentStationData = GameManager.Inst.WorldManager.DockableStationDatas[stationID]; ShipInventorySheet.InventoryItemTypes = _itemTypeFilter; if (_itemTypeFilter.Contains(ItemType.Ammo)) { ShipInventorySheet.InventoryType = InventoryType.AmmoBay; } else { ShipInventorySheet.InventoryType = InventoryType.CargoBay; } ShipInventorySheet.Refresh(); ShipInventorySheet.RefreshLoadButtons(null); if (_currentStationData != null && _currentStationData.TraderSaleItems != null) { List <InvItemData> displayedItems = new List <InvItemData>(); foreach (SaleItem saleItem in _currentStationData.TraderSaleItems) { ItemStats itemStats = GameManager.Inst.ItemManager.GetItemStats(saleItem.ItemID); Item item = new Item(itemStats); InvItemData invItem = new InvItemData(); invItem.Item = item; invItem.Quantity = saleItem.Quantity; if (_itemTypeFilter.Contains(itemStats.Type)) { displayedItems.Add(invItem); } } TraderInventory.Initialize(displayedItems); TraderInventory.RefreshLoadButtons(); } RefreshPrices(); RefreshPlayerMoney(); } }
public void Initialize(InvItemData weaponCapacitorItem) { if (weaponCapacitorItem == null) { Capacity = 0; Amount = 0; RechargeRate = 0; } else { Capacity = weaponCapacitorItem.Item.GetFloatAttribute("Capacity"); Amount = Capacity; RechargeRate = weaponCapacitorItem.Item.GetFloatAttribute("Recharge Rate"); this.PowerRequired = weaponCapacitorItem.Item.GetFloatAttribute("Power Required"); } IsEnabled = true; }
public void Initialize(InvItemData itemData) { if (itemData == null) { MaxFuel = 0; CurrentFuel = 0; } else { MaxSpeed = itemData.Item.GetFloatAttribute("Top Speed"); Acceleration = itemData.Item.GetFloatAttribute("Acceleration"); MaxFuel = itemData.Item.GetFloatAttribute("Max Fuel"); CurrentFuel = MaxFuel; ConsumptionRate = itemData.Item.GetFloatAttribute("Drain Rate"); RestoreRate = itemData.Item.GetFloatAttribute("Restore Rate"); CanStrafe = itemData.Item.GetBoolAttribute("Can Strafe"); this.PowerRequired = itemData.Item.GetFloatAttribute("Power Required"); } }
public bool AddAmmo(InvItemData item) { if (AmmoBaySize - AmmoBayUsage < item.Quantity) { return(false); } if (AmmoBayItems.ContainsKey(item.Item.ID)) { AmmoBayItems[item.Item.ID].Quantity += item.Quantity; } else { AmmoBayItems.Add(item.Item.ID, item); } AmmoBayUsage += item.Quantity * item.Item.CargoUnits; return(true); }
public void AddItemtoInvItemDataList(List <InvItemData> itemList, InvItemData target, int quantity) { bool itemExists = false; foreach (InvItemData item in itemList) { if (item.Item.ID == target.Item.ID) { Debug.Log("Adding item " + quantity + " to existing " + item.Quantity); item.Quantity += quantity; itemExists = true; } } if (!itemExists) { InvItemData newItem = new InvItemData(); newItem.Item = new Item(GameManager.Inst.ItemManager.GetItemStats(target.Item.ID)); newItem.Quantity = quantity; itemList.Add(newItem); } }
public void Initialize(InvItemData itemData) { if (itemData == null) { Range = 100; Coverage = new List <ScannerCoverage>(); Coverage.Add(ScannerCoverage.Ship); ScanDelay = 0; } else { Range = itemData.Item.GetFloatAttribute("Scan Range"); ScanDelay = itemData.Item.GetFloatAttribute("Scan Delay"); Coverage = new List <ScannerCoverage>(); int [] coverages = itemData.Item.GetIntArrayAttribute("Coverage Data"); foreach (int coverage in coverages) { Coverage.Add((ScannerCoverage)coverage); } this.PowerRequired = itemData.Item.GetFloatAttribute("Power Required"); } }
public void LoadWeapon(InvItemData weaponItem) { if (MountedWeapon != null) { GameObject.Destroy(MountedWeapon.gameObject); MountedWeapon = null; } Debug.Log("Loading weapon " + weaponItem.Item.ID); GameObject o = GameObject.Instantiate(Resources.Load(weaponItem.Item.GetStringAttribute("Weapon Prefab ID"))) as GameObject; Weapon weapon = o.GetComponent <Weapon>(); MountedWeapon = weapon; MountedWeapon.transform.parent = transform; MountedWeapon.transform.localPosition = Vector3.zero; MountedWeapon.transform.localEulerAngles = Vector3.zero; //MountedWeapon.transform.LookAt(transform.forward, transform.up); MountedWeapon.ParentShip = ParentShip; MountedWeapon.DisplayName = weaponItem.Item.DisplayName; MountedWeapon.FiringSound = weaponItem.Item.GetStringAttribute("Firing Sound"); MountedWeapon.Initialize(weaponItem, weaponItem.RelatedItemID); MountedWeapon.Rebuild(); }
public void ClearEquipment(InvItemData invItem) { if (Shield == invItem) { Shield = null; } else if (WeaponCapacitor == invItem) { WeaponCapacitor = null; } else if (Thruster == invItem) { Thruster = null; } else if (Scanner == invItem) { Scanner = null; } else if (Teleporter == invItem) { Teleporter = null; } }
public override void Initialize(InvItemData shipModItem) { base.Initialize(shipModItem); }
public virtual void Initialize(InvItemData itemData, string ammoID) { }
public override void Initialize(InvItemData shieldItem) { base.Initialize(shieldItem); Amount = TotalCapacity; }
private Loadout GenerateFactionLoadout(Faction faction, string shipID, int loadoutIndex) { ShipStats shipStats = GameManager.Inst.ItemManager.GetShipStats(shipID); Loadout loadout = new Loadout(shipID, shipStats.ShipType); List <InvItemData> shieldCandidates = new List <InvItemData>(); List <InvItemData> capacitorCandidates = new List <InvItemData>(); List <InvItemData> thrusterCandidates = new List <InvItemData>(); List <InvItemData> scannerCandidates = new List <InvItemData>(); List <InvItemData> defensiveCandidates = new List <InvItemData>(); List <InvItemData> weaponCandidates = new List <InvItemData>(); foreach (string equipmentID in faction.EquipmentPool) { //find the shield with same class as the ship's shield class ItemStats itemStats = GameManager.Inst.ItemManager.GetItemStats(equipmentID); Item item = new Item(itemStats); if (item.Type == ItemType.Equipment) { InvItemData itemData = new InvItemData(); itemData.Quantity = 1; itemData.Item = item; string equipmentType = item.GetStringAttribute("Equipment Type"); if (equipmentType == "Shield") { ShieldClass shieldClass = (ShieldClass)Enum.Parse(typeof(ShieldClass), item.GetStringAttribute("Shield Class")); if (shieldClass == shipStats.ShieldClass) { shieldCandidates.Add(itemData); } } else if (equipmentType == "WeaponCapacitor") { capacitorCandidates.Add(itemData); } else if (equipmentType == "Thruster") { thrusterCandidates.Add(itemData); } else if (equipmentType == "Scanner") { scannerCandidates.Add(itemData); } } else if (item.Type == ItemType.Defensives) { if (shipStats.DefenseSlots > 0) { InvItemData itemData = new InvItemData(); itemData.Quantity = 1; itemData.Item = item; defensiveCandidates.Add(itemData); } } else if (item.Type == ItemType.Weapon) { InvItemData itemData = new InvItemData(); itemData.Quantity = 1; itemData.Item = item; weaponCandidates.Add(itemData); } else if (item.Type == ItemType.Ammo) { InvItemData itemData = new InvItemData(); itemData.Quantity = 1; itemData.Item = item; loadout.AmmoBayItems.Add(itemData); Debug.Log("Party Spawner Added ammo " + itemData.Item.ID); } } loadout.Shield = shieldCandidates[UnityEngine.Random.Range(0, shieldCandidates.Count)]; loadout.WeaponCapacitor = capacitorCandidates[UnityEngine.Random.Range(0, capacitorCandidates.Count)]; loadout.Thruster = thrusterCandidates[UnityEngine.Random.Range(0, thrusterCandidates.Count)]; loadout.Scanner = scannerCandidates[UnityEngine.Random.Range(0, scannerCandidates.Count)]; if (shipStats.DefenseSlots > 0) { loadout.Defensives = new List <InvItemData>(); loadout.Defensives.Add(defensiveCandidates[UnityEngine.Random.Range(0, defensiveCandidates.Count)]); } //go through each weapon slot and find all the weapon candidates that can fit it, and then pick a random one loadout.WeaponJoints = new Dictionary <string, InvItemData>(); foreach (WeaponJointData jointData in shipStats.WeaponJoints) { List <InvItemData> slotWeaponCandidates = new List <InvItemData>(); foreach (InvItemData weaponItem in weaponCandidates) { if (weaponItem.Item.GetIntAttribute("Weapon Class") <= jointData.Class && weaponItem.Item.GetStringAttribute("Rotation Type") == jointData.RotationType.ToString()) { slotWeaponCandidates.Add(weaponItem); } } if (slotWeaponCandidates.Count > 0) { loadout.WeaponJoints.Add(jointData.JointID, slotWeaponCandidates[UnityEngine.Random.Range(0, slotWeaponCandidates.Count)]); } } loadout.ShipMods = new InvItemData[shipStats.ModSlots]; loadout.CurrentPowerMgmtButton = new Vector3(0, -20f, 0); loadout.FuelAmount = shipStats.MaxFuel; loadout.HullAmount = shipStats.Hull; loadout.LifeSupportAmount = shipStats.LifeSupport; loadout.LoadoutID = faction.ID + "_" + loadoutIndex.ToString(); return(loadout); }
public override void Initialize(InvItemData shieldItem) { base.Initialize(shieldItem); Amount = TotalCapacity; _delayTimer = RechargeDelay; }