private void Awake() { if (!reagentContainer) { reagentContainer = GetComponent <ReagentContainer>(); } }
private void EnsureInit() { if (pickupable != null) { return; } pickupable = GetComponent <Pickupable>(); itemAtts = GetComponent <ItemAttributesV2>(); registerTile = GetComponent <RegisterTile>(); fireSource = GetComponent <FireSource>(); reagentContainer = GetComponent <ReagentContainer>(); if (reagentContainer != null) { reagentContainer.OnSpillAllContents.AddListener(ServerEmptyWelder); } damageOff = itemAtts.ServerHitDamage; //leftHandOriginal = itemAtts.inHandReferenceLeft; //rightHandOriginal = itemAtts.inHandReferenceRight; leftHandFlame = leftHandOriginal + 4; rightHandFlame = rightHandOriginal + 4; }
public override bool Interact(GameObject originator, Vector3 position, string hand) { if (UIManager.Hands.CurrentSlot.Item != gameObject) { return(base.Interact(originator, position, hand)); } var targetWorldPos = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition); if (PlayerManager.PlayerScript.IsInReach(targetWorldPos) && extinguisher.isOn) { if (!isServer) { InteractMessage.Send(gameObject, hand); } else { //Play sound and call spray SoundManager.PlayNetworkedAtPos("Extinguish", targetWorldPos); ReagentContainer cleanerContainer = GetComponent <ReagentContainer>(); StartCoroutine(Spray.TriggerSpray(cleanerContainer, targetWorldPos, extinguish)); } } return(base.Interact(originator, position, hand)); }
private void Milk(GameObject performer, ReagentContainer container) { if (currentMilkAmount < milkAmount) { onMilkedEmpty?.Invoke(performer, gameObject); mood.UpdateLevel(moodPenalty * -1); Chat.AddActionMsgToChat( performer, string.Format(noMilkMessage, performer.ExpensiveName(), mobAI.mobName.Capitalize()), "" ); return; } Chat.AddActionMsgToChat( performer, string.Format(milkMessageYou, mobAI.mobName.Capitalize()), string.Format(milkMessageOthers, mobAI.mobName.Capitalize(), performer.ExpensiveName()) ); currentMilkAmount -= milkAmount; var milkyMix = new ReagentMix(milkReagent, milkAmount, 40f); container.Add(milkyMix); }
private static void AssertContainerContentsEqualTo(ReagentContainer container, Dictionary <string, float> expected) { Assert.AreEqual(expected.Count, container.Contents.Count); foreach (var pair in expected) { Assert.IsTrue(container.Contents.TryGetValue(pair.Key, out float val)); Assert.AreEqual(pair.Value, val, 0.00000001, $"Wrong amount of {pair.Key}."); } }
private static ReagentContainer GetContainer(int maxCapacity, ReagentMix contents) { var set = ScriptableObject.CreateInstance <ReactionSet>(); var container = ReagentContainer.Create(set, maxCapacity); container.Add(contents); return(container); }
private void Awake() { pickupable = GetComponent <Pickupable>(); serverContainer = GetComponent <ReagentContainer>(); if (serverContainer) { serverContainer.OnReagentMixChanged.AddListener(ServerUpdateFillState); } }
protected override void ServerPerformInteraction(HandApply interaction) { //put the reagant container inside me Container = interaction.HandObject.GetComponent <ReagentContainer>(); objectse = interaction.HandObject.GetComponentInChildren <ObjectBehaviour> (); var slot = InventoryManager.GetSlotFromOriginatorHand(interaction.Performer, interaction.HandSlot.equipSlot); InventoryManager.ClearInvSlot(slot); UpdateGUI(); }
/// <summary> /// Grind up the object. /// </summary> public void GrindFood() { if (isServer) { audioSourceGrind.Play(); grinderStorage = GetComponent <ReagentContainer>(); grinderStorage.Add(new ReagentMix(CraftingManager.Grind.FindOutputReagent(grind), outputAmount)); } grind = null; }
private void Awake() { BlewUp = false; objectBehaviour = GetComponent <ObjectBehaviour>(); registerObject = GetComponent <RegisterObject>(); integrity = GetComponent <Integrity>(); reagentContainerScript = GetComponent <ReagentContainer>(); reagentContainerObjectInteractionScript = GetComponent <ReagentContainerObjectInteractionScript>(); integrity.OnWillDestroyServer.AddListener(WhenDestroyed); }
private static ReagentContainer GetContainer(int maxCapacity, Dictionary <string, float> contents) { GameObject obj = new GameObject(); obj.AddComponent <ReagentContainer>(); ReagentContainer container = obj.GetComponent <ReagentContainer>(); container.MaxCapacity = maxCapacity; container.AddReagents(contents); return(container); }
public override void OnEventStartTimed() { ReagentContainer container = Instantiate(reagentContainer).GetComponent <ReagentContainer>(); foreach (var scrubber in FindObjectsOfType <Scrubber>()) { StartCoroutine(SpillAtScrubber(scrubber, container)); } StartCoroutine(DeleteContainer(container)); }
private static void AssertContainerContentsEqualTo(ReagentContainer container, ReagentMix expected) { container.Clean(); expected.Clean(); Assert.AreEqual(expected.Count(), container.Count()); foreach (var pair in expected) { var val = container[pair.Key]; Assert.IsTrue(val != null); Assert.AreEqual(pair.Value, val, 0.00000001, $"Wrong amount of {pair.Key}."); } }
private static ReagentContainer GetContainer(int maxCapacity, ReagentMix contents) { GameObject obj = new GameObject(); obj.AddComponent <ReagentContainer>(); ReagentContainer container = obj.GetComponent <ReagentContainer>(); container.ReactionSet = new ReactionSet(); container.maxCapacity = maxCapacity; container.Add(contents); return(container); }
private void Awake() { if (!fillSpriteRender) { return; } fillSpriteHandler = fillSpriteRender.GetComponent <SpriteHandler>(); serverContainer = GetComponent <ReagentContainer>(); if (serverContainer) { serverContainer.OnReagentMixChanged.AddListener(ServerUpdateFillState); } }
void Awake() { pickupable = GetComponent <Pickupable>(); reagentContainer = GetComponent <ReagentContainer>(); itemAtts = GetComponent <ItemAttributesV2>(); registerTile = GetComponent <RegisterTile>(); damageOff = itemAtts.ServerHitDamage; //leftHandOriginal = itemAtts.inHandReferenceLeft; //rightHandOriginal = itemAtts.inHandReferenceRight; leftHandFlame = leftHandOriginal + 4; rightHandFlame = rightHandOriginal + 4; }
private void Awake() { FoodContents = GetComponent <ReagentContainer>(); item = GetComponent <RegisterItem>(); itemAttributes = GetComponent <ItemAttributesV2>(); stackable = GetComponent <Stackable>(); if (itemAttributes != null) { itemAttributes.AddTrait(CommonTraits.Instance.Food); } else { Logger.LogErrorFormat("{0} prefab is missing ItemAttributes", Category.Objects, name); } }
public void MoveReagentsTo(int Amount, ReagentContainer To = null) { float Using = new float(); CurrentCapacity = AmountOfReagents(Contents); if (To != null) { if ((To.CurrentCapacity + Amount) > To.MaxCapacity) { Using = To.MaxCapacity - To.CurrentCapacity; } else { Using = Amount; } } else { Using = Amount; } double DivideAmount = Using / CurrentCapacity; Dictionary <string, float> Transfering = new Dictionary <string, float> (); List <string> keys = new List <string>(Contents.Keys); for (int i = 0; i < keys.Count; i++) { if ((Contents[keys[i]] * DivideAmount) > Contents[keys[i]]) { Transfering[keys[i]] = Contents[keys[i]]; Contents[keys[i]] = 0; } else { Transfering[keys[i]] = (float)(Contents[keys[i]] * DivideAmount); Contents[keys[i]] = Contents[keys[i]] - Transfering[keys[i]]; } } if (To != null) { To.AddReagents(Transfering, Temperature); } CurrentCapacity = AmountOfReagents(Contents); CheckForEmptys(); }
public override bool Interact(GameObject originator, Vector3 position, string hand) { ofthis = this.gameObject; var playerScript = originator.GetComponent <PlayerScript>(); if (playerScript.canNotInteract() || !playerScript.IsInReach(gameObject)) { //check for both client and server return(true); } if (!isServer) { //Client wants this code to be run on server InteractMessage.Send(gameObject, hand); } else { //Server actions if (Container == null) { PlayerScript ps = originator.GetComponent <PlayerScript>(); if (ps.canNotInteract() || !ps.IsInReach(position)) { return(false); } var slot = InventoryManager.GetSlotFromOriginatorHand(originator, hand); var stContainer = slot.Item?.GetComponentInChildren <ReagentContainer>(); if (stContainer != null) { Container = stContainer; //Logger.Log ("set!!"); GameObject item = ps.playerNetworkActions.Inventory[hand].Item; objectse = item.GetComponentInChildren <ObjectBehaviour> (); InventoryManager.UpdateInvSlot(true, "", slot.Item, slot.UUID); UpdateGUI(); return(true); } TabUpdateMessage.Send(originator, gameObject, NetTabType, TabAction.Open); } else { TabUpdateMessage.Send(originator, gameObject, NetTabType, TabAction.Open); } } return(true); }
public void MoveReagentsTo(int Amount, ReagentContainer To = null) { float Using = new float(); CurrentCapacity = AmountOfReagents(Contents); if (To != null) { if ((To.CurrentCapacity + Amount) > To.MaxCapacity) { Using = To.MaxCapacity - To.CurrentCapacity; } else { Using = Amount; } } else { Using = Amount; } double DivideAmount = Using / CurrentCapacity; Dictionary <string, float> Transfering = new Dictionary <string, float> (); Dictionary <string, float> BrokenCS = new Dictionary <string, float> (Contents); foreach (KeyValuePair <string, float> Chemical in BrokenCS) { if ((Chemical.Value * DivideAmount) > Contents [Chemical.Key]) { Transfering [Chemical.Key] = Contents [Chemical.Key]; Contents [Chemical.Key] = 0; } else { Transfering [Chemical.Key] = (float)(Chemical.Value * DivideAmount); Contents [Chemical.Key] = Contents [Chemical.Key] - Transfering [Chemical.Key]; } } if (To != null) { To.AddReagents(Transfering, Temperature); } CurrentCapacity = AmountOfReagents(Contents); CheckForEmptys(); }
private static void AssertContainerContentsEqualTo(ReagentContainer container, ReagentMix expected) { Assert.AreEqual(expected.Count(), container.Count()); foreach (var pair in expected) { var val = container[pair.Key]; if (pair.Key) { Assert.AreEqual(pair.Value, val, 0.00000001, $"Wrong amount of {pair.Key}."); } else { Assert.AreEqual(pair.Value, val, 0.00000001); } } }
public void MoveReagentsTo(int amount, ReagentContainer target = null) { CurrentCapacity = AmountOfReagents(Contents); float toMove = target == null ? amount : Math.Min(target.MaxCapacity - target.CurrentCapacity, amount); float divideAmount = toMove / CurrentCapacity; var transfering = Contents.ToDictionary( reagent => reagent.Key, reagent => divideAmount > 1 ? reagent.Value : (reagent.Value * divideAmount) ); foreach (var reagent in transfering) { Contents[reagent.Key] -= reagent.Value; } Contents = Calculations.RemoveEmptyReagents(Contents); CurrentCapacity = AmountOfReagents(Contents); target?.AddReagents(transfering, Temperature); }
public void MoveReagentsTo(int amount, ReagentContainer target = null) { CurrentCapacity = AmountOfReagents(Contents); float toMove = target == null ? amount : Math.Min(target.MaxCapacity - target.CurrentCapacity, amount); float divideAmount = toMove / CurrentCapacity; var transfering = Contents.ToDictionary( chemical => chemical.Key, chemical => divideAmount > 1 ? chemical.Value : (chemical.Value * divideAmount) ); foreach (var chemical in transfering) { Contents[chemical.Key] -= chemical.Value; } RemoveEmptyChemicals(); CurrentCapacity = AmountOfReagents(Contents); target?.AddReagents(transfering, Temperature); }
private void Awake() { FoodContents = GetComponent <ReagentContainer>(); item = GetComponent <RegisterItem>(); itemAttributes = GetComponent <ItemAttributesV2>(); stackable = GetComponent <Stackable>(); FoodContents.Add(new ReagentMix(Nutriment, StartingNutrients, TemperatureUtils.ToKelvin(20f, TemeratureUnits.C))); if (itemAttributes != null) { itemAttributes.AddTrait(CommonTraits.Instance.Food); } else { Logger.LogErrorFormat("{0} prefab is missing ItemAttributes", Category.Objects, name); } }
private void EnsureInit() { if (pickupable != null) { return; } pickupable = GetComponent <Pickupable>(); reagentContainer = GetComponent <ReagentContainer>(); itemAtts = GetComponent <ItemAttributesV2>(); registerTile = GetComponent <RegisterTile>(); damageOff = itemAtts.ServerHitDamage; //leftHandOriginal = itemAtts.inHandReferenceLeft; //rightHandOriginal = itemAtts.inHandReferenceRight; leftHandFlame = leftHandOriginal + 4; rightHandFlame = rightHandOriginal + 4; }
private void Drink(PlayerScript eater, PlayerScript feeder) { // Start drinking reagent mix var drinkAmount = container.TransferAmount; List <Stomach> stomachs = eater.playerHealth.GetStomachs(); foreach (Stomach currentStomach in stomachs) { ReagentContainer stomachContainer = currentStomach.StomachContents; //fill current stomach as much as we can until empty float transferred = Mathf.Min(drinkAmount, stomachContainer.MaxCapacity - stomachContainer.CurrentReagentMix.Total); container.TransferTo(transferred, stomachContainer); //update how much is left drinkAmount -= transferred; //Yeetity, it's empty if (drinkAmount <= 0) { break; } //We didn't empty the drink, but maybe emptying the drink was the friends we made along the way if (stomachs.LastOrDefault() == currentStomach) { Chat.AddExamineMsgFromServer(eater.gameObject, "You cannot drink anymore!"); if (eater != feeder) { Chat.AddExamineMsgFromServer(feeder.gameObject, $"{eater.visibleName} cannot seem to drink anymore!"); } } } // Play sound if (item && drinkSound != null) { AudioSourceParameters audioSourceParameters = new AudioSourceParameters(RandomPitch, spatialBlend: 1f); SoundManager.PlayNetworkedAtPos(drinkSound, eater.WorldPos, audioSourceParameters, sourceObj: eater.gameObject); } }
private void Awake() { if (!data || !mainSpriteRender) { return; } fillVisual = GetComponent <ReagentContainerFillVisualisation>(); pickupable = GetComponent <Pickupable>(); serverContainer = GetComponent <ReagentContainer>(); item = GetComponent <ItemAttributesV2>(); // save default data defaultSprite = mainSpriteRender.sprite; if (serverContainer) { serverContainer.OnReagentMixChanged.AddListener(OnMixChanged); } }
private IEnumerator SpillAtScrubber(Scrubber scrubber, ReagentContainer container) { yield return(WaitFor.Seconds(Random.Range(spawnDelayRange.x, spawnDelayRange.y))); // Check that the scrubber is still fine to reference after this delay. if (scrubber == null || scrubber.registerTile == null) { yield break; } var reagentMix = new ReagentMix(); reagentMix.reagents.m_dict.Add(allReagents.PickRandom(), 75f); reagentMix.reagents.m_dict.Add(dispersionAgents.PickRandom(), 25f); container.Add(reagentMix); container.Spill(scrubber.registerTile.WorldPositionServer, 50f); // TODO: Play noise. }
public override bool Interact(GameObject originator, Vector3 position, string hand) { if (!CanUse(originator, hand, position, false)) { return(false); } if (!isServer) { //ask server to perform the interaction InteractMessage.Send(gameObject, position, hand); return(true); } if (Container == null) { PlayerScript ps = originator.GetComponent <PlayerScript>(); if (ps.canNotInteract() || !ps.IsInReach(position, true)) { return(false); } var slot = InventoryManager.GetSlotFromOriginatorHand(originator, hand); var stContainer = slot.Item?.GetComponentInChildren <ReagentContainer>(); if (stContainer != null) { Container = stContainer; //Logger.Log ("set!!"); GameObject item = ps.playerNetworkActions.Inventory[hand].Item; objectse = item.GetComponentInChildren <ObjectBehaviour> (); InventoryManager.UpdateInvSlot(true, "", slot.Item, slot.UUID); UpdateGUI(); return(true); } TabUpdateMessage.Send(originator, gameObject, NetTabType, TabAction.Open); } else { TabUpdateMessage.Send(originator, gameObject, NetTabType, TabAction.Open); } return(true); }
public void DispenseProduct(int productId, int numberOfProduct, string newName) { ReagentMix temp = GetBufferMix(); //Do Math float maxProductAmount = ChemMasterProducts[productId].GetComponent <ReagentContainer>().MaxCapacity; float maxTotalAllProducts = maxProductAmount * numberOfProduct; float amountPerProduct = ((maxTotalAllProducts > temp.Total) ? temp.Total : maxTotalAllProducts) / numberOfProduct; for (int i = 0; i < numberOfProduct; i++) { //Spawn Object var product = Spawn.ServerPrefab(ChemMasterProducts[productId], gameObject.WorldPosServer(), transform.parent).GameObject; //Fill Product ReagentContainer productContainer = product.GetComponent <ReagentContainer>(); if (amountPerProduct <= productContainer.MaxCapacity) { temp.TransferTo(productContainer.CurrentReagentMix, amountPerProduct); } else { temp.TransferTo(productContainer.CurrentReagentMix, productContainer.MaxCapacity); } //Give it some color productContainer.OnReagentMixChanged?.Invoke(); //Give it some love product.GetComponent <ItemAttributesV2>().ServerSetArticleName($"{newName}" + $" {product.GetComponent<ItemAttributesV2>().InitialName}"); } ClearBuffer(); TransferMixToBuffer(temp); UpdateGui(); }