This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ggmolly/feat/commander-collection
Add commander collection & Ship likes
- Loading branch information
Showing
11 changed files
with
153 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package answer | ||
|
||
import ( | ||
"github.com/ggmolly/belfast/connection" | ||
"github.com/ggmolly/belfast/orm" | ||
|
||
"github.com/ggmolly/belfast/protobuf" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
type MaxShipStat struct { | ||
GroupID uint32 `gorm:"column:group_id"` | ||
MaxStar uint32 `gorm:"column:max_star"` | ||
MaxIntimacy uint32 `gorm:"column:max_intimacy"` | ||
MaxLevel uint32 `gorm:"column:max_level"` | ||
} | ||
|
||
func CommanderCollection(buffer *[]byte, client *connection.Client) (int, int, error) { | ||
// Out of all commander's OwnedShips, return the max star, max intimacy, and max level | ||
// of each ship group (= TemplateID divided by 10) | ||
|
||
stats := []*protobuf.SHIP_STATISTICS_INFO{} | ||
orm.GormDB.Raw(` | ||
SELECT | ||
ship_id / 10 AS group_id, | ||
MAX(ships.star) AS max_star, | ||
MAX(intimacy) AS max_intimacy, | ||
MAX(level) AS max_level, | ||
MAX(propose::int) AS marry_flag, | ||
(SELECT COUNT(*) FROM likes WHERE group_id = owned_ships.ship_id / 10 AND liker_id = ?) AS heart_flag, | ||
(SELECT COUNT(*) FROM likes WHERE group_id = owned_ships.ship_id / 10) AS heart_count | ||
FROM owned_ships | ||
INNER JOIN ships ON owned_ships.ship_id = ships.template_id | ||
WHERE owner_id = ? | ||
GROUP BY group_id, owned_ships.ship_id | ||
`, client.Commander.CommanderID, client.Commander.CommanderID).Scan(&stats) | ||
|
||
response := protobuf.SC_17001{ | ||
DailyDiscuss: proto.Uint32(0), | ||
ShipInfoList: stats, | ||
} | ||
return client.SendMessage(17001, &response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package answer | ||
|
||
import ( | ||
"github.com/ggmolly/belfast/connection" | ||
"github.com/ggmolly/belfast/protobuf" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func GetShipDiscuss(buffer *[]byte, client *connection.Client) (int, int, error) { | ||
var payload protobuf.CS_17101 | ||
if err := proto.Unmarshal(*buffer, &payload); err != nil { | ||
return 0, 17102, err | ||
} | ||
var response protobuf.SC_17102 | ||
|
||
response.ShipDiscuss = &protobuf.SHIP_DISCUSS_INFO{ | ||
ShipGroupId: payload.ShipGroupId, | ||
DiscussCount: proto.Uint32(0), | ||
HeartCount: proto.Uint32(0), | ||
DailyDiscussCount: proto.Uint32(0), | ||
} | ||
|
||
return client.SendMessage(17102, &response) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package answer | ||
|
||
import ( | ||
"github.com/ggmolly/belfast/connection" | ||
"github.com/ggmolly/belfast/protobuf" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func UpdateShipLike(buffer *[]byte, client *connection.Client) (int, int, error) { | ||
var payload protobuf.CS_17107 | ||
if err := proto.Unmarshal(*buffer, &payload); err != nil { | ||
return 0, 17108, err | ||
} | ||
response := protobuf.SC_17108{ | ||
Result: proto.Uint32(boolToUint32(client.Commander.Like(*payload.ShipGroupId) != nil)), | ||
} | ||
return client.SendMessage(17108, &response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package orm | ||
|
||
import "time" | ||
|
||
type Like struct { | ||
GroupID uint32 `gorm:"primary_key;index:idx_likes_group_id_liker_id"` | ||
LikerID uint32 `gorm:"not_null;primary_key;index:idx_likes_group_id_liker_id"` | ||
CreatedAt time.Time | ||
|
||
Liker Commander `gorm:"foreignkey:LikerID;references:CommanderID"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.