Exemple #1
0
func (p *Player) DropItem(item gameObjectsBase.Itemer, amount int) (int, gameObjectsBase.Itemer) {
	db := connect.CreateConnect()
	place, new_item := p.ActiveObject.DropItem(item, amount)
	if s := p.getSlotByItem(item); s != consts.SLOT_DEFAULT {
		if item.GetAmount()-amount <= 0 {
			p.slots[s].item = nil
		}
		db.Exec("CALL dec_user_slot_amount(?, ?, ?, ?)", p.DBId, item.GetKindId(), s, amount)
	} else {
		db.Exec("CALL dec_user_item_amount(?, ?, ?, ?)", p.DBId, item.GetKindId(), place, amount)
	}
	return place, new_item
}
Exemple #2
0
func (p *Player) DeleteItem(item gameObjectsBase.Itemer, amount int) (bool, gameObjectsBase.Itemer) {
	var (
		i   gameObjectsBase.Itemer = item
		res bool                   = false
	)
	db := connect.CreateConnect()
	var place int
	place, i = p.Inventory.DeleteItem(item, amount)
	if s := p.getSlotByItem(item); s != consts.SLOT_DEFAULT {
		if item.GetAmount() <= 0 {
			p.slots[s].item = nil
			i = nil
		}
		_, err := db.Exec("CALL dec_user_slot_amount(?, ?, ?, ?)", p.DBId, item.GetKindId(), s, amount)
		res = err == nil
	} else {
		_, err := db.Exec("CALL dec_user_item_amount(?, ?, ?, ?)", p.DBId, item.GetKindId(), place, amount)
		res = err == nil
	}
	return res, i
}
Exemple #3
0
func (p *Player) PickUpItem(item gameObjectsBase.Itemer) (bool, gameObjectsBase.Itemer) {
	var err error = nil
	db := connect.CreateConnect()
	place, i := p.AddItem(item)
	if item.IsHeapItem() && place == -1 {
		_, err = db.Exec("CALL inc_user_slot_amount(?, ?, ?, ?)", p.DBId, item.GetKindId(), p.getSlotByItemType(item.GetItemType()), item.GetAmount())
	} else {
		_, err = db.Exec("CALL inc_user_item_amount(?, ?, ?, ?)", p.DBId, item.GetKindId(), place, item.GetAmount())
	}
	if err != nil {
		//
		fmt.Println(err)
	}
	return err == nil, i
}