Example #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
}
Example #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
}
Example #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)
		}
	}
}
Example #4
0
func MakeAccount(username string) *Account {
	a := &Account{
		Username: username,
		Register: time.Now(),
	}

	event.Fire(event.AccountMake, a)

	return a
}
Example #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)
}
Example #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
}
Example #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
}
Example #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
}
Example #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
}
Example #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
}
Example #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
}
Example #12
0
func (e *Entity) QueryUniverse(universeId uint) {
	event.Fire(event.EntityQuery, e, universeId)
	e.Id = 0 // held temp id, that is deleted now
}