public EquippedEventBase(EntityUid equipee, EntityUid equipment, SlotDefinition slotDefinition) { Equipee = equipee; Equipment = equipment; Slot = slotDefinition.Name; SlotFlags = slotDefinition.SlotFlags; }
private void UpdateVisuals(SlotDefinition definition, float percent, TechType batteryTechType) { definition.battery.SetActive(false); definition.batteryIon.SetActive(false); (batteryTechType == TechType.PrecursorIonBattery ? definition.batteryIon : definition.battery).SetActive(percent >= 0f); TextMeshProUGUI text = definition.text; if (text != null) { text.text = ((percent >= 0f) ? string.Format("{0:P0}", percent) : Language.main.Get("ChargerSlotEmpty")); } Image bar = definition.bar; if (bar != null) { Material material = bar.material; if (percent >= 0f) { Color value = (percent < 0.5f) ? Color.Lerp(colorEmpty, colorHalf, 2f * percent) : Color.Lerp(colorHalf, colorFull, 2f * percent - 1f); material.SetColor(ShaderPropertyID._Color, value); material.SetFloat(ShaderPropertyID._Amount, percent); return; } material.SetColor(ShaderPropertyID._Color, colorEmpty); material.SetFloat(ShaderPropertyID._Amount, 0f); } }
public UnequipAttemptEventBase(EntityUid unequipee, EntityUid unEquipTarget, EntityUid equipment, SlotDefinition slotDefinition) { UnEquipTarget = unEquipTarget; Equipment = equipment; Unequipee = unequipee; Slot = slotDefinition.Name; }
/// <summary> /// Adds the slot to drawing. /// </summary> /// <returns>SlotDefinition.</returns> internal SlotDefinition AddSlot() { var slot = new SlotDefinition(); Drawing.AddSlot(slot); return(slot); }
public EquipAttemptBase(EntityUid equipee, EntityUid equipTarget, EntityUid equipment, SlotDefinition slotDefinition) { EquipTarget = equipTarget; Equipment = equipment; Equipee = equipee; SlotFlags = slotDefinition.SlotFlags; Slot = slotDefinition.Name; }
public Product(string reference, string name, string description, string categoryReference, Price price, SlotDefinition slotDef) { this.Reference = reference; this.Name = name; this.Description = description; this.CategoryReference = categoryReference; this.Price = price; this.SlotDefinition = slotDef; }
public Product(string reference, string name, string description, string categoryReference, Price price, List <Part> parts, List <ProductMaterial> productMaterialList, List <DimensionValues> dimensions, SlotDefinition slotDef) { this.Reference = reference; this.Name = name; this.Description = description; this.CategoryReference = categoryReference; this.Price = price; this.Parts = parts; this.ProductMaterialList = productMaterialList; this.Dimensions = dimensions; this.SlotDefinition = slotDef; }
/// <summary> /// Draws the catalog. /// </summary> /// <param name="drawer">The drawer.</param> /// <param name="slot">The slot.</param> private void drawCatalog(InstanceDrawer drawer, SlotDefinition slot) { var composableCatalog = ComposableCatalog.Get(); if (composableCatalog != null) { var catalogDrawing = drawer.GetInstanceDrawing(composableCatalog); slot.Add(catalogDrawing.Reference); } foreach (var composedPart in DirectChildren.Value) { var partDrawing = drawer.GetInstanceDrawing(composedPart); slot.Add(partDrawing.Reference); } }
public static bool AddPart(IItemStack parent, string slotName, ItemStack partstack) { IModularItem item = parent.Item as IModularItem; IToolPart part = partstack.Item as IToolPart; if (item != null && part != null) { SlotDefinition[] slotdefs = GetSlotDefinitions(item); SlotDefinition slot = slotdefs?.First(s => s.SlotName == slotName); if (slot?.ValidPartTypes?.Any(type => part.TinkerProps.PartType == type) == true) { return(ApplyPart(parent, slotName, partstack)); } } return(false); }
public static void OnLoaded(ICoreAPI api, Item item) { if (item.Attributes != null && item.Attributes.KeyExists("tinkerProps")) { TinkerProperties TinkerProps = item.Attributes["tinkerProps"].AsObject <TinkerProperties>(); if (TinkerProps.UseBuiltinSlots) { var defs = new SlotDefinition[3]; defs[0] = new SlotDefinition(); defs[0].SlotName = "toolhead"; defs[0].ValidPartTypes = new string[1]; defs[0].ValidPartTypes[0] = "toolhead"; defs[0].OffsetX = -60.0; defs[0].OffsetY = -90.0; defs[1] = new SlotDefinition(); defs[1].SlotName = "binding"; defs[1].Optional = true; defs[1].ValidPartTypes = new string[1]; defs[1].ValidPartTypes[0] = "binding"; defs[1].OffsetX = 60.0; defs[1].OffsetY = -90.0; defs[2] = new SlotDefinition(); defs[2].SlotName = "handle"; defs[2].ValidPartTypes = new string[1]; defs[2].ValidPartTypes[0] = "handle"; defs[2].OffsetY = 90.0; if (TinkerProps.AvailableSlots != null) { defs = defs.Concat(TinkerProps.AvailableSlots).ToArray(); } TinkerProps.AvailableSlots = defs; } (item as IModularItem).TinkerProps = TinkerProps; } }
private void DropOptionalParts() { Vec3d spawnPos = Pos.ToVec3d(); spawnPos.Y += 1.1; SlotDefinition[] slots = (Inventory[0].Itemstack.Item as IModularItem).GetSlotDefinitions(); for (int i = 1; i < Inventory.Count; ++i) { ItemStack stack = Inventory[i].Itemstack; SlotDefinition slot = slots[i - 1]; ToolPart part = stack?.Item as ToolPart; if (part == null || !slot.ValidPartTypes.Contains(part.TinkerProps.PartType) || slot.Optional) { Api.World.SpawnItemEntity(stack, spawnPos); Inventory[i].Itemstack = null; } } }
private void Initialize() { if (equipment == null) { equipment = new Equipment(gameObject, EquipmentRoot.transform); equipment.SetLabel(labelStorage); equipment.isAllowedToAdd = new IsAllowedToAdd(IsAllowedToAdd); equipment.onEquip += OnEquip; equipment.onUnequip += OnUnequip; batteries = new Dictionary <string, IBattery>(); slots = new Dictionary <string, SlotDefinition>(); int i = 0; int count = slotDefinitions.Count; while (i < count) { SlotDefinition slotDefinition = slotDefinitions[i]; string id = slotDefinition.id; if (!string.IsNullOrEmpty(id) && !batteries.ContainsKey(id)) { batteries[id] = null; slots[id] = slotDefinition; Image bar = slotDefinition.bar; if (bar != null) { bar.material = new Material(bar.material); } } i++; } UnlockDefaultEquipmentSlots(); UpdateVisuals(); } }
public IsUnequippingAttemptEvent(EntityUid unequipee, EntityUid unEquipTarget, EntityUid equipment, SlotDefinition slotDefinition) : base(unequipee, unEquipTarget, equipment, slotDefinition) { }
public DidUnequipEvent(EntityUid equipee, EntityUid equipment, SlotDefinition slotDefinition) : base(equipee, equipment, slotDefinition) { }
public BeingEquippedAttemptEvent(EntityUid equipee, EntityUid equipTarget, EntityUid equipment, SlotDefinition slotDefinition) : base(equipee, equipTarget, equipment, slotDefinition) { }
public GotUnequippedEvent(EntityUid equipee, EntityUid equipment, SlotDefinition slotDefinition) : base(equipee, equipment, slotDefinition) { }
private void OnSlotModified(int slot) { if (Api.Side == EnumAppSide.Server) { bool dirty = false; if (slot == 0) { if (Inventory[0].Itemstack == null) { DropInvalidParts(); inventory.Resize(4); dirty = true; } else if (Inventory[0].Itemstack != null) { // Drop any items that are not ToolPart into the world DropInvalidParts(); IModularItem item = Inventory[0].Itemstack?.Item as IModularItem; if (item != null) { // Fill part slots SlotDefinition[] slotdefs = item.TinkerProps.AvailableSlots; if (slotdefs != null) { inventory.Resize(slotdefs.Length + 1); var slots = item.GetSlots(Inventory[0].Itemstack); for (int i = 0; i < slotdefs.Length; ++i) { var toolpart = slots[slotdefs[i].SlotName]; Inventory[i + 1].Itemstack = toolpart; } } else { DropParts(); inventory.Resize(1); } } else { // Not a valid IModularItem, so no slots DropParts(); inventory.Resize(1); } dirty = true; } } else { if (Inventory[0].Itemstack != null) { int partindex = slot - 1; IModularItem item = Inventory[0].Itemstack.Item as IModularItem; SlotDefinition[] slotdefs = item.TinkerProps.AvailableSlots; // Only apply the part if it inside the number of available slots if (partindex < slotdefs?.Length) { SlotDefinition slotdef = slotdefs[partindex]; item.RemovePart(Inventory[0].Itemstack, slotdef.SlotName); ToolPart part = Inventory[slot].Itemstack?.Item as ToolPart; if (part != null) { item.AddPart(Inventory[0].Itemstack, slotdef.SlotName, Inventory[slot].Itemstack); } } if (!item.HasNeededParts(Inventory[0].Itemstack)) { DropOptionalParts(); Inventory[0].Itemstack = null; } } else { ToolPart toolhead = Inventory[1].Itemstack?.Item as ToolPart; ToolPart handle = Inventory[3].Itemstack?.Item as ToolPart; if (toolhead != null && handle != null && toolhead.TinkerProps.ResultItem != null) { IModularTool result = Api.World.GetItem(new AssetLocation(toolhead.TinkerProps.ResultItem)) as IModularTool; if (result != null) { Inventory[0].Itemstack = new ItemStack(result as Item, 1); if (!(result.AddPart(Inventory[0].Itemstack, "toolhead", Inventory[1].Itemstack) && result.AddPart(Inventory[0].Itemstack, "handle", Inventory[3].Itemstack))) { Inventory[0].Itemstack = null; } } } } dirty = true; } if (lastStack?.Item == null || lastStack.Item is IModularItem) { lastStack = Inventory[0].Itemstack; } // Resend the inventory if needed if (dirty) { byte[] data; using (MemoryStream ms = new MemoryStream()) { BinaryWriter writer = new BinaryWriter(ms); TreeAttribute tree = new TreeAttribute(); inventory.ToTreeAttributes(tree); tree.ToBytes(writer); data = ms.ToArray(); } foreach (string guid in Inventory.openedByPlayerGUIds) { IServerPlayer player = Api.World.PlayerByUid(guid) as IServerPlayer; // Make sure that only online players recieve the update if (player.ConnectionState != EnumClientState.Offline) { UpdateInventory(player, data); } } } } }