Quality Tiers

Item Manufacturers now defined in item data
Items are generated at specific quality tiers with associated colors, displayed in title of properties panel when selected
This commit is contained in:
Reinier Vens 2021-03-08 02:57:38 +00:00
commit ab54f878f4
11 changed files with 78 additions and 223 deletions

BIN
Assets/Resources/Settings.asset (Stored with Git LFS)

Binary file not shown.

View file

@ -3068,10 +3068,10 @@ RectTransform:
m_Father: {fileID: 746825913}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 90.5, y: -8}
m_SizeDelta: {x: 181, y: 16}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &232470598
MonoBehaviour:
@ -4292,7 +4292,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &346000247
RectTransform:
m_ObjectHideFlags: 0
@ -15853,10 +15853,10 @@ RectTransform:
m_Father: {fileID: 204301710}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 92, y: -220}
m_SizeDelta: {x: 184, y: 16}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1277237367
MonoBehaviour:
@ -16837,7 +16837,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 439, y: 204}
m_SizeDelta: {x: 128, y: 0}
m_SizeDelta: {x: 128, y: 16}
m_Pivot: {x: 0, y: 1}
--- !u!114 &1399423351
MonoBehaviour:
@ -19161,10 +19161,10 @@ RectTransform:
m_Father: {fileID: 1399423350}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 63.5, y: -8}
m_SizeDelta: {x: 127, y: 16}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1564656282
MonoBehaviour:
@ -19356,7 +19356,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: 0, y: -224}
m_SizeDelta: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 325.58}
m_Pivot: {x: 0.5, y: 0}
--- !u!114 &1590553660
MonoBehaviour:
@ -22290,10 +22290,10 @@ RectTransform:
m_Father: {fileID: 1359207439}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 127, y: -130}
m_SizeDelta: {x: 16, y: 16}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1889622744
MonoBehaviour:
@ -29173,10 +29173,10 @@ RectTransform:
m_Father: {fileID: 7628189704016736659}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 127, y: -130}
m_SizeDelta: {x: 16, y: 16}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &7628189703197605887
MonoBehaviour:

View file

@ -432,7 +432,7 @@ public class ActionGameManager : MonoBehaviour
testCorp.PlayerHostile = true;
var stationType = ItemData.GetAll<HullData>().First(x=>x.HullType==HullType.Station);
var stationHull = ItemManager.CreateInstance(stationType, 0, 1) as EquippableItem;
var stationHull = ItemManager.CreateInstance(stationType) as EquippableItem;
var stationParent = Zone.PlanetInstances.Values.OrderByDescending(p => p.BodyData.Mass.Value).ElementAt(3);
var stationParentOrbit = stationParent.Orbit.Data.ID;
var stationParentPos = Zone.GetOrbitPosition(stationParentOrbit);
@ -442,7 +442,7 @@ public class ActionGameManager : MonoBehaviour
station.Faction = testCorp;
Zone.Entities.Add(station);
var dockingBayData = ItemData.GetAll<DockingBayData>().First();
var dockingBay = ItemManager.CreateInstance(dockingBayData, 1, 1) as EquippableItem;
var dockingBay = ItemManager.CreateInstance(dockingBayData) as EquippableItem;
station.TryEquip(dockingBay);
station.Activate();

View file

@ -42,4 +42,4 @@ public class BodySettingsCollection
{
public float MinimumMass;
public CelestialBodySettings[] BodySettings;
}
}

View file

@ -10,6 +10,7 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
{
if (target == null) return;
if(weapon.Data is LauncherData launcher)
{
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();

View file

@ -193,8 +193,8 @@ public abstract class ItemData : DatabaseEntry, INamedEntry
[InspectableText, JsonProperty("description"), Key(2)]
public string Description;
[InspectableText, JsonProperty("manufacturer"), Key(3)]
public string Manufacturer;
[InspectableDatabaseLink(typeof(MegaCorporation)), JsonProperty("creator"), Key(3)]
public Guid Manufacturer;
[InspectableField, JsonProperty("mass"), Key(4)]
public float Mass;

View file

@ -432,7 +432,7 @@ public class ItemManager
var data = GetData(item);
if(data is CraftedItemData c)
{
var i = CreateInstance(c, 0, 1);
var i = CreateInstance(c);
i.Rotation = item.Rotation;
return i;
}
@ -445,7 +445,7 @@ public class ItemManager
return null;
}
public CraftedItemInstance CreateInstance(CraftedItemData item, float qualityMin, float qualityMax)
public CraftedItemInstance CreateInstance(CraftedItemData item)
{
if (item == null)
{
@ -481,7 +481,7 @@ public class ItemManager
var craftedIngredientData = ItemData.Get<CraftedItemData>(ingredient.Key);
for (int i = 0; i < ingredient.Value; i++)
{
var itemInstance = CreateInstance(craftedIngredientData, qualityMin, qualityMax);
var itemInstance = CreateInstance(craftedIngredientData);
if (itemInstance == null)
{
invalidIngredientFound = true;
@ -499,6 +499,14 @@ public class ItemManager
{
_logger($"Unable to create crafted item ingredient: {invalidIngredient?.Name??"null"} for item {item.Name}");
}
var quality = Random.NextFloat();
var tier = GameplaySettings.Tiers[0];
foreach (var t in GameplaySettings.Tiers)
{
if (t.Rarity > quality)
tier = t;
}
if (item is EquippableItemData equippableItemData)
{
@ -506,7 +514,7 @@ public class ItemManager
{
Data = item.ID,
Ingredients = ingredients,
Quality = Random.NextFloat(qualityMin, qualityMax),
Quality = tier.Quality,
Blueprint = blueprint.ID,
Name = $"{item.Name}"
};
@ -518,134 +526,20 @@ public class ItemManager
{
Data = item.ID,
Ingredients = ingredients,
Quality = Random.NextFloat(qualityMin, qualityMax),
Quality = tier.Quality,
Blueprint = blueprint.ID,
Name = $"{item.Name}"
};
return newCommodity;
}
// class DijkstraNode
// {
// public float Cost;
// public DijkstraNode Parent;
// public ZoneDefinition Zone;
// }
//
// public List<ZoneDefinition> FindPath(ZoneDefinition source, ZoneDefinition target, bool bestFirst = false)
// {
// SortedList<float,DijkstraNode> members = new SortedList<float,DijkstraNode>{{0,new DijkstraNode{Zone = source}}};
// List<DijkstraNode> searched = new List<DijkstraNode>();
// while (true)
// {
// var s = members.FirstOrDefault(m => !searched.Contains(m.Value)).Value; // Lowest cost unsearched node
// if (s == null) return null; // No vertices left unsearched
// if (s.Zone == target) // We found the path
// {
// Stack<DijkstraNode> path = new Stack<DijkstraNode>(); // Since we start at the end, use a LIFO collection
// path.Push(s);
// while(path.Peek().Parent!=null) // Keep pushing until we reach the start, which has no parent
// path.Push(path.Peek().Parent);
// return path.Select(dv => dv.Zone).ToList();
// }
// // For each adjacent star (filter already visited zones unless heuristic is in use)
// foreach (var dijkstraStar in s.Zone.Links.WhereSelectF(i => !bestFirst || members.All(m => m.Value.Zone != GalaxyZones[i]),
// // Cost is parent cost plus distance
// i => new DijkstraNode {Parent = s, Zone = GalaxyZones[i], Cost = s.Cost + length(s.Zone.Position - GalaxyZones[i].Position)}))
// // Add new member to list, sorted by cost plus optional heuristic
// members.Add(bestFirst ? dijkstraStar.Cost + length(dijkstraStar.Zone.Position - target.Position) : dijkstraStar.Cost, dijkstraStar);
// searched.Add(s);
// }
// }
// public bool MoveCargo(Entity source, Entity target, ItemInstance item, int quantity = int.MaxValue)
// {
// if (item is CraftedItemInstance craftedItemInstance)
// {
// var craftedItemData = Cache.Get<CraftedItemData>(craftedItemInstance.Data);
// if (target.Capacity - target.OccupiedCapacity > craftedItemData.Size)
// {
// // Target has the cargo capacity for the item, simply move the instance
// source.Cargo.Remove(item.ID);
// target.Cargo.Add(item.ID);
// source.RecalculateMass();
// target.RecalculateMass();
// return true;
// }
// return false;
// }
//
// if (item is SimpleCommodity simpleCommoditySource)
// {
// quantity = min(quantity, simpleCommoditySource.Quantity);
// var simpleCommodityData = Cache.Get<SimpleCommodityData>(simpleCommoditySource.Data);
// var spareCapacity = (int) (target.Capacity - target.OccupiedCapacity);
// var simpleCommodityTarget = target.Cargo
// .Select(i => Cache.Get<ItemInstance>(i))
// .FirstOrDefault(i => i.Data == simpleCommodityData.ID) as SimpleCommodity;
// var success = spareCapacity >= quantity;
// quantity = min(quantity, spareCapacity);
// if (simpleCommodityTarget == null)
// {
// if (quantity == simpleCommoditySource.Quantity)
// {
// // Target has the cargo capacity to hold the full quantity,
// // and the target has no matching item instance;
// // simply move the existing item instance to the target
// source.Cargo.Remove(simpleCommoditySource.ID);
// target.Cargo.Add(simpleCommoditySource.ID);
// source.RecalculateMass();
// target.RecalculateMass();
// return success;
// }
// else
// {
// // Target has the cargo capacity to hold the desired quantity
// // and the target has no matching item instance;
// // Create a new item instance on the target and decrement the quantity of the source instance
// var newSimpleCommodity = new SimpleCommodity
// {
// Context = this,
// Data = simpleCommodityData.ID,
// Quantity = simpleCommoditySource.Quantity
// };
// Cache.Add(newSimpleCommodity);
// target.Cargo.Add(newSimpleCommodity.ID);
// simpleCommoditySource.Quantity -= quantity;
// source.RecalculateMass();
// target.RecalculateMass();
// return success;
// }
// }
// else
// {
// if (quantity == simpleCommoditySource.Quantity)
// {
// // Target has the cargo capacity to hold the full quantity,
// // and there is already a matching item instance;
// // delete the source entity's item instance and increment the target's quantity
// source.Cargo.Remove(simpleCommoditySource.ID);
// Cache.Delete(simpleCommoditySource);
// simpleCommodityTarget.Quantity += quantity;
// source.RecalculateMass();
// target.RecalculateMass();
// return success;
// }
// else
// {
// // Target has the cargo capacity to hold the desired quantity,
// // and there is already a matching item instance;
// // decrement the source's quantity and increment the target's quantity
// simpleCommoditySource.Quantity -= quantity;
// simpleCommodityTarget.Quantity += quantity;
// source.RecalculateMass();
// target.RecalculateMass();
// return success;
// }
// }
//
// }
//
// return false;
// }
public (RarityTier tier, int upgrades) GetTier(CraftedItemInstance item)
{
var tier = GameplaySettings.Tiers[0];
foreach (var t in GameplaySettings.Tiers)
if (item.Quality + .001f > t.Quality)
tier = t;
int upgrades = (int) ((item.Quality - tier.Quality) / .0499f);
return (tier, upgrades);
}
}

View file

@ -88,6 +88,7 @@ public class ZoneGenerationSettings
[Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject]
public class GameplaySettings
{
public RarityTier[] Tiers;
public float DefaultShutdownPerformance = .25f;
public float SevereHeatstrokeRiskThreshold = .25f;
public float WormholeDepth = 1000;
@ -129,4 +130,13 @@ public class GameplaySettings
public float AgentForwardLerp = .5f;
public float AgentMaxForwardDistance = 50;
public float AgentFiringMinDot = .99f;
}
[Serializable, MessagePackObject(keyAsPropertyName: true), JsonObject]
public class RarityTier
{
public string Name;
public float Quality;
public float3 Color;
public float Rarity;
}

View file

@ -71,6 +71,7 @@ public class PropertiesPanel : MonoBehaviour
//RemoveListener();
foreach(var property in Properties)
Destroy(property);
Title.text = "Properties";
Properties.Clear();
Buttons.Clear();
SelectedChild = null;
@ -340,34 +341,30 @@ public class PropertiesPanel : MonoBehaviour
{
AddField("Name", () => entity.Name, name => entity.Name = name);
AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
// AddProperty("Temperature", () => $"{entity.Temperature:0}°K");
// AddProperty("Energy", () => $"{entity.Energy:0}/{entity.GetBehavior<Reactor>()?.Capacitance??0:0}");
}
public void AddItemProperties(Entity entity, ItemInstance item)
{
var data = Context.ItemData.Get<ItemData>(item.Data);
AddProperty("Type", () => data.Name);
AddProperty(data.Description).Label.fontStyle = FontStyles.Normal;
// if (item is CraftedItemInstance craftedItemInstance)
// {
// var sourceEntity = Context.ItemData.Get<Entity>(craftedItemInstance.SourceEntity);
// if (sourceEntity != null)
// {
// var corporation = Context.ItemData.Get<Corporation>(sourceEntity.Corporation);
// AddProperty("Manufacturer", () => corporation.Name);
// }
// else
// {
// AddProperty("Manufacturer", () => "GameCult");
// }
// }
var manufacturer = Context.ItemData.Get<MegaCorporation>(data.Manufacturer);
if (manufacturer != null)
{
AddProperty("Manufacturer", () => manufacturer.Name);
}
else
{
AddProperty("Manufacturer", () => "GameCult");
}
if (item is SimpleCommodity simpleCommodity)
AddProperty("Quantity", () => simpleCommodity.Quantity.ToString());
AddProperty("Mass", () => Context.GetMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
AddProperty("Thermal Mass", () => Context.GetThermalMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
if (item is EquippableItem gear)
{
var tier = entity.ItemManager.GetTier(gear);
Title.text =
$"<color=#{ColorUtility.ToHtmlStringRGB(tier.tier.Color.ToColor())}>{gear.Name}</color><smallcaps><size=60%> ({tier.tier.Name}{new string('+', tier.upgrades)})";
var gearData = Context.GetData(gear);
AddProperty("Durability", () =>
$"{gear.Durability.SignificantDigits(Context.GameplaySettings.SignificantDigits)}/{gearData.Durability.SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
@ -497,53 +494,6 @@ public class PropertiesPanel : MonoBehaviour
() => 0, () => entity.Population - entity.AssignedPopulation + populationAssignment.AssignedPopulation);
if (behavior is Thermotoggle thermotoggle)
AddField("Target Temperature", () => thermotoggle.TargetTemperature, temp => thermotoggle.TargetTemperature = temp);
// if (behavior is Factory factory)
// {
// AddField("Production Quality", () => factory.ProductionQuality, f => factory.ProductionQuality = f, 0, 1);
// var corporation = Context.ItemData.Get<Corporation>(entity.Corporation);
// var compatibleBlueprints = corporation.UnlockedBlueprints
// .Select(id => Context.ItemData.Get<BlueprintData>(id))
// .Where(bp => bp.FactoryItem == item.ItemData.ID).ToList();
// if (factory.RetoolingTime > 0)
// {
// AddProgressField("Retooling", () => (factory.ToolingTime - (float) factory.RetoolingTime) / factory.ToolingTime);
// }
// else
// {
// AddField("Item",
// () => compatibleBlueprints.FindIndex(bp=>bp.ID== factory.Blueprint) + 1,
// i => factory.Blueprint = i == 0 ? Guid.Empty : compatibleBlueprints[i - 1].ID,
// new []{"None"}.Concat(compatibleBlueprints.Select(bp=>bp.Name)).ToArray());
// AddField("Active", () => factory.Active, active => factory.Active = active);
// if (factory.Blueprint != Guid.Empty)
// {
// if (factory.Active && factory.ItemUnderConstruction != Guid.Empty)
// {
// AddProgressField("Production", () =>
// {
// if (factory.ItemUnderConstruction == Guid.Empty) return 1;
// var itemInstance = Context.ItemData.Get<CraftedItemInstance>(factory.ItemUnderConstruction);
// var blueprintData = Context.ItemData.Get<BlueprintData>(itemInstance.Blueprint);
// return (blueprintData.ProductionTime - (float) entity.IncompleteCargo[factory.ItemUnderConstruction]) / blueprintData.ProductionTime;
// });
// }
// else
// {
// //AddField("Product Name", () => factory.ItemName, name => factory.ItemName = name);
// AddField("Product Name", () => factory.ItemName, name => factory.ItemName = name);
// var ingredientsList = AddList("Ingredients Needed");
// var blueprintData = Context.ItemData.Get<BlueprintData>(factory.Blueprint);
// foreach (var ingredient in blueprintData.Ingredients)
// {
// var itemData = Context.ItemData.Get<ItemData>(ingredient.Key);
// ingredientsList.AddProperty(itemData.Name, () => ingredient.Value.ToString());
// }
// // ingredientsList.SetExpanded(false, true);
// ingredientsList.RefreshValues();
// }
// }
// }
// }
}
}
RefreshValues();

View file

@ -355,7 +355,7 @@ public class TradeMenu : MonoBehaviour
{
if (data.Price < GameManager.Credits)
{
var hull = GameManager.ItemManager.CreateInstance(data, .1f, 1) as EquippableItem;
var hull = GameManager.ItemManager.CreateInstance(data) as EquippableItem;
Entity entity;
if(data.HullType==HullType.Ship)
entity = new Ship(GameManager.ItemManager, GameManager.Zone, hull);
@ -379,7 +379,7 @@ public class TradeMenu : MonoBehaviour
{
if (data.Price < GameManager.Credits)
{
if (_targetCargo.TryStore(GameManager.ItemManager.CreateInstance(data, .1f, 1)))
if (_targetCargo.TryStore(GameManager.ItemManager.CreateInstance(data)))
{
GameManager.Credits -= data.Price;
}

Binary file not shown.