public Searchspace Route(ItemAmount item, Searchspace space, IEnumerable <RoutingCoordinate> sources, IEnumerable <RoutingCoordinate> destinations) { if (item == null) { throw new ArgumentNullException("item"); } if (destinations == null) { throw new ArgumentNullException("destinations"); } AStar <FluidRouteState> star = new AStar <FluidRouteState>(); star.StateGenerator = (s) => s.NextStates(Grader.CostForBuilding, PipeToGround, Pipe); star.EndStateValidator = ValidateEndState; foreach (var dest in destinations) { star.AddDestination(new RoutingCoordinate(dest.Position, dest.State, dest.Rotation.Invert())); } foreach (var source in sources) { var startBuilding = new VirtualFlowStep(item, PipeToGround, source.Position, source.Rotation.Invert()); var startState = new FluidRouteState(startBuilding, 0, source.Position, space, Depth.None, source.Rotation, true); star.AddState(startState); } while (!star.Step()) { } return(star.EndState.Space); }
public UndergroundFlow(ItemAmount item, Vector2 position, Depth depth, BuildingRotation rotation) : base(item, new Building("underground-flow"), position, rotation) { Position = position; FlowDepth = depth; Rotation = rotation; Size = Vector2.One; }
void OnEnable() { _errorStyle = new GUIStyle { normal = { textColor = Color.red }, alignment = TextAnchor.MiddleCenter }; _plus = Resources.Load("plus") as Texture2D; _minus = Resources.Load("minus") as Texture2D; _goalTiers = new ItemTier[3]; for (var i = 0; i < 3; i++) { _goalTiers[i] = new ItemTier(); } _pendingAddGoal = new ItemAmount[3]; for (var i = 0; i < 3; i++) { _pendingAddGoal[i] = new ItemAmount(1); } _inventoryOnLoad = new List <ItemAmount>(); _showTiers = new bool[3] { true, true, true }; _fuelAmount = 0; _previousFolder = "Assets/_project/Feed The Baby/Levels"; _levelObjectMap = Resources.Load("Level Object Data") as LevelObjectMap; _terrainMap = Resources.Load("Terrain Data") as TerrainMap; }
public bool CanAffordToPlace(Construction component) { bool flag; if (this.isTypeDeployable) { return(true); } BasePlayer ownerPlayer = base.GetOwnerPlayer(); if (!ownerPlayer) { return(false); } List <ItemAmount> .Enumerator enumerator = component.defaultGrade.costToBuild.GetEnumerator(); try { while (enumerator.MoveNext()) { ItemAmount current = enumerator.Current; if ((float)ownerPlayer.inventory.GetAmount(current.itemDef.itemid) >= current.amount) { continue; } flag = false; return(flag); } return(true); } finally { ((IDisposable)enumerator).Dispose(); } return(flag); }
public void tryAddItem(int id, int amount) { if (ItemWeight.getWeight(id) != -1000) { ServerItem serverItem = new ServerItem(id, ItemAmount.getAmount(id), ItemState.getState(id), Vector3.zero); Vector3 position = base.transform.position; if (base.GetComponent <Player>().vehicle != null) { position = base.GetComponent <Player>().vehicle.getPosition(); } for (int i = 0; i < amount; i++) { if (this.hasSpace(serverItem) != 0) { SpawnItems.dropItem(id, position); } else { this.addItem(serverItem); } } } }
public void RemoveItem(ItemAmount instance) { if (!lookup.ContainsKey(instance.item)) { Debug.Log("Tried to remove none-existant item from tray"); return; } int remaining = instance.amount; int removed = 0; foreach (ItemObj item in lookup[instance.item]) { remaining = item.RemoveAmount(remaining); if (remaining >= 0) { ++removed; } else { break; } } slots.RemoveRange(0, removed); if (slots.Count == 0) { Debug.Log("remove Item"); lookup.Remove(instance.item); } }
public void BuyItem(ItemAmount instance) { ResourceManager.SpendResource(ResourceType.gold, -1 * instance.item.value * instance.amount); //bought item will remove itself from the store, since it was the trigger resource.UpdateUI(); //can add sound queue; }
public void QueueUpkeepPayment(List <ItemAmount> itemAmounts) { for (int i = 0; i < itemAmounts.Count; i++) { ItemAmount itemAmount = itemAmounts[i]; bool flag = false; foreach (ItemAmount item in upkeepBuffer) { if (item.itemDef == itemAmount.itemDef) { item.amount += itemAmount.amount; if (IsDebugging()) { Debug.Log(ToString() + ": Adding " + itemAmount.amount + " of " + itemAmount.itemDef.shortname + " to " + item.amount); } flag = true; break; } } if (!flag) { if (IsDebugging()) { Debug.Log(ToString() + ": Adding " + itemAmount.amount + " of " + itemAmount.itemDef.shortname); } upkeepBuffer.Add(new ItemAmount(itemAmount.itemDef, itemAmount.amount)); } } }
public void AddItem(ItemAmount instance) { int remaining = instance.amount; if (lookup.ContainsKey(instance.item)) { foreach (ItemObj item in lookup[instance.item]) { remaining = item.AddAmount(remaining); if (remaining <= 0) { break; } } } if (remaining > 0) { foreach (ItemSlot slot in slots) { if (slot.HasItem()) { continue; } CreateItemObj(instance.item, Mathf.Min(remaining, instance.item.max_amount), slot); remaining -= instance.item.max_amount; if (remaining <= 0) { break; } } } }
public void ApplyUpkeepPayment() { List <Item> obj = Facepunch.Pool.GetList <Item>(); for (int i = 0; i < upkeepBuffer.Count; i++) { ItemAmount itemAmount = upkeepBuffer[i]; int num = (int)itemAmount.amount; if (num < 1) { continue; } base.inventory.Take(obj, itemAmount.itemid, num); foreach (Item item in obj) { if (IsDebugging()) { Debug.Log(ToString() + ": Using " + item.amount + " of " + item.info.shortname); } item.UseItem(item.amount); } obj.Clear(); itemAmount.amount -= num; upkeepBuffer[i] = itemAmount; } Facepunch.Pool.FreeList(ref obj); }
public void GetRepairCostList(ItemBlueprint bp, List <ItemAmount> allIngredients) { foreach (ItemAmount ingredient in bp.ingredients) { allIngredients.Add(new ItemAmount(ingredient.itemDef, ingredient.amount)); } foreach (ItemAmount ingredient1 in bp.ingredients) { if (ingredient1.itemDef.category == ItemCategory.Component && Object.op_Inequality((Object)ingredient1.itemDef.Blueprint, (Object)null)) { bool flag = false; ItemAmount ingredient2 = ingredient1.itemDef.Blueprint.ingredients[0]; foreach (ItemAmount allIngredient in allIngredients) { if (Object.op_Equality((Object)allIngredient.itemDef, (Object)ingredient2.itemDef)) { allIngredient.amount += ingredient2.amount * ingredient1.amount; flag = true; break; } } if (!flag) { allIngredients.Add(new ItemAmount(ingredient2.itemDef, ingredient2.amount * ingredient1.amount)); } } } }
private void QueueUpkeepPayment(List <ItemAmount> itemAmounts) { for (int index = 0; index < itemAmounts.Count; ++index) { ItemAmount itemAmount1 = itemAmounts[index]; bool flag = false; foreach (ItemAmount itemAmount2 in this.upkeepBuffer) { if (Object.op_Equality((Object)itemAmount2.itemDef, (Object)itemAmount1.itemDef)) { itemAmount2.amount += itemAmount1.amount; if (this.IsDebugging()) { Debug.Log((object)(((object)this).ToString() + ": Adding " + (object)itemAmount1.amount + " of " + itemAmount1.itemDef.shortname + " to " + (object)itemAmount2.amount)); } flag = true; break; } } if (!flag) { if (this.IsDebugging()) { Debug.Log((object)(((object)this).ToString() + ": Adding " + (object)itemAmount1.amount + " of " + itemAmount1.itemDef.shortname)); } this.upkeepBuffer.Add(new ItemAmount(itemAmount1.itemDef, itemAmount1.amount)); } } }
void OnTriggerEnter2D(Collider2D col) { if (col.CompareTag("Player")) { var newItem = new ItemAmount() { item = item, amount = 1 }; var collected = false; Debug.Log(InventoryTracker.Items.Count); foreach (var slot in InventoryTracker.Items) { if (slot.item.ID == item.ID) { collected = true; } } if (collected) { return; } InventoryTracker.Items.Add(newItem); Destroy(gameObject); } }
public void GetRepairCostList(ItemBlueprint bp, List <ItemAmount> allIngredients) { foreach (ItemAmount ingredient in bp.ingredients) { allIngredients.Add(new ItemAmount(ingredient.itemDef, ingredient.amount)); } foreach (ItemAmount itemAmount in bp.ingredients) { if (itemAmount.itemDef.category != ItemCategory.Component || !(itemAmount.itemDef.Blueprint != null)) { continue; } bool flag = false; ItemAmount item = itemAmount.itemDef.Blueprint.ingredients[0]; foreach (ItemAmount allIngredient in allIngredients) { if (allIngredient.itemDef != item.itemDef) { continue; } ItemAmount itemAmount1 = allIngredient; itemAmount1.amount = itemAmount1.amount + item.amount * itemAmount.amount; flag = true; goto Label0; } Label0: if (flag) { continue; } allIngredients.Add(new ItemAmount(item.itemDef, item.amount * itemAmount.amount)); } }
public static void Gathering(ResourceDispenser dispenser, BaseEntity to, ItemAmount itemAmt, int amount) { itemAmt.amount += amount; BaseEntity from = (BaseEntity)dispenser.GetFieldValue("baseEntity"); GatherEvent ge = new GatherEvent(dispenser, from, to, itemAmt, amount); OnGathering.OnNext(ge); if (ge.Amount > 0) { amount = Mathf.RoundToInt(Mathf.Min((float)ge.Amount, itemAmt.amount)); if (amount > 0) { itemAmt.amount -= amount; if (itemAmt.amount < 0) { itemAmt.amount = 0; } Item item = ItemManager.CreateByItemID(itemAmt.itemid, amount, false); if (item == null) { return; } to.GiveItem(item); } } }
private void ApplyUpkeepPayment() { List <Item> list = Facepunch.Pool.GetList <Item>(); for (int i = 0; i < this.upkeepBuffer.Count; i++) { ItemAmount item = this.upkeepBuffer[i]; int num = (int)item.amount; if (num >= 1) { this.inventory.Take(list, item.itemid, num); foreach (Item item1 in list) { if (this.IsDebugging()) { Debug.Log(string.Concat(new object[] { this.ToString(), ": Using ", item1.amount, " of ", item1.info.shortname })); } item1.UseItem(item1.amount); } list.Clear(); item.amount -= (float)num; this.upkeepBuffer[i] = item; } } Facepunch.Pool.FreeList <Item>(ref list); }
public void DoPickup(BasePlayer reciever) { if (this.itemList == null) { return; } ItemAmount[] itemAmountArray = this.itemList; for (int i = 0; i < (int)itemAmountArray.Length; i++) { ItemAmount itemAmount = itemAmountArray[i]; Item item = ItemManager.Create(itemAmount.itemDef, (int)itemAmount.amount, (ulong)0); if (item != null) { if (!reciever) { item.Drop(base.transform.position + (Vector3.up * 0.5f), Vector3.up, new Quaternion()); } else { if (Interface.CallHook("OnCollectiblePickup", item, reciever, this) != null) { return; } reciever.GiveItem(item, BaseEntity.GiveItemReason.ResourceHarvested); } } } this.itemList = null; if (this.pickupEffect.isValid) { Effect.server.Run(this.pickupEffect.resourcePath, base.transform.position, base.transform.up, null, false); } base.Kill(BaseNetworkable.DestroyMode.None); }
public int GetProgress(ICharacterData character, int taskIndex, out bool isComplete) { isComplete = false; Quest quest = GetQuest(); if (character == null || quest == null || taskIndex < 0 || taskIndex >= quest.tasks.Length) { return(0); } QuestTask task = quest.tasks[taskIndex]; int progress = 0; switch (task.taskType) { case QuestTaskType.KillMonster: MonsterCharacterAmount monsterCharacterAmount = task.monsterCharacterAmount; progress = monsterCharacterAmount.monster == null ? 0 : CountKillMonster(monsterCharacterAmount.monster.DataId); isComplete = progress >= monsterCharacterAmount.amount; return(progress); case QuestTaskType.CollectItem: ItemAmount itemAmount = task.itemAmount; progress = itemAmount.item == null ? 0 : character.CountNonEquipItems(itemAmount.item.DataId); isComplete = progress >= itemAmount.amount; return(progress); } return(0); }
private void QueueUpkeepPayment(List <ItemAmount> itemAmounts) { for (int i = 0; i < itemAmounts.Count; i++) { ItemAmount item = itemAmounts[i]; bool flag = false; foreach (ItemAmount itemAmount in this.upkeepBuffer) { if (itemAmount.itemDef != item.itemDef) { continue; } itemAmount.amount += item.amount; if (this.IsDebugging()) { Debug.Log(string.Concat(new object[] { this.ToString(), ": Adding ", item.amount, " of ", item.itemDef.shortname, " to ", itemAmount.amount })); } flag = true; goto Label0; } Label0: if (!flag) { if (this.IsDebugging()) { Debug.Log(string.Concat(new object[] { this.ToString(), ": Adding ", item.amount, " of ", item.itemDef.shortname })); } this.upkeepBuffer.Add(new ItemAmount(item.itemDef, item.amount)); } } }
public void AddTrigger(ItemAmount instance) { if (onAddItem != null) { onAddItem(instance); } }
public void SellTrigger(ItemAmount instance) { if (onSellItem != null) { onSellItem(instance); } }
public override void DoAction(Item item, BasePlayer player) { if (item.amount < 1) { return; } ItemAmount[] itemAmountArray = this.becomeItem; for (int i = 0; i < (int)itemAmountArray.Length; i++) { ItemAmount itemAmount = itemAmountArray[i]; Item item1 = ItemManager.Create(itemAmount.itemDef, (int)itemAmount.amount, (ulong)0); if (item1 != null) { if (!item1.MoveToContainer(item.parent, -1, true)) { player.GiveItem(item1, BaseEntity.GiveItemReason.Generic); } if (this.sendPlayerPickupNotification) { player.Command("note.inv", new object[] { item1.info.itemid, item1.amount }); } } } if (this.sendPlayerDropNotification) { player.Command("note.inv", new object[] { item.info.itemid, -1 }); } if (this.actionEffect.isValid) { Effect.server.Run(this.actionEffect.resourcePath, player.transform.position, Vector3.up, null, false); } item.UseItem(1); }
private void ApplyUpkeepPayment() { List <Item> list = (List <Item>)Pool.GetList <Item>(); for (int index = 0; index < this.upkeepBuffer.Count; ++index) { ItemAmount itemAmount = this.upkeepBuffer[index]; int amount = (int)itemAmount.amount; if (amount >= 1) { this.inventory.Take(list, itemAmount.itemid, amount); foreach (Item obj in list) { if (this.IsDebugging()) { Debug.Log((object)(((object)this).ToString() + ": Using " + (object)obj.amount + " of " + obj.info.shortname)); } obj.UseItem(obj.amount); } list.Clear(); itemAmount.amount -= (float)amount; this.upkeepBuffer[index] = itemAmount; } } // ISSUE: cast to a reference type Pool.FreeList <Item>((List <M0>&) ref list); }
private bool CanAffordUpgrade(BuildingGrade.Enum iGrade, BasePlayer player) { bool flag; object obj = Interface.CallHook("CanAffordUpgrade", player, this, iGrade); if (obj as bool) { return((bool)obj); } List <ItemAmount> .Enumerator enumerator = this.GetGrade(iGrade).costToBuild.GetEnumerator(); try { while (enumerator.MoveNext()) { ItemAmount current = enumerator.Current; if ((float)player.inventory.GetAmount(current.itemid) >= current.amount) { continue; } flag = false; return(flag); } return(true); } finally { ((IDisposable)enumerator).Dispose(); } return(flag); }
public void UpdateItems() { for (int i = 0; i < this.height * this.width; i++) { int bagX = i % this.width; int bagY = i / this.width; if (ItemStackable.getStackable(this.items[bagX, bagY].id) && this.items[bagX, bagY].amount > Inventory.MAX_STACK) { this.items[bagX, bagY].amount = Inventory.MAX_STACK; } else if (ItemType.getType(this.items[bagX, bagY].id) == 10 && this.items[bagX, bagY].amount > ItemAmount.getAmount(this.items[bagX, bagY].id)) { this.items[bagX, bagY].amount = ItemAmount.getAmount(this.items[bagX, bagY].id); } else if (ItemType.getType(this.items[bagX, bagY].id) == 7) { if (this.items[bagX, bagY].state == string.Empty) { this.items[bagX, bagY].id = -1; this.items[bagX, bagY].amount = 0; this.items[bagX, bagY].state = string.Empty; } else { string[] itemStateArray = Packer.unpack(this.items[bagX, bagY].state, '\u005F'); int bullets = int.Parse(itemStateArray[0]); int ammoType = int.Parse(itemStateArray[1]); if (!AmmoStats.getGunCompatible(this.items[bagX, bagY].id, ammoType)) { ammoType = -1; bullets = 0; } else if (bullets > AmmoStats.getCapacity(this.items[bagX, bagY].id, ammoType)) { bullets = 0; } object[] objArray = new object[] { bullets, "_", ammoType, "_", itemStateArray[2], "_", itemStateArray[3], "_", itemStateArray[4], "_", itemStateArray[5], "_", itemStateArray[6], "_" }; this.items[bagX, bagY].state = string.Concat(objArray); } } if (this.items[bagX, bagY].id != -1) { if (!ItemStackable.getStackable(this.items[bagX, bagY].id)) { Inventory weight = this; weight.weight = weight.weight + ItemWeight.getWeight(this.items[bagX, bagY].id); } else { Inventory inventory = this; inventory.weight = inventory.weight + ItemWeight.getWeight(this.items[bagX, bagY].id) * this.items[bagX, bagY].amount; } } this.syncItem(bagX, bagY); } }
private bool CanAffordUpgrade(int grade, BuildingBlock buildingBlock, BasePlayer player) { bool flag = true; List <ItemAmount> .Enumerator enumerator = buildingBlock.blockDefinition.grades[(int)buildingBlock.grade].costToBuild.GetEnumerator(); //this[iGrade].costToBuild.GetEnumerator(); /*try * {*/ // Add cost of build grade 0 Dictionary <int, float> costs = new Dictionary <int, float>(); while (enumerator.MoveNext()) { ItemAmount current = enumerator.Current; costs[current.itemid] = current.amount; } enumerator = buildingBlock.blockDefinition.grades[grade].costToBuild.GetEnumerator(); // Calc needed costs for upgrade while (enumerator.MoveNext()) { ItemAmount current = enumerator.Current; var cost = 0f; if (costs.ContainsKey(current.itemid)) { cost = costs[current.itemid]; costs.Remove(current.itemid); } if (player.inventory.GetAmount(current.itemid) >= current.amount + cost) { continue; } flag = false; return(flag); } // check for build grade 0 and needed cost (additional resources) if (costs.Count > 0) { foreach (KeyValuePair <int, float> kvp in costs) { if (player.inventory.GetAmount(kvp.Key) >= kvp.Value) { continue; } flag = false; return(flag); } } //return true; /*} * finally * { * ((IDisposable)(object)enumerator).Dispose(); * }*/ return(flag); }
public bool HasItem(ItemAmount instance) { if (items.ContainsKey(instance.item)) { return(items[instance.item].amount >= instance.amount); } return(instance.amount == 0); }
public int CountAmount(Inventory inventory, Inventory hubchest, ItemAmount itemAmount) { int amount = 0; amount += inventory.ItemCount(itemAmount.item); amount += hubchest.ItemCount(itemAmount.item); return(amount); }
public static KeyValuePair <Item, short> MakeItemAmountPair(ItemAmount source) { if (source.item == null) { return(new KeyValuePair <Item, short>()); } return(new KeyValuePair <Item, short>(source.item, source.amount)); }
public void BuyTrigger(ItemAmount instance) { if (onBuyItem != null && GameState.Instance.inventory.HasRoom(instance) && ResourceManager.HasResource(ResourceType.gold, instance.item.value)) { onBuyItem(instance); } }
public GatherEvent(ResourceDispenser dispenser, BaseEntity from, BaseEntity to, ItemAmount itemAmt, int amount) { if (to is BasePlayer) { _gatherer = Server.GetPlayer((BasePlayer) to); _resource = new Entity(from); _resourceDispenser = dispenser; _itemAmount = itemAmt; _amount = (int)(amount * World.GetInstance().ResourceGatherMultiplier); } }
public GatherEvent(ResourceDispenser resourceDispenser, BaseEntity from, BaseEntity to, ItemAmount itemAmount, int amount) { if (to is BasePlayer) { ResourceDispenser = resourceDispenser; Resource = new Entity(from); Gatherer = Server.GetPlayer(to as BasePlayer); ItemAmount = itemAmount; Amount = (int)(amount * World.GetInstance().ResourceGatherMultiplier); } }
/// <summary> /// Called from <c>ResourceDispenser.GiveResourceFromItem(BaseEntity, ItemAmount, float, float, AttackEntity)</c> . /// </summary> public static void On_PlayerGathering(ResourceDispenser dispenser, BaseEntity to, ItemAmount itemAmount, float gatherDamage, float destroyFraction) { BaseEntity from = (BaseEntity)dispenser.GetFieldValue("baseEntity"); if (itemAmount.amount == 0) return; float num = gatherDamage / from.MaxHealth(); float num2 = itemAmount.startAmount / (float)dispenser.GetFieldValue("startingItemCounts"); float value = itemAmount.startAmount * num / num2; float num3 = Mathf.Clamp(value, 0, itemAmount.amount); float num4 = num3 * destroyFraction * 2; if (itemAmount.amount < num3 + num4) { itemAmount.amount -= destroyFraction * num3; num3 = itemAmount.amount; num4 = 0; } float amount = itemAmount.amount; itemAmount.amount -= num3; if (itemAmount.amount < 0) { itemAmount.amount = 0; } int num5 = Mathf.Clamp(Mathf.RoundToInt(num3), 0, Mathf.CeilToInt(amount)); itemAmount.amount -= num4; if (itemAmount.amount < 0) { itemAmount.amount = 0; } GatherEvent ge = new GatherEvent(dispenser, from, to, itemAmount, num5); OnNext("On_PlayerGathering", ge); if (ge.Amount <= 0) return; Item item = ItemManager.CreateByItemID(itemAmount.itemid, ge.Amount); if (item == null) return; to.GiveItem(item, BaseEntity.GiveItemReason.ResourceHarvested); }
public static void Gathering(ResourceDispenser dispenser, BaseEntity to, ItemAmount itemAmt, int amount) { itemAmt.amount += amount; BaseEntity from = (BaseEntity)dispenser.GetFieldValue("baseEntity"); GatherEvent ge = new GatherEvent(dispenser, from, to, itemAmt, amount); OnGathering.OnNext(ge); if (ge.Amount > 0) { if (amount > 0) { itemAmt.amount -= amount; if (itemAmt.amount < 0) itemAmt.amount = 0; Item item = ItemManager.CreateByItemID(itemAmt.itemid, ge.Amount, false); if (item == null) { return; } to.GiveItem(item); } } }