first
This commit is contained in:
+104
@@ -0,0 +1,104 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CardDef struct {
|
||||
TypeID string
|
||||
Name string
|
||||
MP int
|
||||
Priority int
|
||||
Count int
|
||||
Unusable bool
|
||||
}
|
||||
|
||||
type Card struct {
|
||||
UID string
|
||||
TypeID string
|
||||
Name string
|
||||
MP int
|
||||
}
|
||||
|
||||
var AllCardDefs = []CardDef{
|
||||
{"student_council_president", "学生会长", 3, 4, 1, false},
|
||||
{"class_monitor", "班长", 2, 4, 2, false},
|
||||
{"honor_student", "优等生", 2, 4, 3, false},
|
||||
{"discipline_committee_member", "风纪委员", 1, 4, 2, false},
|
||||
{"library_committee_member", "图书委员", 1, 4, 3, false},
|
||||
{"health_committee_member", "保健委员", 1, 4, 2, false},
|
||||
{"young_lady", "大小姐", 1, 4, 3, false},
|
||||
{"newspaper_club", "新闻部", 1, 4, 3, false},
|
||||
{"go_home_club", "归宅部", 0, 5, 3, false},
|
||||
{"infected_person", "感染者", 0, 2, 1, false},
|
||||
{"accomplice", "共犯", 0, 3, 1, false},
|
||||
{"culprit", "犯人", 0, 3, 1, true},
|
||||
{"alien", "外星人", -1, 1, 1, false},
|
||||
}
|
||||
|
||||
type RemoveRule struct {
|
||||
TypeID string
|
||||
Count int
|
||||
}
|
||||
|
||||
type GameSetting struct {
|
||||
PlayerCount int
|
||||
HarmonyTarget int
|
||||
RemoveCards []RemoveRule
|
||||
TotalCards int
|
||||
HandSize int
|
||||
}
|
||||
|
||||
var GameSettings = map[int]GameSetting{
|
||||
3: {3, 9, []RemoveRule{
|
||||
{"library_committee_member", 1}, {"accomplice", 1}, {"honor_student", 1},
|
||||
{"discipline_committee_member", 1}, {"young_lady", 1}, {"newspaper_club", 1}, {"go_home_club", 1},
|
||||
}, 18, 6},
|
||||
4: {4, 8, []RemoveRule{{"library_committee_member", 1}}, 24, 6},
|
||||
5: {5, 7, nil, 25, 5},
|
||||
6: {6, 6, []RemoveRule{{"library_committee_member", 1}}, 24, 4},
|
||||
}
|
||||
|
||||
func BuildDeck(playerCount int) ([]*Card, GameSetting) {
|
||||
setting := GameSettings[playerCount]
|
||||
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
removeCount := make(map[string]int)
|
||||
for _, r := range setting.RemoveCards {
|
||||
removeCount[r.TypeID] += r.Count
|
||||
}
|
||||
|
||||
var deck []*Card
|
||||
uid := 0
|
||||
for _, def := range AllCardDefs {
|
||||
toRemove := removeCount[def.TypeID]
|
||||
toAdd := def.Count - toRemove
|
||||
for i := 0; i < toAdd; i++ {
|
||||
uid++
|
||||
deck = append(deck, &Card{
|
||||
UID: fmt.Sprintf("c_%03d", uid),
|
||||
TypeID: def.TypeID,
|
||||
Name: def.Name,
|
||||
MP: def.MP,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
rng.Shuffle(len(deck), func(i, j int) { deck[i], deck[j] = deck[j], deck[i] })
|
||||
return deck, setting
|
||||
}
|
||||
|
||||
func IsUnusable(typeID string) bool {
|
||||
return typeID == "culprit"
|
||||
}
|
||||
|
||||
func GetCardDef(typeID string) *CardDef {
|
||||
for i := range AllCardDefs {
|
||||
if AllCardDefs[i].TypeID == typeID {
|
||||
return &AllCardDefs[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user