/// <summary> /// Returns new instance of object to build with specified amount /// </summary> /// <param name="objectBuilder">Object builder</param> /// <param name="amount">Amount</param> /// <returns>New instance of object to build</returns> public static MyObjectToBuild CreateFromObjectBuilder(MyMwcObjectBuilder_Base objectBuilder, float amount) { MyBuildingSpecification buildingSpecification = MyBuildingSpecifications.GetBuildingSpecification(objectBuilder); MyObjectToBuild objectToBuild = new MyObjectToBuild(objectBuilder, buildingSpecification, amount); return(objectToBuild); }
/// <summary> /// Returns new instance of object to build with max amount from gameplay properties /// </summary> /// <param name="objectBuilder">Object builder</param> /// <returns>New instance of object to build</returns> public static MyObjectToBuild CreateFromObjectBuilder(MyMwcObjectBuilder_Base objectBuilder) { //warning: use default faction for get gameplay properties for creating object to build float amount = MyGameplayConstants.GetGameplayProperties(objectBuilder, MyMwcObjectBuilder_FactionEnum.Euroamerican).MaxAmount; return(MyObjectToBuild.CreateFromObjectBuilder(objectBuilder, amount)); }
public static bool HasSameObjectBuilders(MyObjectToBuild obj1, MyObjectToBuild obj2) { if (obj1 == null || obj2 == null) { return false; } else { return obj1.ObjectBuilder.GetObjectBuilderType() == obj2.ObjectBuilder.GetObjectBuilderType() && obj1.ObjectBuilder.GetObjectBuilderId() == obj2.ObjectBuilder.GetObjectBuilderId(); } }
public static bool HasSameObjectBuilders(MyObjectToBuild obj1, MyObjectToBuild obj2) { if (obj1 == null || obj2 == null) { return(false); } else { return(obj1.ObjectBuilder.GetObjectBuilderType() == obj2.ObjectBuilder.GetObjectBuilderType() && obj1.ObjectBuilder.GetObjectBuilderId() == obj2.ObjectBuilder.GetObjectBuilderId()); } }
public bool IsSame(MyObjectToBuild other) { if (other == null) { return false; } if(Amount != other.Amount) { return false; } bool hasSameObjectBuilder = ObjectBuilder.GetObjectBuilderType() == other.ObjectBuilder.GetObjectBuilderType() && ObjectBuilder.GetObjectBuilderId() == other.ObjectBuilder.GetObjectBuilderId(); if(ObjectBuilder is MyMwcObjectBuilder_PrefabBase) { hasSameObjectBuilder = hasSameObjectBuilder && ((MyMwcObjectBuilder_PrefabBase) ObjectBuilder).FactionAppearance == ((MyMwcObjectBuilder_PrefabBase) other.ObjectBuilder).FactionAppearance; } return hasSameObjectBuilder; }
public bool IsSame(MyObjectToBuild other) { if (other == null) { return(false); } if (Amount != other.Amount) { return(false); } bool hasSameObjectBuilder = ObjectBuilder.GetObjectBuilderType() == other.ObjectBuilder.GetObjectBuilderType() && ObjectBuilder.GetObjectBuilderId() == other.ObjectBuilder.GetObjectBuilderId(); if (ObjectBuilder is MyMwcObjectBuilder_PrefabBase) { hasSameObjectBuilder = hasSameObjectBuilder && ((MyMwcObjectBuilder_PrefabBase)ObjectBuilder).FactionAppearance == ((MyMwcObjectBuilder_PrefabBase)other.ObjectBuilder).FactionAppearance; } return(hasSameObjectBuilder); }
/// <summary> /// Returns new instance of object to build with specified amount /// </summary> /// <param name="objectBuilder">Object builder</param> /// <param name="amount">Amount</param> /// <returns>New instance of object to build</returns> public static MyObjectToBuild CreateFromObjectBuilder(MyMwcObjectBuilder_Base objectBuilder, float amount) { MyBuildingSpecification buildingSpecification = MyBuildingSpecifications.GetBuildingSpecification(objectBuilder); MyObjectToBuild objectToBuild = new MyObjectToBuild(objectBuilder, buildingSpecification, amount); return objectToBuild; }
/// <summary> /// Changes inventory item's amount. When add/remove object to/from building queue /// </summary> /// <param name="remove">Remove = true, Add = false</param> /// <param name="ratio">Ratio of item's amount</param> /// <param name="objectToBuild">Object to build</param> private void ChangeInventoryItemsAmount(bool remove, float ratio, MyObjectToBuild objectToBuild) { foreach (IMyBuildingRequirement buildingRequirement in objectToBuild.BuildingSpecification.BuildingRequirements) { MyBuildingRequirementInventoryItem buildingRequirementInventoryItem = buildingRequirement as MyBuildingRequirementInventoryItem; if (buildingRequirementInventoryItem != null) { if (buildingRequirementInventoryItem.RemoveAfterBuild) { if (remove) { Player.Ship.Inventory.RemoveInventoryItemAmount(buildingRequirementInventoryItem.ObjectBuilderType, buildingRequirementInventoryItem.ObjectBuilderId, buildingRequirementInventoryItem.Amount * ratio); } else { Player.Ship.Inventory.AddInventoryItem(buildingRequirementInventoryItem.ObjectBuilderType, buildingRequirementInventoryItem.ObjectBuilderId, buildingRequirementInventoryItem.Amount * ratio, false); } } } } }
/// <summary> /// Removes build object from build objects collection /// </summary> /// <param name="objectToBuild">Build object</param> public void RemoveFromBuildObjects(MyObjectToBuild objectToBuild) { BuildObjects.Remove(objectToBuild); }
/// <summary> /// Removes object from building queue /// </summary> /// <param name="objectToBuild">Object to build</param> public void RemoveFromBuildingQueue(MyObjectToBuild objectToBuild) { int indexOfLastObjectToBuild = BuildingQueue.FindLastIndex(x => x == objectToBuild); if(indexOfLastObjectToBuild >= 0) { BuildingQueue.RemoveAt(indexOfLastObjectToBuild); } ChangeInventoryItemsAmount(false, MyFoundationFactoryConstants.RETURN_AMOUNT_RATIO, objectToBuild); }
/// <summary> /// Adds object to building queue /// </summary> /// <param name="objectToBuild">Object to build</param> public void AddToBuildingQueue(MyObjectToBuild objectToBuild) { if(!objectToBuild.BuildingSpecification.CanBuild(this)) { throw new Exception("You can't build this!"); } BuildingQueue.Add(objectToBuild); ChangeInventoryItemsAmount(true, 1f, objectToBuild); if(!IsBuilding) { StartBuilding(); } }