Skip to content

Commit

Permalink
fix: items
Browse files Browse the repository at this point in the history
  • Loading branch information
leaftail1880 committed Sep 4, 2024
1 parent 2ded531 commit 086823c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion entities/cannon.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"minecraft:physics": {},
"minecraft:input_ground_controlled": {},
"minecraft:movement": {
"value": 0.1
"value": 0.05
}
},

Expand Down
6 changes: 4 additions & 2 deletions src/lib/shop/buttons/item-modifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export function createItemModifier(
itemFilter: ItemFilter,
modifyItem: (itemSlot: ContainerSlot, itemStack: ItemStack, successBuyText: MaybeRawText) => boolean | void,
) {
shopForm.product
shopForm
.product()
.name(name)
.cost(new MultiCost(ShouldHaveItemCost.createFromFilter(itemFilter, itemFilterName), cost))
.onBuy((player, text, success, successBuyText) => {
Expand Down Expand Up @@ -57,7 +58,8 @@ export function createItemModifierSection(
onOpen: ShopMenuWithSlotCreate,
manualSelectItemButton = false,
) {
shopForm.product
shopForm
.product()
.name(name)
.cost(ShouldHaveItemCost.createFromFilter(itemFilter, itemFilterName))
.onBuy((player, text) => {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/shop/buttons/sellable-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ function createBuy(
const total = getTotal(count, i => getBuy(dbCount - i))
const cost = total <= 0 ? ImpossibleBuyCost : dbCount - count < 0 ? NoItemsToSell : new MoneyCost(total)

form.product
form
.product()
.name(itemDescription({ typeId: type, amount: count }))
.cost(cost)
.onBuy(player => {
Expand Down Expand Up @@ -128,7 +129,8 @@ function createSell(
new ItemCost(type, count),
)

form.product
form
.product()
.name(new MoneyCost(total).toString())
.cost(cost)
.onBuy(player => {
Expand Down
23 changes: 12 additions & 11 deletions src/lib/shop/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ export class ShopForm {
* @param onBuy
* @returns
*/
product = Product.create()
.creator<Product>(
product => {
this.buttons.push(product)
return product
},
message => this.show(message),
)
.player(this.player)
product() {
return Product.create()
.creator<Product>(
product => {
this.buttons.push(product)
return product
},
message => this.show(message),
)
.player(this.player)
}

itemModifier(
name: ProductName,
Expand Down Expand Up @@ -123,7 +125,7 @@ export class ShopForm {
* @param cost
*/
itemStack(item: ItemStack, cost: Cost, texture = getAuxOrTexture(item.typeId)) {
this.product
this.product()
.name(itemDescription(item, ''))
.cost(cost)
.onBuy(player => {
Expand All @@ -133,7 +135,6 @@ export class ShopForm {
player.container.addItem(item)
})
.setTexture(texture)
.setSell(false)
.setCustomCostBuy(true)

return this
Expand Down
6 changes: 4 additions & 2 deletions src/modules/places/stone-quarry/gunsmith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class Gunsmith extends ShopNpc {
).includes(item.typeId),
'Алмазный предмет',
(form, slot) => {
form.product
form
.product()
.name('Улучшить')
.cost(new MultiCost().item(i.NetheriteIngot, 1).money(1000))
.onBuy(() => this.upgradeDiamondSwordToNetherite(slot, player))
Expand All @@ -49,7 +50,8 @@ export class Gunsmith extends ShopNpc {
const item = slot.getItem()
if (!item?.durability) return false

form.product
form
.product()
.name('Починить')
.cost(new MultiCost().xp(item.durability.damage / 10))
.onBuy(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/places/tech-city/engineer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const NotNewbieCost = new (class NotNewbieCost extends Cost {

export class Engineer extends ShopNpc {
constructor(public group: Group) {
super(group.point('engineer').name('Инжeнер'))
super(group.point('engineer').name('Инженер'))

this.shop.body(() => 'Ну типа дай мне чертеж, a я те чета там наколупаю, да\n')
this.shop.menu(menu => {
Expand Down
14 changes: 9 additions & 5 deletions src/modules/places/village-of-explorers/mage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Mage extends ShopNpc {
(bookForm, book, bookItem) => {
const bookEnch = bookItem.enchantable?.getEnchantments()[0]
const type = Object.values(MinecraftEnchantmentTypes).find(e => e === bookEnch?.type.id)
if (!bookEnch || !type) return bookForm.product.name('Нет зачарований').cost(Incompatible).onBuy(doNothing)
if (!bookEnch || !type) return bookForm.product().name('Нет зачарований').cost(Incompatible).onBuy(doNothing)

bookForm.itemModifierSection(
'Предмет',
Expand All @@ -88,15 +88,17 @@ export class Mage extends ShopNpc {
const enchs = targetItem.enchantable?.getEnchantments().reduce((p, c) => p + c.level, 1) ?? 1
const level = targetItem.enchantable?.getEnchantment(new EnchantmentType(type))?.level ?? 0

itemForm.product
itemForm
.product()
.name(t.raw`§r§7Выбранная книга: ${translateEnchantment(bookEnch)}`)
.cost(FreeCost)
.onBuy(() => bookForm.show())
.setTexture(getAuxOrTexture(MinecraftItemTypes.EnchantedBook))

addSelectItem()

itemForm.product
itemForm
.product()
.name(t.raw`Зачаровать`)
.cost(
level >= bookEnch.level
Expand All @@ -119,7 +121,8 @@ export class Mage extends ShopNpc {

form.section('Оружие со способностями', (form, player) => {
const cost = new MultiCost().item(i.DiamondSword).item(i.LapisLazuli, 100).item(i.Redstone, 100).money(10000)
form.product
form
.product()
.name(`§r§fМеч со способностью §7${ItemAbility.names[ItemAbility.Ability.Vampire]}`)
.cost(cost)
.onBuy(player => {
Expand Down Expand Up @@ -183,7 +186,8 @@ export class Mage extends ShopNpc {
createEnch(form: ShopFormSection, item: ItemStack, slot: ContainerSlot) {
return (type: e, getCost: (currentLevel: number) => Cost, up = 1) => {
const { can, level } = this.updateEnchatnment(slot, type, up, true)
form.product
form
.product()
.name({ rawtext: [{ text: `${can ? '' : '§7'}+` }, ...(translateEnchantment(type).rawtext ?? [])] })
.cost(
can
Expand Down

0 comments on commit 086823c

Please sign in to comment.