예제 #1
0
func (p *Player) Delete() error {
	_, err := Connection.Exec("DELETE FROM players WHERE username=?", p.Username)

	if err == nil {
		event.Fire(event.PlayerDelete, p)
	}

	return err
}
예제 #2
0
func (a *Account) Delete() error {
	_, err := Connection.Exec("DELETE FROM accounts WHERE username=?", a.Username)

	if err == nil {
		event.Fire(event.AccountDelete, a)
	}

	return err
}
예제 #3
0
func (m *Movement) Update(u *save.Universe, e *save.Entity, d time.Duration) {
	if m.Lock {
		return
	}

	if m.Vector == nil {
		event.Fire(event.MovementUpdate, e, nil)
		return
	}

	location, ok := e.Component(save.COMP_Location).(*save.Location)

	if !ok {
		logrus.WithFields(logrus.Fields{
			"Universe": u.Id,
			"Entity":   e.Id,
		}).Error("run.Movement: no location to move")
		return
	}

	shape := location.Shape.Move(*m.Vector)
	location.Shape = shape

	event.Fire(event.MovementUpdate, e, m.Vector)

	for entityId, entity := range u.Entities {
		if entity == nil {
			continue
		}

		if e.Id == entityId {
			continue
		}

		location2, ok := entity.Component(save.COMP_Location).(*save.Location)
		if !ok {
			continue
		}

		if space.DistanceShapeShape(location.Shape, location2.Shape) < 1 {
			event.Fire(event.MovementCollision, e, entity, u)
		}
	}
}
예제 #4
0
func MakeAccount(username string) *Account {
	a := &Account{
		Username: username,
		Register: time.Now(),
	}

	event.Fire(event.AccountMake, a)

	return a
}
예제 #5
0
func keyup(p *save.Player, key string) {
	bindings := p.Entity.Component(save.COMP_Bindings).(save.Bindings)
	binding := bindings[key]

	if binding == nil {
		return
	}

	event.Fire(event.BindingUp, p, binding)
}
예제 #6
0
func MakePlayer(username string) *Player {
	p := &Player{
		Username: username,
		BagSize:  DEFAULT_BAG_SIZE,
		Entity:   MakeEntity(),
	}

	p.Entity.AddComponent(p)

	event.Fire(event.PlayerMake, p)

	return p
}
예제 #7
0
func (a *Account) Insert() error {
	_, err := Connection.Exec(
		"INSERT INTO accounts (username, password, register) values (?, ?, ?, ?)",
		a.Username,
		a.Password,
		a.Register.Unix(),
	)

	if err == nil {
		event.Fire(event.AccountInsert, a)
	}

	return err
}
예제 #8
0
func (p *Player) Query() error {
	row := Connection.QueryRow(
		"SELECT level, experience, money, class, bagsize FROM players WHERE username=?",
		p.Username,
	)

	if err := row.Scan(&p.Level, &p.Experience, &p.Money, &p.Class, &p.BagSize); err != nil {
		return err
	}

	event.Fire(event.PlayerQuery, p)

	return nil
}
예제 #9
0
func (u *Universe) Query() error {
	row := Connection.QueryRow(
		"SELECT dx, dy, private FROM universes WHERE id=?",
		u.Id,
	)

	if err := row.Scan(&u.Space.Rect.Dimension.DX, &u.Space.Rect.Dimension.DY, &u.Private); err != nil {
		return err
	}

	event.Fire(event.UniverseQuery, u)

	return nil
}
예제 #10
0
func (a *Account) Query() error {
	row := Connection.QueryRow(
		"SELECT password, register FROM accounts WHERE username=?",
		a.Username,
	)

	var timebuff int64
	if err := row.Scan(&a.Password, &timebuff); err != nil {
		return err
	}

	a.Register = time.Unix(timebuff, 0)

	event.Fire(event.AccountQuery, a)

	return nil
}
예제 #11
0
func (p *Player) Insert() error {
	_, err := Connection.Exec(
		"INSERT INTO players (username, level, experience, money, class, bagsize) values (?, ?, ?, ?, ?, ?)",
		p.Username,
		p.Level,
		p.Experience,
		p.Money,
		p.Class,
		p.BagSize,
	)

	if err == nil {
		event.Fire(event.PlayerInsert, p)
	}

	return err
}
예제 #12
0
func (e *Entity) QueryUniverse(universeId uint) {
	event.Fire(event.EntityQuery, e, universeId)
	e.Id = 0 // held temp id, that is deleted now
}