public static bool CanSplitStack(InventoryStack stack) { if (stack != null && stack.count >= 2) return true; else return false; }
public static InventoryStack[] SplitStack(Mine2D game, InventoryStack stack) { InventoryStack[] stacks = new InventoryStack[2]; if (stack != null && stack.count >= 2) { int stack1Count = stack.count / 2; int stack2Count = stack.count - stack1Count; stacks[0] = stack.Clone(game) as InventoryStack; stacks[0].RemoveAmount(stack1Count); stacks[1] = stack.Clone(game) as InventoryStack; stacks[1].RemoveAmount(stack2Count); } return stacks; }
public virtual bool AddStackToInventory(InventoryStack stack) { int i = 0; foreach (InventoryStack invStack in inventoryContents) { if (invStack == null) { inventoryContents[i] = stack; return true; } else if (invStack.stackType == InventoryStack.InventoryStackTypes.Block && stack.stackType == InventoryStack.InventoryStackTypes.Block) { if (Type.GetType("Mine2D.Blocks+" + invStack.GetBlock().name) == Type.GetType("Mine2D.Blocks+" + stack.GetBlock().name)) { if (invStack.AddAmount(stack.count)) return true; else { i++; continue; } } i++; } else if (invStack.stackType == InventoryStack.InventoryStackTypes.Item && stack.stackType == InventoryStack.InventoryStackTypes.Item) { if (Type.GetType("Mine2D.Items+" + invStack.GetItem().name) == Type.GetType("Mine2D.Items+" + stack.GetItem().name)) { if (invStack.AddAmount(stack.count)) return true; else { i++; continue; } } i++; } else i++; } return false; }
public static bool CanSumTwoStacks(InventoryStack stack1, InventoryStack stack2) { if (stack1 != null && stack2 != null) { if (stack1.stackType == InventoryStack.InventoryStackTypes.Block && stack2.stackType == InventoryStack.InventoryStackTypes.Block) { if (stack1.GetBlock().name == stack2.GetBlock().name) { if ((stack1.count + stack2.count <= stack1.maxCount) && (stack1.count + stack2.count <= stack2.maxCount)) return true; } } else if (stack1.stackType == InventoryStack.InventoryStackTypes.Item && stack2.stackType == InventoryStack.InventoryStackTypes.Item) { if (stack1.GetItem().name == stack2.GetItem().name) { if ((stack1.count + stack2.count <= stack1.maxCount) && (stack1.count + stack2.count <= stack2.maxCount)) return true; } } } return false; }
public void Update(Mine2D game) { MouseState mouse = Mouse.GetState(); // Обычный инвентарь if (draggingStack == null) { for (int row = 0; row < 3; row++) { for (int i = 0; i < 9; i++) { if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 249) + 3 && mouse.Y < 135 + (row * 54 + 249) + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && game.normalInventory.inventoryContents[(row * 9) + i] != null) { draggingStack = game.normalInventory.inventoryContents[(row * 9) + i].Clone(game) as InventoryStack; draggingStack.isDragging = true; game.normalInventory.inventoryContents[(row * 9) + i].needRemove = true; goto escapeFor; } } } } else { if (mouse.LeftButton == ButtonState.Pressed && !isMousePressed) isMousePressed = true; else if (mouse.LeftButton == ButtonState.Released && isMousePressed) { isMousePressed = false; for (int row = 0; row < 3; row++) { for (int i = 0; i < 9; i++) { // Обычный инвентарь if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 249) + 3 && mouse.Y < 135 + (row * 54 + 249) + 3 + 48 && (game.normalInventory.inventoryContents[(row * 9) + i] == null || InventoryHelper.CanSumTwoStacks(game.normalInventory.inventoryContents[(row * 9) + i], draggingStack))) { if (game.normalInventory.inventoryContents[(row * 9) + i] == null) game.normalInventory.inventoryContents[(row * 9) + i] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(game.normalInventory.inventoryContents[(row * 9) + i], draggingStack)) game.normalInventory.inventoryContents[(row * 9) + i] = InventoryHelper.SumTwoStacks(game, game.normalInventory.inventoryContents[(row * 9) + i], draggingStack); draggingStack = null; } // Малый инвентарь else if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + 423 + 3 && mouse.Y < 135 + 423 + 3 + 48 && (game.smallInventory.inventoryContents[i] == null || InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack))) { if (game.smallInventory.inventoryContents[i] == null) game.smallInventory.inventoryContents[i] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack)) game.smallInventory.inventoryContents[i] = InventoryHelper.SumTwoStacks(game, game.smallInventory.inventoryContents[i], draggingStack); draggingStack = null; } } } // Инвентарь печки: // - Вход if (mouse.X > 248 + 164 + 4 && mouse.X < 248 + 164 + 4 + 48 && mouse.Y > 135 + 48 + 3 && mouse.Y < 135 + 48 + 3 + 48 && (inventoryContents[0] == null || InventoryHelper.CanSumTwoStacks(inventoryContents[0], draggingStack))) { if (inventoryContents[0] == null) inventoryContents[0] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(inventoryContents[0], draggingStack)) inventoryContents[0] = InventoryHelper.SumTwoStacks(game, inventoryContents[0], draggingStack); draggingStack = null; } // - Топливо if (mouse.X > 248 + 164 + 4 && mouse.X < 248 + 164 + 4 + 48 && mouse.Y > 135 + 156 + 3 && mouse.Y < 135 + 156 + 3 + 48 && (inventoryContents[2] == null || InventoryHelper.CanSumTwoStacks(inventoryContents[2], draggingStack))) { if (inventoryContents[2] == null) inventoryContents[2] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(inventoryContents[2], draggingStack)) inventoryContents[2] = InventoryHelper.SumTwoStacks(game, inventoryContents[2], draggingStack); draggingStack = null; } } } if (draggingStack == null) { for (int i = 0; i < 9; i++) { if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + 423 + 3 && mouse.Y < 135 + 423 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && game.smallInventory.inventoryContents[i] != null) { draggingStack = game.smallInventory.inventoryContents[i].Clone(game) as InventoryStack; draggingStack.isDragging = true; game.smallInventory.inventoryContents[i].needRemove = true; goto escapeFor; } } } if (draggingStack == null) { // Инвентарь печки: // - Вход if (mouse.X > 248 + 164 + 4 && mouse.X < 248 + 164 + 4 + 48 && mouse.Y > 135 + 48 + 3 && mouse.Y < 135 + 48 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && inventoryContents[0] != null) { draggingStack = inventoryContents[0].Clone(game) as InventoryStack; draggingStack.isDragging = true; inventoryContents[0].needRemove = true; goto escapeFor; } // - Выход if (mouse.X > 248 + 344 + 4 && mouse.X < 248 + 344 + 4 + 48 && mouse.Y > 135 + 102 + 3 && mouse.Y < 135 + 102 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && inventoryContents[1] != null) { draggingStack = inventoryContents[1].Clone(game) as InventoryStack; draggingStack.isDragging = true; inventoryContents[1].needRemove = true; goto escapeFor; } // - Топливо if (mouse.X > 248 + 164 + 4 && mouse.X < 248 + 164 + 4 + 48 && mouse.Y > 135 + 156 + 3 && mouse.Y < 135 + 156 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && inventoryContents[2] != null) { draggingStack = inventoryContents[2].Clone(game) as InventoryStack; draggingStack.isDragging = true; inventoryContents[2].needRemove = true; fuelTime = 0; goto escapeFor; } } // Разделение стопок if (mouse.RightButton == ButtonState.Pressed && !isMouse2Pressed) isMouse2Pressed = true; else if (mouse.RightButton == ButtonState.Released && isMouse2Pressed) { isMouse2Pressed = false; for (int row = 0; row < 3; row++) { for (int i = 0; i < 9; i++) { // Обычный инвентарь if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 249) + 3 && mouse.Y < 135 + (row * 54 + 249) + 3 + 48 && InventoryHelper.CanSplitStack(game.normalInventory.inventoryContents[(row * 9) + i]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.normalInventory.inventoryContents[(row * 9) + i]); game.normalInventory.inventoryContents[(row * 9) + i] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } // Малый инвентарь else if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + 423 + 3 && mouse.Y < 135 + 423 + 3 + 48 && InventoryHelper.CanSplitStack(game.smallInventory.inventoryContents[i]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.smallInventory.inventoryContents[i]); game.smallInventory.inventoryContents[i] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } } } // Инвентарь печки: // - Вход if (mouse.X > 248 + 164 + 4 && mouse.X < 248 + 164 + 4 + 48 && mouse.Y > 135 + 48 + 3 && mouse.Y < 135 + 48 + 3 + 48 && InventoryHelper.CanSplitStack(inventoryContents[0]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[0]); inventoryContents[0] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } // - Выход if (mouse.X > 248 + 344 + 4 && mouse.X < 248 + 344 + 4 + 48 && mouse.Y > 135 + 102 + 3 && mouse.Y < 135 + 102 + 3 + 48 && InventoryHelper.CanSplitStack(inventoryContents[1]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[1]); inventoryContents[1] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } // - Топливо if (mouse.X > 248 + 164 + 4 && mouse.X < 248 + 164 + 4 + 48 && mouse.Y > 135 + 156 + 3 && mouse.Y < 135 + 156 + 3 + 48 && InventoryHelper.CanSplitStack(inventoryContents[2]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[2]); inventoryContents[2] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } } escapeFor: Type[] invStacks = CraftHelper.ConvertStacksToTypes(inventoryContents); if (CraftHelper.CheckIsExistingFurnaceRecipe(invStacks[0], invStacks[2]) && (this.inventoryContents[1] == null || InventoryHelper.CanSumTwoStacks(this.inventoryContents[1], CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game))) && !isCooking) { cookingTime = 0; if (fuelTime <= 0) fuelTime = Item.GetFuelValue(invStacks[2]); isCooking = true; } else if (!CraftHelper.CheckIsExistingFurnaceRecipe(invStacks[0], invStacks[2]) && isCooking) { cookingTime = 0; isCooking = false; } if (isCooking && fuelTime <= 0) { this.inventoryContents[2].RemoveAmount(1); if (!this.inventoryContents[2].needRemove) fuelTime = Item.GetFuelValue(invStacks[2]); } else if (isCooking && fuelTime == Item.GetFuelValue(invStacks[2])) { this.inventoryContents[2].RemoveAmount(1); } if (fuelTime > 0) fuelTime--; if (isCooking && this.inventoryContents[1] == null && cookingTime >= 500) { InventoryStack output = CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game); this.inventoryContents[1] = output; this.inventoryContents[0].RemoveAmount(1); isCooking = false; cookingTime = 0; } else if (isCooking && InventoryHelper.CanSumTwoStacks(this.inventoryContents[1], CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game)) && cookingTime >= 500) { InventoryStack output = CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game); this.inventoryContents[1] = InventoryHelper.SumTwoStacks(game, this.inventoryContents[1], CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game)); this.inventoryContents[0].RemoveAmount(1); isCooking = false; cookingTime = 0; } if (inventoryContents != null) { for (int i = 0; i < 3; i++) { if (inventoryContents[i] != null && inventoryContents[i].needRemove) inventoryContents[i] = null; } } if (isCooking) cookingTime++; game.normalInventory.Update(); base.Update(); }
private static void FinishLoadAfterDeserializationForInvStacks(InventoryStack[] invStacks, Mine2D game) { foreach (InventoryStack invStack in invStacks) { if (invStack != null) { if (invStack.stackType == InventoryStack.InventoryStackTypes.Block) invStack.GetBlock().FinishLoadAfterDeserialization(game.blocksAtlas); else if (invStack.stackType == InventoryStack.InventoryStackTypes.Item) invStack.GetItem().FinishLoadAfterDeserialization(game.itemsAtlas); invStack.FinishLoadAfterDeserialization(); } } }
public static Type[] ConvertStacksToTypes(InventoryStack[] invStacks) { Type[] invStacksTypes = new Type[invStacks.Length]; int i = 0; foreach (InventoryStack invStack in invStacks) { if (invStacks[i] != null) { if (invStacks[i].stackType == InventoryStack.InventoryStackTypes.Block) invStacksTypes[i] = Type.GetType("Mine2D.Blocks+" + invStacks[i].GetBlock().name); else if (invStacks[i].stackType == InventoryStack.InventoryStackTypes.Item) invStacksTypes[i] = Type.GetType("Mine2D.Items+" + invStacks[i].GetItem().name); } i++; } return invStacksTypes; }
public void Update(Mine2D game) { MouseState mouse = Mouse.GetState(); // Обычный инвентарь if (draggingStack == null) { for (int row = 0; row < 3; row++) { for (int i = 0; i < 9; i++) { if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 249) + 3 && mouse.Y < 135 + (row * 54 + 249) + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && game.normalInventory.inventoryContents[(row * 9) + i] != null) { draggingStack = game.normalInventory.inventoryContents[(row * 9) + i].Clone(game) as InventoryStack; draggingStack.isDragging = true; game.normalInventory.inventoryContents[(row * 9) + i].needRemove = true; goto escapeFor; } } } } else { if (mouse.LeftButton == ButtonState.Pressed && !isMousePressed) isMousePressed = true; else if (mouse.LeftButton == ButtonState.Released && isMousePressed) { isMousePressed = false; for (int row = 0; row < 3; row++) { for (int i = 0; i < 9; i++) { // Обычный инвентарь if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 249) + 3 && mouse.Y < 135 + (row * 54 + 249) + 3 + 48 && (game.normalInventory.inventoryContents[(row * 9) + i] == null || InventoryHelper.CanSumTwoStacks(game.normalInventory.inventoryContents[(row * 9) + i], draggingStack))) { if (game.normalInventory.inventoryContents[(row * 9) + i] == null) game.normalInventory.inventoryContents[(row * 9) + i] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(game.normalInventory.inventoryContents[(row * 9) + i], draggingStack)) game.normalInventory.inventoryContents[(row * 9) + i] = InventoryHelper.SumTwoStacks(game, game.normalInventory.inventoryContents[(row * 9) + i], draggingStack); draggingStack = null; } // Малый инвентарь else if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + 423 + 3 && mouse.Y < 135 + 423 + 3 + 48 && (game.smallInventory.inventoryContents[i] == null || InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack))) { if (game.smallInventory.inventoryContents[i] == null) game.smallInventory.inventoryContents[i] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack)) game.smallInventory.inventoryContents[i] = InventoryHelper.SumTwoStacks(game, game.smallInventory.inventoryContents[i], draggingStack); draggingStack = null; } } for (int i = 0; i < 3; i++) { // Инвентарь крафта if (mouse.X > 248 + 86 + (i * 54 + 4) && mouse.X < 248 + 86 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 48) + 3 && mouse.Y < 135 + (row * 54 + 48) + 3 + 48 && (inventoryContents[(row * 3) + i] == null || InventoryHelper.CanSumTwoStacks(inventoryContents[(row * 3) + i], draggingStack))) { if (inventoryContents[(row * 3) + i] == null) inventoryContents[(row * 3) + i] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(inventoryContents[(row * 3) + i], draggingStack)) inventoryContents[(row * 3) + i] = InventoryHelper.SumTwoStacks(game, inventoryContents[(row * 3) + i], draggingStack); draggingStack = null; } } } } } if (draggingStack == null) { for (int i = 0; i < 9; i++) { if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + 423 + 3 && mouse.Y < 135 + 423 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && game.smallInventory.inventoryContents[i] != null) { draggingStack = game.smallInventory.inventoryContents[i].Clone(game) as InventoryStack; draggingStack.isDragging = true; game.smallInventory.inventoryContents[i].needRemove = true; goto escapeFor; } } } if (draggingStack == null) { for (int row = 0; row < 3; row++) { for (int i = 0; i < 3; i++) { if (mouse.X > 248 + 86 + (i * 54 + 4) && mouse.X < 248 + 86 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 48) + 3 && mouse.Y < 135 + (row * 54 + 48) + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && inventoryContents[(row * 3) + i] != null) { draggingStack = inventoryContents[(row * 3) + i].Clone(game) as InventoryStack; draggingStack.isDragging = true; inventoryContents[(row * 3) + i].needRemove = true; goto escapeFor; } } } if (mouse.X > 248 + 368 + 4 && mouse.X < 248 + 368 + 4 + 48 && mouse.Y > 135 + 54 + 48 + 3 && mouse.Y < 135 + 54 + 48 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && inventoryContents[9] != null) { for (int i_ = 0; i_ < 9; i_++) { if (inventoryContents[i_] != null) inventoryContents[i_].RemoveAmount(1); } draggingStack = inventoryContents[9].Clone(game) as InventoryStack; draggingStack.isDragging = true; inventoryContents[9].needRemove = true; goto escapeFor; } } // Разделение стопок if (mouse.RightButton == ButtonState.Pressed && !isMouse2Pressed) isMouse2Pressed = true; else if (mouse.RightButton == ButtonState.Released && isMouse2Pressed) { isMouse2Pressed = false; for (int row = 0; row < 3; row++) { for (int i = 0; i < 9; i++) { // Обычный инвентарь if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 249) + 3 && mouse.Y < 135 + (row * 54 + 249) + 3 + 48 && InventoryHelper.CanSplitStack(game.normalInventory.inventoryContents[(row * 9) + i]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.normalInventory.inventoryContents[(row * 9) + i]); game.normalInventory.inventoryContents[(row * 9) + i] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } // Малый инвентарь else if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + 423 + 3 && mouse.Y < 135 + 423 + 3 + 48 && InventoryHelper.CanSplitStack(game.smallInventory.inventoryContents[i]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.smallInventory.inventoryContents[i]); game.smallInventory.inventoryContents[i] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } } for (int i = 0; i < 3; i++) { // Инвентарь крафта if (mouse.X > 248 + 86 + (i * 54 + 4) && mouse.X < 248 + 86 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 48) + 3 && mouse.Y < 135 + (row * 54 + 48) + 3 + 48 && InventoryHelper.CanSplitStack(inventoryContents[(row * 3) + i]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[(row * 3) + i]); inventoryContents[(row * 3) + i] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } } if (mouse.X > 248 + 368 + 4 && mouse.X < 248 + 368 + 4 + 48 && mouse.Y > 135 + 54 + 48 + 3 && mouse.Y < 135 + 54 + 48 + 3 + 48 && InventoryHelper.CanSplitStack(inventoryContents[9]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[9]); inventoryContents[9] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } } } escapeFor: InventoryStack[] invStacks = new InventoryStack[9]; Array.ConstrainedCopy(inventoryContents, 0, invStacks, 0, 9); if (CraftHelper.CheckIsExistingRecipe(CraftHelper.ConvertStacksToTypes(invStacks)) && this.inventoryContents[9] == null) { InventoryStack output = CraftHelper.GetOutputForRecipe(CraftHelper.ConvertStacksToTypes(invStacks), game); this.inventoryContents[9] = output; } else if (!CraftHelper.CheckIsExistingRecipe(CraftHelper.ConvertStacksToTypes(invStacks))) { if (inventoryContents[9] != null) this.inventoryContents[9].needRemove = true; } if (inventoryContents != null) { for (int i = 0; i < 10; i++) { if (inventoryContents[i] != null && inventoryContents[i].needRemove) inventoryContents[i] = null; } } game.normalInventory.Update(); base.Update(); }
public void Update(Mine2D game) { if (craftContents == null) craftContents = new InventoryStack[5]; MouseState mouse = Mouse.GetState(); // Обычный инвентарь if (draggingStack == null) { for (int row = 0; row < 3; row++) { for (int i = 0; i < 9; i++) { if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 249) + 3 && mouse.Y < 135 + (row * 54 + 249) + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && inventoryContents[(row * 9) + i] != null) { draggingStack = inventoryContents[(row * 9) + i].Clone(game) as InventoryStack; draggingStack.isDragging = true; inventoryContents[(row * 9) + i].needRemove = true; goto escapeFor; } } } } else { if (mouse.LeftButton == ButtonState.Pressed && !isMousePressed) isMousePressed = true; else if (mouse.LeftButton == ButtonState.Released && isMousePressed) { isMousePressed = false; for (int row = 0; row < 3; row++) { for (int i = 0; i < 9; i++) { // Обычный инвентарь if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 249) + 3 && mouse.Y < 135 + (row * 54 + 249) + 3 + 48 && (inventoryContents[(row * 9) + i] == null || InventoryHelper.CanSumTwoStacks(inventoryContents[(row * 9) + i], draggingStack))) { if (inventoryContents[(row * 9) + i] == null) inventoryContents[(row * 9) + i] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(inventoryContents[(row * 9) + i], draggingStack)) inventoryContents[(row * 9) + i] = InventoryHelper.SumTwoStacks(game, inventoryContents[(row * 9) + i], draggingStack); draggingStack = null; } // Малый инвентарь else if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + 423 + 3 && mouse.Y < 135 + 423 + 3 + 48 && (game.smallInventory.inventoryContents[i] == null || InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack))) { if (game.smallInventory.inventoryContents[i] == null) game.smallInventory.inventoryContents[i] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack)) game.smallInventory.inventoryContents[i] = InventoryHelper.SumTwoStacks(game, game.smallInventory.inventoryContents[i], draggingStack); draggingStack = null; } } for (int i = 0; i < 2; i++) { // Инвентарь крафта: верх if (mouse.X > 248 + 260 + (i * 54 + 4) && mouse.X < 248 + 260 + (i * 54 + 4) + 48 && mouse.Y > 135 + 75 + 3 && mouse.Y < 135 + 75 + 3 + 48 && (this.craftContents[i] == null || InventoryHelper.CanSumTwoStacks(this.craftContents[i], draggingStack))) { if (this.craftContents[i] == null) this.craftContents[i] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(this.craftContents[i], draggingStack)) this.craftContents[i] = InventoryHelper.SumTwoStacks(game, this.craftContents[i], draggingStack); draggingStack = null; } // Инвентарь крафта: низ else if (mouse.X > 248 + 260 + (i * 54 + 4) && mouse.X < 248 + 260 + (i * 54 + 4) + 48 && mouse.Y > 135 + 129 + 3 && mouse.Y < 135 + 129 + 3 + 48 && (this.craftContents[i + 2] == null || InventoryHelper.CanSumTwoStacks(this.craftContents[i + 2], draggingStack))) { if (this.craftContents[i + 2] == null) this.craftContents[i + 2] = draggingStack.Clone(game) as InventoryStack; else if (InventoryHelper.CanSumTwoStacks(this.craftContents[i + 2], draggingStack)) this.craftContents[i + 2] = InventoryHelper.SumTwoStacks(game, this.craftContents[i + 2], draggingStack); draggingStack = null; } } } } } // Малый инвентарь if (draggingStack == null) { for (int i = 0; i < 9; i++) { if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + 423 + 3 && mouse.Y < 135 + 423 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && game.smallInventory.inventoryContents[i] != null) { draggingStack = game.smallInventory.inventoryContents[i].Clone(game) as InventoryStack; draggingStack.isDragging = true; game.smallInventory.inventoryContents[i].needRemove = true; goto escapeFor; } } } // Инвентарь крафта if (draggingStack == null) { for (int i = 0; i < 2; i++) { // Верх if (mouse.X > 248 + 260 + (i * 54 + 4) && mouse.X < 248 + 260 + (i * 54 + 4) + 48 && mouse.Y > 135 + 75 + 3 && mouse.Y < 135 + 75 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && craftContents[i] != null) { draggingStack = craftContents[i].Clone(game) as InventoryStack; draggingStack.isDragging = true; craftContents[i].needRemove = true; } // Низ else if (mouse.X > 248 + 260 + (i * 54 + 4) && mouse.X < 248 + 260 + (i * 54 + 4) + 48 && mouse.Y > 135 + 129 + 3 && mouse.Y < 135 + 129 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && craftContents[i + 2] != null) { draggingStack = craftContents[i + 2].Clone(game) as InventoryStack; draggingStack.isDragging = true; craftContents[i + 2].needRemove = true; } // Выход else if (mouse.X > 248 + 428 + 4 && mouse.X < 248 + 428 + 4 + 48 && mouse.Y > 135 + 105 + 3 && mouse.Y < 135 + 105 + 3 + 48 && mouse.LeftButton == ButtonState.Pressed && craftContents[4] != null) { for (int i_ = 0; i_ < 4; i_++) { if (this.craftContents[i_] != null) this.craftContents[i_].RemoveAmount(1); } draggingStack = craftContents[4].Clone(game) as InventoryStack; draggingStack.isDragging = true; craftContents[4].needRemove = true; goto escapeFor; } } } // Разделение стопок if (mouse.RightButton == ButtonState.Pressed && !isMouse2Pressed) isMouse2Pressed = true; else if (mouse.RightButton == ButtonState.Released && isMouse2Pressed) { isMouse2Pressed = false; for (int row = 0; row < 3; row++) { for (int i = 0; i < 9; i++) { // Обычный инвентарь if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + (row * 54 + 249) + 3 && mouse.Y < 135 + (row * 54 + 249) + 3 + 48 && InventoryHelper.CanSplitStack(inventoryContents[(row * 9) + i]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[(row * 9) + i]); inventoryContents[(row * 9) + i] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } // Малый инвентарь else if (mouse.X > 248 + 20 + (i * 54 + 4) && mouse.X < 248 + 20 + (i * 54 + 4) + 48 && mouse.Y > 135 + 423 + 3 && mouse.Y < 135 + 423 + 3 + 48 && InventoryHelper.CanSplitStack(game.smallInventory.inventoryContents[i]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.smallInventory.inventoryContents[i]); game.smallInventory.inventoryContents[i] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } } } for (int i = 0; i < 2; i++) { // Инвентарь крафта: верх if (mouse.X > 248 + 260 + (i * 54 + 4) && mouse.X < 248 + 260 + (i * 54 + 4) + 48 && mouse.Y > 135 + 75 + 3 && mouse.Y < 135 + 75 + 3 + 48 && InventoryHelper.CanSplitStack(this.craftContents[i]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, this.craftContents[i]); this.craftContents[i] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } // Инвентарь крафта: низ else if (mouse.X > 248 + 260 + (i * 54 + 4) && mouse.X < 248 + 260 + (i * 54 + 4) + 48 && mouse.Y > 135 + 129 + 3 && mouse.Y < 135 + 129 + 3 + 48 && InventoryHelper.CanSplitStack(this.craftContents[i + 2]) && draggingStack == null) { InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, this.craftContents[i + 2]); this.craftContents[i + 2] = splittedStack[0]; draggingStack = splittedStack[1]; draggingStack.isDragging = true; } } } escapeFor: InventoryStack[] invStacks = new InventoryStack[] { craftContents[0], craftContents[1], craftContents[2], craftContents[3] }; if (CraftHelper.CheckIsExistingRecipe(CraftHelper.ConvertStacksToTypes(invStacks)) && this.craftContents[4] == null) { InventoryStack output = CraftHelper.GetOutputForRecipe(CraftHelper.ConvertStacksToTypes(invStacks), game); this.craftContents[4] = output; } else if (!CraftHelper.CheckIsExistingRecipe(CraftHelper.ConvertStacksToTypes(invStacks))) { if (craftContents[4] != null) this.craftContents[4].needRemove = true; } if (craftContents != null) { for (int i = 0; i < 5; i++) { if (craftContents[i] != null && craftContents[i].needRemove) craftContents[i] = null; } } base.Update(); }
public object Clone(Mine2D game) { InventoryStack invStack = null; if (stackType == InventoryStackTypes.Block) invStack = new InventoryStack((Block)this.GetBlock().Clone(game.blocksAtlas), this.count, this.maxCount); else if (stackType == InventoryStackTypes.Item) invStack = new InventoryStack((Item)this.GetItem().Clone(game.itemsAtlas), this.count, this.maxCount); return invStack; }
public static InventoryStack SumTwoStacks(Mine2D game, InventoryStack stack1, InventoryStack stack2) { InventoryStack stack = stack1.Clone(game) as InventoryStack; stack.AddAmount(stack2.count); return stack; }