Пример #1
0
func Super(u *save.Universe, e *save.Entity, data map[string]string) {
	p := e.Component(save.COMP_Player).(*save.Player)

	_, err := save.Connection.Exec("DELETE FROM actions_players WHERE username=?",
		p.Username,
	)

	if err != nil {
		logrus.Error(err)
		return
	}

	_, err = save.Connection.Exec("INSERT INTO actions_players (username, spellid, timer) SELECT ?, id, 0 FROM spells",
		p.Username,
	)

	if err != nil {
		logrus.Error(err)
		return
	}

	logrus.WithFields(logrus.Fields{
		"Universe": u.Id,
		"Entity":   e.Id,
	}).Warn("script.Super")
}
Пример #2
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)
		}
	}
}