test

test
mail@pastecode.io avatar
unknown
golang
2 months ago
3.6 kB
4
Indexable
Never
// returns page, x_pos, y_pos, fitsHere(bool)
func (c *MuleChar) GetAvailablePositionForItem(itemName string, itemWidth, itemHeight, unid int) (int, int, int, bool) {
	allSlots := c.GetMuleSpace()
	fitsHere := true
	page := 1 //we start with stash stab 1 be
	xPos := 1
	yPos := 1
	for i := 0; i <= 9; i++ {
		if isSharedStashOnlyCharm(itemName, unid) {
			//these items only fit in shared stash
			continue
		}

		for y := 0; y <= 9; y++ {
			fitsHere = true
			for addI := 0; addI < itemWidth; addI++ {
				for addY := 0; addY < itemHeight; addY++ {
					if i+addI > 9 || y+addY > 9 {
						fitsHere = false
						continue
					}
					if allSlots.StashTabOne[i+addI][y+addY] == 1 {
						fitsHere = false
						continue
					}
				}
			}
			if fitsHere {
				return page, xPos + i, yPos + y, fitsHere //page=1 is stash tab 1
			}
		}
	}

	if !isSharedStashOnlyCharm(itemName, unid) {
		//shared stashes are reserved for anni/gheed/torch so anything else will be thrown here
		return 0, 0, 0, false
	}

	page = 2
	for i := 0; i <= 9; i++ {
		for y := 0; y <= 9; y++ {
			fitsHere = true
			for addI := 0; addI < itemWidth; addI++ {
				for addY := 0; addY < itemHeight; addY++ {
					if i+addI > 9 || y+addY > 9 {
						fitsHere = false
						continue
					}
					if allSlots.StashTabTwo[i+addI][y+addY] == 1 {
						fitsHere = false
						continue
					}
				}
			}
			if fitsHere {
				return page, xPos + i, yPos + y, fitsHere //page=1 is stash tab 1
			}
		}
	}

	page = 3
	for i := 0; i <= 9; i++ {
		for y := 0; y <= 9; y++ {

			fitsHere = true
			for addI := 0; addI < itemWidth; addI++ {
				for addY := 0; addY < itemHeight; addY++ {
					if i+addI > 9 || y+addY > 9 {
						fitsHere = false
						continue
					}
					if allSlots.StashTabThree[i+addI][y+addY] == 1 {
						fitsHere = false
						continue
					}
				}
			}
			if fitsHere {
				return page, xPos + i, yPos + y, fitsHere //page=1 is stash tab 1
			}
		}
	}

	page = 4
	for i := 0; i <= 9; i++ {
		for y := 0; y <= 9; y++ {

			fitsHere = true
			for addI := 0; addI < itemWidth; addI++ {
				for addY := 0; addY < itemHeight; addY++ {
					if i+addI > 9 || y+addY > 9 {
						fitsHere = false
						continue
					}
					if allSlots.StashTabFour[i+addI][y+addY] == 1 {
						fitsHere = false
						continue
					}
				}
			}
			if fitsHere {
				return page, xPos + i, yPos + y, fitsHere //page=1 is stash tab 1
			}
		}
	}

	return 0, 0, 0, fitsHere
	//TODO: INVENTORY IS TURNED OFF
	//inventory comes last
	//page = 0
	//for i := 0; i <= 9; i++ {
	//	for y := 0; y <= 3; y++ {
	//		if isSharedStashOnlyCharm(itemName, unid) {
	//			//these items only fit in shared stash
	//			continue
	//		}
	//		fitsHere = true
	//		for addI := 0; addI < itemWidth; addI++ {
	//			for addY := 0; addY < itemHeight; addY++ {
	//				if i+addI > 9 || y+addY > 3 {
	//					fitsHere = false
	//					continue
	//				}
	//				if allSlots.Inventory[i+addI][y+addY] == 1 {
	//					fitsHere = false
	//					continue
	//				}
	//			}
	//		}
	//		if fitsHere {
	//			return page, xPos + i, yPos + y, fitsHere //page=0 is inventory
	//		}
	//	}
	//}
	//
	//return 0, 0, 0, fitsHere
}

// checks if the item only fits in shared stashes
func isSharedStashOnlyCharm(itemName string, unid int) bool {
	if strings.ToUpper(itemName) == "ANNIHILUS" || strings.ToUpper(itemName) == "GHEEDS FORTUNE" || strings.ToUpper(itemName) == "HELLFIRE TORCH" {
		return true
	}

	if (strings.ToUpper(itemName) == "SMALL CHARM" || strings.ToUpper(itemName) == "LARGE CHARM" || strings.ToUpper(itemName) == "GRAND CHARM") && unid == 1 {
		return true
	}

	return false
}
Leave a Comment