func GetSource(c context.Context, w http.ResponseWriter, r *http.Request, u *User, g *goon.Goon) (interface{}, error) { var ss []*Source k := g.Kind(&Source{}) q := datastore.NewQuery(k).Ancestor(g.Key(u)) if _, err := g.GetAll(q, &ss); err != nil { return nil, err } ret := make([]*models.Source, len(ss)) for i, s := range ss { ret[i] = &models.Source{ Protocol: s.Protocol.StringID(), Name: s.ID, Blob: s.Blob, } } return ret, nil }
func updateVillage(us UpdateSchedule, g *goon.Goon) error { village := Village{No: us.VillageNo} if err := g.Get(&village); err != nil || village.Day <= 0 { return nil } village.Day++ err := g.RunInTransaction(func(g *goon.Goon) error { vKey := g.Key(village) q3 := datastore.NewQuery("Person").Ancestor(vKey).Order("CreatedTime") people := make([]Person, 0, 10) _, err := g.GetAll(q3, &people) if err != nil { return err } // 3日目以降のみ投票処理 var posts []Post if village.Day >= 3 { posts = Execute(people) } else if village.Day == 2 { t := setting.NpcName + "は無残な死体で見つかった。" p := Post{Author: "System", AuthorID: "0", Text: t, Time: time.Now(), Type: SystemMessage} posts = append(posts, p) p2 := Post{Author: "System", AuthorID: "0", Time: time.Now(), Type: SystemMessage} p2.Text = setting.SecondDaySystemPost posts = append(posts, p2) } before := make([]Person, len(people)) copy(before, people) posts = append(posts, Fortune(people)...) Raid(people) // Check Dead Person peaceful := true for i := range people { if !before[i].Dead && people[i].Dead { peaceful = false t := people[i].Name + "は無残な死体で見つかった。" p := Post{Author: "System", AuthorID: "0", Text: t, Time: time.Now(), Type: SystemMessage} posts = append(posts, p) } people[i].VoteTarget = "" people[i].AbilityTarget = "" } if peaceful && village.Day >= 3 { t := "今日は誰も犠牲者がいないようだ。" p := Post{Author: "System", AuthorID: "0", Text: t, Time: time.Now(), Type: SystemMessage} posts = append(posts, p) } j := Judge(people) if j > 0 { village.Day *= -1 var t string switch j { case 1: t = setting.VillagerWin case 2: t = setting.WerewolfWin case 3: t = setting.FoxWin } p := Post{Author: "System", AuthorID: "0", Text: t, Time: time.Now(), Type: SystemMessage} posts = append(posts, p) } _, err = g.Put(&village) if err != nil { return err } for i := range posts { posts[i].Day = village.Day if posts[i].Day <= -1 { posts[i].Day = -1 } posts[i].ParentKey = vKey _, err = g.Put(&posts[i]) if err != nil { return err } } for i := 0; i < len(people); i++ { people[i].ParentKey = vKey _, err = g.Put(&people[i]) if err != nil { return err } } us.SetNextUpdateTime(time.Now()) us.ParentKey = vKey _, err = g.Put(&us) if err != nil { return err } return nil }, nil) if err != nil { return err } return nil }