fix Distribution typing, accepting & add demo

This commit is contained in:
wish
2023-11-07 21:07:49 +11:00
parent 29904d5b92
commit 14e61fd661
3 changed files with 46 additions and 27 deletions

View File

@@ -0,0 +1,11 @@
BEGIN;
-- Adds a Distribution that can be accepted up to 20 times that gives one of Item Type 30 (Item Box extra page)
INSERT INTO distribution (type, event_name, description, times_acceptable) VALUES (1, 'Extra Item Storage', '~C05Adds one new page to your Item Box.', 20);
INSERT INTO distribution_items (distribution_id, item_type, item_id, quantity) VALUES ((SELECT id FROM distribution ORDER BY id DESC LIMIT 1), 30, 0, 1);
-- Adds a Distribution that can be accepted up to 20 times that gives one of Item Type 31 (Equipment Box extra page)
INSERT INTO distribution (type, event_name, description, times_acceptable) VALUES (1, 'Extra Equipment Storage', '~C05Adds one new page to your Equipment Box.', 20);
INSERT INTO distribution_items (distribution_id, item_type, item_id, quantity) VALUES ((SELECT id FROM distribution ORDER BY id DESC LIMIT 1), 31, 0, 1);
END;

View File

@@ -7,7 +7,7 @@ CREATE TABLE public.distribution_items
(
id serial PRIMARY KEY,
distribution_id integer NOT NULL,
item_type integer,
item_type integer NOT NULL,
item_id integer,
quantity integer
);

View File

@@ -104,13 +104,9 @@ type DistributionItem struct {
Quantity uint32 `db:"quantity"`
}
func handleMsgMhfApplyDistItem(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfApplyDistItem)
bf := byteframe.NewByteFrame()
bf.WriteUint32(pkt.DistributionID)
func getDistributionItems(s *Session, i uint32) []DistributionItem {
var distItems []DistributionItem
rows, err := s.server.db.Queryx(`SELECT id, item_id, item_type, quantity FROM distribution_items WHERE distribution_id=$1`, pkt.DistributionID)
rows, err := s.server.db.Queryx(`SELECT id, item_type, COALESCE(item_id, 0) AS item_id, COALESCE(quantity, 0) AS quantity FROM distribution_items WHERE distribution_id=$1`, i)
if err == nil {
var distItem DistributionItem
for rows.Next() {
@@ -121,12 +117,31 @@ func handleMsgMhfApplyDistItem(s *Session, p mhfpacket.MHFPacket) {
distItems = append(distItems, distItem)
}
}
return distItems
}
func handleMsgMhfApplyDistItem(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfApplyDistItem)
bf := byteframe.NewByteFrame()
bf.WriteUint32(pkt.DistributionID)
distItems := getDistributionItems(s, pkt.DistributionID)
bf.WriteUint16(uint16(len(distItems)))
for _, item := range distItems {
bf.WriteUint8(item.ItemType)
bf.WriteUint32(item.ItemID)
bf.WriteUint32(item.Quantity)
bf.WriteUint32(item.ID)
}
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}
func handleMsgMhfAcquireDistItem(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfAcquireDistItem)
if pkt.DistributionID > 0 {
_, err := s.server.db.Exec(`INSERT INTO public.distributions_accepted VALUES ($1, $2)`, pkt.DistributionID, s.charID)
if err == nil {
distItems := getDistributionItems(s, pkt.DistributionID)
for _, item := range distItems {
switch item.ItemType {
case 17:
_ = addPointNetcafe(s, int(item.Quantity))
@@ -144,15 +159,8 @@ func handleMsgMhfApplyDistItem(s *Session, p mhfpacket.MHFPacket) {
}
}
}
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
if pkt.DistributionID > 0 {
_, err = s.server.db.Exec(`INSERT INTO public.distributions_accepted VALUES ($1, $2)`, pkt.DistributionID, s.charID)
}
}
func handleMsgMhfAcquireDistItem(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfAcquireDistItem)
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
}