完善了Web管理端
This commit is contained in:
+6
-4
@@ -16,10 +16,12 @@ type CardDef struct {
|
||||
}
|
||||
|
||||
type Card struct {
|
||||
UID string
|
||||
TypeID string
|
||||
Name string
|
||||
MP int
|
||||
UID string
|
||||
TypeID string
|
||||
Name string
|
||||
MP int
|
||||
PlacedBy string
|
||||
PlacedByNick string
|
||||
}
|
||||
|
||||
var AllCardDefs = []CardDef{
|
||||
|
||||
+40
-1
@@ -11,6 +11,7 @@ type PlayerState struct {
|
||||
ID string
|
||||
Nickname string
|
||||
IsBot bool
|
||||
BotControlled bool
|
||||
Hand []*Card
|
||||
SkillZone []*Card
|
||||
ChallengeZone []*Card
|
||||
@@ -31,6 +32,8 @@ type Engine struct {
|
||||
Effect *EffectState
|
||||
ChaosMode bool
|
||||
ActionLogs []string
|
||||
TurnID int
|
||||
RoundNum int
|
||||
rng *rand.Rand
|
||||
}
|
||||
|
||||
@@ -67,6 +70,8 @@ func (e *Engine) Deal() {
|
||||
e.CurrentTurn = e.findStartingPlayer()
|
||||
e.Phase = "playing"
|
||||
e.TurnPhase = "select_card"
|
||||
e.RoundNum = 1
|
||||
e.TurnID = 0
|
||||
e.startTurn()
|
||||
}
|
||||
|
||||
@@ -82,6 +87,11 @@ func (e *Engine) findStartingPlayer() int {
|
||||
}
|
||||
|
||||
func (e *Engine) startTurn() {
|
||||
e.TurnID++
|
||||
cp := e.CurrentPlayer()
|
||||
if cp != nil && !cp.IsBot && !cp.BotControlled {
|
||||
e.log(fmt.Sprintf("轮到 %s 的回合 (第%d轮)", cp.Nickname, e.RoundNum))
|
||||
}
|
||||
if e.CheckInfectedEffect() {
|
||||
e.TurnPhase = "effect_resolving"
|
||||
} else {
|
||||
@@ -190,6 +200,8 @@ func (e *Engine) doChallenge(p *PlayerState, targetID string) error {
|
||||
}
|
||||
card := e.SelectedCard
|
||||
e.removeFromHand(p, card.UID)
|
||||
card.PlacedBy = p.ID
|
||||
card.PlacedByNick = p.Nickname
|
||||
target.ChallengeZone = append(target.ChallengeZone, card)
|
||||
e.log(p.Nickname + " 质疑了 " + target.Nickname)
|
||||
e.SelectedCard = nil
|
||||
@@ -214,10 +226,14 @@ func (e *Engine) finishTurn(p *PlayerState) {
|
||||
|
||||
func (e *Engine) advanceTurn() {
|
||||
n := len(e.Players)
|
||||
old := e.CurrentTurn
|
||||
next := (e.CurrentTurn + 1) % n
|
||||
for i := 0; i < n; i++ {
|
||||
if !e.Players[next].IsExited {
|
||||
e.CurrentTurn = next
|
||||
if next <= old {
|
||||
e.RoundNum++
|
||||
}
|
||||
return
|
||||
}
|
||||
next = (next + 1) % n
|
||||
@@ -256,6 +272,29 @@ func (e *Engine) IsHandTargetable(p *PlayerState) bool {
|
||||
return !p.IsExited
|
||||
}
|
||||
|
||||
func (e *Engine) UpdatePlayerID(oldID, newID string) {
|
||||
for _, p := range e.Players {
|
||||
if p.ID == oldID {
|
||||
p.ID = newID
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Engine) SetBotControlled(playerID string, v bool) {
|
||||
for _, p := range e.Players {
|
||||
if p.ID == playerID {
|
||||
p.BotControlled = v
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Engine) IsPlayerBotLike(playerID string) bool {
|
||||
p := e.GetPlayer(playerID)
|
||||
return p != nil && (p.IsBot || p.BotControlled)
|
||||
}
|
||||
|
||||
func (e *Engine) EffectNeedsResponseFrom(playerID string) bool {
|
||||
if !e.IsEffectResolving() {
|
||||
return false
|
||||
@@ -271,7 +310,7 @@ func (e *Engine) EffectNeedsResponseFrom(playerID string) bool {
|
||||
|
||||
func (e *Engine) BotAutoPlay(playerID string) (string, string) {
|
||||
p := e.GetPlayer(playerID)
|
||||
if p == nil || !p.IsBot || p.IsExited {
|
||||
if p == nil || (!p.IsBot && !p.BotControlled) || p.IsExited {
|
||||
return "", ""
|
||||
}
|
||||
var playable []*Card
|
||||
|
||||
+14
-2
@@ -13,6 +13,8 @@ func (e *Engine) Snapshot(forPlayerID string) map[string]interface{} {
|
||||
"current_turn": currentTurnID,
|
||||
"your_player_id": forPlayerID,
|
||||
"harmony_target": e.HarmonyTarget,
|
||||
"round_num": e.RoundNum,
|
||||
"turn_id": e.TurnID,
|
||||
}
|
||||
|
||||
var players []map[string]interface{}
|
||||
@@ -47,10 +49,20 @@ func (e *Engine) Snapshot(forPlayerID string) map[string]interface{} {
|
||||
}
|
||||
snap["hand_cards"] = hand
|
||||
|
||||
var myChallenge []map[string]interface{}
|
||||
if me != nil {
|
||||
for _, c := range me.ChallengeZone {
|
||||
myChallenge = append(myChallenge, map[string]interface{}{
|
||||
"uid": c.UID, "placed_by": c.PlacedByNick,
|
||||
})
|
||||
}
|
||||
}
|
||||
snap["my_challenge_zone"] = myChallenge
|
||||
|
||||
var harmony []map[string]interface{}
|
||||
for _, c := range e.HarmonyZone {
|
||||
for i, c := range e.HarmonyZone {
|
||||
harmony = append(harmony, map[string]interface{}{
|
||||
"uid": c.UID, "face_up": false,
|
||||
"uid": c.UID, "face_up": false, "order": i + 1,
|
||||
})
|
||||
}
|
||||
snap["harmony_zone"] = harmony
|
||||
|
||||
Reference in New Issue
Block a user