public static bool CanLaunch(Weapon weapon, IWIBase projectileBase) { if (weapon == null || projectileBase == null) { return(false); //whoops } if (!projectileBase.Is <Projectile>()) { return(false); //can't launch it if it's not a projectile } //find out of the projectile keyword matches WorldItem projectileWorldItem = null; if (projectileBase.IsWorldItem) { projectileWorldItem = projectileBase.worlditem; } else if (!WorldItems.Get.PackPrefab(projectileBase.PackName, projectileBase.PrefabName, out projectileWorldItem)) { return(false); } //alright, see if the projectile type matches Projectile projectile = null; if (projectileWorldItem.Is <Projectile>(out projectile)) { return(weapon.ProjectileType == projectile.ProjectileType); } return(false); }
public bool FillLiquidContainer(IWIBase liquidContainer, IWIBase foodStuff, WIStack foodStuffStack) { if (!foodStuff.Is <FoodStuff>()) { //nope! can't do it return(false); } System.Object fssObject = null; //check the foodstuff first since it has to be liquid if (foodStuff.GetStateOf <FoodStuff>(out fssObject)) { FoodStuffState fss = (FoodStuffState)fssObject; if (fss.IsLiquid(foodStuff.State)) { //okay we've confirmed it's a liquid //now see if the liquid container can hold it if (!liquidContainer.Is <LiquidContainer>()) { //we're returning true because it'll make the correct noise and the item will disappear GUIManager.PostWarning("The liquid cannot be held by this container. It seeps away."); foodStuff.RemoveFromGame(); return(true); } System.Object lcObject = null; if (liquidContainer.GetStateOf <LiquidContainer>(out lcObject)) { LiquidContainerState lcs = (LiquidContainerState)lcObject; string liquidFillError = string.Empty; int numFilled = 0; GenericWorldItem genericLiquid = new GenericWorldItem(foodStuff); if (lcs.TryToFillWith(genericLiquid, foodStuffStack.NumItems, out numFilled, out liquidFillError)) { //hooray, it worked //how we have to pop items off the top of the food stuff stack for (int i = 0; i < numFilled; i++) { Stacks.Pop.AndToss(foodStuffStack); } GUIManager.PostInfo("Filled " + numFilled.ToString()); return(true); } else { GUIManager.PostWarning(liquidFillError); } } } } return(false); }
public static bool ConsumeRequirement(WIStack itemStack, IWIBase item, GenericWorldItem template, bool requirementsMet) { if (!requirementsMet) { return(false); } bool result = false; if (item.Is <LiquidContainer> ()) { //see if the thing inside the liquid container has what we need bool foundState = false; LiquidContainerState state = null; System.Object stateObject = null; if (item.GetStateOf <LiquidContainer> (out stateObject)) { state = (LiquidContainerState)stateObject; foundState = state != null; } if (foundState) { //hooray it is a liquid if (!state.IsEmpty) { //and it's not empty so steal one state.Contents.InstanceWeight--; result = true; item.SetStateOf <LiquidContainer> (state); } } } else { Stacks.Pop.AndToss(itemStack); result = true; } return(result); }
//this is used in a lot of places //eg in player inventory squares for crafting to check if the thing you've put in the square meets requirements public static bool AreRequirementsMet(IWIBase item, GenericWorldItem template, BlueprintStrictness strictness, int numItemsInStack, out int maxItemsToCraft) { maxItemsToCraft = 1; if (item != null && item.IsQuestItem) { return(false); } bool prefabReqsMet = true; bool stackReqsMet = true; bool stateReqsMet = true; bool subCatReqsMet = true; //first we need to get the thing we're crafting from //if it's a liquid container we need to get the state data if (item.Is <LiquidContainer> ()) { LiquidContainerState stateData = null; bool foundState = false; if (item.IsWorldItem) { stateData = item.worlditem.Get <LiquidContainer> ().State; foundState = true; } else { if (item.GetStackItem(WIMode.None).GetStateData <LiquidContainerState> (out stateData)) { foundState = true; } } if (foundState) { //see if the liquid container contains what's needed mCheckRequirements.CopyFrom(stateData.Contents); mCheckRequirements.InstanceWeight = stateData.Contents.InstanceWeight; } } else { //if it's not a liquid container just get it from the item mCheckRequirements.CopyFrom(item); mCheckRequirements.InstanceWeight = numItemsInStack; } if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.PrefabName, Flags.CheckType.MatchAny)) { prefabReqsMet = string.Equals(mCheckRequirements.PrefabName, template.PrefabName, StringComparison.InvariantCultureIgnoreCase); } if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.StackName, Flags.CheckType.MatchAny)) { stackReqsMet = string.Equals(mCheckRequirements.StackName, template.StackName, StringComparison.InvariantCultureIgnoreCase); if (!stackReqsMet) { try { //check for the rare case where a non-numbered item is compared against a numbered item //'x #' vs 'x' //'x' vs 'x #' bool isReqDigit = char.IsDigit(mCheckRequirements.StackName, mCheckRequirements.StackName.Length - 1); bool isItemDigit = char.IsDigit(template.StackName, template.StackName.Length - 1); if (isReqDigit != isItemDigit) { string nonNumbered = isItemDigit ? mCheckRequirements.StackName : template.StackName; string numbered = isReqDigit ? mCheckRequirements.StackName.Substring(0, mCheckRequirements.StackName.Length - 2) : template.StackName.Substring(0, template.StackName.Length - 2); stackReqsMet = nonNumbered.Equals(numbered); #if UNITY_EDITOR Debug.Log("Checking numbered against non-numbered in crafting: " + mCheckRequirements.StackName + " vs " + template.StackName + " - check " + nonNumbered + ", " + numbered + " - " + stackReqsMet.ToString()); #endif } } catch (Exception e) { Debug.LogError("Error when checking for item digits in crafting skill: " + e.ToString()); } } } if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.StateName, Flags.CheckType.MatchAny)) { if ((string.IsNullOrEmpty(mCheckRequirements.State) || string.IsNullOrEmpty(template.State)) || (mCheckRequirements.State.Equals("Default") || template.State.Equals("Default"))) { stateReqsMet = true; } else { stateReqsMet = string.Equals(mCheckRequirements.State, template.State, StringComparison.InvariantCultureIgnoreCase); } } if (Flags.Check((uint)strictness, (uint)BlueprintStrictness.Subcategory, Flags.CheckType.MatchAny)) { if (string.IsNullOrEmpty(mCheckRequirements.Subcategory) || string.IsNullOrEmpty(template.Subcategory)) { subCatReqsMet = true; } else { subCatReqsMet = string.Equals(mCheckRequirements.Subcategory, template.Subcategory, StringComparison.InvariantCultureIgnoreCase); } } #if UNITY_EDITOR Debug.Log(template.PrefabName + " prefab reqs met: " + prefabReqsMet.ToString() + "\nstackReqsMet: " + stackReqsMet.ToString() + "\nstateReqsMet: " + stateReqsMet.ToString() + "\nsubCatReqsMet: " + subCatReqsMet.ToString()); #endif //max items to craft is the instance weight divided by instance weight of the template //instance weight of template tells us how many we need in that stack to craft maxItemsToCraft = mCheckRequirements.InstanceWeight / template.InstanceWeight; //if we have enough items to craft, we can proceed return(prefabReqsMet && stackReqsMet && stateReqsMet && subCatReqsMet && maxItemsToCraft >= template.InstanceWeight); }
public void RecalculateValueOfGoods(BarterParty party, bool recalculateItems) { if (!IsActive) { TotalValueCharacterGoods = 0; TotalValuePlayerGoods = 0; BaseValueCharacterGoods = 0; BaseValuePlayerGoods = 0; return; } List <BarterGoods> goods = CharacterGoods; if (party == BarterParty.Player) { goods = PlayerGoods; } if (goods.Count == 0) { BaseValueCharacterGoods = 0; BaseValuePlayerGoods = 0; } else if (recalculateItems) { float baseValueOfGoods = 0; foreach (BarterGoods good in goods) { int numItems = good.NumItems; if (numItems > 0) { IWIBase topItem = good.TopItem; float goodBaseValue = topItem.BaseCurrencyValue; if (topItem.Is <Stolen> ()) { goodBaseValue *= Globals.StolenGoodsValueMultiplier; } baseValueOfGoods += goodBaseValue * numItems; } } if (party == BarterParty.Player) { BaseValuePlayerGoods = baseValueOfGoods; } else { BaseValueCharacterGoods = baseValueOfGoods; } } float repPriceModifier = 0f; ReputationState rep = null; if (IsBarteringWithCharacter) { rep = Profile.Get.CurrentGame.Character.Rep.GetReputation(BarteringCharacter.worlditem.FileName); repPriceModifier = rep.NormalizedOffsetReputation; //this will be a value from -1 to 1 } else { repPriceModifier = Profile.Get.CurrentGame.Character.Rep.NormalizedOffsetGlobalReputation; } float skillPriceModifier = BarterManager.State.NormalizedOffsetUsageLevel; //this will be a value from -1 to 1 float regionPriceModifier = 0f; float goodsPriceModifier = (repPriceModifier + skillPriceModifier + regionPriceModifier) / 2f; if (BarterManager.HasBeenMastered) { //mastering the barter skill reduces all penalties to zero goodsPriceModifier = Mathf.Max(0, goodsPriceModifier); } goodsPriceModifier *= Globals.BarterMaximumPriceModifier; //divide the final modifier by 2 to get its effects on both sets of goods TotalValuePlayerGoods = Mathf.FloorToInt(BaseValuePlayerGoods + (BaseValuePlayerGoods * (goodsPriceModifier / 2f))); TotalValueCharacterGoods = Mathf.FloorToInt(BaseValueCharacterGoods - (BaseValueCharacterGoods * (goodsPriceModifier / 2f))); //the value of currency is not affected by reputation or skill TotalValuePlayerGoods += PlayerGoodsBank.BaseCurrencyValue; TotalValueCharacterGoods += CharacterGoodsBank.BaseCurrencyValue; ReputationPriceModifier = repPriceModifier; SkillPriceModifier = skillPriceModifier; FinalPriceModifier = goodsPriceModifier; RefreshAction.SafeInvoke(); }