mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 07:55:33 +01:00
fix Distribution typing, accepting & add demo
This commit is contained in:
11
bundled-schema/DistributionDemo.sql
Normal file
11
bundled-schema/DistributionDemo.sql
Normal 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;
|
||||||
@@ -7,7 +7,7 @@ CREATE TABLE public.distribution_items
|
|||||||
(
|
(
|
||||||
id serial PRIMARY KEY,
|
id serial PRIMARY KEY,
|
||||||
distribution_id integer NOT NULL,
|
distribution_id integer NOT NULL,
|
||||||
item_type integer,
|
item_type integer NOT NULL,
|
||||||
item_id integer,
|
item_id integer,
|
||||||
quantity integer
|
quantity integer
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -104,13 +104,9 @@ type DistributionItem struct {
|
|||||||
Quantity uint32 `db:"quantity"`
|
Quantity uint32 `db:"quantity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfApplyDistItem(s *Session, p mhfpacket.MHFPacket) {
|
func getDistributionItems(s *Session, i uint32) []DistributionItem {
|
||||||
pkt := p.(*mhfpacket.MsgMhfApplyDistItem)
|
|
||||||
|
|
||||||
bf := byteframe.NewByteFrame()
|
|
||||||
bf.WriteUint32(pkt.DistributionID)
|
|
||||||
var distItems []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 {
|
if err == nil {
|
||||||
var distItem DistributionItem
|
var distItem DistributionItem
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@@ -121,12 +117,31 @@ func handleMsgMhfApplyDistItem(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
distItems = append(distItems, distItem)
|
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)))
|
bf.WriteUint16(uint16(len(distItems)))
|
||||||
for _, item := range distItems {
|
for _, item := range distItems {
|
||||||
bf.WriteUint8(item.ItemType)
|
bf.WriteUint8(item.ItemType)
|
||||||
bf.WriteUint32(item.ItemID)
|
bf.WriteUint32(item.ItemID)
|
||||||
bf.WriteUint32(item.Quantity)
|
bf.WriteUint32(item.Quantity)
|
||||||
bf.WriteUint32(item.ID)
|
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 {
|
switch item.ItemType {
|
||||||
case 17:
|
case 17:
|
||||||
_ = addPointNetcafe(s, int(item.Quantity))
|
_ = 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))
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user