first gen
This commit is contained in:
97
ent/schema/card.go
Normal file
97
ent/schema/card.go
Normal file
@ -0,0 +1,97 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
"math/rand"
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Card holds the schema definition for the Card entity.
|
||||
type Card struct {
|
||||
ent.Schema
|
||||
}
|
||||
var url = "https://card.syui.ai"
|
||||
|
||||
var card int
|
||||
var super string
|
||||
var cp int
|
||||
|
||||
func (Card) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("card").
|
||||
Immutable().
|
||||
DefaultFunc(func() int {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var a = rand.Intn(10)
|
||||
if a == 1 {
|
||||
card = rand.Intn(15)
|
||||
} else {
|
||||
card = 0
|
||||
}
|
||||
if card == 13 {
|
||||
card = 14
|
||||
}
|
||||
return card
|
||||
}).
|
||||
Optional(),
|
||||
|
||||
field.String("status").
|
||||
Immutable().
|
||||
DefaultFunc(func() string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var a = rand.Intn(10)
|
||||
if a == 1 {
|
||||
super = "super"
|
||||
} else {
|
||||
super = "normal"
|
||||
}
|
||||
if card == 0 {
|
||||
super = "normal"
|
||||
}
|
||||
return super
|
||||
}).
|
||||
Optional(),
|
||||
|
||||
field.Int("cp").
|
||||
Immutable().
|
||||
DefaultFunc(func() int {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var cp = rand.Intn(100)
|
||||
if cp == 1 {
|
||||
cp = rand.Intn(250)
|
||||
}
|
||||
if card > 1 {
|
||||
cp = cp + rand.Intn(250)
|
||||
}
|
||||
if super == "super" {
|
||||
cp = cp + rand.Intn(500)
|
||||
}
|
||||
|
||||
return cp
|
||||
}).
|
||||
Optional(),
|
||||
|
||||
field.String("url").
|
||||
Immutable().
|
||||
Default(url).
|
||||
Optional(),
|
||||
|
||||
field.Time("created_at").
|
||||
Immutable().
|
||||
Optional().
|
||||
Default(func() time.Time {
|
||||
return time.Now().In(jst)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
func (Card) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("card").
|
||||
Unique().
|
||||
Required(),
|
||||
}
|
||||
}
|
35
ent/schema/group.go
Normal file
35
ent/schema/group.go
Normal file
@ -0,0 +1,35 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// Group holds the schema definition for the Group entity.
|
||||
type Group struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Group.
|
||||
func (Group) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Group.
|
||||
func (Group) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("users", User.Type),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the Group.
|
||||
func (Group) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("name").Unique(),
|
||||
}
|
||||
}
|
||||
|
74
ent/schema/user.go
Normal file
74
ent/schema/user.go
Normal file
@ -0,0 +1,74 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
//"regexp"
|
||||
//"math/rand"
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
//"entgo.io/ent/schema/mixin"
|
||||
)
|
||||
|
||||
var jst,err = time.LoadLocation("Asia/Tokyo")
|
||||
|
||||
// User holds the schema definition for the User entity.
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func Nextime() (tt string){
|
||||
t := time.Now().In(jst)
|
||||
//t := time.Now().Add(time.Hour * 24 * 1).In(jst)
|
||||
tt = t.Format("20060102")
|
||||
return
|
||||
}
|
||||
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
|
||||
field.String("username").
|
||||
NotEmpty().
|
||||
Immutable().
|
||||
MaxLen(30).
|
||||
//Match(regexp.MustCompile("[a-z]+$")).
|
||||
Unique(),
|
||||
|
||||
//field.Bool("limit").
|
||||
//Optional().
|
||||
//Default(false),
|
||||
|
||||
field.Time("created_at").
|
||||
Immutable().
|
||||
Optional().
|
||||
Default(func() time.Time {
|
||||
return time.Now().In(jst)
|
||||
}),
|
||||
|
||||
field.Time("updated_at").
|
||||
Optional().
|
||||
Default(func() time.Time {
|
||||
return time.Now().In(jst)
|
||||
}),
|
||||
|
||||
field.String("next").
|
||||
Default(Nextime()).
|
||||
Optional(),
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the User.
|
||||
func (User) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("username").Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("card", Card.Type),
|
||||
//Unique(),
|
||||
}
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
"regexp"
|
||||
"entgo.io/ent"
|
||||
"math/rand"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/kyokomi/lottery"
|
||||
)
|
||||
|
||||
type Users struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func Random(i int) (l int){
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
l = rand.Intn(20)
|
||||
for l == 0 {
|
||||
l = rand.Intn(20)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Kira(i int) (l bool){
|
||||
lot := lottery.New(rand.New(rand.NewSource(time.Now().UnixNano())))
|
||||
if lot.Lot(i) {
|
||||
l = true
|
||||
} else {
|
||||
l = false
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var jst,err = time.LoadLocation("Asia/Tokyo")
|
||||
|
||||
var a = Random(4)
|
||||
var d = Random(20)
|
||||
var h = Random(20)
|
||||
var k = Random(20)
|
||||
var s = Random(20)
|
||||
var c = Random(20)
|
||||
var battle = 2
|
||||
|
||||
func StatusR()(status string){
|
||||
if d == 1 {
|
||||
var status = "super"
|
||||
return status
|
||||
} else {
|
||||
var status = "normal"
|
||||
return status
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func CharaR()(chara string){
|
||||
if a == 1 {
|
||||
var chara = "drai"
|
||||
return chara
|
||||
} else if a == 2 {
|
||||
var chara = "octkat"
|
||||
return chara
|
||||
} else if a == 3 {
|
||||
var chara = "kyosuke"
|
||||
return chara
|
||||
} else {
|
||||
var chara = "ponta"
|
||||
return chara
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Nextime() (tt string){
|
||||
t := time.Now().Add(time.Hour * 24 * 1).In(jst)
|
||||
tt = t.Format("20060102")
|
||||
return
|
||||
}
|
||||
|
||||
func (Users) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
|
||||
field.String("user").
|
||||
NotEmpty().
|
||||
Immutable().
|
||||
MaxLen(7).
|
||||
Match(regexp.MustCompile("[a-z]+$")).
|
||||
Unique(),
|
||||
|
||||
field.String("chara").
|
||||
Immutable().
|
||||
Default(CharaR()).
|
||||
Optional(),
|
||||
|
||||
field.Int("skill").
|
||||
Immutable().
|
||||
Optional().
|
||||
Default(k),
|
||||
|
||||
field.Int("hp").
|
||||
Optional().
|
||||
Default(h),
|
||||
|
||||
field.Int("attack").
|
||||
Optional().
|
||||
Default(a),
|
||||
|
||||
field.Int("defense").
|
||||
Optional().
|
||||
Default(d),
|
||||
|
||||
field.Int("critical").
|
||||
Optional().
|
||||
Default(c),
|
||||
|
||||
field.Int("battle").
|
||||
Optional().
|
||||
Default(1),
|
||||
|
||||
field.Int("win").
|
||||
Optional().
|
||||
Default(0),
|
||||
|
||||
field.Int("day").
|
||||
Optional().
|
||||
Default(0),
|
||||
|
||||
field.Float("percentage").
|
||||
Optional().
|
||||
Default(0),
|
||||
|
||||
field.Bool("limit").
|
||||
Optional().
|
||||
Default(false),
|
||||
|
||||
field.String("status").
|
||||
Immutable().
|
||||
Optional().
|
||||
Default(StatusR()),
|
||||
|
||||
field.String("comment").
|
||||
Optional().
|
||||
Default(""),
|
||||
|
||||
field.Time("created_at").
|
||||
Immutable().
|
||||
Optional().
|
||||
Default(func() time.Time {
|
||||
return time.Now().In(jst)
|
||||
}),
|
||||
|
||||
field.String("next").
|
||||
Default(Nextime()).
|
||||
Optional(),
|
||||
|
||||
field.Time("updated_at").
|
||||
Optional().
|
||||
Default(func() time.Time {
|
||||
return time.Now().In(jst)
|
||||
}),
|
||||
|
||||
field.String("url").
|
||||
Immutable().
|
||||
Optional().
|
||||
Default("https://syui.cf/api"),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (Users) Edges() []ent.Edge {
|
||||
return []ent.Edge{}
|
||||
}
|
||||
|
Reference in New Issue
Block a user