first
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package game
|
||||
|
||||
func (e *Engine) Snapshot(forPlayerID string) map[string]interface{} {
|
||||
cp := e.CurrentPlayer()
|
||||
currentTurnID := ""
|
||||
if cp != nil {
|
||||
currentTurnID = cp.ID
|
||||
}
|
||||
|
||||
snap := map[string]interface{}{
|
||||
"phase": e.Phase,
|
||||
"turn_phase": e.TurnPhase,
|
||||
"current_turn": currentTurnID,
|
||||
"your_player_id": forPlayerID,
|
||||
"harmony_target": e.HarmonyTarget,
|
||||
}
|
||||
|
||||
var players []map[string]interface{}
|
||||
for _, p := range e.Players {
|
||||
pi := map[string]interface{}{
|
||||
"player_id": p.ID,
|
||||
"nickname": p.Nickname,
|
||||
"is_bot": p.IsBot,
|
||||
"is_exited": p.IsExited,
|
||||
"hand_card_count": len(p.Hand),
|
||||
"challenge_zone_count": len(p.ChallengeZone),
|
||||
}
|
||||
var skill []map[string]interface{}
|
||||
for _, c := range p.SkillZone {
|
||||
skill = append(skill, map[string]interface{}{
|
||||
"uid": c.UID, "type_id": c.TypeID, "name": c.Name, "mp": c.MP,
|
||||
})
|
||||
}
|
||||
pi["skill_zone"] = skill
|
||||
players = append(players, pi)
|
||||
}
|
||||
snap["players"] = players
|
||||
|
||||
me := e.GetPlayer(forPlayerID)
|
||||
var hand []map[string]interface{}
|
||||
if me != nil {
|
||||
for _, c := range me.Hand {
|
||||
hand = append(hand, map[string]interface{}{
|
||||
"uid": c.UID, "type_id": c.TypeID, "name": c.Name, "mp": c.MP,
|
||||
})
|
||||
}
|
||||
}
|
||||
snap["hand_cards"] = hand
|
||||
|
||||
var harmony []map[string]interface{}
|
||||
for _, c := range e.HarmonyZone {
|
||||
harmony = append(harmony, map[string]interface{}{
|
||||
"uid": c.UID, "face_up": false,
|
||||
})
|
||||
}
|
||||
snap["harmony_zone"] = harmony
|
||||
|
||||
if e.Effect != nil && e.Effect.Active {
|
||||
ef := e.Effect
|
||||
effectInfo := map[string]interface{}{
|
||||
"active": true,
|
||||
"card_type": ef.CardTypeID,
|
||||
"caster_id": ef.CasterID,
|
||||
}
|
||||
if e.EffectNeedsResponseFrom(forPlayerID) {
|
||||
effectInfo["needs_response"] = true
|
||||
effectInfo["choice_type"] = ef.ChoiceType
|
||||
effectInfo["choice_data"] = ef.ChoiceData
|
||||
} else {
|
||||
effectInfo["needs_response"] = false
|
||||
effectInfo["waiting_message"] = "等待效果结算中..."
|
||||
}
|
||||
snap["effect"] = effectInfo
|
||||
}
|
||||
|
||||
return snap
|
||||
}
|
||||
Reference in New Issue
Block a user